]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkmain-x11.c
Updated Azeri and Walloon files
[~andy/gtk] / gdk / x11 / gdkmain-x11.c
index 7b48264b60f595ab17a4594724d5ff94a059c8de..607483402466bcc2f1158e4477484739cebad626 100644 (file)
@@ -2,23 +2,23 @@
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * 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
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * 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-1999.  See the AUTHORS
+ * 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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <limits.h>
 #include <errno.h>
 
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif /* HAVE_SYS_SELECT_H_ */
-
-#define XLIB_ILLEGAL_ACCESS
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
-#include <X11/Xos.h>
 #include <X11/Xutil.h>
-#include <X11/cursorfont.h>
+
+#ifdef HAVE_XKB
+#include <X11/XKBlib.h>
+#endif
 
 #include "gdk.h"
 
 #include "gdkprivate-x11.h"
 #include "gdkinternals.h"
+#include "gdkregion-generic.h"
 #include "gdkinputprivate.h"
+
 #include <pango/pangox.h>
 
 typedef struct _GdkPredicate  GdkPredicate;
@@ -103,34 +103,6 @@ static const int gdk_ndebug_keys = sizeof(gdk_debug_keys)/sizeof(GDebugKey);
 
 #endif /* G_ENABLE_DEBUG */
 
-static void
-gdk_arg_xim_preedit_cb (const gchar *arg, const gchar *value, gpointer cb_data)
-{
-  if (strcmp ("none", value) == 0)
-    gdk_im_set_best_style (GDK_IM_PREEDIT_NONE);
-  else if (strcmp ("nothing", value) == 0)
-    gdk_im_set_best_style (GDK_IM_PREEDIT_NOTHING);
-  else if (strcmp ("area", value) == 0)
-    gdk_im_set_best_style (GDK_IM_PREEDIT_AREA);
-  else if (strcmp ("position", value) == 0)
-    gdk_im_set_best_style (GDK_IM_PREEDIT_POSITION);
-  else if (strcmp ("callbacks", value) == 0)
-    gdk_im_set_best_style (GDK_IM_PREEDIT_CALLBACKS);
-}
-
-static void
-gdk_arg_xim_status_cb (const gchar *arg, const gchar *value, gpointer cb_data)
-{
-  if (strcmp ("none", value) == 0)
-    gdk_im_set_best_style (GDK_IM_STATUS_NONE);
-  else if (strcmp ("nothing", value) == 0)
-    gdk_im_set_best_style (GDK_IM_STATUS_NOTHING);
-  else if (strcmp ("area", value) == 0)
-    gdk_im_set_best_style (GDK_IM_STATUS_AREA);
-  else if (strcmp ("callbacks", value) == 0)
-    gdk_im_set_best_style (GDK_IM_STATUS_CALLBACKS);
-}
-
 GdkArgDesc _gdk_windowing_args[] = {
   { "display",     GDK_ARG_STRING,   &gdk_display_name,    (GdkArgFunc)NULL   },
   { "sync",        GDK_ARG_BOOL,     &gdk_synchronize,     (GdkArgFunc)NULL   },
@@ -138,8 +110,6 @@ GdkArgDesc _gdk_windowing_args[] = {
   { "class",       GDK_ARG_STRING,   &gdk_progclass,       (GdkArgFunc)NULL   },
   { "gxid-host",   GDK_ARG_STRING,   &gdk_input_gxid_host, (GdkArgFunc)NULL   },
   { "gxid-port",   GDK_ARG_INT,      &gdk_input_gxid_port, (GdkArgFunc)NULL   },
-  { "xim-preedit", GDK_ARG_CALLBACK, NULL,                 gdk_arg_xim_preedit_cb },
-  { "xim-status",  GDK_ARG_CALLBACK, NULL,                 gdk_arg_xim_status_cb  },
   { NULL }
 };
 
@@ -148,6 +118,7 @@ _gdk_windowing_init_check (int argc, char **argv)
 {
   XKeyboardState keyboard_state;
   XClassHint *class_hint;
+  guint pid;
   
   XSetErrorHandler (gdk_x_error);
   XSetIOErrorHandler (gdk_x_io_error);
@@ -176,16 +147,57 @@ _gdk_windowing_init_check (int argc, char **argv)
                       NULL, NULL, argv, argc, 
                       NULL, NULL, class_hint);
   XFree (class_hint);
+
+  pid = getpid();
+  XChangeProperty (gdk_display, gdk_leader_window,
+                  gdk_atom_intern ("_NET_WM_PID", FALSE),
+                  XA_CARDINAL, 32,
+                  PropModeReplace,
+                  (guchar *)&pid, 1);
   
-  gdk_wm_delete_window = XInternAtom (gdk_display, "WM_DELETE_WINDOW", False);
-  gdk_wm_take_focus = XInternAtom (gdk_display, "WM_TAKE_FOCUS", False);
-  gdk_wm_protocols = XInternAtom (gdk_display, "WM_PROTOCOLS", False);
+  gdk_wm_delete_window = gdk_atom_intern ("WM_DELETE_WINDOW", FALSE);
+  gdk_wm_take_focus = gdk_atom_intern ("WM_TAKE_FOCUS", FALSE);
+  gdk_wm_protocols = gdk_atom_intern ("WM_PROTOCOLS", FALSE);
   gdk_wm_window_protocols[0] = gdk_wm_delete_window;
   gdk_wm_window_protocols[1] = gdk_wm_take_focus;
-  gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);
+  gdk_wm_window_protocols[2] = gdk_atom_intern ("_NET_WM_PING", FALSE);
+  gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);
   
   XGetKeyboardControl (gdk_display, &keyboard_state);
   autorepeat = keyboard_state.global_auto_repeat;
+
+#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 (gdk_display, NULL, NULL, NULL,
+                               &xkb_major, &xkb_minor))
+          {
+           Bool detectable_autorepeat_supported;
+           
+            _gdk_use_xkb = TRUE;
+
+            XkbSelectEvents (gdk_display,
+                             XkbUseCoreKbd,
+                             XkbMapNotifyMask,
+                             XkbMapNotifyMask);
+
+           XkbSetDetectableAutoRepeat (gdk_display,
+                                       True,
+                                       &detectable_autorepeat_supported);
+
+           GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
+                                      detectable_autorepeat_supported ? "supported" : "not supported"));
+           
+           _gdk_have_xkb_autorepeat = detectable_autorepeat_supported;
+          }
+      }
+  }
+#endif
   
   return TRUE;
 }
@@ -202,6 +214,28 @@ gdk_get_use_xshm (void)
   return gdk_use_xshm;
 }
 
+static GdkGrabStatus
+gdk_x11_convert_grab_status (gint status)
+{
+  switch (status)
+    {
+    case GrabSuccess:
+      return GDK_GRAB_SUCCESS;
+    case AlreadyGrabbed:
+      return GDK_GRAB_ALREADY_GRABBED;
+    case GrabInvalidTime:
+      return GDK_GRAB_INVALID_TIME;
+    case GrabNotViewable:
+      return GDK_GRAB_NOT_VIEWABLE;
+    case GrabFrozen:
+      return GDK_GRAB_FROZEN;
+    }
+
+  g_assert_not_reached();
+
+  return 0;
+}
+
 /*
  *--------------------------------------------------------------
  * gdk_pointer_grab
@@ -225,7 +259,7 @@ gdk_get_use_xshm (void)
  *--------------------------------------------------------------
  */
 
