diff --git a/Servers/WindowServer/WSEventLoop.cpp b/Servers/WindowServer/WSEventLoop.cpp index 20897cd756..f2590b0ba5 100644 --- a/Servers/WindowServer/WSEventLoop.cpp +++ b/Servers/WindowServer/WSEventLoop.cpp @@ -40,6 +40,12 @@ WSEventLoop::WSEventLoop() m_server_notifier = make(m_server_sock.fd(), CNotifier::Read); m_server_notifier->on_ready_to_read = [this] { drain_server(); }; + + m_keyboard_notifier = make(m_keyboard_fd, CNotifier::Read); + m_keyboard_notifier->on_ready_to_read = [this] { drain_keyboard(); }; + + m_mouse_notifier = make(m_mouse_fd, CNotifier::Read); + m_mouse_notifier->on_ready_to_read = [this] { drain_mouse(); }; } WSEventLoop::~WSEventLoop() @@ -57,7 +63,7 @@ void WSEventLoop::drain_server() static int s_next_client_id = 0; int client_id = ++s_next_client_id; - new WSClientConnection(client_fd, client_id); + CIPCServerSideClientCreator(client_fd, client_id); } } @@ -105,22 +111,3 @@ void WSEventLoop::drain_keyboard() } } -void WSEventLoop::add_file_descriptors_for_select(fd_set& fds, int& max_fd_added) -{ - auto add_fd_to_set = [&max_fd_added](int fd, auto& set) { - FD_SET(fd, &set); - if (fd > max_fd_added) - max_fd_added = fd; - }; - add_fd_to_set(m_keyboard_fd, fds); - add_fd_to_set(m_mouse_fd, fds); -} - -void WSEventLoop::process_file_descriptors_after_select(const fd_set& fds) -{ - if (FD_ISSET(m_keyboard_fd, &fds)) - drain_keyboard(); - if (FD_ISSET(m_mouse_fd, &fds)) - drain_mouse(); -} - diff --git a/Servers/WindowServer/WSEventLoop.h b/Servers/WindowServer/WSEventLoop.h index 8935dd0264..6f17f6257e 100644 --- a/Servers/WindowServer/WSEventLoop.h +++ b/Servers/WindowServer/WSEventLoop.h @@ -8,25 +8,23 @@ class WSClientConnection; struct WSAPI_ClientMessage; -class WSEventLoop : public CEventLoop { +class WSEventLoop { public: WSEventLoop(); - virtual ~WSEventLoop() override; + virtual ~WSEventLoop(); - static WSEventLoop& the() { return static_cast(CEventLoop::current()); } + int exec() { return m_event_loop.exec(); } private: - virtual void add_file_descriptors_for_select(fd_set&, int& max_fd_added) override; - virtual void process_file_descriptors_after_select(const fd_set&) override; - void drain_server(); void drain_mouse(); void drain_keyboard(); - void drain_client(WSClientConnection&); - bool on_receive_from_client(int client_id, const WSAPI_ClientMessage&, ByteBuffer&& extra_data); + CEventLoop m_event_loop; int m_keyboard_fd { -1 }; + OwnPtr m_keyboard_notifier; int m_mouse_fd { -1 }; + OwnPtr m_mouse_notifier; CLocalSocket m_server_sock; OwnPtr m_server_notifier; }; diff --git a/Servers/WindowServer/WSScreen.cpp b/Servers/WindowServer/WSScreen.cpp index 3582687881..3d15b9f072 100644 --- a/Servers/WindowServer/WSScreen.cpp +++ b/Servers/WindowServer/WSScreen.cpp @@ -71,19 +71,19 @@ void WSScreen::on_receive_mouse_data(int dx, int dy, int dz, unsigned buttons) if (!(changed_buttons & (unsigned)button)) return; auto message = make(buttons & (unsigned)button ? WSEvent::MouseDown : WSEvent::MouseUp, m_cursor_location, buttons, button, m_modifiers); - WSEventLoop::the().post_event(WSWindowManager::the(), move(message)); + CEventLoop::current().post_event(WSWindowManager::the(), move(message)); }; post_mousedown_or_mouseup_if_needed(MouseButton::Left); post_mousedown_or_mouseup_if_needed(MouseButton::Right); post_mousedown_or_mouseup_if_needed(MouseButton::Middle); if (m_cursor_location != prev_location) { auto message = make(WSEvent::MouseMove, m_cursor_location, buttons, MouseButton::None, m_modifiers); - WSEventLoop::the().post_event(WSWindowManager::the(), move(message)); + CEventLoop::current().post_event(WSWindowManager::the(), move(message)); } if (dz) { auto message = make(WSEvent::MouseWheel, m_cursor_location, buttons, MouseButton::None, m_modifiers, dz); - WSEventLoop::the().post_event(WSWindowManager::the(), move(message)); + CEventLoop::current().post_event(WSWindowManager::the(), move(message)); } if (m_cursor_location != prev_location) @@ -94,7 +94,7 @@ void WSScreen::on_receive_keyboard_data(KeyEvent kernel_event) { m_modifiers = kernel_event.modifiers(); auto message = make(kernel_event.is_press() ? WSEvent::KeyDown : WSEvent::KeyUp, kernel_event.key, kernel_event.character, kernel_event.modifiers()); - WSEventLoop::the().post_event(WSWindowManager::the(), move(message)); + CEventLoop::current().post_event(WSWindowManager::the(), move(message)); } void WSScreen::set_y_offset(int offset) diff --git a/Servers/WindowServer/WSWindow.cpp b/Servers/WindowServer/WSWindow.cpp index b06c70ff60..13b4b49b64 100644 --- a/Servers/WindowServer/WSWindow.cpp +++ b/Servers/WindowServer/WSWindow.cpp @@ -171,7 +171,7 @@ void WSWindow::set_maximized(bool maximized) set_rect(m_unmaximized_rect); } m_frame.did_set_maximized({}, maximized); - WSEventLoop::the().post_event(*this, make(old_rect, m_rect)); + CEventLoop::current().post_event(*this, make(old_rect, m_rect)); } void WSWindow::event(CEvent& event) diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp index ad2a6b4e37..a607696561 100644 --- a/Servers/WindowServer/WSWindowManager.cpp +++ b/Servers/WindowServer/WSWindowManager.cpp @@ -247,7 +247,7 @@ void WSWindowManager::add_window(WSWindow& window) m_windows_in_order.append(&window); if (window.is_fullscreen()) { - WSEventLoop::the().post_event(window, make(window.rect(), WSScreen::the().rect())); + CEventLoop::current().post_event(window, make(window.rect(), WSScreen::the().rect())); window.set_rect(WSScreen::the().rect()); } @@ -294,7 +294,7 @@ void WSWindowManager::remove_window(WSWindow& window) if (!(listener.wm_event_mask() & WSAPI_WMEventMask::WindowRemovals)) return IterationDecision::Continue; if (window.client()) - WSEventLoop::the().post_event(listener, make(window.client()->client_id(), window.window_id())); + CEventLoop::current().post_event(listener, make(window.client()->client_id(), window.window_id())); return IterationDecision::Continue; }); } @@ -304,7 +304,7 @@ void WSWindowManager::tell_wm_listener_about_window(WSWindow& listener, WSWindow if (!(listener.wm_event_mask() & WSAPI_WMEventMask::WindowStateChanges)) return; if (window.client()) - WSEventLoop::the().post_event(listener, make(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active(), window.type(), window.is_minimized())); + CEventLoop::current().post_event(listener, make(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active(), window.type(), window.is_minimized())); } void WSWindowManager::tell_wm_listener_about_window_rect(WSWindow& listener, WSWindow& window) @@ -312,7 +312,7 @@ void WSWindowManager::tell_wm_listener_about_window_rect(WSWindow& listener, WSW if (!(listener.wm_event_mask() & WSAPI_WMEventMask::WindowRectChanges)) return; if (window.client()) - WSEventLoop::the().post_event(listener, make(window.client()->client_id(), window.window_id(), window.rect())); + CEventLoop::current().post_event(listener, make(window.client()->client_id(), window.window_id(), window.rect())); } void WSWindowManager::tell_wm_listener_about_window_icon(WSWindow& listener, WSWindow& window) @@ -320,7 +320,7 @@ void WSWindowManager::tell_wm_listener_about_window_icon(WSWindow& listener, WSW if (!(listener.wm_event_mask() & WSAPI_WMEventMask::WindowIconChanges)) return; if (window.client()) - WSEventLoop::the().post_event(listener, make(window.client()->client_id(), window.window_id(), window.icon_path())); + CEventLoop::current().post_event(listener, make(window.client()->client_id(), window.window_id(), window.icon_path())); } void WSWindowManager::tell_wm_listeners_window_state_changed(WSWindow& window) @@ -490,7 +490,7 @@ bool WSWindowManager::process_ongoing_window_resize(const WSMouseEvent& event, W #ifdef RESIZE_DEBUG dbg() << "[WM] Finish resizing WSWindow{" << m_resize_window << "}"; #endif - WSEventLoop::the().post_event(*m_resize_window, make(m_resize_window->rect(), m_resize_window->rect())); + CEventLoop::current().post_event(*m_resize_window, make(m_resize_window->rect(), m_resize_window->rect())); invalidate(*m_resize_window); if (m_resize_window->rect().contains(event.position())) hovered_window = m_resize_window; @@ -575,7 +575,7 @@ bool WSWindowManager::process_ongoing_window_resize(const WSMouseEvent& event, W dbg() << "[WM] Resizing, original: " << m_resize_window_original_rect << ", now: " << new_rect; #endif m_resize_window->set_rect(new_rect); - WSEventLoop::the().post_event(*m_resize_window, make(old_rect, new_rect)); + CEventLoop::current().post_event(*m_resize_window, make(old_rect, new_rect)); return true; } @@ -904,12 +904,12 @@ void WSWindowManager::set_active_window(WSWindow* window) auto* previously_active_window = m_active_window.ptr(); if (previously_active_window) { - WSEventLoop::the().post_event(*previously_active_window, make(WSEvent::WindowDeactivated)); + CEventLoop::current().post_event(*previously_active_window, make(WSEvent::WindowDeactivated)); invalidate(*previously_active_window); } m_active_window = window->make_weak_ptr(); if (m_active_window) { - WSEventLoop::the().post_event(*m_active_window, make(WSEvent::WindowActivated)); + CEventLoop::current().post_event(*m_active_window, make(WSEvent::WindowActivated)); invalidate(*m_active_window); auto* client = window->client(); @@ -927,12 +927,12 @@ void WSWindowManager::set_hovered_window(WSWindow* window) return; if (m_hovered_window) - WSEventLoop::the().post_event(*m_hovered_window, make(WSEvent::WindowLeft)); + CEventLoop::current().post_event(*m_hovered_window, make(WSEvent::WindowLeft)); m_hovered_window = window ? window->make_weak_ptr() : nullptr; if (m_hovered_window) - WSEventLoop::the().post_event(*m_hovered_window, make(WSEvent::WindowEntered)); + CEventLoop::current().post_event(*m_hovered_window, make(WSEvent::WindowEntered)); } void WSWindowManager::invalidate() diff --git a/Servers/WindowServer/main.cpp b/Servers/WindowServer/main.cpp index 3a8aff5c40..17159a27e3 100644 --- a/Servers/WindowServer/main.cpp +++ b/Servers/WindowServer/main.cpp @@ -27,6 +27,6 @@ int main(int, char**) WSWindowManager window_manager; dbgprintf("Entering WindowServer main loop.\n"); - WSEventLoop::the().exec(); + loop.exec(); ASSERT_NOT_REACHED(); }