config: Extract binds
Browse files at this commita03a7bd1a321ccb6eab91d1279abdb55ee1814f9Parent: 758a4c53 changed files +979 -966
- niri-config/src/binds.rs +975 -0
- niri-config/src/input.rs +2 -1
- niri-config/src/lib.rs +2 -965
niri-config/src/binds.rsadded+975 -0
| @@ -0,0 +1,975 @@ | |||
| 1 | +use std::collections::HashSet; | ||
| 2 | +use std::str::FromStr; | ||
| 3 | +use std::time::Duration; | ||
| 4 | + | ||
| 5 | +use bitflags::bitflags; | ||
| 6 | +use knuffel::errors::DecodeError; | ||
| 7 | +use miette::miette; | ||
| 8 | +use niri_ipc::{ | ||
| 9 | + ColumnDisplay, LayoutSwitchTarget, PositionChange, SizeChange, WorkspaceReferenceArg, | ||
| 10 | +}; | ||
| 11 | +use smithay::input::keyboard::keysyms::KEY_NoSymbol; | ||
| 12 | +use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE}; | ||
| 13 | +use smithay::input::keyboard::Keysym; | ||
| 14 | + | ||
| 15 | +use crate::expect_only_children; | ||
| 16 | + | ||
| 17 | +#[derive(Debug, Default, PartialEq)] | ||
| 18 | +pub struct Binds(pub Vec<Bind>); | ||
| 19 | + | ||
| 20 | +#[derive(Debug, Clone, PartialEq)] | ||
| 21 | +pub struct Bind { | ||
| 22 | + pub key: Key, | ||
| 23 | + pub action: Action, | ||
| 24 | + pub repeat: bool, | ||
| 25 | + pub cooldown: Option<Duration>, | ||
| 26 | + pub allow_when_locked: bool, | ||
| 27 | + pub allow_inhibiting: bool, | ||
| 28 | + pub hotkey_overlay_title: Option<Option<String>>, | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] | ||
| 32 | +pub struct Key { | ||
| 33 | + pub trigger: Trigger, | ||
| 34 | + pub modifiers: Modifiers, | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] | ||
| 38 | +pub enum Trigger { | ||
| 39 | + Keysym(Keysym), | ||
| 40 | + MouseLeft, | ||
| 41 | + MouseRight, | ||
| 42 | + MouseMiddle, | ||
| 43 | + MouseBack, | ||
| 44 | + MouseForward, | ||
| 45 | + WheelScrollDown, | ||
| 46 | + WheelScrollUp, | ||
| 47 | + WheelScrollLeft, | ||
| 48 | + WheelScrollRight, | ||
| 49 | + TouchpadScrollDown, | ||
| 50 | + TouchpadScrollUp, | ||
| 51 | + TouchpadScrollLeft, | ||
| 52 | + TouchpadScrollRight, | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +bitflags! { | ||
| 56 | + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| 57 | + pub struct Modifiers : u8 { | ||
| 58 | + const CTRL = 1; | ||
| 59 | + const SHIFT = 1 << 1; | ||
| 60 | + const ALT = 1 << 2; | ||
| 61 | + const SUPER = 1 << 3; | ||
| 62 | + const ISO_LEVEL3_SHIFT = 1 << 4; | ||
| 63 | + const ISO_LEVEL5_SHIFT = 1 << 5; | ||
| 64 | + const COMPOSITOR = 1 << 6; | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] | ||
| 69 | +pub struct SwitchBinds { | ||
| 70 | + #[knuffel(child)] | ||
| 71 | + pub lid_open: Option<SwitchAction>, | ||
| 72 | + #[knuffel(child)] | ||
| 73 | + pub lid_close: Option<SwitchAction>, | ||
| 74 | + #[knuffel(child)] | ||
| 75 | + pub tablet_mode_on: Option<SwitchAction>, | ||
| 76 | + #[knuffel(child)] | ||
| 77 | + pub tablet_mode_off: Option<SwitchAction>, | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +#[derive(knuffel::Decode, Debug, Clone, PartialEq)] | ||
| 81 | +pub struct SwitchAction { | ||
| 82 | + #[knuffel(child, unwrap(arguments))] | ||
| 83 | + pub spawn: Vec<String>, | ||
| 84 | +} | ||
| 85 | + | ||
| 86 | +// Remember to add new actions to the CLI enum too. | ||
| 87 | +#[derive(knuffel::Decode, Debug, Clone, PartialEq)] | ||
| 88 | +pub enum Action { | ||
| 89 | + Quit(#[knuffel(property(name = "skip-confirmation"), default)] bool), | ||
| 90 | + #[knuffel(skip)] | ||
| 91 | + ChangeVt(i32), | ||
| 92 | + Suspend, | ||
| 93 | + PowerOffMonitors, | ||
| 94 | + PowerOnMonitors, | ||
| 95 | + ToggleDebugTint, | ||
| 96 | + DebugToggleOpaqueRegions, | ||
| 97 | + DebugToggleDamage, | ||
| 98 | + Spawn(#[knuffel(arguments)] Vec<String>), | ||
| 99 | + SpawnSh(#[knuffel(argument)] String), | ||
| 100 | + DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option<u16>), | ||
| 101 | + #[knuffel(skip)] | ||
| 102 | + ConfirmScreenshot { | ||
| 103 | + write_to_disk: bool, | ||
| 104 | + }, | ||
| 105 | + #[knuffel(skip)] | ||
| 106 | + CancelScreenshot, | ||
| 107 | + #[knuffel(skip)] | ||
| 108 | + ScreenshotTogglePointer, | ||
| 109 | + Screenshot(#[knuffel(property(name = "show-pointer"), default = true)] bool), | ||
| 110 | + ScreenshotScreen( | ||
| 111 | + #[knuffel(property(name = "write-to-disk"), default = true)] bool, | ||
| 112 | + #[knuffel(property(name = "show-pointer"), default = true)] bool, | ||
| 113 | + ), | ||
| 114 | + ScreenshotWindow(#[knuffel(property(name = "write-to-disk"), default = true)] bool), | ||
| 115 | + #[knuffel(skip)] | ||
| 116 | + ScreenshotWindowById { | ||
| 117 | + id: u64, | ||
| 118 | + write_to_disk: bool, | ||
| 119 | + }, | ||
| 120 | + ToggleKeyboardShortcutsInhibit, | ||
| 121 | + CloseWindow, | ||
| 122 | + #[knuffel(skip)] | ||
| 123 | + CloseWindowById(u64), | ||
| 124 | + FullscreenWindow, | ||
| 125 | + #[knuffel(skip)] | ||
| 126 | + FullscreenWindowById(u64), | ||
| 127 | + ToggleWindowedFullscreen, | ||
| 128 | + #[knuffel(skip)] | ||
| 129 | + ToggleWindowedFullscreenById(u64), | ||
| 130 | + #[knuffel(skip)] | ||
| 131 | + FocusWindow(u64), | ||
| 132 | + FocusWindowInColumn(#[knuffel(argument)] u8), | ||
| 133 | + FocusWindowPrevious, | ||
| 134 | + FocusColumnLeft, | ||
| 135 | + #[knuffel(skip)] | ||
| 136 | + FocusColumnLeftUnderMouse, | ||
| 137 | + FocusColumnRight, | ||
| 138 | + #[knuffel(skip)] | ||
| 139 | + FocusColumnRightUnderMouse, | ||
| 140 | + FocusColumnFirst, | ||
| 141 | + FocusColumnLast, | ||
| 142 | + FocusColumnRightOrFirst, | ||
| 143 | + FocusColumnLeftOrLast, | ||
| 144 | + FocusColumn(#[knuffel(argument)] usize), | ||
| 145 | + FocusWindowOrMonitorUp, | ||
| 146 | + FocusWindowOrMonitorDown, | ||
| 147 | + FocusColumnOrMonitorLeft, | ||
| 148 | + FocusColumnOrMonitorRight, | ||
| 149 | + FocusWindowDown, | ||
| 150 | + FocusWindowUp, | ||
| 151 | + FocusWindowDownOrColumnLeft, | ||
| 152 | + FocusWindowDownOrColumnRight, | ||
| 153 | + FocusWindowUpOrColumnLeft, | ||
| 154 | + FocusWindowUpOrColumnRight, | ||
| 155 | + FocusWindowOrWorkspaceDown, | ||
| 156 | + FocusWindowOrWorkspaceUp, | ||
| 157 | + FocusWindowTop, | ||
| 158 | + FocusWindowBottom, | ||
| 159 | + FocusWindowDownOrTop, | ||
| 160 | + FocusWindowUpOrBottom, | ||
| 161 | + MoveColumnLeft, | ||
| 162 | + MoveColumnRight, | ||
| 163 | + MoveColumnToFirst, | ||
| 164 | + MoveColumnToLast, | ||
| 165 | + MoveColumnLeftOrToMonitorLeft, | ||
| 166 | + MoveColumnRightOrToMonitorRight, | ||
| 167 | + MoveColumnToIndex(#[knuffel(argument)] usize), | ||
| 168 | + MoveWindowDown, | ||
| 169 | + MoveWindowUp, | ||
| 170 | + MoveWindowDownOrToWorkspaceDown, | ||
| 171 | + MoveWindowUpOrToWorkspaceUp, | ||
| 172 | + ConsumeOrExpelWindowLeft, | ||
| 173 | + #[knuffel(skip)] | ||
| 174 | + ConsumeOrExpelWindowLeftById(u64), | ||
| 175 | + ConsumeOrExpelWindowRight, | ||
| 176 | + #[knuffel(skip)] | ||
| 177 | + ConsumeOrExpelWindowRightById(u64), | ||
| 178 | + ConsumeWindowIntoColumn, | ||
| 179 | + ExpelWindowFromColumn, | ||
| 180 | + SwapWindowLeft, | ||
| 181 | + SwapWindowRight, | ||
| 182 | + ToggleColumnTabbedDisplay, | ||
| 183 | + SetColumnDisplay(#[knuffel(argument, str)] ColumnDisplay), | ||
| 184 | + CenterColumn, | ||
| 185 | + CenterWindow, | ||
| 186 | + #[knuffel(skip)] | ||
| 187 | + CenterWindowById(u64), | ||
| 188 | + CenterVisibleColumns, | ||
| 189 | + FocusWorkspaceDown, | ||
| 190 | + #[knuffel(skip)] | ||
| 191 | + FocusWorkspaceDownUnderMouse, | ||
| 192 | + FocusWorkspaceUp, | ||
| 193 | + #[knuffel(skip)] | ||
| 194 | + FocusWorkspaceUpUnderMouse, | ||
| 195 | + FocusWorkspace(#[knuffel(argument)] WorkspaceReference), | ||
| 196 | + FocusWorkspacePrevious, | ||
| 197 | + MoveWindowToWorkspaceDown(#[knuffel(property(name = "focus"), default = true)] bool), | ||
| 198 | + MoveWindowToWorkspaceUp(#[knuffel(property(name = "focus"), default = true)] bool), | ||
| 199 | + MoveWindowToWorkspace( | ||
| 200 | + #[knuffel(argument)] WorkspaceReference, | ||
| 201 | + #[knuffel(property(name = "focus"), default = true)] bool, | ||
| 202 | + ), | ||
| 203 | + #[knuffel(skip)] | ||
| 204 | + MoveWindowToWorkspaceById { | ||
| 205 | + window_id: u64, | ||
| 206 | + reference: WorkspaceReference, | ||
| 207 | + focus: bool, | ||
| 208 | + }, | ||
| 209 | + MoveColumnToWorkspaceDown(#[knuffel(property(name = "focus"), default = true)] bool), | ||
| 210 | + MoveColumnToWorkspaceUp(#[knuffel(property(name = "focus"), default = true)] bool), | ||
| 211 | + MoveColumnToWorkspace( | ||
| 212 | + #[knuffel(argument)] WorkspaceReference, | ||
| 213 | + #[knuffel(property(name = "focus"), default = true)] bool, | ||
| 214 | + ), | ||
| 215 | + MoveWorkspaceDown, | ||
| 216 | + MoveWorkspaceUp, | ||
| 217 | + MoveWorkspaceToIndex(#[knuffel(argument)] usize), | ||
| 218 | + #[knuffel(skip)] | ||
| 219 | + MoveWorkspaceToIndexByRef { | ||
| 220 | + new_idx: usize, | ||
| 221 | + reference: WorkspaceReference, | ||
| 222 | + }, | ||
| 223 | + #[knuffel(skip)] | ||
| 224 | + MoveWorkspaceToMonitorByRef { | ||
| 225 | + output_name: String, | ||
| 226 | + reference: WorkspaceReference, | ||
| 227 | + }, | ||
| 228 | + MoveWorkspaceToMonitor(#[knuffel(argument)] String), | ||
| 229 | + SetWorkspaceName(#[knuffel(argument)] String), | ||
| 230 | + #[knuffel(skip)] | ||
| 231 | + SetWorkspaceNameByRef { | ||
| 232 | + name: String, | ||
| 233 | + reference: WorkspaceReference, | ||
| 234 | + }, | ||
| 235 | + UnsetWorkspaceName, | ||
| 236 | + #[knuffel(skip)] | ||
| 237 | + UnsetWorkSpaceNameByRef(#[knuffel(argument)] WorkspaceReference), | ||
| 238 | + FocusMonitorLeft, | ||
| 239 | + FocusMonitorRight, | ||
| 240 | + FocusMonitorDown, | ||
| 241 | + FocusMonitorUp, | ||
| 242 | + FocusMonitorPrevious, | ||
| 243 | + FocusMonitorNext, | ||
| 244 | + FocusMonitor(#[knuffel(argument)] String), | ||
| 245 | + MoveWindowToMonitorLeft, | ||
| 246 | + MoveWindowToMonitorRight, | ||
| 247 | + MoveWindowToMonitorDown, | ||
| 248 | + MoveWindowToMonitorUp, | ||
| 249 | + MoveWindowToMonitorPrevious, | ||
| 250 | + MoveWindowToMonitorNext, | ||
| 251 | + MoveWindowToMonitor(#[knuffel(argument)] String), | ||
| 252 | + #[knuffel(skip)] | ||
| 253 | + MoveWindowToMonitorById { | ||
| 254 | + id: u64, | ||
| 255 | + output: String, | ||
| 256 | + }, | ||
| 257 | + MoveColumnToMonitorLeft, | ||
| 258 | + MoveColumnToMonitorRight, | ||
| 259 | + MoveColumnToMonitorDown, | ||
| 260 | + MoveColumnToMonitorUp, | ||
| 261 | + MoveColumnToMonitorPrevious, | ||
| 262 | + MoveColumnToMonitorNext, | ||
| 263 | + MoveColumnToMonitor(#[knuffel(argument)] String), | ||
| 264 | + SetWindowWidth(#[knuffel(argument, str)] SizeChange), | ||
| 265 | + #[knuffel(skip)] | ||
| 266 | + SetWindowWidthById { | ||
| 267 | + id: u64, | ||
| 268 | + change: SizeChange, | ||
| 269 | + }, | ||
| 270 | + SetWindowHeight(#[knuffel(argument, str)] SizeChange), | ||
| 271 | + #[knuffel(skip)] | ||
| 272 | + SetWindowHeightById { | ||
| 273 | + id: u64, | ||
| 274 | + change: SizeChange, | ||
| 275 | + }, | ||
| 276 | + ResetWindowHeight, | ||
| 277 | + #[knuffel(skip)] | ||
| 278 | + ResetWindowHeightById(u64), | ||
| 279 | + SwitchPresetColumnWidth, | ||
| 280 | + SwitchPresetWindowWidth, | ||
| 281 | + #[knuffel(skip)] | ||
| 282 | + SwitchPresetWindowWidthById(u64), | ||
| 283 | + SwitchPresetWindowHeight, | ||
| 284 | + #[knuffel(skip)] | ||
| 285 | + SwitchPresetWindowHeightById(u64), | ||
| 286 | + MaximizeColumn, | ||
| 287 | + SetColumnWidth(#[knuffel(argument, str)] SizeChange), | ||
| 288 | + ExpandColumnToAvailableWidth, | ||
| 289 | + SwitchLayout(#[knuffel(argument, str)] LayoutSwitchTarget), | ||
| 290 | + ShowHotkeyOverlay, | ||
| 291 | + MoveWorkspaceToMonitorLeft, | ||
| 292 | + MoveWorkspaceToMonitorRight, | ||
| 293 | + MoveWorkspaceToMonitorDown, | ||
| 294 | + MoveWorkspaceToMonitorUp, | ||
| 295 | + MoveWorkspaceToMonitorPrevious, | ||
| 296 | + MoveWorkspaceToMonitorNext, | ||
| 297 | + ToggleWindowFloating, | ||
| 298 | + #[knuffel(skip)] | ||
| 299 | + ToggleWindowFloatingById(u64), | ||
| 300 | + MoveWindowToFloating, | ||
| 301 | + #[knuffel(skip)] | ||
| 302 | + MoveWindowToFloatingById(u64), | ||
| 303 | + MoveWindowToTiling, | ||
| 304 | + #[knuffel(skip)] | ||
| 305 | + MoveWindowToTilingById(u64), | ||
| 306 | + FocusFloating, | ||
| 307 | + FocusTiling, | ||
| 308 | + SwitchFocusBetweenFloatingAndTiling, | ||
| 309 | + #[knuffel(skip)] | ||
| 310 | + MoveFloatingWindowById { | ||
| 311 | + id: Option<u64>, | ||
| 312 | + x: PositionChange, | ||
| 313 | + y: PositionChange, | ||
| 314 | + }, | ||
| 315 | + ToggleWindowRuleOpacity, | ||
| 316 | + #[knuffel(skip)] | ||
| 317 | + ToggleWindowRuleOpacityById(u64), | ||
| 318 | + SetDynamicCastWindow, | ||
| 319 | + #[knuffel(skip)] | ||
| 320 | + SetDynamicCastWindowById(u64), | ||
| 321 | + SetDynamicCastMonitor(#[knuffel(argument)] Option<String>), | ||
| 322 | + ClearDynamicCastTarget, | ||
| 323 | + ToggleOverview, | ||
| 324 | + OpenOverview, | ||
| 325 | + CloseOverview, | ||
| 326 | + #[knuffel(skip)] | ||
| 327 | + ToggleWindowUrgent(u64), | ||
| 328 | + #[knuffel(skip)] | ||
| 329 | + SetWindowUrgent(u64), | ||
| 330 | + #[knuffel(skip)] | ||
| 331 | + UnsetWindowUrgent(u64), | ||
| 332 | + #[knuffel(skip)] | ||
| 333 | + LoadConfigFile, | ||
| 334 | +} | ||
| 335 | + | ||
| 336 | +impl From<niri_ipc::Action> for Action { | ||
| 337 | + fn from(value: niri_ipc::Action) -> Self { | ||
| 338 | + match value { | ||
| 339 | + niri_ipc::Action::Quit { skip_confirmation } => Self::Quit(skip_confirmation), | ||
| 340 | + niri_ipc::Action::PowerOffMonitors {} => Self::PowerOffMonitors, | ||
| 341 | + niri_ipc::Action::PowerOnMonitors {} => Self::PowerOnMonitors, | ||
| 342 | + niri_ipc::Action::Spawn { command } => Self::Spawn(command), | ||
| 343 | + niri_ipc::Action::SpawnSh { command } => Self::SpawnSh(command), | ||
| 344 | + niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms), | ||
| 345 | + niri_ipc::Action::Screenshot { show_pointer } => Self::Screenshot(show_pointer), | ||
| 346 | + niri_ipc::Action::ScreenshotScreen { | ||
| 347 | + write_to_disk, | ||
| 348 | + show_pointer, | ||
| 349 | + } => Self::ScreenshotScreen(write_to_disk, show_pointer), | ||
| 350 | + niri_ipc::Action::ScreenshotWindow { | ||
| 351 | + id: None, | ||
| 352 | + write_to_disk, | ||
| 353 | + } => Self::ScreenshotWindow(write_to_disk), | ||
| 354 | + niri_ipc::Action::ScreenshotWindow { | ||
| 355 | + id: Some(id), | ||
| 356 | + write_to_disk, | ||
| 357 | + } => Self::ScreenshotWindowById { id, write_to_disk }, | ||
| 358 | + niri_ipc::Action::ToggleKeyboardShortcutsInhibit {} => { | ||
| 359 | + Self::ToggleKeyboardShortcutsInhibit | ||
| 360 | + } | ||
| 361 | + niri_ipc::Action::CloseWindow { id: None } => Self::CloseWindow, | ||
| 362 | + niri_ipc::Action::CloseWindow { id: Some(id) } => Self::CloseWindowById(id), | ||
| 363 | + niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow, | ||
| 364 | + niri_ipc::Action::FullscreenWindow { id: Some(id) } => Self::FullscreenWindowById(id), | ||
| 365 | + niri_ipc::Action::ToggleWindowedFullscreen { id: None } => { | ||
| 366 | + Self::ToggleWindowedFullscreen | ||
| 367 | + } | ||
| 368 | + niri_ipc::Action::ToggleWindowedFullscreen { id: Some(id) } => { | ||
| 369 | + Self::ToggleWindowedFullscreenById(id) | ||
| 370 | + } | ||
| 371 | + niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id), | ||
| 372 | + niri_ipc::Action::FocusWindowInColumn { index } => Self::FocusWindowInColumn(index), | ||
| 373 | + niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious, | ||
| 374 | + niri_ipc::Action::FocusColumnLeft {} => Self::FocusColumnLeft, | ||
| 375 | + niri_ipc::Action::FocusColumnRight {} => Self::FocusColumnRight, | ||
| 376 | + niri_ipc::Action::FocusColumnFirst {} => Self::FocusColumnFirst, | ||
| 377 | + niri_ipc::Action::FocusColumnLast {} => Self::FocusColumnLast, | ||
| 378 | + niri_ipc::Action::FocusColumnRightOrFirst {} => Self::FocusColumnRightOrFirst, | ||
| 379 | + niri_ipc::Action::FocusColumnLeftOrLast {} => Self::FocusColumnLeftOrLast, | ||
| 380 | + niri_ipc::Action::FocusColumn { index } => Self::FocusColumn(index), | ||
| 381 | + niri_ipc::Action::FocusWindowOrMonitorUp {} => Self::FocusWindowOrMonitorUp, | ||
| 382 | + niri_ipc::Action::FocusWindowOrMonitorDown {} => Self::FocusWindowOrMonitorDown, | ||
| 383 | + niri_ipc::Action::FocusColumnOrMonitorLeft {} => Self::FocusColumnOrMonitorLeft, | ||
| 384 | + niri_ipc::Action::FocusColumnOrMonitorRight {} => Self::FocusColumnOrMonitorRight, | ||
| 385 | + niri_ipc::Action::FocusWindowDown {} => Self::FocusWindowDown, | ||
| 386 | + niri_ipc::Action::FocusWindowUp {} => Self::FocusWindowUp, | ||
| 387 | + niri_ipc::Action::FocusWindowDownOrColumnLeft {} => Self::FocusWindowDownOrColumnLeft, | ||
| 388 | + niri_ipc::Action::FocusWindowDownOrColumnRight {} => Self::FocusWindowDownOrColumnRight, | ||
| 389 | + niri_ipc::Action::FocusWindowUpOrColumnLeft {} => Self::FocusWindowUpOrColumnLeft, | ||
| 390 | + niri_ipc::Action::FocusWindowUpOrColumnRight {} => Self::FocusWindowUpOrColumnRight, | ||
| 391 | + niri_ipc::Action::FocusWindowOrWorkspaceDown {} => Self::FocusWindowOrWorkspaceDown, | ||
| 392 | + niri_ipc::Action::FocusWindowOrWorkspaceUp {} => Self::FocusWindowOrWorkspaceUp, | ||
| 393 | + niri_ipc::Action::FocusWindowTop {} => Self::FocusWindowTop, | ||
| 394 | + niri_ipc::Action::FocusWindowBottom {} => Self::FocusWindowBottom, | ||
| 395 | + niri_ipc::Action::FocusWindowDownOrTop {} => Self::FocusWindowDownOrTop, | ||
| 396 | + niri_ipc::Action::FocusWindowUpOrBottom {} => Self::FocusWindowUpOrBottom, | ||
| 397 | + niri_ipc::Action::MoveColumnLeft {} => Self::MoveColumnLeft, | ||
| 398 | + niri_ipc::Action::MoveColumnRight {} => Self::MoveColumnRight, | ||
| 399 | + niri_ipc::Action::MoveColumnToFirst {} => Self::MoveColumnToFirst, | ||
| 400 | + niri_ipc::Action::MoveColumnToLast {} => Self::MoveColumnToLast, | ||
| 401 | + niri_ipc::Action::MoveColumnToIndex { index } => Self::MoveColumnToIndex(index), | ||
| 402 | + niri_ipc::Action::MoveColumnLeftOrToMonitorLeft {} => { | ||
| 403 | + Self::MoveColumnLeftOrToMonitorLeft | ||
| 404 | + } | ||
| 405 | + niri_ipc::Action::MoveColumnRightOrToMonitorRight {} => { | ||
| 406 | + Self::MoveColumnRightOrToMonitorRight | ||
| 407 | + } | ||
| 408 | + niri_ipc::Action::MoveWindowDown {} => Self::MoveWindowDown, | ||
| 409 | + niri_ipc::Action::MoveWindowUp {} => Self::MoveWindowUp, | ||
| 410 | + niri_ipc::Action::MoveWindowDownOrToWorkspaceDown {} => { | ||
| 411 | + Self::MoveWindowDownOrToWorkspaceDown | ||
| 412 | + } | ||
| 413 | + niri_ipc::Action::MoveWindowUpOrToWorkspaceUp {} => Self::MoveWindowUpOrToWorkspaceUp, | ||
| 414 | + niri_ipc::Action::ConsumeOrExpelWindowLeft { id: None } => { | ||
| 415 | + Self::ConsumeOrExpelWindowLeft | ||
| 416 | + } | ||
| 417 | + niri_ipc::Action::ConsumeOrExpelWindowLeft { id: Some(id) } => { | ||
| 418 | + Self::ConsumeOrExpelWindowLeftById(id) | ||
| 419 | + } | ||
| 420 | + niri_ipc::Action::ConsumeOrExpelWindowRight { id: None } => { | ||
| 421 | + Self::ConsumeOrExpelWindowRight | ||
| 422 | + } | ||
| 423 | + niri_ipc::Action::ConsumeOrExpelWindowRight { id: Some(id) } => { | ||
| 424 | + Self::ConsumeOrExpelWindowRightById(id) | ||
| 425 | + } | ||
| 426 | + niri_ipc::Action::ConsumeWindowIntoColumn {} => Self::ConsumeWindowIntoColumn, | ||
| 427 | + niri_ipc::Action::ExpelWindowFromColumn {} => Self::ExpelWindowFromColumn, | ||
| 428 | + niri_ipc::Action::SwapWindowRight {} => Self::SwapWindowRight, | ||
| 429 | + niri_ipc::Action::SwapWindowLeft {} => Self::SwapWindowLeft, | ||
| 430 | + niri_ipc::Action::ToggleColumnTabbedDisplay {} => Self::ToggleColumnTabbedDisplay, | ||
| 431 | + niri_ipc::Action::SetColumnDisplay { display } => Self::SetColumnDisplay(display), | ||
| 432 | + niri_ipc::Action::CenterColumn {} => Self::CenterColumn, | ||
| 433 | + niri_ipc::Action::CenterWindow { id: None } => Self::CenterWindow, | ||
| 434 | + niri_ipc::Action::CenterWindow { id: Some(id) } => Self::CenterWindowById(id), | ||
| 435 | + niri_ipc::Action::CenterVisibleColumns {} => Self::CenterVisibleColumns, | ||
| 436 | + niri_ipc::Action::FocusWorkspaceDown {} => Self::FocusWorkspaceDown, | ||
| 437 | + niri_ipc::Action::FocusWorkspaceUp {} => Self::FocusWorkspaceUp, | ||
| 438 | + niri_ipc::Action::FocusWorkspace { reference } => { | ||
| 439 | + Self::FocusWorkspace(WorkspaceReference::from(reference)) | ||
| 440 | + } | ||
| 441 | + niri_ipc::Action::FocusWorkspacePrevious {} => Self::FocusWorkspacePrevious, | ||
| 442 | + niri_ipc::Action::MoveWindowToWorkspaceDown { focus } => { | ||
| 443 | + Self::MoveWindowToWorkspaceDown(focus) | ||
| 444 | + } | ||
| 445 | + niri_ipc::Action::MoveWindowToWorkspaceUp { focus } => { | ||
| 446 | + Self::MoveWindowToWorkspaceUp(focus) | ||
| 447 | + } | ||
| 448 | + niri_ipc::Action::MoveWindowToWorkspace { | ||
| 449 | + window_id: None, | ||
| 450 | + reference, | ||
| 451 | + focus, | ||
| 452 | + } => Self::MoveWindowToWorkspace(WorkspaceReference::from(reference), focus), | ||
| 453 | + niri_ipc::Action::MoveWindowToWorkspace { | ||
| 454 | + window_id: Some(window_id), | ||
| 455 | + reference, | ||
| 456 | + focus, | ||
| 457 | + } => Self::MoveWindowToWorkspaceById { | ||
| 458 | + window_id, | ||
| 459 | + reference: WorkspaceReference::from(reference), | ||
| 460 | + focus, | ||
| 461 | + }, | ||
| 462 | + niri_ipc::Action::MoveColumnToWorkspaceDown { focus } => { | ||
| 463 | + Self::MoveColumnToWorkspaceDown(focus) | ||
| 464 | + } | ||
| 465 | + niri_ipc::Action::MoveColumnToWorkspaceUp { focus } => { | ||
| 466 | + Self::MoveColumnToWorkspaceUp(focus) | ||
| 467 | + } | ||
| 468 | + niri_ipc::Action::MoveColumnToWorkspace { reference, focus } => { | ||
| 469 | + Self::MoveColumnToWorkspace(WorkspaceReference::from(reference), focus) | ||
| 470 | + } | ||
| 471 | + niri_ipc::Action::MoveWorkspaceDown {} => Self::MoveWorkspaceDown, | ||
| 472 | + niri_ipc::Action::MoveWorkspaceUp {} => Self::MoveWorkspaceUp, | ||
| 473 | + niri_ipc::Action::SetWorkspaceName { | ||
| 474 | + name, | ||
| 475 | + workspace: None, | ||
| 476 | + } => Self::SetWorkspaceName(name), | ||
| 477 | + niri_ipc::Action::SetWorkspaceName { | ||
| 478 | + name, | ||
| 479 | + workspace: Some(reference), | ||
| 480 | + } => Self::SetWorkspaceNameByRef { | ||
| 481 | + name, | ||
| 482 | + reference: WorkspaceReference::from(reference), | ||
| 483 | + }, | ||
| 484 | + niri_ipc::Action::UnsetWorkspaceName { reference: None } => Self::UnsetWorkspaceName, | ||
| 485 | + niri_ipc::Action::UnsetWorkspaceName { | ||
| 486 | + reference: Some(reference), | ||
| 487 | + } => Self::UnsetWorkSpaceNameByRef(WorkspaceReference::from(reference)), | ||
| 488 | + niri_ipc::Action::FocusMonitorLeft {} => Self::FocusMonitorLeft, | ||
| 489 | + niri_ipc::Action::FocusMonitorRight {} => Self::FocusMonitorRight, | ||
| 490 | + niri_ipc::Action::FocusMonitorDown {} => Self::FocusMonitorDown, | ||
| 491 | + niri_ipc::Action::FocusMonitorUp {} => Self::FocusMonitorUp, | ||
| 492 | + niri_ipc::Action::FocusMonitorPrevious {} => Self::FocusMonitorPrevious, | ||
| 493 | + niri_ipc::Action::FocusMonitorNext {} => Self::FocusMonitorNext, | ||
| 494 | + niri_ipc::Action::FocusMonitor { output } => Self::FocusMonitor(output), | ||
| 495 | + niri_ipc::Action::MoveWindowToMonitorLeft {} => Self::MoveWindowToMonitorLeft, | ||
| 496 | + niri_ipc::Action::MoveWindowToMonitorRight {} => Self::MoveWindowToMonitorRight, | ||
| 497 | + niri_ipc::Action::MoveWindowToMonitorDown {} => Self::MoveWindowToMonitorDown, | ||
| 498 | + niri_ipc::Action::MoveWindowToMonitorUp {} => Self::MoveWindowToMonitorUp, | ||
| 499 | + niri_ipc::Action::MoveWindowToMonitorPrevious {} => Self::MoveWindowToMonitorPrevious, | ||
| 500 | + niri_ipc::Action::MoveWindowToMonitorNext {} => Self::MoveWindowToMonitorNext, | ||
| 501 | + niri_ipc::Action::MoveWindowToMonitor { id: None, output } => { | ||
| 502 | + Self::MoveWindowToMonitor(output) | ||
| 503 | + } | ||
| 504 | + niri_ipc::Action::MoveWindowToMonitor { | ||
| 505 | + id: Some(id), | ||
| 506 | + output, | ||
| 507 | + } => Self::MoveWindowToMonitorById { id, output }, | ||
| 508 | + niri_ipc::Action::MoveColumnToMonitorLeft {} => Self::MoveColumnToMonitorLeft, | ||
| 509 | + niri_ipc::Action::MoveColumnToMonitorRight {} => Self::MoveColumnToMonitorRight, | ||
| 510 | + niri_ipc::Action::MoveColumnToMonitorDown {} => Self::MoveColumnToMonitorDown, | ||
| 511 | + niri_ipc::Action::MoveColumnToMonitorUp {} => Self::MoveColumnToMonitorUp, | ||
| 512 | + niri_ipc::Action::MoveColumnToMonitorPrevious {} => Self::MoveColumnToMonitorPrevious, | ||
| 513 | + niri_ipc::Action::MoveColumnToMonitorNext {} => Self::MoveColumnToMonitorNext, | ||
| 514 | + niri_ipc::Action::MoveColumnToMonitor { output } => Self::MoveColumnToMonitor(output), | ||
| 515 | + niri_ipc::Action::SetWindowWidth { id: None, change } => Self::SetWindowWidth(change), | ||
| 516 | + niri_ipc::Action::SetWindowWidth { | ||
| 517 | + id: Some(id), | ||
| 518 | + change, | ||
| 519 | + } => Self::SetWindowWidthById { id, change }, | ||
| 520 | + niri_ipc::Action::SetWindowHeight { id: None, change } => Self::SetWindowHeight(change), | ||
| 521 | + niri_ipc::Action::SetWindowHeight { | ||
| 522 | + id: Some(id), | ||
| 523 | + change, | ||
| 524 | + } => Self::SetWindowHeightById { id, change }, | ||
| 525 | + niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight, | ||
| 526 | + niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id), | ||
| 527 | + niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth, | ||
| 528 | + niri_ipc::Action::SwitchPresetWindowWidth { id: None } => Self::SwitchPresetWindowWidth, | ||
| 529 | + niri_ipc::Action::SwitchPresetWindowWidth { id: Some(id) } => { | ||
| 530 | + Self::SwitchPresetWindowWidthById(id) | ||
| 531 | + } | ||
| 532 | + niri_ipc::Action::SwitchPresetWindowHeight { id: None } => { | ||
| 533 | + Self::SwitchPresetWindowHeight | ||
| 534 | + } | ||
| 535 | + niri_ipc::Action::SwitchPresetWindowHeight { id: Some(id) } => { | ||
| 536 | + Self::SwitchPresetWindowHeightById(id) | ||
| 537 | + } | ||
| 538 | + niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn, | ||
| 539 | + niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change), | ||
| 540 | + niri_ipc::Action::ExpandColumnToAvailableWidth {} => Self::ExpandColumnToAvailableWidth, | ||
| 541 | + niri_ipc::Action::SwitchLayout { layout } => Self::SwitchLayout(layout), | ||
| 542 | + niri_ipc::Action::ShowHotkeyOverlay {} => Self::ShowHotkeyOverlay, | ||
| 543 | + niri_ipc::Action::MoveWorkspaceToMonitorLeft {} => Self::MoveWorkspaceToMonitorLeft, | ||
| 544 | + niri_ipc::Action::MoveWorkspaceToMonitorRight {} => Self::MoveWorkspaceToMonitorRight, | ||
| 545 | + niri_ipc::Action::MoveWorkspaceToMonitorDown {} => Self::MoveWorkspaceToMonitorDown, | ||
| 546 | + niri_ipc::Action::MoveWorkspaceToMonitorUp {} => Self::MoveWorkspaceToMonitorUp, | ||
| 547 | + niri_ipc::Action::MoveWorkspaceToMonitorPrevious {} => { | ||
| 548 | + Self::MoveWorkspaceToMonitorPrevious | ||
| 549 | + } | ||
| 550 | + niri_ipc::Action::MoveWorkspaceToIndex { | ||
| 551 | + index, | ||
| 552 | + reference: Some(reference), | ||
| 553 | + } => Self::MoveWorkspaceToIndexByRef { | ||
| 554 | + new_idx: index, | ||
| 555 | + reference: WorkspaceReference::from(reference), | ||
| 556 | + }, | ||
| 557 | + niri_ipc::Action::MoveWorkspaceToIndex { | ||
| 558 | + index, | ||
| 559 | + reference: None, | ||
| 560 | + } => Self::MoveWorkspaceToIndex(index), | ||
| 561 | + niri_ipc::Action::MoveWorkspaceToMonitor { | ||
| 562 | + output, | ||
| 563 | + reference: Some(reference), | ||
| 564 | + } => Self::MoveWorkspaceToMonitorByRef { | ||
| 565 | + output_name: output, | ||
| 566 | + reference: WorkspaceReference::from(reference), | ||
| 567 | + }, | ||
| 568 | + niri_ipc::Action::MoveWorkspaceToMonitor { | ||
| 569 | + output, | ||
| 570 | + reference: None, | ||
| 571 | + } => Self::MoveWorkspaceToMonitor(output), | ||
| 572 | + niri_ipc::Action::MoveWorkspaceToMonitorNext {} => Self::MoveWorkspaceToMonitorNext, | ||
| 573 | + niri_ipc::Action::ToggleDebugTint {} => Self::ToggleDebugTint, | ||
| 574 | + niri_ipc::Action::DebugToggleOpaqueRegions {} => Self::DebugToggleOpaqueRegions, | ||
| 575 | + niri_ipc::Action::DebugToggleDamage {} => Self::DebugToggleDamage, | ||
| 576 | + niri_ipc::Action::ToggleWindowFloating { id: None } => Self::ToggleWindowFloating, | ||
| 577 | + niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => { | ||
| 578 | + Self::ToggleWindowFloatingById(id) | ||
| 579 | + } | ||
| 580 | + niri_ipc::Action::MoveWindowToFloating { id: None } => Self::MoveWindowToFloating, | ||
| 581 | + niri_ipc::Action::MoveWindowToFloating { id: Some(id) } => { | ||
| 582 | + Self::MoveWindowToFloatingById(id) | ||
| 583 | + } | ||
| 584 | + niri_ipc::Action::MoveWindowToTiling { id: None } => Self::MoveWindowToTiling, | ||
| 585 | + niri_ipc::Action::MoveWindowToTiling { id: Some(id) } => { | ||
| 586 | + Self::MoveWindowToTilingById(id) | ||
| 587 | + } | ||
| 588 | + niri_ipc::Action::FocusFloating {} => Self::FocusFloating, | ||
| 589 | + niri_ipc::Action::FocusTiling {} => Self::FocusTiling, | ||
| 590 | + niri_ipc::Action::SwitchFocusBetweenFloatingAndTiling {} => { | ||
| 591 | + Self::SwitchFocusBetweenFloatingAndTiling | ||
| 592 | + } | ||
| 593 | + niri_ipc::Action::MoveFloatingWindow { id, x, y } => { | ||
| 594 | + Self::MoveFloatingWindowById { id, x, y } | ||
| 595 | + } | ||
| 596 | + niri_ipc::Action::ToggleWindowRuleOpacity { id: None } => Self::ToggleWindowRuleOpacity, | ||
| 597 | + niri_ipc::Action::ToggleWindowRuleOpacity { id: Some(id) } => { | ||
| 598 | + Self::ToggleWindowRuleOpacityById(id) | ||
| 599 | + } | ||
| 600 | + niri_ipc::Action::SetDynamicCastWindow { id: None } => Self::SetDynamicCastWindow, | ||
| 601 | + niri_ipc::Action::SetDynamicCastWindow { id: Some(id) } => { | ||
| 602 | + Self::SetDynamicCastWindowById(id) | ||
| 603 | + } | ||
| 604 | + niri_ipc::Action::SetDynamicCastMonitor { output } => { | ||
| 605 | + Self::SetDynamicCastMonitor(output) | ||
| 606 | + } | ||
| 607 | + niri_ipc::Action::ClearDynamicCastTarget {} => Self::ClearDynamicCastTarget, | ||
| 608 | + niri_ipc::Action::ToggleOverview {} => Self::ToggleOverview, | ||
| 609 | + niri_ipc::Action::OpenOverview {} => Self::OpenOverview, | ||
| 610 | + niri_ipc::Action::CloseOverview {} => Self::CloseOverview, | ||
| 611 | + niri_ipc::Action::ToggleWindowUrgent { id } => Self::ToggleWindowUrgent(id), | ||
| 612 | + niri_ipc::Action::SetWindowUrgent { id } => Self::SetWindowUrgent(id), | ||
| 613 | + niri_ipc::Action::UnsetWindowUrgent { id } => Self::UnsetWindowUrgent(id), | ||
| 614 | + niri_ipc::Action::LoadConfigFile {} => Self::LoadConfigFile, | ||
| 615 | + } | ||
| 616 | + } | ||
| 617 | +} | ||
| 618 | + | ||
| 619 | +#[derive(Debug, PartialEq, Eq, Clone)] | ||
| 620 | +pub enum WorkspaceReference { | ||
| 621 | + Id(u64), | ||
| 622 | + Index(u8), | ||
| 623 | + Name(String), | ||
| 624 | +} | ||
| 625 | + | ||
| 626 | +impl From<WorkspaceReferenceArg> for WorkspaceReference { | ||
| 627 | + fn from(reference: WorkspaceReferenceArg) -> WorkspaceReference { | ||
| 628 | + match reference { | ||
| 629 | + WorkspaceReferenceArg::Id(id) => Self::Id(id), | ||
| 630 | + WorkspaceReferenceArg::Index(i) => Self::Index(i), | ||
| 631 | + WorkspaceReferenceArg::Name(n) => Self::Name(n), | ||
| 632 | + } | ||
| 633 | + } | ||
| 634 | +} | ||
| 635 | + | ||
| 636 | +impl<S: knuffel::traits::ErrorSpan> knuffel::DecodeScalar<S> for WorkspaceReference { | ||
| 637 | + fn type_check( | ||
| 638 | + type_name: &Option<knuffel::span::Spanned<knuffel::ast::TypeName, S>>, | ||
| 639 | + ctx: &mut knuffel::decode::Context<S>, | ||
| 640 | + ) { | ||
| 641 | + if let Some(type_name) = &type_name { | ||
| 642 | + ctx.emit_error(DecodeError::unexpected( | ||
| 643 | + type_name, | ||
| 644 | + "type name", | ||
| 645 | + "no type name expected for this node", | ||
| 646 | + )); | ||
| 647 | + } | ||
| 648 | + } | ||
| 649 | + | ||
| 650 | + fn raw_decode( | ||
| 651 | + val: &knuffel::span::Spanned<knuffel::ast::Literal, S>, | ||
| 652 | + ctx: &mut knuffel::decode::Context<S>, | ||
| 653 | + ) -> Result<WorkspaceReference, DecodeError<S>> { | ||
| 654 | + match &**val { | ||
| 655 | + knuffel::ast::Literal::String(ref s) => Ok(WorkspaceReference::Name(s.clone().into())), | ||
| 656 | + knuffel::ast::Literal::Int(ref value) => match value.try_into() { | ||
| 657 | + Ok(v) => Ok(WorkspaceReference::Index(v)), | ||
| 658 | + Err(e) => { | ||
| 659 | + ctx.emit_error(DecodeError::conversion(val, e)); | ||
| 660 | + Ok(WorkspaceReference::Index(0)) | ||
| 661 | + } | ||
| 662 | + }, | ||
| 663 | + _ => { | ||
| 664 | + ctx.emit_error(DecodeError::unsupported( | ||
| 665 | + val, | ||
| 666 | + "Unsupported value, only numbers and strings are recognized", | ||
| 667 | + )); | ||
| 668 | + Ok(WorkspaceReference::Index(0)) | ||
| 669 | + } | ||
| 670 | + } | ||
| 671 | + } | ||
| 672 | +} | ||
| 673 | + | ||
| 674 | +impl<S> knuffel::Decode<S> for Binds | ||
| 675 | +where | ||
| 676 | + S: knuffel::traits::ErrorSpan, | ||
| 677 | +{ | ||
| 678 | + fn decode_node( | ||
| 679 | + node: &knuffel::ast::SpannedNode<S>, | ||
| 680 | + ctx: &mut knuffel::decode::Context<S>, | ||
| 681 | + ) -> Result<Self, DecodeError<S>> { | ||
| 682 | + expect_only_children(node, ctx); | ||
| 683 | + | ||
| 684 | + let mut seen_keys = HashSet::new(); | ||
| 685 | + | ||
| 686 | + let mut binds = Vec::new(); | ||
| 687 | + | ||
| 688 | + for child in node.children() { | ||
| 689 | + match Bind::decode_node(child, ctx) { | ||
| 690 | + Err(e) => { | ||
| 691 | + ctx.emit_error(e); | ||
| 692 | + } | ||
| 693 | + Ok(bind) => { | ||
| 694 | + if seen_keys.insert(bind.key) { | ||
| 695 | + binds.push(bind); | ||
| 696 | + } else { | ||
| 697 | + // ideally, this error should point to the previous instance of this keybind | ||
| 698 | + // | ||
| 699 | + // i (sodiboo) have tried to implement this in various ways: | ||
| 700 | + // miette!(), #[derive(Diagnostic)] | ||
| 701 | + // DecodeError::Custom, DecodeError::Conversion | ||
| 702 | + // nothing seems to work, and i suspect it's not possible. | ||
| 703 | + // | ||
| 704 | + // DecodeError is fairly restrictive. | ||
| 705 | + // even DecodeError::Custom just wraps a std::error::Error | ||
| 706 | + // and this erases all rich information from miette. (why???) | ||
| 707 | + // | ||
| 708 | + // why does knuffel do this? | ||
| 709 | + // from what i can tell, it doesn't even use DecodeError for much. | ||
| 710 | + // it only ever converts them to a Report anyways! | ||
| 711 | + // https://github.com/tailhook/knuffel/blob/c44c6b0c0f31ea6d1174d5d2ed41064922ea44ca/src/wrappers.rs#L55-L58 | ||
| 712 | + // | ||
| 713 | + // besides like, allowing downstream users (such as us!) | ||
| 714 | + // to match on parse failure, i don't understand why | ||
| 715 | + // it doesn't just use a generic error type | ||
| 716 | + // | ||
| 717 | + // even the matching isn't consistent, | ||
| 718 | + // because errors can also be omitted as ctx.emit_error. | ||
| 719 | + // why does *that one* especially, require a DecodeError? | ||
| 720 | + // | ||
| 721 | + // anyways if you can make it format nicely, definitely do fix this | ||
| 722 | + ctx.emit_error(DecodeError::unexpected( | ||
| 723 | + &child.node_name, | ||
| 724 | + "keybind", | ||
| 725 | + "duplicate keybind", | ||
| 726 | + )); | ||
| 727 | + } | ||
| 728 | + } | ||
| 729 | + } | ||
| 730 | + } | ||
| 731 | + | ||
| 732 | + Ok(Self(binds)) | ||
| 733 | + } | ||
| 734 | +} | ||
| 735 | + | ||
| 736 | +impl<S> knuffel::Decode<S> for Bind | ||
| 737 | +where | ||
| 738 | + S: knuffel::traits::ErrorSpan, | ||
| 739 | +{ | ||
| 740 | + fn decode_node( | ||
| 741 | + node: &knuffel::ast::SpannedNode<S>, | ||
| 742 | + ctx: &mut knuffel::decode::Context<S>, | ||
| 743 | + ) -> Result<Self, DecodeError<S>> { | ||
| 744 | + if let Some(type_name) = &node.type_name { | ||
| 745 | + ctx.emit_error(DecodeError::unexpected( | ||
| 746 | + type_name, | ||
| 747 | + "type name", | ||
| 748 | + "no type name expected for this node", | ||
| 749 | + )); | ||
| 750 | + } | ||
| 751 | + | ||
| 752 | + for val in node.arguments.iter() { | ||
| 753 | + ctx.emit_error(DecodeError::unexpected( | ||
| 754 | + &val.literal, | ||
| 755 | + "argument", | ||
| 756 | + "no arguments expected for this node", | ||
| 757 | + )); | ||
| 758 | + } | ||
| 759 | + | ||
| 760 | + let key = node | ||
| 761 | + .node_name | ||
| 762 | + .parse::<Key>() | ||
| 763 | + .map_err(|e| DecodeError::conversion(&node.node_name, e.wrap_err("invalid keybind")))?; | ||
| 764 | + | ||
| 765 | + let mut repeat = true; | ||
| 766 | + let mut cooldown = None; | ||
| 767 | + let mut allow_when_locked = false; | ||
| 768 | + let mut allow_when_locked_node = None; | ||
| 769 | + let mut allow_inhibiting = true; | ||
| 770 | + let mut hotkey_overlay_title = None; | ||
| 771 | + for (name, val) in &node.properties { | ||
| 772 | + match &***name { | ||
| 773 | + "repeat" => { | ||
| 774 | + repeat = knuffel::traits::DecodeScalar::decode(val, ctx)?; | ||
| 775 | + } | ||
| 776 | + "cooldown-ms" => { | ||
| 777 | + cooldown = Some(Duration::from_millis( | ||
| 778 | + knuffel::traits::DecodeScalar::decode(val, ctx)?, | ||
| 779 | + )); | ||
| 780 | + } | ||
| 781 | + "allow-when-locked" => { | ||
| 782 | + allow_when_locked = knuffel::traits::DecodeScalar::decode(val, ctx)?; | ||
| 783 | + allow_when_locked_node = Some(name); | ||
| 784 | + } | ||
| 785 | + "allow-inhibiting" => { | ||
| 786 | + allow_inhibiting = knuffel::traits::DecodeScalar::decode(val, ctx)?; | ||
| 787 | + } | ||
| 788 | + "hotkey-overlay-title" => { | ||
| 789 | + hotkey_overlay_title = Some(knuffel::traits::DecodeScalar::decode(val, ctx)?); | ||
| 790 | + } | ||
| 791 | + name_str => { | ||
| 792 | + ctx.emit_error(DecodeError::unexpected( | ||
| 793 | + name, | ||
| 794 | + "property", | ||
| 795 | + format!("unexpected property `{}`", name_str.escape_default()), | ||
| 796 | + )); | ||
| 797 | + } | ||
| 798 | + } | ||
| 799 | + } | ||
| 800 | + | ||
| 801 | + let mut children = node.children(); | ||
| 802 | + | ||
| 803 | + // If the action is invalid but the key is fine, we still want to return something. | ||
| 804 | + // That way, the parent can handle the existence of duplicate keybinds, | ||
| 805 | + // even if their contents are not valid. | ||
| 806 | + let dummy = Self { | ||
| 807 | + key, | ||
| 808 | + action: Action::Spawn(vec![]), | ||
| 809 | + repeat: true, | ||
| 810 | + cooldown: None, | ||
| 811 | + allow_when_locked: false, | ||
| 812 | + allow_inhibiting: true, | ||
| 813 | + hotkey_overlay_title: None, | ||
| 814 | + }; | ||
| 815 | + | ||
| 816 | + if let Some(child) = children.next() { | ||
| 817 | + for unwanted_child in children { | ||
| 818 | + ctx.emit_error(DecodeError::unexpected( | ||
| 819 | + unwanted_child, | ||
| 820 | + "node", | ||
| 821 | + "only one action is allowed per keybind", | ||
| 822 | + )); | ||
| 823 | + } | ||
| 824 | + match Action::decode_node(child, ctx) { | ||
| 825 | + Ok(action) => { | ||
| 826 | + if !matches!(action, Action::Spawn(_) | Action::SpawnSh(_)) { | ||
| 827 | + if let Some(node) = allow_when_locked_node { | ||
| 828 | + ctx.emit_error(DecodeError::unexpected( | ||
| 829 | + node, | ||
| 830 | + "property", | ||
| 831 | + "allow-when-locked can only be set on spawn binds", | ||
| 832 | + )); | ||
| 833 | + } | ||
| 834 | + } | ||
| 835 | + | ||
| 836 | + // The toggle-inhibit action must always be uninhibitable. | ||
| 837 | + // Otherwise, it would be impossible to trigger it. | ||
| 838 | + if matches!(action, Action::ToggleKeyboardShortcutsInhibit) { | ||
| 839 | + allow_inhibiting = false; | ||
| 840 | + } | ||
| 841 | + | ||
| 842 | + Ok(Self { | ||
| 843 | + key, | ||
| 844 | + action, | ||
| 845 | + repeat, | ||
| 846 | + cooldown, | ||
| 847 | + allow_when_locked, | ||
| 848 | + allow_inhibiting, | ||
| 849 | + hotkey_overlay_title, | ||
| 850 | + }) | ||
| 851 | + } | ||
| 852 | + Err(e) => { | ||
| 853 | + ctx.emit_error(e); | ||
| 854 | + Ok(dummy) | ||
| 855 | + } | ||
| 856 | + } | ||
| 857 | + } else { | ||
| 858 | + ctx.emit_error(DecodeError::missing( | ||
| 859 | + node, | ||
| 860 | + "expected an action for this keybind", | ||
| 861 | + )); | ||
| 862 | + Ok(dummy) | ||
| 863 | + } | ||
| 864 | + } | ||
| 865 | +} | ||
| 866 | + | ||
| 867 | +impl FromStr for Key { | ||
| 868 | + type Err = miette::Error; | ||
| 869 | + | ||
| 870 | + fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| 871 | + let mut modifiers = Modifiers::empty(); | ||
| 872 | + | ||
| 873 | + let mut split = s.split('+'); | ||
| 874 | + let key = split.next_back().unwrap(); | ||
| 875 | + | ||
| 876 | + for part in split { | ||
| 877 | + let part = part.trim(); | ||
| 878 | + if part.eq_ignore_ascii_case("mod") { | ||
| 879 | + modifiers |= Modifiers::COMPOSITOR | ||
| 880 | + } else if part.eq_ignore_ascii_case("ctrl") || part.eq_ignore_ascii_case("control") { | ||
| 881 | + modifiers |= Modifiers::CTRL; | ||
| 882 | + } else if part.eq_ignore_ascii_case("shift") { | ||
| 883 | + modifiers |= Modifiers::SHIFT; | ||
| 884 | + } else if part.eq_ignore_ascii_case("alt") { | ||
| 885 | + modifiers |= Modifiers::ALT; | ||
| 886 | + } else if part.eq_ignore_ascii_case("super") || part.eq_ignore_ascii_case("win") { | ||
| 887 | + modifiers |= Modifiers::SUPER; | ||
| 888 | + } else if part.eq_ignore_ascii_case("iso_level3_shift") | ||
| 889 | + || part.eq_ignore_ascii_case("mod5") | ||
| 890 | + { | ||
| 891 | + modifiers |= Modifiers::ISO_LEVEL3_SHIFT; | ||
| 892 | + } else if part.eq_ignore_ascii_case("iso_level5_shift") | ||
| 893 | + || part.eq_ignore_ascii_case("mod3") | ||
| 894 | + { | ||
| 895 | + modifiers |= Modifiers::ISO_LEVEL5_SHIFT; | ||
| 896 | + } else { | ||
| 897 | + return Err(miette!("invalid modifier: {part}")); | ||
| 898 | + } | ||
| 899 | + } | ||
| 900 | + | ||
| 901 | + let trigger = if key.eq_ignore_ascii_case("MouseLeft") { | ||
| 902 | + Trigger::MouseLeft | ||
| 903 | + } else if key.eq_ignore_ascii_case("MouseRight") { | ||
| 904 | + Trigger::MouseRight | ||
| 905 | + } else if key.eq_ignore_ascii_case("MouseMiddle") { | ||
| 906 | + Trigger::MouseMiddle | ||
| 907 | + } else if key.eq_ignore_ascii_case("MouseBack") { | ||
| 908 | + Trigger::MouseBack | ||
| 909 | + } else if key.eq_ignore_ascii_case("MouseForward") { | ||
| 910 | + Trigger::MouseForward | ||
| 911 | + } else if key.eq_ignore_ascii_case("WheelScrollDown") { | ||
| 912 | + Trigger::WheelScrollDown | ||
| 913 | + } else if key.eq_ignore_ascii_case("WheelScrollUp") { | ||
| 914 | + Trigger::WheelScrollUp | ||
| 915 | + } else if key.eq_ignore_ascii_case("WheelScrollLeft") { | ||
| 916 | + Trigger::WheelScrollLeft | ||
| 917 | + } else if key.eq_ignore_ascii_case("WheelScrollRight") { | ||
| 918 | + Trigger::WheelScrollRight | ||
| 919 | + } else if key.eq_ignore_ascii_case("TouchpadScrollDown") { | ||
| 920 | + Trigger::TouchpadScrollDown | ||
| 921 | + } else if key.eq_ignore_ascii_case("TouchpadScrollUp") { | ||
| 922 | + Trigger::TouchpadScrollUp | ||
| 923 | + } else if key.eq_ignore_ascii_case("TouchpadScrollLeft") { | ||
| 924 | + Trigger::TouchpadScrollLeft | ||
| 925 | + } else if key.eq_ignore_ascii_case("TouchpadScrollRight") { | ||
| 926 | + Trigger::TouchpadScrollRight | ||
| 927 | + } else { | ||
| 928 | + let keysym = keysym_from_name(key, KEYSYM_CASE_INSENSITIVE); | ||
| 929 | + if keysym.raw() == KEY_NoSymbol { | ||
| 930 | + return Err(miette!("invalid key: {key}")); | ||
| 931 | + } | ||
| 932 | + Trigger::Keysym(keysym) | ||
| 933 | + }; | ||
| 934 | + | ||
| 935 | + Ok(Key { trigger, modifiers }) | ||
| 936 | + } | ||
| 937 | +} | ||
| 938 | + | ||
| 939 | +#[cfg(test)] | ||
| 940 | +mod tests { | ||
| 941 | + use super::*; | ||
| 942 | + | ||
| 943 | + #[test] | ||
| 944 | + fn parse_iso_level_shifts() { | ||
| 945 | + assert_eq!( | ||
| 946 | + "ISO_Level3_Shift+A".parse::<Key>().unwrap(), | ||
| 947 | + Key { | ||
| 948 | + trigger: Trigger::Keysym(Keysym::a), | ||
| 949 | + modifiers: Modifiers::ISO_LEVEL3_SHIFT | ||
| 950 | + }, | ||
| 951 | + ); | ||
| 952 | + assert_eq!( | ||
| 953 | + "Mod5+A".parse::<Key>().unwrap(), | ||
| 954 | + Key { | ||
| 955 | + trigger: Trigger::Keysym(Keysym::a), | ||
| 956 | + modifiers: Modifiers::ISO_LEVEL3_SHIFT | ||
| 957 | + }, | ||
| 958 | + ); | ||
| 959 | + | ||
| 960 | + assert_eq!( | ||
| 961 | + "ISO_Level5_Shift+A".parse::<Key>().unwrap(), | ||
| 962 | + Key { | ||
| 963 | + trigger: Trigger::Keysym(Keysym::a), | ||
| 964 | + modifiers: Modifiers::ISO_LEVEL5_SHIFT | ||
| 965 | + }, | ||
| 966 | + ); | ||
| 967 | + assert_eq!( | ||
| 968 | + "Mod3+A".parse::<Key>().unwrap(), | ||
| 969 | + Key { | ||
| 970 | + trigger: Trigger::Keysym(Keysym::a), | ||
| 971 | + modifiers: Modifiers::ISO_LEVEL5_SHIFT | ||
| 972 | + }, | ||
| 973 | + ); | ||
| 974 | + } | ||
| 975 | +} | ||
niri-config/src/input.rsmodified+2 -1
| @@ -4,7 +4,8 @@ use miette::miette; | |||
| 4 | use smithay::input::keyboard::XkbConfig; | 4 | use smithay::input::keyboard::XkbConfig; |
| 5 | use smithay::reexports::input; | 5 | use smithay::reexports::input; |
| 6 | 6 | ||
| 7 | -use crate::{FloatOrInt, Modifiers, Percent}; | 7 | +use crate::binds::Modifiers; |
| 8 | +use crate::{FloatOrInt, Percent}; | ||
| 8 | 9 | ||
| 9 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 10 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 10 | pub struct Input { | 11 | pub struct Input { |
niri-config/src/lib.rsmodified+2 -965
| @@ -1,26 +1,18 @@ | |||
| 1 | #[macro_use] | 1 | #[macro_use] |
| 2 | extern crate tracing; | 2 | extern crate tracing; |
| 3 | 3 | ||
| 4 | -use std::collections::HashSet; | ||
| 5 | use std::ffi::OsStr; | 4 | use std::ffi::OsStr; |
| 6 | use std::fs::{self, File}; | 5 | use std::fs::{self, File}; |
| 7 | use std::io::Write; | 6 | use std::io::Write; |
| 8 | use std::path::{Path, PathBuf}; | 7 | use std::path::{Path, PathBuf}; |
| 9 | use std::str::FromStr; | 8 | use std::str::FromStr; |
| 10 | -use std::time::Duration; | ||
| 11 | 9 | ||
| 12 | -use bitflags::bitflags; | ||
| 13 | use knuffel::errors::DecodeError; | 10 | use knuffel::errors::DecodeError; |
| 14 | use miette::{miette, Context, IntoDiagnostic}; | 11 | use miette::{miette, Context, IntoDiagnostic}; |
| 15 | -use niri_ipc::{ | ||
| 16 | - ColumnDisplay, LayoutSwitchTarget, PositionChange, SizeChange, WorkspaceReferenceArg, | ||
| 17 | -}; | ||
| 18 | -use smithay::input::keyboard::keysyms::KEY_NoSymbol; | ||
| 19 | -use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE}; | ||
| 20 | -use smithay::input::keyboard::Keysym; | ||
| 21 | 12 | ||
| 22 | pub mod animations; | 13 | pub mod animations; |
| 23 | pub mod appearance; | 14 | pub mod appearance; |
| 15 | +pub mod binds; | ||
| 24 | pub mod debug; | 16 | pub mod debug; |
| 25 | pub mod gestures; | 17 | pub mod gestures; |
| 26 | pub mod input; | 18 | pub mod input; |
| @@ -34,6 +26,7 @@ pub use crate::animations::{ | |||
| 34 | Animation, AnimationCurve, AnimationKind, Animations, EasingParams, SpringParams, | 26 | Animation, AnimationCurve, AnimationKind, Animations, EasingParams, SpringParams, |
| 35 | }; | 27 | }; |
| 36 | pub use crate::appearance::*; | 28 | pub use crate::appearance::*; |
| 29 | +pub use crate::binds::*; | ||
| 37 | pub use crate::debug::DebugConfig; | 30 | pub use crate::debug::DebugConfig; |
| 38 | pub use crate::gestures::Gestures; | 31 | pub use crate::gestures::Gestures; |
| 39 | pub use crate::input::{Input, ModKey, ScrollMethod, TrackLayout, WarpMouseToFocusMode, Xkb}; | 32 | pub use crate::input::{Input, ModKey, ScrollMethod, TrackLayout, WarpMouseToFocusMode, Xkb}; |
| @@ -217,663 +210,6 @@ pub struct Workspace { | |||
| 217 | #[derive(Debug, Clone, PartialEq, Eq)] | 210 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 218 | pub struct WorkspaceName(pub String); | 211 | pub struct WorkspaceName(pub String); |
| 219 | 212 | ||
| 220 | -#[derive(Debug, Default, PartialEq)] | ||
| 221 | -pub struct Binds(pub Vec<Bind>); | ||
| 222 | - | ||
| 223 | -#[derive(Debug, Clone, PartialEq)] | ||
| 224 | -pub struct Bind { | ||
| 225 | - pub key: Key, | ||
| 226 | - pub action: Action, | ||
| 227 | - pub repeat: bool, | ||
| 228 | - pub cooldown: Option<Duration>, | ||
| 229 | - pub allow_when_locked: bool, | ||
| 230 | - pub allow_inhibiting: bool, | ||
| 231 | - pub hotkey_overlay_title: Option<Option<String>>, | ||
| 232 | -} | ||
| 233 | - | ||
| 234 | -#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] | ||
| 235 | -pub struct Key { | ||
| 236 | - pub trigger: Trigger, | ||
| 237 | - pub modifiers: Modifiers, | ||
| 238 | -} | ||
| 239 | - | ||
| 240 | -#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] | ||
| 241 | -pub enum Trigger { | ||
| 242 | - Keysym(Keysym), | ||
| 243 | - MouseLeft, | ||
| 244 | - MouseRight, | ||
| 245 | - MouseMiddle, | ||
| 246 | - MouseBack, | ||
| 247 | - MouseForward, | ||
| 248 | - WheelScrollDown, | ||
| 249 | - WheelScrollUp, | ||
| 250 | - WheelScrollLeft, | ||
| 251 | - WheelScrollRight, | ||
| 252 | - TouchpadScrollDown, | ||
| 253 | - TouchpadScrollUp, | ||
| 254 | - TouchpadScrollLeft, | ||
| 255 | - TouchpadScrollRight, | ||
| 256 | -} | ||
| 257 | - | ||
| 258 | -bitflags! { | ||
| 259 | - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| 260 | - pub struct Modifiers : u8 { | ||
| 261 | - const CTRL = 1; | ||
| 262 | - const SHIFT = 1 << 1; | ||
| 263 | - const ALT = 1 << 2; | ||
| 264 | - const SUPER = 1 << 3; | ||
| 265 | - const ISO_LEVEL3_SHIFT = 1 << 4; | ||
| 266 | - const ISO_LEVEL5_SHIFT = 1 << 5; | ||
| 267 | - const COMPOSITOR = 1 << 6; | ||
| 268 | - } | ||
| 269 | -} | ||
| 270 | - | ||
| 271 | -#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] | ||
| 272 | -pub struct SwitchBinds { | ||
| 273 | - #[knuffel(child)] | ||
| 274 | - pub lid_open: Option<SwitchAction>, | ||
| 275 | - #[knuffel(child)] | ||
| 276 | - pub lid_close: Option<SwitchAction>, | ||
| 277 | - #[knuffel(child)] | ||
| 278 | - pub tablet_mode_on: Option<SwitchAction>, | ||
| 279 | - #[knuffel(child)] | ||
| 280 | - pub tablet_mode_off: Option<SwitchAction>, | ||
| 281 | -} | ||
| 282 | - | ||
| 283 | -#[derive(knuffel::Decode, Debug, Clone, PartialEq)] | ||
| 284 | -pub struct SwitchAction { | ||
| 285 | - #[knuffel(child, unwrap(arguments))] | ||
| 286 | - pub spawn: Vec<String>, | ||
| 287 | -} | ||
| 288 | - | ||
| 289 | -// Remember to add new actions to the CLI enum too. | ||
| 290 | -#[derive(knuffel::Decode, Debug, Clone, PartialEq)] | ||
| 291 | -pub enum Action { | ||
| 292 | - Quit(#[knuffel(property(name = "skip-confirmation"), default)] bool), | ||
| 293 | - #[knuffel(skip)] | ||
| 294 | - ChangeVt(i32), | ||
| 295 | - Suspend, | ||
| 296 | - PowerOffMonitors, | ||
| 297 | - PowerOnMonitors, | ||
| 298 | - ToggleDebugTint, | ||
| 299 | - DebugToggleOpaqueRegions, | ||
| 300 | - DebugToggleDamage, | ||
| 301 | - Spawn(#[knuffel(arguments)] Vec<String>), | ||
| 302 | - SpawnSh(#[knuffel(argument)] String), | ||
| 303 | - DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option<u16>), | ||
| 304 | - #[knuffel(skip)] | ||
| 305 | - ConfirmScreenshot { | ||
| 306 | - write_to_disk: bool, | ||
| 307 | - }, | ||
| 308 | - #[knuffel(skip)] | ||
| 309 | - CancelScreenshot, | ||
| 310 | - #[knuffel(skip)] | ||
| 311 | - ScreenshotTogglePointer, | ||
| 312 | - Screenshot(#[knuffel(property(name = "show-pointer"), default = true)] bool), | ||
| 313 | - ScreenshotScreen( | ||
| 314 | - #[knuffel(property(name = "write-to-disk"), default = true)] bool, | ||
| 315 | - #[knuffel(property(name = "show-pointer"), default = true)] bool, | ||
| 316 | - ), | ||
| 317 | - ScreenshotWindow(#[knuffel(property(name = "write-to-disk"), default = true)] bool), | ||
| 318 | - #[knuffel(skip)] | ||
| 319 | - ScreenshotWindowById { | ||
| 320 | - id: u64, | ||
| 321 | - write_to_disk: bool, | ||
| 322 | - }, | ||
| 323 | - ToggleKeyboardShortcutsInhibit, | ||
| 324 | - CloseWindow, | ||
| 325 | - #[knuffel(skip)] | ||
| 326 | - CloseWindowById(u64), | ||
| 327 | - FullscreenWindow, | ||
| 328 | - #[knuffel(skip)] | ||
| 329 | - FullscreenWindowById(u64), | ||
| 330 | - ToggleWindowedFullscreen, | ||
| 331 | - #[knuffel(skip)] | ||
| 332 | - ToggleWindowedFullscreenById(u64), | ||
| 333 | - #[knuffel(skip)] | ||
| 334 | - FocusWindow(u64), | ||
| 335 | - FocusWindowInColumn(#[knuffel(argument)] u8), | ||
| 336 | - FocusWindowPrevious, | ||
| 337 | - FocusColumnLeft, | ||
| 338 | - #[knuffel(skip)] | ||
| 339 | - FocusColumnLeftUnderMouse, | ||
| 340 | - FocusColumnRight, | ||
| 341 | - #[knuffel(skip)] | ||
| 342 | - FocusColumnRightUnderMouse, | ||
| 343 | - FocusColumnFirst, | ||
| 344 | - FocusColumnLast, | ||
| 345 | - FocusColumnRightOrFirst, | ||
| 346 | - FocusColumnLeftOrLast, | ||
| 347 | - FocusColumn(#[knuffel(argument)] usize), | ||
| 348 | - FocusWindowOrMonitorUp, | ||
| 349 | - FocusWindowOrMonitorDown, | ||
| 350 | - FocusColumnOrMonitorLeft, | ||
| 351 | - FocusColumnOrMonitorRight, | ||
| 352 | - FocusWindowDown, | ||
| 353 | - FocusWindowUp, | ||
| 354 | - FocusWindowDownOrColumnLeft, | ||
| 355 | - FocusWindowDownOrColumnRight, | ||
| 356 | - FocusWindowUpOrColumnLeft, | ||
| 357 | - FocusWindowUpOrColumnRight, | ||
| 358 | - FocusWindowOrWorkspaceDown, | ||
| 359 | - FocusWindowOrWorkspaceUp, | ||
| 360 | - FocusWindowTop, | ||
| 361 | - FocusWindowBottom, | ||
| 362 | - FocusWindowDownOrTop, | ||
| 363 | - FocusWindowUpOrBottom, | ||
| 364 | - MoveColumnLeft, | ||
| 365 | - MoveColumnRight, | ||
| 366 | - MoveColumnToFirst, | ||
| 367 | - MoveColumnToLast, | ||
| 368 | - MoveColumnLeftOrToMonitorLeft, | ||
| 369 | - MoveColumnRightOrToMonitorRight, | ||
| 370 | - MoveColumnToIndex(#[knuffel(argument)] usize), | ||
| 371 | - MoveWindowDown, | ||
| 372 | - MoveWindowUp, | ||
| 373 | - MoveWindowDownOrToWorkspaceDown, | ||
| 374 | - MoveWindowUpOrToWorkspaceUp, | ||
| 375 | - ConsumeOrExpelWindowLeft, | ||
| 376 | - #[knuffel(skip)] | ||
| 377 | - ConsumeOrExpelWindowLeftById(u64), | ||
| 378 | - ConsumeOrExpelWindowRight, | ||
| 379 | - #[knuffel(skip)] | ||
| 380 | - ConsumeOrExpelWindowRightById(u64), | ||
| 381 | - ConsumeWindowIntoColumn, | ||
| 382 | - ExpelWindowFromColumn, | ||
| 383 | - SwapWindowLeft, | ||
| 384 | - SwapWindowRight, | ||
| 385 | - ToggleColumnTabbedDisplay, | ||
| 386 | - SetColumnDisplay(#[knuffel(argument, str)] ColumnDisplay), | ||
| 387 | - CenterColumn, | ||
| 388 | - CenterWindow, | ||
| 389 | - #[knuffel(skip)] | ||
| 390 | - CenterWindowById(u64), | ||
| 391 | - CenterVisibleColumns, | ||
| 392 | - FocusWorkspaceDown, | ||
| 393 | - #[knuffel(skip)] | ||
| 394 | - FocusWorkspaceDownUnderMouse, | ||
| 395 | - FocusWorkspaceUp, | ||
| 396 | - #[knuffel(skip)] | ||
| 397 | - FocusWorkspaceUpUnderMouse, | ||
| 398 | - FocusWorkspace(#[knuffel(argument)] WorkspaceReference), | ||
| 399 | - FocusWorkspacePrevious, | ||
| 400 | - MoveWindowToWorkspaceDown(#[knuffel(property(name = "focus"), default = true)] bool), | ||
| 401 | - MoveWindowToWorkspaceUp(#[knuffel(property(name = "focus"), default = true)] bool), | ||
| 402 | - MoveWindowToWorkspace( | ||
| 403 | - #[knuffel(argument)] WorkspaceReference, | ||
| 404 | - #[knuffel(property(name = "focus"), default = true)] bool, | ||
| 405 | - ), | ||
| 406 | - #[knuffel(skip)] | ||
| 407 | - MoveWindowToWorkspaceById { | ||
| 408 | - window_id: u64, | ||
| 409 | - reference: WorkspaceReference, | ||
| 410 | - focus: bool, | ||
| 411 | - }, | ||
| 412 | - MoveColumnToWorkspaceDown(#[knuffel(property(name = "focus"), default = true)] bool), | ||
| 413 | - MoveColumnToWorkspaceUp(#[knuffel(property(name = "focus"), default = true)] bool), | ||
| 414 | - MoveColumnToWorkspace( | ||
| 415 | - #[knuffel(argument)] WorkspaceReference, | ||
| 416 | - #[knuffel(property(name = "focus"), default = true)] bool, | ||
| 417 | - ), | ||
| 418 | - MoveWorkspaceDown, | ||
| 419 | - MoveWorkspaceUp, | ||
| 420 | - MoveWorkspaceToIndex(#[knuffel(argument)] usize), | ||
| 421 | - #[knuffel(skip)] | ||
| 422 | - MoveWorkspaceToIndexByRef { | ||
| 423 | - new_idx: usize, | ||
| 424 | - reference: WorkspaceReference, | ||
| 425 | - }, | ||
| 426 | - #[knuffel(skip)] | ||
| 427 | - MoveWorkspaceToMonitorByRef { | ||
| 428 | - output_name: String, | ||
| 429 | - reference: WorkspaceReference, | ||
| 430 | - }, | ||
| 431 | - MoveWorkspaceToMonitor(#[knuffel(argument)] String), | ||
| 432 | - SetWorkspaceName(#[knuffel(argument)] String), | ||
| 433 | - #[knuffel(skip)] | ||
| 434 | - SetWorkspaceNameByRef { | ||
| 435 | - name: String, | ||
| 436 | - reference: WorkspaceReference, | ||
| 437 | - }, | ||
| 438 | - UnsetWorkspaceName, | ||
| 439 | - #[knuffel(skip)] | ||
| 440 | - UnsetWorkSpaceNameByRef(#[knuffel(argument)] WorkspaceReference), | ||
| 441 | - FocusMonitorLeft, | ||
| 442 | - FocusMonitorRight, | ||
| 443 | - FocusMonitorDown, | ||
| 444 | - FocusMonitorUp, | ||
| 445 | - FocusMonitorPrevious, | ||
| 446 | - FocusMonitorNext, | ||
| 447 | - FocusMonitor(#[knuffel(argument)] String), | ||
| 448 | - MoveWindowToMonitorLeft, | ||
| 449 | - MoveWindowToMonitorRight, | ||
| 450 | - MoveWindowToMonitorDown, | ||
| 451 | - MoveWindowToMonitorUp, | ||
| 452 | - MoveWindowToMonitorPrevious, | ||
| 453 | - MoveWindowToMonitorNext, | ||
| 454 | - MoveWindowToMonitor(#[knuffel(argument)] String), | ||
| 455 | - #[knuffel(skip)] | ||
| 456 | - MoveWindowToMonitorById { | ||
| 457 | - id: u64, | ||
| 458 | - output: String, | ||
| 459 | - }, | ||
| 460 | - MoveColumnToMonitorLeft, | ||
| 461 | - MoveColumnToMonitorRight, | ||
| 462 | - MoveColumnToMonitorDown, | ||
| 463 | - MoveColumnToMonitorUp, | ||
| 464 | - MoveColumnToMonitorPrevious, | ||
| 465 | - MoveColumnToMonitorNext, | ||
| 466 | - MoveColumnToMonitor(#[knuffel(argument)] String), | ||
| 467 | - SetWindowWidth(#[knuffel(argument, str)] SizeChange), | ||
| 468 | - #[knuffel(skip)] | ||
| 469 | - SetWindowWidthById { | ||
| 470 | - id: u64, | ||
| 471 | - change: SizeChange, | ||
| 472 | - }, | ||
| 473 | - SetWindowHeight(#[knuffel(argument, str)] SizeChange), | ||
| 474 | - #[knuffel(skip)] | ||
| 475 | - SetWindowHeightById { | ||
| 476 | - id: u64, | ||
| 477 | - change: SizeChange, | ||
| 478 | - }, | ||
| 479 | - ResetWindowHeight, | ||
| 480 | - #[knuffel(skip)] | ||
| 481 | - ResetWindowHeightById(u64), | ||
| 482 | - SwitchPresetColumnWidth, | ||
| 483 | - SwitchPresetWindowWidth, | ||
| 484 | - #[knuffel(skip)] | ||
| 485 | - SwitchPresetWindowWidthById(u64), | ||
| 486 | - SwitchPresetWindowHeight, | ||
| 487 | - #[knuffel(skip)] | ||
| 488 | - SwitchPresetWindowHeightById(u64), | ||
| 489 | - MaximizeColumn, | ||
| 490 | - SetColumnWidth(#[knuffel(argument, str)] SizeChange), | ||
| 491 | - ExpandColumnToAvailableWidth, | ||
| 492 | - SwitchLayout(#[knuffel(argument, str)] LayoutSwitchTarget), | ||
| 493 | - ShowHotkeyOverlay, | ||
| 494 | - MoveWorkspaceToMonitorLeft, | ||
| 495 | - MoveWorkspaceToMonitorRight, | ||
| 496 | - MoveWorkspaceToMonitorDown, | ||
| 497 | - MoveWorkspaceToMonitorUp, | ||
| 498 | - MoveWorkspaceToMonitorPrevious, | ||
| 499 | - MoveWorkspaceToMonitorNext, | ||
| 500 | - ToggleWindowFloating, | ||
| 501 | - #[knuffel(skip)] | ||
| 502 | - ToggleWindowFloatingById(u64), | ||
| 503 | - MoveWindowToFloating, | ||
| 504 | - #[knuffel(skip)] | ||
| 505 | - MoveWindowToFloatingById(u64), | ||
| 506 | - MoveWindowToTiling, | ||
| 507 | - #[knuffel(skip)] | ||
| 508 | - MoveWindowToTilingById(u64), | ||
| 509 | - FocusFloating, | ||
| 510 | - FocusTiling, | ||
| 511 | - SwitchFocusBetweenFloatingAndTiling, | ||
| 512 | - #[knuffel(skip)] | ||
| 513 | - MoveFloatingWindowById { | ||
| 514 | - id: Option<u64>, | ||
| 515 | - x: PositionChange, | ||
| 516 | - y: PositionChange, | ||
| 517 | - }, | ||
| 518 | - ToggleWindowRuleOpacity, | ||
| 519 | - #[knuffel(skip)] | ||
| 520 | - ToggleWindowRuleOpacityById(u64), | ||
| 521 | - SetDynamicCastWindow, | ||
| 522 | - #[knuffel(skip)] | ||
| 523 | - SetDynamicCastWindowById(u64), | ||
| 524 | - SetDynamicCastMonitor(#[knuffel(argument)] Option<String>), | ||
| 525 | - ClearDynamicCastTarget, | ||
| 526 | - ToggleOverview, | ||
| 527 | - OpenOverview, | ||
| 528 | - CloseOverview, | ||
| 529 | - #[knuffel(skip)] | ||
| 530 | - ToggleWindowUrgent(u64), | ||
| 531 | - #[knuffel(skip)] | ||
| 532 | - SetWindowUrgent(u64), | ||
| 533 | - #[knuffel(skip)] | ||
| 534 | - UnsetWindowUrgent(u64), | ||
| 535 | - #[knuffel(skip)] | ||
| 536 | - LoadConfigFile, | ||
| 537 | -} | ||
| 538 | - | ||
| 539 | -impl From<niri_ipc::Action> for Action { | ||
| 540 | - fn from(value: niri_ipc::Action) -> Self { | ||
| 541 | - match value { | ||
| 542 | - niri_ipc::Action::Quit { skip_confirmation } => Self::Quit(skip_confirmation), | ||
| 543 | - niri_ipc::Action::PowerOffMonitors {} => Self::PowerOffMonitors, | ||
| 544 | - niri_ipc::Action::PowerOnMonitors {} => Self::PowerOnMonitors, | ||
| 545 | - niri_ipc::Action::Spawn { command } => Self::Spawn(command), | ||
| 546 | - niri_ipc::Action::SpawnSh { command } => Self::SpawnSh(command), | ||
| 547 | - niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms), | ||
| 548 | - niri_ipc::Action::Screenshot { show_pointer } => Self::Screenshot(show_pointer), | ||
| 549 | - niri_ipc::Action::ScreenshotScreen { | ||
| 550 | - write_to_disk, | ||
| 551 | - show_pointer, | ||
| 552 | - } => Self::ScreenshotScreen(write_to_disk, show_pointer), | ||
| 553 | - niri_ipc::Action::ScreenshotWindow { | ||
| 554 | - id: None, | ||
| 555 | - write_to_disk, | ||
| 556 | - } => Self::ScreenshotWindow(write_to_disk), | ||
| 557 | - niri_ipc::Action::ScreenshotWindow { | ||
| 558 | - id: Some(id), | ||
| 559 | - write_to_disk, | ||
| 560 | - } => Self::ScreenshotWindowById { id, write_to_disk }, | ||
| 561 | - niri_ipc::Action::ToggleKeyboardShortcutsInhibit {} => { | ||
| 562 | - Self::ToggleKeyboardShortcutsInhibit | ||
| 563 | - } | ||
| 564 | - niri_ipc::Action::CloseWindow { id: None } => Self::CloseWindow, | ||
| 565 | - niri_ipc::Action::CloseWindow { id: Some(id) } => Self::CloseWindowById(id), | ||
| 566 | - niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow, | ||
| 567 | - niri_ipc::Action::FullscreenWindow { id: Some(id) } => Self::FullscreenWindowById(id), | ||
| 568 | - niri_ipc::Action::ToggleWindowedFullscreen { id: None } => { | ||
| 569 | - Self::ToggleWindowedFullscreen | ||
| 570 | - } | ||
| 571 | - niri_ipc::Action::ToggleWindowedFullscreen { id: Some(id) } => { | ||
| 572 | - Self::ToggleWindowedFullscreenById(id) | ||
| 573 | - } | ||
| 574 | - niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id), | ||
| 575 | - niri_ipc::Action::FocusWindowInColumn { index } => Self::FocusWindowInColumn(index), | ||
| 576 | - niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious, | ||
| 577 | - niri_ipc::Action::FocusColumnLeft {} => Self::FocusColumnLeft, | ||
| 578 | - niri_ipc::Action::FocusColumnRight {} => Self::FocusColumnRight, | ||
| 579 | - niri_ipc::Action::FocusColumnFirst {} => Self::FocusColumnFirst, | ||
| 580 | - niri_ipc::Action::FocusColumnLast {} => Self::FocusColumnLast, | ||
| 581 | - niri_ipc::Action::FocusColumnRightOrFirst {} => Self::FocusColumnRightOrFirst, | ||
| 582 | - niri_ipc::Action::FocusColumnLeftOrLast {} => Self::FocusColumnLeftOrLast, | ||
| 583 | - niri_ipc::Action::FocusColumn { index } => Self::FocusColumn(index), | ||
| 584 | - niri_ipc::Action::FocusWindowOrMonitorUp {} => Self::FocusWindowOrMonitorUp, | ||
| 585 | - niri_ipc::Action::FocusWindowOrMonitorDown {} => Self::FocusWindowOrMonitorDown, | ||
| 586 | - niri_ipc::Action::FocusColumnOrMonitorLeft {} => Self::FocusColumnOrMonitorLeft, | ||
| 587 | - niri_ipc::Action::FocusColumnOrMonitorRight {} => Self::FocusColumnOrMonitorRight, | ||
| 588 | - niri_ipc::Action::FocusWindowDown {} => Self::FocusWindowDown, | ||
| 589 | - niri_ipc::Action::FocusWindowUp {} => Self::FocusWindowUp, | ||
| 590 | - niri_ipc::Action::FocusWindowDownOrColumnLeft {} => Self::FocusWindowDownOrColumnLeft, | ||
| 591 | - niri_ipc::Action::FocusWindowDownOrColumnRight {} => Self::FocusWindowDownOrColumnRight, | ||
| 592 | - niri_ipc::Action::FocusWindowUpOrColumnLeft {} => Self::FocusWindowUpOrColumnLeft, | ||
| 593 | - niri_ipc::Action::FocusWindowUpOrColumnRight {} => Self::FocusWindowUpOrColumnRight, | ||
| 594 | - niri_ipc::Action::FocusWindowOrWorkspaceDown {} => Self::FocusWindowOrWorkspaceDown, | ||
| 595 | - niri_ipc::Action::FocusWindowOrWorkspaceUp {} => Self::FocusWindowOrWorkspaceUp, | ||
| 596 | - niri_ipc::Action::FocusWindowTop {} => Self::FocusWindowTop, | ||
| 597 | - niri_ipc::Action::FocusWindowBottom {} => Self::FocusWindowBottom, | ||
| 598 | - niri_ipc::Action::FocusWindowDownOrTop {} => Self::FocusWindowDownOrTop, | ||
| 599 | - niri_ipc::Action::FocusWindowUpOrBottom {} => Self::FocusWindowUpOrBottom, | ||
| 600 | - niri_ipc::Action::MoveColumnLeft {} => Self::MoveColumnLeft, | ||
| 601 | - niri_ipc::Action::MoveColumnRight {} => Self::MoveColumnRight, | ||
| 602 | - niri_ipc::Action::MoveColumnToFirst {} => Self::MoveColumnToFirst, | ||
| 603 | - niri_ipc::Action::MoveColumnToLast {} => Self::MoveColumnToLast, | ||
| 604 | - niri_ipc::Action::MoveColumnToIndex { index } => Self::MoveColumnToIndex(index), | ||
| 605 | - niri_ipc::Action::MoveColumnLeftOrToMonitorLeft {} => { | ||
| 606 | - Self::MoveColumnLeftOrToMonitorLeft | ||
| 607 | - } | ||
| 608 | - niri_ipc::Action::MoveColumnRightOrToMonitorRight {} => { | ||
| 609 | - Self::MoveColumnRightOrToMonitorRight | ||
| 610 | - } | ||
| 611 | - niri_ipc::Action::MoveWindowDown {} => Self::MoveWindowDown, | ||
| 612 | - niri_ipc::Action::MoveWindowUp {} => Self::MoveWindowUp, | ||
| 613 | - niri_ipc::Action::MoveWindowDownOrToWorkspaceDown {} => { | ||
| 614 | - Self::MoveWindowDownOrToWorkspaceDown | ||
| 615 | - } | ||
| 616 | - niri_ipc::Action::MoveWindowUpOrToWorkspaceUp {} => Self::MoveWindowUpOrToWorkspaceUp, | ||
| 617 | - niri_ipc::Action::ConsumeOrExpelWindowLeft { id: None } => { | ||
| 618 | - Self::ConsumeOrExpelWindowLeft | ||
| 619 | - } | ||
| 620 | - niri_ipc::Action::ConsumeOrExpelWindowLeft { id: Some(id) } => { | ||
| 621 | - Self::ConsumeOrExpelWindowLeftById(id) | ||
| 622 | - } | ||
| 623 | - niri_ipc::Action::ConsumeOrExpelWindowRight { id: None } => { | ||
| 624 | - Self::ConsumeOrExpelWindowRight | ||
| 625 | - } | ||
| 626 | - niri_ipc::Action::ConsumeOrExpelWindowRight { id: Some(id) } => { | ||
| 627 | - Self::ConsumeOrExpelWindowRightById(id) | ||
| 628 | - } | ||
| 629 | - niri_ipc::Action::ConsumeWindowIntoColumn {} => Self::ConsumeWindowIntoColumn, | ||
| 630 | - niri_ipc::Action::ExpelWindowFromColumn {} => Self::ExpelWindowFromColumn, | ||
| 631 | - niri_ipc::Action::SwapWindowRight {} => Self::SwapWindowRight, | ||
| 632 | - niri_ipc::Action::SwapWindowLeft {} => Self::SwapWindowLeft, | ||
| 633 | - niri_ipc::Action::ToggleColumnTabbedDisplay {} => Self::ToggleColumnTabbedDisplay, | ||
| 634 | - niri_ipc::Action::SetColumnDisplay { display } => Self::SetColumnDisplay(display), | ||
| 635 | - niri_ipc::Action::CenterColumn {} => Self::CenterColumn, | ||
| 636 | - niri_ipc::Action::CenterWindow { id: None } => Self::CenterWindow, | ||
| 637 | - niri_ipc::Action::CenterWindow { id: Some(id) } => Self::CenterWindowById(id), | ||
| 638 | - niri_ipc::Action::CenterVisibleColumns {} => Self::CenterVisibleColumns, | ||
| 639 | - niri_ipc::Action::FocusWorkspaceDown {} => Self::FocusWorkspaceDown, | ||
| 640 | - niri_ipc::Action::FocusWorkspaceUp {} => Self::FocusWorkspaceUp, | ||
| 641 | - niri_ipc::Action::FocusWorkspace { reference } => { | ||
| 642 | - Self::FocusWorkspace(WorkspaceReference::from(reference)) | ||
| 643 | - } | ||
| 644 | - niri_ipc::Action::FocusWorkspacePrevious {} => Self::FocusWorkspacePrevious, | ||
| 645 | - niri_ipc::Action::MoveWindowToWorkspaceDown { focus } => { | ||
| 646 | - Self::MoveWindowToWorkspaceDown(focus) | ||
| 647 | - } | ||
| 648 | - niri_ipc::Action::MoveWindowToWorkspaceUp { focus } => { | ||
| 649 | - Self::MoveWindowToWorkspaceUp(focus) | ||
| 650 | - } | ||
| 651 | - niri_ipc::Action::MoveWindowToWorkspace { | ||
| 652 | - window_id: None, | ||
| 653 | - reference, | ||
| 654 | - focus, | ||
| 655 | - } => Self::MoveWindowToWorkspace(WorkspaceReference::from(reference), focus), | ||
| 656 | - niri_ipc::Action::MoveWindowToWorkspace { | ||
| 657 | - window_id: Some(window_id), | ||
| 658 | - reference, | ||
| 659 | - focus, | ||
| 660 | - } => Self::MoveWindowToWorkspaceById { | ||
| 661 | - window_id, | ||
| 662 | - reference: WorkspaceReference::from(reference), | ||
| 663 | - focus, | ||
| 664 | - }, | ||
| 665 | - niri_ipc::Action::MoveColumnToWorkspaceDown { focus } => { | ||
| 666 | - Self::MoveColumnToWorkspaceDown(focus) | ||
| 667 | - } | ||
| 668 | - niri_ipc::Action::MoveColumnToWorkspaceUp { focus } => { | ||
| 669 | - Self::MoveColumnToWorkspaceUp(focus) | ||
| 670 | - } | ||
| 671 | - niri_ipc::Action::MoveColumnToWorkspace { reference, focus } => { | ||
| 672 | - Self::MoveColumnToWorkspace(WorkspaceReference::from(reference), focus) | ||
| 673 | - } | ||
| 674 | - niri_ipc::Action::MoveWorkspaceDown {} => Self::MoveWorkspaceDown, | ||
| 675 | - niri_ipc::Action::MoveWorkspaceUp {} => Self::MoveWorkspaceUp, | ||
| 676 | - niri_ipc::Action::SetWorkspaceName { | ||
| 677 | - name, | ||
| 678 | - workspace: None, | ||
| 679 | - } => Self::SetWorkspaceName(name), | ||
| 680 | - niri_ipc::Action::SetWorkspaceName { | ||
| 681 | - name, | ||
| 682 | - workspace: Some(reference), | ||
| 683 | - } => Self::SetWorkspaceNameByRef { | ||
| 684 | - name, | ||
| 685 | - reference: WorkspaceReference::from(reference), | ||
| 686 | - }, | ||
| 687 | - niri_ipc::Action::UnsetWorkspaceName { reference: None } => Self::UnsetWorkspaceName, | ||
| 688 | - niri_ipc::Action::UnsetWorkspaceName { | ||
| 689 | - reference: Some(reference), | ||
| 690 | - } => Self::UnsetWorkSpaceNameByRef(WorkspaceReference::from(reference)), | ||
| 691 | - niri_ipc::Action::FocusMonitorLeft {} => Self::FocusMonitorLeft, | ||
| 692 | - niri_ipc::Action::FocusMonitorRight {} => Self::FocusMonitorRight, | ||
| 693 | - niri_ipc::Action::FocusMonitorDown {} => Self::FocusMonitorDown, | ||
| 694 | - niri_ipc::Action::FocusMonitorUp {} => Self::FocusMonitorUp, | ||
| 695 | - niri_ipc::Action::FocusMonitorPrevious {} => Self::FocusMonitorPrevious, | ||
| 696 | - niri_ipc::Action::FocusMonitorNext {} => Self::FocusMonitorNext, | ||
| 697 | - niri_ipc::Action::FocusMonitor { output } => Self::FocusMonitor(output), | ||
| 698 | - niri_ipc::Action::MoveWindowToMonitorLeft {} => Self::MoveWindowToMonitorLeft, | ||
| 699 | - niri_ipc::Action::MoveWindowToMonitorRight {} => Self::MoveWindowToMonitorRight, | ||
| 700 | - niri_ipc::Action::MoveWindowToMonitorDown {} => Self::MoveWindowToMonitorDown, | ||
| 701 | - niri_ipc::Action::MoveWindowToMonitorUp {} => Self::MoveWindowToMonitorUp, | ||
| 702 | - niri_ipc::Action::MoveWindowToMonitorPrevious {} => Self::MoveWindowToMonitorPrevious, | ||
| 703 | - niri_ipc::Action::MoveWindowToMonitorNext {} => Self::MoveWindowToMonitorNext, | ||
| 704 | - niri_ipc::Action::MoveWindowToMonitor { id: None, output } => { | ||
| 705 | - Self::MoveWindowToMonitor(output) | ||
| 706 | - } | ||
| 707 | - niri_ipc::Action::MoveWindowToMonitor { | ||
| 708 | - id: Some(id), | ||
| 709 | - output, | ||
| 710 | - } => Self::MoveWindowToMonitorById { id, output }, | ||
| 711 | - niri_ipc::Action::MoveColumnToMonitorLeft {} => Self::MoveColumnToMonitorLeft, | ||
| 712 | - niri_ipc::Action::MoveColumnToMonitorRight {} => Self::MoveColumnToMonitorRight, | ||
| 713 | - niri_ipc::Action::MoveColumnToMonitorDown {} => Self::MoveColumnToMonitorDown, | ||
| 714 | - niri_ipc::Action::MoveColumnToMonitorUp {} => Self::MoveColumnToMonitorUp, | ||
| 715 | - niri_ipc::Action::MoveColumnToMonitorPrevious {} => Self::MoveColumnToMonitorPrevious, | ||
| 716 | - niri_ipc::Action::MoveColumnToMonitorNext {} => Self::MoveColumnToMonitorNext, | ||
| 717 | - niri_ipc::Action::MoveColumnToMonitor { output } => Self::MoveColumnToMonitor(output), | ||
| 718 | - niri_ipc::Action::SetWindowWidth { id: None, change } => Self::SetWindowWidth(change), | ||
| 719 | - niri_ipc::Action::SetWindowWidth { | ||
| 720 | - id: Some(id), | ||
| 721 | - change, | ||
| 722 | - } => Self::SetWindowWidthById { id, change }, | ||
| 723 | - niri_ipc::Action::SetWindowHeight { id: None, change } => Self::SetWindowHeight(change), | ||
| 724 | - niri_ipc::Action::SetWindowHeight { | ||
| 725 | - id: Some(id), | ||
| 726 | - change, | ||
| 727 | - } => Self::SetWindowHeightById { id, change }, | ||
| 728 | - niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight, | ||
| 729 | - niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id), | ||
| 730 | - niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth, | ||
| 731 | - niri_ipc::Action::SwitchPresetWindowWidth { id: None } => Self::SwitchPresetWindowWidth, | ||
| 732 | - niri_ipc::Action::SwitchPresetWindowWidth { id: Some(id) } => { | ||
| 733 | - Self::SwitchPresetWindowWidthById(id) | ||
| 734 | - } | ||
| 735 | - niri_ipc::Action::SwitchPresetWindowHeight { id: None } => { | ||
| 736 | - Self::SwitchPresetWindowHeight | ||
| 737 | - } | ||
| 738 | - niri_ipc::Action::SwitchPresetWindowHeight { id: Some(id) } => { | ||
| 739 | - Self::SwitchPresetWindowHeightById(id) | ||
| 740 | - } | ||
| 741 | - niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn, | ||
| 742 | - niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change), | ||
| 743 | - niri_ipc::Action::ExpandColumnToAvailableWidth {} => Self::ExpandColumnToAvailableWidth, | ||
| 744 | - niri_ipc::Action::SwitchLayout { layout } => Self::SwitchLayout(layout), | ||
| 745 | - niri_ipc::Action::ShowHotkeyOverlay {} => Self::ShowHotkeyOverlay, | ||
| 746 | - niri_ipc::Action::MoveWorkspaceToMonitorLeft {} => Self::MoveWorkspaceToMonitorLeft, | ||
| 747 | - niri_ipc::Action::MoveWorkspaceToMonitorRight {} => Self::MoveWorkspaceToMonitorRight, | ||
| 748 | - niri_ipc::Action::MoveWorkspaceToMonitorDown {} => Self::MoveWorkspaceToMonitorDown, | ||
| 749 | - niri_ipc::Action::MoveWorkspaceToMonitorUp {} => Self::MoveWorkspaceToMonitorUp, | ||
| 750 | - niri_ipc::Action::MoveWorkspaceToMonitorPrevious {} => { | ||
| 751 | - Self::MoveWorkspaceToMonitorPrevious | ||
| 752 | - } | ||
| 753 | - niri_ipc::Action::MoveWorkspaceToIndex { | ||
| 754 | - index, | ||
| 755 | - reference: Some(reference), | ||
| 756 | - } => Self::MoveWorkspaceToIndexByRef { | ||
| 757 | - new_idx: index, | ||
| 758 | - reference: WorkspaceReference::from(reference), | ||
| 759 | - }, | ||
| 760 | - niri_ipc::Action::MoveWorkspaceToIndex { | ||
| 761 | - index, | ||
| 762 | - reference: None, | ||
| 763 | - } => Self::MoveWorkspaceToIndex(index), | ||
| 764 | - niri_ipc::Action::MoveWorkspaceToMonitor { | ||
| 765 | - output, | ||
| 766 | - reference: Some(reference), | ||
| 767 | - } => Self::MoveWorkspaceToMonitorByRef { | ||
| 768 | - output_name: output, | ||
| 769 | - reference: WorkspaceReference::from(reference), | ||
| 770 | - }, | ||
| 771 | - niri_ipc::Action::MoveWorkspaceToMonitor { | ||
| 772 | - output, | ||
| 773 | - reference: None, | ||
| 774 | - } => Self::MoveWorkspaceToMonitor(output), | ||
| 775 | - niri_ipc::Action::MoveWorkspaceToMonitorNext {} => Self::MoveWorkspaceToMonitorNext, | ||
| 776 | - niri_ipc::Action::ToggleDebugTint {} => Self::ToggleDebugTint, | ||
| 777 | - niri_ipc::Action::DebugToggleOpaqueRegions {} => Self::DebugToggleOpaqueRegions, | ||
| 778 | - niri_ipc::Action::DebugToggleDamage {} => Self::DebugToggleDamage, | ||
| 779 | - niri_ipc::Action::ToggleWindowFloating { id: None } => Self::ToggleWindowFloating, | ||
| 780 | - niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => { | ||
| 781 | - Self::ToggleWindowFloatingById(id) | ||
| 782 | - } | ||
| 783 | - niri_ipc::Action::MoveWindowToFloating { id: None } => Self::MoveWindowToFloating, | ||
| 784 | - niri_ipc::Action::MoveWindowToFloating { id: Some(id) } => { | ||
| 785 | - Self::MoveWindowToFloatingById(id) | ||
| 786 | - } | ||
| 787 | - niri_ipc::Action::MoveWindowToTiling { id: None } => Self::MoveWindowToTiling, | ||
| 788 | - niri_ipc::Action::MoveWindowToTiling { id: Some(id) } => { | ||
| 789 | - Self::MoveWindowToTilingById(id) | ||
| 790 | - } | ||
| 791 | - niri_ipc::Action::FocusFloating {} => Self::FocusFloating, | ||
| 792 | - niri_ipc::Action::FocusTiling {} => Self::FocusTiling, | ||
| 793 | - niri_ipc::Action::SwitchFocusBetweenFloatingAndTiling {} => { | ||
| 794 | - Self::SwitchFocusBetweenFloatingAndTiling | ||
| 795 | - } | ||
| 796 | - niri_ipc::Action::MoveFloatingWindow { id, x, y } => { | ||
| 797 | - Self::MoveFloatingWindowById { id, x, y } | ||
| 798 | - } | ||
| 799 | - niri_ipc::Action::ToggleWindowRuleOpacity { id: None } => Self::ToggleWindowRuleOpacity, | ||
| 800 | - niri_ipc::Action::ToggleWindowRuleOpacity { id: Some(id) } => { | ||
| 801 | - Self::ToggleWindowRuleOpacityById(id) | ||
| 802 | - } | ||
| 803 | - niri_ipc::Action::SetDynamicCastWindow { id: None } => Self::SetDynamicCastWindow, | ||
| 804 | - niri_ipc::Action::SetDynamicCastWindow { id: Some(id) } => { | ||
| 805 | - Self::SetDynamicCastWindowById(id) | ||
| 806 | - } | ||
| 807 | - niri_ipc::Action::SetDynamicCastMonitor { output } => { | ||
| 808 | - Self::SetDynamicCastMonitor(output) | ||
| 809 | - } | ||
| 810 | - niri_ipc::Action::ClearDynamicCastTarget {} => Self::ClearDynamicCastTarget, | ||
| 811 | - niri_ipc::Action::ToggleOverview {} => Self::ToggleOverview, | ||
| 812 | - niri_ipc::Action::OpenOverview {} => Self::OpenOverview, | ||
| 813 | - niri_ipc::Action::CloseOverview {} => Self::CloseOverview, | ||
| 814 | - niri_ipc::Action::ToggleWindowUrgent { id } => Self::ToggleWindowUrgent(id), | ||
| 815 | - niri_ipc::Action::SetWindowUrgent { id } => Self::SetWindowUrgent(id), | ||
| 816 | - niri_ipc::Action::UnsetWindowUrgent { id } => Self::UnsetWindowUrgent(id), | ||
| 817 | - niri_ipc::Action::LoadConfigFile {} => Self::LoadConfigFile, | ||
| 818 | - } | ||
| 819 | - } | ||
| 820 | -} | ||
| 821 | - | ||
| 822 | -#[derive(Debug, PartialEq, Eq, Clone)] | ||
| 823 | -pub enum WorkspaceReference { | ||
| 824 | - Id(u64), | ||
| 825 | - Index(u8), | ||
| 826 | - Name(String), | ||
| 827 | -} | ||
| 828 | - | ||
| 829 | -impl From<WorkspaceReferenceArg> for WorkspaceReference { | ||
| 830 | - fn from(reference: WorkspaceReferenceArg) -> WorkspaceReference { | ||
| 831 | - match reference { | ||
| 832 | - WorkspaceReferenceArg::Id(id) => Self::Id(id), | ||
| 833 | - WorkspaceReferenceArg::Index(i) => Self::Index(i), | ||
| 834 | - WorkspaceReferenceArg::Name(n) => Self::Name(n), | ||
| 835 | - } | ||
| 836 | - } | ||
| 837 | -} | ||
| 838 | - | ||
| 839 | -impl<S: knuffel::traits::ErrorSpan> knuffel::DecodeScalar<S> for WorkspaceReference { | ||
| 840 | - fn type_check( | ||
| 841 | - type_name: &Option<knuffel::span::Spanned<knuffel::ast::TypeName, S>>, | ||
| 842 | - ctx: &mut knuffel::decode::Context<S>, | ||
| 843 | - ) { | ||
| 844 | - if let Some(type_name) = &type_name { | ||
| 845 | - ctx.emit_error(DecodeError::unexpected( | ||
| 846 | - type_name, | ||
| 847 | - "type name", | ||
| 848 | - "no type name expected for this node", | ||
| 849 | - )); | ||
| 850 | - } | ||
| 851 | - } | ||
| 852 | - | ||
| 853 | - fn raw_decode( | ||
| 854 | - val: &knuffel::span::Spanned<knuffel::ast::Literal, S>, | ||
| 855 | - ctx: &mut knuffel::decode::Context<S>, | ||
| 856 | - ) -> Result<WorkspaceReference, DecodeError<S>> { | ||
| 857 | - match &**val { | ||
| 858 | - knuffel::ast::Literal::String(ref s) => Ok(WorkspaceReference::Name(s.clone().into())), | ||
| 859 | - knuffel::ast::Literal::Int(ref value) => match value.try_into() { | ||
| 860 | - Ok(v) => Ok(WorkspaceReference::Index(v)), | ||
| 861 | - Err(e) => { | ||
| 862 | - ctx.emit_error(DecodeError::conversion(val, e)); | ||
| 863 | - Ok(WorkspaceReference::Index(0)) | ||
| 864 | - } | ||
| 865 | - }, | ||
| 866 | - _ => { | ||
| 867 | - ctx.emit_error(DecodeError::unsupported( | ||
| 868 | - val, | ||
| 869 | - "Unsupported value, only numbers and strings are recognized", | ||
| 870 | - )); | ||
| 871 | - Ok(WorkspaceReference::Index(0)) | ||
| 872 | - } | ||
| 873 | - } | ||
| 874 | - } | ||
| 875 | -} | ||
| 876 | - | ||
| 877 | impl<S: knuffel::traits::ErrorSpan, const MIN: i32, const MAX: i32> knuffel::DecodeScalar<S> | 213 | impl<S: knuffel::traits::ErrorSpan, const MIN: i32, const MAX: i32> knuffel::DecodeScalar<S> |
| 878 | for FloatOrInt<MIN, MAX> | 214 | for FloatOrInt<MIN, MAX> |
| 879 | { | 215 | { |
| @@ -1201,271 +537,6 @@ impl<S: knuffel::traits::ErrorSpan> knuffel::DecodeScalar<S> for WorkspaceName { | |||
| 1201 | } | 537 | } |
| 1202 | } | 538 | } |
| 1203 | 539 | ||
| 1204 | -impl<S> knuffel::Decode<S> for Binds | ||
| 1205 | -where | ||
| 1206 | - S: knuffel::traits::ErrorSpan, | ||
| 1207 | -{ | ||
| 1208 | - fn decode_node( | ||
| 1209 | - node: &knuffel::ast::SpannedNode<S>, | ||
| 1210 | - ctx: &mut knuffel::decode::Context<S>, | ||
| 1211 | - ) -> Result<Self, DecodeError<S>> { | ||
| 1212 | - expect_only_children(node, ctx); | ||
| 1213 | - | ||
| 1214 | - let mut seen_keys = HashSet::new(); | ||
| 1215 | - | ||
| 1216 | - let mut binds = Vec::new(); | ||
| 1217 | - | ||
| 1218 | - for child in node.children() { | ||
| 1219 | - match Bind::decode_node(child, ctx) { | ||
| 1220 | - Err(e) => { | ||
| 1221 | - ctx.emit_error(e); | ||
| 1222 | - } | ||
| 1223 | - Ok(bind) => { | ||
| 1224 | - if seen_keys.insert(bind.key) { | ||
| 1225 | - binds.push(bind); | ||
| 1226 | - } else { | ||
| 1227 | - // ideally, this error should point to the previous instance of this keybind | ||
| 1228 | - // | ||
| 1229 | - // i (sodiboo) have tried to implement this in various ways: | ||
| 1230 | - // miette!(), #[derive(Diagnostic)] | ||
| 1231 | - // DecodeError::Custom, DecodeError::Conversion | ||
| 1232 | - // nothing seems to work, and i suspect it's not possible. | ||
| 1233 | - // | ||
| 1234 | - // DecodeError is fairly restrictive. | ||
| 1235 | - // even DecodeError::Custom just wraps a std::error::Error | ||
| 1236 | - // and this erases all rich information from miette. (why???) | ||
| 1237 | - // | ||
| 1238 | - // why does knuffel do this? | ||
| 1239 | - // from what i can tell, it doesn't even use DecodeError for much. | ||
| 1240 | - // it only ever converts them to a Report anyways! | ||
| 1241 | - // https://github.com/tailhook/knuffel/blob/c44c6b0c0f31ea6d1174d5d2ed41064922ea44ca/src/wrappers.rs#L55-L58 | ||
| 1242 | - // | ||
| 1243 | - // besides like, allowing downstream users (such as us!) | ||
| 1244 | - // to match on parse failure, i don't understand why | ||
| 1245 | - // it doesn't just use a generic error type | ||
| 1246 | - // | ||
| 1247 | - // even the matching isn't consistent, | ||
| 1248 | - // because errors can also be omitted as ctx.emit_error. | ||
| 1249 | - // why does *that one* especially, require a DecodeError? | ||
| 1250 | - // | ||
| 1251 | - // anyways if you can make it format nicely, definitely do fix this | ||
| 1252 | - ctx.emit_error(DecodeError::unexpected( | ||
| 1253 | - &child.node_name, | ||
| 1254 | - "keybind", | ||
| 1255 | - "duplicate keybind", | ||
| 1256 | - )); | ||
| 1257 | - } | ||
| 1258 | - } | ||
| 1259 | - } | ||
| 1260 | - } | ||
| 1261 | - | ||
| 1262 | - Ok(Self(binds)) | ||
| 1263 | - } | ||
| 1264 | -} | ||
| 1265 | - | ||
| 1266 | -impl<S> knuffel::Decode<S> for Bind | ||
| 1267 | -where | ||
| 1268 | - S: knuffel::traits::ErrorSpan, | ||
| 1269 | -{ | ||
| 1270 | - fn decode_node( | ||
| 1271 | - node: &knuffel::ast::SpannedNode<S>, | ||
| 1272 | - ctx: &mut knuffel::decode::Context<S>, | ||
| 1273 | - ) -> Result<Self, DecodeError<S>> { | ||
| 1274 | - if let Some(type_name) = &node.type_name { | ||
| 1275 | - ctx.emit_error(DecodeError::unexpected( | ||
| 1276 | - type_name, | ||
| 1277 | - "type name", | ||
| 1278 | - "no type name expected for this node", | ||
| 1279 | - )); | ||
| 1280 | - } | ||
| 1281 | - | ||
| 1282 | - for val in node.arguments.iter() { | ||
| 1283 | - ctx.emit_error(DecodeError::unexpected( | ||
| 1284 | - &val.literal, | ||
| 1285 | - "argument", | ||
| 1286 | - "no arguments expected for this node", | ||
| 1287 | - )); | ||
| 1288 | - } | ||
| 1289 | - | ||
| 1290 | - let key = node | ||
| 1291 | - .node_name | ||
| 1292 | - .parse::<Key>() | ||
| 1293 | - .map_err(|e| DecodeError::conversion(&node.node_name, e.wrap_err("invalid keybind")))?; | ||
| 1294 | - | ||
| 1295 | - let mut repeat = true; | ||
| 1296 | - let mut cooldown = None; | ||
| 1297 | - let mut allow_when_locked = false; | ||
| 1298 | - let mut allow_when_locked_node = None; | ||
| 1299 | - let mut allow_inhibiting = true; | ||
| 1300 | - let mut hotkey_overlay_title = None; | ||
| 1301 | - for (name, val) in &node.properties { | ||
| 1302 | - match &***name { | ||
| 1303 | - "repeat" => { | ||
| 1304 | - repeat = knuffel::traits::DecodeScalar::decode(val, ctx)?; | ||
| 1305 | - } | ||
| 1306 | - "cooldown-ms" => { | ||
| 1307 | - cooldown = Some(Duration::from_millis( | ||
| 1308 | - knuffel::traits::DecodeScalar::decode(val, ctx)?, | ||
| 1309 | - )); | ||
| 1310 | - } | ||
| 1311 | - "allow-when-locked" => { | ||
| 1312 | - allow_when_locked = knuffel::traits::DecodeScalar::decode(val, ctx)?; | ||
| 1313 | - allow_when_locked_node = Some(name); | ||
| 1314 | - } | ||
| 1315 | - "allow-inhibiting" => { | ||
| 1316 | - allow_inhibiting = knuffel::traits::DecodeScalar::decode(val, ctx)?; | ||
| 1317 | - } | ||
| 1318 | - "hotkey-overlay-title" => { | ||
| 1319 | - hotkey_overlay_title = Some(knuffel::traits::DecodeScalar::decode(val, ctx)?); | ||
| 1320 | - } | ||
| 1321 | - name_str => { | ||
| 1322 | - ctx.emit_error(DecodeError::unexpected( | ||
| 1323 | - name, | ||
| 1324 | - "property", | ||
| 1325 | - format!("unexpected property `{}`", name_str.escape_default()), | ||
| 1326 | - )); | ||
| 1327 | - } | ||
| 1328 | - } | ||
| 1329 | - } | ||
| 1330 | - | ||
| 1331 | - let mut children = node.children(); | ||
| 1332 | - | ||
| 1333 | - // If the action is invalid but the key is fine, we still want to return something. | ||
| 1334 | - // That way, the parent can handle the existence of duplicate keybinds, | ||
| 1335 | - // even if their contents are not valid. | ||
| 1336 | - let dummy = Self { | ||
| 1337 | - key, | ||
| 1338 | - action: Action::Spawn(vec![]), | ||
| 1339 | - repeat: true, | ||
| 1340 | - cooldown: None, | ||
| 1341 | - allow_when_locked: false, | ||
| 1342 | - allow_inhibiting: true, | ||
| 1343 | - hotkey_overlay_title: None, | ||
| 1344 | - }; | ||
| 1345 | - | ||
| 1346 | - if let Some(child) = children.next() { | ||
| 1347 | - for unwanted_child in children { | ||
| 1348 | - ctx.emit_error(DecodeError::unexpected( | ||
| 1349 | - unwanted_child, | ||
| 1350 | - "node", | ||
| 1351 | - "only one action is allowed per keybind", | ||
| 1352 | - )); | ||
| 1353 | - } | ||
| 1354 | - match Action::decode_node(child, ctx) { | ||
| 1355 | - Ok(action) => { | ||
| 1356 | - if !matches!(action, Action::Spawn(_) | Action::SpawnSh(_)) { | ||
| 1357 | - if let Some(node) = allow_when_locked_node { | ||
| 1358 | - ctx.emit_error(DecodeError::unexpected( | ||
| 1359 | - node, | ||
| 1360 | - "property", | ||
| 1361 | - "allow-when-locked can only be set on spawn binds", | ||
| 1362 | - )); | ||
| 1363 | - } | ||
| 1364 | - } | ||
| 1365 | - | ||
| 1366 | - // The toggle-inhibit action must always be uninhibitable. | ||
| 1367 | - // Otherwise, it would be impossible to trigger it. | ||
| 1368 | - if matches!(action, Action::ToggleKeyboardShortcutsInhibit) { | ||
| 1369 | - allow_inhibiting = false; | ||
| 1370 | - } | ||
| 1371 | - | ||
| 1372 | - Ok(Self { | ||
| 1373 | - key, | ||
| 1374 | - action, | ||
| 1375 | - repeat, | ||
| 1376 | - cooldown, | ||
| 1377 | - allow_when_locked, | ||
| 1378 | - allow_inhibiting, | ||
| 1379 | - hotkey_overlay_title, | ||
| 1380 | - }) | ||
| 1381 | - } | ||
| 1382 | - Err(e) => { | ||
| 1383 | - ctx.emit_error(e); | ||
| 1384 | - Ok(dummy) | ||
| 1385 | - } | ||
| 1386 | - } | ||
| 1387 | - } else { | ||
| 1388 | - ctx.emit_error(DecodeError::missing( | ||
| 1389 | - node, | ||
| 1390 | - "expected an action for this keybind", | ||
| 1391 | - )); | ||
| 1392 | - Ok(dummy) | ||
| 1393 | - } | ||
| 1394 | - } | ||
| 1395 | -} | ||
| 1396 | - | ||
| 1397 | -impl FromStr for Key { | ||
| 1398 | - type Err = miette::Error; | ||
| 1399 | - | ||
| 1400 | - fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| 1401 | - let mut modifiers = Modifiers::empty(); | ||
| 1402 | - | ||
| 1403 | - let mut split = s.split('+'); | ||
| 1404 | - let key = split.next_back().unwrap(); | ||
| 1405 | - | ||
| 1406 | - for part in split { | ||
| 1407 | - let part = part.trim(); | ||
| 1408 | - if part.eq_ignore_ascii_case("mod") { | ||
| 1409 | - modifiers |= Modifiers::COMPOSITOR | ||
| 1410 | - } else if part.eq_ignore_ascii_case("ctrl") || part.eq_ignore_ascii_case("control") { | ||
| 1411 | - modifiers |= Modifiers::CTRL; | ||
| 1412 | - } else if part.eq_ignore_ascii_case("shift") { | ||
| 1413 | - modifiers |= Modifiers::SHIFT; | ||
| 1414 | - } else if part.eq_ignore_ascii_case("alt") { | ||
| 1415 | - modifiers |= Modifiers::ALT; | ||
| 1416 | - } else if part.eq_ignore_ascii_case("super") || part.eq_ignore_ascii_case("win") { | ||
| 1417 | - modifiers |= Modifiers::SUPER; | ||
| 1418 | - } else if part.eq_ignore_ascii_case("iso_level3_shift") | ||
| 1419 | - || part.eq_ignore_ascii_case("mod5") | ||
| 1420 | - { | ||
| 1421 | - modifiers |= Modifiers::ISO_LEVEL3_SHIFT; | ||
| 1422 | - } else if part.eq_ignore_ascii_case("iso_level5_shift") | ||
| 1423 | - || part.eq_ignore_ascii_case("mod3") | ||
| 1424 | - { | ||
| 1425 | - modifiers |= Modifiers::ISO_LEVEL5_SHIFT; | ||
| 1426 | - } else { | ||
| 1427 | - return Err(miette!("invalid modifier: {part}")); | ||
| 1428 | - } | ||
| 1429 | - } | ||
| 1430 | - | ||
| 1431 | - let trigger = if key.eq_ignore_ascii_case("MouseLeft") { | ||
| 1432 | - Trigger::MouseLeft | ||
| 1433 | - } else if key.eq_ignore_ascii_case("MouseRight") { | ||
| 1434 | - Trigger::MouseRight | ||
| 1435 | - } else if key.eq_ignore_ascii_case("MouseMiddle") { | ||
| 1436 | - Trigger::MouseMiddle | ||
| 1437 | - } else if key.eq_ignore_ascii_case("MouseBack") { | ||
| 1438 | - Trigger::MouseBack | ||
| 1439 | - } else if key.eq_ignore_ascii_case("MouseForward") { | ||
| 1440 | - Trigger::MouseForward | ||
| 1441 | - } else if key.eq_ignore_ascii_case("WheelScrollDown") { | ||
| 1442 | - Trigger::WheelScrollDown | ||
| 1443 | - } else if key.eq_ignore_ascii_case("WheelScrollUp") { | ||
| 1444 | - Trigger::WheelScrollUp | ||
| 1445 | - } else if key.eq_ignore_ascii_case("WheelScrollLeft") { | ||
| 1446 | - Trigger::WheelScrollLeft | ||
| 1447 | - } else if key.eq_ignore_ascii_case("WheelScrollRight") { | ||
| 1448 | - Trigger::WheelScrollRight | ||
| 1449 | - } else if key.eq_ignore_ascii_case("TouchpadScrollDown") { | ||
| 1450 | - Trigger::TouchpadScrollDown | ||
| 1451 | - } else if key.eq_ignore_ascii_case("TouchpadScrollUp") { | ||
| 1452 | - Trigger::TouchpadScrollUp | ||
| 1453 | - } else if key.eq_ignore_ascii_case("TouchpadScrollLeft") { | ||
| 1454 | - Trigger::TouchpadScrollLeft | ||
| 1455 | - } else if key.eq_ignore_ascii_case("TouchpadScrollRight") { | ||
| 1456 | - Trigger::TouchpadScrollRight | ||
| 1457 | - } else { | ||
| 1458 | - let keysym = keysym_from_name(key, KEYSYM_CASE_INSENSITIVE); | ||
| 1459 | - if keysym.raw() == KEY_NoSymbol { | ||
| 1460 | - return Err(miette!("invalid key: {key}")); | ||
| 1461 | - } | ||
| 1462 | - Trigger::Keysym(keysym) | ||
| 1463 | - }; | ||
| 1464 | - | ||
| 1465 | - Ok(Key { trigger, modifiers }) | ||
| 1466 | - } | ||
| 1467 | -} | ||
| 1468 | - | ||
| 1469 | impl FromStr for Percent { | 540 | impl FromStr for Percent { |
| 1470 | type Err = miette::Error; | 541 | type Err = miette::Error; |
| 1471 | 542 | ||
| @@ -3181,40 +2252,6 @@ mod tests { | |||
| 3181 | let _ = Config::default(); | 2252 | let _ = Config::default(); |
| 3182 | } | 2253 | } |
| 3183 | 2254 | ||
| 3184 | - #[test] | ||
| 3185 | - #[test] | ||
| 3186 | - fn parse_iso_level_shifts() { | ||
| 3187 | - assert_eq!( | ||
| 3188 | - "ISO_Level3_Shift+A".parse::<Key>().unwrap(), | ||
| 3189 | - Key { | ||
| 3190 | - trigger: Trigger::Keysym(Keysym::a), | ||
| 3191 | - modifiers: Modifiers::ISO_LEVEL3_SHIFT | ||
| 3192 | - }, | ||
| 3193 | - ); | ||
| 3194 | - assert_eq!( | ||
| 3195 | - "Mod5+A".parse::<Key>().unwrap(), | ||
| 3196 | - Key { | ||
| 3197 | - trigger: Trigger::Keysym(Keysym::a), | ||
| 3198 | - modifiers: Modifiers::ISO_LEVEL3_SHIFT | ||
| 3199 | - }, | ||
| 3200 | - ); | ||
| 3201 | - | ||
| 3202 | - assert_eq!( | ||
| 3203 | - "ISO_Level5_Shift+A".parse::<Key>().unwrap(), | ||
| 3204 | - Key { | ||
| 3205 | - trigger: Trigger::Keysym(Keysym::a), | ||
| 3206 | - modifiers: Modifiers::ISO_LEVEL5_SHIFT | ||
| 3207 | - }, | ||
| 3208 | - ); | ||
| 3209 | - assert_eq!( | ||
| 3210 | - "Mod3+A".parse::<Key>().unwrap(), | ||
| 3211 | - Key { | ||
| 3212 | - trigger: Trigger::Keysym(Keysym::a), | ||
| 3213 | - modifiers: Modifiers::ISO_LEVEL5_SHIFT | ||
| 3214 | - }, | ||
| 3215 | - ); | ||
| 3216 | - } | ||
| 3217 | - | ||
| 3218 | #[test] | 2255 | #[test] |
| 3219 | fn default_repeat_params() { | 2256 | fn default_repeat_params() { |
| 3220 | let config = Config::parse("config.kdl", "").unwrap(); | 2257 | let config = Config::parse("config.kdl", "").unwrap(); |