Merge lp:~3v1n0/bamf/window-action-menu into lp:bamf

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: 592
Merged at revision: 591
Proposed branch: lp:~3v1n0/bamf/window-action-menu
Merge into: lp:bamf
Diff against target: 215 lines (+108/-1)
6 files modified
src/bamf-legacy-screen.c (+66/-0)
src/bamf-legacy-window-test.c (+5/-0)
src/bamf-legacy-window.c (+30/-0)
src/bamf-legacy-window.h (+6/-0)
src/bamf-xutils.c (+1/-0)
src/bamf-xutils.h (+0/-1)
To merge this branch: bzr merge lp:~3v1n0/bamf/window-action-menu
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+206318@code.launchpad.net

Commit message

BamfLegacyScreen: When in Unity monitor for compiz ClientMessage's to show action menu

If we get a _COMPIZ_TOOLKIT_ACTION client message with the internal value
_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU, then we are requested by compiz
to show the window action menu, and thus let's ask the proper BamfLegacyWindow
to do that, thanks to libwnck.

Description of the change

In Unity monitor for compiz Client messages, and if requested (by Alt+Space, Alt+right-click, or directly by it) we show the classic "libwnck" window actions menu in the proper position (top-left corner of the window if activated by keyboard, in the click position otherwise).

The rationale for putting this instead than in unity itself is that having it in unity, a part that it would have needed to add one more build dependency (not a big deal considering that bamf already is), it would have us forced to add one more libwnck screen which means a window event filter, and a lot of logic computation that we don't need at all (as we already do it in bamf itself).

So imho this is the best approach not to duplicate things.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bamf-legacy-screen.c'
2--- src/bamf-legacy-screen.c 2013-08-20 15:09:48 +0000
3+++ src/bamf-legacy-screen.c 2014-02-14 01:33:57 +0000
4@@ -19,6 +19,7 @@
5
6 #include "bamf-legacy-screen.h"
7 #include "bamf-legacy-screen-private.h"
8+#include <gdk/gdkx.h>
9 #include <gio/gio.h>
10
11 G_DEFINE_TYPE (BamfLegacyScreen, bamf_legacy_screen, G_TYPE_OBJECT);
12@@ -38,6 +39,8 @@
13 };
14
15 static guint legacy_screen_signals[LAST_SIGNAL] = { 0 };
16+static Atom _COMPIZ_TOOLKIT_ACTION = 0;
17+static Atom _COMPIZ_TOOLKIT_ACTION_WINDOW_MENU = 0;
18
19 struct _BamfLegacyScreenPrivate
20 {
21@@ -350,6 +353,25 @@
22 return NULL;
23 }
24
25+static BamfLegacyWindow *
26+bamf_legacy_screen_get_window_by_xid (BamfLegacyScreen *screen, Window xid)
27+{
28+ BamfLegacyWindow *window;
29+ GList *l;
30+
31+ g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), NULL);
32+
33+ for (l = screen->priv->windows; l; l = l->next)
34+ {
35+ window = l->data;
36+
37+ if (bamf_legacy_window_get_xid (window) == xid)
38+ return window;
39+ }
40+
41+ return NULL;
42+}
43+
44 static void
45 handle_active_window_changed (WnckScreen *screen, WnckWindow *previous, BamfLegacyScreen *self)
46 {
47@@ -428,6 +450,42 @@
48 G_TYPE_NONE, 0);
49 }
50
51+#include <gdk/gdkx.h>
52+
53+GdkFilterReturn filter_compiz_messages(GdkXEvent *gdkxevent, GdkEvent *event, gpointer data)
54+{
55+ BamfLegacyScreen *self = data;
56+ BamfLegacyWindow *window;
57+ XEvent *xevent = gdkxevent;
58+
59+ if (xevent->type == ClientMessage)
60+ {
61+ if (xevent->xclient.message_type == _COMPIZ_TOOLKIT_ACTION)
62+ {
63+ Atom msg = xevent->xclient.data.l[0];
64+
65+ if (msg == _COMPIZ_TOOLKIT_ACTION_WINDOW_MENU)
66+ {
67+ window = bamf_legacy_screen_get_window_by_xid (self, xevent->xany.window);
68+
69+ if (BAMF_IS_LEGACY_WINDOW (window))
70+ {
71+ Time time = xevent->xclient.data.l[1];
72+ int button = xevent->xclient.data.l[2];
73+ int x = xevent->xclient.data.l[3];
74+ int y = xevent->xclient.data.l[4];
75+
76+ bamf_legacy_window_show_action_menu (window, time, button, x, y);
77+
78+ return GDK_FILTER_REMOVE;
79+ }
80+ }
81+ }
82+ }
83+
84+ return GDK_FILTER_CONTINUE;
85+}
86+
87 BamfLegacyScreen *
88 bamf_legacy_screen_get_default ()
89 {
90@@ -456,6 +514,14 @@
91 g_signal_connect (G_OBJECT (self->priv->legacy_screen), "active-window-changed",
92 (GCallback) handle_active_window_changed, self);
93
94+ if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0)
95+ {
96+ Display *dpy = gdk_x11_get_default_xdisplay ();
97+ _COMPIZ_TOOLKIT_ACTION = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION", False);
98+ _COMPIZ_TOOLKIT_ACTION_WINDOW_MENU = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU", False);
99+ gdk_window_add_filter (NULL, filter_compiz_messages, self);
100+ }
101+
102 return static_screen;
103 }
104
105
106=== modified file 'src/bamf-legacy-window-test.c'
107--- src/bamf-legacy-window-test.c 2014-01-07 19:15:14 +0000
108+++ src/bamf-legacy-window-test.c 2014-02-14 01:33:57 +0000
109@@ -436,6 +436,10 @@
110 return g_strdup (BAMF_LEGACY_WINDOW_TEST (window)->icon);
111 }
112
113+void
114+bamf_legacy_window_test_show_action_menu (BamfLegacyWindow *window, guint32 time, guint button, gint x, gint y)
115+{}
116+
117 static void
118 bamf_legacy_window_test_finalize (GObject *object)
119 {
120@@ -488,6 +492,7 @@
121 win_class->is_closed = bamf_legacy_window_test_is_closed;
122 win_class->get_hint = bamf_legacy_window_test_get_hint;
123 win_class->set_hint = bamf_legacy_window_test_set_hint;
124+ win_class->show_action_menu = bamf_legacy_window_test_show_action_menu;
125 win_class->reopen = bamf_legacy_window_test_reopen;
126 }
127
128
129=== modified file 'src/bamf-legacy-window.c'
130--- src/bamf-legacy-window.c 2013-08-08 11:49:22 +0000
131+++ src/bamf-legacy-window.c 2014-02-14 01:33:57 +0000
132@@ -539,6 +539,36 @@
133 }
134
135 static void
136+top_window_action_menu (GtkMenu *menu, gint *x, gint *y, gboolean *push, gpointer data)
137+{
138+ BamfLegacyWindow *self = data;
139+ gint w, h;
140+ wnck_window_get_client_window_geometry (self->priv->legacy_window, x, y, &w, &h);
141+ *push = TRUE;
142+}
143+
144+void bamf_legacy_window_show_action_menu (BamfLegacyWindow *self, guint32 time,
145+ guint button, gint x, gint y)
146+{
147+ g_return_if_fail (BAMF_IS_LEGACY_WINDOW (self));
148+
149+ if (BAMF_LEGACY_WINDOW_GET_CLASS (self)->show_action_menu)
150+ return BAMF_LEGACY_WINDOW_GET_CLASS (self)->show_action_menu (self, button, time, x, y);
151+
152+ g_return_if_fail (WNCK_IS_WINDOW (self->priv->legacy_window));
153+
154+ GtkWidget *menu = wnck_action_menu_new (self->priv->legacy_window);
155+ g_signal_connect (G_OBJECT (menu), "unmap", G_CALLBACK (g_object_unref), NULL);
156+ g_object_ref_sink (menu);
157+
158+ gtk_menu_set_screen (GTK_MENU (menu), gdk_screen_get_default ());
159+ gtk_widget_show (menu);
160+
161+ GtkMenuPositionFunc position = button ? NULL : top_window_action_menu;
162+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL, position, self, button, time);
163+}
164+
165+static void
166 handle_window_closed (WnckScreen *screen,
167 WnckWindow *window,
168 BamfLegacyWindow *self)
169
170=== modified file 'src/bamf-legacy-window.h'
171--- src/bamf-legacy-window.h 2013-08-08 11:49:22 +0000
172+++ src/bamf-legacy-window.h 2014-02-14 01:33:57 +0000
173@@ -99,6 +99,8 @@
174 gint *x, gint *y, gint *w, gint *h);
175 void (*set_hint) (BamfLegacyWindow *legacy_window,
176 const gchar *name, const gchar *value);
177+ void (*show_action_menu) (BamfLegacyWindow *legacy_window,
178+ guint32 time, guint button, gint x, gint y);
179 void (*reopen) (BamfLegacyWindow *legacy_window);
180
181 /*< signals >*/
182@@ -169,6 +171,10 @@
183
184 gint bamf_legacy_window_get_stacking_position (BamfLegacyWindow *self);
185
186+void bamf_legacy_window_show_action_menu (BamfLegacyWindow *self,
187+ guint32 time, guint button,
188+ gint x, gint y);
189+
190 void bamf_legacy_window_reopen (BamfLegacyWindow *self);
191
192 BamfLegacyWindow * bamf_legacy_window_new (WnckWindow *legacy_window);
193
194=== modified file 'src/bamf-xutils.c'
195--- src/bamf-xutils.c 2013-10-29 00:31:14 +0000
196+++ src/bamf-xutils.c 2014-02-14 01:33:57 +0000
197@@ -19,6 +19,7 @@
198 */
199
200 #include "bamf-xutils.h"
201+#include <X11/Xatom.h>
202 #include <string.h>
203
204 static Display *
205
206=== modified file 'src/bamf-xutils.h'
207--- src/bamf-xutils.h 2012-10-09 08:32:34 +0000
208+++ src/bamf-xutils.h 2014-02-14 01:33:57 +0000
209@@ -22,7 +22,6 @@
210 #define __BAMF_XUTILS_H__
211
212 #include <glib.h>
213-#include <X11/Xatom.h>
214 #include <X11/Xlib.h>
215 #include <gdk/gdkx.h>
216

Subscribers

People subscribed via source and target branches