/* GDK - The GIMP Drawing Kit
- * gdkdisplay-x11.c
+ * gdkdisplay-broadway.c
*
* Copyright 2001 Sun Microsystems Inc.
* Copyright (C) 2004 Nokia Corporation
#include "gdkdisplay-broadway.h"
-#include "gdkx.h"
-#include "gdkasync.h"
#include "gdkdisplay.h"
#include "gdkeventsource.h"
-#include "gdkeventtranslator.h"
#include "gdkscreen.h"
#include "gdkscreen-broadway.h"
#include "gdkinternals.h"
#include "gdkdeviceprivate.h"
-#include "gdkdevicemanager.h"
-#include "xsettings-client.h"
+#include "gdkdevicemanager-broadway.h"
#include <glib.h>
#include <glib/gprintf.h>
#include <errno.h>
#include <unistd.h>
-#include <X11/Xatom.h>
+static void gdk_broadway_display_dispose (GObject *object);
+static void gdk_broadway_display_finalize (GObject *object);
-#ifdef HAVE_XKB
-#include <X11/XKBlib.h>
-#endif
+G_DEFINE_TYPE (GdkBroadwayDisplay, gdk_broadway_display, GDK_TYPE_DISPLAY)
-#ifdef HAVE_XFIXES
-#include <X11/extensions/Xfixes.h>
-#endif
-
-#include <X11/extensions/shape.h>
-
-#ifdef HAVE_XCOMPOSITE
-#include <X11/extensions/Xcomposite.h>
-#endif
-
-#ifdef HAVE_XDAMAGE
-#include <X11/extensions/Xdamage.h>
-#endif
+static void
+gdk_broadway_display_init (GdkBroadwayDisplay *display)
+{
+ _gdk_broadway_display_manager_add_display (gdk_display_manager_get (),
+ GDK_DISPLAY_OBJECT (display));
+ display->id_ht = g_hash_table_new (NULL, NULL);
+}
-#ifdef HAVE_RANDR
-#include <X11/extensions/Xrandr.h>
-#endif
+static void
+gdk_event_init (GdkDisplay *display)
+{
+ GdkBroadwayDisplay *broadway_display;
-typedef struct _GdkErrorTrap GdkErrorTrap;
+ broadway_display = GDK_BROADWAY_DISPLAY (display);
+ broadway_display->event_source = _gdk_broadway_event_source_new (display);
+}
-struct _GdkErrorTrap
+static void
+gdk_broadway_display_init_input (GdkDisplay *display)
{
- /* Next sequence when trap was pushed, i.e. first sequence to
- * ignore
- */
- gulong start_sequence;
+ GdkBroadwayDisplay *broadway_display;
+ GdkDeviceManager *device_manager;
+ GdkDevice *device;
+ GList *list, *l;
- /* Next sequence when trap was popped, i.e. first sequence
- * to not ignore. 0 if trap is still active.
- */
- gulong end_sequence;
+ broadway_display = GDK_BROADWAY_DISPLAY (display);
+ device_manager = gdk_display_get_device_manager (display);
- /* Most recent error code within the sequence */
- int error_code;
-};
+ /* For backwards compatibility, just add
+ * floating devices that are not keyboards.
+ */
+ list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
-static void gdk_display_x11_dispose (GObject *object);
-static void gdk_display_x11_finalize (GObject *object);
+ for (l = list; l; l = l->next)
+ {
+ device = l->data;
-static void gdk_display_x11_event_translator_init (GdkEventTranslatorIface *iface);
+ if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
+ continue;
-static gboolean gdk_display_x11_translate_event (GdkEventTranslator *translator,
- GdkDisplay *display,
- GdkEvent *event,
- XEvent *xevent);
+ broadway_display->input_devices = g_list_prepend (broadway_display->input_devices,
+ g_object_ref (l->data));
+ }
-#ifdef HAVE_X11R6
-static void gdk_internal_connection_watch (Display *display,
- XPointer arg,
- gint fd,
- gboolean opening,
- XPointer *watch_data);
-#endif /* HAVE_X11R6 */
+ g_list_free (list);
-typedef struct _GdkEventTypeX11 GdkEventTypeX11;
+ /* Now set "core" pointer to the first
+ * master device that is a pointer.
+ */
+ list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
-struct _GdkEventTypeX11
-{
- gint base;
- gint n_events;
-};
+ for (l = list; l; l = l->next)
+ {
+ device = list->data;
-/* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
- * but including them here has the side-effect of getting them
- * into the internal Xlib cache
- */
-static const char *const precache_atoms[] = {
- "UTF8_STRING",
- "WM_CLIENT_LEADER",
- "WM_DELETE_WINDOW",
- "WM_ICON_NAME",
- "WM_LOCALE_NAME",
- "WM_NAME",
- "WM_PROTOCOLS",
- "WM_TAKE_FOCUS",
- "WM_WINDOW_ROLE",
- "_NET_ACTIVE_WINDOW",
- "_NET_CURRENT_DESKTOP",
- "_NET_FRAME_EXTENTS",
- "_NET_STARTUP_ID",
- "_NET_WM_CM_S0",
- "_NET_WM_DESKTOP",
- "_NET_WM_ICON",
- "_NET_WM_ICON_NAME",
- "_NET_WM_NAME",
- "_NET_WM_PID",
- "_NET_WM_PING",
- "_NET_WM_STATE",
- "_NET_WM_STATE_ABOVE",
- "_NET_WM_STATE_BELOW",
- "_NET_WM_STATE_FULLSCREEN",
- "_NET_WM_STATE_MODAL",
- "_NET_WM_STATE_MAXIMIZED_VERT",
- "_NET_WM_STATE_MAXIMIZED_HORZ",
- "_NET_WM_STATE_SKIP_TASKBAR",
- "_NET_WM_STATE_SKIP_PAGER",
- "_NET_WM_STATE_STICKY",
- "_NET_WM_SYNC_REQUEST",
- "_NET_WM_SYNC_REQUEST_COUNTER",
- "_NET_WM_WINDOW_TYPE",
- "_NET_WM_WINDOW_TYPE_NORMAL",
- "_NET_WM_USER_TIME",
- "_NET_VIRTUAL_ROOTS"
-};
+ if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
+ continue;
-G_DEFINE_TYPE_WITH_CODE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY,
- G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
- gdk_display_x11_event_translator_init))
+ display->core_pointer = device;
+ break;
+ }
+ /* Add the core pointer to the devices list */
+ broadway_display->input_devices = g_list_prepend (broadway_display->input_devices,
+ g_object_ref (display->core_pointer));
-static void
-_gdk_display_x11_class_init (GdkDisplayX11Class * class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- object_class->dispose = gdk_display_x11_dispose;
- object_class->finalize = gdk_display_x11_finalize;
+ g_list_free (list);
}
-static void
-_gdk_display_x11_init (GdkDisplayX11 *display)
-{
-}
+struct HttpRequest {
+ GdkDisplay *display;
+ GSocketConnection *connection;
+ GDataInputStream *data;
+ GString *request;
+};
static void
-gdk_display_x11_event_translator_init (GdkEventTranslatorIface *iface)
+http_request_free (HttpRequest *request)
{
- iface->translate_event = gdk_display_x11_translate_event;
+ g_object_unref (request->connection);
+ g_object_unref (request->data);
+ g_string_free (request->request, TRUE);
+ g_free (request);
}
+#include <unistd.h>
+#include <fcntl.h>
static void
-do_net_wm_state_changes (GdkWindow *window)
+set_fd_blocking (int fd)
{
- GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
- GdkWindowState old_state;
+ glong arg;
- if (GDK_WINDOW_DESTROYED (window) ||
- gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
- return;
+ if ((arg = fcntl (fd, F_GETFL, NULL)) < 0)
+ arg = 0;
- old_state = gdk_window_get_state (window);
+ arg = arg & ~O_NONBLOCK;
- /* For found_sticky to remain TRUE, we have to also be on desktop
- * 0xFFFFFFFF
- */
- if (old_state & GDK_WINDOW_STATE_STICKY)
- {
- if (!(toplevel->have_sticky && toplevel->on_all_desktops))
- gdk_synthesize_window_state (window,
- GDK_WINDOW_STATE_STICKY,
- 0);
- }
- else
- {
- if (toplevel->have_sticky || toplevel->on_all_desktops)
- gdk_synthesize_window_state (window,
- 0,
- GDK_WINDOW_STATE_STICKY);
- }
+ fcntl (fd, F_SETFL, arg);
+}
- if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
- {
- if (!toplevel->have_fullscreen)
- gdk_synthesize_window_state (window,
- GDK_WINDOW_STATE_FULLSCREEN,
- 0);
- }
- else
- {
- if (toplevel->have_fullscreen)
- gdk_synthesize_window_state (window,
- 0,
- GDK_WINDOW_STATE_FULLSCREEN);
- }
+static char *
+parse_line (char *line, char *key)
+{
+ char *p;
- /* Our "maximized" means both vertical and horizontal; if only one,
- * we don't expose that via GDK
- */
- if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
- {
- if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
- gdk_synthesize_window_state (window,
- GDK_WINDOW_STATE_MAXIMIZED,
- 0);
- }
- else
- {
- if (toplevel->have_maxvert && toplevel->have_maxhorz)
- gdk_synthesize_window_state (window,
- 0,
- GDK_WINDOW_STATE_MAXIMIZED);
- }
+ if (!g_str_has_prefix (line, key))
+ return NULL;
+ p = line + strlen (key);
+ if (*p != ':')
+ return NULL;
+ p++;
+ /* Skip optional initial space */
+ if (*p == ' ')
+ p++;
+ return p;
}
static void
-gdk_check_wm_desktop_changed (GdkWindow *window)
+got_input (GInputStream *stream,
+ GAsyncResult *result,
+ HttpRequest *request)
{
- GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
- GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
-
- Atom type;
- gint format;
- gulong nitems;
- gulong bytes_after;
- guchar *data;
- gulong *desktop;
-
- type = None;
- gdk_error_trap_push ();
- XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
- GDK_WINDOW_XID (window),
- gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
- 0, G_MAXLONG, False, XA_CARDINAL, &type,
- &format, &nitems,
- &bytes_after, &data);
- gdk_error_trap_pop_ignored ();
-
- if (type != None)
+ GError *error;
+ char *message;
+ gsize len;
+
+ error = NULL;
+ message = g_data_input_stream_read_upto_finish (G_DATA_INPUT_STREAM (stream), result, &len, &error);
+ if (message == NULL)
{
- desktop = (gulong *)data;
- toplevel->on_all_desktops = (*desktop == 0xFFFFFFFF);
- XFree (desktop);
+ GDK_BROADWAY_DISPLAY (request->display)->input = NULL;
+ http_request_free (request);
+ return;
}
- else
- toplevel->on_all_desktops = FALSE;
- do_net_wm_state_changes (window);
+ g_assert (message[0] == 0);
+ _gdk_broadway_events_got_input (request->display, message + 1);
+
+ /* Skip past ending 0xff */
+ g_data_input_stream_read_byte (request->data, NULL, NULL);
+ g_data_input_stream_read_upto_async (request->data, "\xff", 1, 0, NULL,
+ (GAsyncReadyCallback)got_input, request);
}
static void
-gdk_check_wm_state_changed (GdkWindow *window)
+send_error (HttpRequest *request,
+ int error_code,
+ const char *reason)
{
- GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
- GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
-
- Atom type;
- gint format;
- gulong nitems;
- gulong bytes_after;
- guchar *data;
- Atom *atoms = NULL;
- gulong i;
-
- gboolean had_sticky = toplevel->have_sticky;
-
- toplevel->have_sticky = FALSE;
- toplevel->have_maxvert = FALSE;
- toplevel->have_maxhorz = FALSE;
- toplevel->have_fullscreen = FALSE;
-
- type = None;
- gdk_error_trap_push ();
- XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
- gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
- 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
- &bytes_after, &data);
- gdk_error_trap_pop_ignored ();
-
- if (type != None)
- {
- Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
- Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
- Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
- Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
-
- atoms = (Atom *)data;
-
- i = 0;
- while (i < nitems)
- {
- if (atoms[i] == sticky_atom)
- toplevel->have_sticky = TRUE;
- else if (atoms[i] == maxvert_atom)
- toplevel->have_maxvert = TRUE;
- else if (atoms[i] == maxhorz_atom)
- toplevel->have_maxhorz = TRUE;
- else if (atoms[i] == fullscreen_atom)
- toplevel->have_fullscreen = TRUE;
-
- ++i;
- }
-
- XFree (atoms);
- }
+ char *res;
- /* When have_sticky is turned on, we have to check the DESKTOP property
- * as well.
- */
- if (toplevel->have_sticky && !had_sticky)
- gdk_check_wm_desktop_changed (window);
- else
- do_net_wm_state_changes (window);
+ res = g_strdup_printf ("HTTP/1.0 %d %s\r\n\r\n"
+ "<html><head><title>%d %s</title></head>"
+ "<body>%s</body></html>",
+ error_code, reason,
+ error_code, reason,
+ reason);
+ /* TODO: This should really be async */
+ g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
+ res, strlen (res), NULL, NULL, NULL);
+ g_free (res);
+ http_request_free (request);
}
-static GdkWindow *
-get_event_window (GdkEventTranslator *translator,
- XEvent *xevent)
+static void
+start_input (HttpRequest *request)
{
- GdkDisplay *display;
- Window xwindow;
+ char **lines;
+ char *p;
+ int num_key1, num_key2;
+ guint64 key1, key2;
+ int num_space;
+ int i;
+ guint8 challenge[16];
+ char *res;
+ gsize len;
+ GChecksum *checksum;
+ char *origin, *host;
+ GdkBroadwayDisplay *broadway_display;
- display = (GdkDisplay *) translator;
+ broadway_display = GDK_BROADWAY_DISPLAY (request->display);
- switch (xevent->type)
+ if (broadway_display->input != NULL)
{
- case DestroyNotify:
- xwindow = xevent->xdestroywindow.window;
- break;
- case UnmapNotify:
- xwindow = xevent->xunmap.window;
- break;
- case MapNotify:
- xwindow = xevent->xmap.window;
- break;
- case ConfigureNotify:
- xwindow = xevent->xconfigure.window;
- break;
- default:
- xwindow = xevent->xany.window;
+ send_error (request, 409, "Input already handled");
+ return;
}
- return gdk_window_lookup_for_display (display, xwindow);
-}
-
-static gboolean
-gdk_display_x11_translate_event (GdkEventTranslator *translator,
- GdkDisplay *display,
- GdkEvent *event,
- XEvent *xevent)
-{
- GdkWindow *window;
- GdkWindowObject *window_private;
- GdkWindowImplX11 *window_impl = NULL;
- GdkScreen *screen = NULL;
- GdkScreenX11 *screen_x11 = NULL;
- GdkToplevelX11 *toplevel = NULL;
- GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
- gboolean return_val;
- Window xwindow = None;
-
- /* Find the GdkWindow that this event relates to.
- * Basically this means substructure events
- * are reported same as structure events
- */
- window = get_event_window (translator, xevent);
- window_private = (GdkWindowObject *) window;
+ lines = g_strsplit (request->request->str, "\n", 0);
- if (window)
+ num_key1 = 0;
+ num_key2 = 0;
+ key1 = 0;
+ key2 = 0;
+ origin = NULL;
+ host = NULL;
+ for (i = 0; lines[i] != NULL; i++)
{
- /* We may receive events such as NoExpose/GraphicsExpose
- * and ShmCompletion for pixmaps
- */
- if (!GDK_IS_WINDOW (window))
- return FALSE;
-
- screen = GDK_WINDOW_SCREEN (window);
- screen_x11 = GDK_SCREEN_X11 (screen);
- toplevel = _gdk_x11_window_get_toplevel (window);
- window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
- xwindow = GDK_WINDOW_XID (window);
-
- g_object_ref (window);
- }
+ if ((p = parse_line (lines[i], "Sec-WebSocket-Key1")))
+ {
+ num_space = 0;
+ while (*p != 0)
+ {
+ if (g_ascii_isdigit (*p))
+ key1 = key1 * 10 + g_ascii_digit_value (*p);
+ else if (*p == ' ')
+ num_space++;
- event->any.window = window;
- event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
+ p++;
+ }
+ key1 /= num_space;
+ num_key1++;
+ }
+ else if ((p = parse_line (lines[i], "Sec-WebSocket-Key2")))
+ {
+ num_space = 0;
+ while (*p != 0)
+ {
+ if (g_ascii_isdigit (*p))
+ key2 = key2 * 10 + g_ascii_digit_value (*p);
+ else if (*p == ' ')
+ num_space++;
- if (window_private && GDK_WINDOW_DESTROYED (window))
- {
- if (xevent->type != DestroyNotify)
+ p++;
+ }
+ key2 /= num_space;
+ num_key2++;
+ }
+ else if ((p = parse_line (lines[i], "Origin")))
+ {
+ origin = p;
+ }
+ else if ((p = parse_line (lines[i], "Host")))
{
- return_val = FALSE;
- goto done;
+ host = p;
}
}
- if (xevent->type == DestroyNotify)
+ if (num_key1 != 1 || num_key2 != 1 || origin == NULL || host == NULL)
{
- int i, n;
-
- n = gdk_display_get_n_screens (display);
- for (i = 0; i < n; i++)
- {
- screen = gdk_display_get_screen (display, i);
- screen_x11 = GDK_SCREEN_X11 (screen);
-
- if (screen_x11->wmspec_check_window == xwindow)
- {
- screen_x11->wmspec_check_window = None;
- screen_x11->last_wmspec_check_time = 0;
- g_free (screen_x11->window_manager_name);
- screen_x11->window_manager_name = g_strdup ("unknown");
-
- /* careful, reentrancy */
- _gdk_x11_screen_window_manager_changed (screen);
-
- return_val = FALSE;
- goto done;
- }
- }
+ g_strfreev (lines);
+ send_error (request, 400, "Bad websocket request");
+ return;
}
- /* We do a "manual" conversion of the XEvent to a
- * GdkEvent. The structures are mostly the same so
- * the conversion is fairly straightforward. We also
- * optionally print debugging info regarding events
- * received.
- */
-
- return_val = TRUE;
+ challenge[0] = (key1 >> 24) & 0xff;
+ challenge[1] = (key1 >> 16) & 0xff;
+ challenge[2] = (key1 >> 8) & 0xff;
+ challenge[3] = (key1 >> 0) & 0xff;
+ challenge[4] = (key2 >> 24) & 0xff;
+ challenge[5] = (key2 >> 16) & 0xff;
+ challenge[6] = (key2 >> 8) & 0xff;
+ challenge[7] = (key2 >> 0) & 0xff;
- switch (xevent->type)
+ if (!g_input_stream_read_all (G_INPUT_STREAM (request->data), challenge+8, 8, NULL, NULL, NULL))
{
- case KeymapNotify:
- GDK_NOTE (EVENTS,
- g_message ("keymap notify"));
-
- /* Not currently handled */
- return_val = FALSE;
- break;
-
- case Expose:
- GDK_NOTE (EVENTS,
- g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
- xevent->xexpose.window, xevent->xexpose.count,
- xevent->xexpose.x, xevent->xexpose.y,
- xevent->xexpose.width, xevent->xexpose.height,
- event->any.send_event ? " (send)" : ""));
+ g_strfreev (lines);
+ send_error (request, 400, "Bad websocket request");
+ return;
+ }
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
+ checksum = g_checksum_new (G_CHECKSUM_MD5);
+ g_checksum_update (checksum, challenge, 16);
+ len = 16;
+ g_checksum_get_digest (checksum, challenge, &len);
+ g_checksum_free (checksum);
- {
- GdkRectangle expose_rect;
+ res = g_strdup_printf ("HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
+ "Upgrade: WebSocket\r\n"
+ "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Origin: %s\r\n"
+ "Sec-WebSocket-Location: ws://%s/input\r\n"
+ "Sec-WebSocket-Protocol: broadway\r\n"
+ "\r\n",
+ origin, host);
- expose_rect.x = xevent->xexpose.x;
- expose_rect.y = xevent->xexpose.y;
- expose_rect.width = xevent->xexpose.width;
- expose_rect.height = xevent->xexpose.height;
+ /* TODO: This should really be async */
+ g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
+ res, strlen (res), NULL, NULL, NULL);
+ g_free (res);
+ g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
+ challenge, 16, NULL, NULL, NULL);
- _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
- return_val = FALSE;
- }
+ broadway_display->input = request;
- break;
+ g_data_input_stream_read_upto_async (request->data, "\xff", 1, 0, NULL,
+ (GAsyncReadyCallback)got_input, request);
- case GraphicsExpose:
- {
- GdkRectangle expose_rect;
+ g_strfreev (lines);
+}
- GDK_NOTE (EVENTS,
- g_message ("graphics expose:\tdrawable: %ld",
- xevent->xgraphicsexpose.drawable));
+static void
+start_output (HttpRequest *request)
+{
+ GSocket *socket;
+ GdkBroadwayDisplay *broadway_display;
+ int fd;
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
+ socket = g_socket_connection_get_socket (request->connection);
- expose_rect.x = xevent->xgraphicsexpose.x;
- expose_rect.y = xevent->xgraphicsexpose.y;
- expose_rect.width = xevent->xgraphicsexpose.width;
- expose_rect.height = xevent->xgraphicsexpose.height;
+ broadway_display = GDK_BROADWAY_DISPLAY (request->display);
+ fd = g_socket_get_fd (socket);
+ set_fd_blocking (fd);
+ /* We dup this because otherwise it'll be closed with the request SocketConnection */
+ broadway_display->output = broadway_output_new (dup(fd));
+ _gdk_broadway_resync_windows ();
+ http_request_free (request);
+}
- _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
- return_val = FALSE;
- }
- break;
+static void
+send_data (HttpRequest *request,
+ const char *mimetype,
+ const char *data, gsize len)
+{
+ char *res;
- case NoExpose:
- GDK_NOTE (EVENTS,
- g_message ("no expose:\t\tdrawable: %ld",
- xevent->xnoexpose.drawable));
+ res = g_strdup_printf ("HTTP/1.0 200 OK\r\n"
+ "Content-Type: %s\r\n"
+ "Content-Length: %"G_GSIZE_FORMAT"\r\n"
+ "\r\n",
+ mimetype, len);
+ /* TODO: This should really be async */
+ g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
+ res, strlen (res), NULL, NULL, NULL);
+ g_free (res);
+ g_output_stream_write_all (g_io_stream_get_output_stream (G_IO_STREAM (request->connection)),
+ data, len, NULL, NULL, NULL);
+ http_request_free (request);
+}
- event->no_expose.type = GDK_NO_EXPOSE;
- event->no_expose.window = window;
+#include "clienthtml.h"
+#include "broadwayjs.h"
- break;
+static void
+got_request (HttpRequest *request)
+{
+ char *start, *escaped, *tmp, *version;
- case VisibilityNotify:
-#ifdef G_ENABLE_DEBUG
- if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
- switch (xevent->xvisibility.state)
- {
- case VisibilityFullyObscured:
- g_message ("visibility notify:\twindow: %ld none",
- xevent->xvisibility.window);
- break;
- case VisibilityPartiallyObscured:
- g_message ("visibility notify:\twindow: %ld partial",
- xevent->xvisibility.window);
- break;
- case VisibilityUnobscured:
- g_message ("visibility notify:\twindow: %ld full",
- xevent->xvisibility.window);
- break;
- }
-#endif /* G_ENABLE_DEBUG */
-
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
-
- event->visibility.type = GDK_VISIBILITY_NOTIFY;
- event->visibility.window = window;
-
- switch (xevent->xvisibility.state)
- {
- case VisibilityFullyObscured:
- event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
- break;
+ if (!g_str_has_prefix (request->request->str, "GET "))
+ {
+ send_error (request, 501, "Only GET implemented");
+ return;
+ }
- case VisibilityPartiallyObscured:
- event->visibility.state = GDK_VISIBILITY_PARTIAL;
- break;
+ start = request->request->str + 4; /* Skip "GET " */
- case VisibilityUnobscured:
- event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
- break;
- }
+ while (*start == ' ')
+ start++;
- break;
+ for (tmp = start; *tmp != 0 && *tmp != ' ' && *tmp != '\n'; tmp++)
+ ;
+ escaped = g_strndup (start, tmp - start);
+ version = NULL;
+ if (*tmp == ' ')
+ {
+ start = tmp;
+ while (*start == ' ')
+ start++;
+ for (tmp = start; *tmp != 0 && *tmp != ' ' && *tmp != '\n'; tmp++)
+ ;
+ version = g_strndup (start, tmp - start);
+ }
- case CreateNotify:
- GDK_NOTE (EVENTS,
- g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
- xevent->xcreatewindow.window,
- xevent->xcreatewindow.x,
- xevent->xcreatewindow.y,
- xevent->xcreatewindow.width,
- xevent->xcreatewindow.height,
- xevent->xcreatewindow.border_width,
- xevent->xcreatewindow.parent,
- xevent->xcreatewindow.override_redirect));
- /* not really handled */
- break;
+ if (strcmp (escaped, "/client.html") == 0 || strcmp (escaped, "/") == 0)
+ send_data (request, "text/html", client_html, G_N_ELEMENTS(client_html) - 1);
+ else if (strcmp (escaped, "/broadway.js") == 0)
+ send_data (request, "text/javascript", broadway_js, G_N_ELEMENTS(broadway_js) - 1);
+ else if (strcmp (escaped, "/output") == 0)
+ start_output (request);
+ else if (strcmp (escaped, "/input") == 0)
+ start_input (request);
+ else
+ send_error (request, 404, "File not found");
+}
- case DestroyNotify:
- GDK_NOTE (EVENTS,
- g_message ("destroy notify:\twindow: %ld",
- xevent->xdestroywindow.window));
+static void
+got_http_request_line (GInputStream *stream,
+ GAsyncResult *result,
+ HttpRequest *request)
+{
+ char *line;
- /* Ignore DestroyNotify from SubstructureNotifyMask */
- if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
+ line = g_data_input_stream_read_line_finish (G_DATA_INPUT_STREAM (stream), result, NULL, NULL);
+ if (line == NULL)
+ {
+ http_request_free (request);
+ g_printerr ("Error reading request lines\n");
+ return;
+ }
+ if (strlen (line) == 0)
+ got_request (request);
+ else
+ {
+ /* Protect against overflow in request length */
+ if (request->request->len > 1024 * 5)
{
- event->any.type = GDK_DESTROY;
- event->any.window = window;
-
- return_val = window_private && !GDK_WINDOW_DESTROYED (window);
-
- if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
- gdk_window_destroy_notify (window);
+ send_error (request, 400, "Request to long");
}
else
- return_val = FALSE;
+ {
+ g_string_append_printf (request->request, "%s\n", line);
+ g_data_input_stream_read_line_async (request->data, 0, NULL,
+ (GAsyncReadyCallback)got_http_request_line, request);
+ }
+ }
+ g_free (line);
+}
- break;
+static gboolean
+handle_incoming_connection (GSocketService *service,
+ GSocketConnection *connection,
+ GObject *source_object)
+{
+ HttpRequest *request;
+ GInputStream *in;
- case UnmapNotify:
- GDK_NOTE (EVENTS,
- g_message ("unmap notify:\t\twindow: %ld",
- xevent->xmap.window));
+ request = g_new0 (HttpRequest, 1);
+ request->connection = g_object_ref (connection);
+ request->display = (GdkDisplay *) source_object;
+ request->request = g_string_new ("");
- event->any.type = GDK_UNMAP;
- event->any.window = window;
+ in = g_io_stream_get_input_stream (G_IO_STREAM (connection));
- /* If we are shown (not withdrawn) and get an unmap, it means we
- * were iconified in the X sense. If we are withdrawn, and get
- * an unmap, it means we hid the window ourselves, so we
- * will have already flipped the iconified bit off.
- */
- if (window)
- {
- if (GDK_WINDOW_IS_MAPPED (window))
- gdk_synthesize_window_state (window,
- 0,
- GDK_WINDOW_STATE_ICONIFIED);
+ request->data = g_data_input_stream_new (in);
+ g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (request->data), FALSE);
+ /* Be tolerant of input */
+ g_data_input_stream_set_newline_type (request->data, G_DATA_STREAM_NEWLINE_TYPE_ANY);
- _gdk_xgrab_check_unmap (window, xevent->xany.serial);
- }
+ g_data_input_stream_read_line_async (request->data, 0, NULL,
+ (GAsyncReadyCallback)got_http_request_line, request);
+ return TRUE;
+}
- break;
+GdkDisplay *
+_gdk_broadway_display_open (const gchar *display_name)
+{
+ GdkDisplay *display;
+ GdkBroadwayDisplay *broadway_display;
+ GError *error;
- case MapNotify:
- GDK_NOTE (EVENTS,
- g_message ("map notify:\t\twindow: %ld",
- xevent->xmap.window));
+ display = g_object_new (GDK_TYPE_BROADWAY_DISPLAY, NULL);
+ broadway_display = GDK_BROADWAY_DISPLAY (display);
- event->any.type = GDK_MAP;
- event->any.window = window;
+ broadway_display->output = NULL;
- /* Unset iconified if it was set */
- if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
- gdk_synthesize_window_state (window,
- GDK_WINDOW_STATE_ICONIFIED,
- 0);
+ /* initialize the display's screens */
+ broadway_display->screens = g_new (GdkScreen *, 1);
+ broadway_display->screens[0] = _gdk_broadway_screen_new (display, 0);
- break;
+ /* We need to initialize events after we have the screen
+ * structures in places
+ */
+ _gdk_broadway_screen_events_init (broadway_display->screens[0]);
- case ReparentNotify:
- GDK_NOTE (EVENTS,
- g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
- xevent->xreparent.window,
- xevent->xreparent.x,
- xevent->xreparent.y,
- xevent->xreparent.parent,
- xevent->xreparent.override_redirect));
-
- /* Not currently handled */
- return_val = FALSE;
- break;
+ /*set the default screen */
+ broadway_display->default_screen = broadway_display->screens[0];
- case ConfigureNotify:
- GDK_NOTE (EVENTS,
- g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
- xevent->xconfigure.window,
- xevent->xconfigure.x,
- xevent->xconfigure.y,
- xevent->xconfigure.width,
- xevent->xconfigure.height,
- xevent->xconfigure.border_width,
- xevent->xconfigure.above,
- xevent->xconfigure.override_redirect,
- !window
- ? " (discarding)"
- : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
- ? " (discarding child)"
- : xevent->xconfigure.event != xevent->xconfigure.window
- ? " (discarding substructure)"
- : ""));
- if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
- {
- window_private->width = xevent->xconfigure.width;
- window_private->height = xevent->xconfigure.height;
-
- _gdk_window_update_size (window);
- _gdk_x11_drawable_update_size (window_private->impl);
- _gdk_x11_screen_size_changed (screen, xevent);
- }
-
-#ifdef HAVE_XSYNC
- if (toplevel && display_x11->use_sync && !XSyncValueIsZero (toplevel->pending_counter_value))
- {
- toplevel->current_counter_value = toplevel->pending_counter_value;
- XSyncIntToValue (&toplevel->pending_counter_value, 0);
- }
-#endif
+ display->device_manager = _gdk_broadway_device_manager_new (display);
- if (!window ||
- xevent->xconfigure.event != xevent->xconfigure.window ||
- GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
- GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
- return_val = FALSE;
- else
- {
- event->configure.type = GDK_CONFIGURE;
- event->configure.window = window;
- event->configure.width = xevent->xconfigure.width;
- event->configure.height = xevent->xconfigure.height;
-
- if (!xevent->xconfigure.send_event &&
- !xevent->xconfigure.override_redirect &&
- !GDK_WINDOW_DESTROYED (window))
- {
- gint tx = 0;
- gint ty = 0;
- Window child_window = 0;
-
- gdk_error_trap_push ();
- if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
- GDK_DRAWABLE_XID (window),
- screen_x11->xroot_window,
- 0, 0,
- &tx, &ty,
- &child_window))
- {
- event->configure.x = tx;
- event->configure.y = ty;
- }
- gdk_error_trap_pop_ignored ();
- }
- else
- {
- event->configure.x = xevent->xconfigure.x;
- event->configure.y = xevent->xconfigure.y;
- }
- window_private->x = event->configure.x;
- window_private->y = event->configure.y;
- window_private->width = xevent->xconfigure.width;
- window_private->height = xevent->xconfigure.height;
+ gdk_event_init (display);
- _gdk_window_update_size (window);
- _gdk_x11_drawable_update_size (window_private->impl);
+ gdk_broadway_display_init_input (display);
+ _gdk_broadway_display_init_dnd (display);
- if (window_private->resize_count >= 1)
- {
- window_private->resize_count -= 1;
+ _gdk_broadway_screen_setup (broadway_display->screens[0]);
- if (window_private->resize_count == 0)
- _gdk_moveresize_configure_done (display, window);
- }
- }
- break;
+ broadway_display->service = g_socket_service_new ();
+ if (!g_socket_listener_add_inet_port (G_SOCKET_LISTENER (broadway_display->service),
+ 8080,
+ G_OBJECT (display),
+ &error))
+ {
+ g_printerr ("Unable to listen to port %d: %s\n", 8080, error->message);
+ g_error_free (error);
+ return NULL;
+ }
+ g_signal_connect (broadway_display->service, "incoming", G_CALLBACK (handle_incoming_connection), NULL);
- case PropertyNotify:
- GDK_NOTE (EVENTS,
- g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
- xevent->xproperty.window,
- xevent->xproperty.atom,
- "\"",
- gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
- "\""));
-
- if (window_private == NULL)
- {
- return_val = FALSE;
- break;
- }
-
- /* We compare with the serial of the last time we mapped the
- * window to avoid refetching properties that we set ourselves
- */
- if (toplevel &&
- xevent->xproperty.serial >= toplevel->map_serial)
- {
- if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
- gdk_check_wm_state_changed (window);
+ g_signal_emit_by_name (display, "opened");
+ g_signal_emit_by_name (gdk_display_manager_get (), "display-opened", display);
- if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
- gdk_check_wm_desktop_changed (window);
- }
+ return display;
+}
- if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
- {
- event->property.type = GDK_PROPERTY_NOTIFY;
- event->property.window = window;
- event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
- event->property.time = xevent->xproperty.time;
- event->property.state = xevent->xproperty.state;
- }
- else
- return_val = FALSE;
- break;
+static G_CONST_RETURN gchar *
+gdk_broadway_display_get_name (GdkDisplay *display)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- case SelectionClear:
- GDK_NOTE (EVENTS,
- g_message ("selection clear:\twindow: %ld",
- xevent->xproperty.window));
+ return (gchar *) "Broadway";
+}
- if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
- {
- event->selection.type = GDK_SELECTION_CLEAR;
- event->selection.window = window;
- event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
- event->selection.time = xevent->xselectionclear.time;
- }
- else
- return_val = FALSE;
+static gint
+gdk_broadway_display_get_n_screens (GdkDisplay *display)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
- break;
+ return 1;
+}
- case SelectionRequest:
- GDK_NOTE (EVENTS,
- g_message ("selection request:\twindow: %ld",
- xevent->xproperty.window));
+static GdkScreen *
+gdk_broadway_display_get_screen (GdkDisplay *display,
+ gint screen_num)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+ g_return_val_if_fail (screen_num == 0, NULL);
- event->selection.type = GDK_SELECTION_REQUEST;
- event->selection.window = window;
- event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
- event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
- event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
- event->selection.requestor = xevent->xselectionrequest.requestor;
- event->selection.time = xevent->xselectionrequest.time;
+ return GDK_BROADWAY_DISPLAY (display)->screens[screen_num];
+}
- break;
+static GdkScreen *
+gdk_broadway_display_get_default_screen (GdkDisplay *display)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- case SelectionNotify:
- GDK_NOTE (EVENTS,
- g_message ("selection notify:\twindow: %ld",
- xevent->xproperty.window));
-
- event->selection.type = GDK_SELECTION_NOTIFY;
- event->selection.window = window;
- event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
- event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
- if (xevent->xselection.property == None)
- event->selection.property = GDK_NONE;
- else
- event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
- event->selection.time = xevent->xselection.time;
+ return GDK_BROADWAY_DISPLAY (display)->default_screen;
+}
- break;
+static void
+gdk_broadway_display_beep (GdkDisplay *display)
+{
+ g_return_if_fail (GDK_IS_DISPLAY (display));
+}
- case ColormapNotify:
- GDK_NOTE (EVENTS,
- g_message ("colormap notify:\twindow: %ld",
- xevent->xcolormap.window));
+static void
+gdk_broadway_display_sync (GdkDisplay *display)
+{
+ g_return_if_fail (GDK_IS_DISPLAY (display));
- /* Not currently handled */
- return_val = FALSE;
- break;
+}
- case ClientMessage:
- {
- GList *tmp_list;
- GdkFilterReturn result = GDK_FILTER_CONTINUE;
- GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
-
- GDK_NOTE (EVENTS,
- g_message ("client message:\twindow: %ld",
- xevent->xclient.window));
-
- tmp_list = display_x11->client_filters;
- while (tmp_list)
- {
- GdkClientFilter *filter = tmp_list->data;
- tmp_list = tmp_list->next;
-
- if (filter->type == message_type)
- {
- result = (*filter->function) (xevent, event, filter->data);
- if (result != GDK_FILTER_CONTINUE)
- break;
- }
- }
-
- switch (result)
- {
- case GDK_FILTER_REMOVE:
- return_val = FALSE;
- break;
- case GDK_FILTER_TRANSLATE:
- return_val = TRUE;
- break;
- case GDK_FILTER_CONTINUE:
- /* Send unknown ClientMessage's on to Gtk for it to use */
- if (window_private == NULL)
- {
- return_val = FALSE;
- }
- else
- {
- event->client.type = GDK_CLIENT_EVENT;
- event->client.window = window;
- event->client.message_type = message_type;
- event->client.data_format = xevent->xclient.format;
- memcpy(&event->client.data, &xevent->xclient.data,
- sizeof(event->client.data));
- }
- break;
- }
- }
+static void
+gdk_broadway_display_flush (GdkDisplay *display)
+{
+ g_return_if_fail (GDK_IS_DISPLAY (display));
- break;
+}
- case MappingNotify:
- GDK_NOTE (EVENTS,
- g_message ("mapping notify"));
+static gboolean
+gdk_broadway_display_has_pending (GdkDisplay *display)
+{
+ return FALSE;
+}
- /* Let XLib know that there is a new keyboard mapping.
- */
- XRefreshKeyboardMapping (&xevent->xmapping);
- _gdk_keymap_keys_changed (display);
- return_val = FALSE;
- break;
+static GdkWindow *
+gdk_broadway_display_get_default_group (GdkDisplay *display)
+{
+ g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- default:
-#ifdef HAVE_XFIXES
- if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
- {
- XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
-
- _gdk_x11_screen_process_owner_change (screen, xevent);
-
- event->owner_change.type = GDK_OWNER_CHANGE;
- event->owner_change.window = window;
- event->owner_change.owner = selection_notify->owner;
- event->owner_change.reason = selection_notify->subtype;
- event->owner_change.selection =
- gdk_x11_xatom_to_atom_for_display (display,
- selection_notify->selection);
- event->owner_change.time = selection_notify->timestamp;
- event->owner_change.selection_time = selection_notify->selection_timestamp;
-
- return_val = TRUE;
- }
- else
-#endif
-#ifdef HAVE_RANDR
- if (xevent->type - display_x11->xrandr_event_base == RRScreenChangeNotify ||
- xevent->type - display_x11->xrandr_event_base == RRNotify)
- {
- if (screen)
- _gdk_x11_screen_size_changed (screen, xevent);
- }
- else
-#endif
-#if defined(HAVE_XCOMPOSITE) && defined (HAVE_XDAMAGE) && defined (HAVE_XFIXES)
- if (display_x11->have_xdamage && window_private && window_private->composited &&
- xevent->type == display_x11->xdamage_event_base + XDamageNotify &&
- ((XDamageNotifyEvent *) xevent)->damage == window_impl->damage)
- {
- XDamageNotifyEvent *damage_event = (XDamageNotifyEvent *) xevent;
- XserverRegion repair;
- GdkRectangle rect;
-
- rect.x = window_private->x + damage_event->area.x;
- rect.y = window_private->y + damage_event->area.y;
- rect.width = damage_event->area.width;
- rect.height = damage_event->area.height;
-
- repair = XFixesCreateRegion (display_x11->xdisplay,
- &damage_event->area, 1);
- XDamageSubtract (display_x11->xdisplay,
- window_impl->damage,
- repair, None);
- XFixesDestroyRegion (display_x11->xdisplay, repair);
-
- if (window_private->parent != NULL)
- _gdk_window_process_expose (GDK_WINDOW (window_private->parent),
- damage_event->serial, &rect);
-
- return_val = TRUE;
- }
- else
-#endif
-#ifdef HAVE_XKB
- if (xevent->type == display_x11->xkb_event_type)
- {
- XkbEvent *xkb_event = (XkbEvent *) xevent;
+ return NULL;
+}
- switch (xkb_event->any.xkb_type)
- {
- case XkbNewKeyboardNotify:
- case XkbMapNotify:
- _gdk_keymap_keys_changed (display);
+static void
+gdk_broadway_display_dispose (GObject *object)
+{
+ GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (object);
- return_val = FALSE;
- break;
+ _gdk_broadway_display_manager_remove_display (gdk_display_manager_get (),
+ GDK_DISPLAY_OBJECT (object));
- case XkbStateNotify:
- _gdk_keymap_state_changed (display, xevent);
- break;
- }
- }
- else
-#endif
- return_val = FALSE;
- }
+ g_list_foreach (broadway_display->input_devices, (GFunc) g_object_run_dispose, NULL);
- done:
- if (return_val)
- {
- if (event->any.window)
- g_object_ref (event->any.window);
- }
- else
+ _gdk_screen_close (broadway_display->screens[0]);
+
+ if (broadway_display->event_source)
{
- /* Mark this event as having no resources to be freed */
- event->any.window = NULL;
- event->any.type = GDK_NOTHING;
+ g_source_destroy (broadway_display->event_source);
+ g_source_unref (broadway_display->event_source);
+ broadway_display->event_source = NULL;
}
- if (window)
- g_object_unref (window);
-
- return return_val;
+ G_OBJECT_CLASS (gdk_broadway_display_parent_class)->dispose (object);
}
-static GdkFilterReturn
-gdk_wm_protocols_filter (GdkXEvent *xev,
- GdkEvent *event,
- gpointer data)
+static void
+gdk_broadway_display_finalize (GObject *object)
{
- XEvent *xevent = (XEvent *)xev;
- GdkWindow *win = event->any.window;
- GdkDisplay *display;
- Atom atom;
-
- if (!win)
- return GDK_FILTER_REMOVE;
-
- display = GDK_WINDOW_DISPLAY (win);
- atom = (Atom)xevent->xclient.data.l[0];
-
- if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
- {
- /* The delete window request specifies a window
- * to delete. We don't actually destroy the
- * window because "it is only a request". (The
- * window might contain vital data that the
- * program does not want destroyed). Instead
- * the event is passed along to the program,
- * which should then destroy the window.
- */
- GDK_NOTE (EVENTS,
- g_message ("delete window:\t\twindow: %ld",
- xevent->xclient.window));
-
- event->any.type = GDK_DELETE;
+ GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (object);
- gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
+ /* Keymap */
+ if (broadway_display->keymap)
+ g_object_unref (broadway_display->keymap);
- return GDK_FILTER_TRANSLATE;
- }
- else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
- {
- GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
- GdkWindowObject *private = (GdkWindowObject *)win;
-
- /* There is no way of knowing reliably whether we are viewable;
- * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
- */
- if (toplevel && private->accept_focus)
- _gdk_x11_set_input_focus_safe (display, toplevel->focus_window,
- RevertToParent,
- xevent->xclient.data.l[1]);
-
- return GDK_FILTER_REMOVE;
- }
- else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
- !_gdk_x11_display_is_root_window (display,
- xevent->xclient.window))
- {
- XClientMessageEvent xclient = xevent->xclient;
+ _gdk_broadway_cursor_display_finalize (GDK_DISPLAY_OBJECT(broadway_display));
- xclient.window = GDK_WINDOW_XROOTWIN (win);
- XSendEvent (GDK_WINDOW_XDISPLAY (win),
- xclient.window,
- False,
- SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient);
+ /* Atom Hashtable */
+ g_hash_table_destroy (broadway_display->atom_from_virtual);
+ g_hash_table_destroy (broadway_display->atom_to_virtual);
- return GDK_FILTER_REMOVE;
- }
- else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
- GDK_DISPLAY_X11 (display)->use_sync)
- {
- GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
- if (toplevel)
- {
-#ifdef HAVE_XSYNC
- XSyncIntsToValue (&toplevel->pending_counter_value,
- xevent->xclient.data.l[2],
- xevent->xclient.data.l[3]);
-#endif
- }
- return GDK_FILTER_REMOVE;
- }
+ /* input GdkDevice list */
+ g_list_foreach (broadway_display->input_devices, (GFunc) g_object_unref, NULL);
+ g_list_free (broadway_display->input_devices);
+ /* Free all GdkScreens */
+ g_object_unref (broadway_display->screens[0]);
+ g_free (broadway_display->screens);
- return GDK_FILTER_CONTINUE;
+ G_OBJECT_CLASS (gdk_broadway_display_parent_class)->finalize (object);
}
-static void
-_gdk_event_init (GdkDisplay *display)
+void
+_gdk_broadway_display_make_default (GdkDisplay *display)
{
- GdkDisplayX11 *display_x11;
- GdkDeviceManager *device_manager;
-
- display_x11 = GDK_DISPLAY_X11 (display);
- display_x11->event_source = gdk_event_source_new (display);
-
- gdk_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
- GDK_EVENT_TRANSLATOR (display));
-
- device_manager = gdk_display_get_device_manager (display);
- gdk_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
- GDK_EVENT_TRANSLATOR (device_manager));
-
- gdk_display_add_client_message_filter (display,
- gdk_atom_intern_static_string ("WM_PROTOCOLS"),
- gdk_wm_protocols_filter,
- NULL);
}
static void
-_gdk_input_init (GdkDisplay *display)
+gdk_broadway_display_notify_startup_complete (GdkDisplay *display,
+ const gchar *startup_id)
{
- GdkDisplayX11 *display_x11;
- GdkDeviceManager *device_manager;
- GdkDevice *device;
- GList *list, *l;
-
- display_x11 = GDK_DISPLAY_X11 (display);
- device_manager = gdk_display_get_device_manager (display);
-
- /* For backwards compatibility, just add
- * floating devices that are not keyboards.
- */
- list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
-
- for (l = list; l; l = l->next)
- {
- device = l->data;
-
- if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
- continue;
-
- display_x11->input_devices = g_list_prepend (display_x11->input_devices,
- g_object_ref (l->data));
- }
-
- g_list_free (list);
-
- /* Now set "core" pointer to the first
- * master device that is a pointer.
- */
- list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
-
- for (l = list; l; l = l->next)
- {
- device = list->data;
-
- if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
- continue;
-
- display->core_pointer = device;
- break;
- }
-
- /* Add the core pointer to the devices list */
- display_x11->input_devices = g_list_prepend (display_x11->input_devices,
- g_object_ref (display->core_pointer));
-
- g_list_free (list);
}
-/**
- * gdk_display_open:
- * @display_name: the name of the display to open
- * @returns: a #GdkDisplay, or %NULL if the display
- * could not be opened.
- *
- * Opens a display.
- *
- * Since: 2.2
- */
-GdkDisplay *
-gdk_display_open (const gchar *display_name)
+static gboolean
+gdk_broadway_display_supports_selection_notification (GdkDisplay *display)
{
- Display *xdisplay;
- GdkDisplay *display;
- GdkDisplayX11 *display_x11;
- GdkWindowAttr attr;
- gint argc;
- gchar *argv[1];
- const char *sm_client_id;
-
- XClassHint *class_hint;
- gulong pid;
- gint i;
- gint ignore;
- gint maj, min;
-
- xdisplay = XOpenDisplay (display_name);
- if (!xdisplay)
- return NULL;
-
- display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
- display_x11 = GDK_DISPLAY_X11 (display);
-
- display_x11->xdisplay = xdisplay;
-
-#ifdef HAVE_X11R6
- /* Set up handlers for Xlib internal connections */
- XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
-#endif /* HAVE_X11R6 */
-
- _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
-
- /* RandR must be initialized before we initialize the screens */
- display_x11->have_randr13 = FALSE;
-#ifdef HAVE_RANDR
- if (XRRQueryExtension (display_x11->xdisplay,
- &display_x11->xrandr_event_base, &ignore))
- {
- int major, minor;
-
- XRRQueryVersion (display_x11->xdisplay, &major, &minor);
-
- if ((major == 1 && minor >= 3) || major > 1)
- display_x11->have_randr13 = TRUE;
-
- gdk_x11_register_standard_event_type (display, display_x11->xrandr_event_base, RRNumberEvents);
- }
-#endif
-
- /* initialize the display's screens */
- display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
- for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
- display_x11->screens[i] = _gdk_x11_screen_new (display, i);
-
- /* We need to initialize events after we have the screen
- * structures in places
- */
- for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
- _gdk_screen_x11_events_init (display_x11->screens[i]);
-
- /*set the default screen */
- display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
-
- display->device_manager = _gdk_device_manager_new (display);
-
- _gdk_event_init (display);
-
- attr.window_type = GDK_WINDOW_TOPLEVEL;
- attr.wclass = GDK_INPUT_OUTPUT;
- attr.x = 10;
- attr.y = 10;
- attr.width = 10;
- attr.height = 10;
- attr.event_mask = 0;
-
- display_x11->leader_gdk_window = gdk_window_new (GDK_SCREEN_X11 (display_x11->default_screen)->root_window,
- &attr, GDK_WA_X | GDK_WA_Y);
- (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
-
- display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
-
- display_x11->leader_window_title_set = FALSE;
-
-#ifdef HAVE_XFIXES
- if (XFixesQueryExtension (display_x11->xdisplay,
- &display_x11->xfixes_event_base,
- &ignore))
- {
- display_x11->have_xfixes = TRUE;
-
- gdk_x11_register_standard_event_type (display,
- display_x11->xfixes_event_base,
- XFixesNumberEvents);
- }
- else
-#endif
- display_x11->have_xfixes = FALSE;
-
-#ifdef HAVE_XCOMPOSITE
- if (XCompositeQueryExtension (display_x11->xdisplay,
- &ignore, &ignore))
- {
- int major, minor;
-
- XCompositeQueryVersion (display_x11->xdisplay, &major, &minor);
-
- /* Prior to Composite version 0.4, composited windows clipped their
- * parents, so you had to use IncludeInferiors to draw to the parent
- * This isn't useful for our purposes, so require 0.4
- */
- display_x11->have_xcomposite = major > 0 || (major == 0 && minor >= 4);
- }
- else
-#endif
- display_x11->have_xcomposite = FALSE;
-
-#ifdef HAVE_XDAMAGE
- if (XDamageQueryExtension (display_x11->xdisplay,
- &display_x11->xdamage_event_base,
- &ignore))
- {
- display_x11->have_xdamage = TRUE;
-
- gdk_x11_register_standard_event_type (display,
- display_x11->xdamage_event_base,
- XDamageNumberEvents);
- }
- else
-#endif
- display_x11->have_xdamage = FALSE;
-
- display_x11->have_shapes = FALSE;
- display_x11->have_input_shapes = FALSE;
-
- if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &display_x11->shape_event_base, &ignore))
- {
- display_x11->have_shapes = TRUE;
-#ifdef ShapeInput
- if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
- display_x11->have_input_shapes = (maj == 1 && min >= 1);
-#endif
- }
-
- display_x11->trusted_client = TRUE;
- {
- Window root, child;
- int rootx, rooty, winx, winy;
- unsigned int xmask;
-
- gdk_error_trap_push ();
- XQueryPointer (display_x11->xdisplay,
- GDK_SCREEN_X11 (display_x11->default_screen)->xroot_window,
- &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
- if (G_UNLIKELY (gdk_error_trap_pop () == BadWindow))
- {
- g_warning ("Connection to display %s appears to be untrusted. Pointer and keyboard grabs and inter-client communication may not work as expected.", gdk_display_get_name (display));
- display_x11->trusted_client = FALSE;
- }
- }
-
- if (_gdk_synchronize)
- XSynchronize (display_x11->xdisplay, True);
-
- class_hint = XAllocClassHint();
- class_hint->res_name = g_get_prgname ();
-
- class_hint->res_class = (char *)gdk_get_program_class ();
-
- /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
- * from argv[0], so we just synthesize an argument array here.
- */
- argc = 1;
- argv[0] = g_get_prgname ();
-
- XmbSetWMProperties (display_x11->xdisplay,
- display_x11->leader_window,
- NULL, NULL, argv, argc, NULL, NULL,
- class_hint);
- XFree (class_hint);
-
- sm_client_id = _gdk_get_sm_client_id ();
- if (sm_client_id)
- _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
-
- pid = getpid ();
- XChangeProperty (display_x11->xdisplay,
- display_x11->leader_window,
- gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
- XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
-
- /* We don't yet know a valid time. */
- display_x11->user_time = 0;
-
-#ifdef HAVE_XKB
- {
- gint xkb_major = XkbMajorVersion;
- gint xkb_minor = XkbMinorVersion;
- if (XkbLibraryVersion (&xkb_major, &xkb_minor))
- {
- xkb_major = XkbMajorVersion;
- xkb_minor = XkbMinorVersion;
-
- if (XkbQueryExtension (display_x11->xdisplay,
- NULL, &display_x11->xkb_event_type, NULL,
- &xkb_major, &xkb_minor))
- {
- Bool detectable_autorepeat_supported;
-
- display_x11->use_xkb = TRUE;
-
- XkbSelectEvents (display_x11->xdisplay,
- XkbUseCoreKbd,
- XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
- XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
-
- /* keep this in sync with _gdk_keymap_state_changed() */
- XkbSelectEventDetails (display_x11->xdisplay,
- XkbUseCoreKbd, XkbStateNotify,
- XkbAllStateComponentsMask,
- XkbGroupLockMask|XkbModifierLockMask);
-
- XkbSetDetectableAutoRepeat (display_x11->xdisplay,
- True,
- &detectable_autorepeat_supported);
-
- GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
- detectable_autorepeat_supported ?
- "supported" : "not supported"));
-
- display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
- }
- }
- }
-#endif
-
- display_x11->use_sync = FALSE;
-#ifdef HAVE_XSYNC
- {
- int major, minor;
- int error_base, event_base;
-
- if (XSyncQueryExtension (display_x11->xdisplay,
- &event_base, &error_base) &&
- XSyncInitialize (display_x11->xdisplay,
- &major, &minor))
- display_x11->use_sync = TRUE;
- }
-#endif
-
- _gdk_input_init (display);
- _gdk_dnd_init (display);
-
- for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
- _gdk_x11_screen_setup (display_x11->screens[i]);
-
- g_signal_emit_by_name (display, "opened");
- g_signal_emit_by_name (gdk_display_manager_get (), "display-opened", display);
-
- return display;
+ return FALSE;
}
-#ifdef HAVE_X11R6
-/*
- * XLib internal connection handling
- */
-typedef struct _GdkInternalConnection GdkInternalConnection;
-
-struct _GdkInternalConnection
-{
- gint fd;
- GSource *source;
- Display *display;
-};
-
static gboolean
-process_internal_connection (GIOChannel *gioc,
- GIOCondition cond,
- gpointer data)
-{
- GdkInternalConnection *connection = (GdkInternalConnection *)data;
-
- GDK_THREADS_ENTER ();
-
- XProcessInternalConnection ((Display*)connection->display, connection->fd);
-
- GDK_THREADS_LEAVE ();
+gdk_broadway_display_request_selection_notification (GdkDisplay *display,
+ GdkAtom selection)
- return TRUE;
-}
-
-gulong
-_gdk_windowing_window_get_next_serial (GdkDisplay *display)
{
- return NextRequest (GDK_DISPLAY_XDISPLAY (display));
+ return FALSE;
}
-
-static GdkInternalConnection *
-gdk_add_connection_handler (Display *display,
- guint fd)
+static gboolean
+gdk_broadway_display_supports_clipboard_persistence (GdkDisplay *display)
{
- GIOChannel *io_channel;
- GdkInternalConnection *connection;
-
- connection = g_new (GdkInternalConnection, 1);
-
- connection->fd = fd;
- connection->display = display;
-
- io_channel = g_io_channel_unix_new (fd);
-
- connection->source = g_io_create_watch (io_channel, G_IO_IN);
- g_source_set_callback (connection->source,
- (GSourceFunc)process_internal_connection, connection, NULL);
- g_source_attach (connection->source, NULL);
-
- g_io_channel_unref (io_channel);
-
- return connection;
+ return FALSE;
}
static void
-gdk_remove_connection_handler (GdkInternalConnection *connection)
+gdk_broadway_display_store_clipboard (GdkDisplay *display,
+ GdkWindow *clipboard_window,
+ guint32 time_,
+ const GdkAtom *targets,
+ gint n_targets)
{
- g_source_destroy (connection->source);
- g_free (connection);
}
-static void
-gdk_internal_connection_watch (Display *display,
- XPointer arg,
- gint fd,
- gboolean opening,
- XPointer *watch_data)
+static gboolean
+gdk_broadway_display_supports_shapes (GdkDisplay *display)
{
- if (opening)
- *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
- else
- gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
+ return FALSE;
}
-#endif /* HAVE_X11R6 */
-/**
- * gdk_display_get_name:
- * @display: a #GdkDisplay
- *
- * Gets the name of the display.
- *
- * Returns: a string representing the display name. This string is owned
- * by GDK and should not be modified or freed.
- *
- * Since: 2.2
- */
-G_CONST_RETURN gchar *
-gdk_display_get_name (GdkDisplay *display)
+static gboolean
+gdk_broadway_display_supports_input_shapes (GdkDisplay *display)
{
- g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
-
- return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
+ return FALSE;
}
-/**
- * gdk_display_get_n_screens:
- * @display: a #GdkDisplay
- *
- * Gets the number of screen managed by the @display.
- *
- * Returns: number of screens.
- *
- * Since: 2.2
- */
-gint
-gdk_display_get_n_screens (GdkDisplay *display)
+static gboolean
+gdk_broadway_display_supports_composite (GdkDisplay *display)
{
- g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
-
- return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
+ return FALSE;
}
-/**
- * gdk_display_get_screen:
- * @display: a #GdkDisplay
- * @screen_num: the screen number
- *
- * Returns a screen object for one of the screens of the display.
- *
- * Returns: the #GdkScreen object
- *
- * Since: 2.2
- */
-GdkScreen *
-gdk_display_get_screen (GdkDisplay *display,
- gint screen_num)
+static GList *
+gdk_broadway_display_list_devices (GdkDisplay *display)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
-
- return GDK_DISPLAY_X11 (display)->screens[screen_num];
-}
-/**
- * gdk_display_get_default_screen:
- * @display: a #GdkDisplay
- *
- * Get the default #GdkScreen for @display.
- *
- * Returns: the default #GdkScreen object for @display
- *
- * Since: 2.2
- */
-GdkScreen *
-gdk_display_get_default_screen (GdkDisplay *display)
-{
- g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
-
- return GDK_DISPLAY_X11 (display)->default_screen;
+ return GDK_BROADWAY_DISPLAY (display)->input_devices;
}
-gboolean
-_gdk_x11_display_is_root_window (GdkDisplay *display,
- Window xroot_window)
+static gboolean
+gdk_broadway_display_send_client_message (GdkDisplay *display,
+ GdkEvent *event,
+ GdkNativeWindow winid)
{
- GdkDisplayX11 *display_x11;
- gint i;
-
- g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
-
- display_x11 = GDK_DISPLAY_X11 (display);
-
- for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
- {
- if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
- return TRUE;
- }
return FALSE;
}
-struct XPointerUngrabInfo {
- GdkDisplay *display;
- guint32 time;
-};
-
static void
-device_ungrab_callback (GdkDisplay *display,
- gpointer data,
- gulong serial)
-{
- GdkDevice *device = data;
-
- _gdk_display_device_grab_update (display, device, serial);
-}
-
-
-#define XSERVER_TIME_IS_LATER(time1, time2) \
- ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
- (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
- )
-
-/**
- * gdk_device_ungrab:
- * @device: a #GdkDevice
- * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
- *
- * Release any grab on @device.
- *
- * Since: 3.0
- */
-void
-gdk_device_ungrab (GdkDevice *device,
- guint32 time_)
-{
- GdkDisplay *display;
- Display *xdisplay;
- GdkDeviceGrabInfo *grab;
- unsigned long serial;
-
- g_return_if_fail (GDK_IS_DEVICE (device));
-
- display = gdk_device_get_display (device);
- xdisplay = GDK_DISPLAY_XDISPLAY (display);
-
- serial = NextRequest (xdisplay);
-
- GDK_DEVICE_GET_CLASS (device)->ungrab (device, time_);
- XFlush (xdisplay);
-
- grab = _gdk_display_get_last_device_grab (display, device);
- if (grab &&
- (time_ == GDK_CURRENT_TIME ||
- grab->time == GDK_CURRENT_TIME ||
- !XSERVER_TIME_IS_LATER (grab->time, time_)))
- {
- grab->serial_end = serial;
- _gdk_x11_roundtrip_async (display,
- device_ungrab_callback,
- device);
- }
-}
-
-/**
- * gdk_display_beep:
- * @display: a #GdkDisplay
- *
- * Emits a short beep on @display
- *
- * Since: 2.2
- */
-void
-gdk_display_beep (GdkDisplay *display)
-{
- g_return_if_fail (GDK_IS_DISPLAY (display));
-
-#ifdef HAVE_XKB
- XkbBell (GDK_DISPLAY_XDISPLAY (display), None, 0, None);
-#else
- XBell (GDK_DISPLAY_XDISPLAY (display), 0);
-#endif
-}
-
-/**
- * gdk_display_sync:
- * @display: a #GdkDisplay
- *
- * Flushes any requests queued for the windowing system and waits until all
- * requests have been handled. This is often used for making sure that the
- * display is synchronized with the current state of the program. Calling
- * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
- * generated from earlier requests are handled before the error trap is
- * removed.
- *
- * This is most useful for X11. On windowing systems where requests are
- * handled synchronously, this function will do nothing.
- *
- * Since: 2.2
- */
-void
-gdk_display_sync (GdkDisplay *display)
-{
- g_return_if_fail (GDK_IS_DISPLAY (display));
-
- XSync (GDK_DISPLAY_XDISPLAY (display), False);
-}
-
-/**
- * gdk_display_flush:
- * @display: a #GdkDisplay
- *
- * Flushes any requests queued for the windowing system; this happens automatically
- * when the main loop blocks waiting for new events, but if your application
- * is drawing without returning control to the main loop, you may need
- * to call this function explicitely. A common case where this function
- * needs to be called is when an application is executing drawing commands
- * from a thread other than the thread where the main loop is running.
- *
- * This is most useful for X11. On windowing systems where requests are
- * handled synchronously, this function will do nothing.
- *
- * Since: 2.4
- */
-void
-gdk_display_flush (GdkDisplay *display)
+gdk_broadway_display_add_client_message_filter (GdkDisplay *display,
+ GdkAtom message_type,
+ GdkFilterFunc func,
+ gpointer data)
{
- g_return_if_fail (GDK_IS_DISPLAY (display));
-
- if (!display->closed)
- XFlush (GDK_DISPLAY_XDISPLAY (display));
}
-/**
- * gdk_display_get_default_group:
- * @display: a #GdkDisplay
- *
- * Returns the default group leader window for all toplevel windows
- * on @display. This window is implicitly created by GDK.
- * See gdk_window_set_group().
- *
- * Return value: The default group leader window for @display
- *
- * Since: 2.4
- **/
-GdkWindow *
-gdk_display_get_default_group (GdkDisplay *display)
+static gulong
+gdk_broadway_display_get_next_serial (GdkDisplay *display)
{
- g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
-
- return GDK_DISPLAY_X11 (display)->leader_gdk_window;
+ return 0;
}
-/**
- * gdk_x11_display_grab:
- * @display: a #GdkDisplay
- *
- * Call XGrabServer() on @display.
- * To ungrab the display again, use gdk_x11_display_ungrab().
- *
- * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
- *
- * Since: 2.2
- **/
-void
-gdk_x11_display_grab (GdkDisplay *display)
-{
- GdkDisplayX11 *display_x11;
-
- g_return_if_fail (GDK_IS_DISPLAY (display));
-
- display_x11 = GDK_DISPLAY_X11 (display);
-
- if (display_x11->grab_count == 0)
- XGrabServer (display_x11->xdisplay);
- display_x11->grab_count++;
-}
-/**
- * gdk_x11_display_ungrab:
- * @display: a #GdkDisplay
- *
- * Ungrab @display after it has been grabbed with
- * gdk_x11_display_grab().
- *
- * Since: 2.2
- **/
-void
-gdk_x11_display_ungrab (GdkDisplay *display)
+static void
+gdk_broadway_display_event_data_copy (GdkDisplay *display,
+ const GdkEvent *src,
+ GdkEvent *dst)
{
- GdkDisplayX11 *display_x11;
-
- g_return_if_fail (GDK_IS_DISPLAY (display));
-
- display_x11 = GDK_DISPLAY_X11 (display);;
- g_return_if_fail (display_x11->grab_count > 0);
-
- display_x11->grab_count--;
- if (display_x11->grab_count == 0)
- {
- XUngrabServer (display_x11->xdisplay);
- XFlush (display_x11->xdisplay);
- }
}
static void
-gdk_display_x11_dispose (GObject *object)
+gdk_broadway_display_event_data_free (GdkDisplay *display,
+ GdkEvent *event)
{
- GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
- gint i;
-
- g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);
-
- for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
- _gdk_screen_close (display_x11->screens[i]);
-
- if (display_x11->event_source)
- {
- g_source_destroy (display_x11->event_source);
- g_source_unref (display_x11->event_source);
- display_x11->event_source = NULL;
- }
-
- G_OBJECT_CLASS (_gdk_display_x11_parent_class)->dispose (object);
}
static void
-gdk_display_x11_finalize (GObject *object)
+gdk_broadway_display_class_init (GdkBroadwayDisplayClass * class)
{
- GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
- gint i;
-
- /* Keymap */
- if (display_x11->keymap)
- g_object_unref (display_x11->keymap);
-
- /* Free motif Dnd */
- if (display_x11->motif_target_lists)
- {
- for (i = 0; i < display_x11->motif_n_target_lists; i++)
- g_list_free (display_x11->motif_target_lists[i]);
- g_free (display_x11->motif_target_lists);
- }
-
- _gdk_x11_cursor_display_finalize (GDK_DISPLAY_OBJECT(display_x11));
-
- /* Atom Hashtable */
- g_hash_table_destroy (display_x11->atom_from_virtual);
- g_hash_table_destroy (display_x11->atom_to_virtual);
-
- /* Leader Window */
- XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
-
- /* list of filters for client messages */
- g_list_foreach (display_x11->client_filters, (GFunc) g_free, NULL);
- g_list_free (display_x11->client_filters);
-
- /* List of event window extraction functions */
- g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
- g_slist_free (display_x11->event_types);
-
- /* input GdkDevice list */
- g_list_foreach (display_x11->input_devices, (GFunc) g_object_unref, NULL);
- g_list_free (display_x11->input_devices);
-
- /* input GdkWindow list */
- g_list_foreach (display_x11->input_windows, (GFunc) g_free, NULL);
- g_list_free (display_x11->input_windows);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GdkDisplayClass *display_class = GDK_DISPLAY_CLASS (class);
+
+ object_class->dispose = gdk_broadway_display_dispose;
+ object_class->finalize = gdk_broadway_display_finalize;
+
+ display_class->window_type = GDK_TYPE_BROADWAY_WINDOW;
+
+ display_class->get_name = gdk_broadway_display_get_name;
+ display_class->get_n_screens = gdk_broadway_display_get_n_screens;
+ display_class->get_screen = gdk_broadway_display_get_screen;
+ display_class->get_default_screen = gdk_broadway_display_get_default_screen;
+ display_class->beep = gdk_broadway_display_beep;
+ display_class->sync = gdk_broadway_display_sync;
+ display_class->flush = gdk_broadway_display_flush;
+ display_class->has_pending = gdk_broadway_display_has_pending;
+ display_class->queue_events = _gdk_broadway_display_queue_events;
+ display_class->get_default_group = gdk_broadway_display_get_default_group;
+ display_class->supports_selection_notification = gdk_broadway_display_supports_selection_notification;
+ display_class->request_selection_notification = gdk_broadway_display_request_selection_notification;
+ display_class->supports_clipboard_persistence = gdk_broadway_display_supports_clipboard_persistence;
+ display_class->store_clipboard = gdk_broadway_display_store_clipboard;
+ display_class->supports_shapes = gdk_broadway_display_supports_shapes;
+ display_class->supports_input_shapes = gdk_broadway_display_supports_input_shapes;
+ display_class->supports_composite = gdk_broadway_display_supports_composite;
+ display_class->list_devices = gdk_broadway_display_list_devices;
+ display_class->send_client_message = gdk_broadway_display_send_client_message;
+ display_class->add_client_message_filter = gdk_broadway_display_add_client_message_filter;
+ display_class->get_drag_protocol = _gdk_broadway_display_get_drag_protocol;
+ display_class->get_cursor_for_type = _gdk_broadway_display_get_cursor_for_type;
+ display_class->get_cursor_for_name = _gdk_broadway_display_get_cursor_for_name;
+ display_class->get_cursor_for_pixbuf = _gdk_broadway_display_get_cursor_for_pixbuf;
+ display_class->get_default_cursor_size = _gdk_broadway_display_get_default_cursor_size;
+ display_class->get_maximal_cursor_size = _gdk_broadway_display_get_maximal_cursor_size;
+ display_class->supports_cursor_alpha = _gdk_broadway_display_supports_cursor_alpha;
+ display_class->supports_cursor_color = _gdk_broadway_display_supports_cursor_color;
+
+ display_class->before_process_all_updates = _gdk_broadway_display_before_process_all_updates;
+ display_class->after_process_all_updates = _gdk_broadway_display_after_process_all_updates;
+ display_class->get_next_serial = gdk_broadway_display_get_next_serial;
+ display_class->notify_startup_complete = gdk_broadway_display_notify_startup_complete;
+ display_class->event_data_copy = gdk_broadway_display_event_data_copy;
+ display_class->event_data_free = gdk_broadway_display_event_data_free;
+ display_class->create_window_impl = _gdk_broadway_display_create_window_impl;
+ display_class->get_keymap = _gdk_broadway_display_get_keymap;
+ display_class->get_selection_owner = _gdk_broadway_display_get_selection_owner;
+ display_class->set_selection_owner = _gdk_broadway_display_set_selection_owner;
+ display_class->send_selection_notify = _gdk_broadway_display_send_selection_notify;
+ display_class->get_selection_property = _gdk_broadway_display_get_selection_property;
+ display_class->convert_selection = _gdk_broadway_display_convert_selection;
+ display_class->text_property_to_utf8_list = _gdk_broadway_display_text_property_to_utf8_list;
+ display_class->utf8_to_string_target = _gdk_broadway_display_utf8_to_string_target;
+}
- /* Free all GdkScreens */
- for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
- g_object_unref (display_x11->screens[i]);
- g_free (display_x11->screens);
-
- g_free (display_x11->startup_notification_id);
-
- /* X ID hashtable */
- g_hash_table_destroy (display_x11->xid_ht);
-
- XCloseDisplay (display_x11->xdisplay);
-
- /* error traps */
- while (display_x11->error_traps != NULL)
- {
- GdkErrorTrap *trap = display_x11->error_traps->data;
-
- display_x11->error_traps =
- g_slist_delete_link (display_x11->error_traps,
- display_x11->error_traps);
-
- if (trap->end_sequence == 0)
- g_warning ("Display finalized with an unpopped error trap");
-
- g_slice_free (GdkErrorTrap, trap);
- }
-
- G_OBJECT_CLASS (_gdk_display_x11_parent_class)->finalize (object);
-}
-
-/**
- * gdk_x11_lookup_xdisplay:
- * @xdisplay: a pointer to an X Display
- *
- * Find the #GdkDisplay corresponding to @display, if any exists.
- *
- * Return value: the #GdkDisplay, if found, otherwise %NULL.
- *
- * Since: 2.2
- **/
-GdkDisplay *
-gdk_x11_lookup_xdisplay (Display *xdisplay)
-{
- GSList *tmp_list;
-
- for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
- {
- if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
- return tmp_list->data;
- }
-
- return NULL;
-}
-
-/**
- * _gdk_x11_display_screen_for_xrootwin:
- * @display: a #GdkDisplay
- * @xrootwin: window ID for one of of the screen's of the display.
- *
- * Given the root window ID of one of the screen's of a #GdkDisplay,
- * finds the screen.
- *
- * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
- **/
-GdkScreen *
-_gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
- Window xrootwin)
-{
- gint i;
-
- for (i = 0; i < ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay); i++)
- {
- GdkScreen *screen = gdk_display_get_screen (display, i);
- if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
- return screen;
- }
-
- return NULL;
-}
-
-/**
- * gdk_x11_display_get_xdisplay:
- * @display: a #GdkDisplay
- * @returns: an X display.
- *
- * Returns the X display of a #GdkDisplay.
- *
- * Since: 2.2
- */
-Display *
-gdk_x11_display_get_xdisplay (GdkDisplay *display)
-{
- g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- return GDK_DISPLAY_X11 (display)->xdisplay;
-}
-
-void
-_gdk_windowing_set_default_display (GdkDisplay *display)
-{
- GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
- const gchar *startup_id;
-
- if (!display)
- return;
-
- g_free (display_x11->startup_notification_id);
- display_x11->startup_notification_id = NULL;
-
- startup_id = g_getenv ("DESKTOP_STARTUP_ID");
- if (startup_id && *startup_id != '\0')
- {
- if (!g_utf8_validate (startup_id, -1, NULL))
- g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
- else
- gdk_x11_display_set_startup_notification_id (display, startup_id);
-
- /* Clear the environment variable so it won't be inherited by
- * child processes and confuse things.
- */
- g_unsetenv ("DESKTOP_STARTUP_ID");
- }
-}
-
-static void
-broadcast_xmessage (GdkDisplay *display,
- const char *message_type,
- const char *message_type_begin,
- const char *message)
-{
- Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
- GdkScreen *screen = gdk_display_get_default_screen (display);
- GdkWindow *root_window = gdk_screen_get_root_window (screen);
- Window xroot_window = GDK_WINDOW_XID (root_window);
-
- Atom type_atom;
- Atom type_atom_begin;
- Window xwindow;
-
- if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
- return;
-
- {
- XSetWindowAttributes attrs;
-
- attrs.override_redirect = True;
- attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
-
- xwindow =
- XCreateWindow (xdisplay,
- xroot_window,
- -100, -100, 1, 1,
- 0,
- CopyFromParent,
- CopyFromParent,
- (Visual *)CopyFromParent,
- CWOverrideRedirect | CWEventMask,
- &attrs);
- }
-
- type_atom = gdk_x11_get_xatom_by_name_for_display (display,
- message_type);
- type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
- message_type_begin);
-
- {
- XClientMessageEvent xclient;
- const char *src;
- const char *src_end;
- char *dest;
- char *dest_end;
-
- memset(&xclient, 0, sizeof (xclient));
- xclient.type = ClientMessage;
- xclient.message_type = type_atom_begin;
- xclient.display =xdisplay;
- xclient.window = xwindow;
- xclient.format = 8;
-
- src = message;
- src_end = message + strlen (message) + 1; /* +1 to include nul byte */
-
- while (src != src_end)
- {
- dest = &xclient.data.b[0];
- dest_end = dest + 20;
-
- while (dest != dest_end &&
- src != src_end)
- {
- *dest = *src;
- ++dest;
- ++src;
- }
-
- while (dest != dest_end)
- {
- *dest = 0;
- ++dest;
- }
-
- XSendEvent (xdisplay,
- xroot_window,
- False,
- PropertyChangeMask,
- (XEvent *)&xclient);
-
- xclient.message_type = type_atom;
- }
- }
-
- XDestroyWindow (xdisplay, xwindow);
- XFlush (xdisplay);
-}
-
-/**
- * gdk_x11_display_broadcast_startup_message:
- * @display: a #GdkDisplay
- * @message_type: startup notification message type ("new", "change",
- * or "remove")
- * @...: a list of key/value pairs (as strings), terminated by a
- * %NULL key. (A %NULL value for a key will cause that key to be
- * skipped in the output.)
- *
- * Sends a startup notification message of type @message_type to
- * @display.
- *
- * This is a convenience function for use by code that implements the
- * freedesktop startup notification specification. Applications should
- * not normally need to call it directly. See the <ulink
- * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
- * Notification Protocol specification</ulink> for
- * definitions of the message types and keys that can be used.
- *
- * Since: 2.12
- **/
-void
-gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
- const char *message_type,
- ...)
-{
- GString *message;
- va_list ap;
- const char *key, *value, *p;
-
- message = g_string_new (message_type);
- g_string_append_c (message, ':');
-
- va_start (ap, message_type);
- while ((key = va_arg (ap, const char *)))
- {
- value = va_arg (ap, const char *);
- if (!value)
- continue;
-
- g_string_append_printf (message, " %s=\"", key);
- for (p = value; *p; p++)
- {
- switch (*p)
- {
- case ' ':
- case '"':
- case '\\':
- g_string_append_c (message, '\\');
- break;
- }
-
- g_string_append_c (message, *p);
- }
- g_string_append_c (message, '\"');
- }
- va_end (ap);
-
- broadcast_xmessage (display,
- "_NET_STARTUP_INFO",
- "_NET_STARTUP_INFO_BEGIN",
- message->str);
-
- g_string_free (message, TRUE);
-}
-
-/**
- * gdk_notify_startup_complete:
- *
- * Indicates to the GUI environment that the application has finished
- * loading. If the applications opens windows, this function is
- * normally called after opening the application's initial set of
- * windows.
- *
- * GTK+ will call this function automatically after opening the first
- * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
- * to disable that feature.
- *
- * Since: 2.2
- **/
-void
-gdk_notify_startup_complete (void)
-{
- GdkDisplay *display;
- GdkDisplayX11 *display_x11;
-
- display = gdk_display_get_default ();
- if (!display)
- return;
-
- display_x11 = GDK_DISPLAY_X11 (display);
-
- if (display_x11->startup_notification_id == NULL)
- return;
-
- gdk_notify_startup_complete_with_id (display_x11->startup_notification_id);
-}
-
-/**
- * gdk_notify_startup_complete_with_id:
- * @startup_id: a startup-notification identifier, for which notification
- * process should be completed
- *
- * Indicates to the GUI environment that the application has finished
- * loading, using a given identifier.
- *
- * GTK+ will call this function automatically for #GtkWindow with custom
- * startup-notification identifier unless
- * gtk_window_set_auto_startup_notification() is called to disable
- * that feature.
- *
- * Since: 2.12
- **/
-void
-gdk_notify_startup_complete_with_id (const gchar* startup_id)
-{
- GdkDisplay *display;
-
- display = gdk_display_get_default ();
- if (!display)
- return;
-
- gdk_x11_display_broadcast_startup_message (display, "remove",
- "ID", startup_id,
- NULL);
-}
-
-/**
- * gdk_display_supports_selection_notification:
- * @display: a #GdkDisplay
- *
- * Returns whether #GdkEventOwnerChange events will be
- * sent when the owner of a selection changes.
- *
- * Return value: whether #GdkEventOwnerChange events will
- * be sent.
- *
- * Since: 2.6
- **/
-gboolean
-gdk_display_supports_selection_notification (GdkDisplay *display)
-{
- GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
-
- return display_x11->have_xfixes;
-}
-
-/**
- * gdk_display_request_selection_notification:
- * @display: a #GdkDisplay
- * @selection: the #GdkAtom naming the selection for which
- * ownership change notification is requested
- *
- * Request #GdkEventOwnerChange events for ownership changes
- * of the selection named by the given atom.
- *
- * Return value: whether #GdkEventOwnerChange events will
- * be sent.
- *
- * Since: 2.6
- **/
-gboolean
-gdk_display_request_selection_notification (GdkDisplay *display,
- GdkAtom selection)
-
-{
-#ifdef HAVE_XFIXES
- GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
- Atom atom;
-
- if (display_x11->have_xfixes)
- {
- atom = gdk_x11_atom_to_xatom_for_display (display,
- selection);
- XFixesSelectSelectionInput (display_x11->xdisplay,
- display_x11->leader_window,
- atom,
- XFixesSetSelectionOwnerNotifyMask |
- XFixesSelectionWindowDestroyNotifyMask |
- XFixesSelectionClientCloseNotifyMask);
- return TRUE;
- }
- else
-#endif
- return FALSE;
-}
-
-/**
- * gdk_display_supports_clipboard_persistence
- * @display: a #GdkDisplay
- *
- * Returns whether the speicifed display supports clipboard
- * persistance; i.e. if it's possible to store the clipboard data after an
- * application has quit. On X11 this checks if a clipboard daemon is
- * running.
- *
- * Returns: %TRUE if the display supports clipboard persistance.
- *
- * Since: 2.6
- */
-gboolean
-gdk_display_supports_clipboard_persistence (GdkDisplay *display)
-{
- Atom clipboard_manager;
-
- /* It might make sense to cache this */
- clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
- return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay, clipboard_manager) != None;
-}
-
-/**
- * gdk_display_store_clipboard
- * @display: a #GdkDisplay
- * @clipboard_window: a #GdkWindow belonging to the clipboard owner
- * @time_: a timestamp
- * @targets: an array of targets that should be saved, or %NULL
- * if all available targets should be saved.
- * @n_targets: length of the @targets array
- *
- * Issues a request to the clipboard manager to store the
- * clipboard data. On X11, this is a special program that works
- * according to the freedesktop clipboard specification, available at
- * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
- * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
- *
- * Since: 2.6
- */
-void
-gdk_display_store_clipboard (GdkDisplay *display,
- GdkWindow *clipboard_window,
- guint32 time_,
- const GdkAtom *targets,
- gint n_targets)
-{
- GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
- Atom clipboard_manager, save_targets;
-
- g_return_if_fail (GDK_WINDOW_IS_X11 (clipboard_window));
-
- clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
- save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
-
- gdk_error_trap_push ();
-
- if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
- {
- Atom property_name = None;
- Atom *xatoms;
- int i;
-
- if (n_targets > 0)
- {
- property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
-
- xatoms = g_new (Atom, n_targets);
- for (i = 0; i < n_targets; i++)
- xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
-
- XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
- property_name, XA_ATOM,
- 32, PropModeReplace, (guchar *)xatoms, n_targets);
- g_free (xatoms);
-
- }
-
- XConvertSelection (display_x11->xdisplay,
- clipboard_manager, save_targets, property_name,
- GDK_WINDOW_XID (clipboard_window), time_);
-
- }
- gdk_error_trap_pop_ignored ();
-
-}
-
-/**
- * gdk_x11_display_get_user_time:
- * @display: a #GdkDisplay
- *
- * Returns the timestamp of the last user interaction on
- * @display. The timestamp is taken from events caused
- * by user interaction such as key presses or pointer
- * movements. See gdk_x11_window_set_user_time().
- *
- * Returns: the timestamp of the last user interaction
- *
- * Since: 2.8
- */
-guint32
-gdk_x11_display_get_user_time (GdkDisplay *display)
-{
- return GDK_DISPLAY_X11 (display)->user_time;
-}
-
-/**
- * gdk_display_supports_shapes:
- * @display: a #GdkDisplay
- *
- * Returns %TRUE if gdk_window_shape_combine_mask() can
- * be used to create shaped windows on @display.
- *
- * Returns: %TRUE if shaped windows are supported
- *
- * Since: 2.10
- */
-gboolean
-gdk_display_supports_shapes (GdkDisplay *display)
-{
- return GDK_DISPLAY_X11 (display)->have_shapes;
-}
-
-/**
- * gdk_display_supports_input_shapes:
- * @display: a #GdkDisplay
- *
- * Returns %TRUE if gdk_window_input_shape_combine_mask() can
- * be used to modify the input shape of windows on @display.
- *
- * Returns: %TRUE if windows with modified input shape are supported
- *
- * Since: 2.10
- */
-gboolean
-gdk_display_supports_input_shapes (GdkDisplay *display)
-{
- return GDK_DISPLAY_X11 (display)->have_input_shapes;
-}
-
-
-/**
- * gdk_x11_display_get_startup_notification_id:
- * @display: a #GdkDisplay
- *
- * Gets the startup notification ID for a display.
- *
- * Returns: the startup notification ID for @display
- *
- * Since: 2.12
- */
-G_CONST_RETURN gchar *
-gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
-{
- return GDK_DISPLAY_X11 (display)->startup_notification_id;
-}
-
-/**
- * gdk_x11_display_set_startup_notification_id:
- * @display: a #GdkDisplay
- * @startup_id: the startup notification ID (must be valid utf8)
- *
- * Sets the startup notification ID for a display.
- *
- * This is usually taken from the value of the DESKTOP_STARTUP_ID
- * environment variable, but in some cases (such as the application not
- * being launched using exec()) it can come from other sources.
- *
- * If the ID contains the string "_TIME" then the portion following that
- * string is taken to be the X11 timestamp of the event that triggered
- * the application to be launched and the GDK current event time is set
- * accordingly.
- *
- * The startup ID is also what is used to signal that the startup is
- * complete (for example, when opening a window or when calling
- * gdk_notify_startup_complete()).
- *
- * Since: 3.0
- **/
-void
-gdk_x11_display_set_startup_notification_id (GdkDisplay *display,
- const gchar *startup_id)
-{
- GdkDisplayX11 *display_x11;
- gchar *time_str;
-
- display_x11 = GDK_DISPLAY_X11 (display);
-
- g_free (display_x11->startup_notification_id);
- display_x11->startup_notification_id = g_strdup (startup_id);
-
- /* Find the launch time from the startup_id, if it's there. Newer spec
- * states that the startup_id is of the form <unique>_TIME<timestamp>
- */
- time_str = g_strrstr (startup_id, "_TIME");
- if (time_str != NULL)
- {
- gulong retval;
- gchar *end;
- errno = 0;
-
- /* Skip past the "_TIME" part */
- time_str += 5;
-
- retval = strtoul (time_str, &end, 0);
- if (end != time_str && errno == 0)
- display_x11->user_time = retval;
- }
-
- /* Set the startup id on the leader window so it
- * applies to all windows we create on this display
- */
- XChangeProperty (display_x11->xdisplay,
- display_x11->leader_window,
- gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
- gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
- PropModeReplace,
- (guchar *)startup_id, strlen (startup_id));
-}
-
-/**
- * gdk_display_supports_composite:
- * @display: a #GdkDisplay
- *
- * Returns %TRUE if gdk_window_set_composited() can be used
- * to redirect drawing on the window using compositing.
- *
- * Currently this only works on X11 with XComposite and
- * XDamage extensions available.
- *
- * Returns: %TRUE if windows may be composited.
- *
- * Since: 2.12
- */
-gboolean
-gdk_display_supports_composite (GdkDisplay *display)
-{
- GdkDisplayX11 *x11_display = GDK_DISPLAY_X11 (display);
-
- return x11_display->have_xcomposite &&
- x11_display->have_xdamage &&
- x11_display->have_xfixes;
-}
-
-/**
- * gdk_display_list_devices:
- * @display: a #GdkDisplay
- *
- * Returns the list of available input devices attached to @display.
- * The list is statically allocated and should not be freed.
- *
- * Return value: (transfer none) (element-type GdkDevice):
- * a list of #GdkDevice
- *
- * Since: 2.2
- *
- * Deprecated: 3.0: Use gdk_device_manager_list_devices() instead.
- **/
-GList *
-gdk_display_list_devices (GdkDisplay *display)
-{
- g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
-
- return GDK_DISPLAY_X11 (display)->input_devices;
-}
-
-/**
- * gdk_event_send_client_message_for_display:
- * @display: the #GdkDisplay for the window where the message is to be sent.
- * @event: the #GdkEvent to send, which should be a #GdkEventClient.
- * @winid: the window to send the client message to.
- *
- * On X11, sends an X ClientMessage event to a given window. On
- * Windows, sends a message registered with the name
- * GDK_WIN32_CLIENT_MESSAGE.
- *
- * This could be used for communicating between different
- * applications, though the amount of data is limited to 20 bytes on
- * X11, and to just four bytes on Windows.
- *
- * Returns: non-zero on success.
- *
- * Since: 2.2
- */
-gboolean
-gdk_event_send_client_message_for_display (GdkDisplay *display,
- GdkEvent *event,
- GdkNativeWindow winid)
-{
- XEvent sev;
-
- g_return_val_if_fail(event != NULL, FALSE);
-
- /* Set up our event to send, with the exception of its target window */
- sev.xclient.type = ClientMessage;
- sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
- sev.xclient.format = event->client.data_format;
- sev.xclient.window = winid;
- memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
- sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
-
- return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
-}
-
-/**
- * gdk_display_add_client_message_filter:
- * @display: a #GdkDisplay for which this message filter applies
- * @message_type: the type of ClientMessage events to receive.
- * This will be checked against the @message_type field
- * of the XClientMessage event struct.
- * @func: the function to call to process the event.
- * @data: user data to pass to @func.
- *
- * Adds a filter to be called when X ClientMessage events are received.
- * See gdk_window_add_filter() if you are interested in filtering other
- * types of events.
- *
- * Since: 2.2
- **/
-void
-gdk_display_add_client_message_filter (GdkDisplay *display,
- GdkAtom message_type,
- GdkFilterFunc func,
- gpointer data)
-{
- GdkClientFilter *filter;
- g_return_if_fail (GDK_IS_DISPLAY (display));
- filter = g_new (GdkClientFilter, 1);
-
- filter->type = message_type;
- filter->function = func;
- filter->data = data;
-
- GDK_DISPLAY_X11(display)->client_filters =
- g_list_append (GDK_DISPLAY_X11 (display)->client_filters,
- filter);
-}
-
-/**
- * gdk_add_client_message_filter:
- * @message_type: the type of ClientMessage events to receive. This will be
- * checked against the <structfield>message_type</structfield> field of the
- * XClientMessage event struct.
- * @func: the function to call to process the event.
- * @data: user data to pass to @func.
- *
- * Adds a filter to the default display to be called when X ClientMessage events
- * are received. See gdk_display_add_client_message_filter().
- **/
-void
-gdk_add_client_message_filter (GdkAtom message_type,
- GdkFilterFunc func,
- gpointer data)
-{
- gdk_display_add_client_message_filter (gdk_display_get_default (),
- message_type, func, data);
-}
-
-/*
- *--------------------------------------------------------------
- * gdk_flush
- *
- * Flushes the Xlib output buffer and then waits
- * until all requests have been received and processed
- * by the X server. The only real use for this function
- * is in dealing with XShm.
- *
- * Arguments:
- *
- * Results:
- *
- * Side effects:
- *
- *--------------------------------------------------------------
- */
-void
-gdk_flush (void)
-{
- GSList *tmp_list = _gdk_displays;
-
- while (tmp_list)
- {
- XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
- tmp_list = tmp_list->next;
- }
-}
-
-/**
- * gdk_x11_register_standard_event_type:
- * @display: a #GdkDisplay
- * @event_base: first event type code to register
- * @n_events: number of event type codes to register
- *
- * Registers interest in receiving extension events with type codes
- * between @event_base and <literal>event_base + n_events - 1</literal>.
- * The registered events must have the window field in the same place
- * as core X events (this is not the case for e.g. XKB extension events).
- *
- * If an event type is registered, events of this type will go through
- * global and window-specific filters (see gdk_window_add_filter()).
- * Unregistered events will only go through global filters.
- * GDK may register the events of some X extensions on its own.
- *
- * This function should only be needed in unusual circumstances, e.g.
- * when filtering XInput extension events on the root window.
- *
- * Since: 2.4
- **/
-void
-gdk_x11_register_standard_event_type (GdkDisplay *display,
- gint event_base,
- gint n_events)
-{
- GdkEventTypeX11 *event_type;
- GdkDisplayX11 *display_x11;
-
- display_x11 = GDK_DISPLAY_X11 (display);
- event_type = g_new (GdkEventTypeX11, 1);
-
- event_type->base = event_base;
- event_type->n_events = n_events;
-
- display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
-}
-
-/* compare X sequence numbers handling wraparound */
-#define SEQUENCE_COMPARE(a,op,b) (((long) (a) - (long) (b)) op 0)
-
-/* delivers an error event from the error handler in gdkmain-x11.c */
-void
-_gdk_x11_display_error_event (GdkDisplay *display,
- XErrorEvent *error)
-{
- GdkDisplayX11 *display_x11;
- GSList *tmp_list;
- gboolean ignore;
-
- display_x11 = GDK_DISPLAY_X11 (display);
-
- ignore = FALSE;
- for (tmp_list = display_x11->error_traps;
- tmp_list != NULL;
- tmp_list = tmp_list->next)
- {
- GdkErrorTrap *trap;
-
- trap = tmp_list->data;
-
- if (SEQUENCE_COMPARE (trap->start_sequence, <=, error->serial) &&
- (trap->end_sequence == 0 ||
- SEQUENCE_COMPARE (trap->end_sequence, >, error->serial)))
- {
- ignore = TRUE;
- trap->error_code = error->error_code;
- break; /* only innermost trap gets the error code */
- }
- }
-
- if (!ignore)
- {
- gchar buf[64];
- gchar *msg;
-
- XGetErrorText (display_x11->xdisplay, error->error_code, buf, 63);
-
- msg =
- g_strdup_printf ("The program '%s' received an X Window System error.\n"
- "This probably reflects a bug in the program.\n"
- "The error was '%s'.\n"
- " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
- " (Note to programmers: normally, X errors are reported asynchronously;\n"
- " that is, you will receive the error a while after causing it.\n"
- " To debug your program, run it with the --sync command line\n"
- " option to change this behavior. You can then get a meaningful\n"
- " backtrace from your debugger if you break on the gdk_x_error() function.)",
- g_get_prgname (),
- buf,
- error->serial,
- error->error_code,
- error->request_code,
- error->minor_code);
-
-#ifdef G_ENABLE_DEBUG
- g_error ("%s", msg);
-#else /* !G_ENABLE_DEBUG */
- g_warning ("%s\n", msg);
-
- exit (1);
-#endif /* G_ENABLE_DEBUG */
- }
-}
-
-static void
-delete_outdated_error_traps (GdkDisplayX11 *display_x11)
-{
- GSList *tmp_list;
- gulong processed_sequence;
-
- processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
-
- tmp_list = display_x11->error_traps;
- while (tmp_list != NULL)
- {
- GdkErrorTrap *trap = tmp_list->data;
-
- if (trap->end_sequence != 0 &&
- SEQUENCE_COMPARE (trap->end_sequence, <=, processed_sequence))
- {
- GSList *free_me = tmp_list;
-
- tmp_list = tmp_list->next;
- display_x11->error_traps =
- g_slist_delete_link (display_x11->error_traps, free_me);
- g_slice_free (GdkErrorTrap, trap);
- }
- else
- {
- tmp_list = tmp_list->next;
- }
- }
-}
-
-/**
- * gdk_x11_display_error_trap_push:
- * @display: a #GdkDisplay
- *
- * Begins a range of X requests on @display for which X error events
- * will be ignored. Unignored errors (when no trap is pushed) will abort
- * the application. Use gdk_x11_display_error_trap_pop() or
- * gdk_x11_display_error_trap_pop_ignored()to lift a trap pushed
- * with this function.
- *
- * See also gdk_error_trap_push() to push a trap on all displays.
- *
- * Since: 3.0
- */
-void
-gdk_x11_display_error_trap_push (GdkDisplay *display)
-{
- GdkDisplayX11 *display_x11;
- GdkErrorTrap *trap;
-
- display_x11 = GDK_DISPLAY_X11 (display);
-
- delete_outdated_error_traps (display_x11);
-
- /* set up the Xlib callback to tell us about errors */
- _gdk_x11_error_handler_push ();
-
- trap = g_slice_new0 (GdkErrorTrap);
-
- trap->start_sequence = XNextRequest (display_x11->xdisplay);
- trap->error_code = Success;
-
- display_x11->error_traps =
- g_slist_prepend (display_x11->error_traps, trap);
-}
-
-static gint
-gdk_x11_display_error_trap_pop_internal (GdkDisplay *display,
- gboolean need_code)
-{
- GdkDisplayX11 *display_x11;
- GdkErrorTrap *trap;
- GSList *tmp_list;
- int result;
-
- display_x11 = GDK_DISPLAY_X11 (display);
-
- g_return_val_if_fail (display_x11->error_traps != NULL, Success);
-
- /* Find the first trap that hasn't been popped already */
- trap = NULL; /* quiet gcc */
- for (tmp_list = display_x11->error_traps;
- tmp_list != NULL;
- tmp_list = tmp_list->next)
- {
- trap = tmp_list->data;
-
- if (trap->end_sequence == 0)
- break;
- }
-
- g_return_val_if_fail (trap != NULL, Success);
- g_assert (trap->end_sequence == 0);
-
- /* May need to sync to fill in trap->error_code if we care about
- * getting an error code.
- */
- if (need_code)
- {
- gulong processed_sequence;
- gulong next_sequence;
-
- next_sequence = XNextRequest (display_x11->xdisplay);
- processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
-
- /* If our last request was already processed, there is no point
- * in syncing. i.e. if last request was a round trip (or even if
- * we got an event with the serial of a non-round-trip)
- */
- if ((next_sequence - 1) != processed_sequence)
- {
- XSync (display_x11->xdisplay, False);
- }
-
- result = trap->error_code;
- }
- else
- {
- result = Success;
- }
-
- /* record end of trap, giving us a range of
- * error sequences we'll ignore.
- */
- trap->end_sequence = XNextRequest (display_x11->xdisplay);
-
- /* remove the Xlib callback */
- _gdk_x11_error_handler_pop ();
-
- /* we may already be outdated */
- delete_outdated_error_traps (display_x11);
-
- return result;
-}
-
-/**
- * gdk_x11_display_error_trap_pop:
- * @display: the display
- *
- * Pops the error trap pushed by gdk_x11_display_error_trap_push().
- * Will XSync() if necessary and will always block until
- * the error is known to have occurred or not occurred,
- * so the error code can be returned.
- *
- * If you don't need to use the return value,
- * gdk_x11_display_error_trap_pop_ignored() would be more efficient.
- *
- * See gdk_error_trap_pop() for the all-displays-at-once
- * equivalent.
- *
- * Since: 3.0
- *
- * Return value: X error code or 0 on success
- */
-gint
-gdk_x11_display_error_trap_pop (GdkDisplay *display)
-{
- g_return_val_if_fail (GDK_IS_DISPLAY_X11 (display), Success);
-
- return gdk_x11_display_error_trap_pop_internal (display, TRUE);
-}
-
-/**
- * gdk_x11_display_error_trap_pop_ignored:
- * @display: the display
- *
- * Pops the error trap pushed by gdk_x11_display_error_trap_push().
- * Does not block to see if an error occurred; merely records the
- * range of requests to ignore errors for, and ignores those errors
- * if they arrive asynchronously.
- *
- * See gdk_error_trap_pop_ignored() for the all-displays-at-once
- * equivalent.
- *
- * Since: 3.0
- */
-void
-gdk_x11_display_error_trap_pop_ignored (GdkDisplay *display)
-{
- g_return_if_fail (GDK_IS_DISPLAY_X11 (display));
-
- gdk_x11_display_error_trap_pop_internal (display, FALSE);
-}