Nux

Merge lp:~3v1n0/nux/textentry-toggle-cursor-visibility into lp:nux

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 840
Merged at revision: 840
Proposed branch: lp:~3v1n0/nux/textentry-toggle-cursor-visibility
Merge into: lp:nux
Diff against target: 97 lines (+49/-0)
2 files modified
Nux/TextEntry.cpp (+46/-0)
Nux/TextEntry.h (+3/-0)
To merge this branch: bzr merge lp:~3v1n0/nux/textentry-toggle-cursor-visibility
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+209488@code.launchpad.net

Commit message

TextEntry: add setter/getter to make the cursor visible only on key focus

When the toggle is false, the text entry cursor is shown only if the area
is key-focused.

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/TextEntry.cpp'
2--- Nux/TextEntry.cpp 2013-12-18 21:43:30 +0000
3+++ Nux/TextEntry.cpp 2014-03-05 16:14:40 +0000
4@@ -179,6 +179,7 @@
5 , key_nav_mode_(false)
6 , lose_key_focus_on_key_nav_direction_up_(true)
7 , lose_key_focus_on_key_nav_direction_down_(true)
8+ , cursor_visible_on_key_focus_only_(false)
9 {
10 cairo_font_options_set_antialias(font_options_, CAIRO_ANTIALIAS_SUBPIXEL);
11 cairo_font_options_set_hint_style(font_options_, CAIRO_HINT_STYLE_FULL);
12@@ -914,6 +915,13 @@
13 cursor_visible_ = false; // hide cursor when losing focus
14 selection_changed_ = true;
15 cursor_moved_ = true;
16+
17+ if (cursor_visible_on_key_focus_only_ && cursor_blink_timer_)
18+ {
19+ g_source_remove(cursor_blink_timer_);
20+ cursor_blink_timer_ = 0;
21+ }
22+
23 // Don't adjust scroll.
24 QueueRefresh(true, false);
25 }
26@@ -1144,6 +1152,9 @@
27
28 void TextEntry::QueueCursorBlink()
29 {
30+ if (cursor_visible_on_key_focus_only_ && !focused_)
31+ return;
32+
33 if (!cursor_blink_timer_)
34 cursor_blink_timer_ = g_timeout_add(kCursorBlinkTimeout,
35 (GSourceFunc)&CursorBlinkCallback,
36@@ -2517,6 +2528,41 @@
37 return lose_key_focus_on_key_nav_direction_down_;
38 }
39
40+ void TextEntry::SetToggleCursorVisibilityOnKeyFocus(bool b)
41+ {
42+ if (cursor_visible_on_key_focus_only_ == b)
43+ return;
44+
45+ cursor_visible_on_key_focus_only_ = b;
46+
47+ if (cursor_visible_on_key_focus_only_)
48+ {
49+ if (!focused_)
50+ {
51+ if (cursor_blink_timer_)
52+ {
53+ g_source_remove(cursor_blink_timer_);
54+ cursor_blink_timer_ = 0;
55+ }
56+
57+ cursor_visible_ = false;
58+ QueueDraw();
59+ }
60+ }
61+ else
62+ {
63+ if (!focused_)
64+ {
65+ QueueCursorBlink();
66+ }
67+ }
68+ }
69+
70+ bool TextEntry::GetToggleCursorVisibilityOnKeyFocus() const
71+ {
72+ return cursor_visible_on_key_focus_only_;
73+ }
74+
75 bool TextEntry::IsInTextInputMode() const
76 {
77 return text_input_mode_;
78
79=== modified file 'Nux/TextEntry.h'
80--- Nux/TextEntry.h 2013-12-18 21:43:30 +0000
81+++ Nux/TextEntry.h 2014-03-05 16:14:40 +0000
82@@ -173,6 +173,8 @@
83 void MoveCursorToLineStart();
84 void MoveCursorToLineEnd();
85
86+ void SetToggleCursorVisibilityOnKeyFocus(bool b);
87+ bool GetToggleCursorVisibilityOnKeyFocus() const;
88
89 /*!
90 When the text entry is in single line mode, the keyboard arrow up/down may be used
91@@ -511,6 +513,7 @@
92
93 bool lose_key_focus_on_key_nav_direction_up_;
94 bool lose_key_focus_on_key_nav_direction_down_;
95+ bool cursor_visible_on_key_focus_only_;
96
97 std::vector<unsigned long> composition_list_;
98

Subscribers

People subscribed via source and target branches