Add mod-key and mod-key-nested settings
Browse files at this commitc3609efb7aaa4f118eacdfed7003285f124f6b8aParent: fd1f4365 changed files +167 -130
- niri-config/src/lib.rs +52 -0
- src/backend/mod.rs +10 -5
- src/input/mod.rs +50 -84
- src/niri.rs +13 -12
- src/ui/hotkey_overlay.rs +42 -29
niri-config/src/lib.rsmodified+52 -0
| @@ -100,6 +100,10 @@ pub struct Input { | |||
| 100 | pub focus_follows_mouse: Option<FocusFollowsMouse>, | 100 | pub focus_follows_mouse: Option<FocusFollowsMouse>, |
| 101 | #[knuffel(child)] | 101 | #[knuffel(child)] |
| 102 | pub workspace_auto_back_and_forth: bool, | 102 | pub workspace_auto_back_and_forth: bool, |
| 103 | + #[knuffel(child, unwrap(argument, str))] | ||
| 104 | + pub mod_key: Option<ModKey>, | ||
| 105 | + #[knuffel(child, unwrap(argument, str))] | ||
| 106 | + pub mod_key_nested: Option<ModKey>, | ||
| 103 | } | 107 | } |
| 104 | 108 | ||
| 105 | #[derive(knuffel::Decode, Debug, PartialEq, Eq)] | 109 | #[derive(knuffel::Decode, Debug, PartialEq, Eq)] |
| @@ -368,6 +372,29 @@ pub struct FocusFollowsMouse { | |||
| 368 | #[derive(Debug, Clone, Copy, PartialEq)] | 372 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 369 | pub struct Percent(pub f64); | 373 | pub struct Percent(pub f64); |
| 370 | 374 | ||
| 375 | +#[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
| 376 | +pub enum ModKey { | ||
| 377 | + Ctrl, | ||
| 378 | + Shift, | ||
| 379 | + Alt, | ||
| 380 | + Super, | ||
| 381 | + IsoLevel3Shift, | ||
| 382 | + IsoLevel5Shift, | ||
| 383 | +} | ||
| 384 | + | ||
| 385 | +impl ModKey { | ||
| 386 | + pub fn to_modifiers(&self) -> Modifiers { | ||
| 387 | + match self { | ||
| 388 | + ModKey::Ctrl => Modifiers::CTRL, | ||
| 389 | + ModKey::Shift => Modifiers::SHIFT, | ||
| 390 | + ModKey::Alt => Modifiers::ALT, | ||
| 391 | + ModKey::Super => Modifiers::SUPER, | ||
| 392 | + ModKey::IsoLevel3Shift => Modifiers::ISO_LEVEL3_SHIFT, | ||
| 393 | + ModKey::IsoLevel5Shift => Modifiers::ISO_LEVEL5_SHIFT, | ||
| 394 | + } | ||
| 395 | + } | ||
| 396 | +} | ||
| 397 | + | ||
| 371 | #[derive(Debug, Default, Clone, PartialEq)] | 398 | #[derive(Debug, Default, Clone, PartialEq)] |
| 372 | pub struct Outputs(pub Vec<Output>); | 399 | pub struct Outputs(pub Vec<Output>); |
| 373 | 400 | ||
| @@ -3427,6 +3454,22 @@ where | |||
| 3427 | } | 3454 | } |
| 3428 | } | 3455 | } |
| 3429 | 3456 | ||
| 3457 | +impl FromStr for ModKey { | ||
| 3458 | + type Err = miette::Error; | ||
| 3459 | + | ||
| 3460 | + fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| 3461 | + match &*s.to_ascii_lowercase() { | ||
| 3462 | + "ctrl" | "control" => Ok(Self::Ctrl), | ||
| 3463 | + "shift" => Ok(Self::Shift), | ||
| 3464 | + "alt" => Ok(Self::Alt), | ||
| 3465 | + "super" | "win" => Ok(Self::Super), | ||
| 3466 | + "iso_level3_shift" | "mod5" => Ok(Self::IsoLevel3Shift), | ||
| 3467 | + "iso_level5_shift" | "mod3" => Ok(Self::IsoLevel5Shift), | ||
| 3468 | + _ => Err(miette!("invalid Mod key: {s}")), | ||
| 3469 | + } | ||
| 3470 | + } | ||
| 3471 | +} | ||
| 3472 | + | ||
| 3430 | impl FromStr for Key { | 3473 | impl FromStr for Key { |
| 3431 | type Err = miette::Error; | 3474 | type Err = miette::Error; |
| 3432 | 3475 | ||
| @@ -3664,6 +3707,9 @@ mod tests { | |||
| 3664 | warp-mouse-to-focus | 3707 | warp-mouse-to-focus |
| 3665 | focus-follows-mouse | 3708 | focus-follows-mouse |
| 3666 | workspace-auto-back-and-forth | 3709 | workspace-auto-back-and-forth |
| 3710 | + | ||
| 3711 | + mod-key "Mod5" | ||
| 3712 | + mod-key-nested "Super" | ||
| 3667 | } | 3713 | } |
| 3668 | 3714 | ||
| 3669 | output "eDP-1" { | 3715 | output "eDP-1" { |
| @@ -3984,6 +4030,12 @@ mod tests { | |||
| 3984 | }, | 4030 | }, |
| 3985 | ), | 4031 | ), |
| 3986 | workspace_auto_back_and_forth: true, | 4032 | workspace_auto_back_and_forth: true, |
| 4033 | + mod_key: Some( | ||
| 4034 | + IsoLevel3Shift, | ||
| 4035 | + ), | ||
| 4036 | + mod_key_nested: Some( | ||
| 4037 | + Super, | ||
| 4038 | + ), | ||
| 3987 | }, | 4039 | }, |
| 3988 | outputs: Outputs( | 4040 | outputs: Outputs( |
| 3989 | [ | 4041 | [ |
src/backend/mod.rsmodified+10 -5
| @@ -2,12 +2,12 @@ use std::collections::HashMap; | |||
| 2 | use std::sync::{Arc, Mutex}; | 2 | use std::sync::{Arc, Mutex}; |
| 3 | use std::time::Duration; | 3 | use std::time::Duration; |
| 4 | 4 | ||
| 5 | +use niri_config::{Config, ModKey}; | ||
| 5 | use smithay::backend::allocator::dmabuf::Dmabuf; | 6 | use smithay::backend::allocator::dmabuf::Dmabuf; |
| 6 | use smithay::backend::renderer::gles::GlesRenderer; | 7 | use smithay::backend::renderer::gles::GlesRenderer; |
| 7 | use smithay::output::Output; | 8 | use smithay::output::Output; |
| 8 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 9 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 9 | 10 | ||
| 10 | -use crate::input::CompositorMod; | ||
| 11 | use crate::niri::Niri; | 11 | use crate::niri::Niri; |
| 12 | use crate::utils::id::IdCounter; | 12 | use crate::utils::id::IdCounter; |
| 13 | 13 | ||
| @@ -94,11 +94,16 @@ impl Backend { | |||
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | - pub fn mod_key(&self) -> CompositorMod { | 97 | + pub fn mod_key(&self, config: &Config) -> ModKey { |
| 98 | match self { | 98 | match self { |
| 99 | - Backend::Tty(_) => CompositorMod::Super, | 99 | + Backend::Winit(_) => config.input.mod_key_nested.unwrap_or({ |
| 100 | - Backend::Winit(_) => CompositorMod::Alt, | 100 | + if let Some(ModKey::Alt) = config.input.mod_key { |
| 101 | - Backend::Headless(_) => CompositorMod::Super, | 101 | + ModKey::Super |
| 102 | + } else { | ||
| 103 | + ModKey::Alt | ||
| 104 | + } | ||
| 105 | + }), | ||
| 106 | + Backend::Tty(_) | Backend::Headless(_) => config.input.mod_key.unwrap_or(ModKey::Super), | ||
| 102 | } | 107 | } |
| 103 | } | 108 | } |
| 104 | 109 | ||
src/input/mod.rsmodified+50 -84
| @@ -6,7 +6,7 @@ use std::time::Duration; | |||
| 6 | 6 | ||
| 7 | use calloop::timer::{TimeoutAction, Timer}; | 7 | use calloop::timer::{TimeoutAction, Timer}; |
| 8 | use input::event::gesture::GestureEventCoordinates as _; | 8 | use input::event::gesture::GestureEventCoordinates as _; |
| 9 | -use niri_config::{Action, Bind, Binds, Key, Modifiers, SwitchBinds, Trigger}; | 9 | +use niri_config::{Action, Bind, Binds, Key, ModKey, Modifiers, SwitchBinds, Trigger}; |
| 10 | use niri_ipc::LayoutSwitchTarget; | 10 | use niri_ipc::LayoutSwitchTarget; |
| 11 | use smithay::backend::input::{ | 11 | use smithay::backend::input::{ |
| 12 | AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, | 12 | AbsolutePositionEvent, Axis, AxisSource, ButtonState, Device, DeviceCapability, Event, |
| @@ -60,12 +60,6 @@ use backend_ext::{NiriInputBackend as InputBackend, NiriInputDevice as _}; | |||
| 60 | 60 | ||
| 61 | pub const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(400); | 61 | pub const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(400); |
| 62 | 62 | ||
| 63 | -#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 64 | -pub enum CompositorMod { | ||
| 65 | - Super, | ||
| 66 | - Alt, | ||
| 67 | -} | ||
| 68 | - | ||
| 69 | #[derive(Debug, Clone, Copy, PartialEq)] | 63 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 70 | pub struct TabletData { | 64 | pub struct TabletData { |
| 71 | pub aspect_ratio: f64, | 65 | pub aspect_ratio: f64, |
| @@ -336,7 +330,7 @@ impl State { | |||
| 336 | } | 330 | } |
| 337 | 331 | ||
| 338 | fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) { | 332 | fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) { |
| 339 | - let comp_mod = self.backend.mod_key(); | 333 | + let mod_key = self.backend.mod_key(&self.niri.config.borrow()); |
| 340 | 334 | ||
| 341 | let serial = SERIAL_COUNTER.next_serial(); | 335 | let serial = SERIAL_COUNTER.next_serial(); |
| 342 | let time = Event::time_msec(&event); | 336 | let time = Event::time_msec(&event); |
| @@ -399,7 +393,7 @@ impl State { | |||
| 399 | should_intercept_key( | 393 | should_intercept_key( |
| 400 | &mut this.niri.suppressed_keys, | 394 | &mut this.niri.suppressed_keys, |
| 401 | bindings, | 395 | bindings, |
| 402 | - comp_mod, | 396 | + mod_key, |
| 403 | key_code, | 397 | key_code, |
| 404 | modified, | 398 | modified, |
| 405 | raw, | 399 | raw, |
| @@ -2118,6 +2112,8 @@ impl State { | |||
| 2118 | 2112 | ||
| 2119 | let button_state = event.state(); | 2113 | let button_state = event.state(); |
| 2120 | 2114 | ||
| 2115 | + let mod_key = self.backend.mod_key(&self.niri.config.borrow()); | ||
| 2116 | + | ||
| 2121 | // Ignore release events for mouse clicks that triggered a bind. | 2117 | // Ignore release events for mouse clicks that triggered a bind. |
| 2122 | if self.niri.suppressed_buttons.remove(&button_code) { | 2118 | if self.niri.suppressed_buttons.remove(&button_code) { |
| 2123 | return; | 2119 | return; |
| @@ -2128,8 +2124,6 @@ impl State { | |||
| 2128 | let modifiers = modifiers_from_state(mods); | 2124 | let modifiers = modifiers_from_state(mods); |
| 2129 | 2125 | ||
| 2130 | if self.niri.mods_with_mouse_binds.contains(&modifiers) { | 2126 | if self.niri.mods_with_mouse_binds.contains(&modifiers) { |
| 2131 | - let comp_mod = self.backend.mod_key(); | ||
| 2132 | - | ||
| 2133 | if let Some(bind) = match button { | 2127 | if let Some(bind) = match button { |
| 2134 | Some(MouseButton::Left) => Some(Trigger::MouseLeft), | 2128 | Some(MouseButton::Left) => Some(Trigger::MouseLeft), |
| 2135 | Some(MouseButton::Right) => Some(Trigger::MouseRight), | 2129 | Some(MouseButton::Right) => Some(Trigger::MouseRight), |
| @@ -2141,7 +2135,7 @@ impl State { | |||
| 2141 | .and_then(|trigger| { | 2135 | .and_then(|trigger| { |
| 2142 | let config = self.niri.config.borrow(); | 2136 | let config = self.niri.config.borrow(); |
| 2143 | let bindings = &config.binds; | 2137 | let bindings = &config.binds; |
| 2144 | - find_configured_bind(bindings, comp_mod, trigger, mods) | 2138 | + find_configured_bind(bindings, mod_key, trigger, mods) |
| 2145 | }) { | 2139 | }) { |
| 2146 | self.niri.suppressed_buttons.insert(button_code); | 2140 | self.niri.suppressed_buttons.insert(button_code); |
| 2147 | self.handle_bind(bind.clone()); | 2141 | self.handle_bind(bind.clone()); |
| @@ -2154,10 +2148,7 @@ impl State { | |||
| 2154 | self.niri.tablet_cursor_location = None; | 2148 | self.niri.tablet_cursor_location = None; |
| 2155 | 2149 | ||
| 2156 | if button == Some(MouseButton::Middle) && !pointer.is_grabbed() { | 2150 | if button == Some(MouseButton::Middle) && !pointer.is_grabbed() { |
| 2157 | - let mod_down = match self.backend.mod_key() { | 2151 | + let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers()); |
| 2158 | - CompositorMod::Super => mods.logo, | ||
| 2159 | - CompositorMod::Alt => mods.alt, | ||
| 2160 | - }; | ||
| 2161 | if mod_down { | 2152 | if mod_down { |
| 2162 | if let Some(output) = self.niri.output_under_cursor() { | 2153 | if let Some(output) = self.niri.output_under_cursor() { |
| 2163 | self.niri.layout.activate_output(&output); | 2154 | self.niri.layout.activate_output(&output); |
| @@ -2189,10 +2180,7 @@ impl State { | |||
| 2189 | 2180 | ||
| 2190 | // Check if we need to start an interactive move. | 2181 | // Check if we need to start an interactive move. |
| 2191 | if button == Some(MouseButton::Left) && !pointer.is_grabbed() { | 2182 | if button == Some(MouseButton::Left) && !pointer.is_grabbed() { |
| 2192 | - let mod_down = match self.backend.mod_key() { | 2183 | + let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers()); |
| 2193 | - CompositorMod::Super => mods.logo, | ||
| 2194 | - CompositorMod::Alt => mods.alt, | ||
| 2195 | - }; | ||
| 2196 | if mod_down { | 2184 | if mod_down { |
| 2197 | let location = pointer.current_location(); | 2185 | let location = pointer.current_location(); |
| 2198 | let (output, pos_within_output) = self.niri.output_under(location).unwrap(); | 2186 | let (output, pos_within_output) = self.niri.output_under(location).unwrap(); |
| @@ -2220,10 +2208,7 @@ impl State { | |||
| 2220 | } | 2208 | } |
| 2221 | // Check if we need to start an interactive resize. | 2209 | // Check if we need to start an interactive resize. |
| 2222 | else if button == Some(MouseButton::Right) && !pointer.is_grabbed() { | 2210 | else if button == Some(MouseButton::Right) && !pointer.is_grabbed() { |
| 2223 | - let mod_down = match self.backend.mod_key() { | 2211 | + let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers()); |
| 2224 | - CompositorMod::Super => mods.logo, | ||
| 2225 | - CompositorMod::Alt => mods.alt, | ||
| 2226 | - }; | ||
| 2227 | if mod_down { | 2212 | if mod_down { |
| 2228 | let location = pointer.current_location(); | 2213 | let location = pointer.current_location(); |
| 2229 | let (output, pos_within_output) = self.niri.output_under(location).unwrap(); | 2214 | let (output, pos_within_output) = self.niri.output_under(location).unwrap(); |
| @@ -2353,6 +2338,8 @@ impl State { | |||
| 2353 | 2338 | ||
| 2354 | let source = event.source(); | 2339 | let source = event.source(); |
| 2355 | 2340 | ||
| 2341 | + let mod_key = self.backend.mod_key(&self.niri.config.borrow()); | ||
| 2342 | + | ||
| 2356 | // We received an event for the regular pointer, so show it now. This is also needed for | 2343 | // We received an event for the regular pointer, so show it now. This is also needed for |
| 2357 | // update_pointer_contents() below to return the real contents, necessary for the pointer | 2344 | // update_pointer_contents() below to return the real contents, necessary for the pointer |
| 2358 | // axis event to reach the window. | 2345 | // axis event to reach the window. |
| @@ -2369,17 +2356,15 @@ impl State { | |||
| 2369 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | 2356 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); |
| 2370 | let modifiers = modifiers_from_state(mods); | 2357 | let modifiers = modifiers_from_state(mods); |
| 2371 | if self.niri.mods_with_wheel_binds.contains(&modifiers) { | 2358 | if self.niri.mods_with_wheel_binds.contains(&modifiers) { |
| 2372 | - let comp_mod = self.backend.mod_key(); | ||
| 2373 | - | ||
| 2374 | let horizontal = horizontal_amount_v120.unwrap_or(0.); | 2359 | let horizontal = horizontal_amount_v120.unwrap_or(0.); |
| 2375 | let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal); | 2360 | let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal); |
| 2376 | if ticks != 0 { | 2361 | if ticks != 0 { |
| 2377 | let config = self.niri.config.borrow(); | 2362 | let config = self.niri.config.borrow(); |
| 2378 | let bindings = &config.binds; | 2363 | let bindings = &config.binds; |
| 2379 | let bind_left = | 2364 | let bind_left = |
| 2380 | - find_configured_bind(bindings, comp_mod, Trigger::WheelScrollLeft, mods); | 2365 | + find_configured_bind(bindings, mod_key, Trigger::WheelScrollLeft, mods); |
| 2381 | let bind_right = | 2366 | let bind_right = |
| 2382 | - find_configured_bind(bindings, comp_mod, Trigger::WheelScrollRight, mods); | 2367 | + find_configured_bind(bindings, mod_key, Trigger::WheelScrollRight, mods); |
| 2383 | drop(config); | 2368 | drop(config); |
| 2384 | 2369 | ||
| 2385 | if let Some(right) = bind_right { | 2370 | if let Some(right) = bind_right { |
| @@ -2400,9 +2385,9 @@ impl State { | |||
| 2400 | let config = self.niri.config.borrow(); | 2385 | let config = self.niri.config.borrow(); |
| 2401 | let bindings = &config.binds; | 2386 | let bindings = &config.binds; |
| 2402 | let bind_up = | 2387 | let bind_up = |
| 2403 | - find_configured_bind(bindings, comp_mod, Trigger::WheelScrollUp, mods); | 2388 | + find_configured_bind(bindings, mod_key, Trigger::WheelScrollUp, mods); |
| 2404 | let bind_down = | 2389 | let bind_down = |
| 2405 | - find_configured_bind(bindings, comp_mod, Trigger::WheelScrollDown, mods); | 2390 | + find_configured_bind(bindings, mod_key, Trigger::WheelScrollDown, mods); |
| 2406 | drop(config); | 2391 | drop(config); |
| 2407 | 2392 | ||
| 2408 | if let Some(down) = bind_down { | 2393 | if let Some(down) = bind_down { |
| @@ -2432,8 +2417,6 @@ impl State { | |||
| 2432 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | 2417 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); |
| 2433 | let modifiers = modifiers_from_state(mods); | 2418 | let modifiers = modifiers_from_state(mods); |
| 2434 | if self.niri.mods_with_finger_scroll_binds.contains(&modifiers) { | 2419 | if self.niri.mods_with_finger_scroll_binds.contains(&modifiers) { |
| 2435 | - let comp_mod = self.backend.mod_key(); | ||
| 2436 | - | ||
| 2437 | let horizontal = horizontal_amount.unwrap_or(0.); | 2420 | let horizontal = horizontal_amount.unwrap_or(0.); |
| 2438 | let ticks = self | 2421 | let ticks = self |
| 2439 | .niri | 2422 | .niri |
| @@ -2443,13 +2426,9 @@ impl State { | |||
| 2443 | let config = self.niri.config.borrow(); | 2426 | let config = self.niri.config.borrow(); |
| 2444 | let bindings = &config.binds; | 2427 | let bindings = &config.binds; |
| 2445 | let bind_left = | 2428 | let bind_left = |
| 2446 | - find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollLeft, mods); | 2429 | + find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollLeft, mods); |
| 2447 | - let bind_right = find_configured_bind( | 2430 | + let bind_right = |
| 2448 | - bindings, | 2431 | + find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollRight, mods); |
| 2449 | - comp_mod, | ||
| 2450 | - Trigger::TouchpadScrollRight, | ||
| 2451 | - mods, | ||
| 2452 | - ); | ||
| 2453 | drop(config); | 2432 | drop(config); |
| 2454 | 2433 | ||
| 2455 | if let Some(right) = bind_right { | 2434 | if let Some(right) = bind_right { |
| @@ -2473,9 +2452,9 @@ impl State { | |||
| 2473 | let config = self.niri.config.borrow(); | 2452 | let config = self.niri.config.borrow(); |
| 2474 | let bindings = &config.binds; | 2453 | let bindings = &config.binds; |
| 2475 | let bind_up = | 2454 | let bind_up = |
| 2476 | - find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollUp, mods); | 2455 | + find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollUp, mods); |
| 2477 | let bind_down = | 2456 | let bind_down = |
| 2478 | - find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollDown, mods); | 2457 | + find_configured_bind(bindings, mod_key, Trigger::TouchpadScrollDown, mods); |
| 2479 | drop(config); | 2458 | drop(config); |
| 2480 | 2459 | ||
| 2481 | if let Some(down) = bind_down { | 2460 | if let Some(down) = bind_down { |
| @@ -2987,16 +2966,15 @@ impl State { | |||
| 2987 | 2966 | ||
| 2988 | let under = self.niri.contents_under(touch_location); | 2967 | let under = self.niri.contents_under(touch_location); |
| 2989 | 2968 | ||
| 2969 | + let mod_key = self.backend.mod_key(&self.niri.config.borrow()); | ||
| 2970 | + | ||
| 2990 | if !handle.is_grabbed() { | 2971 | if !handle.is_grabbed() { |
| 2991 | if let Some((window, _)) = under.window { | 2972 | if let Some((window, _)) = under.window { |
| 2992 | self.niri.layout.activate_window(&window); | 2973 | self.niri.layout.activate_window(&window); |
| 2993 | 2974 | ||
| 2994 | // Check if we need to start an interactive move. | 2975 | // Check if we need to start an interactive move. |
| 2995 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | 2976 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); |
| 2996 | - let mod_down = match self.backend.mod_key() { | 2977 | + let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers()); |
| 2997 | - CompositorMod::Super => mods.logo, | ||
| 2998 | - CompositorMod::Alt => mods.alt, | ||
| 2999 | - }; | ||
| 3000 | if mod_down { | 2978 | if mod_down { |
| 3001 | let (output, pos_within_output) = | 2979 | let (output, pos_within_output) = |
| 3002 | self.niri.output_under(touch_location).unwrap(); | 2980 | self.niri.output_under(touch_location).unwrap(); |
| @@ -3129,7 +3107,7 @@ impl State { | |||
| 3129 | fn should_intercept_key( | 3107 | fn should_intercept_key( |
| 3130 | suppressed_keys: &mut HashSet<Keycode>, | 3108 | suppressed_keys: &mut HashSet<Keycode>, |
| 3131 | bindings: &Binds, | 3109 | bindings: &Binds, |
| 3132 | - comp_mod: CompositorMod, | 3110 | + mod_key: ModKey, |
| 3133 | key_code: Keycode, | 3111 | key_code: Keycode, |
| 3134 | modified: Keysym, | 3112 | modified: Keysym, |
| 3135 | raw: Option<Keysym>, | 3113 | raw: Option<Keysym>, |
| @@ -3148,7 +3126,7 @@ fn should_intercept_key( | |||
| 3148 | 3126 | ||
| 3149 | let mut final_bind = find_bind( | 3127 | let mut final_bind = find_bind( |
| 3150 | bindings, | 3128 | bindings, |
| 3151 | - comp_mod, | 3129 | + mod_key, |
| 3152 | modified, | 3130 | modified, |
| 3153 | raw, | 3131 | raw, |
| 3154 | mods, | 3132 | mods, |
| @@ -3212,7 +3190,7 @@ fn should_intercept_key( | |||
| 3212 | 3190 | ||
| 3213 | fn find_bind( | 3191 | fn find_bind( |
| 3214 | bindings: &Binds, | 3192 | bindings: &Binds, |
| 3215 | - comp_mod: CompositorMod, | 3193 | + mod_key: ModKey, |
| 3216 | modified: Keysym, | 3194 | modified: Keysym, |
| 3217 | raw: Option<Keysym>, | 3195 | raw: Option<Keysym>, |
| 3218 | mods: ModifiersState, | 3196 | mods: ModifiersState, |
| @@ -3253,22 +3231,19 @@ fn find_bind( | |||
| 3253 | } | 3231 | } |
| 3254 | 3232 | ||
| 3255 | let trigger = Trigger::Keysym(raw?); | 3233 | let trigger = Trigger::Keysym(raw?); |
| 3256 | - find_configured_bind(bindings, comp_mod, trigger, mods) | 3234 | + find_configured_bind(bindings, mod_key, trigger, mods) |
| 3257 | } | 3235 | } |
| 3258 | 3236 | ||
| 3259 | fn find_configured_bind( | 3237 | fn find_configured_bind( |
| 3260 | bindings: &Binds, | 3238 | bindings: &Binds, |
| 3261 | - comp_mod: CompositorMod, | 3239 | + mod_key: ModKey, |
| 3262 | trigger: Trigger, | 3240 | trigger: Trigger, |
| 3263 | mods: ModifiersState, | 3241 | mods: ModifiersState, |
| 3264 | ) -> Option<Bind> { | 3242 | ) -> Option<Bind> { |
| 3265 | // Handle configured binds. | 3243 | // Handle configured binds. |
| 3266 | let mut modifiers = modifiers_from_state(mods); | 3244 | let mut modifiers = modifiers_from_state(mods); |
| 3267 | 3245 | ||
| 3268 | - let (mod_down, comp_mod) = match comp_mod { | 3246 | + let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers()); |
| 3269 | - CompositorMod::Super => (mods.logo, Modifiers::SUPER), | ||
| 3270 | - CompositorMod::Alt => (mods.alt, Modifiers::ALT), | ||
| 3271 | - }; | ||
| 3272 | if mod_down { | 3247 | if mod_down { |
| 3273 | modifiers |= Modifiers::COMPOSITOR; | 3248 | modifiers |= Modifiers::COMPOSITOR; |
| 3274 | } | 3249 | } |
| @@ -3280,8 +3255,8 @@ fn find_configured_bind( | |||
| 3280 | 3255 | ||
| 3281 | let mut bind_modifiers = bind.key.modifiers; | 3256 | let mut bind_modifiers = bind.key.modifiers; |
| 3282 | if bind_modifiers.contains(Modifiers::COMPOSITOR) { | 3257 | if bind_modifiers.contains(Modifiers::COMPOSITOR) { |
| 3283 | - bind_modifiers |= comp_mod; | 3258 | + bind_modifiers |= mod_key.to_modifiers(); |
| 3284 | - } else if bind_modifiers.contains(comp_mod) { | 3259 | + } else if bind_modifiers.contains(mod_key.to_modifiers()) { |
| 3285 | bind_modifiers |= Modifiers::COMPOSITOR; | 3260 | bind_modifiers |= Modifiers::COMPOSITOR; |
| 3286 | } | 3261 | } |
| 3287 | 3262 | ||
| @@ -3661,16 +3636,7 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 3661 | } | 3636 | } |
| 3662 | } | 3637 | } |
| 3663 | 3638 | ||
| 3664 | -pub fn mods_with_binds( | 3639 | +pub fn mods_with_binds(mod_key: ModKey, binds: &Binds, triggers: &[Trigger]) -> HashSet<Modifiers> { |
| 3665 | - comp_mod: CompositorMod, | ||
| 3666 | - binds: &Binds, | ||
| 3667 | - triggers: &[Trigger], | ||
| 3668 | -) -> HashSet<Modifiers> { | ||
| 3669 | - let comp_mod = match comp_mod { | ||
| 3670 | - CompositorMod::Super => Modifiers::SUPER, | ||
| 3671 | - CompositorMod::Alt => Modifiers::ALT, | ||
| 3672 | - }; | ||
| 3673 | - | ||
| 3674 | let mut rv = HashSet::new(); | 3640 | let mut rv = HashSet::new(); |
| 3675 | for bind in &binds.0 { | 3641 | for bind in &binds.0 { |
| 3676 | if !triggers.iter().any(|trigger| bind.key.trigger == *trigger) { | 3642 | if !triggers.iter().any(|trigger| bind.key.trigger == *trigger) { |
| @@ -3680,7 +3646,7 @@ pub fn mods_with_binds( | |||
| 3680 | let mut mods = bind.key.modifiers; | 3646 | let mut mods = bind.key.modifiers; |
| 3681 | if mods.contains(Modifiers::COMPOSITOR) { | 3647 | if mods.contains(Modifiers::COMPOSITOR) { |
| 3682 | mods.remove(Modifiers::COMPOSITOR); | 3648 | mods.remove(Modifiers::COMPOSITOR); |
| 3683 | - mods.insert(comp_mod); | 3649 | + mods.insert(mod_key.to_modifiers()); |
| 3684 | } | 3650 | } |
| 3685 | 3651 | ||
| 3686 | rv.insert(mods); | 3652 | rv.insert(mods); |
| @@ -3689,9 +3655,9 @@ pub fn mods_with_binds( | |||
| 3689 | rv | 3655 | rv |
| 3690 | } | 3656 | } |
| 3691 | 3657 | ||
| 3692 | -pub fn mods_with_mouse_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> { | 3658 | +pub fn mods_with_mouse_binds(mod_key: ModKey, binds: &Binds) -> HashSet<Modifiers> { |
| 3693 | mods_with_binds( | 3659 | mods_with_binds( |
| 3694 | - comp_mod, | 3660 | + mod_key, |
| 3695 | binds, | 3661 | binds, |
| 3696 | &[ | 3662 | &[ |
| 3697 | Trigger::MouseLeft, | 3663 | Trigger::MouseLeft, |
| @@ -3703,9 +3669,9 @@ pub fn mods_with_mouse_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet< | |||
| 3703 | ) | 3669 | ) |
| 3704 | } | 3670 | } |
| 3705 | 3671 | ||
| 3706 | -pub fn mods_with_wheel_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> { | 3672 | +pub fn mods_with_wheel_binds(mod_key: ModKey, binds: &Binds) -> HashSet<Modifiers> { |
| 3707 | mods_with_binds( | 3673 | mods_with_binds( |
| 3708 | - comp_mod, | 3674 | + mod_key, |
| 3709 | binds, | 3675 | binds, |
| 3710 | &[ | 3676 | &[ |
| 3711 | Trigger::WheelScrollUp, | 3677 | Trigger::WheelScrollUp, |
| @@ -3716,9 +3682,9 @@ pub fn mods_with_wheel_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet< | |||
| 3716 | ) | 3682 | ) |
| 3717 | } | 3683 | } |
| 3718 | 3684 | ||
| 3719 | -pub fn mods_with_finger_scroll_binds(comp_mod: CompositorMod, binds: &Binds) -> HashSet<Modifiers> { | 3685 | +pub fn mods_with_finger_scroll_binds(mod_key: ModKey, binds: &Binds) -> HashSet<Modifiers> { |
| 3720 | mods_with_binds( | 3686 | mods_with_binds( |
| 3721 | - comp_mod, | 3687 | + mod_key, |
| 3722 | binds, | 3688 | binds, |
| 3723 | &[ | 3689 | &[ |
| 3724 | Trigger::TouchpadScrollUp, | 3690 | Trigger::TouchpadScrollUp, |
| @@ -3752,7 +3718,7 @@ mod tests { | |||
| 3752 | hotkey_overlay_title: None, | 3718 | hotkey_overlay_title: None, |
| 3753 | }]); | 3719 | }]); |
| 3754 | 3720 | ||
| 3755 | - let comp_mod = CompositorMod::Super; | 3721 | + let comp_mod = ModKey::Super; |
| 3756 | let mut suppressed_keys = HashSet::new(); | 3722 | let mut suppressed_keys = HashSet::new(); |
| 3757 | 3723 | ||
| 3758 | let screenshot_ui = ScreenshotUi::new(Clock::default(), Default::default()); | 3724 | let screenshot_ui = ScreenshotUi::new(Clock::default(), Default::default()); |
| @@ -3990,7 +3956,7 @@ mod tests { | |||
| 3990 | assert_eq!( | 3956 | assert_eq!( |
| 3991 | find_configured_bind( | 3957 | find_configured_bind( |
| 3992 | &bindings, | 3958 | &bindings, |
| 3993 | - CompositorMod::Super, | 3959 | + ModKey::Super, |
| 3994 | Trigger::Keysym(Keysym::q), | 3960 | Trigger::Keysym(Keysym::q), |
| 3995 | ModifiersState { | 3961 | ModifiersState { |
| 3996 | logo: true, | 3962 | logo: true, |
| @@ -4003,7 +3969,7 @@ mod tests { | |||
| 4003 | assert_eq!( | 3969 | assert_eq!( |
| 4004 | find_configured_bind( | 3970 | find_configured_bind( |
| 4005 | &bindings, | 3971 | &bindings, |
| 4006 | - CompositorMod::Super, | 3972 | + ModKey::Super, |
| 4007 | Trigger::Keysym(Keysym::q), | 3973 | Trigger::Keysym(Keysym::q), |
| 4008 | ModifiersState::default(), | 3974 | ModifiersState::default(), |
| 4009 | ), | 3975 | ), |
| @@ -4013,7 +3979,7 @@ mod tests { | |||
| 4013 | assert_eq!( | 3979 | assert_eq!( |
| 4014 | find_configured_bind( | 3980 | find_configured_bind( |
| 4015 | &bindings, | 3981 | &bindings, |
| 4016 | - CompositorMod::Super, | 3982 | + ModKey::Super, |
| 4017 | Trigger::Keysym(Keysym::h), | 3983 | Trigger::Keysym(Keysym::h), |
| 4018 | ModifiersState { | 3984 | ModifiersState { |
| 4019 | logo: true, | 3985 | logo: true, |
| @@ -4026,7 +3992,7 @@ mod tests { | |||
| 4026 | assert_eq!( | 3992 | assert_eq!( |
| 4027 | find_configured_bind( | 3993 | find_configured_bind( |
| 4028 | &bindings, | 3994 | &bindings, |
| 4029 | - CompositorMod::Super, | 3995 | + ModKey::Super, |
| 4030 | Trigger::Keysym(Keysym::h), | 3996 | Trigger::Keysym(Keysym::h), |
| 4031 | ModifiersState::default(), | 3997 | ModifiersState::default(), |
| 4032 | ), | 3998 | ), |
| @@ -4036,7 +4002,7 @@ mod tests { | |||
| 4036 | assert_eq!( | 4002 | assert_eq!( |
| 4037 | find_configured_bind( | 4003 | find_configured_bind( |
| 4038 | &bindings, | 4004 | &bindings, |
| 4039 | - CompositorMod::Super, | 4005 | + ModKey::Super, |
| 4040 | Trigger::Keysym(Keysym::j), | 4006 | Trigger::Keysym(Keysym::j), |
| 4041 | ModifiersState { | 4007 | ModifiersState { |
| 4042 | logo: true, | 4008 | logo: true, |
| @@ -4048,7 +4014,7 @@ mod tests { | |||
| 4048 | assert_eq!( | 4014 | assert_eq!( |
| 4049 | find_configured_bind( | 4015 | find_configured_bind( |
| 4050 | &bindings, | 4016 | &bindings, |
| 4051 | - CompositorMod::Super, | 4017 | + ModKey::Super, |
| 4052 | Trigger::Keysym(Keysym::j), | 4018 | Trigger::Keysym(Keysym::j), |
| 4053 | ModifiersState::default(), | 4019 | ModifiersState::default(), |
| 4054 | ) | 4020 | ) |
| @@ -4059,7 +4025,7 @@ mod tests { | |||
| 4059 | assert_eq!( | 4025 | assert_eq!( |
| 4060 | find_configured_bind( | 4026 | find_configured_bind( |
| 4061 | &bindings, | 4027 | &bindings, |
| 4062 | - CompositorMod::Super, | 4028 | + ModKey::Super, |
| 4063 | Trigger::Keysym(Keysym::k), | 4029 | Trigger::Keysym(Keysym::k), |
| 4064 | ModifiersState { | 4030 | ModifiersState { |
| 4065 | logo: true, | 4031 | logo: true, |
| @@ -4072,7 +4038,7 @@ mod tests { | |||
| 4072 | assert_eq!( | 4038 | assert_eq!( |
| 4073 | find_configured_bind( | 4039 | find_configured_bind( |
| 4074 | &bindings, | 4040 | &bindings, |
| 4075 | - CompositorMod::Super, | 4041 | + ModKey::Super, |
| 4076 | Trigger::Keysym(Keysym::k), | 4042 | Trigger::Keysym(Keysym::k), |
| 4077 | ModifiersState::default(), | 4043 | ModifiersState::default(), |
| 4078 | ), | 4044 | ), |
| @@ -4082,7 +4048,7 @@ mod tests { | |||
| 4082 | assert_eq!( | 4048 | assert_eq!( |
| 4083 | find_configured_bind( | 4049 | find_configured_bind( |
| 4084 | &bindings, | 4050 | &bindings, |
| 4085 | - CompositorMod::Super, | 4051 | + ModKey::Super, |
| 4086 | Trigger::Keysym(Keysym::l), | 4052 | Trigger::Keysym(Keysym::l), |
| 4087 | ModifiersState { | 4053 | ModifiersState { |
| 4088 | logo: true, | 4054 | logo: true, |
| @@ -4096,7 +4062,7 @@ mod tests { | |||
| 4096 | assert_eq!( | 4062 | assert_eq!( |
| 4097 | find_configured_bind( | 4063 | find_configured_bind( |
| 4098 | &bindings, | 4064 | &bindings, |
| 4099 | - CompositorMod::Super, | 4065 | + ModKey::Super, |
| 4100 | Trigger::Keysym(Keysym::l), | 4066 | Trigger::Keysym(Keysym::l), |
| 4101 | ModifiersState { | 4067 | ModifiersState { |
| 4102 | logo: true, | 4068 | logo: true, |
src/niri.rsmodified+13 -12
| @@ -1247,14 +1247,15 @@ impl State { | |||
| 1247 | preserved_output_config = Some(mem::take(&mut old_config.outputs)); | 1247 | preserved_output_config = Some(mem::take(&mut old_config.outputs)); |
| 1248 | } | 1248 | } |
| 1249 | 1249 | ||
| 1250 | - if config.binds != old_config.binds { | 1250 | + let new_mod_key = self.backend.mod_key(&config); |
| 1251 | - self.niri.hotkey_overlay.on_hotkey_config_updated(); | 1251 | + if new_mod_key != self.backend.mod_key(&old_config) || config.binds != old_config.binds { |
| 1252 | - self.niri.mods_with_mouse_binds = | 1252 | + self.niri |
| 1253 | - mods_with_mouse_binds(self.backend.mod_key(), &config.binds); | 1253 | + .hotkey_overlay |
| 1254 | - self.niri.mods_with_wheel_binds = | 1254 | + .on_hotkey_config_updated(new_mod_key); |
| 1255 | - mods_with_wheel_binds(self.backend.mod_key(), &config.binds); | 1255 | + self.niri.mods_with_mouse_binds = mods_with_mouse_binds(new_mod_key, &config.binds); |
| 1256 | + self.niri.mods_with_wheel_binds = mods_with_wheel_binds(new_mod_key, &config.binds); | ||
| 1256 | self.niri.mods_with_finger_scroll_binds = | 1257 | self.niri.mods_with_finger_scroll_binds = |
| 1257 | - mods_with_finger_scroll_binds(self.backend.mod_key(), &config.binds); | 1258 | + mods_with_finger_scroll_binds(new_mod_key, &config.binds); |
| 1258 | } | 1259 | } |
| 1259 | 1260 | ||
| 1260 | if config.window_rules != old_config.window_rules { | 1261 | if config.window_rules != old_config.window_rules { |
| @@ -2135,16 +2136,16 @@ impl Niri { | |||
| 2135 | let cursor_manager = | 2136 | let cursor_manager = |
| 2136 | CursorManager::new(&config_.cursor.xcursor_theme, config_.cursor.xcursor_size); | 2137 | CursorManager::new(&config_.cursor.xcursor_theme, config_.cursor.xcursor_size); |
| 2137 | 2138 | ||
| 2138 | - let mods_with_mouse_binds = mods_with_mouse_binds(backend.mod_key(), &config_.binds); | 2139 | + let mod_key = backend.mod_key(&config.borrow()); |
| 2139 | - let mods_with_wheel_binds = mods_with_wheel_binds(backend.mod_key(), &config_.binds); | 2140 | + let mods_with_mouse_binds = mods_with_mouse_binds(mod_key, &config_.binds); |
| 2140 | - let mods_with_finger_scroll_binds = | 2141 | + let mods_with_wheel_binds = mods_with_wheel_binds(mod_key, &config_.binds); |
| 2141 | - mods_with_finger_scroll_binds(backend.mod_key(), &config_.binds); | 2142 | + let mods_with_finger_scroll_binds = mods_with_finger_scroll_binds(mod_key, &config_.binds); |
| 2142 | 2143 | ||
| 2143 | let screenshot_ui = ScreenshotUi::new(animation_clock.clone(), config.clone()); | 2144 | let screenshot_ui = ScreenshotUi::new(animation_clock.clone(), config.clone()); |
| 2144 | let config_error_notification = | 2145 | let config_error_notification = |
| 2145 | ConfigErrorNotification::new(animation_clock.clone(), config.clone()); | 2146 | ConfigErrorNotification::new(animation_clock.clone(), config.clone()); |
| 2146 | 2147 | ||
| 2147 | - let mut hotkey_overlay = HotkeyOverlay::new(config.clone(), backend.mod_key()); | 2148 | + let mut hotkey_overlay = HotkeyOverlay::new(config.clone(), mod_key); |
| 2148 | if !config_.hotkey_overlay.skip_at_startup { | 2149 | if !config_.hotkey_overlay.skip_at_startup { |
| 2149 | hotkey_overlay.show(); | 2150 | hotkey_overlay.show(); |
| 2150 | } | 2151 | } |
src/ui/hotkey_overlay.rsmodified+42 -29
| @@ -4,7 +4,7 @@ use std::collections::HashMap; | |||
| 4 | use std::iter::zip; | 4 | use std::iter::zip; |
| 5 | use std::rc::Rc; | 5 | use std::rc::Rc; |
| 6 | 6 | ||
| 7 | -use niri_config::{Action, Bind, Config, Key, Modifiers, Trigger}; | 7 | +use niri_config::{Action, Bind, Config, Key, ModKey, Modifiers, Trigger}; |
| 8 | use pangocairo::cairo::{self, ImageSurface}; | 8 | use pangocairo::cairo::{self, ImageSurface}; |
| 9 | use pangocairo::pango::{AttrColor, AttrInt, AttrList, AttrString, FontDescription, Weight}; | 9 | use pangocairo::pango::{AttrColor, AttrInt, AttrList, AttrString, FontDescription, Weight}; |
| 10 | use smithay::backend::renderer::element::Kind; | 10 | use smithay::backend::renderer::element::Kind; |
| @@ -14,7 +14,6 @@ use smithay::output::{Output, WeakOutput}; | |||
| 14 | use smithay::reexports::gbm::Format as Fourcc; | 14 | use smithay::reexports::gbm::Format as Fourcc; |
| 15 | use smithay::utils::{Scale, Transform}; | 15 | use smithay::utils::{Scale, Transform}; |
| 16 | 16 | ||
| 17 | -use crate::input::CompositorMod; | ||
| 18 | use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; | 17 | use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; |
| 19 | use crate::render_helpers::renderer::NiriRenderer; | 18 | use crate::render_helpers::renderer::NiriRenderer; |
| 20 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; | 19 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; |
| @@ -30,7 +29,7 @@ const TITLE: &str = "Important Hotkeys"; | |||
| 30 | pub struct HotkeyOverlay { | 29 | pub struct HotkeyOverlay { |
| 31 | is_open: bool, | 30 | is_open: bool, |
| 32 | config: Rc<RefCell<Config>>, | 31 | config: Rc<RefCell<Config>>, |
| 33 | - comp_mod: CompositorMod, | 32 | + mod_key: ModKey, |
| 34 | buffers: RefCell<HashMap<WeakOutput, RenderedOverlay>>, | 33 | buffers: RefCell<HashMap<WeakOutput, RenderedOverlay>>, |
| 35 | } | 34 | } |
| 36 | 35 | ||
| @@ -39,11 +38,11 @@ pub struct RenderedOverlay { | |||
| 39 | } | 38 | } |
| 40 | 39 | ||
| 41 | impl HotkeyOverlay { | 40 | impl HotkeyOverlay { |
| 42 | - pub fn new(config: Rc<RefCell<Config>>, comp_mod: CompositorMod) -> Self { | 41 | + pub fn new(config: Rc<RefCell<Config>>, mod_key: ModKey) -> Self { |
| 43 | Self { | 42 | Self { |
| 44 | is_open: false, | 43 | is_open: false, |
| 45 | config, | 44 | config, |
| 46 | - comp_mod, | 45 | + mod_key, |
| 47 | buffers: RefCell::new(HashMap::new()), | 46 | buffers: RefCell::new(HashMap::new()), |
| 48 | } | 47 | } |
| 49 | } | 48 | } |
| @@ -70,7 +69,8 @@ impl HotkeyOverlay { | |||
| 70 | self.is_open | 69 | self.is_open |
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | - pub fn on_hotkey_config_updated(&mut self) { | 72 | + pub fn on_hotkey_config_updated(&mut self, mod_key: ModKey) { |
| 73 | + self.mod_key = mod_key; | ||
| 74 | self.buffers.borrow_mut().clear(); | 74 | self.buffers.borrow_mut().clear(); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| @@ -101,7 +101,7 @@ impl HotkeyOverlay { | |||
| 101 | 101 | ||
| 102 | let rendered = buffers.entry(weak).or_insert_with(|| { | 102 | let rendered = buffers.entry(weak).or_insert_with(|| { |
| 103 | let renderer = renderer.as_gles_renderer(); | 103 | let renderer = renderer.as_gles_renderer(); |
| 104 | - render(renderer, &self.config.borrow(), self.comp_mod, scale) | 104 | + render(renderer, &self.config.borrow(), self.mod_key, scale) |
| 105 | .unwrap_or_else(|_| RenderedOverlay { buffer: None }) | 105 | .unwrap_or_else(|_| RenderedOverlay { buffer: None }) |
| 106 | }); | 106 | }); |
| 107 | let buffer = rendered.buffer.as_ref()?; | 107 | let buffer = rendered.buffer.as_ref()?; |
| @@ -125,11 +125,7 @@ impl HotkeyOverlay { | |||
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | -fn format_bind( | 128 | +fn format_bind(binds: &[Bind], mod_key: ModKey, action: &Action) -> Option<(String, String)> { |
| 129 | - binds: &[Bind], | ||
| 130 | - comp_mod: CompositorMod, | ||
| 131 | - action: &Action, | ||
| 132 | -) -> Option<(String, String)> { | ||
| 133 | let mut bind_with_non_null = None; | 129 | let mut bind_with_non_null = None; |
| 134 | let mut bind_with_custom_title = None; | 130 | let mut bind_with_custom_title = None; |
| 135 | let mut found_null_title = false; | 131 | let mut found_null_title = false; |
| @@ -162,7 +158,7 @@ fn format_bind( | |||
| 162 | title = Some(custom.clone()); | 158 | title = Some(custom.clone()); |
| 163 | } | 159 | } |
| 164 | 160 | ||
| 165 | - key_name(comp_mod, &bind.key) | 161 | + key_name(mod_key, &bind.key) |
| 166 | } else { | 162 | } else { |
| 167 | String::from("(not bound)") | 163 | String::from("(not bound)") |
| 168 | }; | 164 | }; |
| @@ -174,7 +170,7 @@ fn format_bind( | |||
| 174 | fn render( | 170 | fn render( |
| 175 | renderer: &mut GlesRenderer, | 171 | renderer: &mut GlesRenderer, |
| 176 | config: &Config, | 172 | config: &Config, |
| 177 | - comp_mod: CompositorMod, | 173 | + mod_key: ModKey, |
| 178 | scale: f64, | 174 | scale: f64, |
| 179 | ) -> anyhow::Result<RenderedOverlay> { | 175 | ) -> anyhow::Result<RenderedOverlay> { |
| 180 | let _span = tracy_client::span!("hotkey_overlay::render"); | 176 | let _span = tracy_client::span!("hotkey_overlay::render"); |
| @@ -290,7 +286,7 @@ fn render( | |||
| 290 | 286 | ||
| 291 | let strings = actions | 287 | let strings = actions |
| 292 | .into_iter() | 288 | .into_iter() |
| 293 | - .filter_map(|action| format_bind(binds, comp_mod, action)) | 289 | + .filter_map(|action| format_bind(binds, mod_key, action)) |
| 294 | .collect::<Vec<_>>(); | 290 | .collect::<Vec<_>>(); |
| 295 | 291 | ||
| 296 | let mut font = FontDescription::from_string(FONT); | 292 | let mut font = FontDescription::from_string(FONT); |
| @@ -448,38 +444,55 @@ fn action_name(action: &Action) -> String { | |||
| 448 | } | 444 | } |
| 449 | } | 445 | } |
| 450 | 446 | ||
| 451 | -fn key_name(comp_mod: CompositorMod, key: &Key) -> String { | 447 | +fn key_name(mod_key: ModKey, key: &Key) -> String { |
| 452 | let mut name = String::new(); | 448 | let mut name = String::new(); |
| 453 | 449 | ||
| 454 | let has_comp_mod = key.modifiers.contains(Modifiers::COMPOSITOR); | 450 | let has_comp_mod = key.modifiers.contains(Modifiers::COMPOSITOR); |
| 455 | 451 | ||
| 456 | // Compositor mod goes first. | 452 | // Compositor mod goes first. |
| 457 | if has_comp_mod { | 453 | if has_comp_mod { |
| 458 | - if comp_mod == CompositorMod::Super { | 454 | + match mod_key { |
| 459 | - name.push_str("Super + "); | 455 | + ModKey::Super => { |
| 460 | - } else if comp_mod == CompositorMod::Alt { | 456 | + name.push_str("Super + "); |
| 461 | - name.push_str("Alt + "); | 457 | + } |
| 458 | + ModKey::Alt => { | ||
| 459 | + name.push_str("Alt + "); | ||
| 460 | + } | ||
| 461 | + ModKey::Shift => { | ||
| 462 | + name.push_str("Shift + "); | ||
| 463 | + } | ||
| 464 | + ModKey::Ctrl => { | ||
| 465 | + name.push_str("Ctrl + "); | ||
| 466 | + } | ||
| 467 | + ModKey::IsoLevel3Shift => { | ||
| 468 | + name.push_str("ISO_Level3_Shift + "); | ||
| 469 | + } | ||
| 470 | + ModKey::IsoLevel5Shift => { | ||
| 471 | + name.push_str("ISO_Level5_Shift + "); | ||
| 472 | + } | ||
| 462 | } | 473 | } |
| 463 | } | 474 | } |
| 464 | 475 | ||
| 465 | - if key.modifiers.contains(Modifiers::SUPER) | 476 | + if key.modifiers.contains(Modifiers::SUPER) && !(has_comp_mod && mod_key == ModKey::Super) { |
| 466 | - && !(has_comp_mod && comp_mod == CompositorMod::Super) | ||
| 467 | - { | ||
| 468 | name.push_str("Super + "); | 477 | name.push_str("Super + "); |
| 469 | } | 478 | } |
| 470 | - if key.modifiers.contains(Modifiers::CTRL) { | 479 | + if key.modifiers.contains(Modifiers::CTRL) && !(has_comp_mod && mod_key == ModKey::Ctrl) { |
| 471 | name.push_str("Ctrl + "); | 480 | name.push_str("Ctrl + "); |
| 472 | } | 481 | } |
| 473 | - if key.modifiers.contains(Modifiers::SHIFT) { | 482 | + if key.modifiers.contains(Modifiers::SHIFT) && !(has_comp_mod && mod_key == ModKey::Shift) { |
| 474 | name.push_str("Shift + "); | 483 | name.push_str("Shift + "); |
| 475 | } | 484 | } |
| 476 | - if key.modifiers.contains(Modifiers::ALT) && !(has_comp_mod && comp_mod == CompositorMod::Alt) { | 485 | + if key.modifiers.contains(Modifiers::ALT) && !(has_comp_mod && mod_key == ModKey::Alt) { |
| 477 | name.push_str("Alt + "); | 486 | name.push_str("Alt + "); |
| 478 | } | 487 | } |
| 479 | - if key.modifiers.contains(Modifiers::ISO_LEVEL3_SHIFT) { | 488 | + if key.modifiers.contains(Modifiers::ISO_LEVEL3_SHIFT) |
| 489 | + && !(has_comp_mod && mod_key == ModKey::IsoLevel3Shift) | ||
| 490 | + { | ||
| 480 | name.push_str("ISO_Level3_Shift + "); | 491 | name.push_str("ISO_Level3_Shift + "); |
| 481 | } | 492 | } |
| 482 | - if key.modifiers.contains(Modifiers::ISO_LEVEL5_SHIFT) { | 493 | + if key.modifiers.contains(Modifiers::ISO_LEVEL5_SHIFT) |
| 494 | + && !(has_comp_mod && mod_key == ModKey::IsoLevel5Shift) | ||
| 495 | + { | ||
| 483 | name.push_str("ISO_Level5_Shift + "); | 496 | name.push_str("ISO_Level5_Shift + "); |
| 484 | } | 497 | } |
| 485 | 498 | ||
| @@ -538,7 +551,7 @@ mod tests { | |||
| 538 | #[track_caller] | 551 | #[track_caller] |
| 539 | fn check(config: &str, action: Action) -> String { | 552 | fn check(config: &str, action: Action) -> String { |
| 540 | let config = Config::parse("test.kdl", config).unwrap(); | 553 | let config = Config::parse("test.kdl", config).unwrap(); |
| 541 | - if let Some((key, title)) = format_bind(&config.binds.0, CompositorMod::Super, &action) { | 554 | + if let Some((key, title)) = format_bind(&config.binds.0, ModKey::Super, &action) { |
| 542 | format!("{key}: {title}") | 555 | format!("{key}: {title}") |
| 543 | } else { | 556 | } else { |
| 544 | String::from("None") | 557 | String::from("None") |