Merge lp:~didrocks/unity/fix-661049 into lp:unity

Proposed by Didier Roche-Tolomelli
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 793
Proposed branch: lp:~didrocks/unity/fix-661049
Merge into: lp:unity
Diff against target: 149 lines (+65/-10)
3 files modified
src/PanelMenuView.cpp (+1/-0)
src/PanelTitlebarGrabAreaView.cpp (+50/-8)
src/PanelTitlebarGrabAreaView.h (+14/-2)
To merge this branch: bzr merge lp:~didrocks/unity/fix-661049
Reviewer Review Type Date Requested Status
Gord Allott Pending
Review via email: mp+47530@code.launchpad.net

Description of the change

Enabling double click on the launcher to restore a maximized window
(LP: #661049)

This isn't the best fix as nux seems to have some broken piece in
OnMouseDoubleClick but rather a temporary solution. Fixing it in nux will enable
us to depend on system setup and such. For now, the faked double-click time is
500ms.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/PanelMenuView.cpp'
2--- src/PanelMenuView.cpp 2011-01-25 15:35:00 +0000
3+++ src/PanelMenuView.cpp 2011-01-26 14:21:33 +0000
4@@ -78,6 +78,7 @@
5
6 _panel_titlebar_grab_area = new PanelTitlebarGrabArea ();
7 _panel_titlebar_grab_area->mouse_down.connect (sigc::mem_fun (this, &PanelMenuView::OnMaximizedGrab));
8+ _panel_titlebar_grab_area->mouse_doubleclick.connect (sigc::mem_fun (this, &PanelMenuView::OnRestoreClicked));
9
10 win_manager = WindowManager::Default ();
11
12
13=== modified file 'src/PanelTitlebarGrabAreaView.cpp'
14--- src/PanelTitlebarGrabAreaView.cpp 2010-12-30 15:57:11 +0000
15+++ src/PanelTitlebarGrabAreaView.cpp 2011-01-26 14:21:33 +0000
16@@ -15,6 +15,7 @@
17 *
18 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
19 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
20+ * Authored by: Didier Roche <didier.roche@canonical.com>
21 */
22
23 #include "Nux/Nux.h"
24@@ -30,6 +31,8 @@
25
26 #include <glib.h>
27
28+#define DELTA_MOUSE_DOUBLE_CLICK 500000000
29+
30 enum
31 {
32 BUTTON_CLOSE=0,
33@@ -40,7 +43,16 @@
34
35 PanelTitlebarGrabArea::PanelTitlebarGrabArea ()
36 : InputArea (NUX_TRACKER_LOCATION)
37-{
38+{
39+ // FIXME: the two following functions should be used instead of the insane trick with fixed value. But nux is broken
40+ // right now and we need jay to focus on other things
41+ /*InputArea::EnableDoubleClick (true);
42+ InputArea::OnMouseDoubleClick.connect (sigc::mem_fun (this, &PanelTitlebarGrabArea::RecvMouseDoubleClick));*/
43+ InputArea::OnMouseClick.connect (sigc::mem_fun (this, &PanelTitlebarGrabArea::RecvMouseClick));
44+ _last_click_time.tv_sec = 0;
45+ _last_click_time.tv_nsec = 0;
46+
47+ // connect the *Click events before the *Down ones otherwise, weird race happens
48 InputArea::OnMouseDown.connect (sigc::mem_fun (this, &PanelTitlebarGrabArea::RecvMouseDown));
49 }
50
51@@ -49,6 +61,43 @@
52 {
53 }
54
55+void PanelTitlebarGrabArea::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
56+{
57+ mouse_down.emit (x, y);
58+}
59+
60+void PanelTitlebarGrabArea::RecvMouseDoubleClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
61+{
62+ mouse_doubleclick.emit ();
63+}
64+
65+// TODO: can be safely removed once OnMouseDoubleClick is fixed in nux
66+void PanelTitlebarGrabArea::RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
67+{
68+ struct timespec event_time, delta;
69+ clock_gettime(CLOCK_MONOTONIC, &event_time);
70+ delta = time_diff (_last_click_time, event_time);
71+
72+ if ((delta.tv_sec == 0) && (delta.tv_nsec < DELTA_MOUSE_DOUBLE_CLICK))
73+ RecvMouseDoubleClick (x, y, button_flags, key_flags);
74+
75+ _last_click_time.tv_sec = event_time.tv_sec;
76+ _last_click_time.tv_nsec = event_time.tv_nsec;
77+}
78+
79+struct timespec PanelTitlebarGrabArea::time_diff (struct timespec start, struct timespec end)
80+{
81+ struct timespec temp;
82+ if ((end.tv_nsec - start.tv_nsec) < 0) {
83+ temp.tv_sec = end.tv_sec - start.tv_sec-1;
84+ temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
85+ } else {
86+ temp.tv_sec = end.tv_sec - start.tv_sec;
87+ temp.tv_nsec = end.tv_nsec - start.tv_nsec;
88+ }
89+ return temp;
90+}
91+
92 const gchar *
93 PanelTitlebarGrabArea::GetName ()
94 {
95@@ -72,10 +121,3 @@
96 g_variant_builder_add (builder, "{sv}", "width", g_variant_new_int32 (geo.width));
97 g_variant_builder_add (builder, "{sv}", "height", g_variant_new_int32 (geo.height));
98 }
99-
100-void PanelTitlebarGrabArea::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
101-{
102- mouse_down.emit (x, y);
103-}
104-
105-
106
107=== modified file 'src/PanelTitlebarGrabAreaView.h'
108--- src/PanelTitlebarGrabAreaView.h 2010-12-30 15:57:11 +0000
109+++ src/PanelTitlebarGrabAreaView.h 2011-01-26 14:21:33 +0000
110@@ -15,11 +15,16 @@
111 *
112 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
113 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
114+ * Authored by: Didier Roche <didier.roche@canonical.com>
115 */
116
117 #ifndef PANEL_TITLEBAR_GRAB_AREA_H
118 #define PANEL_TITLEBAR_GRAB_AREA_H_H
119
120+
121+// TODO: remove once double click will work in nux
122+#include <time.h>
123+
124 #include <Nux/View.h>
125
126 #include "Introspectable.h"
127@@ -34,13 +39,20 @@
128 ~PanelTitlebarGrabArea ();
129
130 sigc::signal <void, int, int> mouse_down;
131+ sigc::signal <void> mouse_doubleclick;
132
133 protected:
134+ void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
135+ void RecvMouseDoubleClick (int x, int y, unsigned long button_flags, unsigned long key_flags);
136+ // TODO: can be safely removed once OnMouseDoubleClick is fixed in nux
137+ void RecvMouseClick (int x, int y, unsigned long button_flags, unsigned long key_flags);
138+ struct timespec time_diff (struct timespec start, struct timespec end);
139+
140+ struct timespec _last_click_time;
141+
142 const gchar * GetName ();
143 const gchar * GetChildsName ();
144 void AddProperties (GVariantBuilder *builder);
145-
146- void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags);
147 };
148
149 #endif