| 1 |
#include "config.h" |
| 2 |
#include <string.h> |
| 3 |
#ifdef HAVE_SYS_MMAN_H |
| 4 |
#include <sys/mman.h> |
| 5 |
#endif |
| 6 |
#include <sys/stat.h> |
| 7 |
#include <fcntl.h> |
| 8 |
#include <stdlib.h> |
| 9 |
#include <stdio.h> |
| 10 |
#include <locale.h> |
| 11 |
|
| 12 |
#include <glib.h> |
| 13 |
#include <gio/gio.h> |
| 14 |
#ifdef G_OS_UNIX |
| 15 |
#include <gio/gunixsocketaddress.h> |
| 16 |
#endif |
| 17 |
|
| 18 |
#include "broadway-server.h" |
| 19 |
|
| 20 |
BroadwayServer *server; |
| 21 |
GList *clients; |
| 22 |
|
| 23 |
static guint32 client_id_count = 1; |
| 24 |
|
| 25 |
/* Serials: |
| 26 |
* |
| 27 |
* Broadway tracks serials for all clients primarily to get the right behaviour wrt |
| 28 |
* grabs. Each request the client sends gets an increasing per-client serial number, starting |
| 29 |
* at 1. Thus, the client can now when a mouse event is seen whether the mouse event was |
| 30 |
* sent before or after the server saw the grab request from the client (as this affects how |
| 31 |
* the event is handled). |
| 32 |
* |
| 33 |
* There is only a single stream of increasing serials sent from the daemon to the web browser |
| 34 |
* though, called "daemon serials", so we need to map back from the daemon serials to the client |
| 35 |
* serials when we send an event to a client. So, each client keeps track of the mappings |
| 36 |
* between its serials and daemon serials for any outstanding requests. |
| 37 |
* |
| 38 |
* There is some additional complexity in that there may be multiple consecutive web browser |
| 39 |
* sessions, so we need to keep track of the last daemon serial used inbetween each web client |
| 40 |
* connection so that the daemon serials can be strictly increasing. |
| 41 |
*/ |
| 42 |
|
| 43 |
typedef struct { |
| 44 |
guint32 client_serial; |
| 45 |
guint32 daemon_serial; |
| 46 |
} BroadwaySerialMapping; |
| 47 |
|
| 48 |
typedef struct { |
| 49 |
guint32 id; |
| 50 |
GSocketConnection *connection; |
| 51 |
GBufferedInputStream *in; |
| 52 |
GSList *serial_mappings; |
| 53 |
GList *windows; |
| 54 |
guint disconnect_idle; |
| 55 |
} BroadwayClient; |
| 56 |
|
| 57 |
static void |
| 58 |
client_free (BroadwayClient *client) |
| 59 |
{ |
| 60 |
g_assert (client->windows == NULL); |
| 61 |
g_assert (client->disconnect_idle == 0); |
| 62 |
clients = g_list_remove (clients, client); |
| 63 |
g_object_unref (client->connection); |
| 64 |
g_object_unref (client->in); |
| 65 |
g_slist_free_full (client->serial_mappings, g_free); |
| 66 |
g_free (client); |
| 67 |
} |
| 68 |
|
| 69 |
static void |
| 70 |
client_disconnected (BroadwayClient *client) |
| 71 |
{ |
| 72 |
GList *l; |
| 73 |
|
| 74 |
if (client->disconnect_idle != 0) |
| 75 |
{ |
| 76 |
g_source_remove (client->disconnect_idle); |
| 77 |
client->disconnect_idle = 0; |
| 78 |
} |
| 79 |
|
| 80 |
for (l = client->windows; l != NULL; l = l->next) |
| 81 |
broadway_server_destroy_window (server, |
| 82 |
GPOINTER_TO_UINT (l->data)); |
| 83 |
g_list_free (client->windows); |
| 84 |
client->windows = NULL; |
| 85 |
|
| 86 |
broadway_server_flush (server); |
| 87 |
|
| 88 |
client_free (client); |
| 89 |
} |
| 90 |
|
| 91 |
static gboolean |
| 92 |
disconnect_idle_cb (BroadwayClient *client) |
| 93 |
{ |
| 94 |
client->disconnect_idle = 0; |
| 95 |
client_disconnected (client); |
| 96 |
return G_SOURCE_REMOVE; |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
client_disconnect_in_idle (BroadwayClient *client) |
| 101 |
{ |
| 102 |
if (client->disconnect_idle == 0) |
| 103 |
client->disconnect_idle = |
| 104 |
g_idle_add_full (G_PRIORITY_DEFAULT, (GSourceFunc)disconnect_idle_cb, client, NULL); |
| 105 |
} |
| 106 |
|
| 107 |
static void |
| 108 |
send_reply (BroadwayClient *client, |
| 109 |
BroadwayRequest *request, |
| 110 |
BroadwayReply *reply, |
| 111 |
gsize size, |
| 112 |
guint32 type) |
| 113 |
{ |
| 114 |
GOutputStream *output; |
| 115 |
|
| 116 |
reply->base.size = size; |
| 117 |
reply->base.in_reply_to = request ? request->base.serial : 0; |
| 118 |
reply->base.type = type; |
| 119 |
|
| 120 |
output = g_io_stream_get_output_stream (G_IO_STREAM (client->connection)); |
| 121 |
if (!g_output_stream_write_all (output, reply, size, NULL, NULL, NULL)) |
| 122 |
{ |
| 123 |
g_printerr ("can't write to client"); |
| 124 |
client_disconnect_in_idle (client); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
static void |
| 129 |
add_client_serial_mapping (BroadwayClient *client, |
| 130 |
guint32 client_serial, |
| 131 |
guint32 daemon_serial) |
| 132 |
{ |
| 133 |
BroadwaySerialMapping *map; |
| 134 |
GSList *last; |
| 135 |
|
| 136 |
last = g_slist_last (client->serial_mappings); |
| 137 |
|
| 138 |
if (last != NULL) |
| 139 |
{ |
| 140 |
map = last->data; |
| 141 |
|
| 142 |
/* If we have no web client, don't grow forever */ |
| 143 |
if (map->daemon_serial == daemon_serial) |
| 144 |
{ |
| 145 |
map->client_serial = client_serial; |
| 146 |
return; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
map = g_new0 (BroadwaySerialMapping, 1); |
| 151 |
map->client_serial = client_serial; |
| 152 |
map->daemon_serial = daemon_serial; |
| 153 |
client->serial_mappings = g_slist_append (client->serial_mappings, map); |
| 154 |
} |
| 155 |
|
| 156 |
/* Returns the latest seen client serial at the time we sent |
| 157 |
a daemon request to the browser with a specific daemon serial */ |
| 158 |
static guint32 |
| 159 |
get_client_serial (BroadwayClient *client, guint32 daemon_serial) |
| 160 |
{ |
| 161 |
BroadwaySerialMapping *map; |
| 162 |
GSList *l, *found; |
| 163 |
guint32 client_serial = 0; |
| 164 |
|
| 165 |
found = NULL; |
| 166 |
for (l = client->serial_mappings; l != NULL; l = l->next) |
| 167 |
{ |
| 168 |
map = l->data; |
| 169 |
|
| 170 |
if (map->daemon_serial <= daemon_serial) |
| 171 |
{ |
| 172 |
found = l; |
| 173 |
client_serial = map->client_serial; |
| 174 |
} |
| 175 |
else |
| 176 |
break; |
| 177 |
} |
| 178 |
|
| 179 |
/* Remove mappings before the found one, they will never more be used */ |
| 180 |
while (found != NULL && |
| 181 |
client->serial_mappings != found) |
| 182 |
{ |
| 183 |
g_free (client->serial_mappings->data); |
| 184 |
client->serial_mappings = |
| 185 |
g_slist_delete_link (client->serial_mappings, client->serial_mappings); |
| 186 |
} |
| 187 |
|
| 188 |
return client_serial; |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
static void |
| 193 |
client_handle_request (BroadwayClient *client, |
| 194 |
BroadwayRequest *request) |
| 195 |
{ |
| 196 |
BroadwayReplyNewWindow reply_new_window; |
| 197 |
BroadwayReplySync reply_sync; |
| 198 |
BroadwayReplyQueryMouse reply_query_mouse; |
| 199 |
BroadwayReplyGrabPointer reply_grab_pointer; |
| 200 |
BroadwayReplyUngrabPointer reply_ungrab_pointer; |
| 201 |
cairo_surface_t *surface; |
| 202 |
guint32 before_serial, now_serial; |
| 203 |
|
| 204 |
before_serial = broadway_server_get_next_serial (server); |
| 205 |
|
| 206 |
switch (request->base.type) |
| 207 |
{ |
| 208 |
case BROADWAY_REQUEST_NEW_WINDOW: |
| 209 |
reply_new_window.id = |
| 210 |
broadway_server_new_window (server, |
| 211 |
request->new_window.x, |
| 212 |
request->new_window.y, |
| 213 |
request->new_window.width, |
| 214 |
request->new_window.height, |
| 215 |
request->new_window.is_temp); |
| 216 |
client->windows = |
| 217 |
g_list_prepend (client->windows, |
| 218 |
GUINT_TO_POINTER (reply_new_window.id)); |
| 219 |
|
| 220 |
send_reply (client, request, (BroadwayReply *)&reply_new_window, sizeof (reply_new_window), |
| 221 |
BROADWAY_REPLY_NEW_WINDOW); |
| 222 |
break; |
| 223 |
case BROADWAY_REQUEST_FLUSH: |
| 224 |
broadway_server_flush (server); |
| 225 |
break; |
| 226 |
case BROADWAY_REQUEST_SYNC: |
| 227 |
broadway_server_flush (server); |
| 228 |
send_reply (client, request, (BroadwayReply *)&reply_sync, sizeof (reply_sync), |
| 229 |
BROADWAY_REPLY_SYNC); |
| 230 |
break; |
| 231 |
case BROADWAY_REQUEST_QUERY_MOUSE: |
| 232 |
broadway_server_query_mouse (server, |
| 233 |
&reply_query_mouse.toplevel, |
| 234 |
&reply_query_mouse.root_x, |
| 235 |
&reply_query_mouse.root_y, |
| 236 |
&reply_query_mouse.mask); |
| 237 |
send_reply (client, request, (BroadwayReply *)&reply_query_mouse, sizeof (reply_query_mouse), |
| 238 |
BROADWAY_REPLY_QUERY_MOUSE); |
| 239 |
break; |
| 240 |
case BROADWAY_REQUEST_DESTROY_WINDOW: |
| 241 |
client->windows = |
| 242 |
g_list_remove (client->windows, |
| 243 |
GUINT_TO_POINTER (request->destroy_window.id)); |
| 244 |
broadway_server_destroy_window (server, request->destroy_window.id); |
| 245 |
break; |
| 246 |
case BROADWAY_REQUEST_SHOW_WINDOW: |
| 247 |
broadway_server_window_show (server, request->show_window.id); |
| 248 |
break; |
| 249 |
case BROADWAY_REQUEST_HIDE_WINDOW: |
| 250 |
broadway_server_window_hide (server, request->hide_window.id); |
| 251 |
break; |
| 252 |
case BROADWAY_REQUEST_SET_TRANSIENT_FOR: |
| 253 |
broadway_server_window_set_transient_for (server, |
| 254 |
request->set_transient_for.id, |
| 255 |
request->set_transient_for.parent); |
| 256 |
break; |
| 257 |
case BROADWAY_REQUEST_UPDATE: |
| 258 |
surface = broadway_server_open_surface (server, |
| 259 |
request->update.id, |
| 260 |
request->update.name, |
| 261 |
request->update.width, |
| 262 |
request->update.height); |
| 263 |
if (surface != NULL) |
| 264 |
{ |
| 265 |
broadway_server_window_update (server, |
| 266 |
request->update.id, |
| 267 |
surface); |
| 268 |
cairo_surface_destroy (surface); |
| 269 |
} |
| 270 |
break; |
| 271 |
case BROADWAY_REQUEST_MOVE_RESIZE: |
| 272 |
broadway_server_window_move_resize (server, |
| 273 |
request->move_resize.id, |
| 274 |
request->move_resize.with_move, |
| 275 |
request->move_resize.x, |
| 276 |
request->move_resize.y, |
| 277 |
request->move_resize.width, |
| 278 |
request->move_resize.height); |
| 279 |
break; |
| 280 |
case BROADWAY_REQUEST_GRAB_POINTER: |
| 281 |
reply_grab_pointer.status = |
| 282 |
broadway_server_grab_pointer (server, |
| 283 |
client->id, |
| 284 |
request->grab_pointer.id, |
| 285 |
request->grab_pointer.owner_events, |
| 286 |
request->grab_pointer.event_mask, |
| 287 |
request->grab_pointer.time_); |
| 288 |
send_reply (client, request, (BroadwayReply *)&reply_grab_pointer, sizeof (reply_grab_pointer), |
| 289 |
BROADWAY_REPLY_GRAB_POINTER); |
| 290 |
break; |
| 291 |
case BROADWAY_REQUEST_UNGRAB_POINTER: |
| 292 |
reply_ungrab_pointer.status = |
| 293 |
broadway_server_ungrab_pointer (server, |
| 294 |
request->ungrab_pointer.time_); |
| 295 |
send_reply (client, request, (BroadwayReply *)&reply_ungrab_pointer, sizeof (reply_ungrab_pointer), |
| 296 |
BROADWAY_REPLY_UNGRAB_POINTER); |
| 297 |
break; |
| 298 |
case BROADWAY_REQUEST_FOCUS_WINDOW: |
| 299 |
broadway_server_focus_window (server, request->focus_window.id); |
| 300 |
break; |
| 301 |
case BROADWAY_REQUEST_SET_SHOW_KEYBOARD: |
| 302 |
broadway_server_set_show_keyboard (server, request->set_show_keyboard.show_keyboard); |
| 303 |
break; |
| 304 |
case BROADWAY_REQUEST_SET_MODAL_HINT: |
| 305 |
broadway_server_window_set_modal_hint (server, |
| 306 |
request->set_modal_hint.id, |
| 307 |
request->set_modal_hint.modal_hint); |
| 308 |
break; |
| 309 |
default: |
| 310 |
g_warning ("Unknown request of type %d", request->base.type); |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
now_serial = broadway_server_get_next_serial (server); |
| 315 |
|
| 316 |
/* If we sent a new output request, map that this client serial to that, otherwise |
| 317 |
update old mapping for previously sent daemon serial */ |
| 318 |
if (now_serial != before_serial) |
| 319 |
add_client_serial_mapping (client, |
| 320 |
request->base.serial, |
| 321 |
before_serial); |
| 322 |
else |
| 323 |
add_client_serial_mapping (client, |
| 324 |
request->base.serial, |
| 325 |
before_serial - 1); |
| 326 |
} |
| 327 |
|
| 328 |
static void |
| 329 |
client_fill_cb (GObject *source_object, |
| 330 |
GAsyncResult *result, |
| 331 |
gpointer user_data) |
| 332 |
{ |
| 333 |
BroadwayClient *client = user_data; |
| 334 |
gssize res; |
| 335 |
|
| 336 |
res = g_buffered_input_stream_fill_finish (client->in, result, NULL); |
| 337 |
|
| 338 |
if (res > 0) |
| 339 |
{ |
| 340 |
guint32 size; |
| 341 |
gsize count, remaining; |
| 342 |
guint8 *buffer; |
| 343 |
|
| 344 |
buffer = (guint8 *)g_buffered_input_stream_peek_buffer (client->in, &count); |
| 345 |
|
| 346 |
remaining = count; |
| 347 |
while (remaining >= sizeof (guint32)) |
| 348 |
{ |
| 349 |
memcpy (&size, buffer, sizeof (guint32)); |
| 350 |
|
| 351 |
if (size <= remaining) |
| 352 |
{ |
| 353 |
client_handle_request (client, (BroadwayRequest *)buffer); |
| 354 |
|
| 355 |
remaining -= size; |
| 356 |
buffer += size; |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
/* This is guaranteed not to block */ |
| 361 |
g_input_stream_skip (G_INPUT_STREAM (client->in), count - remaining, NULL, NULL); |
| 362 |
|
| 363 |
g_buffered_input_stream_fill_async (client->in, |
| 364 |
4*1024, |
| 365 |
0, |
| 366 |
NULL, |
| 367 |
client_fill_cb, client); |
| 368 |
} |
| 369 |
else |
| 370 |
{ |
| 371 |
client_disconnected (client); |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
static gboolean |
| 377 |
incoming_client (GSocketService *service, |
| 378 |
GSocketConnection *connection, |
| 379 |
GObject *source_object) |
| 380 |
{ |
| 381 |
BroadwayClient *client; |
| 382 |
GInputStream *input; |
| 383 |
BroadwayInputMsg ev = { {0} }; |
| 384 |
|
| 385 |
client = g_new0 (BroadwayClient, 1); |
| 386 |
client->id = client_id_count++; |
| 387 |
client->connection = g_object_ref (connection); |
| 388 |
|
| 389 |
input = g_io_stream_get_input_stream (G_IO_STREAM (client->connection)); |
| 390 |
client->in = (GBufferedInputStream *)g_buffered_input_stream_new (input); |
| 391 |
|
| 392 |
clients = g_list_prepend (clients, client); |
| 393 |
|
| 394 |
g_buffered_input_stream_fill_async (client->in, |
| 395 |
4*1024, |
| 396 |
0, |
| 397 |
NULL, |
| 398 |
client_fill_cb, client); |
| 399 |
|
| 400 |
/* Send initial resize notify */ |
| 401 |
ev.base.type = BROADWAY_EVENT_SCREEN_SIZE_CHANGED; |
| 402 |
ev.base.serial = broadway_server_get_next_serial (server) - 1; |
| 403 |
ev.base.time = broadway_server_get_last_seen_time (server); |
| 404 |
broadway_server_get_screen_size (server, |
| 405 |
&ev.screen_resize_notify.width, |
| 406 |
&ev.screen_resize_notify.height); |
| 407 |
|
| 408 |
broadway_events_got_input (&ev, |
| 409 |
client->id); |
| 410 |
|
| 411 |
return TRUE; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
int |
| 416 |
main (int argc, char *argv[]) |
| 417 |
{ |
| 418 |
GError *error = NULL; |
| 419 |
GOptionContext *context; |
| 420 |
GMainLoop *loop; |
| 421 |
GInetAddress *inet; |
| 422 |
GSocketAddress *address; |
| 423 |
GSocketService *listener; |
| 424 |
char *http_address = NULL; |
| 425 |
char *unixsocket_address = NULL; |
| 426 |
int http_port = 0; |
| 427 |
char *ssl_cert = NULL; |
| 428 |
char *ssl_key = NULL; |
| 429 |
char *display; |
| 430 |
int port = 0; |
| 431 |
const GOptionEntry entries[] = { |
| 432 |
{ "port", 'p', 0, G_OPTION_ARG_INT, &http_port, "Httpd port", "PORT" }, |
| 433 |
{ "address", 'a', 0, G_OPTION_ARG_STRING, &http_address, "Ip address to bind to ", "ADDRESS" }, |
| 434 |
#ifdef G_OS_UNIX |
| 435 |
{ "unixsocket", 'u', 0, G_OPTION_ARG_STRING, &unixsocket_address, "Unix domain socket address", "ADDRESS" }, |
| 436 |
#endif |
| 437 |
{ "cert", 'c', 0, G_OPTION_ARG_STRING, &ssl_cert, "SSL certificate path", "PATH" }, |
| 438 |
{ "key", 'k', 0, G_OPTION_ARG_STRING, &ssl_key, "SSL key path", "PATH" }, |
| 439 |
{ NULL } |
| 440 |
}; |
| 441 |
|
| 442 |
setlocale (LC_ALL, ""); |
| 443 |
|
| 444 |
context = g_option_context_new ("[:DISPLAY] - broadway display daemon"); |
| 445 |
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); |
| 446 |
if (!g_option_context_parse (context, &argc, &argv, &error)) |
| 447 |
{ |
| 448 |
g_printerr ("option parsing failed: %s\n", error->message); |
| 449 |
exit (1); |
| 450 |
} |
| 451 |
|
| 452 |
display = NULL; |
| 453 |
if (argc > 1) |
| 454 |
{ |
| 455 |
if (*argv[1] != ':') |
| 456 |
{ |
| 457 |
g_printerr ("Usage broadwayd [:DISPLAY]\n"); |
| 458 |
exit (1); |
| 459 |
} |
| 460 |
display = argv[1]; |
| 461 |
} |
| 462 |
|
| 463 |
if (display == NULL) |
| 464 |
{ |
| 465 |
#ifdef G_OS_UNIX |
| 466 |
if (g_unix_socket_address_abstract_names_supported ()) |
| 467 |
display = ":0"; |
| 468 |
else |
| 469 |
#endif |
| 470 |
display = ":tcp"; |
| 471 |
} |
| 472 |
|
| 473 |
if (g_str_has_prefix (display, ":tcp")) |
| 474 |
{ |
| 475 |
port = strtol (display + strlen (":tcp"), NULL, 10); |
| 476 |
|
| 477 |
inet = g_inet_address_new_from_string ("127.0.0.1"); |
| 478 |
g_print ("Listening on 127.0.0.1:%d\n", port + 9090); |
| 479 |
address = g_inet_socket_address_new (inet, port + 9090); |
| 480 |
g_object_unref (inet); |
| 481 |
} |
| 482 |
#ifdef G_OS_UNIX |
| 483 |
else if (display[0] == ':' && g_ascii_isdigit(display[1])) |
| 484 |
{ |
| 485 |
char *path, *basename; |
| 486 |
|
| 487 |
port = strtol (display + strlen (":"), NULL, 10); |
| 488 |
basename = g_strdup_printf ("broadway%d.socket", port + 1); |
| 489 |
path = g_build_filename (g_get_user_runtime_dir (), basename, NULL); |
| 490 |
g_free (basename); |
| 491 |
|
| 492 |
g_print ("Listening on %s\n", path); |
| 493 |
address = g_unix_socket_address_new_with_type (path, -1, |
| 494 |
G_UNIX_SOCKET_ADDRESS_ABSTRACT); |
| 495 |
g_free (path); |
| 496 |
} |
| 497 |
#endif |
| 498 |
else |
| 499 |
{ |
| 500 |
g_printerr ("Failed to parse display %s\n", display); |
| 501 |
exit (1); |
| 502 |
} |
| 503 |
|
| 504 |
if (http_port == 0) |
| 505 |
http_port = 8080 + port; |
| 506 |
|
| 507 |
if (unixsocket_address != NULL) |
| 508 |
server = broadway_server_on_unix_socket_new (unixsocket_address, &error); |
| 509 |
else |
| 510 |
server = broadway_server_new (http_address, |
| 511 |
http_port, |
| 512 |
ssl_cert, |
| 513 |
ssl_key, |
| 514 |
&error); |
| 515 |
|
| 516 |
if (server == NULL) |
| 517 |
{ |
| 518 |
g_printerr ("%s\n", error->message); |
| 519 |
return 1; |
| 520 |
} |
| 521 |
|
| 522 |
listener = g_socket_service_new (); |
| 523 |
if (!g_socket_listener_add_address (G_SOCKET_LISTENER (listener), |
| 524 |
address, |
| 525 |
G_SOCKET_TYPE_STREAM, |
| 526 |
G_SOCKET_PROTOCOL_DEFAULT, |
| 527 |
G_OBJECT (server), |
| 528 |
NULL, |
| 529 |
&error)) |
| 530 |
{ |
| 531 |
g_printerr ("Can't listen: %s\n", error->message); |
| 532 |
return 1; |
| 533 |
} |
| 534 |
g_object_unref (address); |
| 535 |
g_signal_connect (listener, "incoming", G_CALLBACK (incoming_client), NULL); |
| 536 |
|
| 537 |
g_socket_service_start (G_SOCKET_SERVICE (listener)); |
| 538 |
|
| 539 |
loop = g_main_loop_new (NULL, FALSE); |
| 540 |
g_main_loop_run (loop); |
| 541 |
|
| 542 |
return 0; |
| 543 |
} |
| 544 |
|
| 545 |
static gsize |
| 546 |
get_event_size (int type) |
| 547 |
{ |
| 548 |
switch (type) |
| 549 |
{ |
| 550 |
case BROADWAY_EVENT_ENTER: |
| 551 |
case BROADWAY_EVENT_LEAVE: |
| 552 |
return sizeof (BroadwayInputCrossingMsg); |
| 553 |
case BROADWAY_EVENT_POINTER_MOVE: |
| 554 |
return sizeof (BroadwayInputPointerMsg); |
| 555 |
case BROADWAY_EVENT_BUTTON_PRESS: |
| 556 |
case BROADWAY_EVENT_BUTTON_RELEASE: |
| 557 |
return sizeof (BroadwayInputButtonMsg); |
| 558 |
case BROADWAY_EVENT_SCROLL: |
| 559 |
return sizeof (BroadwayInputScrollMsg); |
| 560 |
case BROADWAY_EVENT_TOUCH: |
| 561 |
return sizeof (BroadwayInputTouchMsg); |
| 562 |
case BROADWAY_EVENT_KEY_PRESS: |
| 563 |
case BROADWAY_EVENT_KEY_RELEASE: |
| 564 |
return sizeof (BroadwayInputKeyMsg); |
| 565 |
case BROADWAY_EVENT_GRAB_NOTIFY: |
| 566 |
case BROADWAY_EVENT_UNGRAB_NOTIFY: |
| 567 |
return sizeof (BroadwayInputGrabReply); |
| 568 |
case BROADWAY_EVENT_CONFIGURE_NOTIFY: |
| 569 |
return sizeof (BroadwayInputConfigureNotify); |
| 570 |
case BROADWAY_EVENT_DELETE_NOTIFY: |
| 571 |
return sizeof (BroadwayInputDeleteNotify); |
| 572 |
case BROADWAY_EVENT_SCREEN_SIZE_CHANGED: |
| 573 |
return sizeof (BroadwayInputScreenResizeNotify); |
| 574 |
case BROADWAY_EVENT_FOCUS: |
| 575 |
return sizeof (BroadwayInputFocusMsg); |
| 576 |
default: |
| 577 |
g_assert_not_reached (); |
| 578 |
} |
| 579 |
return 0; |
| 580 |
} |
| 581 |
|
| 582 |
void |
| 583 |
broadway_events_got_input (BroadwayInputMsg *message, |
| 584 |
gint32 client_id) |
| 585 |
{ |
| 586 |
GList *l; |
| 587 |
BroadwayReplyEvent reply_event; |
| 588 |
gsize size; |
| 589 |
guint32 daemon_serial; |
| 590 |
|
| 591 |
size = get_event_size (message->base.type); |
| 592 |
g_assert (sizeof (BroadwayReplyBase) + size <= sizeof (BroadwayReplyEvent)); |
| 593 |
|
| 594 |
memset (&reply_event, 0, sizeof (BroadwayReplyEvent)); |
| 595 |
daemon_serial = message->base.serial; |
| 596 |
|
| 597 |
memcpy (&reply_event.msg, message, size); |
| 598 |
|
| 599 |
for (l = clients; l != NULL; l = l->next) |
| 600 |
{ |
| 601 |
BroadwayClient *client = l->data; |
| 602 |
|
| 603 |
if (client_id == -1 || |
| 604 |
client->id == client_id) |
| 605 |
{ |
| 606 |
reply_event.msg.base.serial = get_client_serial (client, daemon_serial); |
| 607 |
|
| 608 |
send_reply (client, NULL, (BroadwayReply *)&reply_event, |
| 609 |
G_STRUCT_OFFSET (BroadwayReplyEvent, msg) + size, |
| 610 |
BROADWAY_REPLY_EVENT); |
| 611 |
} |
| 612 |
} |
| 613 |
} |