Nux

Merge lp:~azzar1/nux/please-dont-focus-me-on-mouse-down into lp:nux/2.0

Proposed by Andrea Azzarone
Status: Merged
Approved by: Jay Taoko
Approved revision: 533
Merged at revision: 533
Proposed branch: lp:~azzar1/nux/please-dont-focus-me-on-mouse-down
Merge into: lp:nux/2.0
Diff against target: 326 lines (+193/-5)
8 files modified
Nux/BaseWindow.cpp (+2/-0)
Nux/InputArea.cpp (+11/-0)
Nux/InputArea.h (+4/-0)
Nux/WindowCompositor.cpp (+1/-1)
configure.ac (+1/-1)
tests/Makefile.am (+15/-2)
tests/Readme.txt (+2/-1)
tests/focus-on-mouse-down-test.cpp (+157/-0)
To merge this branch: bzr merge lp:~azzar1/nux/please-dont-focus-me-on-mouse-down
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Tim Penhey (community) Approve
Review via email: mp+86175@code.launchpad.net

Description of the change

Adds a way to disable the focus on mouse down behaviour. Adds a simple test too.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Looks good.

review: Approve
Revision history for this message
Jay Taoko (jaytaoko) wrote :

There is no need to have Area::AcceptKeyNavFocusOnMouseDown use GetInputEventSensitivity().
Area::AcceptKeyNavFocus() uses GetInputEventSensitivity() already.

I propose the following

class InputArea
{

  virtual bool AcceptKeyNavFocusOnMouseDown();
  void SetAcceptKeyNavFocusOnMouseDown(bool accept);

  bool accept_key_nav_focus_on_mouse_down_;
}

InputArea::InputArea()
{
  accept_key_nav_focus_on_mouse_down_ = true;
}

bool InputArea::AcceptKeyNavFocusOnMouseDown()
{
  return accept_key_nav_focus_on_mouse_down_;
}

void InputArea::SetAcceptKeyNavFocusOnMouseDown(bool accept)
{
  accept_key_nav_focus_on_mouse_down_ = accept;
}

BaseWindow::BaseWindow(...)
{

  SetAcceptKeyNavFocusOnMouseDown(false);

}

That way we can also get other Views to not get the focus on mouse down events if there is a need for it. Not just BaseWindows. Let me know if this still works with your branch.

There is a similar problem with InputArea::AcceptKeyNavFocus(). I will re-factor it to work like SetAcceptKeyNavFocusOnMouseDown.

review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) wrote :

Done.

530. By Andrea Azzarone

Makes sure that the scroll wheel works with nux::VScrollbar. Fixes: https://bugs.launchpad.net/bugs/888819. Appoved by Jay Taoko.

531. By Jay Taoko

Added separate file for GLib main loop functions
* Cleanup: variable renaming
* Marked some functions as obsolete
* Core objects take the WindowThread as a constructor parameters: Painter, WindowCompositor.... Fixes: . Appoved by Jason Smith.

532. By Jay Taoko

* Removed API:
   GraphicsDisplay& GetWindow();
   GraphicsEngine& GetGraphicsEngine();
   NThread* GetThreadApplication();
   WindowThread* GetGraphicsThread();

* Modified code to to use GetWindowThread() to access its internal objects.

* Added tests:
   - WindowThread
   - StaticText
. Fixes: . Appoved by Jason Smith.

533. By Andrea Azzarone

Adds the possiblity to don't get the focus on mouse down.

