]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkevents-x11.c
Updated Azeri and Walloon files
[~andy/gtk] / gdk / x11 / gdkevents-x11.c
index ccb50711a4df02835ba0d3b53cbeebfd84e94bab..a102e2b82717fa2a52c1a6295795a717870c71a1 100644 (file)
@@ -31,6 +31,8 @@
 
 #include "gdkkeysyms.h"
 
+#include "xsettings-client.h"
+
 #if HAVE_CONFIG_H
 #  include <config.h>
 #  if STDC_HEADERS
@@ -103,6 +105,15 @@ GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
                                         GdkEvent  *event,
                                         gpointer   data);
 
+static void gdk_xsettings_watch_cb  (Window            window,
+                                    Bool              is_start,
+                                    long              mask,
+                                    void             *cb_data);
+static void gdk_xsettings_notify_cb (const char       *name,
+                                    XSettingsAction   action,
+                                    XSettingsSetting *setting,
+                                    void             *data);
+
 /* Private variable declarations
  */
 
@@ -125,6 +136,8 @@ static GPollFD event_poll_fd;
 
 static Window wmspec_check_window = None;
 
+static XSettingsClient *xsettings_client;
+
 /*********************************************
  * Functions for maintaining the event queue *
  *********************************************/
@@ -151,6 +164,11 @@ gdk_events_init (void)
 
   gdk_add_client_message_filter (gdk_wm_protocols, 
                                 gdk_wm_protocols_filter, NULL);
+
+  xsettings_client = xsettings_client_new (gdk_display, DefaultScreen (gdk_display),
+                                          gdk_xsettings_notify_cb,
+                                          gdk_xsettings_watch_cb,
+                                          NULL);
 }
 
 /*
@@ -386,6 +404,23 @@ gdk_check_wm_state_changed (GdkWindow *window)
     }
 }
 
+#define HAS_FOCUS(window_impl)                           \
+  ((window_impl)->has_focus || (window_impl)->has_pointer_focus)
+
+static void
+generate_focus_event (GdkWindow *window,
+                     gboolean   in)
+{
+  GdkEvent event;
+  
+  event.type = GDK_FOCUS_CHANGE;
+  event.focus_change.window = window;
+  event.focus_change.send_event = FALSE;
+  event.focus_change.in = in;
+  
+  gdk_event_put (&event);
+}
+
 static gint
 gdk_event_translate (GdkEvent *event,
                     XEvent   *xevent,
@@ -394,6 +429,7 @@ gdk_event_translate (GdkEvent *event,
   
   GdkWindow *window;
   GdkWindowObject *window_private;
+  GdkWindowImplX11 *window_impl = NULL;
   static XComposeStatus compose;
   KeySym keysym;
   int charcount;
@@ -421,12 +457,7 @@ gdk_event_translate (GdkEvent *event,
     }
   
   window = gdk_window_lookup (xevent->xany.window);
-  /* FIXME: window might be a GdkPixmap!!! */
-  
   window_private = (GdkWindowObject *) window;
-  
-  if (window != NULL)
-    gdk_window_ref (window);
 
   if (_gdk_moveresize_window &&
       (xevent->xany.type == MotionNotify ||
@@ -450,6 +481,29 @@ gdk_event_translate (GdkEvent *event,
         return FALSE;
     }
   
+  /* FIXME: window might be a GdkPixmap!!! */
+  if (window != NULL)
+    {
+      window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
+         
+      if (xevent->xany.window != GDK_WINDOW_XID (window))
+       {
+         g_assert (xevent->xany.window == window_impl->focus_window);
+
+         switch (xevent->type)
+           {
+           case KeyPress:
+           case KeyRelease:
+             xevent->xany.window = GDK_WINDOW_XID (window);
+             break;
+           default:
+             return False;
+           }
+       }
+
+      gdk_window_ref (window);
+    }
+
   event->any.window = window;
   event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
   
@@ -596,11 +650,23 @@ gdk_event_translate (GdkEvent *event,
       
       /* If we get a ButtonPress event where the button is 4 or 5,
         it's a Scroll event */
-      if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
-       {
+      switch (xevent->xbutton.button)
+        {
+        case 4: /* up */
+        case 5: /* down */
+        case 6: /* left */
+        case 7: /* right */
          event->scroll.type = GDK_SCROLL;
-         event->scroll.direction = (xevent->xbutton.button == 4) ? 
-           GDK_SCROLL_UP : GDK_SCROLL_DOWN;
+
+          if (xevent->xbutton.button == 4)
+            event->scroll.direction = GDK_SCROLL_UP;
+          else if (xevent->xbutton.button == 5)
+            event->scroll.direction = GDK_SCROLL_DOWN;
+          else if (xevent->xbutton.button == 6)
+            event->scroll.direction = GDK_SCROLL_LEFT;
+          else
+            event->scroll.direction = GDK_SCROLL_RIGHT;
+
          event->scroll.window = window;
          event->scroll.time = xevent->xbutton.x;
          event->scroll.x = xevent->xbutton.x + xoffset;
@@ -609,9 +675,9 @@ gdk_event_translate (GdkEvent *event,
          event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
          event->scroll.state = (GdkModifierType) xevent->xbutton.state;
          event->scroll.device = gdk_core_pointer;
-       }
-      else
-       {
+          break;
+          
+        default:
          event->button.type = GDK_BUTTON_PRESS;
          event->button.window = window;
          event->button.time = xevent->xbutton.time;
@@ -625,6 +691,7 @@ gdk_event_translate (GdkEvent *event,
          event->button.device = gdk_core_pointer;
          
          gdk_event_button_generate (event);
+          break;
        }
 
       break;
@@ -645,7 +712,8 @@ gdk_event_translate (GdkEvent *event,
        }
       
       /* We treat button presses as scroll wheel events, so ignore the release */
-      if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
+      if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
+          xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
        {
          return_val = FALSE;
          break;
@@ -700,7 +768,21 @@ gdk_event_translate (GdkEvent *event,
                           xevent->xcrossing.window,
                           xevent->xcrossing.detail,
                           xevent->xcrossing.subwindow));
-      
+
+      /* Handle focusing (in the case where no window manager is running */
+      if (window &&
+         GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
+         xevent->xcrossing.detail != NotifyInferior &&
+         xevent->xcrossing.focus && !window_impl->has_focus)
+       {
+         gboolean had_focus = HAS_FOCUS (window_impl);
+         
+         window_impl->has_pointer_focus = TRUE;
+
+         if (HAS_FOCUS (window_impl) != had_focus)
+           generate_focus_event (window, TRUE);
+       }
+
       /* Tell XInput stuff about it if appropriate */
       if (window_private &&
          !GDK_WINDOW_DESTROYED (window) &&
@@ -774,6 +856,20 @@ gdk_event_translate (GdkEvent *event,
                           xevent->xcrossing.window,
                           xevent->xcrossing.detail, xevent->xcrossing.subwindow));
       
+      /* Handle focusing (in the case where no window manager is running */
+      if (window &&
+         GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
+         xevent->xcrossing.detail != NotifyInferior &&
+         xevent->xcrossing.focus && !window_impl->has_focus)
+       {
+         gboolean had_focus = HAS_FOCUS (window_impl);
+         
+         window_impl->has_pointer_focus = FALSE;
+
+         if (HAS_FOCUS (window_impl) != had_focus)
+           generate_focus_event (window, FALSE);
+       }
+
       event->crossing.type = GDK_LEAVE_NOTIFY;
       event->crossing.window = window;
       
@@ -835,38 +931,77 @@ gdk_event_translate (GdkEvent *event,
       
       break;
       
-    case FocusIn:
-    case FocusOut:
       /* We only care about focus events that indicate that _this_
        * window (not a ancestor or child) got or lost the focus
        */
-      switch (xevent->xfocus.detail)
+    case FocusIn:
+      GDK_NOTE (EVENTS,
+               g_message ("focus in:\t\twindow: %ld", xevent->xfocus.window));
+      
+      if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
        {
-       case NotifyAncestor:
-       case NotifyInferior:
-       case NotifyNonlinear:
-         GDK_NOTE (EVENTS,
-                   g_message ("focus %s:\t\twindow: %ld",
-                              (xevent->xany.type == FocusIn) ? "in" : "out",
-                              xevent->xfocus.window));
+         gboolean had_focus = HAS_FOCUS (window_impl);
          
+         switch (xevent->xfocus.detail)
+           {
+           case NotifyAncestor:
+           case NotifyNonlinear:
+           case NotifyVirtual:
+           case NotifyNonlinearVirtual:
+             window_impl->has_focus = TRUE;
+             break;
+           case NotifyPointer:
+             window_impl->has_pointer_focus = TRUE;
+             break;
+           case NotifyInferior:
+           case NotifyPointerRoot:
+           case NotifyDetailNone:
+             break;
+           }
+
+         if (HAS_FOCUS (window_impl) != had_focus)
+           generate_focus_event (window, TRUE);
+       }
+      break;
+    case FocusOut:
+      GDK_NOTE (EVENTS,
+               g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));
+
+      if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
+       {
+         gboolean had_focus = HAS_FOCUS (window_impl);
+           
+         switch (xevent->xfocus.detail)
+           {
+           case NotifyAncestor:
+           case NotifyNonlinear:
+           case NotifyVirtual:
+           case NotifyNonlinearVirtual:
+             window_impl->has_focus = FALSE;
+             break;
+           case NotifyPointer:
+             window_impl->has_pointer_focus = FALSE;
+           break;
+           case NotifyInferior:
+           case NotifyPointerRoot:
+           case NotifyDetailNone:
+             break;
+           }
+
+         if (HAS_FOCUS (window_impl) != had_focus)
+           generate_focus_event (window, FALSE);
+       }
+      break;
+
+#if 0      
          /* gdk_keyboard_grab() causes following events. These events confuse
           * the XIM focus, so ignore them.
           */
          if (xevent->xfocus.mode == NotifyGrab ||
              xevent->xfocus.mode == NotifyUngrab)
            break;
-         
-         event->focus_change.type = GDK_FOCUS_CHANGE;
-         event->focus_change.window = window;
-         event->focus_change.in = (xevent->xany.type == FocusIn);
+#endif
 
-         break;
-       default:
-         return_val = FALSE;
-       }
-      break;
-      
     case KeymapNotify:
       GDK_NOTE (EVENTS,
                g_message ("keymap notify"));
@@ -1036,7 +1171,7 @@ gdk_event_translate (GdkEvent *event,
        * an unmap, it means we hid the window ourselves, so we
        * will have already flipped the iconified bit off.
        */
-      if (GDK_WINDOW_IS_MAPPED (window))
+      if (window && GDK_WINDOW_IS_MAPPED (window))
         gdk_synthesize_window_state (window,
                                      0,
                                      GDK_WINDOW_STATE_ICONIFIED);
@@ -1055,7 +1190,7 @@ gdk_event_translate (GdkEvent *event,
       event->any.window = window;
 
       /* Unset iconified if it was set */
-      if (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED)
+      if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
         gdk_synthesize_window_state (window,
                                      GDK_WINDOW_STATE_ICONIFIED,
                                      0);
@@ -1363,6 +1498,19 @@ gdk_wm_protocols_filter (GdkXEvent *xev,
     }
   else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
     {
+      GdkWindow *win = event->any.window;
+      Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
+
+      /* There is no way of knowing reliably whether we are viewable so we need
+       * to trap errors so we don't cause a BadMatch.
+       */
+      gdk_error_trap_push ();
+      XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
+                     focus_win,
+                     RevertToParent,
+                     xevent->xclient.data.l[1]);
+      XSync (GDK_WINDOW_XDISPLAY (win), False);
+      gdk_error_trap_pop ();
     }
   else if ((Atom) xevent->xclient.data.l[0] == gdk_atom_intern ("_NET_WM_PING", FALSE))
     {
@@ -1772,5 +1920,174 @@ gdk_net_wm_supports (GdkAtom property)
   return gdk_net_wm_supports (property);
 }
 
+static struct
+{
+  const char *xsettings_name;
+  const char *gdk_name;
+} settings_map[] = {
+  { "Net/DoubleClickTime", "gtk-double-click-timeout" },
+  { "Net/DragThreshold", "gtk-drag-threshold" },
+  { "Gtk/ColorPalette", "gtk-color-palette" },
+  { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
+  { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
+  { "Net/CursorBlink", "gtk-cursor-blink" },
+  { "Net/CursorBlinkTime", "gtk-cursor-blink-time" }
+};
+
+static void
+gdk_xsettings_notify_cb (const char       *name,
+                        XSettingsAction   action,
+                        XSettingsSetting *setting,
+                        void             *data)
+{
+  GdkEvent new_event;
+  int i;
+
+  new_event.type = GDK_SETTING;
+  new_event.setting.window = NULL;
+  new_event.setting.send_event = FALSE;
+  new_event.setting.name = NULL;
+
+  for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
+    if (strcmp (settings_map[i].xsettings_name, name) == 0)
+      {
+       new_event.setting.name = g_strdup (settings_map[i].gdk_name);
+       break;
+      }
+
+  if (!new_event.setting.name)
+    return;
+  
+  switch (action)
+    {
+    case XSETTINGS_ACTION_NEW:
+      new_event.setting.action = GDK_SETTING_ACTION_NEW;
+      break;
+    case XSETTINGS_ACTION_CHANGED:
+      new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
+      break;
+    case XSETTINGS_ACTION_DELETED:
+      new_event.setting.action = GDK_SETTING_ACTION_DELETED;
+      break;
+    }
 
+  gdk_event_put (&new_event);
+}
 
+static gboolean
+check_transform (const gchar *xsettings_name,
+                GType        src_type,
+                GType        dest_type)
+{
+  if (!g_value_type_transformable (src_type, dest_type))
+    {
+      g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
+                xsettings_name,
+                g_type_name (src_type),
+                g_type_name (dest_type));
+      return FALSE;
+    }
+  else
+    return TRUE;
+}
+
+gboolean
+gdk_setting_get (const gchar *name,
+                GValue      *value)
+{
+  const char *xsettings_name = NULL;
+  XSettingsResult result;
+  XSettingsSetting *setting;
+  gboolean success = FALSE;
+  gint i;
+  GValue tmp_val = { 0, };
+
+  for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
+    if (strcmp (settings_map[i].gdk_name, name) == 0)
+      {
+       xsettings_name = settings_map[i].xsettings_name;
+       break;
+      }
+
+  if (!xsettings_name)
+    return FALSE;
+
+  result = xsettings_client_get_setting (xsettings_client, xsettings_name, &setting);
+  if (result != XSETTINGS_SUCCESS)
+    return FALSE;
+
+  switch (setting->type)
+    {
+    case XSETTINGS_TYPE_INT:
+      if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
+       {
+         g_value_init (&tmp_val, G_TYPE_INT);
+         g_value_set_int (&tmp_val, setting->data.v_int);
+         g_value_transform (&tmp_val, value);
+
+         success = TRUE;
+       }
+      break;
+    case XSETTINGS_TYPE_STRING:
+      if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
+       {
+         g_value_init (&tmp_val, G_TYPE_STRING);
+         g_value_set_string (&tmp_val, setting->data.v_string);
+         g_value_transform (&tmp_val, value);
+
+         success = TRUE;
+       }
+      break;
+    case XSETTINGS_TYPE_COLOR:
+      if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
+       {
+         GdkColor color;
+         
+         g_value_init (&tmp_val, GDK_TYPE_COLOR);
+
+         color.pixel = 0;
+         color.red = setting->data.v_color.red;
+         color.green = setting->data.v_color.green;
+         color.blue = setting->data.v_color.blue;
+         
+         g_value_set_boxed (&tmp_val, &color);
+         
+         g_value_transform (&tmp_val, value);
+         
+         success = TRUE;
+       }
+      break;
+    }
+  
+  g_value_unset (&tmp_val);
+
+  xsettings_setting_free (setting);
+
+  return success;
+}
+
+GdkFilterReturn 
+gdk_xsettings_client_event_filter (GdkXEvent *xevent,
+                                  GdkEvent  *event,
+                                  gpointer   data)
+{
+  if (xsettings_client_process_event (xsettings_client, (XEvent *)xevent))
+    return GDK_FILTER_REMOVE;
+  else
+    return GDK_FILTER_CONTINUE;
+}
+
+static void 
+gdk_xsettings_watch_cb (Window window,
+                       Bool   is_start,
+                       long   mask,
+                       void  *cb_data)
+{
+  GdkWindow *gdkwin;
+
+  gdkwin = gdk_window_lookup (window);
+  if (is_start)
+    gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, NULL);
+  else
+    gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, NULL);
+}