1
From upstream SVN r16366 (trunk)
2
===================================================================
4
Stop cursor blinking after a configurable timeout.
5
(#353670, #352442, Arjan van de Ven, Manu Cornet)
7
* gtk/gtksettings.c (gtk_settings_class_init): Add a
8
gtk-cursor-blink-timeout setting, which specifies the number
9
of seconds that the cursor should blink after a user interaction.
10
The default value is G_MAXINT to preserve the current behaviour.
12
* gtk/gtkentry.c (blink_cb): Stop blinking after blink-timeout
15
* gtk/gtkentry.c (gtk_entry_completion_key_press)
16
(gtk_entry_button_press, gtk_entry_focus_in): Reset the
19
* gtk/gtktextview.c (blink_cb): Stop blinking after blink-timeout
22
* gtk/gtktextview.c (gtk_text_view_key_press_event)
23
(gtk_text_view_button_press_event, gtk_text_view_focus_in_event):
24
Reset the blink timer.
26
Index: gtk+2.0-2.10.10/gtk/gtkentry.c
27
===================================================================
28
--- gtk+2.0-2.10.10.orig/gtk/gtkentry.c 2007-03-13 14:10:39.000000000 +0100
29
+++ gtk+2.0-2.10.10/gtk/gtkentry.c 2007-03-13 14:10:42.000000000 +0100
34
+ guint blink_time; /* time in msec the cursor has blinked since last user event */
35
guint real_changed : 1;
36
guint change_count : 8;
39
GtkStateType previous_state);
40
static void gtk_entry_check_cursor_blink (GtkEntry *entry);
41
static void gtk_entry_pend_cursor_blink (GtkEntry *entry);
42
+static void gtk_entry_reset_blink_time (GtkEntry *entry);
43
static void get_text_area_size (GtkEntry *entry,
47
(entry->button && event->button != entry->button))
50
+ gtk_entry_reset_blink_time (entry);
52
entry->button = event->button;
54
if (!GTK_WIDGET_HAS_FOCUS (widget))
56
entry->drag_start_y = event->y;
59
- gtk_editable_set_position (editable, tmp_pos);
60
+ gtk_editable_set_position (editable, tmp_pos);
63
case GDK_2BUTTON_PRESS:
66
GtkEntry *entry = GTK_ENTRY (widget);
68
+ gtk_entry_reset_blink_time (entry);
69
gtk_entry_pend_cursor_blink (entry);
74
G_CALLBACK (gtk_entry_keymap_direction_changed), entry);
76
+ gtk_entry_reset_blink_time (entry);
77
gtk_entry_check_cursor_blink (entry);
80
@@ -5281,9 +5287,10 @@
81
* - the widget has focus
84
-#define CURSOR_ON_MULTIPLIER 0.66
85
-#define CURSOR_OFF_MULTIPLIER 0.34
86
-#define CURSOR_PEND_MULTIPLIER 1.0
87
+#define CURSOR_ON_MULTIPLIER 2
88
+#define CURSOR_OFF_MULTIPLIER 1
89
+#define CURSOR_PEND_MULTIPLIER 3
90
+#define CURSOR_DIVIDER 3
93
cursor_blinks (GtkEntry *entry)
94
@@ -5315,6 +5322,17 @@
99
+get_cursor_blink_timeout (GtkEntry *entry)
101
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
104
+ g_object_get (settings, "gtk-cursor-blink-timeout", &timeout, NULL);
110
show_cursor (GtkEntry *entry)
112
@@ -5346,11 +5364,14 @@
113
blink_cb (gpointer data)
116
+ GtkEntryPrivate *priv;
117
+ gint blink_timeout;
119
GDK_THREADS_ENTER ();
121
entry = GTK_ENTRY (data);
123
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
125
if (!GTK_WIDGET_HAS_FOCUS (entry))
127
g_warning ("GtkEntry - did not receive focus-out-event. If you\n"
128
@@ -5363,18 +5384,27 @@
131
g_assert (entry->selection_bound == entry->current_pos);
133
- if (entry->cursor_visible)
135
+ blink_timeout = get_cursor_blink_timeout (entry);
136
+ if (priv->blink_time > 1000 * blink_timeout &&
137
+ blink_timeout < G_MAXINT/1000)
139
+ /* we've blinked enough without the user doing anything, stop blinking */
140
+ show_cursor (entry);
141
+ entry->blink_timeout = 0;
143
+ else if (entry->cursor_visible)
146
- entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER,
147
+ entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
154
- entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER,
155
+ priv->blink_time += get_cursor_time (entry);
156
+ entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
160
@@ -5388,14 +5418,18 @@
162
gtk_entry_check_cursor_blink (GtkEntry *entry)
164
+ GtkEntryPrivate *priv;
166
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
168
if (cursor_blinks (entry))
170
if (!entry->blink_timeout)
172
- entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER,
173
+ show_cursor (entry);
174
+ entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
177
- show_cursor (entry);
181
@@ -5419,13 +5453,24 @@
182
if (entry->blink_timeout != 0)
183
g_source_remove (entry->blink_timeout);
185
- entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER,
186
+ entry->blink_timeout = g_timeout_add (get_cursor_time (entry) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
194
+gtk_entry_reset_blink_time (GtkEntry *entry)
196
+ GtkEntryPrivate *priv;
198
+ priv = GTK_ENTRY_GET_PRIVATE (entry);
200
+ priv->blink_time = 0;
206
gtk_entry_completion_timeout (gpointer data)
207
Index: gtk+2.0-2.10.10/gtk/gtksettings.c
208
===================================================================
209
--- gtk+2.0-2.10.10.orig/gtk/gtksettings.c 2007-03-12 14:50:58.000000000 +0100
210
+++ gtk+2.0-2.10.10/gtk/gtksettings.c 2007-03-13 14:10:42.000000000 +0100
212
PROP_DOUBLE_CLICK_DISTANCE,
214
PROP_CURSOR_BLINK_TIME,
215
+ PROP_CURSOR_BLINK_TIMEOUT,
218
PROP_ICON_THEME_NAME,
220
GTK_PARAM_READWRITE),
222
g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
225
+ * GtkSettings:gtk-cursor-blink:
227
+ * Whether the cursor should blink.
229
+ * Also see the gtk-cursor-blink-timeout setting, which allows
230
+ * more flexible control over cursor blinking.
232
result = settings_install_property_parser (class,
233
g_param_spec_boolean ("gtk-cursor-blink",
235
@@ -212,11 +222,31 @@
236
result = settings_install_property_parser (class,
237
g_param_spec_int ("gtk-cursor-blink-time",
238
P_("Cursor Blink Time"),
239
- P_("Length of the cursor blink cycle, in milleseconds"),
240
+ P_("Length of the cursor blink cycle, in milliseconds"),
242
GTK_PARAM_READWRITE),
244
g_assert (result == PROP_CURSOR_BLINK_TIME);
247
+ * GtkSettings:gtk-cursor-blink-timeout:
249
+ * Time after which the cursor stops blinking, in seconds.
250
+ * The timer is reset after each user interaction.
252
+ * Setting this to zero has the same effect as setting
253
+ * gtk-cursor-blinks to %FALSE.
257
+ result = settings_install_property_parser (class,
258
+ g_param_spec_int ("gtk-cursor-blink-timeout",
259
+ P_("Cursor Blink Timeout"),
260
+ P_("Time after which the cursor stops blinking, in seconds"),
261
+ 1, G_MAXINT, G_MAXINT,
262
+ GTK_PARAM_READWRITE),
264
+ g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
265
result = settings_install_property_parser (class,
266
g_param_spec_boolean ("gtk-split-cursor",
268
Index: gtk+2.0-2.10.10/gtk/gtktextview.c
269
===================================================================
270
--- gtk+2.0-2.10.10.orig/gtk/gtktextview.c 2007-03-12 14:50:26.000000000 +0100
271
+++ gtk+2.0-2.10.10/gtk/gtktextview.c 2007-03-13 14:10:42.000000000 +0100
274
#define SPACE_FOR_CURSOR 1
276
+typedef struct _GtkTextViewPrivate GtkTextViewPrivate;
278
+#define GTK_TEXT_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TEXT_VIEW, GtkTextViewPrivate))
280
+struct _GtkTextViewPrivate
282
+ guint blink_time; /* time in msec the cursor has blinked since last user event */
286
struct _GtkTextPendingScroll
290
static void gtk_text_view_check_cursor_blink (GtkTextView *text_view);
291
static void gtk_text_view_pend_cursor_blink (GtkTextView *text_view);
292
static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
293
+static void gtk_text_view_reset_blink_time (GtkTextView *text_view);
295
static void gtk_text_view_value_changed (GtkAdjustment *adj,
297
@@ -1007,6 +1018,8 @@
298
gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_SHIFT_MASK | GDK_CONTROL_MASK,
300
GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
302
+ g_type_class_add_private (gobject_class, sizeof (GtkTextViewPrivate));
306
@@ -3920,6 +3933,7 @@
308
gtk_text_view_obscure_mouse_cursor (text_view);
310
+ gtk_text_view_reset_blink_time (text_view);
311
gtk_text_view_pend_cursor_blink (text_view);
314
@@ -3963,6 +3977,8 @@
318
+ gtk_text_view_reset_blink_time (text_view);
322
if (event->button == 3 && (event->state & GDK_CONTROL_MASK) != 0)
323
@@ -4104,7 +4120,9 @@
324
gtk_widget_queue_draw (widget);
326
DV(g_print (G_STRLOC": focus_in_event\n"));
329
+ gtk_text_view_reset_blink_time (text_view);
331
if (text_view->cursor_visible && text_view->layout)
333
gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
334
@@ -4437,9 +4455,10 @@
338
-#define CURSOR_ON_MULTIPLIER 0.66
339
-#define CURSOR_OFF_MULTIPLIER 0.34
340
-#define CURSOR_PEND_MULTIPLIER 1.0
341
+#define CURSOR_ON_MULTIPLIER 2
342
+#define CURSOR_OFF_MULTIPLIER 1
343
+#define CURSOR_PEND_MULTIPLIER 3
344
+#define CURSOR_DIVIDER 3
347
cursor_blinks (GtkTextView *text_view)
348
@@ -4484,6 +4503,18 @@
353
+get_cursor_blink_timeout (GtkTextView *text_view)
355
+ GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
358
+ g_object_get (settings, "gtk-cursor-blink-timeout", &time, NULL);
367
@@ -4492,12 +4523,15 @@
368
blink_cb (gpointer data)
370
GtkTextView *text_view;
371
+ GtkTextViewPrivate *priv;
373
+ gint blink_timeout;
375
GDK_THREADS_ENTER ();
377
text_view = GTK_TEXT_VIEW (data);
379
+ priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
381
if (!GTK_WIDGET_HAS_FOCUS (text_view))
383
g_warning ("GtkTextView - did not receive focus-out-event. If you\n"
384
@@ -4514,14 +4548,25 @@
386
visible = gtk_text_layout_get_cursor_visible (text_view->layout);
389
- text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER,
393
- text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_ON_MULTIPLIER,
394
+ blink_timeout = get_cursor_blink_timeout (text_view);
395
+ if (priv->blink_time > 1000 * blink_timeout &&
396
+ blink_timeout < G_MAXINT/1000)
398
+ /* we've blinked enough without the user doing anything, stop blinking */
400
+ text_view->blink_timeout = 0;
403
+ text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
408
+ text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_ON_MULTIPLIER / CURSOR_DIVIDER,
411
+ priv->blink_time += get_cursor_time (text_view);
414
/* Block changed_handler while changing the layout's cursor visibility
415
* because it would expose the whole paragraph. Instead, we expose
416
@@ -4567,7 +4612,7 @@
418
gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
420
- text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER,
421
+ text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_OFF_MULTIPLIER / CURSOR_DIVIDER,
425
@@ -4596,12 +4641,22 @@
426
gtk_text_view_stop_cursor_blink (text_view);
427
gtk_text_layout_set_cursor_visible (text_view->layout, TRUE);
429
- text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_PEND_MULTIPLIER,
430
+ text_view->blink_timeout = g_timeout_add (get_cursor_time (text_view) * CURSOR_PEND_MULTIPLIER / CURSOR_DIVIDER,
437
+gtk_text_view_reset_blink_time (GtkTextView *text_view)
439
+ GtkTextViewPrivate *priv;
441
+ priv = GTK_TEXT_VIEW_GET_PRIVATE (text_view);
443
+ priv->blink_time = 0;
448
* Key binding handlers