Add prefer-no-csd option

This commit is contained in:
Ivan Molodetskikh
2023-09-26 13:44:37 +04:00
parent dc10e464ad
commit 80928632ba
4 changed files with 50 additions and 1 deletions
+4
View File
@@ -56,6 +56,10 @@ focus-ring {
inactive-color 0.3 0.3 0.3 1.0 inactive-color 0.3 0.3 0.3 1.0
} }
// Uncomment this line to ask the clients to omit their client-side decorations if possible.
// If the client will specifically ask for CSD, the request will be honored.
// prefer-no-csd
binds { binds {
// Keys consist of modifiers separated by + signs, followed by an XKB key name // Keys consist of modifiers separated by + signs, followed by an XKB key name
// in the end. To find an XKB name for a particular key, you may use a program // in the end. To find an XKB name for a particular key, you may use a program
+5
View File
@@ -19,6 +19,8 @@ pub struct Config {
#[knuffel(child, default)] #[knuffel(child, default)]
pub focus_ring: FocusRing, pub focus_ring: FocusRing,
#[knuffel(child, default)] #[knuffel(child, default)]
pub prefer_no_csd: bool,
#[knuffel(child, default)]
pub binds: Binds, pub binds: Binds,
#[knuffel(child, default)] #[knuffel(child, default)]
pub debug: DebugConfig, pub debug: DebugConfig,
@@ -350,6 +352,8 @@ mod tests {
inactive-color 1.0 0.5 0.25 0.0 inactive-color 1.0 0.5 0.25 0.0
} }
prefer-no-csd
binds { binds {
Mod+T { spawn "alacritty"; } Mod+T { spawn "alacritty"; }
Mod+Q { close-window; } Mod+Q { close-window; }
@@ -403,6 +407,7 @@ mod tests {
a: 0., a: 0.,
}, },
}, },
prefer_no_csd: true,
binds: Binds(vec![ binds: Binds(vec![
Bind { Bind {
key: Key { key: Key {
+37 -1
View File
@@ -1,16 +1,18 @@
use smithay::delegate_xdg_shell;
use smithay::desktop::{find_popup_root_surface, PopupKind, Window}; use smithay::desktop::{find_popup_root_surface, PopupKind, Window};
use smithay::output::Output; use smithay::output::Output;
use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self, ResizeEdge}; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self, ResizeEdge};
use smithay::reexports::wayland_server::protocol::wl_output; use smithay::reexports::wayland_server::protocol::wl_output;
use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::utils::Serial; use smithay::utils::Serial;
use smithay::wayland::compositor::with_states; use smithay::wayland::compositor::with_states;
use smithay::wayland::shell::xdg::decoration::XdgDecorationHandler;
use smithay::wayland::shell::xdg::{ use smithay::wayland::shell::xdg::{
PopupSurface, PositionerState, ToplevelSurface, XdgPopupSurfaceData, XdgShellHandler, PopupSurface, PositionerState, ToplevelSurface, XdgPopupSurfaceData, XdgShellHandler,
XdgShellState, XdgToplevelSurfaceData, XdgShellState, XdgToplevelSurfaceData,
}; };
use smithay::{delegate_xdg_decoration, delegate_xdg_shell};
use crate::layout::{configure_new_window, output_size}; use crate::layout::{configure_new_window, output_size};
use crate::niri::State; use crate::niri::State;
@@ -164,6 +166,40 @@ impl XdgShellHandler for State {
delegate_xdg_shell!(State); delegate_xdg_shell!(State);
impl XdgDecorationHandler for State {
fn new_decoration(&mut self, toplevel: ToplevelSurface) {
let mode = if self.niri.config.borrow().prefer_no_csd {
Some(zxdg_toplevel_decoration_v1::Mode::ServerSide)
} else {
None
};
toplevel.with_pending_state(|state| {
state.decoration_mode = mode;
});
toplevel.send_configure();
}
fn request_mode(&mut self, toplevel: ToplevelSurface, mode: zxdg_toplevel_decoration_v1::Mode) {
toplevel.with_pending_state(|state| {
state.decoration_mode = Some(mode);
});
toplevel.send_configure();
}
fn unset_mode(&mut self, toplevel: ToplevelSurface) {
let mode = if self.niri.config.borrow().prefer_no_csd {
Some(zxdg_toplevel_decoration_v1::Mode::ServerSide)
} else {
None
};
toplevel.with_pending_state(|state| {
state.decoration_mode = mode;
});
toplevel.send_configure();
}
}
delegate_xdg_decoration!(State);
pub fn send_initial_configure_if_needed(window: &Window) { pub fn send_initial_configure_if_needed(window: &Window) {
let initial_configure_sent = with_states(window.toplevel().wl_surface(), |states| { let initial_configure_sent = with_states(window.toplevel().wl_surface(), |states| {
states states
+4
View File
@@ -54,6 +54,7 @@ use smithay::wayland::output::OutputManagerState;
use smithay::wayland::pointer_gestures::PointerGesturesState; use smithay::wayland::pointer_gestures::PointerGesturesState;
use smithay::wayland::presentation::PresentationState; use smithay::wayland::presentation::PresentationState;
use smithay::wayland::shell::wlr_layer::{Layer, WlrLayerShellState}; use smithay::wayland::shell::wlr_layer::{Layer, WlrLayerShellState};
use smithay::wayland::shell::xdg::decoration::XdgDecorationState;
use smithay::wayland::shell::xdg::XdgShellState; use smithay::wayland::shell::xdg::XdgShellState;
use smithay::wayland::shm::ShmState; use smithay::wayland::shm::ShmState;
use smithay::wayland::socket::ListeningSocketSource; use smithay::wayland::socket::ListeningSocketSource;
@@ -94,6 +95,7 @@ pub struct Niri {
// Smithay state. // Smithay state.
pub compositor_state: CompositorState, pub compositor_state: CompositorState,
pub xdg_shell_state: XdgShellState, pub xdg_shell_state: XdgShellState,
pub xdg_decoration_state: XdgDecorationState,
pub layer_shell_state: WlrLayerShellState, pub layer_shell_state: WlrLayerShellState,
pub shm_state: ShmState, pub shm_state: ShmState,
pub output_manager_state: OutputManagerState, pub output_manager_state: OutputManagerState,
@@ -213,6 +215,7 @@ impl Niri {
&display_handle, &display_handle,
[WmCapabilities::Fullscreen], [WmCapabilities::Fullscreen],
); );
let xdg_decoration_state = XdgDecorationState::new::<State>(&display_handle);
let layer_shell_state = WlrLayerShellState::new::<State>(&display_handle); let layer_shell_state = WlrLayerShellState::new::<State>(&display_handle);
let shm_state = ShmState::new::<State>(&display_handle, vec![]); let shm_state = ShmState::new::<State>(&display_handle, vec![]);
let output_manager_state = let output_manager_state =
@@ -563,6 +566,7 @@ impl Niri {
compositor_state, compositor_state,
xdg_shell_state, xdg_shell_state,
xdg_decoration_state,
layer_shell_state, layer_shell_state,
shm_state, shm_state,
output_manager_state, output_manager_state,