]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdk.c
only count the special cell if it is also visible,
[~andy/gtk] / gdk / gdk.c
index bca94582f6e3865b5c04034f620a82ea2af64f9c..87d12ea46931ef4d0908544cdc61611d59d416f8 100644 (file)
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -50,9 +50,9 @@ static int gdk_initialized = 0;                           /* 1 if the library is initialized,
                                                     * 0 otherwise.
                                                     */
 
-static GSList *gdk_error_trap_free_list = NULL;      /* Free list */
-
 static gchar  *gdk_progclass = NULL;
+static gint    gdk_argc = 0;
+static gchar **gdk_argv = NULL;
 
 #ifdef G_ENABLE_DEBUG
 static const GDebugKey gdk_debug_keys[] = {
@@ -61,9 +61,17 @@ static const GDebugKey gdk_debug_keys[] = {
   {"dnd",          GDK_DEBUG_DND},
   {"xim",          GDK_DEBUG_XIM},
   {"nograbs",       GDK_DEBUG_NOGRABS},
+  {"colormap",     GDK_DEBUG_COLORMAP},
+  {"gdkrgb",       GDK_DEBUG_GDKRGB},
+  {"gc",           GDK_DEBUG_GC},
+  {"pixmap",       GDK_DEBUG_PIXMAP},
+  {"image",        GDK_DEBUG_IMAGE},
+  {"input",        GDK_DEBUG_INPUT},
+  {"cursor",       GDK_DEBUG_CURSOR},
+  {"multihead",            GDK_DEBUG_MULTIHEAD},
 };
 
-static const int gdk_ndebug_keys = sizeof(gdk_debug_keys)/sizeof(GDebugKey);
+static const int gdk_ndebug_keys = G_N_ELEMENTS (gdk_debug_keys);
 
 #endif /* G_ENABLE_DEBUG */
 
@@ -128,7 +136,7 @@ gdk_arg_context_parse (GdkArgContext *context, gint *argc, gchar ***argv)
                        int len = strlen (table[k].name);
                        
                        if (strncmp (arg, table[k].name, len) == 0 &&
-                           (arg[len] == '=' || argc[len] == 0))
+                           (arg[len] == '=' || arg[len] == 0))
                          {
                            char *value = NULL;
 
@@ -228,8 +236,11 @@ gdk_arg_name_cb (const char *key, const char *value, gpointer user_data)
 }
 
 static GdkArgDesc gdk_args[] = {
-  { "class" ,       GDK_ARG_STRING,   NULL, gdk_arg_class_cb    },
-  { "name",         GDK_ARG_STRING,   NULL, gdk_arg_name_cb     },
+  { "class" ,       GDK_ARG_CALLBACK, NULL, gdk_arg_class_cb                   },
+  { "name",         GDK_ARG_CALLBACK, NULL, gdk_arg_name_cb                    },
+  { "display",      GDK_ARG_STRING,   &_gdk_display_name,     (GdkArgFunc)NULL },
+  { "screen",       GDK_ARG_INT,      &_gdk_screen_number,    (GdkArgFunc)NULL },
+
 #ifdef G_ENABLE_DEBUG
   { "gdk-debug",    GDK_ARG_CALLBACK, NULL, gdk_arg_debug_cb    },
   { "gdk-no-debug", GDK_ARG_CALLBACK, NULL, gdk_arg_no_debug_cb },
@@ -237,49 +248,60 @@ static GdkArgDesc gdk_args[] = {
   { NULL }
 };
 
-/*
- *--------------------------------------------------------------
- * gdk_init_check
- *
- *   Initialize the library for use.
- *
- * Arguments:
- *   "argc" is the number of arguments.
- *   "argv" is an array of strings.
+
+/**
+ * _gdk_get_command_line_args:
+ * @argv: location to store argv pointer
+ * @argc: location 
+ * 
+ * Retrieve the command line arguments passed to gdk_init().
+ * The returned argv pointer points to static storage ; no
+ * copy is made.
+ **/
+void
+_gdk_get_command_line_args (int    *argc,
+                           char ***argv)
+{
+  *argc = gdk_argc;
+  *argv = gdk_argv;
+}
+
+/**
+ * gdk_parse_args:
+ * @argc: the number of command line arguments.
+ * @argv: the array of command line arguments.
+ * 
+ * Parse command line arguments, and store for future
+ * use by calls to gdk_display_open().
  *
- * Results:
- *   "argc" and "argv" are modified to reflect any arguments
- *   which were not handled. (Such arguments should either
- *   be handled by the application or dismissed). If initialization
- *   fails, returns FALSE, otherwise TRUE.
+ * Any arguments used by GDK are removed from the array and @argc and @argv are
+ * updated accordingly.
  *
- * Side effects:
- *   The library is initialized.
+ * You shouldn't call this function explicitely if you are using
+ * gtk_init(), gtk_init_check(), gdk_init(), or gdk_init_check().
  *
- *--------------------------------------------------------------
- */
-
-gboolean
-gdk_init_check (int    *argc,
+ * Since: 2.2
+ **/
+void
+gdk_parse_args (int    *argc,
                char ***argv)
 {
-  gchar **argv_orig = NULL;
-  gint argc_orig = 0;
   GdkArgContext *arg_context;
-  gboolean result;
-  int i;
-  
+  gint i;
+
   if (gdk_initialized)
-    return TRUE;
+    return;
+
+  gdk_initialized = TRUE;
 
   if (argc && argv)
     {
-      argc_orig = *argc;
+      gdk_argc = *argc;
       
-      argv_orig = g_malloc ((argc_orig + 1) * sizeof (char*));
-      for (i = 0; i < argc_orig; i++)
-       argv_orig[i] = g_strdup ((*argv)[i]);
-      argv_orig[argc_orig] = NULL;
+      gdk_argv = g_malloc ((gdk_argc + 1) * sizeof (char*));
+      for (i = 0; i < gdk_argc; i++)
+       gdk_argv[i] = g_strdup ((*argv)[i]);
+      gdk_argv[gdk_argc] = NULL;
 
       if (*argc > 0)
        {
@@ -296,6 +318,13 @@ gdk_init_check (int    *argc,
     {
       g_set_prgname ("<unknown>");
     }
+
+  /* We set the fallback program class here, rather than lazily in
+   * gdk_get_program_class, since we don't want -name to override it.
+   */
+  gdk_progclass = g_strdup (g_get_prgname ());
+  if (gdk_progclass[0])
+    gdk_progclass[0] = g_ascii_toupper (gdk_progclass[0]);
   
 #ifdef G_ENABLE_DEBUG
   {
@@ -316,114 +345,143 @@ gdk_init_check (int    *argc,
   GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ()));
 
   g_type_init ();
-  
-  result = _gdk_windowing_init_check (argc_orig, argv_orig);
-
-  for (i = 0; i < argc_orig; i++)
-    g_free(argv_orig[i]);
-  g_free(argv_orig);
 
-  if (!result)
-    return FALSE;
-  
-  _gdk_visual_init ();
-  _gdk_windowing_window_init ();
-  _gdk_windowing_image_init ();
-  _gdk_events_init ();
-  _gdk_input_init ();
-  _gdk_dnd_init ();
+  /* Do any setup particular to the windowing system
+   */
+  _gdk_windowing_init (argc, argv);
+}
 
-  gdk_initialized = 1;
+/** 
+ * gdk_get_display_arg_name:
+ *
+ * Gets the display name specified in the command line arguments passed
+ * to gdk_init() or gdk_parse_args(), if any.
+ *
+ * Returns: the display name, if specified explicitely, otherwise %NULL
+ *   this string is owned by GTK+ and must not be modified or freed.
+ *
+ * Since: 2.2
+ */
+G_CONST_RETURN gchar *
+gdk_get_display_arg_name (void)
+{
+  if (!_gdk_display_arg_name)
+    {
+      if (_gdk_screen_number >= 0)
+       _gdk_display_arg_name = _gdk_windowing_substitute_screen_number (_gdk_display_name, _gdk_screen_number);
+      else
+       _gdk_display_arg_name = g_strdup (_gdk_display_name);
+   }
 
-  return TRUE;
+   return _gdk_display_arg_name;
 }
 
-void
-gdk_init (int *argc, char ***argv)
+/**
+ * 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: the default display, if it could be opened,
+ *   otherwise %NULL.
+ **/
+GdkDisplay *
+gdk_display_open_default_libgtk_only (void)
 {
-  if (!gdk_init_check (argc, argv))
+  GdkDisplay *display;
+
+  g_return_val_if_fail (gdk_initialized, NULL);
+  
+  display = gdk_display_get_default ();
+  if (display)
+    return display;
+
+  display = gdk_display_open (gdk_get_display_arg_name ());
+
+  if (!display && _gdk_screen_number >= 0)
     {
-      g_warning ("cannot open display: %s", gdk_get_display ());
-      exit(1);
+      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;
 }
 
 /*
  *--------------------------------------------------------------
- * gdk_exit
+ * gdk_init_check
  *
- *   Restores the library to an un-itialized state and exits
- *   the program using the "exit" system call.
+ *   Initialize the library for use.
  *
  * Arguments:
- *   "errorcode" is the error value to pass to "exit".
+ *   "argc" is the number of arguments.
+ *   "argv" is an array of strings.
  *
  * Results:
- *   Allocated structures are freed and the program exits
- *   cleanly.
+ *   "argc" and "argv" are modified to reflect any arguments
+ *   which were not handled. (Such arguments should either
+ *   be handled by the application or dismissed). If initialization
+ *   fails, returns FALSE, otherwise TRUE.
  *
  * Side effects:
+ *   The library is initialized.
  *
  *--------------------------------------------------------------
  */
 
-void
-gdk_exit (gint errorcode)
+gboolean
+gdk_init_check (int    *argc,
+               char ***argv)
 {
-  /* de-initialisation is done by the gdk_exit_funct(),
-     no need to do this here (Alex J.) */
-  exit (errorcode);
-}
+  gdk_parse_args (argc, argv);
 
-#if 0
+  return gdk_display_open_default_libgtk_only () != NULL;
+}
 
-/* This is disabled, but the code isn't removed, because we might
- * want to have some sort of explicit way to shut down GDK cleanly
- * at some point in the future.
- */
+void
+gdk_init (int *argc, char ***argv)
+{
+  if (!gdk_init_check (argc, argv))
+    {
+      g_warning ("cannot open display: %s", gdk_get_display_arg_name ());
+      exit(1);
+    }
+}
 
 /*
  *--------------------------------------------------------------
- * gdk_exit_func
+ * gdk_exit
  *
- *   This is the "atexit" function that makes sure the
- *   library gets a chance to cleanup.
+ *   Restores the library to an un-itialized state and exits
+ *   the program using the "exit" system call.
  *
  * Arguments:
+ *   "errorcode" is the error value to pass to "exit".
  *
  * Results:
+ *   Allocated structures are freed and the program exits
+ *   cleanly.
  *
  * Side effects:
- *   The library is un-initialized and the program exits.
  *
  *--------------------------------------------------------------
  */
 
-static void
-gdk_exit_func (void)
+void
+gdk_exit (gint errorcode)
 {
-  static gboolean in_gdk_exit_func = FALSE;
-  
-  /* This is to avoid an infinite loop if a program segfaults in
-     an atexit() handler (and yes, it does happen, especially if a program
-     has trounced over memory too badly for even g_message to work) */
-  if (in_gdk_exit_func == TRUE)
-    return;
-  in_gdk_exit_func = TRUE;
-  
-  if (gdk_initialized)
-    {
-      _gdk_image_exit ();
-      _gdk_input_exit ();
-
-      _gdk_windowing_exit ();
-      
-      gdk_initialized = 0;
-    }
+  exit (errorcode);
 }
 
-#endif
-
 void
 gdk_threads_enter ()
 {
@@ -458,12 +516,6 @@ gdk_threads_init ()
 G_CONST_RETURN char *
 gdk_get_program_class (void)
 {
-  if (gdk_progclass == NULL)
-    {
-      gdk_progclass = g_strdup (g_get_prgname ());
-      gdk_progclass[0] = g_ascii_toupper (gdk_progclass[0]);
-    }
-  
   return gdk_progclass;
 }