diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-01-29 19:34:12 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-01-30 12:30:57 +0400 |
| commit | 59ff331597633dc66113e5070d672ba70035421b (patch) | |
| tree | 68d8c275a7661337ea64a6f8254a51a41224ab72 /src/handlers | |
| parent | b813f99abd2d6e09eb72e8c0083e92b486b4b210 (diff) | |
| download | niri-59ff331597633dc66113e5070d672ba70035421b.tar.gz niri-59ff331597633dc66113e5070d672ba70035421b.tar.bz2 niri-59ff331597633dc66113e5070d672ba70035421b.zip | |
Implement wlr-foreign-toplevel-management
The parent event isn't sent but whatever.
Diffstat (limited to 'src/handlers')
| -rw-r--r-- | src/handlers/mod.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index d44d9e8c..f0620a5b 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -14,6 +14,7 @@ use smithay::input::pointer::{CursorIcon, CursorImageStatus, PointerHandle}; use smithay::input::{keyboard, Seat, SeatHandler, SeatState}; use smithay::output::Output; use smithay::reexports::input; +use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource; use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; @@ -46,7 +47,9 @@ use smithay::{ delegate_tablet_manager, delegate_text_input_manager, delegate_virtual_keyboard_manager, }; +use crate::delegate_foreign_toplevel; use crate::niri::{ClientState, State}; +use crate::protocols::foreign_toplevel::{ForeignToplevelHandler, ForeignToplevelManagerState}; use crate::utils::output_size; impl SeatHandler for State { @@ -291,3 +294,57 @@ impl SecurityContextHandler for State { } } delegate_security_context!(State); + +impl ForeignToplevelHandler for State { + fn foreign_toplevel_manager_state(&mut self) -> &mut ForeignToplevelManagerState { + &mut self.niri.foreign_toplevel_state + } + + fn activate(&mut self, wl_surface: WlSurface) { + if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) { + let window = window.clone(); + self.niri.layout.activate_window(&window); + self.niri.queue_redraw_all(); + } + } + + fn close(&mut self, wl_surface: WlSurface) { + if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) { + window.toplevel().send_close(); + } + } + + fn set_fullscreen(&mut self, wl_surface: WlSurface, wl_output: Option<WlOutput>) { + if let Some((window, current_output)) = self.niri.layout.find_window_and_output(&wl_surface) + { + if !window + .toplevel() + .current_state() + .capabilities + .contains(xdg_toplevel::WmCapabilities::Fullscreen) + { + return; + } + + let window = window.clone(); + + if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { + if &requested_output != current_output { + self.niri + .layout + .move_window_to_output(window.clone(), &requested_output); + } + } + + self.niri.layout.set_fullscreen(&window, true); + } + } + + fn unset_fullscreen(&mut self, wl_surface: WlSurface) { + if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) { + let window = window.clone(); + self.niri.layout.set_fullscreen(&window, false); + } + } +} +delegate_foreign_toplevel!(State); |
