diff options
-rw-r--r-- | gdk/gdk.c | 27 | ||||
-rw-r--r-- | gdk/gdkdisplay.c | 60 | ||||
-rw-r--r-- | gdk/gdkdisplay.h | 3 | ||||
-rw-r--r-- | gdk/gdkdisplaymanager.c | 147 | ||||
-rw-r--r-- | gdk/gdkdisplaymanager.h | 26 | ||||
-rw-r--r-- | gdk/gdkevents.c | 69 | ||||
-rw-r--r-- | gdk/gdkglobals.c | 1 | ||||
-rw-r--r-- | gdk/gdkinternals.h | 23 | ||||
-rw-r--r-- | gdk/gdkmain.h | 7 | ||||
-rw-r--r-- | gdk/gdktypes.h | 8 | ||||
-rw-r--r-- | gdk/win32/gdkmain-win32.c | 9 | ||||
-rw-r--r-- | gdk/x11/Makefile.am | 1 | ||||
-rw-r--r-- | gdk/x11/gdkdisplay-x11.c | 109 | ||||
-rw-r--r-- | gdk/x11/gdkdisplaymanager-x11.c | 134 | ||||
-rw-r--r-- | gdk/x11/gdkeventsource.c | 33 | ||||
-rw-r--r-- | gdk/x11/gdkmain-x11.c | 17 | ||||
-rw-r--r-- | gdk/x11/gdkprivate-x11.h | 8 |
17 files changed, 422 insertions, 260 deletions
@@ -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 (); } @@ -262,13 +261,13 @@ gdk_parse_args (int *argc, return; gdk_pre_parse_libgtk_only (); - + option_context = g_option_context_new (NULL); g_option_context_set_ignore_unknown_options (option_context, TRUE); g_option_context_set_help_enabled (option_context, FALSE); option_group = g_option_group_new (NULL, NULL, NULL, NULL, NULL); g_option_context_set_main_group (option_context, option_group); - + g_option_group_add_entries (option_group, gdk_args); g_option_group_add_entries (option_group, _gdk_windowing_args); @@ -282,7 +281,7 @@ gdk_parse_args (int *argc, GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ())); } -/** +/** * gdk_get_display_arg_name: * * Gets the display name specified in the command line arguments passed @@ -309,13 +308,13 @@ gdk_get_display_arg_name (void) /** * gdk_display_open_default_libgtk_only: - * + * * Opens the default display specified by command line arguments or * environment variables, sets it as the default display, and returns * it. gdk_parse_args must have been called first. If the default * display has previously been set, simply returns that. An internal * function that should not be used by applications. - * + * * Return value: (transfer none): the default display, if it could be * opened, otherwise %NULL. **/ @@ -325,7 +324,7 @@ gdk_display_open_default_libgtk_only (void) GdkDisplay *display; g_return_val_if_fail (gdk_initialized, NULL); - + display = gdk_display_get_default (); if (display) return display; @@ -336,14 +335,10 @@ gdk_display_open_default_libgtk_only (void) { g_free (_gdk_display_arg_name); _gdk_display_arg_name = g_strdup (_gdk_display_name); - + display = gdk_display_open (_gdk_display_name); } - - if (display) - gdk_display_manager_set_default_display (gdk_display_manager_get (), - display); - + return display; } @@ -365,7 +360,7 @@ gdk_display_open_default_libgtk_only (void) */ gboolean gdk_init_check (int *argc, - char ***argv) + char ***argv) { gdk_parse_args (argc, argv); diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c index fbaf43897a..157e5ef0b1 100644 --- a/gdk/gdkdisplay.c +++ b/gdk/gdkdisplay.c @@ -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 @@ -610,6 +596,29 @@ gdk_beep (void) } /** + * 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. * @winid: the window to send the X ClientMessage event to. @@ -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); +} diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h index 0da46083f7..97ab5b32a6 100644 --- a/gdk/gdkdisplay.h +++ b/gdk/gdkdisplay.h @@ -227,7 +227,8 @@ GList * gdk_display_list_devices (GdkDisplay *display); GdkEvent* gdk_display_get_event (GdkDisplay *display); GdkEvent* gdk_display_peek_event (GdkDisplay *display); void gdk_display_put_event (GdkDisplay *display, - const GdkEvent *event); + const GdkEvent *event); +gboolean gdk_display_has_pending (GdkDisplay *display); void gdk_display_add_client_message_filter (GdkDisplay *display, GdkAtom message_type, diff --git a/gdk/gdkdisplaymanager.c b/gdk/gdkdisplaymanager.c index ec975f26fa..c5653967cd 100644 --- a/gdk/gdkdisplaymanager.c +++ b/gdk/gdkdisplaymanager.c @@ -21,11 +21,12 @@ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "config.h" +#include "gdkconfig.h" #include "gdkdisplaymanager.h" #include "gdkscreen.h" @@ -58,18 +59,16 @@ enum { static void gdk_display_manager_class_init (GdkDisplayManagerClass *klass); static void gdk_display_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); + guint prop_id, + const GValue *value, + GParamSpec *pspec); static void gdk_display_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); + guint prop_id, + GValue *value, + GParamSpec *pspec); static guint signals[LAST_SIGNAL] = { 0 }; -static GdkDisplay *default_display = NULL; - G_DEFINE_TYPE (GdkDisplayManager, gdk_display_manager, G_TYPE_OBJECT) static void @@ -82,32 +81,32 @@ 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 */ signals[DISPLAY_OPENED] = g_signal_new (g_intern_static_string ("display-opened"), - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GdkDisplayManagerClass, display_opened), - NULL, NULL, - _gdk_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - GDK_TYPE_DISPLAY); + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GdkDisplayManagerClass, display_opened), + NULL, NULL, + _gdk_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + GDK_TYPE_DISPLAY); g_object_class_install_property (object_class, - PROP_DEFAULT_DISPLAY, - g_param_spec_object ("default-display", - P_("Default Display"), - P_("The default display for GDK"), - GDK_TYPE_DISPLAY, - G_PARAM_READWRITE|G_PARAM_STATIC_NAME| - G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)); + PROP_DEFAULT_DISPLAY, + g_param_spec_object ("default-display", + P_("Default Display"), + P_("The default display for GDK"), + GDK_TYPE_DISPLAY, + G_PARAM_READWRITE|G_PARAM_STATIC_NAME| + G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB)); } static void @@ -117,15 +116,15 @@ gdk_display_manager_init (GdkDisplayManager *manager) static void gdk_display_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { switch (prop_id) { case PROP_DEFAULT_DISPLAY: gdk_display_manager_set_default_display (GDK_DISPLAY_MANAGER (object), - g_value_get_object (value)); + g_value_get_object (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -135,14 +134,15 @@ gdk_display_manager_set_property (GObject *object, static void gdk_display_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { 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 (!manager) + { + const gchar *backend; - if (!display_manager) - display_manager = g_object_new (GDK_TYPE_DISPLAY_MANAGER, NULL); + 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 display_manager; + 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, - GdkDisplay *display) +gdk_display_manager_set_default_display (GdkDisplayManager *manager, + GdkDisplay *display) { - default_display = display; - - _gdk_windowing_set_default_display (display); + GDK_DISPLAY_MANAGER_GET_CLASS (manager)->set_default_display (manager, 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 GDK_DISPLAY_MANAGER_GET_CLASS (manager)->list_displays (manager); +} + +GdkDisplay * +gdk_display_manager_open_display (GdkDisplayManager *manager, + const gchar *name) { - return g_slist_copy (_gdk_displays); + return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->open_display (manager, name); } diff --git a/gdk/gdkdisplaymanager.h b/gdk/gdkdisplaymanager.h index 4d5bd989a4..dccca92541 100644 --- a/gdk/gdkdisplaymanager.h +++ b/gdk/gdkdisplaymanager.h @@ -8,7 +8,7 @@ * * 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public @@ -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 *display); -GSList * gdk_display_manager_list_displays (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 *manager); +GdkDisplay * gdk_display_manager_open_display (GdkDisplayManager *manager, + const gchar *name); G_END_DECLS diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index d6322db795..4499d22061 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -277,6 +277,45 @@ gdk_event_handler_set (GdkEventFunc func, } /** + * 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: * * Checks all open displays for a #GdkEvent to process,to be processed @@ -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; } /** diff --git a/gdk/gdkglobals.c b/gdk/gdkglobals.c index 2a572981dc..5af484b93d 100644 --- a/gdk/gdkglobals.c +++ b/gdk/gdkglobals.c @@ -40,4 +40,3 @@ gchar *_gdk_display_arg_name = NULL; gboolean _gdk_native_windows = FALSE; gboolean _gdk_disable_multidevice = FALSE; -GSList *_gdk_displays = NULL; diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h index 5d1944c447..a0dfff8cae 100644 --- a/gdk/gdkinternals.h +++ b/gdk/gdkinternals.h @@ -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; diff --git a/gdk/gdkmain.h b/gdk/gdkmain.h index 2d05590e7a..b9915a3bcf 100644 --- a/gdk/gdkmain.h +++ b/gdk/gdkmain.h @@ -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 diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h index 410cade6d9..e540b657f0 100644 --- a/gdk/gdktypes.h +++ b/gdk/gdktypes.h @@ -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; /** diff --git a/gdk/win32/gdkmain-win32.c b/gdk/win32/gdkmain-win32.c index e07c1ca548..ba04cdee43 100644 --- a/gdk/win32/gdkmain-win32.c +++ b/gdk/win32/gdkmain-win32.c @@ -189,15 +189,6 @@ gdk_display_beep (GdkDisplay *display) } void -_gdk_windowing_exit (void) -{ - _gdk_win32_dnd_exit (); - CoUninitialize (); - DeleteDC (_gdk_display_hdc); - _gdk_display_hdc = NULL; -} - -void gdk_error_trap_push (void) { } diff --git a/gdk/x11/Makefile.am b/gdk/x11/Makefile.am index 30295b42f6..6c07ff4aed 100644 --- a/gdk/x11/Makefile.am +++ b/gdk/x11/Makefile.am @@ -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 \ diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index b750a326a7..01bd04008e 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -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; @@ -1214,7 +1216,7 @@ gdk_display_open (const gchar *display_name) &display_x11->xrandr_event_base, &ignore)) { int major, minor; - + XRRQueryVersion (display_x11->xdisplay, &major, &minor); if ((major == 1 && minor >= 3) || major > 1) @@ -1223,7 +1225,7 @@ gdk_display_open (const gchar *display_name) 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++) @@ -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,17 +1535,14 @@ 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]; } 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; } @@ -1557,11 +1552,9 @@ _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++) { if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window) @@ -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; + + display = NULL; - for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next) + 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,17 +1870,14 @@ 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; - + startup_id = g_getenv ("DESKTOP_STARTUP_ID"); if (startup_id && *startup_id != '\0') { @@ -1882,9 +1885,9 @@ _gdk_windowing_set_default_display (GdkDisplay *display) 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. + * child processes and confuse things. */ g_unsetenv ("DESKTOP_STARTUP_ID"); } @@ -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; diff --git a/gdk/x11/gdkdisplaymanager-x11.c b/gdk/x11/gdkdisplaymanager-x11.c new file mode 100644 index 0000000000..b422975238 --- /dev/null +++ b/gdk/x11/gdkdisplaymanager-x11.c @@ -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); + } +} diff --git a/gdk/x11/gdkeventsource.c b/gdk/x11/gdkeventsource.c index 37275fb183..22cc5b1e5e 100644 --- a/gdk/x11/gdkeventsource.c +++ b/gdk/x11/gdkeventsource.c @@ -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; -} diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c index 5890335c0f..056c90b629 100644 --- a/gdk/x11/gdkmain-x11.c +++ b/gdk/x11/gdkmain-x11.c @@ -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 diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h index 682cc10dd0..e878b5146a 100644 --- a/gdk/x11/gdkprivate-x11.h +++ b/gdk/x11/gdkprivate-x11.h @@ -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); |