[gnome-shell] StEntry: add a hook to set the cursor from libgnome-shell



commit 8ae0f1a9dc20e2f59b4fc777748c0e1871cbcaf9
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Wed Sep 11 18:11:55 2013 +0200

    StEntry: add a hook to set the cursor from libgnome-shell
    
    We need to call into MetaScreen to set the cursor, but we can't
    do that from libst, so add a hook that libgnome-shell can fill,
    and remove more ClutterX11 usage.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707467

 src/shell-global.c |   11 +++++++++++
 src/st/st-entry.c  |   45 ++++++++++++++++++---------------------------
 src/st/st-entry.h  |    4 ++++
 3 files changed, 33 insertions(+), 27 deletions(-)
---
diff --git a/src/shell-global.c b/src/shell-global.c
index 97cdebd..3f85ac5 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -828,6 +828,16 @@ gnome_shell_gdk_event_handler (GdkEvent *event_gdk,
   gtk_main_do_event (event_gdk);
 }
 
+static void
+entry_cursor_func (StEntry  *entry,
+                   gboolean  use_ibeam,
+                   gpointer  user_data)
+{
+  ShellGlobal *global = user_data;
+
+  meta_screen_set_cursor (global->meta_screen, use_ibeam ? META_CURSOR_IBEAM : META_CURSOR_DEFAULT);
+}
+
 void
 _shell_global_set_plugin (ShellGlobal *global,
                           MetaPlugin  *plugin)
@@ -878,6 +888,7 @@ _shell_global_set_plugin (ShellGlobal *global,
     }
 
   st_im_text_set_event_window (global->ibus_window);
+  st_entry_set_cursor_func (entry_cursor_func, global);
 
   g_signal_connect (global->stage, "notify::width",
                     G_CALLBACK (global_stage_notify_width), global);
diff --git a/src/st/st-entry.c b/src/st/st-entry.c
index c00caa4..8fec0f4 100644
--- a/src/st/st-entry.c
+++ b/src/st/st-entry.c
@@ -65,10 +65,6 @@
 #include "st-clipboard.h"
 #include "st-private.h"
 
-#include <clutter/x11/clutter-x11.h>
-#include <X11/Xlib.h>
-#include <X11/cursorfont.h>
-
 #include "st-widget-accessible.h"
 
 #define HAS_FOCUS(actor) (clutter_actor_get_stage (actor) && clutter_stage_get_key_focus ((ClutterStage *) 
clutter_actor_get_stage (actor)) == actor)
@@ -681,33 +677,28 @@ st_entry_key_focus_in (ClutterActor *actor)
   clutter_actor_grab_key_focus (priv->entry);
 }
 
+static StEntryCursorFunc cursor_func;
+static gpointer          cursor_func_data;
+
+/**
+ * st_entry_set_cursor_func: (skip)
+ *
+ * This function is for private use by libgnome-shell.
+ * Do not ever use.
+ */
+void
+st_entry_set_cursor_func (StEntryCursorFunc func,
+                          gpointer          data)
+{
+  cursor_func = func;
+  cursor_func_data = data;
+}
+
 static void
 st_entry_set_cursor (StEntry  *entry,
                      gboolean  use_ibeam)
 {
-  Display *dpy;
-  ClutterActor *stage, *actor = CLUTTER_ACTOR (entry);
-  Window wid;
-  static Cursor ibeam = None;
-
-  dpy = clutter_x11_get_default_display ();
-  stage = clutter_actor_get_stage (actor);
-
-  if (stage == NULL)
-    {
-      g_warn_if_fail (!entry->priv->has_ibeam);
-      return;
-    }
-
-  wid = clutter_x11_get_stage_window (CLUTTER_STAGE (stage));
-
-  if (ibeam == None)
-    ibeam = XCreateFontCursor (dpy, XC_xterm);
-
-  if (use_ibeam)
-    XDefineCursor (dpy, wid, ibeam);
-  else
-    XUndefineCursor (dpy, wid);
+  cursor_func (entry, use_ibeam, cursor_func_data);
 
   entry->priv->has_ibeam = use_ibeam;
 }
diff --git a/src/st/st-entry.h b/src/st/st-entry.h
index ebe95bf..bc79db4 100644
--- a/src/st/st-entry.h
+++ b/src/st/st-entry.h
@@ -86,6 +86,10 @@ void            st_entry_set_primary_icon   (StEntry        *entry,
 void            st_entry_set_secondary_icon (StEntry        *entry,
                                              ClutterActor   *icon);
 
+typedef void (*StEntryCursorFunc) (StEntry *entry, gboolean use_ibeam, gpointer data);
+void            st_entry_set_cursor_func    (StEntryCursorFunc func,
+                                             gpointer          user_data);
+
 G_END_DECLS
 
 #endif /* __ST_ENTRY_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]