diff --git a/Kernel/ProcessGUI.cpp b/Kernel/ProcessGUI.cpp index 5b8e492848..6487d155c9 100644 --- a/Kernel/ProcessGUI.cpp +++ b/Kernel/ProcessGUI.cpp @@ -145,7 +145,7 @@ int Process::gui$invalidate_window(int window_id, const GUI_Rect* a_rect) Rect rect; if (a_rect) rect = *a_rect; - WSMessageLoop::the().post_event(&window, make(rect)); + WSMessageLoop::the().post_message(&window, make(rect)); WSMessageLoop::the().server_process().request_wakeup(); return 0; } @@ -169,7 +169,7 @@ int Process::gui$notify_paint_finished(int window_id, const GUI_Rect* a_rect) Rect rect; if (a_rect) rect = *a_rect; - WSMessageLoop::the().post_event(&window, make(rect)); + WSMessageLoop::the().post_message(&window, make(rect)); WSMessageLoop::the().server_process().request_wakeup(); return 0; } @@ -207,7 +207,7 @@ int Process::gui$set_window_title(int window_id, const char* title, size_t size) return -EBADWINDOW; auto& window = *(*it).value; String new_title(title, size); - WSMessageLoop::the().post_event(&window, make(move(new_title))); + WSMessageLoop::the().post_message(&window, make(move(new_title))); WSMessageLoop::the().server_process().request_wakeup(); return 0; } @@ -240,7 +240,7 @@ int Process::gui$set_window_rect(int window_id, const GUI_Rect* rect) return -EBADWINDOW; auto& window = *(*it).value; Rect new_rect = *rect; - WSMessageLoop::the().post_event(&window, make(new_rect)); + WSMessageLoop::the().post_message(&window, make(new_rect)); WSMessageLoop::the().server_process().request_wakeup(); return 0; } diff --git a/WindowServer/WSMessageLoop.cpp b/WindowServer/WSMessageLoop.cpp index 16ebd8668d..ec38aa1233 100644 --- a/WindowServer/WSMessageLoop.cpp +++ b/WindowServer/WSMessageLoop.cpp @@ -45,46 +45,46 @@ int WSMessageLoop::exec() m_running = true; for (;;) { - wait_for_event(); + wait_for_message(); - Vector events; + Vector messages; { ASSERT_INTERRUPTS_ENABLED(); LOCKER(m_lock); - events = move(m_queued_events); + messages = move(m_queued_messages); } - for (auto& queued_event : events) { - auto* receiver = queued_event.receiver; - auto& event = *queued_event.event; + for (auto& queued_message : messages) { + auto* receiver = queued_message.receiver; + auto& message = *queued_message.message; #ifdef WSEVENTLOOP_DEBUG - dbgprintf("WSMessageLoop: receiver{%p} event %u (%s)\n", receiver, (unsigned)event.type(), event.name()); + dbgprintf("WSMessageLoop: receiver{%p} message %u (%s)\n", receiver, (unsigned)event.type(), event.name()); #endif if (!receiver) { - dbgprintf("WSMessage type %u with no receiver :(\n", event.type()); + dbgprintf("WSMessage type %u with no receiver :(\n", message.type()); ASSERT_NOT_REACHED(); return 1; } else { - receiver->event(event); + receiver->on_message(message); } } } } -void WSMessageLoop::post_event(WSMessageReceiver* receiver, OwnPtr&& event) +void WSMessageLoop::post_message(WSMessageReceiver* receiver, OwnPtr&& message) { ASSERT_INTERRUPTS_ENABLED(); LOCKER(m_lock); #ifdef WSEVENTLOOP_DEBUG - dbgprintf("WSMessageLoop::post_event: {%u} << receiver=%p, event=%p\n", m_queued_events.size(), receiver, event.ptr()); + dbgprintf("WSMessageLoop::post_message: {%u} << receiver=%p, message=%p\n", m_queued_messages.size(), receiver, message.ptr()); #endif - if (event->type() == WSMessage::WM_Invalidate) { - auto& invalidation_event = static_cast(*event); - for (auto& queued_event : m_queued_events) { - if (receiver == queued_event.receiver && queued_event.event->type() == WSMessage::WM_Invalidate) { - auto& queued_invalidation_event = static_cast(*queued_event.event); - if (queued_invalidation_event.rect().is_empty() || queued_invalidation_event.rect().contains(invalidation_event.rect())) { + if (message->type() == WSMessage::WM_Invalidate) { + auto& invalidation_message = static_cast(*message); + for (auto& queued_message : m_queued_messages) { + if (receiver == queued_message.receiver && queued_message.message->type() == WSMessage::WM_Invalidate) { + auto& queued_invalidation_message = static_cast(*queued_message.message); + if (queued_invalidation_message.rect().is_empty() || queued_invalidation_message.rect().contains(invalidation_message.rect())) { #ifdef WSEVENTLOOP_DEBUG dbgprintf("Swallow WM_Invalidate\n"); #endif @@ -94,12 +94,12 @@ void WSMessageLoop::post_event(WSMessageReceiver* receiver, OwnPtr&& } } - if (event->type() == WSMessage::Paint) { - auto& invalidation_event = static_cast(*event); - for (auto& queued_event : m_queued_events) { - if (receiver == queued_event.receiver && queued_event.event->type() == WSMessage::Paint) { - auto& queued_invalidation_event = static_cast(*queued_event.event); - if (queued_invalidation_event.rect().is_empty() || queued_invalidation_event.rect().contains(invalidation_event.rect())) { + if (message->type() == WSMessage::Paint) { + auto& invalidation_message = static_cast(*message); + for (auto& queued_message : m_queued_messages) { + if (receiver == queued_message.receiver && queued_message.message->type() == WSMessage::Paint) { + auto& queued_invalidation_message = static_cast(*queued_message.message); + if (queued_invalidation_message.rect().is_empty() || queued_invalidation_message.rect().contains(invalidation_message.rect())) { #ifdef WSEVENTLOOP_DEBUG dbgprintf("Swallow WM_Paint\n"); #endif @@ -109,13 +109,13 @@ void WSMessageLoop::post_event(WSMessageReceiver* receiver, OwnPtr&& } } - m_queued_events.append({ receiver, move(event) }); + m_queued_messages.append({ receiver, move(message) }); if (current != m_server_process) m_server_process->request_wakeup(); } -void WSMessageLoop::wait_for_event() +void WSMessageLoop::wait_for_message() { fd_set rfds; memset(&rfds, 0, sizeof(rfds)); @@ -128,7 +128,7 @@ void WSMessageLoop::wait_for_event() params.writefds = nullptr; params.exceptfds = nullptr; struct timeval timeout = { 0, 0 }; - if (m_queued_events.is_empty()) + if (m_queued_messages.is_empty()) params.timeout = nullptr; else params.timeout = &timeout; diff --git a/WindowServer/WSMessageLoop.h b/WindowServer/WSMessageLoop.h index 1559f959f1..e9d32306e0 100644 --- a/WindowServer/WSMessageLoop.h +++ b/WindowServer/WSMessageLoop.h @@ -15,7 +15,7 @@ public: int exec(); - void post_event(WSMessageReceiver* receiver, OwnPtr&&); + void post_message(WSMessageReceiver* receiver, OwnPtr&&); static WSMessageLoop& the(); @@ -25,17 +25,17 @@ public: Process& server_process() { return *m_server_process; } private: - void wait_for_event(); + void wait_for_message(); void drain_mouse(); void drain_keyboard(); Lock m_lock; - struct QueuedEvent { + struct QueuedMessage { WSMessageReceiver* receiver { nullptr }; - OwnPtr event; + OwnPtr message; }; - Vector m_queued_events; + Vector m_queued_messages; Process* m_server_process { nullptr }; bool m_running { false }; diff --git a/WindowServer/WSMessageReceiver.h b/WindowServer/WSMessageReceiver.h index 7be42a5503..97ee114c8c 100644 --- a/WindowServer/WSMessageReceiver.h +++ b/WindowServer/WSMessageReceiver.h @@ -9,5 +9,5 @@ public: WSMessageReceiver(); virtual ~WSMessageReceiver(); - virtual void event(WSMessage&) = 0; + virtual void on_message(WSMessage&) = 0; }; diff --git a/WindowServer/WSScreen.cpp b/WindowServer/WSScreen.cpp index 483396dda2..4c4fb88aca 100644 --- a/WindowServer/WSScreen.cpp +++ b/WindowServer/WSScreen.cpp @@ -47,20 +47,20 @@ void WSScreen::on_receive_mouse_data(int dx, int dy, bool left_button, bool righ if (right_button) buttons |= (unsigned)MouseButton::Right; if (m_cursor_location != prev_location) { - auto event = make(WSMessage::MouseMove, m_cursor_location, buttons); - WSMessageLoop::the().post_event(&WSWindowManager::the(), move(event)); + auto message = make(WSMessage::MouseMove, m_cursor_location, buttons); + WSMessageLoop::the().post_message(&WSWindowManager::the(), move(message)); } bool prev_left_button = m_left_mouse_button_pressed; bool prev_right_button = m_right_mouse_button_pressed; m_left_mouse_button_pressed = left_button; m_right_mouse_button_pressed = right_button; if (prev_left_button != left_button) { - auto event = make(left_button ? WSMessage::MouseDown : WSMessage::MouseUp, m_cursor_location, buttons, MouseButton::Left); - WSMessageLoop::the().post_event(&WSWindowManager::the(), move(event)); + auto message = make(left_button ? WSMessage::MouseDown : WSMessage::MouseUp, m_cursor_location, buttons, MouseButton::Left); + WSMessageLoop::the().post_message(&WSWindowManager::the(), move(message)); } if (prev_right_button != right_button) { - auto event = make(right_button ? WSMessage::MouseDown : WSMessage::MouseUp, m_cursor_location, buttons, MouseButton::Right); - WSMessageLoop::the().post_event(&WSWindowManager::the(), move(event)); + auto message = make(right_button ? WSMessage::MouseDown : WSMessage::MouseUp, m_cursor_location, buttons, MouseButton::Right); + WSMessageLoop::the().post_message(&WSWindowManager::the(), move(message)); } if (m_cursor_location != prev_location || prev_left_button != left_button) WSWindowManager::the().draw_cursor(); @@ -68,9 +68,9 @@ void WSScreen::on_receive_mouse_data(int dx, int dy, bool left_button, bool righ void WSScreen::on_receive_keyboard_data(Keyboard::Event kernel_event) { - auto event = make(kernel_event.is_press() ? WSMessage::KeyDown : WSMessage::KeyUp, kernel_event.key, kernel_event.character); - event->m_shift = kernel_event.shift(); - event->m_ctrl = kernel_event.ctrl(); - event->m_alt = kernel_event.alt(); - WSMessageLoop::the().post_event(&WSWindowManager::the(), move(event)); + auto message = make(kernel_event.is_press() ? WSMessage::KeyDown : WSMessage::KeyUp, kernel_event.key, kernel_event.character); + message->m_shift = kernel_event.shift(); + message->m_ctrl = kernel_event.ctrl(); + message->m_alt = kernel_event.alt(); + WSMessageLoop::the().post_message(&WSWindowManager::the(), move(message)); } diff --git a/WindowServer/WSWindow.cpp b/WindowServer/WSWindow.cpp index b1c7d0d5f3..5e4b24ee40 100644 --- a/WindowServer/WSWindow.cpp +++ b/WindowServer/WSWindow.cpp @@ -54,50 +54,50 @@ static GUI_MouseButton to_api(MouseButton button) } } -void WSWindow::event(WSMessage& event) +void WSWindow::on_message(WSMessage& message) { GUI_Event gui_event; gui_event.window_id = window_id(); - switch (event.type()) { + switch (message.type()) { case WSMessage::Paint: gui_event.type = GUI_Event::Type::Paint; - gui_event.paint.rect = static_cast(event).rect(); + gui_event.paint.rect = static_cast(message).rect(); break; case WSMessage::MouseMove: gui_event.type = GUI_Event::Type::MouseMove; - gui_event.mouse.position = static_cast(event).position(); + gui_event.mouse.position = static_cast(message).position(); gui_event.mouse.button = GUI_MouseButton::NoButton; - gui_event.mouse.buttons = static_cast(event).buttons(); + gui_event.mouse.buttons = static_cast(message).buttons(); break; case WSMessage::MouseDown: gui_event.type = GUI_Event::Type::MouseDown; - gui_event.mouse.position = static_cast(event).position(); - gui_event.mouse.button = to_api(static_cast(event).button()); - gui_event.mouse.buttons = static_cast(event).buttons(); + gui_event.mouse.position = static_cast(message).position(); + gui_event.mouse.button = to_api(static_cast(message).button()); + gui_event.mouse.buttons = static_cast(message).buttons(); break; case WSMessage::MouseUp: gui_event.type = GUI_Event::Type::MouseUp; - gui_event.mouse.position = static_cast(event).position(); - gui_event.mouse.button = to_api(static_cast(event).button()); - gui_event.mouse.buttons = static_cast(event).buttons(); + gui_event.mouse.position = static_cast(message).position(); + gui_event.mouse.button = to_api(static_cast(message).button()); + gui_event.mouse.buttons = static_cast(message).buttons(); break; case WSMessage::KeyDown: gui_event.type = GUI_Event::Type::KeyDown; - gui_event.key.character = static_cast(event).character(); - gui_event.key.key = static_cast(event).key(); - gui_event.key.alt = static_cast(event).alt(); - gui_event.key.ctrl = static_cast(event).ctrl(); - gui_event.key.shift = static_cast(event).shift(); + gui_event.key.character = static_cast(message).character(); + gui_event.key.key = static_cast(message).key(); + gui_event.key.alt = static_cast(message).alt(); + gui_event.key.ctrl = static_cast(message).ctrl(); + gui_event.key.shift = static_cast(message).shift(); break; case WSMessage::WM_Invalidate: - WSWindowManager::the().invalidate(*this, static_cast(event).rect()); + WSWindowManager::the().invalidate(*this, static_cast(message).rect()); return; case WSMessage::WM_SetWindowRect: - set_rect(static_cast(event).rect()); + set_rect(static_cast(message).rect()); return; case WSMessage::WM_SetWindowTitle: - set_title(static_cast(event).title()); + set_title(static_cast(message).title()); return; case WSMessage::WindowActivated: gui_event.type = GUI_Event::Type::WindowActivated; diff --git a/WindowServer/WSWindow.h b/WindowServer/WSWindow.h index 38178b3bb5..e91845f02b 100644 --- a/WindowServer/WSWindow.h +++ b/WindowServer/WSWindow.h @@ -33,7 +33,7 @@ public: void set_position(const Point& position) { set_rect({ position.x(), position.y(), width(), height() }); } void set_position_without_repaint(const Point& position) { set_rect_without_repaint({ position.x(), position.y(), width(), height() }); } - virtual void event(WSMessage&) override; + virtual void on_message(WSMessage&) override; bool is_being_dragged() const { return m_is_being_dragged; } void set_is_being_dragged(bool b) { m_is_being_dragged = b; } diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index f685d197fc..0b25730e0a 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -305,7 +305,7 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event) // FIXME: Should we just alter the coordinates of the existing MouseEvent and pass it through? Point position { event.x() - window->rect().x(), event.y() - window->rect().y() }; auto local_event = make(event.type(), position, event.buttons(), event.button()); - window->event(*local_event); + window->on_message(*local_event); return; } } @@ -387,21 +387,21 @@ void WSWindowManager::draw_cursor() m_last_cursor_rect = cursor_rect; } -void WSWindowManager::event(WSMessage& event) +void WSWindowManager::on_message(WSMessage& message) { ASSERT_INTERRUPTS_ENABLED(); LOCKER(m_lock); - if (event.is_mouse_event()) - return process_mouse_event(static_cast(event)); + if (message.is_mouse_event()) + return process_mouse_event(static_cast(message)); - if (event.is_key_event()) { + if (message.is_key_event()) { // FIXME: This is a good place to hook key events globally. :) if (m_active_window) - return m_active_window->event(event); + return m_active_window->on_message(message); return; } - if (event.type() == WSMessage::WM_Compose) { + if (message.type() == WSMessage::WM_Compose) { m_pending_compose_event = false; compose(); return; @@ -415,12 +415,12 @@ void WSWindowManager::set_active_window(WSWindow* window) return; if (auto* previously_active_window = m_active_window.ptr()) { - WSMessageLoop::the().post_event(previously_active_window, make(WSMessage::WindowDeactivated)); + WSMessageLoop::the().post_message(previously_active_window, make(WSMessage::WindowDeactivated)); invalidate(*previously_active_window); } m_active_window = window->makeWeakPtr(); if (m_active_window) { - WSMessageLoop::the().post_event(m_active_window.ptr(), make(WSMessage::WindowActivated)); + WSMessageLoop::the().post_message(m_active_window.ptr(), make(WSMessage::WindowActivated)); invalidate(*m_active_window); } } @@ -454,7 +454,7 @@ void WSWindowManager::invalidate(const Rect& a_rect) if (!m_pending_compose_event) { ASSERT_INTERRUPTS_ENABLED(); - WSMessageLoop::the().post_event(this, make(WSMessage::WM_Compose)); + WSMessageLoop::the().post_message(this, make(WSMessage::WM_Compose)); m_pending_compose_event = true; } } diff --git a/WindowServer/WSWindowManager.h b/WindowServer/WSWindowManager.h index 1e42f44337..e3336e9f33 100644 --- a/WindowServer/WSWindowManager.h +++ b/WindowServer/WSWindowManager.h @@ -48,7 +48,7 @@ private: void set_active_window(WSWindow*); - virtual void event(WSMessage&) override; + virtual void on_message(WSMessage&) override; void compose(); void paint_window_frame(WSWindow&);