Skip to content

Commit a280f3a

Browse files
committed
Allow for hide_titlebar config to be updated on the fly (does not work for shadows for now)
1 parent 1f27a90 commit a280f3a

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

examples/window.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ fn main() {
101101
themed_pointer: None,
102102
set_cursor: false,
103103
cursor_icon: CursorIcon::Crosshair,
104+
hide_titlebar: false,
104105
};
105106

106107
// We don't draw immediately, the configure will notify us when to first draw.
@@ -137,6 +138,8 @@ struct SimpleWindow {
137138
themed_pointer: Option<ThemedPointer>,
138139
set_cursor: bool,
139140
cursor_icon: CursorIcon,
141+
142+
hide_titlebar: bool,
140143
}
141144

142145
impl CompositorHandler for SimpleWindow {
@@ -251,7 +254,7 @@ impl WindowHandler for SimpleWindow {
251254
self.compositor_state.clone(),
252255
self.subcompositor_state.clone(),
253256
qh.clone(),
254-
FrameConfig::auto(),
257+
FrameConfig::auto().hide_titlebar(self.hide_titlebar),
255258
)
256259
.expect("failed to create client side decorations frame.");
257260
frame.set_title(self.title.clone());
@@ -447,7 +450,45 @@ impl PointerHandler for SimpleWindow {
447450
}
448451
} else if pressed {
449452
println!("Press {:x} @ {:?}", button, event.position);
450-
self.shift = self.shift.xor(Some(0));
453+
454+
if button == 0x111 {
455+
self.hide_titlebar = !self.hide_titlebar;
456+
457+
if let Some(frame) = self.window_frame.as_mut() {
458+
// FrameConfig::auto() is not free, this shouldn't be called here
459+
let config = FrameConfig::auto();
460+
461+
if self.hide_titlebar {
462+
frame.set_config(config.hide_titlebar(true));
463+
self.window.xdg_surface().set_window_geometry(
464+
0,
465+
0,
466+
self.width.get() as i32,
467+
self.height.get() as i32,
468+
);
469+
} else {
470+
let (width, height) = (self.width, self.height);
471+
472+
frame.set_config(config.hide_titlebar(false));
473+
frame.resize(width, height);
474+
475+
let (x, y) = frame.location();
476+
let outer_size = frame.add_borders(width.get(), height.get());
477+
self.window.xdg_surface().set_window_geometry(
478+
x,
479+
y,
480+
outer_size.0 as i32,
481+
outer_size.1 as i32,
482+
);
483+
484+
// Update new width and height;
485+
self.width = width;
486+
self.height = height;
487+
}
488+
}
489+
} else {
490+
self.shift = self.shift.xor(Some(0));
491+
}
451492
}
452493
}
453494
Axis {

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub struct AdwaitaFrame<State> {
9292

9393
/// Draw decorations but without the titlebar
9494
hide_titlebar: bool,
95+
96+
width: NonZeroU32,
97+
height: NonZeroU32,
9598
}
9699

97100
impl<State> AdwaitaFrame<State>
@@ -139,13 +142,27 @@ where
139142
resizable: true,
140143
shadow: Shadow::default(),
141144
hide_titlebar: frame_config.hide_titlebar,
145+
width: NonZeroU32::new(1).unwrap(),
146+
height: NonZeroU32::new(1).unwrap(),
142147
})
143148
}
144149

145150
/// Update the current frame config.
146151
pub fn set_config(&mut self, config: FrameConfig) {
147152
self.theme = config.theme;
148153
self.dirty = true;
154+
155+
if self.hide_titlebar != config.hide_titlebar {
156+
self.hide_titlebar = config.hide_titlebar;
157+
let mut decorations = DecorationParts::new(
158+
&self.base_surface,
159+
&self.subcompositor,
160+
&self.queue_handle,
161+
self.hide_titlebar,
162+
);
163+
decorations.resize(self.width.get(), self.height.get());
164+
self.decorations = Some(decorations);
165+
}
149166
}
150167

151168
fn precise_location(
@@ -443,6 +460,9 @@ where
443460
}
444461

445462
fn resize(&mut self, width: NonZeroU32, height: NonZeroU32) {
463+
self.width = width;
464+
self.height = height;
465+
446466
let Some(decorations) = self.decorations.as_mut() else {
447467
log::error!("trying to resize the hidden frame.");
448468
return;

0 commit comments

Comments
 (0)