소스 검색

Rename GUI_Event to GUI_ServerMessage.

Now that communication is becoming bidirectional, "event" is no longer right.
Andreas Kling 6 년 전
부모
커밋
fbbf57b61c

+ 3 - 3
Kernel/GUIEventDevice.cpp

@@ -23,13 +23,13 @@ bool GUIEventDevice::can_read(Process& process) const
 ssize_t GUIEventDevice::read(Process& process, byte* buffer, size_t size)
 {
 #ifdef GUIEVENTDEVICE_DEBUG
-    dbgprintf("GUIEventDevice::read(): %s<%u>, size=%u, sizeof(GUI_Event)=%u\n", process.name().characters(), process.pid(), size, sizeof(GUI_Event));
+    dbgprintf("GUIEventDevice::read(): %s<%u>, size=%u, sizeof(GUI_ServerMessage)=%u\n", process.name().characters(), process.pid(), size, sizeof(GUI_ServerMessage));
 #endif
     if (process.gui_events().is_empty())
         return 0;
     LOCKER(process.gui_events_lock());
-    ASSERT(size == sizeof(GUI_Event));
-    *reinterpret_cast<GUI_Event*>(buffer) = process.gui_events().take_first();
+    ASSERT(size == sizeof(GUI_ServerMessage));
+    *reinterpret_cast<GUI_ServerMessage*>(buffer) = process.gui_events().take_first();
     return size;
 }
 

+ 1 - 1
Kernel/GUITypes.h

@@ -55,7 +55,7 @@ struct GUI_KeyModifiers { enum {
 }; };
 
 
