Merge lp:~smspillaz/compiz-core/compiz-core.lim into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~smspillaz/compiz-core/compiz-core.lim
Merge into: lp:compiz-core/0.9.5
Diff against target: 843 lines (+623/-8)
15 files modified
gtk/window-decorator/CMakeLists.txt (+6/-0)
gtk/window-decorator/decorator.c (+32/-6)
gtk/window-decorator/events.c (+48/-0)
gtk/window-decorator/gtk-window-decorator.h (+7/-1)
gtk/window-decorator/local-menus/CMakeLists.txt (+60/-0)
gtk/window-decorator/local-menus/src/local-menus.c (+200/-0)
gtk/window-decorator/local-menus/src/local-menus.h (+69/-0)
gtk/window-decorator/local-menus/tests/CMakeLists.txt (+3/-0)
gtk/window-decorator/local-menus/tests/check_local_menu_on_off/CMakeLists.txt (+21/-0)
gtk/window-decorator/local-menus/tests/check_local_menu_on_off/test-local-menu-on-off.cpp (+17/-0)
gtk/window-decorator/local-menus/tests/force_local_menu_on/CMakeLists.txt (+21/-0)
gtk/window-decorator/local-menus/tests/force_local_menu_on/test-force-local-menu-on.cpp (+67/-0)
gtk/window-decorator/local-menus/tests/test-local-menu.h (+48/-0)
gtk/window-decorator/metacity.c (+22/-0)
gtk/window-decorator/wnck.c (+2/-1)
To merge this branch: bzr merge lp:~smspillaz/compiz-core/compiz-core.lim
Reviewer Review Type Date Requested Status
Daniel van Vugt Needs Resubmitting
Review via email: mp+91231@code.launchpad.net

This proposal has been superseded by a proposal from 2012-02-06.

Description of the change

Adds support for Ubuntu's "locally integrated menu bars" into gtk-window-decorator.

No tests as of yet, but I'll try and write some for

showing/hiding
forcing them on/off
positions etc

soonish.

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

8 +#define GWD_SHOW_LOCAL_MENU (WNCK_WINDOW_ACTION_BELOW << 1)

No plausible reason for using a macro. In C++ constants (enum or unsigned int) are better as they respect scope rules. Also, should this be inside "#ifdef META_HAS_LOCAL_MENUS" conditional?

296 button_layout->right_buttons[2] = META_BUTTON_FUNCTION_CLOSE;
297
298 - for (i = 3; i < MAX_BUTTONS_PER_CORNER; i++)
299 + for (i = 4; i < MAX_BUTTONS_PER_CORNER; i++)
300 button_layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST;
301 }

I'm not sure what the magic number "3"->"4" is. But we now seem to miss 3 entirely. Is that correct?

2980. By Sam Spilsbury

Split the local menus stuff out into its own file(s)

2981. By Sam Spilsbury

Move the code into a more testable state, add unit tests, etc

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

> 8 +#define GWD_SHOW_LOCAL_MENU (WNCK_WINDOW_ACTION_BELOW << 1)
>
> No plausible reason for using a macro. In C++ constants (enum or unsigned
> int) are better as they respect scope rules. Also, should this be inside
> "#ifdef META_HAS_LOCAL_MENUS" conditional?
>

Its C

>
> 296 button_layout->right_buttons[2] = META_BUTTON_FUNCTION_CLOSE;
> 297
> 298 - for (i = 3; i < MAX_BUTTONS_PER_CORNER; i++)
> 299 + for (i = 4; i < MAX_BUTTONS_PER_CORNER; i++)
> 300 button_layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST;
> 301 }
>
> I'm not sure what the magic number "3"->"4" is. But we now seem to miss 3
> entirely. Is that correct?

Its for initializing the array, though maybe thats wrong. Good find let me check

2982. By Sam Spilsbury

Fix typo

2983. By Sam Spilsbury

Fix typo

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Please resubmit for target branch lp:compiz-core (0.9.7)

review: Needs Resubmitting
2984. By Sam Spilsbury

Also show the menu on the window titlebar and adapt for changed wire protocol

2985. By Sam Spilsbury

Move window if we've held the button down for a bit

2986. By Sam Spilsbury

Theoretically provide the information required for the flair on the decoration

2987. By Sam Spilsbury

Show the flair in the right place

2988. By Sam Spilsbury

Use the right key

2989. By Sam Spilsbury

Use the correct key

2990. By Sam Spilsbury

Merged from lp:compiz-core

Revision history for this message
Marco Trevisan (TreviƱo) (3v1n0) wrote :

+ gboolean empty = g_strcmp0 (entry_id, "") == 0;

You can do the same with:
gboolean empty = (!entry_id || entry_id[0] == '\0');

2991. By Sam Spilsbury

Merged from lp:compiz-core

2992. By Sam Spilsbury

Merged from lp:compiz-core

2993. By Sam Spilsbury

Merge lp:compiz-core

2994. By Sam Spilsbury

Fix incorrect variant and initial button layout

2995. By Sam Spilsbury

Fix build without META_HAS_LOCAL_MENUS

2996. By Sam Spilsbury

Also ifdef the local menus tests

2997. By Sam Spilsbury

Don't run global setup or teardown functions if no local menus

2998. By Sam Spilsbury

Merge lp:compiz-core and allow alt-accelerator to open menus as well as reading the xprop
to determine if local menus are applicable

2999. By Sam Spilsbury

Fix memory error and menu button not showing

3000. By Sam Spilsbury

Fix placement of menus on alt-accelerator, remove debug messages

3001. By Sam Spilsbury

Fix build failure without META_HAS_LOCAL_MENUS

3002. By Sam Spilsbury

Fix a crash when trying to show the window menu on a non decorated window

3003. By Sam Spilsbury

Tell us if we have them

3004. By Sam Spilsbury

Merged lp:compiz-core

3005. By Sam Spilsbury

We also need to test the property too

3006. By Sam Spilsbury

Grab buttons too so that we can process motion events on the titlebar and
move the window instead.

Unmerged revisions

3006. By Sam Spilsbury

Grab buttons too so that we can process motion events on the titlebar and
move the window instead.

3005. By Sam Spilsbury

We also need to test the property too

3004. By Sam Spilsbury

Merged lp:compiz-core

3003. By Sam Spilsbury

Tell us if we have them

3002. By Sam Spilsbury

Fix a crash when trying to show the window menu on a non decorated window

3001. By Sam Spilsbury

Fix build failure without META_HAS_LOCAL_MENUS

3000. By Sam Spilsbury

Fix placement of menus on alt-accelerator, remove debug messages

2999. By Sam Spilsbury

Fix memory error and menu button not showing

2998. By Sam Spilsbury

Merge lp:compiz-core and allow alt-accelerator to open menus as well as reading the xprop
to determine if local menus are applicable

2997. By Sam Spilsbury

