GdkLibrary



I've been working on notification for new displays and
for the default display.

To do this, it was easiest to have a global singleton
object with a ::display-opened signal a ::default-display
property; and the following functions:

===
GdkLibrary *gdk_library_get                 (void);
GdkDisplay *gdk_library_get_default_display (GdkLibrary *library);
void        gdk_library_set_default_display (GdkLibrary *library,
					     GdkDisplay *display);
GSList     *gdk_library_list_displays       (GdkLibrary *library);
===

This is basically a resurrection of Erwann's GdkDisplayMgr object,
implemented in a somewhat simpler way.

Questions:

 * Does it make sense to move more functions onto this object;
   possibilities among newly added 2.2 functions would be:

    void gdk_parse_args (...) => GdkLibrary *gdk_library_open (...)
    gdk_get_display_arg_name => gdk_library_get_display_arg_name()
    gdk_open_display () => gdk_library_open_display ()

   The convenience functions gdk_display_get_default() and 
   gdk_screen_get_default()() are important to keep convenient
   since they are used *a lot*. So, I don't see them as candidates.

 * Any suggestions for a better name than GdkLibrary? GdkApplication
   is possible, but brings up sticky questions about "what is an 
   application".

   If we stick to the above API, then GdkDisplayManager wouldn't
   be a horrible name, and certainly describes what it does.
   It would constrain future additions, but are there other
   interesting global notifications? most notifications would
   belong on the GdkDisplay.

   (In really far out land would be the future possibility of 
 
     library1 = gdk_library_open_x11 (...);
     library2 = gdk_library_open_fb (...);

    But that would be a ton of work for a stupid parlor trick.

    In general, I think integrating smoothly with current API
    is more important than integrating smoothly with whacky 
    future ideas.)

Thanks for any feedback,
                                          Owen

   
