Merge lp:~3v1n0/unity/panel-p-grab-area into lp:~3v1n0/unity/panel-p-window-buttons

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merge reported by: Marco Trevisan (Treviño)
Merged at revision: not available
Proposed branch: lp:~3v1n0/unity/panel-p-grab-area
Merge into: lp:~3v1n0/unity/panel-p-window-buttons
Diff against target: 247 lines (+152/-19)
2 files modified
plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp (+125/-13)
plugins/unityshell/src/PanelTitlebarGrabAreaView.h (+27/-6)
To merge this branch: bzr merge lp:~3v1n0/unity/panel-p-grab-area
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Marco Trevisan (Treviño) Pending
Review via email: mp+100124@code.launchpad.net

Description of the change

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

Looks fine.

FYI You can change the privacy scope of inherited methods, like the debug ones. It is fine for them to be private.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp'
2--- plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp 2012-02-25 16:19:39 +0000
3+++ plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp 2012-04-04 20:17:22 +0000
4@@ -1,6 +1,6 @@
5 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
6 /*
7- * Copyright (C) 2010-2011 Canonical Ltd
8+ * Copyright (C) 2010-2012 Canonical Ltd
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 3 as
12@@ -27,17 +27,41 @@
13 #include <UnityCore/Variant.h>
14 #include <X11/cursorfont.h>
15
16+namespace unity
17+{
18+namespace
19+{
20+ unsigned int MOUSE_DOWN_TIMEOUT = 150;
21+ unsigned int MOUSE_MOVEMENT_TOLERANCE = 4;
22+}
23+
24 PanelTitlebarGrabArea::PanelTitlebarGrabArea()
25 : InputArea(NUX_TRACKER_LOCATION)
26- , _grab_cursor(None)
27+ , grab_cursor_(None)
28+ , grab_started_(false)
29+ , mouse_down_timer_(0)
30+ , mouse_down_button_(0)
31 {
32 EnableDoubleClick(true);
33+
34+ mouse_down.connect(sigc::mem_fun(this, &PanelTitlebarGrabArea::OnMouseDown));
35+ mouse_up.connect(sigc::mem_fun(this, &PanelTitlebarGrabArea::OnMouseUp));
36+ mouse_drag.connect(sigc::mem_fun(this, &PanelTitlebarGrabArea::OnGrabMove));
37+
38+ mouse_double_click.connect([&] (int x, int y, unsigned long button_flags, unsigned long)
39+ {
40+ if (nux::GetEventButton(button_flags) == 1)
41+ restore_request.emit(x, y);
42+ });
43 }
44
45 PanelTitlebarGrabArea::~PanelTitlebarGrabArea()
46 {
47- if (_grab_cursor)
48- XFreeCursor(nux::GetGraphicsDisplay()->GetX11Display(), _grab_cursor);
49+ if (grab_cursor_)
50+ XFreeCursor(nux::GetGraphicsDisplay()->GetX11Display(), grab_cursor_);
51+
52+ if (mouse_down_timer_)
53+ g_source_remove(mouse_down_timer_);
54 }
55
56 void PanelTitlebarGrabArea::SetGrabbed(bool enabled)
57@@ -48,32 +72,120 @@
58 if (!panel_window || !display)
59 return;
60
61- if (enabled && !_grab_cursor)
62+ if (enabled && !grab_cursor_)
63 {
64- _grab_cursor = XCreateFontCursor(display, XC_fleur);
65- XDefineCursor(display, panel_window->GetInputWindowId(), _grab_cursor);
66+ grab_cursor_ = XCreateFontCursor(display, XC_fleur);
67+ XDefineCursor(display, panel_window->GetInputWindowId(), grab_cursor_);
68 }
69- else if (!enabled && _grab_cursor)
70+ else if (!enabled && grab_cursor_)
71 {
72 XUndefineCursor(display, panel_window->GetInputWindowId());
73- XFreeCursor(display, _grab_cursor);
74- _grab_cursor = None;
75+ XFreeCursor(display, grab_cursor_);
76+ grab_cursor_ = None;
77 }
78 }
79
80 bool PanelTitlebarGrabArea::IsGrabbed()
81 {
82- return (_grab_cursor != None);
83+ return (grab_cursor_ != None);
84+}
85+
86+void PanelTitlebarGrabArea::OnMouseDown(int x, int y, unsigned long button_flags, unsigned long)
87+{
88+ mouse_down_button_ = nux::GetEventButton(button_flags);
89+
90+ if (mouse_down_button_ == 2)
91+ {
92+ lower_request.emit(x, y);
93+ }
94+ else if (mouse_down_button_ == 1)
95+ {
96+ mouse_down_point_.x = x;
97+ mouse_down_point_.y = y;
98+
99+ mouse_down_timer_ =
100+ g_timeout_add(MOUSE_DOWN_TIMEOUT, [] (gpointer data) -> gboolean {
101+ auto self = static_cast<PanelTitlebarGrabArea*>(data);
102+
103+ if (!self->grab_started_)
104+ {
105+ nux::Point const& mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord();
106+ self->grab_started.emit(mouse.x - self->GetAbsoluteX(), mouse.y - self->GetAbsoluteY());
107+ self->grab_started_ = true;
108+ }
109+
110+ self->mouse_down_timer_ = 0;
111+ return FALSE;
112+ }, this);
113+ }
114+}
115+
116+void PanelTitlebarGrabArea::OnMouseUp(int x, int y, unsigned long button_flags, unsigned long)
117+{
118+ int button = nux::GetEventButton(button_flags);
119+
120+ if (button == 1)
121+ {
122+ if (mouse_down_timer_)
123+ {
124+ g_source_remove(mouse_down_timer_);
125+ mouse_down_timer_ = 0;
126+
127+ activate_request.emit(x, y);
128+ }
129+
130+ if (grab_started_)
131+ {
132+ grab_end.emit(x, y);
133+ grab_started_ = false;
134+ }
135+ }
136+
137+ mouse_down_button_ = 0;
138+ mouse_down_point_.x = 0;
139+ mouse_down_point_.y = 0;
140+}
141+
142+void PanelTitlebarGrabArea::OnGrabMove(int x, int y, int, int, unsigned long button_flags, unsigned long)
143+{
144+ if (mouse_down_button_ != 1)
145+ return;
146+
147+ if (mouse_down_timer_)
148+ {
149+ if (abs(mouse_down_point_.x - x) <= MOUSE_MOVEMENT_TOLERANCE &&
150+ abs(mouse_down_point_.y - y) <= MOUSE_MOVEMENT_TOLERANCE)
151+ {
152+ return;
153+ }
154+
155+ g_source_remove(mouse_down_timer_);
156+ mouse_down_timer_ = 0;
157+ }
158+
159+ if (!grab_started_)
160+ {
161+ grab_started.emit(x, y);
162+ grab_started_ = true;
163+ }
164+ else
165+ {
166+ grab_move.emit(x, y);
167+ }
168 }
169
170 std::string
171 PanelTitlebarGrabArea::GetName() const
172 {
173- return "panel-titlebar-grab-area";
174+ return "GrabArea";
175 }
176
177 void
178 PanelTitlebarGrabArea::AddProperties(GVariantBuilder* builder)
179 {
180- unity::variant::BuilderWrapper(builder).add(GetGeometry());
181+ unity::variant::BuilderWrapper(builder)
182+ .add(GetGeometry())
183+ .add("grabbed", IsGrabbed());
184+}
185+
186 }
187
188=== modified file 'plugins/unityshell/src/PanelTitlebarGrabAreaView.h'
189--- plugins/unityshell/src/PanelTitlebarGrabAreaView.h 2012-02-25 16:19:39 +0000
190+++ plugins/unityshell/src/PanelTitlebarGrabAreaView.h 2012-04-04 20:17:22 +0000
191@@ -1,6 +1,6 @@
192 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
193 /*
194- * Copyright (C) 2010-2011 Canonical Ltd
195+ * Copyright (C) 2010-2012 Canonical Ltd
196 *
197 * This program is free software: you can redistribute it and/or modify
198 * it under the terms of the GNU General Public License version 3 as
199@@ -27,10 +27,13 @@
200
201 #include "Introspectable.h"
202
203+namespace unity
204+{
205+
206 class PanelTitlebarGrabArea : public nux::InputArea, public unity::debug::Introspectable
207 {
208- /* This acts a bit like a titlebar, it can be grabbed (such that we can pull
209- * the window down) */
210+ /* This acts a bit like a decorator, it can be clicked or grabbed (such that
211+ * we can pull the window down) */
212
213 public:
214 PanelTitlebarGrabArea();
215@@ -39,11 +42,29 @@
216 void SetGrabbed(bool enabled);
217 bool IsGrabbed();
218
219+ sigc::signal<void, int, int> lower_request;
220+ sigc::signal<void, int, int> activate_request;
221+ sigc::signal<void, int, int> restore_request;
222+ sigc::signal<void, int, int> grab_started;
223+ sigc::signal<void, int, int> grab_move;
224+ sigc::signal<void, int, int> grab_end;
225+
226+protected:
227+ std::string GetName() const;
228+ void AddProperties(GVariantBuilder* builder);
229+
230 private:
231- std::string GetName() const;
232- void AddProperties(GVariantBuilder* builder);
233+ void OnMouseDown(int x, int y, unsigned long button_flags, unsigned long);
234+ void OnMouseUp(int x, int y, unsigned long button_flags, unsigned long);
235+ void OnGrabMove(int x, int y, int, int, unsigned long button_flags, unsigned long);
236
237- Cursor _grab_cursor;
238+ Cursor grab_cursor_;
239+ bool grab_started_;
240+ guint mouse_down_timer_;
241+ nux::Point mouse_down_point_;
242+ unsigned int mouse_down_button_;
243 };
244
245+} // NAMESPACE
246+
247 #endif

Subscribers

People subscribed via source and target branches

to all changes: