]> Pileus Git - ~andy/gtk/blob - gdk/broadway/gdkdisplay-broadway.c
broadway: Break out websockets parsing and message processing
[~andy/gtk] / gdk / broadway / gdkdisplay-broadway.c
1 /* GDK - The GIMP Drawing Kit
2  * gdkdisplay-broadway.c
3  * 
4  * Copyright 2001 Sun Microsystems Inc.
5  * Copyright (C) 2004 Nokia Corporation
6  *
7  * Erwann Chenede <erwann.chenede@sun.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include "config.h"
26
27 #include "gdkdisplay-broadway.h"
28
29 #include "gdkdisplay.h"
30 #include "gdkeventsource.h"
31 #include "gdkscreen.h"
32 #include "gdkscreen-broadway.h"
33 #include "gdkinternals.h"
34 #include "gdkdeviceprivate.h"
35 #include "gdkdevicemanager-broadway.h"
36
37 #include <glib.h>
38 #include <glib/gprintf.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <errno.h>
42 #include <unistd.h>
43
44 static void   gdk_broadway_display_dispose            (GObject            *object);
45 static void   gdk_broadway_display_finalize           (GObject            *object);
46
47 G_DEFINE_TYPE (GdkBroadwayDisplay, gdk_broadway_display, GDK_TYPE_DISPLAY)
48
49 static void
50 gdk_broadway_display_init (GdkBroadwayDisplay *display)
51 {
52   _gdk_broadway_display_manager_add_display (gdk_display_manager_get (),
53                                              GDK_DISPLAY_OBJECT (display));
54   display->id_ht = g_hash_table_new (NULL, NULL);
55 }
56
57 static void
58 gdk_event_init (GdkDisplay *display)
59 {
60   GdkBroadwayDisplay *broadway_display;
61
62   broadway_display = GDK_BROADWAY_DISPLAY (display);
63   broadway_display->event_source = _gdk_broadway_event_source_new (display);
64   broadway_display->saved_serial = 1;
65 }
66
67 static void
68 gdk_broadway_display_init_input (GdkDisplay *display)
69 {
70   GdkBroadwayDisplay *broadway_display;
71   GdkDeviceManager *device_manager;
72   GdkDevice *device;
73   GList *list, *l;
74
75   broadway_display = GDK_BROADWAY_DISPLAY (display);
76   device_manager = gdk_display_get_device_manager (display);
77
78   /* For backwards compatibility, just add
79    * floating devices that are not keyboards.
80    */
81   list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
82
83   for (l = list; l; l = l->next)
84     {
85       device = l->data;
86
87       if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
88         continue;
89
90       broadway_display->input_devices = g_list_prepend (broadway_display->input_devices,
91                                                    g_object_ref (l->data));
92     }
93
94   g_list_free (list);
95
96   /* Now set "core" pointer to the first
97    * master device that is a pointer.
98    */
99   list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
100
101   for (l = list; l; l = l->next)
102     {
103       device = list->data;
104
105       if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
106         continue;
107
108       display->core_pointer = device;
109       break;
110     }
111
112   /* Add the core pointer to the devices list */
113   broadway_display->input_devices = g_list_prepend (broadway_display->input_devices,
114                                                g_object_ref (display->core_pointer));
115
116   g_list_free (list);
117 }
118
119 typedef struct HttpRequest {
120   GdkDisplay *display;
121   GSocketConnection *connection;
122   GDataInputStream *data;
123   GString *request;
124 }  HttpRequest;
125
126 static void
127 http_request_free (HttpRequest *request)
128 {
129   g_object_unref (request->connection);
130   g_object_unref (request->data);
131   g_string_free (request->request, TRUE);
132   g_free (request);
133 }
134
135 struct BroadwayInput {
136   GdkDisplay *display;
137   GSocketConnection *connection;
138   GByteArray *buffer;
139   GSource *source;
140 };
141
142 static void
143 broadway_input_free (BroadwayInput *input)
144 {
145   g_object_unref (input->connection);
146   g_byte_array_free (input->buffer, FALSE);
147   g_source_destroy (input->source);
148   g_free (input);
149 }
150
151 static void
152 process_input_messages (GdkBroadwayDisplay *broadway_display)
153 {
154   char *message;
155
156   while (broadway_display->input_messages)
157     {
158       message = broadway_display->input_messages->data;
159       broadway_display->input_messages =
160         g_list_delete_link (broadway_display->input_messages,
161                             broadway_display->input_messages);
162
163       _gdk_broadway_events_got_input (GDK_DISPLAY (broadway_display), message);
164       g_free (message);
165     }
166 }
167
168 static void
169 parse_input (BroadwayInput *input)
170 {
171   GdkBroadwayDisplay *broadway_display;
172   char *buf, *ptr, *message;
173   gsize len;
174
175   broadway_display = GDK_BROADWAY_DISPLAY (input->display);
176
177   buf = (char *)input->buffer->data;
178   len = input->buffer->len;
179
180   if (len == 0)
181     return;
182
183   if (buf[0] != 0)
184     {
185       broadway_display->input = NULL;
186       broadway_input_free (input);
187       return;
188     }
189
190   while ((ptr = memchr (buf, 0xff, len)) != NULL)
191     {
192       ptr++;
193
194       message = g_strndup (buf+1, (ptr-1) - (buf + 1));
195       broadway_display->input_messages = g_list_append (broadway_display->input_messages, message);
196
197       len -= ptr - buf;
198       buf = ptr;
199
200       if (len > 0 && buf[0] != 0)
201         {
202           broadway_display->input = NULL;
203           broadway_input_free (input);
204           break;
205         }
206     }
207
208   g_byte_array_remove_range (input->buffer, 0, buf - (char *)input->buffer->data);
209 }
210
211 static gboolean
212 input_data_cb (GObject  *stream,
213                BroadwayInput *input)
214 {
215   GdkBroadwayDisplay *broadway_display;
216   GInputStream *in;
217   gssize res;
218   guint8 buffer[1024];
219   GError *error;
220
221   broadway_display = GDK_BROADWAY_DISPLAY (input->display);
222   in = g_io_stream_get_input_stream (G_IO_STREAM (input->connection));
223
224   error = NULL;
225   res = g_pollable_input_stream_read_nonblocking (G_POLLABLE_INPUT_STREAM (in),
226                                                   buffer, sizeof (buffer), NULL, &error);
227
228   if (res <= 0)
229     {
230       if (res < 0 &&
231           g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
232         {
233           g_error_free (error);
234           return TRUE;
235         }
236
237       broadway_display->input = NULL;
238       broadway_input_free (input);
239       if (res < 0)
240         {
241           g_print ("input error %s", error->message);
242           g_error_free (error);
243         }
244       return FALSE;
245     }
246
247   g_byte_array_append (input->buffer, buffer, res);
248
249   parse_input (input);
250   process_input_messages (broadway_display);
251
252   return TRUE;
253 }
254
255 #include <unistd.h>
256 #include <fcntl.h>
257 static void
258 set_fd_blocking (int fd)
259 {
260   glong arg;
261
262   if ((arg = fcntl (fd, F_GETFL, NULL)) < 0)
263     arg = 0;
264
265   arg = arg & ~O_NONBLOCK;
266
267   fcntl (fd, F_SETFL, arg);
268 }
269
270 static char *
271 parse_line (char *line, char *key)
272 {
273   char *p;
274
275   if (!g_str_has_prefix (line, key))
276     return NULL;
277   p = line + strlen (key);
278   if (*p != ':')
279     return NULL;
280   p++;
281   /* Skip optional initial space */
282   if (*p == ' ')
283     p++;
284   return p;
285 }
286 static void
287 send_error (HttpRequest *request,
288             int error_code,
289             const char *reason)
290 {
291   char *res;
292
293   res = g_strdup_printf ("HTTP/1.0 %d %s\r\n\r\n"
294                          "<html><head><title>%d %s</title></head>"
295                          "<body>%s</body></html>",
296                          error_code, reason,
297                          error_code, reason,
298                          reason);
299   /* TODO: This should really be async */
300   g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
301                              res, strlen (res), NULL, NULL, NULL);
302   g_free (res);
303   http_request_free (request);
304 }
305
306 static void
307 start_input (HttpRequest *request)
308 {
309   char **lines;
310   char *p;
311   int num_key1, num_key2;
312   guint64 key1, key2;
313   int num_space;
314   int i;
315   guint8 challenge[16];
316   char *res;
317   gsize len;
318   GChecksum *checksum;
319   char *origin, *host;
320   GdkBroadwayDisplay *broadway_display;
321   BroadwayInput *input;
322   const void *data_buffer;
323   gsize data_buffer_size;
324   GInputStream *in;
325
326   broadway_display = GDK_BROADWAY_DISPLAY (request->display);
327
328   if (broadway_display->input != NULL)
329     {
330       send_error (request, 409, "Input already handled");
331       return;
332     }
333
334   lines = g_strsplit (request->request->str, "\n", 0);
335
336   num_key1 = 0;
337   num_key2 = 0;
338   key1 = 0;
339   key2 = 0;
340   origin = NULL;
341   host = NULL;
342   for (i = 0; lines[i] != NULL; i++)
343     {
344       if ((p = parse_line (lines[i], "Sec-WebSocket-Key1")))
345         {
346           num_space = 0;
347           while (*p != 0)
348             {
349               if (g_ascii_isdigit (*p))
350                 key1 = key1 * 10 + g_ascii_digit_value (*p);
351               else if (*p == ' ')
352                 num_space++;
353
354               p++;
355             }
356           key1 /= num_space;
357           num_key1++;
358         }
359       else if ((p = parse_line (lines[i], "Sec-WebSocket-Key2")))
360         {
361           num_space = 0;
362           while (*p != 0)
363             {
364               if (g_ascii_isdigit (*p))
365                 key2 = key2 * 10 + g_ascii_digit_value (*p);
366               else if (*p == ' ')
367                 num_space++;
368
369               p++;
370             }
371           key2 /= num_space;
372           num_key2++;
373         }
374       else if ((p = parse_line (lines[i], "Origin")))
375         {
376           origin = p;
377         }
378       else if ((p = parse_line (lines[i], "Host")))
379         {
380           host = p;
381         }
382     }
383
384   if (num_key1 != 1 || num_key2 != 1 || origin == NULL || host == NULL)
385     {
386       g_strfreev (lines);
387       send_error (request, 400, "Bad websocket request");
388       return;
389     }
390
391   challenge[0] = (key1 >> 24) & 0xff;
392   challenge[1] = (key1 >> 16) & 0xff;
393   challenge[2] = (key1 >>  8) & 0xff;
394   challenge[3] = (key1 >>  0) & 0xff;
395   challenge[4] = (key2 >> 24) & 0xff;
396   challenge[5] = (key2 >> 16) & 0xff;
397   challenge[6] = (key2 >>  8) & 0xff;
398   challenge[7] = (key2 >>  0) & 0xff;
399
400   if (!g_input_stream_read_all (G_INPUT_STREAM (request->data), challenge+8, 8, NULL, NULL, NULL))
401     {
402       g_strfreev (lines);
403       send_error (request, 400, "Bad websocket request");
404       return;
405     }
406
407   checksum = g_checksum_new (G_CHECKSUM_MD5);
408   g_checksum_update (checksum, challenge, 16);
409   len = 16;
410   g_checksum_get_digest (checksum, challenge, &len);
411   g_checksum_free (checksum);
412
413   res = g_strdup_printf ("HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
414                          "Upgrade: WebSocket\r\n"
415                          "Connection: Upgrade\r\n"
416                          "Sec-WebSocket-Origin: %s\r\n"
417                          "Sec-WebSocket-Location: ws://%s/input\r\n"
418                          "Sec-WebSocket-Protocol: broadway\r\n"
419                          "\r\n",
420                          origin, host);
421
422   g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
423                              res, strlen (res), NULL, NULL, NULL);
424   g_free (res);
425   g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
426                              challenge, 16, NULL, NULL, NULL);
427
428   input = g_new0 (BroadwayInput, 1);
429
430   input->display = request->display;
431   input->connection = g_object_ref (request->connection);
432
433   data_buffer = g_buffered_input_stream_peek_buffer (G_BUFFERED_INPUT_STREAM (request->data), &data_buffer_size);
434   input->buffer = g_byte_array_sized_new (data_buffer_size);
435   g_byte_array_append (input->buffer, data_buffer, data_buffer_size);
436
437   broadway_display->input = input;
438
439   /* This will free and close the data input stream, but we got all the buffered content already */
440   http_request_free (request);
441
442   in = g_io_stream_get_input_stream (G_IO_STREAM (input->connection));
443   input->source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (in), NULL);
444   g_source_set_callback (input->source, (GSourceFunc)input_data_cb, input, NULL);
445   g_source_attach (input->source, NULL);
446
447   /* Process any data in the pipe already */
448   parse_input (input);
449   process_input_messages (broadway_display);
450
451   g_strfreev (lines);
452 }
453
454 static void
455 start_output (HttpRequest *request)
456 {
457   GSocket *socket;
458   GdkBroadwayDisplay *broadway_display;
459   int fd;
460
461   socket = g_socket_connection_get_socket (request->connection);
462
463   broadway_display = GDK_BROADWAY_DISPLAY (request->display);
464   fd = g_socket_get_fd (socket);
465   set_fd_blocking (fd);
466   /* We dup this because otherwise it'll be closed with the request SocketConnection */
467
468   if (broadway_display->output)
469     {
470       broadway_display->saved_serial = broadway_output_get_next_serial (broadway_display->output);
471       broadway_output_free (broadway_display->output);
472     }
473
474   broadway_display->output = broadway_output_new (dup(fd), broadway_display->saved_serial);
475   _gdk_broadway_resync_windows ();
476   http_request_free (request);
477 }
478
479 static void
480 send_data (HttpRequest *request,
481              const char *mimetype,
482              const char *data, gsize len)
483 {
484   char *res;
485
486   res = g_strdup_printf ("HTTP/1.0 200 OK\r\n"
487                          "Content-Type: %s\r\n"
488                          "Content-Length: %"G_GSIZE_FORMAT"\r\n"
489                          "\r\n",
490                          mimetype, len);
491   /* TODO: This should really be async */
492   g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
493                              res, strlen (res), NULL, NULL, NULL);
494   g_free (res);
495   g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
496                              data, len, NULL, NULL, NULL);
497   http_request_free (request);
498 }
499
500 #include "clienthtml.h"
501 #include "broadwayjs.h"
502
503 static void
504 got_request (HttpRequest *request)
505 {
506   char *start, *escaped, *tmp, *version;
507
508   if (!g_str_has_prefix (request->request->str, "GET "))
509     {
510       send_error (request, 501, "Only GET implemented");
511       return;
512     }
513
514   start = request->request->str + 4; /* Skip "GET " */
515
516   while (*start == ' ')
517     start++;
518
519   for (tmp = start; *tmp != 0 && *tmp != ' ' && *tmp != '\n'; tmp++)
520     ;
521   escaped = g_strndup (start, tmp - start);
522   version = NULL;
523   if (*tmp == ' ')
524     {
525       start = tmp;
526       while (*start == ' ')
527         start++;
528       for (tmp = start; *tmp != 0 && *tmp != ' ' && *tmp != '\n'; tmp++)
529         ;
530       version = g_strndup (start, tmp - start);
531     }
532
533   if (strcmp (escaped, "/client.html") == 0 || strcmp (escaped, "/") == 0)
534     send_data (request, "text/html", client_html, G_N_ELEMENTS(client_html) - 1);
535   else if (strcmp (escaped, "/broadway.js") == 0)
536     send_data (request, "text/javascript", broadway_js, G_N_ELEMENTS(broadway_js) - 1);
537   else if (strcmp (escaped, "/output") == 0)
538     start_output (request);
539   else if (strcmp (escaped, "/input") == 0)
540     start_input (request);
541   else
542     send_error (request, 404, "File not found");
543 }
544
545 static void
546 got_http_request_line (GInputStream *stream,
547                        GAsyncResult *result,
548                        HttpRequest *request)
549 {
550   char *line;
551
552   line = g_data_input_stream_read_line_finish (G_DATA_INPUT_STREAM (stream), result, NULL, NULL);
553   if (line == NULL)
554     {
555       http_request_free (request);
556       g_printerr ("Error reading request lines\n");
557       return;
558     }
559   if (strlen (line) == 0)
560     got_request (request);
561   else
562     {
563       /* Protect against overflow in request length */
564       if (request->request->len > 1024 * 5)
565         {
566           send_error (request, 400, "Request to long");
567         }
568       else
569         {
570           g_string_append_printf (request->request, "%s\n", line);
571           g_data_input_stream_read_line_async (request->data, 0, NULL,
572                                                (GAsyncReadyCallback)got_http_request_line, request);
573         }
574     }
575   g_free (line);
576 }
577
578 static gboolean
579 handle_incoming_connection (GSocketService    *service,
580                             GSocketConnection *connection,
581                             GObject           *source_object)
582 {
583   HttpRequest *request;
584   GInputStream *in;
585
586   request = g_new0 (HttpRequest, 1);
587   request->connection = g_object_ref (connection);
588   request->display = (GdkDisplay *) source_object;
589   request->request = g_string_new ("");
590
591   in = g_io_stream_get_input_stream (G_IO_STREAM (connection));
592
593   request->data = g_data_input_stream_new (in);
594   g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (request->data), FALSE);
595   /* Be tolerant of input */
596   g_data_input_stream_set_newline_type (request->data, G_DATA_STREAM_NEWLINE_TYPE_ANY);
597
598   g_data_input_stream_read_line_async (request->data, 0, NULL,
599                                        (GAsyncReadyCallback)got_http_request_line, request);
600   return TRUE;
601 }
602
603 GdkDisplay *
604 _gdk_broadway_display_open (const gchar *display_name)
605 {
606   GdkDisplay *display;
607   GdkBroadwayDisplay *broadway_display;
608   GError *error;
609
610   display = g_object_new (GDK_TYPE_BROADWAY_DISPLAY, NULL);
611   broadway_display = GDK_BROADWAY_DISPLAY (display);
612
613   broadway_display->output = NULL;
614
615   /* initialize the display's screens */
616   broadway_display->screens = g_new (GdkScreen *, 1);
617   broadway_display->screens[0] = _gdk_broadway_screen_new (display, 0);
618
619   /* We need to initialize events after we have the screen
620    * structures in places
621    */
622   _gdk_broadway_screen_events_init (broadway_display->screens[0]);
623
624   /*set the default screen */
625   broadway_display->default_screen = broadway_display->screens[0];
626
627   display->device_manager = _gdk_broadway_device_manager_new (display);
628
629   gdk_event_init (display);
630
631   gdk_broadway_display_init_input (display);
632   _gdk_broadway_display_init_dnd (display);
633
634   _gdk_broadway_screen_setup (broadway_display->screens[0]);
635
636   broadway_display->service = g_socket_service_new ();
637   if (!g_socket_listener_add_inet_port (G_SOCKET_LISTENER (broadway_display->service),
638                                         8080,
639                                         G_OBJECT (display),
640                                         &error))
641     {
642       g_printerr ("Unable to listen to port %d: %s\n", 8080, error->message);
643       g_error_free (error);
644       return NULL;
645     }
646   g_signal_connect (broadway_display->service, "incoming", G_CALLBACK (handle_incoming_connection), NULL);
647
648   g_signal_emit_by_name (display, "opened");
649   g_signal_emit_by_name (gdk_display_manager_get (), "display-opened", display);
650
651   return display;
652 }
653
654
655 static G_CONST_RETURN gchar *
656 gdk_broadway_display_get_name (GdkDisplay *display)
657 {
658   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
659
660   return (gchar *) "Broadway";
661 }
662
663 static gint
664 gdk_broadway_display_get_n_screens (GdkDisplay *display)
665 {
666   g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
667
668   return 1;
669 }
670
671 static GdkScreen *
672 gdk_broadway_display_get_screen (GdkDisplay *display,
673                                  gint        screen_num)
674 {
675   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
676   g_return_val_if_fail (screen_num == 0, NULL);
677
678   return GDK_BROADWAY_DISPLAY (display)->screens[screen_num];
679 }
680
681 static GdkScreen *
682 gdk_broadway_display_get_default_screen (GdkDisplay *display)
683 {
684   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
685
686   return GDK_BROADWAY_DISPLAY (display)->default_screen;
687 }
688
689 static void
690 gdk_broadway_display_beep (GdkDisplay *display)
691 {
692   g_return_if_fail (GDK_IS_DISPLAY (display));
693 }
694
695 static void
696 gdk_broadway_display_sync (GdkDisplay *display)
697 {
698   g_return_if_fail (GDK_IS_DISPLAY (display));
699
700 }
701
702 static void
703 gdk_broadway_display_flush (GdkDisplay *display)
704 {
705   GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (display);
706
707   g_return_if_fail (GDK_IS_DISPLAY (display));
708
709   if (broadway_display->output &&
710       !broadway_output_flush (broadway_display->output))
711     {
712       broadway_display->saved_serial = broadway_output_get_next_serial (broadway_display->output);
713       broadway_output_free (broadway_display->output);
714       broadway_display->output = NULL;
715     }
716 }
717
718 static gboolean
719 gdk_broadway_display_has_pending (GdkDisplay *display)
720 {
721   return FALSE;
722 }
723
724 static GdkWindow *
725 gdk_broadway_display_get_default_group (GdkDisplay *display)
726 {
727   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
728
729   return NULL;
730 }
731
732 static void
733 gdk_broadway_display_dispose (GObject *object)
734 {
735   GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (object);
736
737   _gdk_broadway_display_manager_remove_display (gdk_display_manager_get (),
738                                                 GDK_DISPLAY_OBJECT (object));
739
740   g_list_foreach (broadway_display->input_devices, (GFunc) g_object_run_dispose, NULL);
741
742   _gdk_screen_close (broadway_display->screens[0]);
743
744   if (broadway_display->event_source)
745     {
746       g_source_destroy (broadway_display->event_source);
747       g_source_unref (broadway_display->event_source);
748       broadway_display->event_source = NULL;
749     }
750
751   G_OBJECT_CLASS (gdk_broadway_display_parent_class)->dispose (object);
752 }
753
754 static void
755 gdk_broadway_display_finalize (GObject *object)
756 {
757   GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (object);
758
759   /* Keymap */
760   if (broadway_display->keymap)
761     g_object_unref (broadway_display->keymap);
762
763   _gdk_broadway_cursor_display_finalize (GDK_DISPLAY_OBJECT(broadway_display));
764
765   /* Atom Hashtable */
766   g_hash_table_destroy (broadway_display->atom_from_virtual);
767   g_hash_table_destroy (broadway_display->atom_to_virtual);
768
769   /* input GdkDevice list */
770   g_list_foreach (broadway_display->input_devices, (GFunc) g_object_unref, NULL);
771   g_list_free (broadway_display->input_devices);
772   /* Free all GdkScreens */
773   g_object_unref (broadway_display->screens[0]);
774   g_free (broadway_display->screens);
775
776   G_OBJECT_CLASS (gdk_broadway_display_parent_class)->finalize (object);
777 }
778
779 void
780 _gdk_broadway_display_make_default (GdkDisplay *display)
781 {
782 }
783
784 static void
785 gdk_broadway_display_notify_startup_complete (GdkDisplay  *display,
786                                               const gchar *startup_id)
787 {
788 }
789
790 static gboolean
791 gdk_broadway_display_supports_selection_notification (GdkDisplay *display)
792 {
793   return FALSE;
794 }
795
796 static gboolean
797 gdk_broadway_display_request_selection_notification (GdkDisplay *display,
798                                                      GdkAtom     selection)
799
800 {
801     return FALSE;
802 }
803
804 static gboolean
805 gdk_broadway_display_supports_clipboard_persistence (GdkDisplay *display)
806 {
807   return FALSE;
808 }
809
810 static void
811 gdk_broadway_display_store_clipboard (GdkDisplay    *display,
812                                       GdkWindow     *clipboard_window,
813                                       guint32        time_,
814                                       const GdkAtom *targets,
815                                       gint           n_targets)
816 {
817 }
818
819 static gboolean
820 gdk_broadway_display_supports_shapes (GdkDisplay *display)
821 {
822   return FALSE;
823 }
824
825 static gboolean
826 gdk_broadway_display_supports_input_shapes (GdkDisplay *display)
827 {
828   return FALSE;
829 }
830
831 static gboolean
832 gdk_broadway_display_supports_composite (GdkDisplay *display)
833 {
834   return FALSE;
835 }
836
837 static GList *
838 gdk_broadway_display_list_devices (GdkDisplay *display)
839 {
840   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
841
842   return GDK_BROADWAY_DISPLAY (display)->input_devices;
843 }
844
845 static gulong
846 gdk_broadway_display_get_next_serial (GdkDisplay *display)
847 {
848   GdkBroadwayDisplay *broadway_display;
849   broadway_display = GDK_BROADWAY_DISPLAY (display);
850   if (broadway_display->output)
851     return broadway_output_get_next_serial (broadway_display->output);
852   return broadway_display->saved_serial;
853 }
854
855
856 static void
857 gdk_broadway_display_event_data_copy (GdkDisplay    *display,
858                                       const GdkEvent *src,
859                                       GdkEvent       *dst)
860 {
861 }
862
863 static void
864 gdk_broadway_display_event_data_free (GdkDisplay    *display,
865                                       GdkEvent *event)
866 {
867 }
868
869 static void
870 gdk_broadway_display_class_init (GdkBroadwayDisplayClass * class)
871 {
872   GObjectClass *object_class = G_OBJECT_CLASS (class);
873   GdkDisplayClass *display_class = GDK_DISPLAY_CLASS (class);
874
875   object_class->dispose = gdk_broadway_display_dispose;
876   object_class->finalize = gdk_broadway_display_finalize;
877
878   display_class->window_type = GDK_TYPE_BROADWAY_WINDOW;
879
880   display_class->get_name = gdk_broadway_display_get_name;
881   display_class->get_n_screens = gdk_broadway_display_get_n_screens;
882   display_class->get_screen = gdk_broadway_display_get_screen;
883   display_class->get_default_screen = gdk_broadway_display_get_default_screen;
884   display_class->beep = gdk_broadway_display_beep;
885   display_class->sync = gdk_broadway_display_sync;
886   display_class->flush = gdk_broadway_display_flush;
887   display_class->has_pending = gdk_broadway_display_has_pending;
888   display_class->queue_events = _gdk_broadway_display_queue_events;
889   display_class->get_default_group = gdk_broadway_display_get_default_group;
890   display_class->supports_selection_notification = gdk_broadway_display_supports_selection_notification;
891   display_class->request_selection_notification = gdk_broadway_display_request_selection_notification;
892   display_class->supports_clipboard_persistence = gdk_broadway_display_supports_clipboard_persistence;
893   display_class->store_clipboard = gdk_broadway_display_store_clipboard;
894   display_class->supports_shapes = gdk_broadway_display_supports_shapes;
895   display_class->supports_input_shapes = gdk_broadway_display_supports_input_shapes;
896   display_class->supports_composite = gdk_broadway_display_supports_composite;
897   display_class->list_devices = gdk_broadway_display_list_devices;
898   display_class->get_cursor_for_type = _gdk_broadway_display_get_cursor_for_type;
899   display_class->get_cursor_for_name = _gdk_broadway_display_get_cursor_for_name;
900   display_class->get_cursor_for_pixbuf = _gdk_broadway_display_get_cursor_for_pixbuf;
901   display_class->get_default_cursor_size = _gdk_broadway_display_get_default_cursor_size;
902   display_class->get_maximal_cursor_size = _gdk_broadway_display_get_maximal_cursor_size;
903   display_class->supports_cursor_alpha = _gdk_broadway_display_supports_cursor_alpha;
904   display_class->supports_cursor_color = _gdk_broadway_display_supports_cursor_color;
905
906   display_class->before_process_all_updates = _gdk_broadway_display_before_process_all_updates;
907   display_class->after_process_all_updates = _gdk_broadway_display_after_process_all_updates;
908   display_class->get_next_serial = gdk_broadway_display_get_next_serial;
909   display_class->notify_startup_complete = gdk_broadway_display_notify_startup_complete;
910   display_class->event_data_copy = gdk_broadway_display_event_data_copy;
911   display_class->event_data_free = gdk_broadway_display_event_data_free;
912   display_class->create_window_impl = _gdk_broadway_display_create_window_impl;
913   display_class->get_keymap = _gdk_broadway_display_get_keymap;
914   display_class->get_selection_owner = _gdk_broadway_display_get_selection_owner;
915   display_class->set_selection_owner = _gdk_broadway_display_set_selection_owner;
916   display_class->send_selection_notify = _gdk_broadway_display_send_selection_notify;
917   display_class->get_selection_property = _gdk_broadway_display_get_selection_property;
918   display_class->convert_selection = _gdk_broadway_display_convert_selection;
919   display_class->text_property_to_utf8_list = _gdk_broadway_display_text_property_to_utf8_list;
920   display_class->utf8_to_string_target = _gdk_broadway_display_utf8_to_string_target;
921 }
922