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
=== modified file 'Nux/BaseWindow.cpp'
--- Nux/BaseWindow.cpp 2011-12-06 16:29:06 +0000
+++ Nux/BaseWindow.cpp 2012-01-03 14:49:27 +0000
@@ -68,6 +68,8 @@
68 _entering_hidden_state = false;68 _entering_hidden_state = false;
69 _enter_focus_input_area = NULL;69 _enter_focus_input_area = NULL;
70 accept_key_nav_focus_ = false;70 accept_key_nav_focus_ = false;
71
72 SetAcceptKeyNavFocusOnMouseDown(false);
7173
72 // Should be at the end of the constructor74 // Should be at the end of the constructor
73 GetWindowThread()->GetWindowCompositor().RegisterWindow(this);75 GetWindowThread()->GetWindowCompositor().RegisterWindow(this);
7476
=== modified file 'Nux/InputArea.cpp'
--- Nux/InputArea.cpp 2011-12-06 22:44:57 +0000
+++ Nux/InputArea.cpp 2012-01-03 14:49:27 +0000
@@ -43,6 +43,7 @@
43 InputArea::InputArea(NUX_FILE_LINE_DECL)43 InputArea::InputArea(NUX_FILE_LINE_DECL)
44 : Area(NUX_FILE_LINE_PARAM)44 : Area(NUX_FILE_LINE_PARAM)
45 , m_AreaColor(color::Green)45 , m_AreaColor(color::Green)
46 , accept_key_nav_focus_on_mouse_down_(true)
46 {47 {
47 SetGeometry(0, 0, 1, 1);48 SetGeometry(0, 0, 1, 1);
48 _has_keyboard_focus = false;49 _has_keyboard_focus = false;
@@ -82,6 +83,11 @@
82 {83 {
83 _has_keyboard_focus = b;84 _has_keyboard_focus = b;
84 }85 }
86
87 void InputArea::SetAcceptKeyNavFocusOnMouseDown(bool accept)
88 {
89 accept_key_nav_focus_on_mouse_down_ = accept;
90 }
8591
86 int InputArea::GetMouseX()92 int InputArea::GetMouseX()
87 {93 {
@@ -418,5 +424,10 @@
418 {424 {
419 return false;425 return false;
420 }426 }
427
428 bool InputArea::AcceptKeyNavFocusOnMouseDown()
429 {
430 return accept_key_nav_focus_on_mouse_down_;
431 }
421}432}
422433
423434
=== modified file 'Nux/InputArea.h'
--- Nux/InputArea.h 2011-10-17 21:23:50 +0000
+++ Nux/InputArea.h 2012-01-03 14:49:27 +0000
@@ -61,6 +61,7 @@
6161
62 bool HasKeyboardFocus();62 bool HasKeyboardFocus();
63 void SetKeyboardFocus(bool b);63 void SetKeyboardFocus(bool b);
64 void SetAcceptKeyNavFocusOnMouseDown(bool accept);
64 int GetMouseX();65 int GetMouseX();
65 int GetMouseY();66 int GetMouseY();
66 67
@@ -154,6 +155,8 @@
154 155
155 int _dnd_safety_x;156 int _dnd_safety_x;
156 int _dnd_safety_y;157 int _dnd_safety_y;
158
159 bool accept_key_nav_focus_on_mouse_down_;
157160
158 protected:161 protected:
159162
@@ -314,6 +317,7 @@
314 protected:317 protected:
315318
316 virtual bool AcceptKeyNavFocus();319 virtual bool AcceptKeyNavFocus();
320 virtual bool AcceptKeyNavFocusOnMouseDown();
317321
318 // == Signals with 1 to 1 mapping to input device ==322 // == Signals with 1 to 1 mapping to input device ==
319 virtual void EmitMouseDownSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);323 virtual void EmitMouseDownSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
320324
=== modified file 'Nux/WindowCompositor.cpp'
--- Nux/WindowCompositor.cpp 2011-12-29 18:06:53 +0000
+++ Nux/WindowCompositor.cpp 2012-01-03 14:49:27 +0000
@@ -473,7 +473,7 @@
473 // In the case of a mouse down event, if there is currently a keyboard event receiver and it is different473 // In the case of a mouse down event, if there is currently a keyboard event receiver and it is different
474 // from the area returned by GetAreaUnderMouse, then stop that receiver from receiving anymore keyboard events and switch474 // from the area returned by GetAreaUnderMouse, then stop that receiver from receiving anymore keyboard events and switch
475 // make mouse_over_area_ the new receiver(if it accept keyboard events).475 // make mouse_over_area_ the new receiver(if it accept keyboard events).
476 if (mouse_over_area_ != GetKeyFocusArea())476 if (mouse_over_area_ != GetKeyFocusArea() and mouse_over_area_->AcceptKeyNavFocusOnMouseDown())
477 {477 {
478 InputArea* grab_area = GetKeyboardGrabArea();478 InputArea* grab_area = GetKeyboardGrabArea();
479 if (grab_area)479 if (grab_area)
480480
=== modified file 'configure.ac'
--- configure.ac 2012-01-03 03:10:54 +0000
+++ configure.ac 2012-01-03 14:49:27 +0000
@@ -22,7 +22,7 @@
22# The number format is : year/month/day22# The number format is : year/month/day
23# e.g.: december 5th, 2011 is: 2011120523# e.g.: december 5th, 2011 is: 20111205
24# So far there is no provision for more than one break in a day.24# So far there is no provision for more than one break in a day.
25m4_define([nux_abi_version], [20111211])25m4_define([nux_abi_version], [20111212])
2626
27m4_define([nux_version],27m4_define([nux_version],
28 [nux_major_version.nux_minor_version.nux_micro_version])28 [nux_major_version.nux_minor_version.nux_micro_version])
2929
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2012-01-03 03:10:54 +0000
+++ tests/Makefile.am 2012-01-03 14:49:27 +0000
@@ -11,7 +11,8 @@
11 hgrid-key-navigation-test \11 hgrid-key-navigation-test \
12 hlayout-key-navigation-test \12 hlayout-key-navigation-test \
13 vlayout-key-navigation-test \13 vlayout-key-navigation-test \
14 scrollbar-test14 scrollbar-test \
15 focus-on-mouse-down-test
1516
16# Please keep alphabetical17# Please keep alphabetical
17test_nux_SOURCES = \18test_nux_SOURCES = \
@@ -208,6 +209,17 @@
208vlayout_key_navigation_test_LDADD = $(TestLibs)209vlayout_key_navigation_test_LDADD = $(TestLibs)
209vlayout_key_navigation_test_LDFLAGS = -lpthread -lXtst210vlayout_key_navigation_test_LDFLAGS = -lpthread -lXtst
210211
212focus_on_mouse_down_test_SOURCES = focus-on-mouse-down-test.cpp \
213 nux_test_framework.cpp \
214 nux_test_framework.h \
215 nux_automated_test_framework.cpp \
216 nux_automated_test_framework.h \
217 test-view.cpp \
218 test-view.h
219
220focus_on_mouse_down_test_CPPFLAGS = $(TestFlags)
221focus_on_mouse_down_test_LDADD = $(TestLibs)
222focus_on_mouse_down_test_LDFLAGS = -lpthread -lXtst
211223
212scrollbar_test_SOURCES = scrollbar-test.cpp \224scrollbar_test_SOURCES = scrollbar-test.cpp \
213 nux_test_framework.cpp \225 nux_test_framework.cpp \
@@ -234,7 +246,7 @@
234 ./gtest-nux-core246 ./gtest-nux-core
235 ./gtest-nux247 ./gtest-nux
236248
237test-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-test249test-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
238 ./test-graphics-display250 ./test-graphics-display
239 ./test-empty-window251 ./test-empty-window
240 ./button-xtest252 ./button-xtest
@@ -244,6 +256,7 @@
244 ./hlayout-key-navigation-test256 ./hlayout-key-navigation-test
245 ./vlayout-key-navigation-test257 ./vlayout-key-navigation-test
246 ./scrollbar-test258 ./scrollbar-test
259 ./focus-on-mouse-down-test
247260
248check-report:261check-report:
249 @gtester -k -o=test-nux-results.xml -k ./test-nux \262 @gtester -k -o=test-nux-results.xml -k ./test-nux \
250263
=== modified file 'tests/Readme.txt'
--- tests/Readme.txt 2011-12-12 07:21:11 +0000
+++ tests/Readme.txt 2012-01-03 14:49:27 +0000
@@ -42,6 +42,7 @@
42vlayout_key_navigation_test42vlayout_key_navigation_test
43 Make sure that the key navigation works well in a VLayout.43 Make sure that the key navigation works well in a VLayout.
4444
4545focus_on_mouse_down_test
46 Make sure that AcceptKeyNavFocusOnMouseDown works well.
4647
4748
4849
=== added file 'tests/focus-on-mouse-down-test.cpp'
--- tests/focus-on-mouse-down-test.cpp 1970-01-01 00:00:00 +0000
+++ tests/focus-on-mouse-down-test.cpp 2012-01-03 14:49:27 +0000
@@ -0,0 +1,157 @@
1/*
2 * Copyright 2011 Inalogic Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 *
19 */
20
21#include "Nux/Nux.h"
22#include "Nux/WindowThread.h"
23#include "Nux/VLayout.h"
24#include <X11/extensions/XTest.h>
25#include <X11/keysym.h>
26#include "nux_test_framework.h"
27#include "nux_automated_test_framework.h"
28#include "test-view.h"
29
30class FocusOnMouseDownTest: public NuxTestFramework
31{
32public:
33 FocusOnMouseDownTest(const char *program_name, int window_width, int window_height, int program_life_span);
34 ~FocusOnMouseDownTest();
35
36 virtual void UserInterfaceSetup();
37
38 TestView* focus_view_;
39 TestView* no_focus_view_;
40};
41
42FocusOnMouseDownTest::FocusOnMouseDownTest(const char* program_name,
43 int window_width,
44 int window_height,
45 int program_life_span)
46 : NuxTestFramework(program_name, window_width, window_height, program_life_span)
47 , focus_view_(nullptr)
48 , no_focus_view_(nullptr)
49{
50}
51
52FocusOnMouseDownTest::~FocusOnMouseDownTest()
53{
54}
55
56void FocusOnMouseDownTest::UserInterfaceSetup()
57{
58 nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
59 main_layout->SetSpaceBetweenChildren(10);
60 main_layout->SetPadding(10, 10);
61
62 focus_view_ = new TestView(NUX_TRACKER_LOCATION);
63 focus_view_->can_focus_ = true;
64 focus_view_->SetAcceptKeyNavFocusOnMouseDown(true);
65 main_layout->AddView(focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
66
67 no_focus_view_ = new TestView(NUX_TRACKER_LOCATION);
68 no_focus_view_->can_focus_ = true;
69 no_focus_view_->SetAcceptKeyNavFocusOnMouseDown(false);
70 main_layout->AddView(no_focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
71
72 static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout);
73
74 nux::ColorLayer background(nux::Color(0xFF4D4D4D));
75 static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
76}
77
78FocusOnMouseDownTest* focus_on_mouse_down_test = nullptr;
79
80void TestingThread(nux::NThread* thread, void* user_data)
81{
82 while (focus_on_mouse_down_test->ReadyToGo() == false)
83 {
84 nuxDebugMsg("Waiting to start");
85 nux::SleepForMilliseconds(300);
86 }
87
88 nux::SleepForMilliseconds(1000);
89
90 nux::WindowThread *wnd_thread = static_cast<nux::WindowThread*>(user_data);
91
92 NuxAutomatedTestFramework test(wnd_thread);
93
94 test.Startup();
95
96 // Set the mouse at coordinates (0, 0) (top-left corner) on the display
97 test.PutMouseAt(0, 0);
98
99 test.TestReportMsg(focus_on_mouse_down_test->focus_view_, "Focus view created");
100 test.TestReportMsg(focus_on_mouse_down_test->no_focus_view_, "No focus view created");
101
102 // Move mouse to center of focus_view
103 test.ViewSendMouseMotionToCenter(focus_on_mouse_down_test->focus_view_);
104
105 // Mouse down/up on focus_view_
106 test.ViewSendMouseClick(focus_on_mouse_down_test->focus_view_, 1);
107 nux::SleepForMilliseconds(500);
108 test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse down: focus_view_ got the focus");
109 test.ViewSendMouseUp(focus_on_mouse_down_test->focus_view_, 1);
110 nux::SleepForMilliseconds(500);
111 test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse up: focus is still on focus_view_");
112
113 // Move mouse to center of no_focus_view
114 test.ViewSendMouseMotionToCenter(focus_on_mouse_down_test->no_focus_view_);
115
116 // Mouse down/up on no_focus_view_
117 test.ViewSendMouseDown(focus_on_mouse_down_test->no_focus_view_, 1);
118 nux::SleepForMilliseconds(500);
119 test.TestReportMsg(!focus_on_mouse_down_test->no_focus_view_->has_focus_, "Mouse down: no_focus_view_ did not take the focus");
120 test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse down: focus is still on focus_view_");
121 test.ViewSendMouseUp(focus_on_mouse_down_test->no_focus_view_, 1);
122 nux::SleepForMilliseconds(500);
123 test.TestReportMsg(!focus_on_mouse_down_test->no_focus_view_->has_focus_, "Mouse up: no_focus_view_ still doesn't have the focus");
124 test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse up: focus is still on focus_view_");
125
126
127 if (test.WhenDoneTerminateProgram())
128 {
129 nux::SleepForMilliseconds(1000);
130 wnd_thread->ExitMainLoop();
131 }
132 nuxDebugMsg("Exit testing thread");
133}
134
135int main(int argc, char **argv)
136{
137 int xstatus = XInitThreads();
138 nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
139
140 focus_on_mouse_down_test = new FocusOnMouseDownTest("Focus On Mouse Down Test", 300, 300, 15000);
141 focus_on_mouse_down_test->Startup();
142 focus_on_mouse_down_test->UserInterfaceSetup();
143
144 nux::SystemThread *test_thread = nux::CreateSystemThread(focus_on_mouse_down_test->GetWindowThread(),
145 &TestingThread,
146 focus_on_mouse_down_test->GetWindowThread());
147
148 test_thread->Start(focus_on_mouse_down_test);
149
150 focus_on_mouse_down_test->Run();
151
152 delete test_thread;
153 delete focus_on_mouse_down_test;
154
155 return 0;
156}
157

Subscribers

People subscribed via source and target branches

to all changes: