///| Keyboard shortcuts: the compositor's end of the shortcut table (compositor/shell/shortcuts.mbt). /// /// Every key press that isn't a modifier is looked up as a combo (the held modifiers plus the key) /// and, when a shortcut has it, runs that shortcut's action instead of reaching a client; its /// release is swallowed too. A Super tap (Super pressed and let go alone) runs the shortcut bound to /// "Super", the launcher by default. Window switching is driven from switcher.mbt, which reads its /// combo from the same table. While the settings module's Shortcuts tab waits for a new combo /// (`shell.shortcut_capturing()`), the next combo pressed is taken for it here and does nothing else. ///| The modifiers held now, as combo bits. The Super and Alt keys are tracked from their own key /// events as well, as the nested host doesn't always report them in the modifier mask. pub fn ChandraCompositor::held_mods(self : ChandraCompositor) -> UInt { let mut m = self.mods & @shell.combo_mods if self.super_down { m = m | @shell.mod_logo } if self.alt_down { m = m | @shell.mod_alt } m } ///| Keep track of the Super and Alt keys (for combos and the Super tap). fn ChandraCompositor::track_modifier_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Unit { if code == key_lsuper || code == key_rsuper { self.super_down = pressed } else if code == key_lalt || code == key_ralt { self.alt_down = pressed } } ///| While the Shortcuts tab waits for a combo: take the next one for it. Escape cancels, Backspace /// unbinds; a Super tap binds "Super". True when the key was used (it goes nowhere else). fn ChandraCompositor::capture_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Bool { let shell = self.shell if shell.shortcut_capturing() < 0 { // The release of a key the capture took. if !pressed && self.capture_swallow.contains(code) { self.capture_swallow.retain(c => c != code) return true } return false } self.super_solo = false if code == key_lsuper || code == key_rsuper { if pressed { self.capture_super = true } else if self.capture_super { self.capture_super = false ignore(shell.finish_shortcut_capture(Some({ mods: 0U, key: @shell.key_super }))) } return true // Super never reaches clients } if @shell.is_modifier_key(code) { return false // other modifiers pass, so clients keep their state right } self.capture_super = false if !pressed { return true } self.capture_swallow.push(code) let mods = self.held_mods() if mods == 0U && code == key_esc { shell.cancel_shortcut_capture() } else if mods == 0U && code == key_backspace { ignore(shell.finish_shortcut_capture(None)) } else { ignore(shell.finish_shortcut_capture(Some({ mods, key: code }))) } self.damage.mark_full() true } ///| A key for the shortcut table: runs the action bound to the combo it makes with the held /// modifiers. True when the key was used (neither it nor its release reaches a client). fn ChandraCompositor::shortcut_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Bool { if !pressed { if self.sc_swallow.contains(code) { self.sc_swallow.retain(c => c != code) return true } return false } if @shell.is_modifier_key(code) || self.shell.inspecting() { return false } match self.shell.shortcuts.lookup({ mods: self.held_mods(), key: code }) { // Window switching is the switcher's (switcher_key runs before this). None | Some(SwitchWindows) => false Some(action) => { self.sc_swallow.push(code) self.run_shortcut(action) true } } } ///| A Super tap: the shortcut bound to "Super" (the launcher by default), if any. fn ChandraCompositor::super_tap(self : ChandraCompositor) -> Unit { match self.shell.shortcuts.lookup({ mods: 0U, key: @shell.key_super }) { None | Some(SwitchWindows) => () Some(action) => self.run_shortcut(action) } } ///| Do what a shortcut stands for. pub fn ChandraCompositor::run_shortcut(self : ChandraCompositor, action : @shell.ShortcutAction) -> Unit { self.super_solo = false match action { Launcher => if !self.shell.inspecting() { self.shell.toggle_launcher() } ShowDesktop => self.toggle_show_desktop() SwitchWindows => () ShotRegion => self.take_screenshot(ShotMode::Region) ShotFull => self.take_screenshot(ShotMode::FullScreen) ShotActiveWindow => self.take_screenshot(ShotMode::ActiveWindow) ShotWindowUnderCursor => self.take_screenshot(ShotMode::WindowUnderCursor) RecordRegion => self.toggle_recording(ShotMode::Region) RecordScreen => self.toggle_recording(ShotMode::FullScreen) RecordWindow => self.toggle_recording(ShotMode::WindowUnderCursor) } } ///| evdev code of Backspace (unbinds while capturing). let key_backspace : UInt = 14