Handle KDE decorations in Mapped::has_ssd
Browse files at this commit226273f6607ae83b17c06e0e094ace64ed7a4f7cParent: c0ded353 changed files +55 -3
- src/handlers/mod.rs +1 -0
- src/handlers/xdg_shell.rs +38 -1
- src/window/mapped.rs +16 -2
src/handlers/mod.rsmodified+1 -0
| @@ -62,6 +62,7 @@ use smithay::{ | |||
| 62 | delegate_virtual_keyboard_manager, delegate_xdg_activation, | 62 | delegate_virtual_keyboard_manager, delegate_xdg_activation, |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | +pub use crate::handlers::xdg_shell::KdeDecorationsModeState; | ||
| 65 | use crate::niri::{ClientState, State}; | 66 | use crate::niri::{ClientState, State}; |
| 66 | use crate::protocols::foreign_toplevel::{ | 67 | use crate::protocols::foreign_toplevel::{ |
| 67 | self, ForeignToplevelHandler, ForeignToplevelManagerState, | 68 | self, ForeignToplevelHandler, ForeignToplevelManagerState, |
src/handlers/xdg_shell.rsmodified+38 -1
| @@ -1,3 +1,5 @@ | |||
| 1 | +use std::cell::Cell; | ||
| 2 | + | ||
| 1 | use smithay::desktop::{ | 3 | use smithay::desktop::{ |
| 2 | find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, utils, LayerSurface, | 4 | find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, utils, LayerSurface, |
| 3 | PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window, | 5 | PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window, |
| @@ -8,10 +10,11 @@ use smithay::output::Output; | |||
| 8 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; | 10 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; |
| 9 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_positioner::ConstraintAdjustment; | 11 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_positioner::ConstraintAdjustment; |
| 10 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self}; | 12 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self}; |
| 13 | +use smithay::reexports::wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration; | ||
| 11 | use smithay::reexports::wayland_server::protocol::wl_output; | 14 | use smithay::reexports::wayland_server::protocol::wl_output; |
| 12 | use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; | 15 | use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; |
| 13 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 16 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 14 | -use smithay::reexports::wayland_server::Resource; | 17 | +use smithay::reexports::wayland_server::{self, Resource, WEnum}; |
| 15 | use smithay::utils::{Logical, Rectangle, Serial}; | 18 | use smithay::utils::{Logical, Rectangle, Serial}; |
| 16 | use smithay::wayland::compositor::{ | 19 | use smithay::wayland::compositor::{ |
| 17 | add_pre_commit_hook, with_states, BufferAssignment, HookId, SurfaceAttributes, | 20 | add_pre_commit_hook, with_states, BufferAssignment, HookId, SurfaceAttributes, |
| @@ -544,10 +547,44 @@ impl XdgDecorationHandler for State { | |||
| 544 | } | 547 | } |
| 545 | delegate_xdg_decoration!(State); | 548 | delegate_xdg_decoration!(State); |
| 546 | 549 | ||
| 550 | +/// Whether KDE server decorations are in use. | ||
| 551 | +#[derive(Default)] | ||
| 552 | +pub struct KdeDecorationsModeState { | ||
| 553 | + server: Cell<bool>, | ||
| 554 | +} | ||
| 555 | + | ||
| 556 | +impl KdeDecorationsModeState { | ||
| 557 | + pub fn is_server(&self) -> bool { | ||
| 558 | + self.server.get() | ||
| 559 | + } | ||
| 560 | +} | ||
| 561 | + | ||
| 547 | impl KdeDecorationHandler for State { | 562 | impl KdeDecorationHandler for State { |
| 548 | fn kde_decoration_state(&self) -> &KdeDecorationState { | 563 | fn kde_decoration_state(&self) -> &KdeDecorationState { |
| 549 | &self.niri.kde_decoration_state | 564 | &self.niri.kde_decoration_state |
| 550 | } | 565 | } |
| 566 | + | ||
| 567 | + fn request_mode( | ||
| 568 | + &mut self, | ||
| 569 | + surface: &WlSurface, | ||
| 570 | + decoration: &org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration, | ||
| 571 | + mode: wayland_server::WEnum<org_kde_kwin_server_decoration::Mode>, | ||
| 572 | + ) { | ||
| 573 | + let WEnum::Value(mode) = mode else { | ||
| 574 | + return; | ||
| 575 | + }; | ||
| 576 | + | ||
| 577 | + decoration.mode(mode); | ||
| 578 | + | ||
| 579 | + with_states(surface, |states| { | ||
| 580 | + let state = states | ||
| 581 | + .data_map | ||
| 582 | + .get_or_insert(KdeDecorationsModeState::default); | ||
| 583 | + state | ||
| 584 | + .server | ||
| 585 | + .set(mode == org_kde_kwin_server_decoration::Mode::Server); | ||
| 586 | + }); | ||
| 587 | + } | ||
| 551 | } | 588 | } |
| 552 | delegate_kde_decoration!(State); | 589 | delegate_kde_decoration!(State); |
| 553 | 590 | ||
src/window/mapped.rsmodified+16 -2
| @@ -17,6 +17,7 @@ use smithay::wayland::compositor::{remove_pre_commit_hook, with_states, HookId}; | |||
| 17 | use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface}; | 17 | use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface}; |
| 18 | 18 | ||
| 19 | use super::{ResolvedWindowRules, WindowRef}; | 19 | use super::{ResolvedWindowRules, WindowRef}; |
| 20 | +use crate::handlers::KdeDecorationsModeState; | ||
| 20 | use crate::layout::{ | 21 | use crate::layout::{ |
| 21 | InteractiveResizeData, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot, | 22 | InteractiveResizeData, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot, |
| 22 | }; | 23 | }; |
| @@ -422,8 +423,21 @@ impl LayoutElement for Mapped { | |||
| 422 | } | 423 | } |
| 423 | 424 | ||
| 424 | fn has_ssd(&self) -> bool { | 425 | fn has_ssd(&self) -> bool { |
| 425 | - self.toplevel().current_state().decoration_mode | 426 | + let toplevel = self.toplevel(); |
| 426 | - == Some(zxdg_toplevel_decoration_v1::Mode::ServerSide) | 427 | + let mode = toplevel.current_state().decoration_mode; |
| 428 | + | ||
| 429 | + match mode { | ||
| 430 | + Some(zxdg_toplevel_decoration_v1::Mode::ServerSide) => true, | ||
| 431 | + // Check KDE decorations when XDG are not in use. | ||
| 432 | + None => with_states(toplevel.wl_surface(), |states| { | ||
| 433 | + states | ||
| 434 | + .data_map | ||
| 435 | + .get::<KdeDecorationsModeState>() | ||
| 436 | + .map(KdeDecorationsModeState::is_server) | ||
| 437 | + == Some(true) | ||
| 438 | + }), | ||
| 439 | + _ => false, | ||
| 440 | + } | ||
| 427 | } | 441 | } |
| 428 | 442 | ||
| 429 | fn output_enter(&self, output: &Output) { | 443 | fn output_enter(&self, output: &Output) { |