Index: gdk/gdk.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdk.c,v
retrieving revision 1.141
diff -u -p -u -r1.141 gdk.c
--- gdk/gdk.c	18 Jun 2002 18:35:41 -0000	1.141
+++ gdk/gdk.c	19 Jun 2002 23:08:12 -0000
@@ -399,7 +399,8 @@ gdk_init_check (int    *argc,
 
   if (display)
     {
-      gdk_set_default_display (display);
+      gdk_library_set_default_display (gdk_library_get (),
+				       display);
       return TRUE;
     }
   else
Index: gdk/gdk.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdk.h,v
retrieving revision 1.93
diff -u -p -u -r1.93 gdk.h
--- gdk/gdk.h	25 Apr 2002 22:29:08 -0000	1.93
+++ gdk/gdk.h	19 Jun 2002 23:08:12 -0000
@@ -39,6 +39,7 @@
 #include <gdk/gdkimage.h>
 #include <gdk/gdkinput.h>
 #include <gdk/gdkkeys.h>
+#include <gdk/gdklibrary.h>
 #include <gdk/gdkpango.h>
 #include <gdk/gdkpixbuf.h>
 #include <gdk/gdkpixmap.h>
Index: gdk/gdkdisplay.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkdisplay.c,v
retrieving revision 1.6
diff -u -p -u -r1.6 gdkdisplay.c
--- gdk/gdkdisplay.c	18 Jun 2002 23:23:28 -0000	1.6
+++ gdk/gdkdisplay.c	19 Jun 2002 23:08:12 -0000
@@ -31,8 +31,6 @@ static void gdk_display_class_init (GdkD
 static void gdk_display_init       (GdkDisplay      *display);
 static void gdk_display_finalize   (GObject         *object);
 
-static GdkDisplay *default_display = NULL;
-
 static GObjectClass *parent_class;
 
 GType
@@ -90,8 +88,8 @@ gdk_display_finalize (GObject *object)
   
   _gdk_displays = g_slist_remove (_gdk_displays, display);
 
-  if (default_display == display)
-    default_display = NULL;
+  if (gdk_get_default_display() == display)
+    gdk_library_set_default_display (gdk_library_get(), NULL);
   
   parent_class->finalize (object);
 }
@@ -107,62 +105,6 @@ gdk_display_close (GdkDisplay *display)
 {
   g_return_if_fail (GDK_IS_DISPLAY (display));
   g_object_unref (G_OBJECT (display));
-}
-
-/**
- * gdk_set_default_display:
- * @display: a #GdkDisplay
- * 
- * Sets @display as the default display.
- **/
-void
-gdk_set_default_display (GdkDisplay *display)
-{
-  default_display = display;
-
-  _gdk_windowing_set_default_display (display);
-}
-
-/**
- * gdk_get_default_display:
- *
- * Gets the default #GdkDisplay. 
- * 
- * Returns: a #GdkDisplay, or %NULL if there is no default
- *   display.
- */
-GdkDisplay *
-gdk_get_default_display (void)
-{
-  return default_display;
-}
-
-/**
- * gdk_get_default_screen:
- *
- * Gets the default screen for the default display. (See
- * gdk_get_default_display ()).
- * 
- * Returns: a #GdkScreen.
- */
-GdkScreen *
-gdk_get_default_screen (void)
-{
-  return gdk_display_get_default_screen (gdk_get_default_display ());
-}
-
-/**
- * gdk_list_displays:
- *
- * List all currently open displays.
- * 
- * Return value: a newly allocated #GSList of #GdkDisplay objects.
- *  Free this list with g_slist_free() when you are done with it.
- **/
-GSList *
-gdk_list_displays (void)
-{
-  return g_slist_copy (_gdk_displays);
 }
 
 /**
Index: gdk/gdkdisplay.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkdisplay.h,v
retrieving revision 1.3
diff -u -p -u -r1.3 gdkdisplay.h
--- gdk/gdkdisplay.h	18 Jun 2002 23:23:28 -0000	1.3
+++ gdk/gdkdisplay.h	19 Jun 2002 23:08:12 -0000
@@ -106,7 +106,6 @@ void gdk_display_set_double_click_time (
 void gdk_display_set_sm_client_id      (GdkDisplay  *display,
 					const gchar *sm_client_id);
 
-void        gdk_set_default_display (GdkDisplay *display);
 GdkDisplay *gdk_get_default_display (void);
 
 GdkDevice  *gdk_display_get_core_pointer (GdkDisplay *display);
Index: gdk/gdkinternals.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkinternals.h,v
retrieving revision 1.19
diff -u -p -u -r1.19 gdkinternals.h
--- gdk/gdkinternals.h	18 Jun 2002 23:23:28 -0000	1.19
+++ gdk/gdkinternals.h	19 Jun 2002 23:08:12 -0000
@@ -147,8 +147,8 @@ extern GdkEventFunc   _gdk_event_func;  
 extern gpointer       _gdk_event_data;
 extern GDestroyNotify _gdk_event_notify;
 
-extern GSList    *_gdk_displays;
-extern gchar     *_gdk_display_name;
+extern GSList     *_gdk_displays;
+extern gchar      *_gdk_display_name;
 
 extern const GdkPointerHooks *_gdk_current_pointer_hooks;
 
Index: gdk/gdklibrary.c
===================================================================
RCS file: gdk/gdklibrary.c
diff -N gdk/gdklibrary.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdk/gdklibrary.c	19 Jun 2002 23:08:12 -0000
@@ -0,0 +1,243 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2000 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+/*
+ * 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/. 
+ */
+
+#include <config.h>
+
+#include "gdkdisplay.h"
+#include "gdklibrary.h"
+
+#include "gdkinternals.h"
+
+struct _GdkLibrary
+{
+  GObject parent_instance;
+};
+
+enum {
+  PROP_0,
+
+  PROP_DEFAULT_DISPLAY
+};
+
+enum {
+  DISPLAY_OPENED,
+  LAST_SIGNAL
+};
+
+static void gdk_library_class_init   (GdkLibraryClass *klass);
+static void gdk_library_set_property (GObject         *object,
+				      guint            prop_id,
+				      const GValue    *value,
+				      GParamSpec      *pspec);
+static void gdk_library_get_property (GObject         *object,
+				      guint            prop_id,
+				      GValue          *value,
+				      GParamSpec      *pspec);
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+GdkDisplay *default_display = NULL;
+
+GType
+gdk_library_get_type (void)
+{
+  static GType object_type = 0;
+
+  if (!object_type)
+    {
+      static const GTypeInfo object_info =
+      {
+        sizeof (GdkLibraryClass),
+        (GBaseInitFunc) NULL,
+        (GBaseFinalizeFunc) NULL,
+        (GClassInitFunc) gdk_library_class_init,
+        NULL,           /* class_finalize */
+        NULL,           /* class_data */
+        sizeof (GdkLibrary),
+        0,              /* n_preallocs */
+        (GInstanceInitFunc) NULL,
+      };
+      
+      object_type = g_type_register_static (G_TYPE_OBJECT,
+                                            "GdkLibrary",
+                                            &object_info, 0);
+    }
+  
+  return object_type;
+}
+
+static void
+gdk_library_class_init (GdkLibraryClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  signals[DISPLAY_OPENED] =
+    g_signal_new ("display_opened",
+		  G_OBJECT_CLASS_TYPE (object_class),
+		  G_SIGNAL_RUN_LAST,
+		  G_STRUCT_OFFSET (GdkLibraryClass, display_opened),
+		  NULL, NULL,
+		  g_cclosure_marshal_VOID__VOID,
+		  G_TYPE_NONE,
+		  1,
+		  GDK_TYPE_DISPLAY);
+
+  object_class->set_property = gdk_library_set_property;
+  object_class->get_property = gdk_library_get_property;
+}
+
+static void
+gdk_library_set_property (GObject      *object,
+			  guint         prop_id,
+			  const GValue *value,
+			  GParamSpec   *pspec)
+{
+  switch (prop_id)
+    {
+    case PROP_DEFAULT_DISPLAY:
+      default_display = g_value_get_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gdk_library_get_property (GObject      *object,
+			  guint         prop_id,
+			  GValue       *value,
+			  GParamSpec   *pspec)
+{
+  switch (prop_id)
+    {
+    case PROP_DEFAULT_DISPLAY:
+      g_value_set_object (value, default_display);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+/** 
+ * gdk_library_get:
+ * @returns: the singleton #GdkLibrary object.
+ *
+ * Returns the global #GdkLibrary singleton; gdk_parse_pargs(),
+ * gdk_init(), or gdk_init_check() must have been called first.
+ **/
+GdkLibrary*
+gdk_library_get (void)
+{
+  static GdkLibrary *library = NULL;
+
+  if (!library)
+    library = g_object_new (GDK_TYPE_LIBRARY, NULL);
+
+  return library;
+}
+
+/**
+ * gdk_library_get_default_display:
+ *
+ * Gets the default #GdkDisplay. This is a convenience
+ * function for:
+ * <programlisting>
+ *   gdk_library_get_default_display (gdk_library_get ())
+ * </programlisting>
+ * 
+ * Returns: a #GdkDisplay, or %NULL if there is no default
+ *   display.
+ */
+GdkDisplay *
+gdk_library_get_default_display (GdkLibrary *library)
+{
+  return default_display;
+}
+
+/**
+ * gdk_get_default_display:
+ *
+ * Gets the default #GdkDisplay. This is a convenience
+ * function for:
+ * <programlisting>
+ *   gdk_library_get_default_display (gdk_library_get ())
+ * </programlisting>
+ * 
+ * Returns: a #GdkDisplay, or %NULL if there is no default
+ *   display.
+ */
+GdkDisplay *
+gdk_get_default_display (void)
+{
+  return default_display;
+}
+
+/**
+ * gdk_get_default_screen:
+ *
+ * Gets the default screen for the default display. (See
+ * gdk_get_default_display ()).
+ * 
+ * Returns: a #GdkScreen.
+ */
+GdkScreen *
+gdk_get_default_screen (void)
+{
+  return gdk_display_get_default_screen (default_display);
+}
+
+/**
+ * gdk_library_set_default_display:
+ * @display: a #GdkDisplay
+ * 
+ * Sets @display as the default display.
+ **/
+void
+gdk_library_set_default_display (GdkLibrary *library,
+				 GdkDisplay *display)
+{
+  default_display = display;
+
+  _gdk_windowing_set_default_display (display);
+
+  g_object_notify (G_OBJECT (library), "default_display");
+}
+
+/**
+ * gdk_library_list_displays:
+ *
+ * List all currently open displays.
+ * 
+ * Return value: a newly allocated #GSList of #GdkDisplay objects.
+ *  Free this list with g_slist_free() when you are done with it.
+ **/
+GSList *
+gdk_library_list_displays (GdkLibrary *library)
+{
+  return g_slist_copy (_gdk_displays);
+}
Index: gdk/gdklibrary.h
===================================================================
RCS file: gdk/gdklibrary.h
diff -N gdk/gdklibrary.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdk/gdklibrary.h	19 Jun 2002 23:08:12 -0000
@@ -0,0 +1,63 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2000 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+/*
+ * 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/.
+ */
+
+#ifndef __GDK_LIBRARY_H__
+#define __GDK_LIBRARY_H__
+
+#include <gdk/gdktypes.h>
+#include <gdk/gdkdisplay.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GdkLibrary      GdkLibrary;
+typedef struct _GdkLibraryClass GdkLibraryClass;
+
+#define GDK_TYPE_LIBRARY              (gdk_library_get_type ())
+#define GDK_LIBRARY(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_LIBRARY, GdkLibrary))
+#define GDK_LIBRARY_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_LIBRARY, GdkLibraryClass))
+#define GDK_IS_LIBRARY(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_LIBRARY))
+#define GDK_IS_LIBRARY_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_LIBRARY))
+#define GDK_LIBRARY_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_LIBRARY, GdkLibraryClass))
+
+struct _GdkLibraryClass
+{
+  GObjectClass parent_class;
+
+  void (*display_opened) (GdkLibrary *library,
+			  GdkDisplay *display);
+};
+
+GType       gdk_library_get_type (void) G_GNUC_CONST;
+
+GdkLibrary *gdk_library_get                 (void);
+GdkDisplay *gdk_library_get_default_display (GdkLibrary *library);
+void        gdk_library_set_default_display (GdkLibrary *library,
+					     GdkDisplay *display);
+GSList     *gdk_library_list_displays       (GdkLibrary *library);
+
+G_END_DECLS
+
+#endif /* __GDK_LIBRARY_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]