mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +00:00
WindowServer: Move key event handling to its own function
Instead of making WindowManager::event() all about key events.
This commit is contained in:
parent
4895f46d8c
commit
de8aa1b17d
2 changed files with 88 additions and 81 deletions
|
@ -1154,98 +1154,103 @@ void WindowManager::event(Core::Event& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (static_cast<Event&>(event).is_key_event()) {
|
if (static_cast<Event&>(event).is_key_event()) {
|
||||||
auto& key_event = static_cast<KeyEvent const&>(event);
|
process_key_event(static_cast<KeyEvent&>(event));
|
||||||
m_keyboard_modifiers = key_event.modifiers();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Escape key cancels an ongoing drag.
|
Core::Object::event(event);
|
||||||
if (key_event.type() == Event::KeyDown && key_event.key() == Key_Escape && m_dnd_client) {
|
}
|
||||||
// Notify the drag-n-drop client that the drag was cancelled.
|
|
||||||
m_dnd_client->async_drag_cancelled();
|
|
||||||
|
|
||||||
// Also notify the currently hovered window (if any) that the ongoing drag was cancelled.
|
void WindowManager::process_key_event(KeyEvent& event)
|
||||||
if (m_hovered_window && m_hovered_window->client() && m_hovered_window->client() != m_dnd_client)
|
{
|
||||||
m_hovered_window->client()->async_drag_cancelled();
|
m_keyboard_modifiers = event.modifiers();
|
||||||
|
|
||||||
end_dnd_drag();
|
// Escape key cancels an ongoing drag.
|
||||||
return;
|
if (event.type() == Event::KeyDown && event.key() == Key_Escape && m_dnd_client) {
|
||||||
}
|
// Notify the drag-n-drop client that the drag was cancelled.
|
||||||
|
m_dnd_client->async_drag_cancelled();
|
||||||
|
|
||||||
if (key_event.type() == Event::KeyDown && (key_event.modifiers() == (Mod_Ctrl | Mod_Super | Mod_Shift) && key_event.key() == Key_I)) {
|
// Also notify the currently hovered window (if any) that the ongoing drag was cancelled.
|
||||||
reload_icon_bitmaps_after_scale_change(!m_allow_hidpi_icons);
|
if (m_hovered_window && m_hovered_window->client() && m_hovered_window->client() != m_dnd_client)
|
||||||
Compositor::the().invalidate_screen();
|
m_hovered_window->client()->async_drag_cancelled();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key_event.type() == Event::KeyDown && key_event.key() == Key_Super) {
|
end_dnd_drag();
|
||||||
m_previous_event_was_super_keydown = true;
|
return;
|
||||||
} else if (m_previous_event_was_super_keydown) {
|
}
|
||||||
m_previous_event_was_super_keydown = false;
|
|
||||||
if (!m_dnd_client && !m_active_input_tracking_window && 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) {
|
if (event.type() == Event::KeyDown && (event.modifiers() == (Mod_Ctrl | Mod_Super | Mod_Shift) && event.key() == Key_I)) {
|
||||||
MenuManager::the().dispatch_event(event);
|
reload_icon_bitmaps_after_scale_change(!m_allow_hidpi_icons);
|
||||||
return;
|
Compositor::the().invalidate_screen();
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (key_event.type() == Event::KeyDown && ((key_event.modifiers() == Mod_Super && key_event.key() == Key_Tab) || (key_event.modifiers() == (Mod_Super | Mod_Shift) && key_event.key() == Key_Tab)))
|
if (event.type() == Event::KeyDown && event.key() == Key_Super) {
|
||||||
m_switcher.show();
|
m_previous_event_was_super_keydown = true;
|
||||||
if (m_switcher.is_visible()) {
|
} else if (m_previous_event_was_super_keydown) {
|
||||||
m_switcher.on_key_event(key_event);
|
m_previous_event_was_super_keydown = false;
|
||||||
return;
|
if (!m_dnd_client && !m_active_input_tracking_window && event.type() == Event::KeyUp && event.key() == Key_Super) {
|
||||||
}
|
tell_wms_super_key_pressed();
|
||||||
|
|
||||||
if (m_active_input_window) {
|
|
||||||
if (key_event.type() == Event::KeyDown && key_event.modifiers() == Mod_Super && m_active_input_window->type() != WindowType::Desktop) {
|
|
||||||
if (key_event.key() == Key_Down) {
|
|
||||||
if (m_active_input_window->is_resizable() && m_active_input_window->is_maximized()) {
|
|
||||||
maximize_windows(*m_active_input_window, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_active_input_window->is_minimizable())
|
|
||||||
minimize_windows(*m_active_input_window, true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_active_input_window->is_resizable()) {
|
|
||||||
if (key_event.key() == Key_Up) {
|
|
||||||
maximize_windows(*m_active_input_window, !m_active_input_window->is_maximized());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (key_event.key() == Key_Left) {
|
|
||||||
if (m_active_input_window->tiled() == WindowTileType::Left)
|
|
||||||
return;
|
|
||||||
if (m_active_input_window->tiled() != WindowTileType::None) {
|
|
||||||
m_active_input_window->set_untiled();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_active_input_window->is_maximized())
|
|
||||||
maximize_windows(*m_active_input_window, false);
|
|
||||||
m_active_input_window->set_tiled(WindowTileType::Left);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (key_event.key() == Key_Right) {
|
|
||||||
if (m_active_input_window->tiled() == WindowTileType::Right)
|
|
||||||
return;
|
|
||||||
if (m_active_input_window->tiled() != WindowTileType::None) {
|
|
||||||
m_active_input_window->set_untiled();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_active_input_window->is_maximized())
|
|
||||||
maximize_windows(*m_active_input_window, false);
|
|
||||||
m_active_input_window->set_tiled(WindowTileType::Right);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_active_input_window->dispatch_event(event);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Object::event(event);
|
if (MenuManager::the().current_menu() && event.key() != Key_Super) {
|
||||||
|
MenuManager::the().dispatch_event(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type() == Event::KeyDown && ((event.modifiers() == Mod_Super && event.key() == Key_Tab) || (event.modifiers() == (Mod_Super | Mod_Shift) && event.key() == Key_Tab)))
|
||||||
|
m_switcher.show();
|
||||||
|
if (m_switcher.is_visible()) {
|
||||||
|
m_switcher.on_key_event(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_active_input_window)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event.type() == Event::KeyDown && event.modifiers() == Mod_Super && m_active_input_window->type() != WindowType::Desktop) {
|
||||||
|
if (event.key() == Key_Down) {
|
||||||
|
if (m_active_input_window->is_resizable() && m_active_input_window->is_maximized()) {
|
||||||
|
maximize_windows(*m_active_input_window, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_active_input_window->is_minimizable())
|
||||||
|
minimize_windows(*m_active_input_window, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_active_input_window->is_resizable()) {
|
||||||
|
if (event.key() == Key_Up) {
|
||||||
|
maximize_windows(*m_active_input_window, !m_active_input_window->is_maximized());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == Key_Left) {
|
||||||
|
if (m_active_input_window->tiled() == WindowTileType::Left)
|
||||||
|
return;
|
||||||
|
if (m_active_input_window->tiled() != WindowTileType::None) {
|
||||||
|
m_active_input_window->set_untiled();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_active_input_window->is_maximized())
|
||||||
|
maximize_windows(*m_active_input_window, false);
|
||||||
|
m_active_input_window->set_tiled(WindowTileType::Left);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key() == Key_Right) {
|
||||||
|
if (m_active_input_window->tiled() == WindowTileType::Right)
|
||||||
|
return;
|
||||||
|
if (m_active_input_window->tiled() != WindowTileType::None) {
|
||||||
|
m_active_input_window->set_untiled();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_active_input_window->is_maximized())
|
||||||
|
maximize_windows(*m_active_input_window, false);
|
||||||
|
m_active_input_window->set_tiled(WindowTileType::Right);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_active_input_window->dispatch_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::set_highlight_window(Window* new_highlight_window)
|
void WindowManager::set_highlight_window(Window* new_highlight_window)
|
||||||
|
|
|
@ -243,6 +243,8 @@ private:
|
||||||
bool process_mouse_event_for_titlebar_buttons(MouseEvent const&);
|
bool process_mouse_event_for_titlebar_buttons(MouseEvent const&);
|
||||||
void process_mouse_event_for_window(HitTestResult&, MouseEvent const&);
|
void process_mouse_event_for_window(HitTestResult&, MouseEvent const&);
|
||||||
|
|
||||||
|
void process_key_event(KeyEvent&);
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void for_each_window_manager(Callback);
|
void for_each_window_manager(Callback);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue