Enable server side decorations on wayland (#8037)

This PR enables server side decorations on Wayland if possible. This is
stopgap solution, so that the window can be moved, resized and dragged
on Wayland sessions at all.


![image](https://github.com/zed-industries/zed/assets/25827180/3dc9af53-76c0-4664-8746-ed6a6e5eafe7)

Since Wayland compositors can decide to force either mode (as in,
forcing server or client side decorations), this requires additional
handling in zed. Since zed doesn't provide any of that handling as of
now, as a temporary solution server side decorations are always
requested.
This commit is contained in:
Janrupf 2024-02-20 02:53:31 +01:00 committed by GitHub
parent 77974a4367
commit fddb778e5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 110 additions and 2 deletions

View file

@ -41,6 +41,7 @@ struct WaylandWindowInner {
bounds: Bounds<i32>,
scale: f32,
input_handler: Option<PlatformInputHandler>,
decoration_state: WaylandDecorationState,
}
struct RawWindow {
@ -96,6 +97,9 @@ impl WaylandWindowInner {
bounds,
scale: 1.0,
input_handler: None,
// On wayland, decorations are by default provided by the client
decoration_state: WaylandDecorationState::Client,
}
}
}
@ -187,6 +191,20 @@ impl WaylandWindowState {
self.set_size_and_scale(bounds.size.width, bounds.size.height, scale)
}
/// Notifies the window of the state of the decorations.
///
/// # Note
///
/// This API is indirectly called by the wayland compositor and
/// not meant to be called by a user who wishes to change the state
/// of the decorations. This is because the state of the decorations
/// is managed by the compositor and not the client.
pub fn set_decoration_state(&self, state: WaylandDecorationState) {
self.inner.lock().decoration_state = state;
log::trace!("Window decorations are now handled by {:?}", state);
// todo!(linux) - Handle this properly
}
pub fn close(&self) {
let mut callbacks = self.callbacks.lock();
if let Some(fun) = callbacks.close.take() {
@ -377,3 +395,12 @@ impl PlatformWindow for WaylandWindow {
//todo!(linux)
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum WaylandDecorationState {
/// Decorations are to be provided by the client
Client,
/// Decorations are provided by the server
Server,
}