-struct GUI_Event {
+struct GUI_ServerMessage {
     enum Type : unsigned {
         Invalid,
         Paint,

+ 2 - 2
Kernel/Process.h

@@ -301,7 +301,7 @@ public:
 
     bool is_root() const { return m_euid == 0; }
 
-    Vector<GUI_Event>& gui_events() { return m_gui_events; }
+    Vector<GUI_ServerMessage>& gui_events() { return m_gui_events; }
     Lock& gui_events_lock() { return m_gui_events_lock; }
 
     bool wakeup_requested() { return m_wakeup_requested; }
@@ -417,7 +417,7 @@ private:
     HashMap<int, OwnPtr<WSWindow>> m_windows;
     Vector<RetainPtr<GraphicsBitmap>> m_retained_backing_stores;
 
-    Vector<GUI_Event> m_gui_events;
+    Vector<GUI_ServerMessage> m_gui_events;
     Lock m_gui_events_lock;
     int m_next_window_id { 1 };
 

+ 37 - 37
LibGUI/GEventLoop.cpp

@@ -93,7 +93,7 @@ void GEventLoop::post_event(GObject* receiver, OwnPtr<GEvent>&& event)
     m_queued_events.append({ receiver, move(event) });
 }
 
-void GEventLoop::handle_paint_event(const GUI_Event& event, GWindow& window)
+void GEventLoop::handle_paint_event(const GUI_ServerMessage& event, GWindow& window)
 {
 #ifdef GEVENTLOOP_DEBUG
     dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height);
@@ -101,25 +101,25 @@ void GEventLoop::handle_paint_event(const GUI_Event& event, GWindow& window)
     post_event(&window, make<GPaintEvent>(event.paint.rect));
 }
 
-void GEventLoop::handle_window_activation_event(const GUI_Event& event, GWindow& window)
+void GEventLoop::handle_window_activation_event(const GUI_ServerMessage& event, GWindow& window)
 {
 #ifdef GEVENTLOOP_DEBUG
     dbgprintf("WID=%x WindowActivation\n", event.window_id);
 #endif
-    post_event(&window, make<GEvent>(event.type == GUI_Event::Type::WindowActivated ? GEvent::WindowBecameActive : GEvent::WindowBecameInactive));
+    post_event(&window, make<GEvent>(event.type == GUI_ServerMessage::Type::WindowActivated ? GEvent::WindowBecameActive : GEvent::WindowBecameInactive));
 }
 
-void GEventLoop::handle_window_close_request_event(const GUI_Event&, GWindow& window)
+void GEventLoop::handle_window_close_request_event(const GUI_ServerMessage&, GWindow& window)
 {
     post_event(&window, make<GEvent>(GEvent::WindowCloseRequest));
 }
 
-void GEventLoop::handle_key_event(const GUI_Event& event, GWindow& window)
+void GEventLoop::handle_key_event(const GUI_ServerMessage& event, GWindow& window)
 {
 #ifdef GEVENTLOOP_DEBUG
     dbgprintf("WID=%x KeyEvent character=0x%b\n", event.window_id, event.key.character);
 #endif
-    auto key_event = make<GKeyEvent>(event.type == GUI_Event::Type::KeyDown ? GEvent::KeyDown : GEvent::KeyUp, event.key.key);
+    auto key_event = make<GKeyEvent>(event.type == GUI_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;
@@ -128,16 +128,16 @@ void GEventLoop::handle_key_event(const GUI_Event& event, GWindow& window)
     post_event(&window, move(key_event));
 }
 
-void GEventLoop::handle_mouse_event(const GUI_Event& event, GWindow& window)
+void GEventLoop::handle_mouse_event(const GUI_ServerMessage& event, GWindow& window)
 {
 #ifdef GEVENTLOOP_DEBUG
     dbgprintf("WID=%x MouseEvent %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y);
 #endif
     GMouseEvent::Type type;
     switch (event.type) {
-    case GUI_Event::Type::MouseMove: type = GEvent::MouseMove; break;
-    case GUI_Event::Type::MouseUp: type = GEvent::MouseUp; break;
-    case GUI_Event::Type::MouseDown: type = GEvent::MouseDown; break;
+    case GUI_ServerMessage::Type::MouseMove: type = GEvent::MouseMove; break;
+    case GUI_ServerMessage::Type::MouseUp: type = GEvent::MouseUp; break;
+    case GUI_ServerMessage::Type::MouseDown: type = GEvent::MouseDown; break;
     default: ASSERT_NOT_REACHED(); break;
     }
     GMouseButton button { GMouseButton::None };
@@ -151,9 +151,9 @@ void GEventLoop::handle_mouse_event(const GUI_Event& event, GWindow& window)
     post_event(&window, make<GMouseEvent>(type, event.mouse.position, event.mouse.buttons, button));
 }
 
-void GEventLoop::handle_menu_event(const GUI_Event& event)
+void GEventLoop::handle_menu_event(const GUI_ServerMessage& event)
 {
-    if (event.type == GUI_Event::Type::MenuItemActivated) {
+    if (event.type == GUI_ServerMessage::Type::MenuItemActivated) {
         auto* menu = GMenu::from_menu_id(event.menu.menu_id);
         if (!menu) {
             dbgprintf("GEventLoop received event for invalid window ID %d\n", event.window_id);
@@ -228,13 +228,13 @@ void GEventLoop::wait_for_event()
     if (!FD_ISSET(m_event_fd, &rfds))
         return;
 
-    bool success = drain_events_from_server();
+    bool success = drain_messages_from_server();
     ASSERT(success);
 
-    auto unprocessed_events = move(m_unprocessed_events);
+    auto unprocessed_events = move(m_unprocessed_messages);
     for (auto& event : unprocessed_events) {
         switch (event.type) {
-        case GUI_Event::MenuItemActivated:
+        case GUI_ServerMessage::MenuItemActivated:
             handle_menu_event(event);
             continue;
         default:
@@ -247,23 +247,23 @@ void GEventLoop::wait_for_event()
             continue;
         }
         switch (event.type) {
-        case GUI_Event::Type::Paint:
+        case GUI_ServerMessage::Type::Paint:
             handle_paint_event(event, *window);
             break;
-        case GUI_Event::Type::MouseDown:
-        case GUI_Event::Type::MouseUp:
-        case GUI_Event::Type::MouseMove:
+        case GUI_ServerMessage::Type::MouseDown:
+        case GUI_ServerMessage::Type::MouseUp:
+        case GUI_ServerMessage::Type::MouseMove:
             handle_mouse_event(event, *window);
             break;
-        case GUI_Event::Type::WindowActivated:
-        case GUI_Event::Type::WindowDeactivated:
+        case GUI_ServerMessage::Type::WindowActivated:
+        case GUI_ServerMessage::Type::WindowDeactivated:
             handle_window_activation_event(event, *window);
             break;
-        case GUI_Event::Type::WindowCloseRequest:
+        case GUI_ServerMessage::Type::WindowCloseRequest:
             handle_window_close_request_event(event, *window);
             break;
-        case GUI_Event::Type::KeyDown:
-        case GUI_Event::Type::KeyUp:
+        case GUI_ServerMessage::Type::KeyDown:
+        case GUI_ServerMessage::Type::KeyUp:
             handle_key_event(event, *window);
             break;
         default:
@@ -272,11 +272,11 @@ void GEventLoop::wait_for_event()
     }
 }
 
-bool GEventLoop::drain_events_from_server()
+bool GEventLoop::drain_messages_from_server()
 {
     for (;;) {
-        GUI_Event event;
-        ssize_t nread = read(m_event_fd, &event, sizeof(GUI_Event));
+        GUI_ServerMessage message;
+        ssize_t nread = read(m_event_fd, &message, sizeof(GUI_ServerMessage));
         if (nread < 0) {
             perror("read");
             exit(1);
@@ -284,8 +284,8 @@ bool GEventLoop::drain_events_from_server()
         }
         if (nread == 0)
             return true;
-        assert(nread == sizeof(event));
-        m_unprocessed_events.append(move(event));
+        assert(nread == sizeof(message));
+        m_unprocessed_messages.append(move(message));
     }
 }
 
@@ -355,28 +355,28 @@ bool GEventLoop::post_message_to_server(const GUI_ClientMessage& message)
     return nwritten == sizeof(GUI_ClientMessage);
 }
 
-bool GEventLoop::wait_for_specific_event(GUI_Event::Type type, GUI_Event& event)
+bool GEventLoop::wait_for_specific_event(GUI_ServerMessage::Type type, GUI_ServerMessage& event)
 {
     for (;;) {
-        bool success = drain_events_from_server();
+        bool success = drain_messages_from_server();
         if (!success)
             return false;
-        for (size_t i = 0; i < m_unprocessed_events.size(); ++i) {
-            if (m_unprocessed_events[i].type == type) {
-                event = move(m_unprocessed_events[i]);
-                m_unprocessed_events.remove(i);
+        for (size_t i = 0; i < m_unprocessed_messages.size(); ++i) {
+            if (m_unprocessed_messages[i].type == type) {
+                event = move(m_unprocessed_messages[i]);
+                m_unprocessed_messages.remove(i);
                 return true;
             }
         }
     }
 }
 
-GUI_Event GEventLoop::sync_request(const GUI_ClientMessage& request, GUI_Event::Type response_type)
+GUI_ServerMessage GEventLoop::sync_request(const GUI_ClientMessage& request, GUI_ServerMessage::Type response_type)
 {
     bool success = post_message_to_server(request);
     ASSERT(success);
 
-    GUI_Event response;
+    GUI_ServerMessage response;
     success = GEventLoop::main().wait_for_specific_event(response_type, response);
     ASSERT(success);
     return response;

+ 10 - 10
LibGUI/GEventLoop.h

@@ -35,19 +35,19 @@ public:
     void exit(int);
 
     bool post_message_to_server(const GUI_ClientMessage&);
-    bool wait_for_specific_event(GUI_Event::Type, GUI_Event&);
+    bool wait_for_specific_event(GUI_ServerMessage::Type, GUI_ServerMessage&);
 
-    GUI_Event sync_request(const GUI_ClientMessage& request, GUI_Event::Type response_type);
+    GUI_ServerMessage sync_request(const GUI_ClientMessage& request, GUI_ServerMessage::Type response_type);
 
 private:
     void wait_for_event();
-    bool drain_events_from_server();
-    void handle_paint_event(const GUI_Event&, GWindow&);
-    void handle_mouse_event(const GUI_Event&, GWindow&);
-    void handle_key_event(const GUI_Event&, GWindow&);
-    void handle_window_activation_event(const GUI_Event&, GWindow&);
-    void handle_window_close_request_event(const GUI_Event&, GWindow&);
-    void handle_menu_event(const GUI_Event&);
+    bool drain_messages_from_server();
+    void handle_paint_event(const GUI_ServerMessage&, GWindow&);
+    void handle_mouse_event(const GUI_ServerMessage&, GWindow&);
+    void handle_key_event(const GUI_ServerMessage&, GWindow&);
+    void handle_window_activation_event(const GUI_ServerMessage&, GWindow&);
+    void handle_window_close_request_event(const GUI_ServerMessage&, GWindow&);
+    void handle_menu_event(const GUI_ServerMessage&);
     void get_next_timer_expiration(timeval&);
 
     struct QueuedEvent {
@@ -56,7 +56,7 @@ private:
     };
     Vector<QueuedEvent> m_queued_events;
 
-    Vector<GUI_Event> m_unprocessed_events;
+    Vector<GUI_ServerMessage> m_unprocessed_messages;
 
     int m_event_fd { -1 };
     bool m_running { false };

+ 2 - 2
LibGUI/GMenuBar.cpp

@@ -20,7 +20,7 @@ int GMenuBar::realize_menubar()
 {
     GUI_ClientMessage request;
     request.type = GUI_ClientMessage::Type::CreateMenubar;
-    GUI_Event response = GEventLoop::main().sync_request(request, GUI_Event::Type::DidCreateMenubar);
+    GUI_ServerMessage response = GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidCreateMenubar);
     return response.menu.menubar_id;
 }
 
@@ -31,7 +31,7 @@ void GMenuBar::unrealize_menubar()
     GUI_ClientMessage request;
     request.type = GUI_ClientMessage::Type::DestroyMenubar;
     request.menu.menubar_id = m_menubar_id;
-    GEventLoop::main().sync_request(request, GUI_Event::Type::DidDestroyMenubar);
+    GEventLoop::main().sync_request(request, GUI_ServerMessage::Type::DidDestroyMenubar);
     m_menubar_id = 0;
 }
 

+ 13 - 13
Userland/guitest.cpp

@@ -51,30 +51,30 @@ int main(int argc, char** argv)
     }
 
     for (;;) {
-        GUI_Event event;
-        ssize_t nread = read(fd, &event, sizeof(event));
+        GUI_ServerMessage message;
+        ssize_t nread = read(fd, &message, sizeof(message));
         if (nread < 0) {
             perror("read");
             return 1;
         }
         dbgprintf("(%d) ", getpid());
-        assert(nread == sizeof(event));
-        switch (event.type) {
-        case GUI_Event::Type::Paint: dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", event.window_id, event.paint.rect.location.x, event.paint.rect.location.y, event.paint.rect.size.width, event.paint.rect.size.height); break;
-        case GUI_Event::Type::MouseDown: dbgprintf("WID=%x MouseDown %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
-        case GUI_Event::Type::MouseUp: dbgprintf("WID=%x MouseUp %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
-        case GUI_Event::Type::MouseMove: dbgprintf("WID=%x MouseMove %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
-        case GUI_Event::Type::WindowActivated: dbgprintf("WID=%x WindowActivated\n", event.window_id); break;
-        case GUI_Event::Type::WindowDeactivated: dbgprintf("WID=%x WindowDeactivated\n", event.window_id); break;
-        case GUI_Event::Type::WindowCloseRequest: return 0;
+        assert(nread == sizeof(message));
+        switch (message.type) {
+        case GUI_ServerMessage::Type::Paint: dbgprintf("WID=%x Paint [%d,%d %dx%d]\n", message.window_id, message.paint.rect.location.x, message.paint.rect.location.y, message.paint.rect.size.width, message.paint.rect.size.height); break;
+        case GUI_ServerMessage::Type::MouseDown: dbgprintf("WID=%x MouseDown %d,%d\n", message.window_id, message.mouse.position.x, message.mouse.position.y); break;
+        case GUI_ServerMessage::Type::MouseUp: dbgprintf("WID=%x MouseUp %d,%d\n", message.window_id, message.mouse.position.x, message.mouse.position.y); break;
+        case GUI_ServerMessage::Type::MouseMove: dbgprintf("WID=%x MouseMove %d,%d\n", message.window_id, message.mouse.position.x, message.mouse.position.y); break;
+        case GUI_ServerMessage::Type::WindowActivated: dbgprintf("WID=%x WindowActivated\n", message.window_id); break;
+        case GUI_ServerMessage::Type::WindowDeactivated: dbgprintf("WID=%x WindowDeactivated\n", message.window_id); break;
+        case GUI_ServerMessage::Type::WindowCloseRequest: return 0;
         }
 
-        if (event.type == GUI_Event::Type::Paint) {
+        if (message.type == GUI_ServerMessage::Type::Paint) {
             paint(*bitmap, backing.size.width, backing.size.height);
             gui_notify_paint_finished(window_id, nullptr);
         }
 
-        if (event.type == GUI_Event::Type::MouseDown) {
+        if (message.type == GUI_ServerMessage::Type::MouseDown) {
             gui_invalidate_window(window_id, nullptr);
         }
 

+ 2 - 2
WindowServer/WSMenu.cpp

@@ -140,8 +140,8 @@ void WSMenu::did_activate(WSMenuItem& item)
 
     close();
 
-    GUI_Event gui_event;
-    gui_event.type = GUI_Event::Type::MenuItemActivated;
+    GUI_ServerMessage gui_event;
+    gui_event.type = GUI_ServerMessage::Type::MenuItemActivated;
     gui_event.menu.menu_id = m_menu_id;
     gui_event.menu.identifier = item.identifier();
 

+ 1 - 1
WindowServer/WSMessageLoop.cpp

@@ -73,7 +73,7 @@ Process* WSMessageLoop::process_from_client_id(int client_id)
     return (Process*)client_id;
 }
 
-void WSMessageLoop::post_message_to_client(int client_id, const GUI_Event& message)
+void WSMessageLoop::post_message_to_client(int client_id, const GUI_ServerMessage& message)
 {
     auto* process = process_from_client_id(client_id);
     if (!process)

+ 2 - 2
WindowServer/WSMessageLoop.h

@@ -9,7 +9,7 @@
 
 class WSMessageReceiver;
 class Process;
-struct GUI_Event;
+struct GUI_ServerMessage;
 
 class WSMessageLoop {
 public:
@@ -30,7 +30,7 @@ public:
     int start_timer(int ms, Function<void()>&&);
     int stop_timer(int timer_id);
 
-    void post_message_to_client(int client_id, const GUI_Event&);
+    void post_message_to_client(int client_id, const GUI_ServerMessage&);
     ssize_t on_receive_from_client(int client_id, const byte*, size_t);
 
     static Process* process_from_client_id(int client_id);

+ 11 - 11
WindowServer/WSWindow.cpp

@@ -79,34 +79,34 @@ void WSWindow::on_message(WSMessage& message)
         return;
     }
 
-    GUI_Event gui_event;
+    GUI_ServerMessage gui_event;
     gui_event.window_id = window_id();
 
     switch (message.type()) {
     case WSMessage::WM_ClientWantsToPaint:
-        gui_event.type = GUI_Event::Type::Paint;
+        gui_event.type = GUI_ServerMessage::Type::Paint;
         gui_event.paint.rect = static_cast<WSClientWantsToPaintMessage&>(message).rect();
         break;
     case WSMessage::MouseMove:
-        gui_event.type = GUI_Event::Type::MouseMove;
+        gui_event.type = GUI_ServerMessage::Type::MouseMove;
         gui_event.mouse.position = static_cast<WSMouseEvent&>(message).position();
         gui_event.mouse.button = GUI_MouseButton::NoButton;
         gui_event.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
         break;
     case WSMessage::MouseDown:
-        gui_event.type = GUI_Event::Type::MouseDown;
+        gui_event.type = GUI_ServerMessage::Type::MouseDown;
         gui_event.mouse.position = static_cast<WSMouseEvent&>(message).position();
         gui_event.mouse.button = to_api(static_cast<WSMouseEvent&>(message).button());
         gui_event.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
         break;
     case WSMessage::MouseUp:
-        gui_event.type = GUI_Event::Type::MouseUp;
+        gui_event.type = GUI_ServerMessage::Type::MouseUp;
         gui_event.mouse.position = static_cast<WSMouseEvent&>(message).position();
         gui_event.mouse.button = to_api(static_cast<WSMouseEvent&>(message).button());
         gui_event.mouse.buttons = static_cast<WSMouseEvent&>(message).buttons();
         break;
     case WSMessage::KeyDown:
-        gui_event.type = GUI_Event::Type::KeyDown;
+        gui_event.type = GUI_ServerMessage::Type::KeyDown;
         gui_event.key.character = static_cast<WSKeyEvent&>(message).character();
         gui_event.key.key = static_cast<WSKeyEvent&>(message).key();
         gui_event.key.alt = static_cast<WSKeyEvent&>(message).alt();
@@ -114,7 +114,7 @@ void WSWindow::on_message(WSMessage& message)
         gui_event.key.shift = static_cast<WSKeyEvent&>(message).shift();
         break;
     case WSMessage::KeyUp:
-        gui_event.type = GUI_Event::Type::KeyUp;
+        gui_event.type = GUI_ServerMessage::Type::KeyUp;
         gui_event.key.character = static_cast<WSKeyEvent&>(message).character();
         gui_event.key.key = static_cast<WSKeyEvent&>(message).key();
         gui_event.key.alt = static_cast<WSKeyEvent&>(message).alt();
@@ -134,19 +134,19 @@ void WSWindow::on_message(WSMessage& message)
         delete this;
         return;
     case WSMessage::WindowActivated:
-        gui_event.type = GUI_Event::Type::WindowActivated;
+        gui_event.type = GUI_ServerMessage::Type::WindowActivated;
         break;
     case WSMessage::WindowDeactivated:
-        gui_event.type = GUI_Event::Type::WindowDeactivated;
+        gui_event.type = GUI_ServerMessage::Type::WindowDeactivated;
         break;
     case WSMessage::WindowCloseRequest:
-        gui_event.type = GUI_Event::Type::WindowCloseRequest;
+        gui_event.type = GUI_ServerMessage::Type::WindowCloseRequest;
         break;
     default:
         break;
     }
 
-    if (gui_event.type == GUI_Event::Type::Invalid)
+    if (gui_event.type == GUI_ServerMessage::Type::Invalid)
         return;
 
     {

+ 8 - 8
WindowServer/WSWindowManager.cpp

@@ -741,10 +741,10 @@ void WSWindowManager::on_message(WSMessage& message)
             int menubar_id = m_next_menubar_id++;
             auto menubar = make<WSMenuBar>(menubar_id, *WSMessageLoop::process_from_client_id(request.client_id()));
             m_menubars.set(menubar_id, move(menubar));
-            GUI_Event event;
-            event.type = GUI_Event::Type::DidCreateMenubar;
-            event.menu.menubar_id = menubar_id;
-            WSMessageLoop::the().post_message_to_client(request.client_id(), event);
+            GUI_ServerMessage response;
+            response.type = GUI_ServerMessage::Type::DidCreateMenubar;
+            response.menu.menubar_id = menubar_id;
+            WSMessageLoop::the().post_message_to_client(request.client_id(), response);
             break;
         }
         case WSMessage::APIDestroyMenubarRequest: {
@@ -759,10 +759,10 @@ void WSWindowManager::on_message(WSMessage& message)
             if (&menubar == m_current_menubar)
                 set_current_menubar(nullptr);
             m_menubars.remove(it);
-            GUI_Event event;
-            event.type = GUI_Event::Type::DidDestroyMenubar;
-            event.menu.menubar_id = menubar_id;
-            WSMessageLoop::the().post_message_to_client(request.client_id(), event);
+            GUI_ServerMessage response;
+            response.type = GUI_ServerMessage::Type::DidDestroyMenubar;
+            response.menu.menubar_id = menubar_id;
+            WSMessageLoop::the().post_message_to_client(request.client_id(), response);
         }
         default:
             break;