Revision history for this message
Jay Taoko (jaytaoko) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/BaseWindow.cpp'
2--- Nux/BaseWindow.cpp 2011-12-06 16:29:06 +0000
3+++ Nux/BaseWindow.cpp 2012-01-03 14:49:27 +0000
4@@ -68,6 +68,8 @@
5 _entering_hidden_state = false;
6 _enter_focus_input_area = NULL;
7 accept_key_nav_focus_ = false;
8+
9+ SetAcceptKeyNavFocusOnMouseDown(false);
10
11 // Should be at the end of the constructor
12 GetWindowThread()->GetWindowCompositor().RegisterWindow(this);
13
14=== modified file 'Nux/InputArea.cpp'
15--- Nux/InputArea.cpp 2011-12-06 22:44:57 +0000
16+++ Nux/InputArea.cpp 2012-01-03 14:49:27 +0000
17@@ -43,6 +43,7 @@
18 InputArea::InputArea(NUX_FILE_LINE_DECL)
19 : Area(NUX_FILE_LINE_PARAM)
20 , m_AreaColor(color::Green)
21+ , accept_key_nav_focus_on_mouse_down_(true)
22 {
23 SetGeometry(0, 0, 1, 1);
24 _has_keyboard_focus = false;
25@@ -82,6 +83,11 @@
26 {
27 _has_keyboard_focus = b;
28 }
29+
30+ void InputArea::SetAcceptKeyNavFocusOnMouseDown(bool accept)
31+ {
32+ accept_key_nav_focus_on_mouse_down_ = accept;
33+ }
34
35 int InputArea::GetMouseX()
36 {
37@@ -418,5 +424,10 @@
38 {
39 return false;
40 }
41+
42+ bool InputArea::AcceptKeyNavFocusOnMouseDown()
43+ {
44+ return accept_key_nav_focus_on_mouse_down_;
45+ }
46 }
47
48
49=== modified file 'Nux/InputArea.h'
50--- Nux/InputArea.h 2011-10-17 21:23:50 +0000
51+++ Nux/InputArea.h 2012-01-03 14:49:27 +0000
52@@ -61,6 +61,7 @@
53
54 bool HasKeyboardFocus();
55 void SetKeyboardFocus(bool b);
56+ void SetAcceptKeyNavFocusOnMouseDown(bool accept);
57 int GetMouseX();
58 int GetMouseY();
59
60@@ -154,6 +155,8 @@
61
62 int _dnd_safety_x;
63 int _dnd_safety_y;
64+
65+ bool accept_key_nav_focus_on_mouse_down_;
66
67 protected:
68
69@@ -314,6 +317,7 @@
70 protected:
71
72 virtual bool AcceptKeyNavFocus();
73+ virtual bool AcceptKeyNavFocusOnMouseDown();
74
75 // == Signals with 1 to 1 mapping to input device ==
76 virtual void EmitMouseDownSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
77
78=== modified file 'Nux/WindowCompositor.cpp'
79--- Nux/WindowCompositor.cpp 2011-12-29 18:06:53 +0000
80+++ Nux/WindowCompositor.cpp 2012-01-03 14:49:27 +0000
81@@ -473,7 +473,7 @@
82 // In the case of a mouse down event, if there is currently a keyboard event receiver and it is different
83 // from the area returned by GetAreaUnderMouse, then stop that receiver from receiving anymore keyboard events and switch
84 // make mouse_over_area_ the new receiver(if it accept keyboard events).
85- if (mouse_over_area_ != GetKeyFocusArea())
86+ if (mouse_over_area_ != GetKeyFocusArea() and mouse_over_area_->AcceptKeyNavFocusOnMouseDown())
87 {
88 InputArea* grab_area = GetKeyboardGrabArea();
89 if (grab_area)
90
91=== modified file 'configure.ac'
92--- configure.ac 2012-01-03 03:10:54 +0000
93+++ configure.ac 2012-01-03 14:49:27 +0000
94@@ -22,7 +22,7 @@
95 # The number format is : year/month/day
96 # e.g.: december 5th, 2011 is: 20111205
97 # So far there is no provision for more than one break in a day.
98-m4_define([nux_abi_version], [20111211])
99+m4_define([nux_abi_version], [20111212])
100
101 m4_define([nux_version],
102 [nux_major_version.nux_minor_version.nux_micro_version])
103
104=== modified file 'tests/Makefile.am'
105--- tests/Makefile.am 2012-01-03 03:10:54 +0000
106+++ tests/Makefile.am 2012-01-03 14:49:27 +0000
107@@ -11,7 +11,8 @@
108 hgrid-key-navigation-test \
109 hlayout-key-navigation-test \
110 vlayout-key-navigation-test \
111- scrollbar-test
112+ scrollbar-test \
113+ focus-on-mouse-down-test
114
115 # Please keep alphabetical
116 test_nux_SOURCES = \
117@@ -208,6 +209,17 @@
118 vlayout_key_navigation_test_LDADD = $(TestLibs)
119 vlayout_key_navigation_test_LDFLAGS = -lpthread -lXtst
120
121+focus_on_mouse_down_test_SOURCES = focus-on-mouse-down-test.cpp \
122+ nux_test_framework.cpp \
123+ nux_test_framework.h \
124+ nux_automated_test_framework.cpp \
125+ nux_automated_test_framework.h \
126+ test-view.cpp \
127+ test-view.h
128+
129+focus_on_mouse_down_test_CPPFLAGS = $(TestFlags)
130+focus_on_mouse_down_test_LDADD = $(TestLibs)
131+focus_on_mouse_down_test_LDFLAGS = -lpthread -lXtst
132
133 scrollbar_test_SOURCES = scrollbar-test.cpp \
134 nux_test_framework.cpp \
135@@ -234,7 +246,7 @@
136 ./gtest-nux-core
137 ./gtest-nux
138
139-test-apps: test-graphics-display test-empty-window button-xtest mouse-events-test mouse-buttons-test hgrid-key-navigation-test hlayout-key-navigation-test vlayout-key-navigation-test scrollbar-test
140+test-apps: test-graphics-display test-empty-window button-xtest mouse-events-test mouse-buttons-test hgrid-key-navigation-test hlayout-key-navigation-test vlayout-key-navigation-test scrollbar-test focus-on-mouse-down-test
141 ./test-graphics-display
142 ./test-empty-window
143 ./button-xtest
144@@ -244,6 +256,7 @@
145 ./hlayout-key-navigation-test
146 ./vlayout-key-navigation-test
147 ./scrollbar-test
148+ ./focus-on-mouse-down-test
149
150 check-report:
151 @gtester -k -o=test-nux-results.xml -k ./test-nux \
152
153=== modified file 'tests/Readme.txt'
154--- tests/Readme.txt 2011-12-12 07:21:11 +0000
155+++ tests/Readme.txt 2012-01-03 14:49:27 +0000
156@@ -42,6 +42,7 @@
157 vlayout_key_navigation_test
158 Make sure that the key navigation works well in a VLayout.
159
160-
161+focus_on_mouse_down_test
162+ Make sure that AcceptKeyNavFocusOnMouseDown works well.
163
164
165
166=== added file 'tests/focus-on-mouse-down-test.cpp'
167--- tests/focus-on-mouse-down-test.cpp 1970-01-01 00:00:00 +0000
168+++ tests/focus-on-mouse-down-test.cpp 2012-01-03 14:49:27 +0000
169@@ -0,0 +1,157 @@
170+/*
171+ * Copyright 2011 Inalogic Inc.
172+ *
173+ * This program is free software: you can redistribute it and/or modify it
174+ * under the terms of the GNU General Public License version 3, as published
175+ * by the Free Software Foundation.
176+ *
177+ * This program is distributed in the hope that it will be useful, but
178+ * WITHOUT ANY WARRANTY; without even the implied warranties of
179+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
180+ * PURPOSE. See the GNU General Public License for more details.
181+ *
182+ * You should have received a copy of the GNU General Public License
183+ * version 3 along with this program. If not, see
184+ * <http://www.gnu.org/licenses/>
185+ *
186+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
187+ *
188+ */
189+
190+#include "Nux/Nux.h"
191+#include "Nux/WindowThread.h"
192+#include "Nux/VLayout.h"
193+#include <X11/extensions/XTest.h>
194+#include <X11/keysym.h>
195+#include "nux_test_framework.h"
196+#include "nux_automated_test_framework.h"
197+#include "test-view.h"
198+
199+class FocusOnMouseDownTest: public NuxTestFramework
200+{
201+public:
202+ FocusOnMouseDownTest(const char *program_name, int window_width, int window_height, int program_life_span);
203+ ~FocusOnMouseDownTest();
204+
205+ virtual void UserInterfaceSetup();
206+
207+ TestView* focus_view_;
208+ TestView* no_focus_view_;
209+};
210+
211+FocusOnMouseDownTest::FocusOnMouseDownTest(const char* program_name,
212+ int window_width,
213+ int window_height,
214+ int program_life_span)
215+ : NuxTestFramework(program_name, window_width, window_height, program_life_span)
216+ , focus_view_(nullptr)
217+ , no_focus_view_(nullptr)
218+{
219+}
220+
221+FocusOnMouseDownTest::~FocusOnMouseDownTest()
222+{
223+}
224+
225+void FocusOnMouseDownTest::UserInterfaceSetup()
226+{
227+ nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
228+ main_layout->SetSpaceBetweenChildren(10);
229+ main_layout->SetPadding(10, 10);
230+
231+ focus_view_ = new TestView(NUX_TRACKER_LOCATION);
232+ focus_view_->can_focus_ = true;
233+ focus_view_->SetAcceptKeyNavFocusOnMouseDown(true);
234+ main_layout->AddView(focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
235+
236+ no_focus_view_ = new TestView(NUX_TRACKER_LOCATION);
237+ no_focus_view_->can_focus_ = true;
238+ no_focus_view_->SetAcceptKeyNavFocusOnMouseDown(false);
239+ main_layout->AddView(no_focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
240+
241+ static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout);
242+
243+ nux::ColorLayer background(nux::Color(0xFF4D4D4D));
244+ static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
245+}
246+
247+FocusOnMouseDownTest* focus_on_mouse_down_test = nullptr;
248+
249+void TestingThread(nux::NThread* thread, void* user_data)
250+{
251+ while (focus_on_mouse_down_test->ReadyToGo() == false)
252+ {
253+ nuxDebugMsg("Waiting to start");
254+ nux::SleepForMilliseconds(300);
255+ }
256+
257+ nux::SleepForMilliseconds(1000);
258+
259+ nux::WindowThread *wnd_thread = static_cast<nux::WindowThread*>(user_data);
260+
261+ NuxAutomatedTestFramework test(wnd_thread);
262+
263+ test.Startup();
264+
265+ // Set the mouse at coordinates (0, 0) (top-left corner) on the display
266+ test.PutMouseAt(0, 0);
267+
268+ test.TestReportMsg(focus_on_mouse_down_test->focus_view_, "Focus view created");
269+ test.TestReportMsg(focus_on_mouse_down_test->no_focus_view_, "No focus view created");
270+
271+ // Move mouse to center of focus_view
272+ test.ViewSendMouseMotionToCenter(focus_on_mouse_down_test->focus_view_);
273+
274+ // Mouse down/up on focus_view_
275+ test.ViewSendMouseClick(focus_on_mouse_down_test->focus_view_, 1);
276+ nux::SleepForMilliseconds(500);
277+ test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse down: focus_view_ got the focus");
278+ test.ViewSendMouseUp(focus_on_mouse_down_test->focus_view_, 1);
279+ nux::SleepForMilliseconds(500);
280+ test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse up: focus is still on focus_view_");
281+
282+ // Move mouse to center of no_focus_view
283+ test.ViewSendMouseMotionToCenter(focus_on_mouse_down_test->no_focus_view_);
284+
285+ // Mouse down/up on no_focus_view_
286+ test.ViewSendMouseDown(focus_on_mouse_down_test->no_focus_view_, 1);
287+ nux::SleepForMilliseconds(500);
288+ test.TestReportMsg(!focus_on_mouse_down_test->no_focus_view_->has_focus_, "Mouse down: no_focus_view_ did not take the focus");
289+ test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse down: focus is still on focus_view_");
290+ test.ViewSendMouseUp(focus_on_mouse_down_test->no_focus_view_, 1);
291+ nux::SleepForMilliseconds(500);
292+ test.TestReportMsg(!focus_on_mouse_down_test->no_focus_view_->has_focus_, "Mouse up: no_focus_view_ still doesn't have the focus");
293+ test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse up: focus is still on focus_view_");
294+
295+
296+ if (test.WhenDoneTerminateProgram())
297+ {
298+ nux::SleepForMilliseconds(1000);
299+ wnd_thread->ExitMainLoop();
300+ }
301+ nuxDebugMsg("Exit testing thread");
302+}
303+
304+int main(int argc, char **argv)
305+{
306+ int xstatus = XInitThreads();
307+ nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
308+
309+ focus_on_mouse_down_test = new FocusOnMouseDownTest("Focus On Mouse Down Test", 300, 300, 15000);
310+ focus_on_mouse_down_test->Startup();
311+ focus_on_mouse_down_test->UserInterfaceSetup();
312+
313+ nux::SystemThread *test_thread = nux::CreateSystemThread(focus_on_mouse_down_test->GetWindowThread(),
314+ &TestingThread,
315+ focus_on_mouse_down_test->GetWindowThread());
316+
317+ test_thread->Start(focus_on_mouse_down_test);
318+
319+ focus_on_mouse_down_test->Run();
320+
321+ delete test_thread;
322+ delete focus_on_mouse_down_test;
323+
324+ return 0;
325+}
326+

Subscribers

People subscribed via source and target branches

to all changes: