diff options
author | Timur Sultanov <SultanovTS@yandex.ru> | 2022-01-19 14:44:56 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-03 00:47:22 +0100 |
commit | b9c558f6c6e4adb3e10d9bc94dcdbec793f5bc23 (patch) | |
tree | 67fdf26d250f5a6bce4339ff03ba5c706f6d5311 /Userland/Services | |
parent | 68a01f0e273675ba225e29c1522d997a5d898e61 (diff) | |
download | serenity-b9c558f6c6e4adb3e10d9bc94dcdbec793f5bc23.zip |
WindowServer+Keymap+LibGUI: Add widget to display current keymap
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/WindowServer/KeymapSwitcher.cpp | 16 | ||||
-rw-r--r-- | Userland/Services/WindowServer/KeymapSwitcher.h | 8 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Window.h | 1 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowManager.cpp | 12 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowManagerClient.ipc | 1 |
5 files changed, 22 insertions, 16 deletions
diff --git a/Userland/Services/WindowServer/KeymapSwitcher.cpp b/Userland/Services/WindowServer/KeymapSwitcher.cpp index e34fdb3e0c..f35543d8f7 100644 --- a/Userland/Services/WindowServer/KeymapSwitcher.cpp +++ b/Userland/Services/WindowServer/KeymapSwitcher.cpp @@ -12,17 +12,8 @@ namespace WindowServer { -static KeymapSwitcher* s_the; - -KeymapSwitcher& KeymapSwitcher::the() -{ - VERIFY(s_the); - return *s_the; -} - KeymapSwitcher::KeymapSwitcher() { - s_the = this; } KeymapSwitcher::~KeymapSwitcher() @@ -80,10 +71,7 @@ String KeymapSwitcher::get_current_keymap() const auto json = JsonValue::from_string(proc_keymap->read_all()).release_value_but_fixme_should_propagate_errors(); auto const& keymap_object = json.as_object(); VERIFY(keymap_object.has("keymap")); - auto keymap = keymap_object.get("keymap").to_string(); - dbgln("Current keymap is: {}", keymap); - - return keymap; + return keymap_object.get("keymap").to_string(); } void KeymapSwitcher::setkeymap(const AK::String& keymap) @@ -94,6 +82,8 @@ void KeymapSwitcher::setkeymap(const AK::String& keymap) perror("posix_spawn"); dbgln("Failed to call /bin/keymap, error: {} ({})", errno, strerror(errno)); } + if (on_keymap_change) + on_keymap_change(keymap); } } diff --git a/Userland/Services/WindowServer/KeymapSwitcher.h b/Userland/Services/WindowServer/KeymapSwitcher.h index c9f6a0b77c..04dfb09b61 100644 --- a/Userland/Services/WindowServer/KeymapSwitcher.h +++ b/Userland/Services/WindowServer/KeymapSwitcher.h @@ -11,27 +11,29 @@ #include <AK/WeakPtr.h> #include <LibCore/Object.h> #include <LibKeyboard/CharacterMap.h> +#include <WindowServer/WMClientConnection.h> namespace WindowServer { class KeymapSwitcher final : public Core::Object { C_OBJECT(KeymapSwitcher) public: - static KeymapSwitcher& the(); - virtual ~KeymapSwitcher() override; void refresh(); void next_keymap(); + Function<void(String const& keymap)> on_keymap_change; + + String get_current_keymap() const; + private: KeymapSwitcher(); Vector<AK::String> m_keymaps; void setkeymap(AK::String const&); - String get_current_keymap() const; }; } diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index 11348b23cd..3dfbfaa1ef 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -36,6 +36,7 @@ enum WMEventMask { WindowIconChanges = 1 << 2, WindowRemovals = 1 << 3, WorkspaceChanges = 1 << 4, + KeymapChanged = 1 << 5, }; enum class WindowTileType { diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index b9b8db61fc..084c6465f0 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -53,6 +53,18 @@ WindowManager::WindowManager(Gfx::PaletteImpl const& palette) reload_config(); + m_keymap_switcher->on_keymap_change = [&](String const& keymap) { + for_each_window_manager([&keymap](WMClientConnection& conn) { + if (!(conn.event_mask() & WMEventMask::KeymapChanged)) + return IterationDecision::Continue; + if (conn.window_id() < 0) + return IterationDecision::Continue; + + conn.async_keymap_changed(conn.window_id(), keymap); + return IterationDecision::Continue; + }); + }; + Compositor::the().did_construct_window_manager({}); } diff --git a/Userland/Services/WindowServer/WindowManagerClient.ipc b/Userland/Services/WindowServer/WindowManagerClient.ipc index d422085eed..d22a934e79 100644 --- a/Userland/Services/WindowServer/WindowManagerClient.ipc +++ b/Userland/Services/WindowServer/WindowManagerClient.ipc @@ -10,4 +10,5 @@ endpoint WindowManagerClient super_key_pressed(i32 wm_id) =| super_space_key_pressed(i32 wm_id) =| workspace_changed(i32 wm_id, u32 row, u32 column) =| + keymap_changed(i32 wm_id, [UTF8] String keymap) =| } |