Nux

Merge lp:~njpatel/nux/input-area-ungrab-on-destroy-3.0 into lp:nux/3.0

Proposed by Neil J. Patel
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 654
Merged at revision: 655
Proposed branch: lp:~njpatel/nux/input-area-ungrab-on-destroy-3.0
Merge into: lp:nux/3.0
Diff against target: 114 lines (+85/-1)
3 files modified
Nux/InputArea.cpp (+2/-1)
tests/Makefile.am (+1/-0)
tests/gtest-nux-input-area.cpp (+82/-0)
To merge this branch: bzr merge lp:~njpatel/nux/input-area-ungrab-on-destroy-3.0
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+125005@code.launchpad.net

Commit message

InputArea: remove the pending grabs on destroy (it could cause crash otherwise)

Description of the change

THIS IS A CROSS MERGE FROM LP:NUX TO HAVE THIS FIX IN QUANTAL

When an InputArea grabs the keyboard or the pointer and then it gets destroyed, it is not removed from the window compositor list of the grabbed areas; this could cause a crash (mostly when doing current_keyboard_grab->end_keyboard_grab.emit(current_keyboard_grab);)

I think it's safer to remove all the references of the current area from the compositor on destroy.

Gtests included.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Correctly backported! ;)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nux/InputArea.cpp'
2--- Nux/InputArea.cpp 2012-06-14 14:48:26 +0000
3+++ Nux/InputArea.cpp 2012-09-18 18:08:22 +0000
4@@ -67,9 +67,10 @@
5
6 InputArea::~InputArea()
7 {
8+ while (GetWindowCompositor().GrabPointerRemove(this));
9+ while (GetWindowCompositor().GrabKeyboardRemove(this));
10 }
11
12-
13 void InputArea::OnDraw(GraphicsEngine &graphics_engine, bool force_draw)
14 {
15 graphics_engine.QRP_Color(GetBaseX(), GetBaseY(), GetBaseWidth(), GetBaseHeight(), area_color_);
16
17=== modified file 'tests/Makefile.am'
18--- tests/Makefile.am 2012-08-13 20:48:38 +0000
19+++ tests/Makefile.am 2012-09-18 18:08:22 +0000
20@@ -77,6 +77,7 @@
21 gtest-nux-textentry.cpp \
22 gtest-nux-utils.h \
23 gtest-nux-inputmethodibus.cpp \
24+ gtest-nux-input-area.cpp \
25 gtest-nux-view.cpp \
26 gtest-nux-windowcompositor.cpp \
27 gtest-nux-windowthread.cpp
28
29=== added file 'tests/gtest-nux-input-area.cpp'
30--- tests/gtest-nux-input-area.cpp 1970-01-01 00:00:00 +0000
31+++ tests/gtest-nux-input-area.cpp 2012-09-18 18:08:22 +0000
32@@ -0,0 +1,82 @@
33+/*
34+ * Copyright 2012 Canonical Ltd.
35+ *
36+ * This program is free software: you can redistribute it and/or modify it
37+ * under the terms of the GNU Lesser General Public License version 3, as
38+ * published by the Free Software Foundation.
39+ *
40+ * This program is distributed in the hope that it will be useful, but
41+ * WITHOUT ANY WARRANTY; without even the implied warranties of
42+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
43+ * PURPOSE. See the applicable version of the GNU Lesser General Public
44+ * License for more details.
45+ *
46+ * You should have received a copy of both the GNU Lesser General Public
47+ * License version 3 along with this program. If not, see
48+ * <http://www.gnu.org/licenses/>
49+ *
50+ * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
51+ */
52+
53+#include <gmock/gmock.h>
54+#include <boost/shared_ptr.hpp>
55+#include "Nux/Nux.h"
56+
57+namespace {
58+
59+struct TestInputArea : public testing::Test
60+{
61+ void SetUp()
62+ {
63+ nux::NuxInitialize(0);
64+ wnd_thread.reset(nux::CreateNuxWindow("InputArea Test", 300, 200, nux::WINDOWSTYLE_NORMAL,
65+ NULL, false, NULL, NULL));
66+ area = new nux::InputArea("InputArea");
67+ }
68+
69+ boost::shared_ptr<nux::WindowThread> wnd_thread;
70+ nux::ObjectPtr<nux::InputArea> area;
71+};
72+
73+TEST_F(TestInputArea, GrabKeyboard)
74+{
75+ area->GrabKeyboard();
76+ EXPECT_TRUE(nux::GetWindowCompositor().IsInKeyboardGrabStack(area.GetPointer()));
77+}
78+
79+TEST_F(TestInputArea, GrabPointer)
80+{
81+ area->GrabPointer();
82+ EXPECT_TRUE(nux::GetWindowCompositor().IsInPointerGrabStack(area.GetPointer()));
83+}
84+
85+TEST_F(TestInputArea, UngrabsOnDestroy)
86+{
87+ nux::InputArea* area1 = new nux::InputArea("InputArea1");
88+ nux::InputArea* area2 = new nux::InputArea("InputArea2");
89+
90+ // Adding some grabs
91+ area1->GrabKeyboard();
92+ area1->GrabPointer();
93+ area2->GrabPointer();
94+ area2->GrabKeyboard();
95+ area1->GrabKeyboard();
96+
97+ ASSERT_TRUE(nux::GetWindowCompositor().IsInKeyboardGrabStack(area1));
98+ ASSERT_TRUE(nux::GetWindowCompositor().IsInPointerGrabStack(area1));
99+ ASSERT_TRUE(nux::GetWindowCompositor().IsInKeyboardGrabStack(area2));
100+ ASSERT_TRUE(nux::GetWindowCompositor().IsInPointerGrabStack(area2));
101+
102+ // This should cleanup the references in the compositor
103+ area1->UnReference();
104+
105+ EXPECT_FALSE(nux::GetWindowCompositor().IsInKeyboardGrabStack(area1));
106+ EXPECT_FALSE(nux::GetWindowCompositor().IsInPointerGrabStack(area1));
107+
108+ area2->UnReference();
109+
110+ EXPECT_FALSE(nux::GetWindowCompositor().IsInKeyboardGrabStack(area2));
111+ EXPECT_FALSE(nux::GetWindowCompositor().IsInPointerGrabStack(area2));
112+}
113+
114+}

Subscribers

People subscribed via source and target branches