x11: Implement the set_accept_focus() vfunc
authorEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 28 Dec 2010 17:38:39 +0000 (17:38 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Thu, 30 Dec 2010 12:47:00 +0000 (12:47 +0000)
Actually set the InputHint flag and set the input field of the WM_SPEC
hints depending on the value of the accept-focus bitfield.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2500

clutter/x11/clutter-stage-x11.c
clutter/x11/clutter-stage-x11.h

index 1b384a0..a3666d6 100644 (file)
@@ -537,7 +537,7 @@ clutter_stage_x11_set_user_resizable (ClutterStageWindow *stage_window,
                                      stage_x11->xwin_height);
 }
 
-static void
+static inline void
 update_wm_hints (ClutterStageX11 *stage_x11)
 {
   ClutterBackend *backend;
@@ -551,17 +551,27 @@ update_wm_hints (ClutterStageX11 *stage_x11)
     return;
 
   backend = clutter_get_default_backend ();
-
-  g_return_if_fail (CLUTTER_IS_BACKEND_X11 (backend));
+  g_assert (CLUTTER_IS_BACKEND_X11 (backend));
   backend_x11 = CLUTTER_BACKEND_X11 (backend);
 
-  wm_hints.flags = StateHint;
+  wm_hints.flags = StateHint | InputHint;
   wm_hints.initial_state = NormalState;
+  wm_hints.input = stage_x11->accept_focus ? True : False;
 
   XSetWMHints (backend_x11->xdpy, stage_x11->xwin, &wm_hints);
 }
 
 static void
+clutter_stage_x11_set_accept_focus (ClutterStageWindow *stage_window,
+                                    gboolean            accept_focus)
+{
+  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
+
+  stage_x11->accept_focus = !!accept_focus;
+  update_wm_hints (stage_x11);
+}
+
+static void
 set_stage_state (ClutterStageX11      *stage_x11,
                  ClutterStageX11State  unset_flags,
                  ClutterStageX11State  set_flags)
@@ -691,6 +701,7 @@ clutter_stage_x11_init (ClutterStageX11 *stage)
   stage->is_foreign_xwin = FALSE;
   stage->fullscreening = FALSE;
   stage->is_cursor_visible = TRUE;
+  stage->accept_focus = TRUE;
 
   stage->title = NULL;
 
@@ -705,6 +716,7 @@ clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
   iface->set_fullscreen = clutter_stage_x11_set_fullscreen;
   iface->set_cursor_visible = clutter_stage_x11_set_cursor_visible;
   iface->set_user_resizable = clutter_stage_x11_set_user_resizable;
+  iface->set_accept_focus = clutter_stage_x11_set_accept_focus;
   iface->show = clutter_stage_x11_show;
   iface->hide = clutter_stage_x11_hide;
   iface->resize = clutter_stage_x11_resize;
index e1d10e8..b62c2d2 100644 (file)
@@ -54,6 +54,7 @@ struct _ClutterStageX11
   guint        fullscreening        : 1;
   guint        is_cursor_visible    : 1;
   guint        viewport_initialized : 1;
+  guint        accept_focus         : 1;
 
   Window       xwin;
   gint         xwin_width;