mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 19:45:08 +00:00
LibGUI: Move shortcut actions from GEventLoop to GApplications.
I'm gonna want to have nested event loops sooner or later, so let's not pollute GEventLoop with things that are meant to work globally. This patch also changes key events to pass around their modifiers as a bitfield all the way around the system instead of breaking them up.
This commit is contained in:
parent
725b57fe1f
commit
5e40aa4f1a
11 changed files with 63 additions and 55 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "GEvent.h"
|
||||
#include "GObject.h"
|
||||
#include "GWindow.h"
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GNotifier.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
|
@ -153,20 +154,14 @@ void GEventLoop::handle_key_event(const WSAPI_ServerMessage& event, GWindow& win
|
|||
#ifdef GEVENTLOOP_DEBUG
|
||||
dbgprintf("WID=%x KeyEvent character=0x%b\n", event.window_id, event.key.character);
|
||||
#endif
|
||||
|
||||
unsigned modifiers = (event.key.alt * Mod_Alt) + (event.key.ctrl * Mod_Ctrl) + (event.key.shift * Mod_Shift);
|
||||
auto it = g_actions->find(GShortcut(modifiers, (KeyCode)event.key.key));
|
||||
if (it != g_actions->end()) {
|
||||
(*it).value->activate();
|
||||
return;
|
||||
}
|
||||
|
||||
auto key_event = make<GKeyEvent>(event.type == WSAPI_ServerMessage::Type::KeyDown ? GEvent::KeyDown : GEvent::KeyUp, event.key.key);
|
||||
key_event->m_alt = event.key.alt;
|
||||
key_event->m_ctrl = event.key.ctrl;
|
||||
key_event->m_shift = event.key.shift;
|
||||
auto key_event = make<GKeyEvent>(event.type == WSAPI_ServerMessage::Type::KeyDown ? GEvent::KeyDown : GEvent::KeyUp, event.key.key, event.key.modifiers);
|
||||
if (event.key.character != '\0')
|
||||
key_event->m_text = String(&event.key.character, 1);
|
||||
|
||||
if (auto* action = GApplication::the().action_for_key_event(*key_event)) {
|
||||
action->activate();
|
||||
return;
|
||||
}
|
||||
post_event(window, move(key_event));
|
||||
}
|
||||
|
||||
|
@ -455,13 +450,3 @@ WSAPI_ServerMessage GEventLoop::sync_request(const WSAPI_ClientMessage& request,
|
|||
ASSERT(success);
|
||||
return response;
|
||||
}
|
||||
|
||||
void GEventLoop::register_action_with_shortcut(Badge<GAction>, GAction& action)
|
||||
{
|
||||
g_actions->set(action.shortcut(), &action);
|
||||
}
|
||||
|
||||
void GEventLoop::unregister_action_with_shortcut(Badge<GAction>, GAction& action)
|
||||
{
|
||||
g_actions->remove(action.shortcut());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue