input: Add Super+F to fullscreen
Browse files at this commitf734cb0129a804c4e9c0f20a6c5318554969730dParent: 91a809b1 changed file +32 -0
- src/input.rs +32 -0
src/input.rsmodified+32 -0
| @@ -7,8 +7,10 @@ use smithay::backend::input::{ | |||
| 7 | }; | 7 | }; |
| 8 | use smithay::input::keyboard::{keysyms, FilterResult}; | 8 | use smithay::input::keyboard::{keysyms, FilterResult}; |
| 9 | use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent, RelativeMotionEvent}; | 9 | use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent, RelativeMotionEvent}; |
| 10 | +use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | ||
| 10 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 11 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 11 | use smithay::utils::SERIAL_COUNTER; | 12 | use smithay::utils::SERIAL_COUNTER; |
| 13 | +use smithay::wayland::shell::xdg::XdgShellHandler; | ||
| 12 | 14 | ||
| 13 | use crate::niri::Niri; | 15 | use crate::niri::Niri; |
| 14 | 16 | ||
| @@ -17,6 +19,7 @@ enum InputAction { | |||
| 17 | ChangeVt(i32), | 19 | ChangeVt(i32), |
| 18 | SpawnTerminal, | 20 | SpawnTerminal, |
| 19 | CloseWindow, | 21 | CloseWindow, |
| 22 | + ToggleFullscreen, | ||
| 20 | } | 23 | } |
| 21 | 24 | ||
| 22 | impl Niri { | 25 | impl Niri { |
| @@ -58,6 +61,9 @@ impl Niri { | |||
| 58 | keysyms::KEY_q if mods.logo => { | 61 | keysyms::KEY_q if mods.logo => { |
| 59 | FilterResult::Intercept(InputAction::CloseWindow) | 62 | FilterResult::Intercept(InputAction::CloseWindow) |
| 60 | } | 63 | } |
| 64 | + keysyms::KEY_f if mods.logo => { | ||
| 65 | + FilterResult::Intercept(InputAction::ToggleFullscreen) | ||
| 66 | + } | ||
| 61 | _ => FilterResult::Forward, | 67 | _ => FilterResult::Forward, |
| 62 | } | 68 | } |
| 63 | } else { | 69 | } else { |
| @@ -97,6 +103,32 @@ impl Niri { | |||
| 97 | } | 103 | } |
| 98 | } | 104 | } |
| 99 | } | 105 | } |
| 106 | + InputAction::ToggleFullscreen => { | ||
| 107 | + if let Some(focus) = self.seat.get_keyboard().unwrap().current_focus() { | ||
| 108 | + // FIXME: is there a better way of doing this? | ||
| 109 | + let window = self.space.elements().find(|window| { | ||
| 110 | + let found = Cell::new(false); | ||
| 111 | + window.with_surfaces(|surface, _| { | ||
| 112 | + if surface == &focus { | ||
| 113 | + found.set(true); | ||
| 114 | + } | ||
| 115 | + }); | ||
| 116 | + found.get() | ||
| 117 | + }); | ||
| 118 | + if let Some(window) = window { | ||
| 119 | + let toplevel = window.toplevel().clone(); | ||
| 120 | + if toplevel | ||
| 121 | + .current_state() | ||
| 122 | + .states | ||
| 123 | + .contains(xdg_toplevel::State::Fullscreen) | ||
| 124 | + { | ||
| 125 | + self.unfullscreen_request(toplevel); | ||
| 126 | + } else { | ||
| 127 | + self.fullscreen_request(toplevel, None); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + } | ||
| 100 | } | 132 | } |
| 101 | } | 133 | } |
| 102 | } | 134 | } |