Hide decoration globals when we need CSD

This gets the current SDL2 with libdecor working.
This commit is contained in:
Ivan Molodetskikh
2024-01-15 16:01:01 +04:00
parent 533659eef8
commit 59763fd0da
3 changed files with 32 additions and 23 deletions
+6 -3
View File
@@ -25,9 +25,12 @@ impl ServiceChannel {
} }
let (sock1, sock2) = UnixStream::pair().unwrap(); let (sock1, sock2) = UnixStream::pair().unwrap();
self.display let data = Arc::new(ClientState {
.insert_client(sock2, Arc::new(ClientState::default())) compositor_state: Default::default(),
.unwrap(); // Would be nice to thread config here but for now it's fine.
can_view_decoration_globals: false,
});
self.display.insert_client(sock2, data).unwrap();
Ok(unsafe { zbus::zvariant::OwnedFd::from_raw_fd(sock1.into_raw_fd()) }) Ok(unsafe { zbus::zvariant::OwnedFd::from_raw_fd(sock1.into_raw_fd()) })
} }
} }
+4 -12
View File
@@ -277,13 +277,9 @@ delegate_xdg_shell!(State);
impl XdgDecorationHandler for State { impl XdgDecorationHandler for State {
fn new_decoration(&mut self, toplevel: ToplevelSurface) { fn new_decoration(&mut self, toplevel: ToplevelSurface) {
let mode = if self.niri.config.borrow().prefer_no_csd { // If we want CSD, we hide this global altogether.
Some(zxdg_toplevel_decoration_v1::Mode::ServerSide)
} else {
None
};
toplevel.with_pending_state(|state| { toplevel.with_pending_state(|state| {
state.decoration_mode = mode; state.decoration_mode = Some(zxdg_toplevel_decoration_v1::Mode::ServerSide);
}); });
} }
@@ -308,13 +304,9 @@ impl XdgDecorationHandler for State {
} }
fn unset_mode(&mut self, toplevel: ToplevelSurface) { fn unset_mode(&mut self, toplevel: ToplevelSurface) {
let mode = if self.niri.config.borrow().prefer_no_csd { // If we want CSD, we hide this global altogether.
Some(zxdg_toplevel_decoration_v1::Mode::ServerSide)
} else {
None
};
toplevel.with_pending_state(|state| { toplevel.with_pending_state(|state| {
state.decoration_mode = mode; state.decoration_mode = Some(zxdg_toplevel_decoration_v1::Mode::ServerSide);
}); });
// A configure is required in response to this event. However, if an initial configure // A configure is required in response to this event. However, if an initial configure
+22 -8
View File
@@ -695,13 +695,22 @@ impl Niri {
&display_handle, &display_handle,
[WmCapabilities::Fullscreen], [WmCapabilities::Fullscreen],
); );
let xdg_decoration_state = XdgDecorationState::new::<State>(&display_handle); let xdg_decoration_state =
let kde_decoration_state = KdeDecorationState::new::<State>( XdgDecorationState::new_with_filter::<State, _>(&display_handle, |client| {
client
.get_data::<ClientState>()
.unwrap()
.can_view_decoration_globals
});
let kde_decoration_state = KdeDecorationState::new_with_filter::<State, _>(
&display_handle, &display_handle,
if config_.prefer_no_csd { // If we want CSD we will hide the global.
KdeDecorationsMode::Server KdeDecorationsMode::Server,
} else { |client| {
KdeDecorationsMode::Client client
.get_data::<ClientState>()
.unwrap()
.can_view_decoration_globals
}, },
); );
let layer_shell_state = WlrLayerShellState::new::<State>(&display_handle); let layer_shell_state = WlrLayerShellState::new::<State>(&display_handle);
@@ -768,7 +777,12 @@ impl Niri {
let socket_name = socket_source.socket_name().to_os_string(); let socket_name = socket_source.socket_name().to_os_string();
event_loop event_loop
.insert_source(socket_source, move |client, _, state| { .insert_source(socket_source, move |client, _, state| {
let data = Arc::new(ClientState::default()); let config = state.niri.config.borrow();
let data = Arc::new(ClientState {
compositor_state: Default::default(),
can_view_decoration_globals: config.prefer_no_csd,
});
if let Err(err) = state.niri.display_handle.insert_client(client, data) { if let Err(err) = state.niri.display_handle.insert_client(client, data) {
error!("error inserting client: {err}"); error!("error inserting client: {err}");
} }
@@ -2518,9 +2532,9 @@ impl Niri {
} }
} }
#[derive(Default)]
pub struct ClientState { pub struct ClientState {
pub compositor_state: CompositorClientState, pub compositor_state: CompositorClientState,
pub can_view_decoration_globals: bool,
} }
impl ClientData for ClientState { impl ClientData for ClientState {