mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:57:34 +00:00
LibGUI+WindowServer: Add WM_SuperKeyPressed event
This commit adds an event called WM_SuperKeyPressed which is sent to all windows via WindowManagerServerConnection. The event is fired from WindowManager when the super key is pressed, which is the windows key on most keyboards :)
This commit is contained in:
parent
ec3596545a
commit
88ecfa164a
6 changed files with 45 additions and 1 deletions
|
@ -82,6 +82,7 @@ public:
|
||||||
WM_WindowRectChanged,
|
WM_WindowRectChanged,
|
||||||
WM_WindowIconBitmapChanged,
|
WM_WindowIconBitmapChanged,
|
||||||
WM_AppletAreaSizeChanged,
|
WM_AppletAreaSizeChanged,
|
||||||
|
WM_SuperKeyPressed,
|
||||||
__End_WM_Events,
|
__End_WM_Events,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,6 +114,14 @@ private:
|
||||||
int m_window_id { -1 };
|
int m_window_id { -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WMSuperKeyPressedEvent : public WMEvent {
|
||||||
|
public:
|
||||||
|
explicit WMSuperKeyPressedEvent(int client_id)
|
||||||
|
: WMEvent(Event::Type::WM_SuperKeyPressed, client_id, 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class WMAppletAreaSizeChangedEvent : public WMEvent {
|
class WMAppletAreaSizeChangedEvent : public WMEvent {
|
||||||
public:
|
public:
|
||||||
explicit WMAppletAreaSizeChangedEvent(const Gfx::IntSize& size)
|
explicit WMAppletAreaSizeChangedEvent(const Gfx::IntSize& size)
|
||||||
|
|
|
@ -74,4 +74,10 @@ void WindowManagerServerConnection::handle(const Messages::WindowManagerClient::
|
||||||
if (auto* window = Window::from_window_id(message.wm_id()))
|
if (auto* window = Window::from_window_id(message.wm_id()))
|
||||||
Core::EventLoop::current().post_event(*window, make<WMWindowRemovedEvent>(message.client_id(), message.window_id()));
|
Core::EventLoop::current().post_event(*window, make<WMWindowRemovedEvent>(message.client_id(), message.window_id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowManagerServerConnection::handle(const Messages::WindowManagerClient::SuperKeyPressed& message)
|
||||||
|
{
|
||||||
|
if (auto* window = Window::from_window_id(message.wm_id()))
|
||||||
|
Core::EventLoop::current().post_event(*window, make<WMSuperKeyPressedEvent>(message.wm_id()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ private:
|
||||||
virtual void handle(const Messages::WindowManagerClient::WindowIconBitmapChanged&) override;
|
virtual void handle(const Messages::WindowManagerClient::WindowIconBitmapChanged&) override;
|
||||||
virtual void handle(const Messages::WindowManagerClient::WindowRectChanged&) override;
|
virtual void handle(const Messages::WindowManagerClient::WindowRectChanged&) override;
|
||||||
virtual void handle(const Messages::WindowManagerClient::AppletAreaSizeChanged&) override;
|
virtual void handle(const Messages::WindowManagerClient::AppletAreaSizeChanged&) override;
|
||||||
|
virtual void handle(const Messages::WindowManagerClient::SuperKeyPressed&) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibGUI/WindowManagerServerConnection.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/CharacterBitmap.h>
|
#include <LibGfx/CharacterBitmap.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
|
@ -377,6 +378,17 @@ void WindowManager::tell_wms_applet_area_size_changed(const Gfx::IntSize& size)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowManager::tell_wms_super_key_pressed()
|
||||||
|
{
|
||||||
|
for_each_window_manager([](WMClientConnection& conn) {
|
||||||
|
if (conn.window_id() < 0)
|
||||||
|
return IterationDecision::Continue;
|
||||||
|
|
||||||
|
conn.post_message(Messages::WindowManagerClient::SuperKeyPressed(conn.window_id()));
|
||||||
|
return IterationDecision::Continue;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static bool window_type_has_title(WindowType type)
|
static bool window_type_has_title(WindowType type)
|
||||||
{
|
{
|
||||||
return type == WindowType::Normal || type == WindowType::ToolWindow;
|
return type == WindowType::Normal || type == WindowType::ToolWindow;
|
||||||
|
@ -1182,6 +1194,9 @@ Gfx::IntRect WindowManager::arena_rect_for_type(WindowType type) const
|
||||||
void WindowManager::event(Core::Event& event)
|
void WindowManager::event(Core::Event& event)
|
||||||
{
|
{
|
||||||
if (static_cast<Event&>(event).is_mouse_event()) {
|
if (static_cast<Event&>(event).is_mouse_event()) {
|
||||||
|
if (event.type() != Event::MouseMove)
|
||||||
|
m_previous_event_was_super_keydown = false;
|
||||||
|
|
||||||
Window* hovered_window = nullptr;
|
Window* hovered_window = nullptr;
|
||||||
process_mouse_event(static_cast<MouseEvent&>(event), hovered_window);
|
process_mouse_event(static_cast<MouseEvent&>(event), hovered_window);
|
||||||
set_hovered_window(hovered_window);
|
set_hovered_window(hovered_window);
|
||||||
|
@ -1211,7 +1226,17 @@ void WindowManager::event(Core::Event& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MenuManager::the().current_menu()) {
|
if (key_event.type() == Event::KeyDown && key_event.key() == Key_Super) {
|
||||||
|
m_previous_event_was_super_keydown = true;
|
||||||
|
} else if (m_previous_event_was_super_keydown) {
|
||||||
|
m_previous_event_was_super_keydown = false;
|
||||||
|
if (!m_dnd_client && key_event.type() == Event::KeyUp && key_event.key() == Key_Super) {
|
||||||
|
tell_wms_super_key_pressed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MenuManager::the().current_menu() && key_event.key() != Key_Super) {
|
||||||
MenuManager::the().dispatch_event(event);
|
MenuManager::the().dispatch_event(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,6 +175,7 @@ public:
|
||||||
void tell_wms_window_icon_changed(Window&);
|
void tell_wms_window_icon_changed(Window&);
|
||||||
void tell_wms_window_rect_changed(Window&);
|
void tell_wms_window_rect_changed(Window&);
|
||||||
void tell_wms_applet_area_size_changed(const Gfx::IntSize&);
|
void tell_wms_applet_area_size_changed(const Gfx::IntSize&);
|
||||||
|
void tell_wms_super_key_pressed();
|
||||||
|
|
||||||
bool is_active_window_or_accessory(Window&) const;
|
bool is_active_window_or_accessory(Window&) const;
|
||||||
|
|
||||||
|
@ -334,6 +335,7 @@ private:
|
||||||
DoubleClickInfo m_double_click_info;
|
DoubleClickInfo m_double_click_info;
|
||||||
int m_double_click_speed { 0 };
|
int m_double_click_speed { 0 };
|
||||||
int m_max_distance_for_double_click { 4 };
|
int m_max_distance_for_double_click { 4 };
|
||||||
|
bool m_previous_event_was_super_keydown { false };
|
||||||
|
|
||||||
WeakPtr<Window> m_active_window;
|
WeakPtr<Window> m_active_window;
|
||||||
WeakPtr<Window> m_hovered_window;
|
WeakPtr<Window> m_hovered_window;
|
||||||
|
|
|
@ -5,4 +5,5 @@ endpoint WindowManagerClient = 1872
|
||||||
WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::ShareableBitmap bitmap) =|
|
WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::ShareableBitmap bitmap) =|
|
||||||
WindowRectChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect rect) =|
|
WindowRectChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect rect) =|
|
||||||
AppletAreaSizeChanged(i32 wm_id, Gfx::IntSize size) =|
|
AppletAreaSizeChanged(i32 wm_id, Gfx::IntSize size) =|
|
||||||
|
SuperKeyPressed(i32 wm_id) =|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue