From 2d763bd0337d9b83b1d5f3f992ba8c3a9156f7a7 Mon Sep 17 00:00:00 2001 From: Thomas Wood Date: Mon, 29 Oct 2012 15:47:25 +0000 Subject: [PATCH] st-entry: Change the pointer cursor on enter/leave events Change the pointer cursor to an i-beam when it is inside the ClutterText. https://bugzilla.gnome.org/show_bug.cgi?id=687130 --- src/st/st-entry.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/st/st-entry.c b/src/st/st-entry.c index ad9b3a84f..4cd1da6fa 100644 --- a/src/st/st-entry.c +++ b/src/st/st-entry.c @@ -65,6 +65,10 @@ #include "st-clipboard.h" #include "st-private.h" +#include +#include +#include + #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) @@ -613,6 +617,38 @@ st_entry_key_focus_in (ClutterActor *actor) clutter_actor_grab_key_focus (priv->entry); } +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); + 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); +} + +static gboolean +st_entry_crossing_event (ClutterActor *actor, + ClutterCrossingEvent *event) +{ + if (event->source == ST_ENTRY (actor)->priv->entry && event->related != NULL) + st_entry_set_cursor (ST_ENTRY (actor), (event->type == CLUTTER_ENTER)); + + return FALSE; +} + static void st_entry_class_init (StEntryClass *klass) { @@ -635,6 +671,9 @@ st_entry_class_init (StEntryClass *klass) actor_class->key_press_event = st_entry_key_press_event; actor_class->key_focus_in = st_entry_key_focus_in; + actor_class->enter_event = st_entry_crossing_event; + actor_class->leave_event = st_entry_crossing_event; + widget_class->style_changed = st_entry_style_changed; widget_class->navigate_focus = st_entry_navigate_focus; widget_class->get_accessible_type = st_entry_accessible_get_type;