Work toward turning GdkDisplayManager into a backend singleton

This commit hides the GdkDisplayManager instance and class structs,
adds vfuncs for listing displays, opening displays, and getting and
setting the default display. The X11 backend has a derived
GdkDisplayManagerX11.

The gdk_display_manager_get() function is responsible for deciding on
which of the compiled in backends to use. Currently, it consults the
GDK_BACKEND environment variable and falls back to x11.
This commit is contained in:
Matthias Clasen 2010-12-10 19:42:09 -05:00
parent fa4b54b6de
commit ec9c97752d
17 changed files with 422 additions and 260 deletions

View File

@ -228,9 +228,8 @@ gdk_pre_parse_libgtk_only (void)
g_type_init ();
/* Do any setup particular to the windowing system
*/
_gdk_windowing_init ();
/* Do any setup particular to the windowing system */
gdk_display_manager_get ();
}
@ -340,10 +339,6 @@ gdk_display_open_default_libgtk_only (void)
display = gdk_display_open (_gdk_display_name);
}
if (display)
gdk_display_manager_set_default_display (gdk_display_manager_get (),
display);
return display;
}

View File

@ -272,8 +272,6 @@ gdk_display_opened (GdkDisplay *display)
static void
gdk_display_init (GdkDisplay *display)
{
_gdk_displays = g_slist_prepend (_gdk_displays, display);
display->double_click_time = 250;
display->double_click_distance = 5;
@ -306,18 +304,6 @@ gdk_display_dispose (GObject *object)
display->queued_events = NULL;
display->queued_tail = NULL;
_gdk_displays = g_slist_remove (_gdk_displays, object);
if (gdk_display_get_default () == display)
{
if (_gdk_displays)
gdk_display_manager_set_default_display (gdk_display_manager_get(),
_gdk_displays->data);
else
gdk_display_manager_set_default_display (gdk_display_manager_get(),
NULL);
}
if (device_manager)
{
/* this is to make it drop devices which may require using the X
@ -609,6 +595,29 @@ gdk_beep (void)
gdk_display_beep (gdk_display_get_default ());
}
/**
* gdk_flush:
*
* Flushes the output buffers of all display connections and waits
* until all requests have been processed.
* This is rarely needed by applications.
*/
void
gdk_flush (void)
{
GSList *list, *l;
list = gdk_display_manager_list_displays (gdk_display_manager_get ());
for (l = list; l; l = l->next)
{
GdkDisplay *display = l->data;
GDK_DISPLAY_GET_CLASS (display)->sync (display);
}
g_slist_free (list);
}
/**
* gdk_event_send_client_message:
* @event: the #GdkEvent to send, which should be a #GdkEventClient.
@ -2264,3 +2273,26 @@ gdk_drag_get_protocol_for_display (GdkDisplay *display,
{
return GDK_DISPLAY_GET_CLASS (display)->get_drag_protocol (display, xid, protocol, NULL);
}
/**
* gdk_display_open:
* @display_name: the name of the display to open
*
* Opens a display.
*
* Return value: (transfer none): a #GdkDisplay, or %NULL if the display
* could not be opened.
*
* Since: 2.2
*/
GdkDisplay *
gdk_display_open (const gchar *display_name)
{
return gdk_display_manager_open_display (gdk_display_manager_get (), display_name);
}
gboolean
gdk_display_has_pending (GdkDisplay *display)
{
return GDK_DISPLAY_GET_CLASS (display)->has_pending (display);
}

View File

@ -228,6 +228,7 @@ GdkEvent* gdk_display_get_event (GdkDisplay *display);
GdkEvent* gdk_display_peek_event (GdkDisplay *display);
void gdk_display_put_event (GdkDisplay *display,
const GdkEvent *event);
gboolean gdk_display_has_pending (GdkDisplay *display);
void gdk_display_add_client_message_filter (GdkDisplay *display,
GdkAtom message_type,

View File

@ -26,6 +26,7 @@
#include "config.h"
#include "gdkconfig.h"
#include "gdkdisplaymanager.h"
#include "gdkscreen.h"
@ -68,8 +69,6 @@ static void gdk_display_manager_get_property (GObject *object,
static guint signals[LAST_SIGNAL] = { 0 };
static GdkDisplay *default_display = NULL;
G_DEFINE_TYPE (GdkDisplayManager, gdk_display_manager, G_TYPE_OBJECT)
static void
@ -82,10 +81,10 @@ gdk_display_manager_class_init (GdkDisplayManagerClass *klass)
/**
* GdkDisplayManager::display-opened:
* @display_manager: the object on which the signal is emitted
* @manager: the object on which the signal is emitted
* @display: the opened display
*
* The ::display_opened signal is emitted when a display is opened.
* The ::display-opened signal is emitted when a display is opened.
*
* Since: 2.2
*/
@ -142,7 +141,8 @@ gdk_display_manager_get_property (GObject *object,
switch (prop_id)
{
case PROP_DEFAULT_DISPLAY:
g_value_set_object (value, default_display);
g_value_set_object (value,
gdk_display_manager_get_default_display (GDK_DISPLAY_MANAGER (object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -150,42 +150,60 @@ gdk_display_manager_get_property (GObject *object,
}
}
#ifdef GDK_WINDOWING_X11
extern GType gdk_display_manager_x11_get_type (void);
#endif
/**
* gdk_display_manager_get:
*
* Gets the singleton #GdkDisplayManager object.
*
* Returns: (transfer none): The global #GdkDisplayManager singleton; gdk_parse_pargs(),
* gdk_init(), or gdk_init_check() must have been called first.
* Returns: (transfer none): The global #GdkDisplayManager singleton;
* gdk_parse_pargs(), gdk_init(), or gdk_init_check() must have
* been called first.
*
* Since: 2.2
**/
GdkDisplayManager*
gdk_display_manager_get (void)
{
static GdkDisplayManager *display_manager = NULL;
static GdkDisplayManager *manager = NULL;
if (!display_manager)
display_manager = g_object_new (GDK_TYPE_DISPLAY_MANAGER, NULL);
if (!manager)
{
const gchar *backend;
return display_manager;
backend = g_getenv ("GDK_BACKEND");
#ifdef GDK_WINDOWING_X11
if (backend == NULL || strcmp (backend, "x11") == 0)
manager = g_object_new (gdk_display_manager_x11_get_type (), NULL);
else
#endif
if (backend != NULL)
g_error ("Unsupported GDK backend: %s", backend);
else
g_error ("No GDK backend found");
}
return manager;
}
/**
* gdk_display_manager_get_default_display:
* @display_manager: a #GdkDisplayManager
* @manager: a #GdkDisplayManager
*
* Gets the default #GdkDisplay.
*
* Returns: (transfer none): a #GdkDisplay, or %NULL if there is no default
* display.
* Returns: (transfer none): a #GdkDisplay, or %NULL
* if there is no default display.
*
* Since: 2.2
*/
GdkDisplay *
gdk_display_manager_get_default_display (GdkDisplayManager *display_manager)
gdk_display_manager_get_default_display (GdkDisplayManager *manager)
{
return default_display;
return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_default_display (manager);
}
/**
@ -203,7 +221,7 @@ gdk_display_manager_get_default_display (GdkDisplayManager *display_manager)
GdkDisplay *
gdk_display_get_default (void)
{
return default_display;
return gdk_display_manager_get_default_display (gdk_display_manager_get ());
}
/**
@ -219,6 +237,10 @@ gdk_display_get_default (void)
GdkScreen *
gdk_screen_get_default (void)
{
GdkDisplay *default_display;
default_display = gdk_display_get_default ();
if (default_display)
return gdk_display_get_default_screen (default_display);
else
@ -227,7 +249,7 @@ gdk_screen_get_default (void)
/**
* gdk_display_manager_set_default_display:
* @display_manager: a #GdkDisplayManager
* @manager: a #GdkDisplayManager
* @display: a #GdkDisplay
*
* Sets @display as the default display.
@ -235,30 +257,35 @@ gdk_screen_get_default (void)
* Since: 2.2
**/
void
gdk_display_manager_set_default_display (GdkDisplayManager *display_manager,
gdk_display_manager_set_default_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
default_display = display;
GDK_DISPLAY_MANAGER_GET_CLASS (manager)->set_default_display (manager, display);
_gdk_windowing_set_default_display (display);
g_object_notify (G_OBJECT (display_manager), "default-display");
g_object_notify (G_OBJECT (manager), "default-display");
}
/**
* gdk_display_manager_list_displays:
* @display_manager: a #GdkDisplayManager
* @manager: a #GdkDisplayManager
*
* List all currently open displays.
*
* Return value: (transfer container) (element-type GdkDisplay): a newly allocated
* #GSList of #GdkDisplay objects. Free this list with g_slist_free() when you
* are done with it.
* Return value: (transfer container) (element-type GdkDisplay): a newly
* allocated #GSList of #GdkDisplay objects. Free with g_slist_free()
* when you are done with it.
*
* Since: 2.2
**/
GSList *
gdk_display_manager_list_displays (GdkDisplayManager *display_manager)
gdk_display_manager_list_displays (GdkDisplayManager *manager)
{
return g_slist_copy (_gdk_displays);
return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->list_displays (manager);
}
GdkDisplay *
gdk_display_manager_open_display (GdkDisplayManager *manager,
const gchar *name)
{
return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->open_display (manager, name);
}

View File

@ -44,29 +44,17 @@ G_BEGIN_DECLS
#define GDK_IS_DISPLAY_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_DISPLAY_MANAGER))
#define GDK_DISPLAY_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_DISPLAY_MANAGER, GdkDisplayManagerClass))
typedef struct _GdkDisplayManager GdkDisplayManager;
typedef struct _GdkDisplayManagerClass GdkDisplayManagerClass;
struct _GdkDisplayManager
{
GObject parent_instance;
};
struct _GdkDisplayManagerClass
{
GObjectClass parent_class;
void (*display_opened) (GdkDisplayManager *display_manager,
GdkDisplay *display);
};
GType gdk_display_manager_get_type (void) G_GNUC_CONST;
GdkDisplayManager *gdk_display_manager_get (void);
GdkDisplay * gdk_display_manager_get_default_display (GdkDisplayManager *display_manager);
void gdk_display_manager_set_default_display (GdkDisplayManager *display_manager,
GdkDisplay * gdk_display_manager_get_default_display (GdkDisplayManager *manager);
void gdk_display_manager_set_default_display (GdkDisplayManager *manager,
GdkDisplay *display);
GSList * gdk_display_manager_list_displays (GdkDisplayManager *display_manager);
GSList * gdk_display_manager_list_displays (GdkDisplayManager *manager);
GdkDisplay * gdk_display_manager_open_display (GdkDisplayManager *manager,
const gchar *name);
G_END_DECLS

View File

@ -276,6 +276,45 @@ gdk_event_handler_set (GdkEventFunc func,
_gdk_event_notify = notify;
}
/**
* gdk_events_pending:
*
* Checks if any events are ready to be processed for any display.
*
* Return value: %TRUE if any events are pending.
*/
gboolean
gdk_events_pending (void)
{
GSList *list, *l;
gboolean pending;
pending = FALSE;
list = gdk_display_manager_list_displays (gdk_display_manager_get ());
for (l = list; l; l = l->next)
{
if (_gdk_event_queue_find_first (l->data))
{
pending = TRUE;
goto out;
}
}
for (l = list; l; l = l->next)
{
if (gdk_display_has_pending (l->data))
{
pending = TRUE;
goto out;
}
}
out:
g_slist_free (list);
return pending;
}
/**
* gdk_event_get:
*
@ -289,16 +328,21 @@ gdk_event_handler_set (GdkEventFunc func,
GdkEvent*
gdk_event_get (void)
{
GSList *tmp_list;
GSList *list, *l;
GdkEvent *event;
for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
event = NULL;
list = gdk_display_manager_list_displays (gdk_display_manager_get ());
for (l = list; l; l = l->next)
{
GdkEvent *event = gdk_display_get_event (tmp_list->data);
event = gdk_display_get_event (l->data);
if (event)
return event;
break;
}
return NULL;
g_slist_free (list);
return event;
}
/**
@ -314,16 +358,21 @@ gdk_event_get (void)
GdkEvent*
gdk_event_peek (void)
{
GSList *tmp_list;
GSList *list, *l;
GdkEvent *event;
for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
event = NULL;
list = gdk_display_manager_list_displays (gdk_display_manager_get ());
for (l = list; l; l = l->next)
{
GdkEvent *event = gdk_display_peek_event (tmp_list->data);
event = gdk_display_peek_event (l->data);
if (event)
return event;
break;
}
return NULL;
g_slist_free (list);
return event;
}
/**

View File

@ -40,4 +40,3 @@ gchar *_gdk_display_arg_name = NULL;
gboolean _gdk_native_windows = FALSE;
gboolean _gdk_disable_multidevice = FALSE;
GSList *_gdk_displays = NULL;

View File

@ -269,6 +269,27 @@ struct _GdkWindow
#define GDK_WINDOW_TYPE(d) (((GDK_WINDOW (d)))->window_type)
#define GDK_WINDOW_DESTROYED(d) (GDK_WINDOW (d)->destroyed)
struct _GdkDisplayManager
{
GObject parent_instance;
};
struct _GdkDisplayManagerClass
{
GObjectClass parent_class;
GSList * (*list_displays) (GdkDisplayManager *manager);
GdkDisplay * (*get_default_display) (GdkDisplayManager *manager);
void (*set_default_display) (GdkDisplayManager *manager,
GdkDisplay *display);
GdkDisplay * (*open_display) (GdkDisplayManager *manager,
const gchar *name);
/* signals */
void (*display_opened) (GdkDisplayManager *manager,
GdkDisplay *display);
};
struct _GdkDisplayClass
{
GObjectClass parent_class;
@ -281,6 +302,7 @@ struct _GdkDisplayClass
void (*beep) (GdkDisplay *display);
void (*sync) (GdkDisplay *display);
void (*flush) (GdkDisplay *display);
gboolean (*has_pending) (GdkDisplay *display);
GdkWindow * (*get_default_group) (GdkDisplay *display);
gboolean (*supports_selection_notification) (GdkDisplay *display);
gboolean (*request_selection_notification) (GdkDisplay *display,
@ -530,7 +552,6 @@ struct _GdkDeviceManagerClass
GdkDevice * (* get_client_pointer) (GdkDeviceManager *device_manager);
};
extern GSList *_gdk_displays;
extern gchar *_gdk_display_name;
extern gint _gdk_screen_number;
extern gchar *_gdk_display_arg_name;

View File

@ -132,13 +132,6 @@ void gdk_beep (void);
#endif /* GDK_MULTIHEAD_SAFE */
/**
* gdk_flush:
*
* Flushes the X output buffer and waits until all requests have been processed
* by the server. This is rarely needed by applications. It's main use is for
* trapping X errors with gdk_error_trap_push() and gdk_error_trap_pop().
*/
void gdk_flush (void);
G_END_DECLS

View File

@ -139,14 +139,10 @@ typedef struct _GdkRGBA GdkRGBA;
typedef struct _GdkCursor GdkCursor;
typedef struct _GdkVisual GdkVisual;
/**
* GdkWindow:
*
* An opaque structure representing an onscreen drawable.
*/
typedef struct _GdkWindow GdkWindow;
typedef struct _GdkDisplayManager GdkDisplayManager;
typedef struct _GdkDisplay GdkDisplay;
typedef struct _GdkScreen GdkScreen;
typedef struct _GdkWindow GdkWindow;
typedef struct GdkAppLaunchContext GdkAppLaunchContext;
/**

View File

@ -188,15 +188,6 @@ gdk_display_beep (GdkDisplay *display)
Beep(1000, 50);
}
void
_gdk_windowing_exit (void)
{
_gdk_win32_dnd_exit ();
CoUninitialize ();
DeleteDC (_gdk_display_hdc);
_gdk_display_hdc = NULL;
}
void
gdk_error_trap_push (void)
{

View File

@ -27,6 +27,7 @@ libgdk_x11_la_SOURCES = \
gdkdevicemanager-core.h \
gdkdevicemanager-core.c \
gdkdevicemanager-x11.c \
gdkdisplaymanager-x11.c \
gdkdisplay-x11.c \
gdkdisplay-x11.h \
gdkdnd-x11.c \

View File

@ -165,6 +165,8 @@ G_DEFINE_TYPE_WITH_CODE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY,
static void
_gdk_display_x11_init (GdkDisplayX11 *display)
{
_gdk_x11_display_manager_add_display (gdk_display_manager_get (),
GDK_DISPLAY_OBJECT (display));
}
static void
@ -1090,7 +1092,7 @@ gdk_wm_protocols_filter (GdkXEvent *xev,
}
static void
_gdk_event_init (GdkDisplay *display)
gdk_event_init (GdkDisplay *display)
{
GdkDisplayX11 *display_x11;
GdkDeviceManager *device_manager;
@ -1112,7 +1114,7 @@ _gdk_event_init (GdkDisplay *display)
}
static void
_gdk_input_init (GdkDisplay *display)
gdk_input_init (GdkDisplay *display)
{
GdkDisplayX11 *display_x11;
GdkDeviceManager *device_manager;
@ -1175,7 +1177,7 @@ _gdk_input_init (GdkDisplay *display)
* Since: 2.2
*/
GdkDisplay *
gdk_display_open (const gchar *display_name)
_gdk_x11_display_open (const gchar *display_name)
{
Display *xdisplay;
GdkDisplay *display;
@ -1240,7 +1242,7 @@ gdk_display_open (const gchar *display_name)
display->device_manager = _gdk_device_manager_new (display);
_gdk_event_init (display);
gdk_event_init (display);
attr.window_type = GDK_WINDOW_TOPLEVEL;
attr.wclass = GDK_INPUT_OUTPUT;
@ -1424,7 +1426,7 @@ gdk_display_open (const gchar *display_name)
}
#endif
_gdk_input_init (display);
gdk_input_init (display);
_gdk_x11_dnd_init (display);
for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
@ -1520,16 +1522,12 @@ gdk_internal_connection_watch (Display *display,
static G_CONST_RETURN gchar *
gdk_x11_display_get_name (GdkDisplay *display)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
}
static gint
gdk_x11_display_get_n_screens (GdkDisplay *display)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
}
@ -1537,7 +1535,6 @@ static GdkScreen *
gdk_x11_display_get_screen (GdkDisplay *display,
gint screen_num)
{
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];
@ -1546,8 +1543,6 @@ gdk_x11_display_get_screen (GdkDisplay *display,
static GdkScreen *
gdk_x11_display_get_default_screen (GdkDisplay *display)
{
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
return GDK_DISPLAY_X11 (display)->default_screen;
}
@ -1558,8 +1553,6 @@ _gdk_x11_display_is_root_window (GdkDisplay *display,
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++)
@ -1617,8 +1610,6 @@ _gdk_x11_display_update_grab_info_ungrab (GdkDisplay *display,
static void
gdk_x11_display_beep (GdkDisplay *display)
{
g_return_if_fail (GDK_IS_DISPLAY (display));
#ifdef HAVE_XKB
XkbBell (GDK_DISPLAY_XDISPLAY (display), None, 0, None);
#else
@ -1629,20 +1620,22 @@ gdk_x11_display_beep (GdkDisplay *display)
static void
gdk_x11_display_sync (GdkDisplay *display)
{
g_return_if_fail (GDK_IS_DISPLAY (display));
XSync (GDK_DISPLAY_XDISPLAY (display), False);
}
static void
gdk_x11_display_flush (GdkDisplay *display)
{
g_return_if_fail (GDK_IS_DISPLAY (display));
if (!display->closed)
XFlush (GDK_DISPLAY_XDISPLAY (display));
}
static gboolean
gdk_x11_display_has_pending (GdkDisplay *display)
{
return XPending (GDK_DISPLAY_XDISPLAY (display));
}
static GdkWindow *
gdk_x11_display_get_default_group (GdkDisplay *display)
{
@ -1706,9 +1699,12 @@ gdk_x11_display_ungrab (GdkDisplay *display)
static void
gdk_display_x11_dispose (GObject *object)
{
GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
gint i;
_gdk_x11_display_manager_remove_display (gdk_display_manager_get (), display);
g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);
for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
@ -1810,15 +1806,25 @@ gdk_display_x11_finalize (GObject *object)
GdkDisplay *
gdk_x11_lookup_xdisplay (Display *xdisplay)
{
GSList *tmp_list;
GSList *list, *l;
GdkDisplay *display;
for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
display = NULL;
list = gdk_display_manager_list_displays (gdk_display_manager_get ());
for (l = list; l; l = l->next)
{
if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
return tmp_list->data;
if (GDK_DISPLAY_XDISPLAY (l->data) == xdisplay)
{
display = l->data;
break;
}
}
return NULL;
g_slist_free (list);
return display;
}
/**
@ -1864,14 +1870,11 @@ gdk_x11_display_get_xdisplay (GdkDisplay *display)
}
void
_gdk_windowing_set_default_display (GdkDisplay *display)
_gdk_x11_display_make_default (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;
@ -2367,35 +2370,6 @@ gdk_x11_display_add_client_message_filter (GdkDisplay *display,
filter);
}
/*
*--------------------------------------------------------------
* 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
@ -2707,6 +2681,7 @@ _gdk_display_x11_class_init (GdkDisplayX11Class * class)
display_class->beep = gdk_x11_display_beep;
display_class->sync = gdk_x11_display_sync;
display_class->flush = gdk_x11_display_flush;
display_class->has_pending = gdk_x11_display_has_pending;
display_class->get_default_group = gdk_x11_display_get_default_group;
display_class->supports_selection_notification = gdk_x11_display_supports_selection_notification;
display_class->request_selection_notification = gdk_x11_display_request_selection_notification;

View File

@ -0,0 +1,134 @@
/* GDK - The GIMP Drawing Kit
* gdkdisplaymanager-x11.c
*
* Copyright 2010 Red Hat, Inc.
*
* Author: Matthias clasen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "gdkdisplay-x11.h"
#include "gdkprivate-x11.h"
#include "gdkdisplaymanager.h"
#include "gdkinternals.h"
#define GDK_TYPE_DISPLAY_MANAGER_X11 (gdk_display_manager_x11_get_type ())
#define GDK_DISPLAY_MANAGER_X11(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_DISPLAY_MANAGER_X11, GdkDisplayManagerX11))
typedef struct _GdkDisplayManagerX11 GdkDisplayManagerX11;
typedef struct _GdkDisplayManagerClass GdkDisplayManagerX11Class;
struct _GdkDisplayManagerX11
{
GdkDisplayManager parent;
GdkDisplay *default_display;
GSList *displays;
};
G_DEFINE_TYPE (GdkDisplayManagerX11, gdk_display_manager_x11, GDK_TYPE_DISPLAY_MANAGER)
static GdkDisplay *
gdk_display_manager_x11_open_display (GdkDisplayManager *manager,
const gchar *name)
{
return _gdk_x11_display_open (name);
}
static GSList *
gdk_display_manager_x11_list_displays (GdkDisplayManager *manager)
{
GdkDisplayManagerX11 *manager_x11 = GDK_DISPLAY_MANAGER_X11 (manager);
return g_slist_copy (manager_x11->displays);
}
static GdkDisplay *
gdk_display_manager_x11_get_default_display (GdkDisplayManager *manager)
{
return GDK_DISPLAY_MANAGER_X11 (manager)->default_display;
}
static void
gdk_display_manager_x11_set_default_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
GdkDisplayManagerX11 *manager_x11 = GDK_DISPLAY_MANAGER_X11 (manager);
manager_x11->default_display = display;
_gdk_x11_display_make_default (display);
}
static void
gdk_display_manager_x11_init (GdkDisplayManagerX11 *manager)
{
_gdk_x11_windowing_init ();
}
static void
gdk_display_manager_x11_finalize (GObject *object)
{
g_error ("A GdkDisplayManagerX11 object was finalized. This should not happen");
G_OBJECT_CLASS (gdk_display_manager_x11_parent_class)->finalize (object);
}
static void
gdk_display_manager_x11_class_init (GdkDisplayManagerX11Class *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GdkDisplayManagerClass *manager_class = GDK_DISPLAY_MANAGER_CLASS (class);
object_class->finalize = gdk_display_manager_x11_finalize;
manager_class->open_display = gdk_display_manager_x11_open_display;
manager_class->list_displays = gdk_display_manager_x11_list_displays;
manager_class->set_default_display = gdk_display_manager_x11_set_default_display;
manager_class->get_default_display = gdk_display_manager_x11_get_default_display;
}
void
_gdk_x11_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
GdkDisplayManagerX11 *manager_x11 = GDK_DISPLAY_MANAGER_X11 (manager);
if (manager_x11->displays == NULL)
gdk_display_manager_set_default_display (manager, display);
manager_x11->displays = g_slist_prepend (manager_x11->displays, display);
}
void
_gdk_x11_display_manager_remove_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
GdkDisplayManagerX11 *manager_x11 = GDK_DISPLAY_MANAGER_X11 (manager);
manager_x11->displays = g_slist_remove (manager_x11->displays, display);
if (manager_x11->default_display == display)
{
if (manager_x11->displays)
gdk_display_manager_set_default_display (manager, manager_x11->displays->data);
else
gdk_display_manager_set_default_display (manager, NULL);
}
}

View File

@ -414,36 +414,3 @@ gdk_event_source_select_events (GdkEventSource *source,
XSelectInput (GDK_DISPLAY_XDISPLAY (source->display), window, xmask);
}
/**
* gdk_events_pending:
*
* Checks if any events are ready to be processed for any display.
*
* Return value: %TRUE if any events are pending.
**/
gboolean
gdk_events_pending (void)
{
GList *tmp_list;
for (tmp_list = event_sources; tmp_list; tmp_list = tmp_list->next)
{
GdkEventSource *tmp_source = tmp_list->data;
GdkDisplay *display = tmp_source->display;
if (_gdk_event_queue_find_first (display))
return TRUE;
}
for (tmp_list = event_sources; tmp_list; tmp_list = tmp_list->next)
{
GdkEventSource *tmp_source = tmp_list->data;
GdkDisplay *display = tmp_source->display;
if (gdk_check_xpending (display))
return TRUE;
}
return FALSE;
}

View File

@ -96,7 +96,7 @@ const GOptionEntry _gdk_windowing_args[] = {
};
void
_gdk_windowing_init (void)
_gdk_x11_windowing_init (void)
{
_gdk_x11_initialize_locale ();
@ -224,21 +224,6 @@ _gdk_windowing_display_set_sm_client_id (GdkDisplay *display,
gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
}
/* Close all open displays
*/
void
_gdk_windowing_exit (void)
{
GSList *tmp_list = _gdk_displays;
while (tmp_list)
{
XCloseDisplay (GDK_DISPLAY_XDISPLAY (tmp_list->data));
tmp_list = tmp_list->next;
}
}
/*
*--------------------------------------------------------------
* gdk_x_io_error

View File

@ -131,6 +131,7 @@ gboolean _gdk_keymap_key_is_modifier (GdkKeymap *keymap,
guint keycode);
void _gdk_x11_initialize_locale (void);
void _gdk_x11_windowing_init (void);
void _gdk_xgrab_check_unmap (GdkWindow *window,
gulong serial);
@ -139,6 +140,8 @@ void _gdk_xgrab_check_destroy (GdkWindow *window);
gboolean _gdk_x11_display_is_root_window (GdkDisplay *display,
Window xroot_window);
GdkDisplay * _gdk_x11_display_open (const gchar *display_name);
void _gdk_x11_display_make_default (GdkDisplay *display);
void _gdk_x11_display_update_grab_info (GdkDisplay *display,
GdkDevice *device,
gint status);
@ -148,6 +151,11 @@ void _gdk_x11_display_update_grab_info_ungrab (GdkDisplay *display,
gulong serial);
void _gdk_x11_device_check_extension_events (GdkDevice *device);
void _gdk_x11_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display);
void _gdk_x11_display_manager_remove_display (GdkDisplayManager *manager,
GdkDisplay *display);
void _gdk_x11_precache_atoms (GdkDisplay *display,
const gchar * const *atom_names,
gint n_atoms);