diff options
author | Jan Grau <jan.grau95@gmail.com> | 2022-02-23 21:43:50 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-24 18:57:20 +0000 |
commit | 6992a07afcdce14f316490b8a26e116d3f5e8059 (patch) | |
tree | fe8307382e6f8f0fcdac76ae42104ac03144dd18 /Userland | |
parent | 001b08dec9a28859ecd5fb9e9a6d42f00bdb9a57 (diff) | |
download | serenity-6992a07afcdce14f316490b8a26e116d3f5e8059.zip |
LibGUI+WindowServer: Add new `WMEvent` Super+Digit
This adds a keyboard event for Super+0 to Super+9. Later to be consumed
in the taskbar.
Currently only this keyboard sequence is supported:
- Super key down
- Digit key down
But not this:
- Super key down
- Digit key down
- Digit key up
- Digit key down
Diffstat (limited to 'Userland')
6 files changed, 41 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Event.h b/Userland/Libraries/LibGUI/Event.h index b386858195..be57fab47f 100644 --- a/Userland/Libraries/LibGUI/Event.h +++ b/Userland/Libraries/LibGUI/Event.h @@ -66,6 +66,7 @@ public: WM_AppletAreaSizeChanged, WM_SuperKeyPressed, WM_SuperSpaceKeyPressed, + WM_SuperDigitKeyPressed, WM_WorkspaceChanged, WM_KeymapChanged, __End_WM_Events, @@ -115,6 +116,20 @@ public: } }; +class WMSuperDigitKeyPressedEvent : public WMEvent { +public: + WMSuperDigitKeyPressedEvent(int client_id, u8 digit) + : WMEvent(Event::Type::WM_SuperDigitKeyPressed, client_id, 0) + , m_digit(digit) + { + } + + u8 digit() const { return m_digit; } + +private: + u8 m_digit { 0 }; +}; + class WMAppletAreaSizeChangedEvent : public WMEvent { public: explicit WMAppletAreaSizeChangedEvent(const Gfx::IntSize& size) diff --git a/Userland/Libraries/LibGUI/WindowManagerServerConnection.cpp b/Userland/Libraries/LibGUI/WindowManagerServerConnection.cpp index 9d894ab43b..412540a670 100644 --- a/Userland/Libraries/LibGUI/WindowManagerServerConnection.cpp +++ b/Userland/Libraries/LibGUI/WindowManagerServerConnection.cpp @@ -64,6 +64,12 @@ void WindowManagerServerConnection::super_space_key_pressed(i32 wm_id) Core::EventLoop::current().post_event(*window, make<WMSuperSpaceKeyPressedEvent>(wm_id)); } +void WindowManagerServerConnection::super_digit_key_pressed(i32 wm_id, u8 digit) +{ + if (auto* window = Window::from_window_id(wm_id)) + Core::EventLoop::current().post_event(*window, make<WMSuperDigitKeyPressedEvent>(wm_id, digit)); +} + void WindowManagerServerConnection::workspace_changed(i32 wm_id, u32 row, u32 column) { if (auto* window = Window::from_window_id(wm_id)) diff --git a/Userland/Libraries/LibGUI/WindowManagerServerConnection.h b/Userland/Libraries/LibGUI/WindowManagerServerConnection.h index 78c2e4ce3e..db9c3d5f79 100644 --- a/Userland/Libraries/LibGUI/WindowManagerServerConnection.h +++ b/Userland/Libraries/LibGUI/WindowManagerServerConnection.h @@ -34,6 +34,7 @@ private: virtual void applet_area_size_changed(i32, Gfx::IntSize const&) override; virtual void super_key_pressed(i32) override; virtual void super_space_key_pressed(i32) override; + virtual void super_digit_key_pressed(i32, u8) override; virtual void workspace_changed(i32, u32, u32) override; virtual void keymap_changed(i32, String const&) override; }; diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 8f11211cf9..38019e25b4 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -546,6 +546,17 @@ void WindowManager::tell_wms_super_space_key_pressed() }); } +void WindowManager::tell_wms_super_digit_key_pressed(u8 digit) +{ + for_each_window_manager([digit](WMClientConnection& conn) { + if (conn.window_id() < 0) + return IterationDecision::Continue; + + conn.async_super_digit_key_pressed(conn.window_id(), digit); + return IterationDecision::Continue; + }); +} + void WindowManager::tell_wms_current_window_stack_changed() { for_each_window_manager([&](WMClientConnection& conn) { @@ -1603,6 +1614,12 @@ void WindowManager::process_key_event(KeyEvent& event) tell_wms_super_space_key_pressed(); return; } + + if (event.type() == Event::KeyDown && event.key() >= Key_0 && event.key() <= Key_9) { + auto digit = event.key() - Key_0; + tell_wms_super_digit_key_pressed(digit); + return; + } } if (MenuManager::the().current_menu() && event.key() != Key_Super) { diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index 1b9c4fb32c..b489164607 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -187,6 +187,7 @@ public: void tell_wms_applet_area_size_changed(Gfx::IntSize const&); void tell_wms_super_key_pressed(); void tell_wms_super_space_key_pressed(); + void tell_wms_super_digit_key_pressed(u8); void tell_wms_current_window_stack_changed(); bool is_active_window_or_accessory(Window&) const; diff --git a/Userland/Services/WindowServer/WindowManagerClient.ipc b/Userland/Services/WindowServer/WindowManagerClient.ipc index d22a934e79..676af0a21f 100644 --- a/Userland/Services/WindowServer/WindowManagerClient.ipc +++ b/Userland/Services/WindowServer/WindowManagerClient.ipc @@ -9,6 +9,7 @@ endpoint WindowManagerClient applet_area_size_changed(i32 wm_id, Gfx::IntSize size) =| super_key_pressed(i32 wm_id) =| super_space_key_pressed(i32 wm_id) =| + super_digit_key_pressed(i32 wm_id, u8 digit) =| workspace_changed(i32 wm_id, u32 row, u32 column) =| keymap_changed(i32 wm_id, [UTF8] String keymap) =| } |