Don't run global setup or teardown functions if no local menus

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'gtk/window-decorator/CMakeLists.txt'
--- gtk/window-decorator/CMakeLists.txt 2011-02-16 17:39:56 +0000
+++ gtk/window-decorator/CMakeLists.txt 2012-02-02 17:13:31 +0000
@@ -4,7 +4,10 @@
4 set (CMAKE_INSTALL_RPATH ${libdir})4 set (CMAKE_INSTALL_RPATH ${libdir})
5 endif (COMPIZ_BUILD_WITH_RPATH)5 endif (COMPIZ_BUILD_WITH_RPATH)
66
7 add_subdirectory (local-menus)
8
7 include_directories (9 include_directories (
10 ${CMAKE_CURRENT_SOURCE_DIR}/local-menus/src
8 ${compiz_SOURCE_DIR}/include11 ${compiz_SOURCE_DIR}/include
9 ${CMAKE_BINARY_DIR}/gtk12 ${CMAKE_BINARY_DIR}/gtk
10 ${GTK_WINDOW_DECORATOR_INCLUDE_DIRS}13 ${GTK_WINDOW_DECORATOR_INCLUDE_DIRS}
@@ -63,6 +66,9 @@
63 target_link_libraries (66 target_link_libraries (
64 gtk-window-decorator67 gtk-window-decorator
65 decoration68 decoration
69
70 gtk_window_decorator_local_menus
71
66 ${GTK_WINDOW_DECORATOR_LIBRARIES}72 ${GTK_WINDOW_DECORATOR_LIBRARIES}
67 ${GCONF_LIBRARIES}73 ${GCONF_LIBRARIES}
68 ${DBUS_GLIB_LIBRARIES}74 ${DBUS_GLIB_LIBRARIES}
6975
=== modified file 'gtk/window-decorator/decorator.c'
--- gtk/window-decorator/decorator.c 2011-10-13 11:31:37 +0000
+++ gtk/window-decorator/decorator.c 2012-02-02 17:13:31 +0000
@@ -24,6 +24,7 @@
24 */24 */
2525
26#include "gtk-window-decorator.h"26#include "gtk-window-decorator.h"
27#include "local-menus.h"
2728
28decor_frame_t *29decor_frame_t *
29create_normal_frame (const gchar *type)30create_normal_frame (const gchar *type)
@@ -230,12 +231,16 @@
230void231void
231update_event_windows (WnckWindow *win)232update_event_windows (WnckWindow *win)
232{233{
234#define GWD_SHOW_LOCAL_MENU (WNCK_WINDOW_ACTION_BELOW << 1)
233 Display *xdisplay;235 Display *xdisplay;
234 decor_t *d = g_object_get_data (G_OBJECT (win), "decor");236 decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
235 gint x0, y0, width, height, x, y, w, h;237 gint x0, y0, width, height, x, y, w, h;
236 gint i, j, k, l;238 gint i, j, k, l;
237 gint actions = d->actions;239 gint actions = d->actions;
238240
241 if (gwd_window_should_have_local_menu (win))
242 d->actions |= GWD_SHOW_LOCAL_MENU;
243
239 xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());244 xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
240245
241 /* Get the geometry of the client */246 /* Get the geometry of the client */
@@ -298,11 +303,19 @@
298 XMapWindow (xdisplay, d->event_windows[i][j].window);303 XMapWindow (xdisplay, d->event_windows[i][j].window);
299 XMoveResizeWindow (xdisplay, d->event_windows[i][j].window,304 XMoveResizeWindow (xdisplay, d->event_windows[i][j].window,
300 x, y, w, h);305 x, y, w, h);
306
307 BoxPtr box = &d->event_windows[i][j].pos;
308 box->x1 = x;
309 box->x2 = x + w;
310 box->y1 = y;
311 box->y2 = y + h;
301 }312 }
302 /* No parent and no geometry - unmap all event windows */313 /* No parent and no geometry - unmap all event windows */
303 else if (!d->frame_window)314 else if (!d->frame_window)
304 {315 {
305 XUnmapWindow (xdisplay, d->event_windows[i][j].window);316 XUnmapWindow (xdisplay, d->event_windows[i][j].window);
317
318 memset (&d->event_windows[i][j].pos, 0, sizeof (Box));
306 }319 }
307 }320 }
308 }321 }
@@ -326,12 +339,18 @@
326 WNCK_WINDOW_ACTION_STICK,339 WNCK_WINDOW_ACTION_STICK,
327 WNCK_WINDOW_ACTION_UNSHADE,340 WNCK_WINDOW_ACTION_UNSHADE,
328 WNCK_WINDOW_ACTION_ABOVE,341 WNCK_WINDOW_ACTION_ABOVE,
329 WNCK_WINDOW_ACTION_UNSTICK342 WNCK_WINDOW_ACTION_UNSTICK,
330#else343#else
331 0,344 0,
332 0,345 0,
333 0,346 0,
334 0,347 0,
348 0,
349#endif
350
351#ifdef META_HAS_LOCAL_MENUS
352 GWD_SHOW_LOCAL_MENU
353#else
335 0354 0
336#endif355#endif
337356
@@ -371,10 +390,17 @@
371 Window win = d->button_windows[i].window;390 Window win = d->button_windows[i].window;
372 XMapWindow (xdisplay, win);391 XMapWindow (xdisplay, win);
373 XMoveResizeWindow (xdisplay, win, x, y, w, h);392 XMoveResizeWindow (xdisplay, win, x, y, w, h);
393
394 BoxPtr box = &d->button_windows[i].pos;
395 box->x1 = x;
396 box->x2 = x + w;
397 box->y1 = y;
398 box->y2 = y + h;
374 }399 }
375 else if (!d->frame_window)400 else if (!d->frame_window)
376 {401 {
377 XUnmapWindow (xdisplay, d->button_windows[i].window);402 XUnmapWindow (xdisplay, d->button_windows[i].window);
403 memset (&d->button_windows[i].pos, 0, sizeof (Box));
378 }404 }
379 }405 }
380406
381407
=== modified file 'gtk/window-decorator/events.c'
--- gtk/window-decorator/events.c 2011-10-13 12:22:14 +0000
+++ gtk/window-decorator/events.c 2012-02-02 17:13:31 +0000
@@ -24,6 +24,7 @@
24 */24 */
2525
26#include "gtk-window-decorator.h" 26#include "gtk-window-decorator.h"
27#include "local-menus.h"
2728
28void29void
29move_resize_window (WnckWindow *win,30move_resize_window (WnckWindow *win,
@@ -380,6 +381,53 @@
380}381}
381382
382void383void
384on_local_menu_hidden (gpointer user_data)
385{
386 decor_t *d = (decor_t *) user_data;
387
388 d->button_states[BUTTON_WINDOW_MENU] &= ~PRESSED_EVENT_WINDOW;
389
390 queue_decor_draw (d);
391}
392
393void
394window_menu_button_event (WnckWindow *win,
395 decor_event *gtkwd_event,
396 decor_event_type gtkwd_type)
397{
398 decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
399
400 common_button_event (win, gtkwd_event, gtkwd_type,
401 BUTTON_WINDOW_MENU, 1, _("Window Menu"));
402
403 switch (gtkwd_type) {
404 case GButtonPress:
405 if (gtkwd_event->button == 1)
406 if (d->button_states[BUTTON_WINDOW_MENU] == BUTTON_EVENT_ACTION_STATE)
407 {
408 int win_x, win_y;
409 int box_x = d->button_windows[BUTTON_WINDOW_MENU].pos.x1;
410
411 wnck_window_get_geometry (win, &win_x, &win_y, NULL, NULL);
412
413 int x = win_x + box_x;
414 int y = win_y + d->context->extents.top;
415
416 gwd_show_local_menu (gdk_x11_display_get_xdisplay (gdk_display_get_default ()),
417 wnck_window_get_xid (win),
418 x, y,
419 gtkwd_event->button,
420 gtkwd_event->time,
421 (show_window_menu_hidden_cb) on_local_menu_hidden,
422 (gpointer) d);
423 }
424 break;
425 default:
426 break;
427 }
428}
429
430void
383handle_title_button_event (WnckWindow *win,431handle_title_button_event (WnckWindow *win,
384 int action,432 int action,
385 decor_event *gtkwd_event)433 decor_event *gtkwd_event)
386434
=== modified file 'gtk/window-decorator/gtk-window-decorator.h'
--- gtk/window-decorator/gtk-window-decorator.h 2011-10-13 12:22:14 +0000
+++ gtk/window-decorator/gtk-window-decorator.h 2012-02-02 17:13:31 +0000
@@ -328,7 +328,8 @@
328#define BUTTON_UNSHADE 7328#define BUTTON_UNSHADE 7
329#define BUTTON_UNABOVE 8329#define BUTTON_UNABOVE 8
330#define BUTTON_UNSTICK 9330#define BUTTON_UNSTICK 9
331#define BUTTON_NUM 10331#define BUTTON_WINDOW_MENU 10
332#define BUTTON_NUM 11
332333
333struct _pos {334struct _pos {
334 int x, y, w, h;335 int x, y, w, h;
@@ -1013,6 +1014,11 @@
1013 decor_event_type gtkwd_type);1014 decor_event_type gtkwd_type);
10141015
1015void1016void
1017window_menu_button_event (WnckWindow *win,
1018 decor_event *gtkwd_event,
1019 decor_event_type gtkwd_type);
1020
1021void
1016handle_title_button_event (WnckWindow *win,1022handle_title_button_event (WnckWindow *win,
1017 int action,1023 int action,
1018 decor_event *gtkwd_event);1024 decor_event *gtkwd_event);
10191025
=== added directory 'gtk/window-decorator/local-menus'
=== added file 'gtk/window-decorator/local-menus/CMakeLists.txt'
--- gtk/window-decorator/local-menus/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/CMakeLists.txt 2012-02-02 17:13:31 +0000
@@ -0,0 +1,60 @@
1pkg_check_modules(
2 LOCAL_MENUS
3 REQUIRED
4 glib-2.0 gio-2.0 libwnck-1.0 gtk+-2.0>=2.18.0
5)
6
7INCLUDE_DIRECTORIES(
8 ${CMAKE_CURRENT_SOURCE_DIR}/include
9 ${CMAKE_CURRENT_SOURCE_DIR}/src
10
11 ${compiz_SOURCE_DIR}/gtk/window-decorator
12
13 ${Boost_INCLUDE_DIRS}
14
15 ${LOCAL_MENUS_INCLUDE_DIRS}
16 ${METACITY_INCLUDE_DIRS}
17)
18
19LINK_DIRECTORIES (${LOCAL_MENUS_LIBRARY_DIRS})
20
21SET(
22 PUBLIC_HEADERS
23)
24
25SET(
26 PRIVATE_HEADERS
27 ${CMAKE_CURRENT_SOURCE_DIR}/src/local-menus.h
28)
29
30SET(
31 SRCS
32 ${CMAKE_CURRENT_SOURCE_DIR}/src/local-menus.c
33)
34
35ADD_LIBRARY(
36 gtk_window_decorator_local_menus STATIC
37
38 ${SRCS}
39
40 ${PUBLIC_HEADERS}
41 ${PRIVATE_HEADERS}
42)
43
44IF (COMPIZ_BUILD_TESTING)
45ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests )
46ENDIF (COMPIZ_BUILD_TESTING)
47
48SET_TARGET_PROPERTIES(
49 gtk_window_decorator_local_menus PROPERTIES
50 PUBLIC_HEADER "${PUBLIC_HEADERS}"
51)
52
53install (FILES ${PUBLIC_HEADERS} DESTINATION ${COMPIZ_CORE_INCLUDE_DIR})
54
55TARGET_LINK_LIBRARIES(
56 gtk_window_decorator_local_menus
57
58 ${LOCAL_MENUS_LIBRARIES}
59)
60
061
=== added directory 'gtk/window-decorator/local-menus/include'
=== added directory 'gtk/window-decorator/local-menus/src'
=== added file 'gtk/window-decorator/local-menus/src/local-menus.c'
--- gtk/window-decorator/local-menus/src/local-menus.c 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/src/local-menus.c 2012-02-02 17:13:31 +0000
@@ -0,0 +1,200 @@
1/*
2 * Copyright Ā© 2006 Novell, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 * Author: David Reveman <davidr@novell.com>
20 *
21 * 2D Mode: Copyright Ā© 2010 Sam Spilsbury <smspillaz@gmail.com>
22 * Frames Management: Copright Ā© 2011 Canonical Ltd.
23 * Authored By: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#include "local-menus.h"
27#include <gdk/gdk.h>
28#include <gdk/gdkx.h>
29
30gboolean
31gwd_window_should_have_local_menu (WnckWindow *win)
32{
33#ifdef META_HAS_LOCAL_MENUS
34 const gchar * const *schemas = g_settings_list_schemas ();
35 static GSettings *lim_settings = NULL;
36 while (*schemas != NULL && !lim_settings)
37 {
38 if (g_str_equal (*schemas, "com.canonical.Unity.Menus"))
39 {
40 lim_settings = g_settings_new ("com.canonical.Unity.Menus");
41 break;
42 }
43 ++schemas;
44 }
45
46 if (lim_settings)
47 {
48 if (g_settings_get_boolean (lim_settings, "force-local-menus"))
49 {
50 return TRUE;
51 }
52 }
53#endif
54
55 return FALSE;
56}
57
58static void
59on_local_menu_activated (GDBusProxy *proxy,
60 gchar *sender_name,
61 gchar *signal_name,
62 GVariant *parameters,
63 gpointer user_data)
64{
65#ifdef META_HAS_LOCAL_MENUS
66 if (g_strcmp0 (signal_name, "EntryActivated") == 0)
67 {
68 gchar *entry_id = NULL;
69
70 g_variant_get (parameters, "(s)", &entry_id, NULL);
71
72 gboolean empty = g_strcmp0 (entry_id, "") == 0;
73
74 if (empty)
75 {
76 show_local_menu_data *d = (show_local_menu_data *) user_data;
77
78 (*d->cb) (d->user_data);
79
80 g_signal_handlers_disconnect_by_func (d->proxy, on_local_menu_activated, d);
81
82 g_object_unref (d->proxy);
83 g_object_unref (d->conn);
84 g_free (d->entry_id);
85 }
86 }
87#endif
88}
89
90void
91gwd_show_local_menu (Display *xdisplay,
92 Window frame_xwindow,
93 int x,
94 int y,
95 int button,
96 guint32 timestamp,
97 show_window_menu_hidden_cb cb,
98 gpointer user_data)
99{
100#ifdef META_HAS_LOCAL_MENUS
101 GError *error = NULL;
102 GDBusConnection *conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
103
104 XUngrabPointer (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), CurrentTime);
105 XUngrabKeyboard (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), CurrentTime);
106 XSync (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), FALSE);
107
108 if (!conn)
109 {
110 g_print ("error getting connection: %s\n", error->message);
111 return;
112 }
113
114 GDBusProxy *proxy = g_dbus_proxy_new_sync (conn, 0, NULL, "com.canonical.Unity.Panel.Service",
115 "/com/canonical/Unity/Panel/Service",
116 "com.canonical.Unity.Panel.Service",
117 NULL, &error);
118
119 if (proxy)
120 {
121 GVariant *message = g_variant_new ("(uiiu)", frame_xwindow, x, y, time);
122 GVariant *reply = g_dbus_proxy_call_sync (proxy, "ShowAppMenu", message, 0, 500, NULL, &error);
123 if (error)
124 {
125 g_print ("error calling ShowAppMenu: %s\n", error->message);
126 g_object_unref (proxy);
127 g_object_unref (conn);
128 return;
129 }
130
131 show_local_menu_data *data = g_new0 (show_local_menu_data, 1);
132 g_variant_get (reply, "(s)", data->entry_id, NULL);
133
134 data->conn = g_object_ref (conn);
135 data->proxy = g_object_ref (proxy);
136 data->cb = cb;
137 data->user_data = user_data;
138
139 g_signal_connect (proxy, "g-signal", G_CALLBACK (on_local_menu_activated), data);
140
141 g_object_unref (conn);
142 g_object_unref (proxy);
143
144 return;
145 }
146 else
147 {
148 g_print ("error getting proxy: %s\n", error->message);
149 }
150
151 g_object_unref (conn);
152#endif
153}
154
155void
156force_local_menus_on (WnckWindow *win,
157 MetaButtonLayout *button_layout)
158{
159#ifdef META_HAS_LOCAL_MENUS
160 if (gwd_window_should_have_local_menu (win))
161 {
162 if (button_layout->left_buttons[0] != META_BUTTON_FUNCTION_LAST)
163 {
164 unsigned int i = 0;
165 for (; i < MAX_BUTTONS_PER_CORNER; i++)
166 {
167 if (button_layout->left_buttons[i] == META_BUTTON_FUNCTION_WINDOW_MENU)
168 break;
169 else if (button_layout->left_buttons[i] == META_BUTTON_FUNCTION_LAST)
170 {
171 if ((i + 1) < MAX_BUTTONS_PER_CORNER)
172 {
173 button_layout->left_buttons[i + 1] = META_BUTTON_FUNCTION_LAST;
174 button_layout->left_buttons[i] = META_BUTTON_FUNCTION_WINDOW_MENU;
175 }
176 }
177 }
178 }
179 if (button_layout->right_buttons[0] != META_BUTTON_FUNCTION_LAST)
180 {
181 unsigned int i = 0;
182 for (; i < MAX_BUTTONS_PER_CORNER; i++)
183 {
184 if (button_layout->right_buttons[i] == META_BUTTON_FUNCTION_WINDOW_MENU)
185 break;
186 else if (button_layout->right_buttons[i] == META_BUTTON_FUNCTION_LAST)
187 {
188 if ((i + 1) < MAX_BUTTONS_PER_CORNER)
189 {
190 button_layout->right_buttons[i + 1] = META_BUTTON_FUNCTION_LAST;
191 button_layout->right_buttons[i] = META_BUTTON_FUNCTION_WINDOW_MENU;
192 }
193 }
194 }
195 }
196 }
197#endif
198}
199
200
0201
=== added file 'gtk/window-decorator/local-menus/src/local-menus.h'
--- gtk/window-decorator/local-menus/src/local-menus.h 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/src/local-menus.h 2012-02-02 17:13:31 +0000
@@ -0,0 +1,69 @@
1/*
2 * Copyright Ā© 2006 Novell, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 * Author: David Reveman <davidr@novell.com>
20 *
21 * 2D Mode: Copyright Ā© 2010 Sam Spilsbury <smspillaz@gmail.com>
22 * Frames Management: Copright Ā© 2011 Canonical Ltd.
23 * Authored By: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */
25
26#ifdef __cplusplus
27extern "C"
28{
29#endif
30
31#include <glib.h>
32#include <gio/gio.h>
33#ifndef WNCK_I_KNOW_THIS_IS_UNSTABLE
34#define WNCK_I_KNOW_THIS_IS_UNSTABLE
35#endif
36#include <libwnck/libwnck.h>
37#include <libwnck/window-action-menu.h>
38#include <metacity-private/theme.h>
39
40typedef void (*show_window_menu_hidden_cb) (gpointer);
41
42typedef struct _show_local_menu_data
43{
44 GDBusConnection *conn;
45 GDBusProxy *proxy;
46 gchar *entry_id;
47 show_window_menu_hidden_cb cb;
48 gpointer user_data;
49} show_local_menu_data;
50
51gboolean
52gwd_window_should_have_local_menu (WnckWindow *win);
53
54void
55force_local_menus_on (WnckWindow *win,
56 MetaButtonLayout *layout);
57
58void
59gwd_show_local_menu (Display *xdisplay,
60 Window frame_xwindow,
61 int x,
62 int y,
63 int button,
64 guint32 timestamp,
65 show_window_menu_hidden_cb cb,
66 gpointer user_data);
67#ifdef __cplusplus
68}
69#endif
070
=== added directory 'gtk/window-decorator/local-menus/tests'
=== added file 'gtk/window-decorator/local-menus/tests/CMakeLists.txt'
--- gtk/window-decorator/local-menus/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/tests/CMakeLists.txt 2012-02-02 17:13:31 +0000
@@ -0,0 +1,3 @@
1include_directories (${CMAKE_CURRENT_SOURCE_DIR})
2add_subdirectory (check_local_menu_on_off)
3add_subdirectory (force_local_menu_on)
04
=== added directory 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off'
=== added file 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off/CMakeLists.txt'
--- gtk/window-decorator/local-menus/tests/check_local_menu_on_off/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/tests/check_local_menu_on_off/CMakeLists.txt 2012-02-02 17:13:31 +0000
@@ -0,0 +1,21 @@
1include_directories (${CMAKE_CURRENT_SOURCE_DIR}
2 ${compiz_SOURCE_DIR}/gtk/window-decorator/local-menus/tests
3 ${compiz_SOURCE_DIR}/gtk/window-decorator
4 ${compiz_SOURCE_DIR}/gtk/window-decorator/local-menus/src)
5
6add_executable(
7 gtk_window_decorator_check_local_menu_on_off_test
8
9 ${CMAKE_CURRENT_SOURCE_DIR}/test-local-menu-on-off.cpp
10)
11
12target_link_libraries(
13 gtk_window_decorator_check_local_menu_on_off_test
14
15 gtk_window_decorator_local_menus
16
17 ${GTEST_BOTH_LIBRARIES}
18 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
19)
20
21add_test (gtk_window_decorator_local_menus_on_off gtk_window_decorator_check_local_menu_on_off_test)
022
=== added directory 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off/check_local_menu_on_off'
=== added directory 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off/check_local_menu_on_off/CMakeFiles'
=== added file 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off/test-local-menu-on-off.cpp'
--- gtk/window-decorator/local-menus/tests/check_local_menu_on_off/test-local-menu-on-off.cpp 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/tests/check_local_menu_on_off/test-local-menu-on-off.cpp 2012-02-02 17:13:31 +0000
@@ -0,0 +1,17 @@
1#include "test-local-menu.h"
2
3TEST_F (GtkWindowDecoratorTestLocalMenu, TestOn)
4{
5 g_settings_set_boolean (getSettings (), "force-local-menus", TRUE);
6 gboolean result = gwd_window_should_have_local_menu (getWindow ());
7
8 EXPECT_TRUE (result);
9}
10
11TEST_F (GtkWindowDecoratorTestLocalMenu, TestOff)
12{
13 g_settings_set_boolean (getSettings (), "force-local-menus", FALSE);
14 gboolean result = gwd_window_should_have_local_menu (getWindow ());
15
16 EXPECT_FALSE (result);
17}
018
=== added directory 'gtk/window-decorator/local-menus/tests/force_local_menu_on'
=== added file 'gtk/window-decorator/local-menus/tests/force_local_menu_on/CMakeLists.txt'
--- gtk/window-decorator/local-menus/tests/force_local_menu_on/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/tests/force_local_menu_on/CMakeLists.txt 2012-02-02 17:13:31 +0000
@@ -0,0 +1,21 @@
1include_directories (${CMAKE_CURRENT_SOURCE_DIR}
2 ${compiz_SOURCE_DIR}/gtk/window-decorator/local-menus/tests
3 ${compiz_SOURCE_DIR}/gtk/window-decorator
4 ${compiz_SOURCE_DIR}/gtk/window-decorator/local-menus/src)
5
6add_executable(
7 gtk_window_decorator_force_local_menu_on_test
8
9 ${CMAKE_CURRENT_SOURCE_DIR}/test-force-local-menu-on.cpp
10)
11
12target_link_libraries(
13 gtk_window_decorator_force_local_menu_on_test
14
15 gtk_window_decorator_local_menus
16
17 ${GTEST_BOTH_LIBRARIES}
18 ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
19)
20
21add_test (gtk_window_decorator_force_local_menu_on gtk_window_decorator_force_local_menu_on_test)
022
=== added file 'gtk/window-decorator/local-menus/tests/force_local_menu_on/test-force-local-menu-on.cpp'
--- gtk/window-decorator/local-menus/tests/force_local_menu_on/test-force-local-menu-on.cpp 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/tests/force_local_menu_on/test-force-local-menu-on.cpp 2012-02-02 17:13:31 +0000
@@ -0,0 +1,67 @@
1#include "test-local-menu.h"
2#include <cstring>
3
4namespace
5{
6 void initializeMetaButtonLayout (MetaButtonLayout *layout)
7 {
8 memset (layout, 0, sizeof (MetaButtonLayout));
9
10 unsigned int i;
11
12 for (i = 0; i < MAX_BUTTONS_PER_CORNER; i++)
13 {
14 layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST;
15 layout->left_buttons[i] = META_BUTTON_FUNCTION_LAST;
16 }
17 }
18}
19
20class GtkWindowDecoratorTestLocalMenuLayout :
21 public GtkWindowDecoratorTestLocalMenu
22{
23 public:
24
25 MetaButtonLayout * getLayout () { return &mLayout; }
26
27 virtual void SetUp ()
28 {
29 GtkWindowDecoratorTestLocalMenu::SetUp ();
30 ::initializeMetaButtonLayout (&mLayout);
31 g_settings_set_boolean (getSettings (), "force-local-menus", TRUE);
32 }
33
34 private:
35
36 MetaButtonLayout mLayout;
37};
38
39TEST_F (GtkWindowDecoratorTestLocalMenuLayout, TestForceNoButtonsSet)
40{
41 force_local_menus_on (getWindow (), getLayout ());
42
43 EXPECT_EQ (getLayout ()->right_buttons[0], META_BUTTON_FUNCTION_LAST);
44 EXPECT_EQ (getLayout ()->left_buttons[0], META_BUTTON_FUNCTION_LAST);
45}
46
47TEST_F (GtkWindowDecoratorTestLocalMenuLayout, TestForceNoCloseButtonSet)
48{
49 getLayout ()->right_buttons[0] = META_BUTTON_FUNCTION_CLOSE;
50
51 force_local_menus_on (getWindow (), getLayout ());
52
53 EXPECT_EQ (getLayout ()->right_buttons[1], META_BUTTON_FUNCTION_WINDOW_MENU);
54 EXPECT_EQ (getLayout ()->left_buttons[0], META_BUTTON_FUNCTION_LAST);
55}
56
57TEST_F (GtkWindowDecoratorTestLocalMenuLayout, TestForceNoCloseMinimizeMaximizeButtonSet)
58{
59 getLayout ()->left_buttons[0] = META_BUTTON_FUNCTION_CLOSE;
60 getLayout ()->left_buttons[1] = META_BUTTON_FUNCTION_CLOSE;
61 getLayout ()->left_buttons[2] = META_BUTTON_FUNCTION_CLOSE;
62
63 force_local_menus_on (getWindow (), getLayout ());
64
65 EXPECT_EQ (getLayout ()->right_buttons[0], META_BUTTON_FUNCTION_LAST);
66 EXPECT_EQ (getLayout ()->left_buttons[3], META_BUTTON_FUNCTION_WINDOW_MENU);
67}
068
=== added directory 'gtk/window-decorator/local-menus/tests/show_hide_menu'
=== added file 'gtk/window-decorator/local-menus/tests/test-local-menu.h'
--- gtk/window-decorator/local-menus/tests/test-local-menu.h 1970-01-01 00:00:00 +0000
+++ gtk/window-decorator/local-menus/tests/test-local-menu.h 2012-02-02 17:13:31 +0000
@@ -0,0 +1,48 @@
1#include <gtest/gtest.h>
2#include <gmock/gmock.h>
3#include "local-menus.h"
4#include <X11/Xlib.h>
5#include <gio/gio.h>
6
7class GtkWindowDecoratorTestLocalMenu :
8 public ::testing::Test
9{
10 public:
11
12 WnckWindow * getWindow () { return mWindow; }
13 GSettings * getSettings () { return mSettings; }
14
15 virtual void SetUp ()
16 {
17 gtk_init (NULL, NULL);
18
19 mXDisplay = XOpenDisplay (NULL);
20 mXWindow = XCreateSimpleWindow (mXDisplay, DefaultRootWindow (mXDisplay), 0, 0, 100, 100, 0, 0, 0);
21
22 XMapRaised (mXDisplay, mXWindow);
23
24 XFlush (mXDisplay);
25
26 while (g_main_context_iteration (g_main_context_default (), FALSE));
27
28 mWindow = wnck_window_get (mXWindow);
29
30 g_setenv("GSETTINGS_BACKEND", "memory", true);
31 mSettings = g_settings_new ("com.canonical.Unity.Menus");
32 }
33
34 virtual void TearDown ()
35 {
36 XDestroyWindow (mXDisplay, mXWindow);
37 XCloseDisplay (mXDisplay);
38
39 g_object_unref (mSettings);
40 }
41
42 private:
43
44 WnckWindow *mWindow;
45 Window mXWindow;
46 Display *mXDisplay;
47 GSettings *mSettings;
48};
049
=== modified file 'gtk/window-decorator/metacity.c'
--- gtk/window-decorator/metacity.c 2012-01-12 06:48:58 +0000
+++ gtk/window-decorator/metacity.c 2012-02-02 17:13:31 +0000
@@ -24,6 +24,7 @@
24 */24 */
2525
26#include "gtk-window-decorator.h"26#include "gtk-window-decorator.h"
27#include "local-menus.h"
2728
28#ifdef USE_METACITY29#ifdef USE_METACITY
2930
@@ -488,6 +489,8 @@
488 button_layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST;489 button_layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST;
489 }490 }
490491
492 force_local_menus_on (d->win, button_layout);
493
491 *flags = 0;494 *flags = 0;
492495
493 if (d->actions & WNCK_WINDOW_ACTION_CLOSE)496 if (d->actions & WNCK_WINDOW_ACTION_CLOSE)
@@ -601,6 +604,11 @@
601 GdkColor bg_color;604 GdkColor bg_color;
602 double bg_alpha;605 double bg_alpha;
603606
607 memset (&button_layout, 0, sizeof (MetaButtonLayout));
608
609 for (i = 0; i < MAX_BUTTONS_PER_CORNER; i++)
610 button_layout.left_buttons[i] = button_layout.right_buttons[i] = META_BUTTON_FUNCTION_LAST;
611
604 if (!d->pixmap || !d->picture)612 if (!d->pixmap || !d->picture)
605 return;613 return;
606614
@@ -1078,6 +1086,15 @@
1078 break;1086 break;
1079#endif1087#endif
10801088
1089#ifdef META_HAS_LOCAL_MENUS
1090 case BUTTON_WINDOW_MENU:
1091 if (!meta_button_present (&button_layout, META_BUTTON_FUNCTION_WINDOW_MENU))
1092 return FALSE;
1093
1094 space = &fgeom.window_menu_rect;
1095 break;
1096#endif
1097
1081 default:1098 default:
1082 return FALSE;1099 return FALSE;
1083 }1100 }
@@ -1490,6 +1507,11 @@
1490 return META_BUTTON_FUNCTION_UNSTICK;1507 return META_BUTTON_FUNCTION_UNSTICK;
1491#endif1508#endif
14921509
1510#ifdef META_HAS_LOCAL_MENUS
1511 else if (strcmp (str, "window_menu") == 0)
1512 return META_BUTTON_FUNCTION_WINDOW_MENU;
1513#endif
1514
1493 else1515 else
1494 return META_BUTTON_FUNCTION_LAST;1516 return META_BUTTON_FUNCTION_LAST;
1495}1517}
14961518
=== modified file 'gtk/window-decorator/wnck.c'
--- gtk/window-decorator/wnck.c 2011-10-13 09:53:38 +0000
+++ gtk/window-decorator/wnck.c 2012-02-02 17:13:31 +0000
@@ -727,7 +727,8 @@
727 stick_button_event,727 stick_button_event,
728 unshade_button_event,728 unshade_button_event,
729 unabove_button_event,729 unabove_button_event,
730 unstick_button_event730 unstick_button_event,
731 window_menu_button_event
731 };732 };
732733
733 d = calloc (1, sizeof (decor_t));734 d = calloc (1, sizeof (decor_t));

Subscribers

People subscribed via source and target branches