mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
WindowServer: Simplify a few things in WSEventLoop.
This commit is contained in:
parent
94a5e08faf
commit
2af729a58a
2 changed files with 27 additions and 45 deletions
|
@ -44,11 +44,6 @@ WSEventLoop::~WSEventLoop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WSEventLoop& WSEventLoop::the()
|
|
||||||
{
|
|
||||||
return static_cast<WSEventLoop&>(CEventLoop::current());
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSEventLoop::drain_server()
|
void WSEventLoop::drain_server()
|
||||||
{
|
{
|
||||||
sockaddr_un address;
|
sockaddr_un address;
|
||||||
|
@ -102,14 +97,6 @@ void WSEventLoop::drain_keyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSEventLoop::notify_client_disconnected(int client_id)
|
|
||||||
{
|
|
||||||
auto* client = WSClientConnection::from_client_id(client_id);
|
|
||||||
if (!client)
|
|
||||||
return;
|
|
||||||
post_event(*client, make<WSClientDisconnectedNotification>(client_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
static WSWindowType from_api(WSAPI_WindowType api_type)
|
static WSWindowType from_api(WSAPI_WindowType api_type)
|
||||||
{
|
{
|
||||||
switch (api_type) {
|
switch (api_type) {
|
||||||
|
@ -261,24 +248,28 @@ void WSEventLoop::process_file_descriptors_after_select(const fd_set& fds)
|
||||||
if (FD_ISSET(m_mouse_fd, &fds))
|
if (FD_ISSET(m_mouse_fd, &fds))
|
||||||
drain_mouse();
|
drain_mouse();
|
||||||
WSClientConnection::for_each_client([&] (WSClientConnection& client) {
|
WSClientConnection::for_each_client([&] (WSClientConnection& client) {
|
||||||
if (!FD_ISSET(client.fd(), &fds))
|
if (FD_ISSET(client.fd(), &fds))
|
||||||
return;
|
drain_client(client);
|
||||||
unsigned messages_received = 0;
|
|
||||||
for (;;) {
|
|
||||||
WSAPI_ClientMessage message;
|
|
||||||
// FIXME: Don't go one message at a time, that's so much context switching, oof.
|
|
||||||
ssize_t nread = read(client.fd(), &message, sizeof(WSAPI_ClientMessage));
|
|
||||||
if (nread == 0) {
|
|
||||||
if (!messages_received)
|
|
||||||
notify_client_disconnected(client.client_id());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (nread < 0) {
|
|
||||||
perror("read");
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
on_receive_from_client(client.client_id(), message);
|
|
||||||
++messages_received;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WSEventLoop::drain_client(WSClientConnection& client)
|
||||||
|
{
|
||||||
|
unsigned messages_received = 0;
|
||||||
|
for (;;) {
|
||||||
|
WSAPI_ClientMessage message;
|
||||||
|
// FIXME: Don't go one message at a time, that's so much context switching, oof.
|
||||||
|
ssize_t nread = read(client.fd(), &message, sizeof(WSAPI_ClientMessage));
|
||||||
|
if (nread == 0) {
|
||||||
|
if (!messages_received)
|
||||||
|
post_event(client, make<WSClientDisconnectedNotification>(client.client_id()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (nread < 0) {
|
||||||
|
perror("read");
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
on_receive_from_client(client.client_id(), message);
|
||||||
|
++messages_received;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,35 +1,26 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "WSEvent.h"
|
|
||||||
#include <AK/HashMap.h>
|
|
||||||
#include <AK/OwnPtr.h>
|
|
||||||
#include <AK/Vector.h>
|
|
||||||
#include <AK/Function.h>
|
|
||||||
#include <AK/WeakPtr.h>
|
|
||||||
#include <LibCore/CEventLoop.h>
|
#include <LibCore/CEventLoop.h>
|
||||||
|
|
||||||
class CObject;
|
class WSClientConnection;
|
||||||
struct WSAPI_ClientMessage;
|
struct WSAPI_ClientMessage;
|
||||||
struct WSAPI_ServerMessage;
|
|
||||||
|
|
||||||
class WSEventLoop : public CEventLoop {
|
class WSEventLoop : public CEventLoop {
|
||||||
public:
|
public:
|
||||||
WSEventLoop();
|
WSEventLoop();
|
||||||
virtual ~WSEventLoop() override;
|
virtual ~WSEventLoop() override;
|
||||||
|
|
||||||
static WSEventLoop& the();
|
static WSEventLoop& the() { return static_cast<WSEventLoop&>(CEventLoop::current()); }
|
||||||
|
|
||||||
void on_receive_from_client(int client_id, const WSAPI_ClientMessage&);
|
|
||||||
void notify_client_disconnected(int client_id);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void add_file_descriptors_for_select(fd_set&, int& max_fd_added) override;
|
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;
|
virtual void process_file_descriptors_after_select(const fd_set&) override;
|
||||||
virtual void do_processing() override { }
|
|
||||||
|
|
||||||
void drain_server();
|
void drain_server();
|
||||||
void drain_mouse();
|
void drain_mouse();
|
||||||
void drain_keyboard();
|
void drain_keyboard();
|
||||||
|
void drain_client(WSClientConnection&);
|
||||||
|
void on_receive_from_client(int client_id, const WSAPI_ClientMessage&);
|
||||||
|
|
||||||
int m_keyboard_fd { -1 };
|
int m_keyboard_fd { -1 };
|
||||||
int m_mouse_fd { -1 };
|
int m_mouse_fd { -1 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue