]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkevents-x11.c
Updated Azeri and Walloon files
[~andy/gtk] / gdk / x11 / gdkevents-x11.c
index bcb70be448a2ed92af39530b9f9907e96ca148d6..a102e2b82717fa2a52c1a6295795a717870c71a1 100644 (file)
@@ -404,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,
@@ -412,6 +429,7 @@ gdk_event_translate (GdkEvent *event,
   
   GdkWindow *window;
   GdkWindowObject *window_private;
+  GdkWindowImplX11 *window_impl = NULL;
   static XComposeStatus compose;
   KeySym keysym;
   int charcount;
@@ -439,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 ||
@@ -468,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;
   
@@ -614,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;
@@ -627,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;
@@ -643,6 +691,7 @@ gdk_event_translate (GdkEvent *event,
          event->button.device = gdk_core_pointer;
          
          gdk_event_button_generate (event);
+          break;
        }
 
       break;
@@ -663,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;
@@ -718,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) &&
@@ -792,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;
       
@@ -853,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"));
@@ -1054,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);
@@ -1073,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);
@@ -1381,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))
     {
@@ -1795,8 +1925,13 @@ static struct
   const char *xsettings_name;
   const char *gdk_name;
 } settings_map[] = {
-  { "Net/DoubleClickTime", "double-click-timeout" },
-  { "Net/DragThreshold", "drag-threshold" }
+  { "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
@@ -1865,6 +2000,7 @@ gdk_setting_get (const gchar *name,
   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)
@@ -1885,14 +2021,20 @@ gdk_setting_get (const gchar *name,
     case XSETTINGS_TYPE_INT:
       if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
        {
-         g_value_set_int (value, setting->data.v_int);
+         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_set_string (value, setting->data.v_string);
+         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;
@@ -1901,17 +2043,23 @@ gdk_setting_get (const gchar *name,
        {
          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 (value, &color);
+         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);