Skip to content

Commit 394f9d2

Browse files
wayland: add prefer_csd attribute
1 parent 66283a7 commit 394f9d2

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

winit-wayland/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub(crate) struct ApplicationName {
9999
pub struct WindowAttributesWayland {
100100
pub(crate) name: Option<ApplicationName>,
101101
pub(crate) activation_token: Option<ActivationToken>,
102+
pub(crate) prefer_csd: bool,
102103
}
103104

104105
impl WindowAttributesWayland {
@@ -120,6 +121,12 @@ impl WindowAttributesWayland {
120121
self.activation_token = Some(token);
121122
self
122123
}
124+
125+
#[inline]
126+
pub fn with_prefer_csd(mut self, prefer_csd: bool) -> Self {
127+
self.prefer_csd = prefer_csd;
128+
self
129+
}
123130
}
124131

125132
impl PlatformWindowAttributes for WindowAttributesWayland {

winit-wayland/src/window/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,20 @@ impl Window {
106106
let window =
107107
state.xdg_shell.create_window(surface.clone(), default_decorations, &queue_handle);
108108

109+
let WindowAttributesWayland { name: app_name, activation_token, prefer_csd } = *attributes
110+
.platform
111+
.take()
112+
.and_then(|p| p.cast::<WindowAttributesWayland>().ok())
113+
.unwrap_or_default();
114+
109115
let mut window_state = WindowState::new(
110116
event_loop_window_target.handle.clone(),
111117
&event_loop_window_target.queue_handle,
112118
&state,
113119
size,
114120
window.clone(),
115121
attributes.preferred_theme,
122+
prefer_csd,
116123
);
117124

118125
window_state.set_window_icon(attributes.window_icon);
@@ -125,13 +132,6 @@ impl Window {
125132
// Set the decorations hint.
126133
window_state.set_decorate(attributes.decorations);
127134

128-
let (app_name, activation_token) =
129-
match attributes.platform.take().and_then(|p| p.cast::<WindowAttributesWayland>().ok())
130-
{
131-
Some(attrs) => (attrs.name, attrs.activation_token),
132-
None => (None, None),
133-
};
134-
135135
// Set the app_id.
136136
if let Some(name) = app_name.map(|name| name.general) {
137137
window.set_app_id(name);

winit-wayland/src/window/state.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ pub struct WindowState {
134134
/// Whether we should decorate the frame.
135135
decorate: bool,
136136

137+
/// Whether we should tell the compositor that we prefer drawing decorations ourself.
138+
prefer_csd: bool,
139+
137140
/// Min size.
138141
min_surface_size: LogicalSize<u32>,
139142
max_surface_size: Option<LogicalSize<u32>>,
@@ -180,6 +183,7 @@ impl WindowState {
180183
initial_size: Size,
181184
window: Window,
182185
theme: Option<Theme>,
186+
prefer_csd: bool,
183187
) -> Self {
184188
let compositor = winit_state.compositor_state.clone();
185189
let pointer_constraints = winit_state.pointer_constraints.clone();
@@ -209,6 +213,7 @@ impl WindowState {
209213
selected_cursor: Default::default(),
210214
cursor_visible: true,
211215
decorate: true,
216+
prefer_csd,
212217
fractional_scale,
213218
frame: None,
214219
frame_callback_state: FrameCallbackState::None,
@@ -955,7 +960,7 @@ impl WindowState {
955960
/// Whether show or hide client side decorations.
956961
#[inline]
957962
pub fn set_decorate(&mut self, decorate: bool) {
958-
if decorate == self.decorate {
963+
if decorate == self.decorate && !self.prefer_csd {
959964
return;
960965
}
961966

@@ -966,6 +971,9 @@ impl WindowState {
966971
// To disable decorations we should request client and hide the frame.
967972
self.window.request_decoration_mode(Some(DecorationMode::Client))
968973
},
974+
_ if self.decorate && self.prefer_csd => {
975+
self.window.request_decoration_mode(Some(DecorationMode::Client))
976+
},
969977
_ if self.decorate => self.window.request_decoration_mode(Some(DecorationMode::Server)),
970978
_ => (),
971979
}

0 commit comments

Comments
 (0)