-gint
+GdkGrabStatus
 gdk_pointer_grab (GdkWindow *    window,
                  gboolean        owner_events,
                  GdkEventMask    event_mask,
@@ -273,7 +307,7 @@ gdk_pointer_grab (GdkWindow *         window,
                                        confine_to,
                                        time);
 
-  if (return_val == Success)
+  if (return_val == GrabSuccess)
     {
       if (!GDK_WINDOW_DESTROYED (window))
        return_val = XGrabPointer (GDK_WINDOW_XDISPLAY (window),
@@ -290,8 +324,8 @@ gdk_pointer_grab (GdkWindow *         window,
   
   if (return_val == GrabSuccess)
     gdk_xgrab_window = (GdkWindowObject *)window;
-  
-  return return_val;
+
+  return gdk_x11_convert_grab_status (return_val);
 }
 
 /*
@@ -359,22 +393,26 @@ gdk_pointer_is_grabbed (void)
  *--------------------------------------------------------------
  */
 
-gint
+GdkGrabStatus
 gdk_keyboard_grab (GdkWindow *    window,
                   gboolean        owner_events,
                   guint32         time)
 {
+  gint return_val;
+  
   g_return_val_if_fail (window != NULL, 0);
   g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
   
   if (!GDK_WINDOW_DESTROYED (window))
-    return XGrabKeyboard (GDK_WINDOW_XDISPLAY (window),
-                         GDK_WINDOW_XID (window),
-                         owner_events,
-                         GrabModeAsync, GrabModeAsync,
-                         time);
+    return_val = XGrabKeyboard (GDK_WINDOW_XDISPLAY (window),
+                               GDK_WINDOW_XID (window),
+                               owner_events,
+                               GrabModeAsync, GrabModeAsync,
+                               time);
   else
-    return AlreadyGrabbed;
+    return_val = AlreadyGrabbed;
+
+  return gdk_x11_convert_grab_status (return_val);
 }
 
 /*
@@ -535,22 +573,6 @@ gdk_set_sm_client_id (const gchar* sm_client_id)
                      gdk_atom_intern ("SM_CLIENT_ID", FALSE));
 }
 
-void
-gdk_key_repeat_disable (void)
-{
-  XAutoRepeatOff (gdk_display);
-}
-
-void
-gdk_key_repeat_restore (void)
-{
-  if (autorepeat)
-    XAutoRepeatOn (gdk_display);
-  else
-    XAutoRepeatOff (gdk_display);
-}
-
-
 void
 gdk_beep (void)
 {
@@ -595,24 +617,32 @@ gdk_x_error (Display       *display,
     {
       if (gdk_error_warnings)
        {
-         char buf[64];
-         
+         gchar buf[64];
+          gchar *msg;
+          
          XGetErrorText (display, 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\n  serial %ld error_code %d request_code %d minor_code %d\n", 
-                  buf, 
-                  error->serial, 
-                  error->error_code, 
-                  error->request_code,
-                  error->minor_code);
+         g_error ("%s", msg);
 #else /* !G_ENABLE_DEBUG */
-         fprintf (stderr, "Gdk-ERROR **: %s\n  serial %ld error_code %d request_code %d minor_code %d\n",
-                  buf, 
-                  error->serial, 
-                  error->error_code, 
-                  error->request_code,
-                  error->minor_code);
+         fprintf (stderr, "%s\n", msg);
 
          exit(1);
 #endif /* G_ENABLE_DEBUG */
@@ -653,11 +683,17 @@ gdk_x_io_error (Display *display)
    */
   if (errno == EPIPE)
     {
-      fprintf (stderr, "Gdk-ERROR **: X connection to %s broken (explicit kill or server shutdown).\n", gdk_display ? DisplayString (gdk_display) : gdk_get_display());
+      fprintf (stderr,
+               "The application '%s' lost its connection to the display %s;\n"
+               "most likely the X server was shut down or you killed/destroyed\n"
+               "the application.\n",
+               g_get_prgname (),
+               gdk_display ? DisplayString (gdk_display) : gdk_get_display());
     }
   else
     {
-      fprintf (stderr, "Gdk-ERROR **: Fatal IO error %d (%s) on X server %s.\n",
+      fprintf (stderr, "%s: Fatal IO error %d (%s) on X server %s.\n",
+               g_get_prgname (),
               errno, g_strerror (errno),
               gdk_display ? DisplayString (gdk_display) : gdk_get_display());
     }
@@ -691,35 +727,25 @@ gdk_send_xevent (Window window, gboolean propagate, glong event_mask,
   return result && !gdk_error_code;
 }
 
-gchar*
-gdk_keyval_name (guint       keyval)
-{
-  return XKeysymToString (keyval);
-}
-
-guint
-gdk_keyval_from_name (const gchar *keyval_name)
+void
+_gdk_region_get_xrectangles (GdkRegion   *region,
+                             gint         x_offset,
+                             gint         y_offset,
+                             XRectangle **rects,
+                             gint        *n_rects)
 {
-  g_return_val_if_fail (keyval_name != NULL, 0);
+  XRectangle *rectangles = g_new (XRectangle, region->numRects);
+  GdkRegionBox *boxes = region->rects;
+  gint i;
   
-  return XStringToKeysym (keyval_name);
-}
+  for (i = 0; i < region->numRects; i++)
+    {
+      rectangles[i].x = CLAMP (boxes[i].x1 + x_offset, G_MINSHORT, G_MAXSHORT);
+      rectangles[i].y = CLAMP (boxes[i].y1 + y_offset, G_MINSHORT, G_MAXSHORT);
+      rectangles[i].width = CLAMP (boxes[i].x2 + x_offset, G_MINSHORT, G_MAXSHORT) - rectangles[i].x;
+      rectangles[i].height = CLAMP (boxes[i].y2 + y_offset, G_MINSHORT, G_MAXSHORT) - rectangles[i].y;
+    }
 
-#ifdef HAVE_XCONVERTCASE
-void
-gdk_keyval_convert_case (guint symbol,
-                        guint *lower,
-                        guint *upper)
-{
-  KeySym xlower = 0;
-  KeySym xupper = 0;
-
-  if (symbol)
-    XConvertCase (symbol, &xlower, &xupper);
-
-  if (lower)
-    *lower = xlower;
-  if (upper)
-    *upper = xupper;
-}  
-#endif HAVE_XCONVERTCASE
+  *rects = rectangles;
+  *n_rects = region->numRects;
+}