Merge lp:~smspillaz/compiz-core/compiz-core.lim into lp:compiz-core/0.9.5
- compiz-core.lim
- Merge into 0.9.5
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 | ||||||||
Related bugs: |
|
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.
Commit message
Description of the change
Adds support for Ubuntu's "locally integrated menu bars" into gtk-window-
No tests as of yet, but I'll try and write some for
showing/hiding
forcing them on/off
positions etc
soonish.
Alan Griffiths (alan-griffiths) wrote : | # |
- 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
Sam Spilsbury (smspillaz) wrote : | # |
> 8 +#define GWD_SHOW_LOCAL_MENU (WNCK_WINDOW_
>
> 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_
>
Its C
>
> 296 button_
> 297
> 298 - for (i = 3; i < MAX_BUTTONS_
> 299 + for (i = 4; i < MAX_BUTTONS_
> 300 button_
> 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
Daniel van Vugt (vanvugt) wrote : | # |
Please resubmit for target branch lp:compiz-core (0.9.7)
- 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
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
1 | === modified file 'gtk/window-decorator/CMakeLists.txt' | |||
2 | --- gtk/window-decorator/CMakeLists.txt 2011-02-16 17:39:56 +0000 | |||
3 | +++ gtk/window-decorator/CMakeLists.txt 2012-02-02 17:13:31 +0000 | |||
4 | @@ -4,7 +4,10 @@ | |||
5 | 4 | set (CMAKE_INSTALL_RPATH ${libdir}) | 4 | set (CMAKE_INSTALL_RPATH ${libdir}) |
6 | 5 | endif (COMPIZ_BUILD_WITH_RPATH) | 5 | endif (COMPIZ_BUILD_WITH_RPATH) |
7 | 6 | 6 | ||
8 | 7 | add_subdirectory (local-menus) | ||
9 | 8 | |||
10 | 7 | include_directories ( | 9 | include_directories ( |
11 | 10 | ${CMAKE_CURRENT_SOURCE_DIR}/local-menus/src | ||
12 | 8 | ${compiz_SOURCE_DIR}/include | 11 | ${compiz_SOURCE_DIR}/include |
13 | 9 | ${CMAKE_BINARY_DIR}/gtk | 12 | ${CMAKE_BINARY_DIR}/gtk |
14 | 10 | ${GTK_WINDOW_DECORATOR_INCLUDE_DIRS} | 13 | ${GTK_WINDOW_DECORATOR_INCLUDE_DIRS} |
15 | @@ -63,6 +66,9 @@ | |||
16 | 63 | target_link_libraries ( | 66 | target_link_libraries ( |
17 | 64 | gtk-window-decorator | 67 | gtk-window-decorator |
18 | 65 | decoration | 68 | decoration |
19 | 69 | |||
20 | 70 | gtk_window_decorator_local_menus | ||
21 | 71 | |||
22 | 66 | ${GTK_WINDOW_DECORATOR_LIBRARIES} | 72 | ${GTK_WINDOW_DECORATOR_LIBRARIES} |
23 | 67 | ${GCONF_LIBRARIES} | 73 | ${GCONF_LIBRARIES} |
24 | 68 | ${DBUS_GLIB_LIBRARIES} | 74 | ${DBUS_GLIB_LIBRARIES} |
25 | 69 | 75 | ||
26 | === modified file 'gtk/window-decorator/decorator.c' | |||
27 | --- gtk/window-decorator/decorator.c 2011-10-13 11:31:37 +0000 | |||
28 | +++ gtk/window-decorator/decorator.c 2012-02-02 17:13:31 +0000 | |||
29 | @@ -24,6 +24,7 @@ | |||
30 | 24 | */ | 24 | */ |
31 | 25 | 25 | ||
32 | 26 | #include "gtk-window-decorator.h" | 26 | #include "gtk-window-decorator.h" |
33 | 27 | #include "local-menus.h" | ||
34 | 27 | 28 | ||
35 | 28 | decor_frame_t * | 29 | decor_frame_t * |
36 | 29 | create_normal_frame (const gchar *type) | 30 | create_normal_frame (const gchar *type) |
37 | @@ -230,12 +231,16 @@ | |||
38 | 230 | void | 231 | void |
39 | 231 | update_event_windows (WnckWindow *win) | 232 | update_event_windows (WnckWindow *win) |
40 | 232 | { | 233 | { |
41 | 234 | #define GWD_SHOW_LOCAL_MENU (WNCK_WINDOW_ACTION_BELOW << 1) | ||
42 | 233 | Display *xdisplay; | 235 | Display *xdisplay; |
43 | 234 | decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); | 236 | decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); |
44 | 235 | gint x0, y0, width, height, x, y, w, h; | 237 | gint x0, y0, width, height, x, y, w, h; |
45 | 236 | gint i, j, k, l; | 238 | gint i, j, k, l; |
46 | 237 | gint actions = d->actions; | 239 | gint actions = d->actions; |
47 | 238 | 240 | ||
48 | 241 | if (gwd_window_should_have_local_menu (win)) | ||
49 | 242 | d->actions |= GWD_SHOW_LOCAL_MENU; | ||
50 | 243 | |||
51 | 239 | xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); | 244 | xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); |
52 | 240 | 245 | ||
53 | 241 | /* Get the geometry of the client */ | 246 | /* Get the geometry of the client */ |
54 | @@ -298,11 +303,19 @@ | |||
55 | 298 | XMapWindow (xdisplay, d->event_windows[i][j].window); | 303 | XMapWindow (xdisplay, d->event_windows[i][j].window); |
56 | 299 | XMoveResizeWindow (xdisplay, d->event_windows[i][j].window, | 304 | XMoveResizeWindow (xdisplay, d->event_windows[i][j].window, |
57 | 300 | x, y, w, h); | 305 | x, y, w, h); |
58 | 306 | |||
59 | 307 | BoxPtr box = &d->event_windows[i][j].pos; | ||
60 | 308 | box->x1 = x; | ||
61 | 309 | box->x2 = x + w; | ||
62 | 310 | box->y1 = y; | ||
63 | 311 | box->y2 = y + h; | ||
64 | 301 | } | 312 | } |
65 | 302 | /* No parent and no geometry - unmap all event windows */ | 313 | /* No parent and no geometry - unmap all event windows */ |
66 | 303 | else if (!d->frame_window) | 314 | else if (!d->frame_window) |
67 | 304 | { | 315 | { |
68 | 305 | XUnmapWindow (xdisplay, d->event_windows[i][j].window); | 316 | XUnmapWindow (xdisplay, d->event_windows[i][j].window); |
69 | 317 | |||
70 | 318 | memset (&d->event_windows[i][j].pos, 0, sizeof (Box)); | ||
71 | 306 | } | 319 | } |
72 | 307 | } | 320 | } |
73 | 308 | } | 321 | } |
74 | @@ -326,12 +339,18 @@ | |||
75 | 326 | WNCK_WINDOW_ACTION_STICK, | 339 | WNCK_WINDOW_ACTION_STICK, |
76 | 327 | WNCK_WINDOW_ACTION_UNSHADE, | 340 | WNCK_WINDOW_ACTION_UNSHADE, |
77 | 328 | WNCK_WINDOW_ACTION_ABOVE, | 341 | WNCK_WINDOW_ACTION_ABOVE, |
84 | 329 | WNCK_WINDOW_ACTION_UNSTICK | 342 | WNCK_WINDOW_ACTION_UNSTICK, |
85 | 330 | #else | 343 | #else |
86 | 331 | 0, | 344 | 0, |
87 | 332 | 0, | 345 | 0, |
88 | 333 | 0, | 346 | 0, |
89 | 334 | 0, | 347 | 0, |
90 | 348 | 0, | ||
91 | 349 | #endif | ||
92 | 350 | |||
93 | 351 | #ifdef META_HAS_LOCAL_MENUS | ||
94 | 352 | GWD_SHOW_LOCAL_MENU | ||
95 | 353 | #else | ||
96 | 335 | 0 | 354 | 0 |
97 | 336 | #endif | 355 | #endif |
98 | 337 | 356 | ||
99 | @@ -371,10 +390,17 @@ | |||
100 | 371 | Window win = d->button_windows[i].window; | 390 | Window win = d->button_windows[i].window; |
101 | 372 | XMapWindow (xdisplay, win); | 391 | XMapWindow (xdisplay, win); |
102 | 373 | XMoveResizeWindow (xdisplay, win, x, y, w, h); | 392 | XMoveResizeWindow (xdisplay, win, x, y, w, h); |
103 | 393 | |||
104 | 394 | BoxPtr box = &d->button_windows[i].pos; | ||
105 | 395 | box->x1 = x; | ||
106 | 396 | box->x2 = x + w; | ||
107 | 397 | box->y1 = y; | ||
108 | 398 | box->y2 = y + h; | ||
109 | 374 | } | 399 | } |
110 | 375 | else if (!d->frame_window) | 400 | else if (!d->frame_window) |
111 | 376 | { | 401 | { |
112 | 377 | XUnmapWindow (xdisplay, d->button_windows[i].window); | 402 | XUnmapWindow (xdisplay, d->button_windows[i].window); |
113 | 403 | memset (&d->button_windows[i].pos, 0, sizeof (Box)); | ||
114 | 378 | } | 404 | } |
115 | 379 | } | 405 | } |
116 | 380 | 406 | ||
117 | 381 | 407 | ||
118 | === modified file 'gtk/window-decorator/events.c' | |||
119 | --- gtk/window-decorator/events.c 2011-10-13 12:22:14 +0000 | |||
120 | +++ gtk/window-decorator/events.c 2012-02-02 17:13:31 +0000 | |||
121 | @@ -24,6 +24,7 @@ | |||
122 | 24 | */ | 24 | */ |
123 | 25 | 25 | ||
124 | 26 | #include "gtk-window-decorator.h" | 26 | #include "gtk-window-decorator.h" |
125 | 27 | #include "local-menus.h" | ||
126 | 27 | 28 | ||
127 | 28 | void | 29 | void |
128 | 29 | move_resize_window (WnckWindow *win, | 30 | move_resize_window (WnckWindow *win, |
129 | @@ -380,6 +381,53 @@ | |||
130 | 380 | } | 381 | } |
131 | 381 | 382 | ||
132 | 382 | void | 383 | void |
133 | 384 | on_local_menu_hidden (gpointer user_data) | ||
134 | 385 | { | ||
135 | 386 | decor_t *d = (decor_t *) user_data; | ||
136 | 387 | |||
137 | 388 | d->button_states[BUTTON_WINDOW_MENU] &= ~PRESSED_EVENT_WINDOW; | ||
138 | 389 | |||
139 | 390 | queue_decor_draw (d); | ||
140 | 391 | } | ||
141 | 392 | |||
142 | 393 | void | ||
143 | 394 | window_menu_button_event (WnckWindow *win, | ||
144 | 395 | decor_event *gtkwd_event, | ||
145 | 396 | decor_event_type gtkwd_type) | ||
146 | 397 | { | ||
147 | 398 | decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); | ||
148 | 399 | |||
149 | 400 | common_button_event (win, gtkwd_event, gtkwd_type, | ||
150 | 401 | BUTTON_WINDOW_MENU, 1, _("Window Menu")); | ||
151 | 402 | |||
152 | 403 | switch (gtkwd_type) { | ||
153 | 404 | case GButtonPress: | ||
154 | 405 | if (gtkwd_event->button == 1) | ||
155 | 406 | if (d->button_states[BUTTON_WINDOW_MENU] == BUTTON_EVENT_ACTION_STATE) | ||
156 | 407 | { | ||
157 | 408 | int win_x, win_y; | ||
158 | 409 | int box_x = d->button_windows[BUTTON_WINDOW_MENU].pos.x1; | ||
159 | 410 | |||
160 | 411 | wnck_window_get_geometry (win, &win_x, &win_y, NULL, NULL); | ||
161 | 412 | |||
162 | 413 | int x = win_x + box_x; | ||
163 | 414 | int y = win_y + d->context->extents.top; | ||
164 | 415 | |||
165 | 416 | gwd_show_local_menu (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), | ||
166 | 417 | wnck_window_get_xid (win), | ||
167 | 418 | x, y, | ||
168 | 419 | gtkwd_event->button, | ||
169 | 420 | gtkwd_event->time, | ||
170 | 421 | (show_window_menu_hidden_cb) on_local_menu_hidden, | ||
171 | 422 | (gpointer) d); | ||
172 | 423 | } | ||
173 | 424 | break; | ||
174 | 425 | default: | ||
175 | 426 | break; | ||
176 | 427 | } | ||
177 | 428 | } | ||
178 | 429 | |||
179 | 430 | void | ||
180 | 383 | handle_title_button_event (WnckWindow *win, | 431 | handle_title_button_event (WnckWindow *win, |
181 | 384 | int action, | 432 | int action, |
182 | 385 | decor_event *gtkwd_event) | 433 | decor_event *gtkwd_event) |
183 | 386 | 434 | ||
184 | === modified file 'gtk/window-decorator/gtk-window-decorator.h' | |||
185 | --- gtk/window-decorator/gtk-window-decorator.h 2011-10-13 12:22:14 +0000 | |||
186 | +++ gtk/window-decorator/gtk-window-decorator.h 2012-02-02 17:13:31 +0000 | |||
187 | @@ -328,7 +328,8 @@ | |||
188 | 328 | #define BUTTON_UNSHADE 7 | 328 | #define BUTTON_UNSHADE 7 |
189 | 329 | #define BUTTON_UNABOVE 8 | 329 | #define BUTTON_UNABOVE 8 |
190 | 330 | #define BUTTON_UNSTICK 9 | 330 | #define BUTTON_UNSTICK 9 |
192 | 331 | #define BUTTON_NUM 10 | 331 | #define BUTTON_WINDOW_MENU 10 |
193 | 332 | #define BUTTON_NUM 11 | ||
194 | 332 | 333 | ||
195 | 333 | struct _pos { | 334 | struct _pos { |
196 | 334 | int x, y, w, h; | 335 | int x, y, w, h; |
197 | @@ -1013,6 +1014,11 @@ | |||
198 | 1013 | decor_event_type gtkwd_type); | 1014 | decor_event_type gtkwd_type); |
199 | 1014 | 1015 | ||
200 | 1015 | void | 1016 | void |
201 | 1017 | window_menu_button_event (WnckWindow *win, | ||
202 | 1018 | decor_event *gtkwd_event, | ||
203 | 1019 | decor_event_type gtkwd_type); | ||
204 | 1020 | |||
205 | 1021 | void | ||
206 | 1016 | handle_title_button_event (WnckWindow *win, | 1022 | handle_title_button_event (WnckWindow *win, |
207 | 1017 | int action, | 1023 | int action, |
208 | 1018 | decor_event *gtkwd_event); | 1024 | decor_event *gtkwd_event); |
209 | 1019 | 1025 | ||
210 | === added directory 'gtk/window-decorator/local-menus' | |||
211 | === added file 'gtk/window-decorator/local-menus/CMakeLists.txt' | |||
212 | --- gtk/window-decorator/local-menus/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
213 | +++ gtk/window-decorator/local-menus/CMakeLists.txt 2012-02-02 17:13:31 +0000 | |||
214 | @@ -0,0 +1,60 @@ | |||
215 | 1 | pkg_check_modules( | ||
216 | 2 | LOCAL_MENUS | ||
217 | 3 | REQUIRED | ||
218 | 4 | glib-2.0 gio-2.0 libwnck-1.0 gtk+-2.0>=2.18.0 | ||
219 | 5 | ) | ||
220 | 6 | |||
221 | 7 | INCLUDE_DIRECTORIES( | ||
222 | 8 | ${CMAKE_CURRENT_SOURCE_DIR}/include | ||
223 | 9 | ${CMAKE_CURRENT_SOURCE_DIR}/src | ||
224 | 10 | |||
225 | 11 | ${compiz_SOURCE_DIR}/gtk/window-decorator | ||
226 | 12 | |||
227 | 13 | ${Boost_INCLUDE_DIRS} | ||
228 | 14 | |||
229 | 15 | ${LOCAL_MENUS_INCLUDE_DIRS} | ||
230 | 16 | ${METACITY_INCLUDE_DIRS} | ||
231 | 17 | ) | ||
232 | 18 | |||
233 | 19 | LINK_DIRECTORIES (${LOCAL_MENUS_LIBRARY_DIRS}) | ||
234 | 20 | |||
235 | 21 | SET( | ||
236 | 22 | PUBLIC_HEADERS | ||
237 | 23 | ) | ||
238 | 24 | |||
239 | 25 | SET( | ||
240 | 26 | PRIVATE_HEADERS | ||
241 | 27 | ${CMAKE_CURRENT_SOURCE_DIR}/src/local-menus.h | ||
242 | 28 | ) | ||
243 | 29 | |||
244 | 30 | SET( | ||
245 | 31 | SRCS | ||
246 | 32 | ${CMAKE_CURRENT_SOURCE_DIR}/src/local-menus.c | ||
247 | 33 | ) | ||
248 | 34 | |||
249 | 35 | ADD_LIBRARY( | ||
250 | 36 | gtk_window_decorator_local_menus STATIC | ||
251 | 37 | |||
252 | 38 | ${SRCS} | ||
253 | 39 | |||
254 | 40 | ${PUBLIC_HEADERS} | ||
255 | 41 | ${PRIVATE_HEADERS} | ||
256 | 42 | ) | ||
257 | 43 | |||
258 | 44 | IF (COMPIZ_BUILD_TESTING) | ||
259 | 45 | ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests ) | ||
260 | 46 | ENDIF (COMPIZ_BUILD_TESTING) | ||
261 | 47 | |||
262 | 48 | SET_TARGET_PROPERTIES( | ||
263 | 49 | gtk_window_decorator_local_menus PROPERTIES | ||
264 | 50 | PUBLIC_HEADER "${PUBLIC_HEADERS}" | ||
265 | 51 | ) | ||
266 | 52 | |||
267 | 53 | install (FILES ${PUBLIC_HEADERS} DESTINATION ${COMPIZ_CORE_INCLUDE_DIR}) | ||
268 | 54 | |||
269 | 55 | TARGET_LINK_LIBRARIES( | ||
270 | 56 | gtk_window_decorator_local_menus | ||
271 | 57 | |||
272 | 58 | ${LOCAL_MENUS_LIBRARIES} | ||
273 | 59 | ) | ||
274 | 60 | |||
275 | 0 | 61 | ||
276 | === added directory 'gtk/window-decorator/local-menus/include' | |||
277 | === added directory 'gtk/window-decorator/local-menus/src' | |||
278 | === added file 'gtk/window-decorator/local-menus/src/local-menus.c' | |||
279 | --- gtk/window-decorator/local-menus/src/local-menus.c 1970-01-01 00:00:00 +0000 | |||
280 | +++ gtk/window-decorator/local-menus/src/local-menus.c 2012-02-02 17:13:31 +0000 | |||
281 | @@ -0,0 +1,200 @@ | |||
282 | 1 | /* | ||
283 | 2 | * Copyright Ā© 2006 Novell, Inc. | ||
284 | 3 | * | ||
285 | 4 | * This library is free software; you can redistribute it and/or | ||
286 | 5 | * modify it under the terms of the GNU Lesser General Public | ||
287 | 6 | * License as published by the Free Software Foundation; either | ||
288 | 7 | * version 2 of the License, or (at your option) any later version. | ||
289 | 8 | * | ||
290 | 9 | * This library is distributed in the hope that it will be useful, | ||
291 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
292 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
293 | 12 | * Lesser General Public License for more details. | ||
294 | 13 | * | ||
295 | 14 | * You should have received a copy of the GNU Lesser General Public | ||
296 | 15 | * License along with this library; if not, write to the | ||
297 | 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
298 | 17 | * Boston, MA 02111-1307, USA. | ||
299 | 18 | * | ||
300 | 19 | * Author: David Reveman <davidr@novell.com> | ||
301 | 20 | * | ||
302 | 21 | * 2D Mode: Copyright Ā© 2010 Sam Spilsbury <smspillaz@gmail.com> | ||
303 | 22 | * Frames Management: Copright Ā© 2011 Canonical Ltd. | ||
304 | 23 | * Authored By: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
305 | 24 | */ | ||
306 | 25 | |||
307 | 26 | #include "local-menus.h" | ||
308 | 27 | #include <gdk/gdk.h> | ||
309 | 28 | #include <gdk/gdkx.h> | ||
310 | 29 | |||
311 | 30 | gboolean | ||
312 | 31 | gwd_window_should_have_local_menu (WnckWindow *win) | ||
313 | 32 | { | ||
314 | 33 | #ifdef META_HAS_LOCAL_MENUS | ||
315 | 34 | const gchar * const *schemas = g_settings_list_schemas (); | ||
316 | 35 | static GSettings *lim_settings = NULL; | ||
317 | 36 | while (*schemas != NULL && !lim_settings) | ||
318 | 37 | { | ||
319 | 38 | if (g_str_equal (*schemas, "com.canonical.Unity.Menus")) | ||
320 | 39 | { | ||
321 | 40 | lim_settings = g_settings_new ("com.canonical.Unity.Menus"); | ||
322 | 41 | break; | ||
323 | 42 | } | ||
324 | 43 | ++schemas; | ||
325 | 44 | } | ||
326 | 45 | |||
327 | 46 | if (lim_settings) | ||
328 | 47 | { | ||
329 | 48 | if (g_settings_get_boolean (lim_settings, "force-local-menus")) | ||
330 | 49 | { | ||
331 | 50 | return TRUE; | ||
332 | 51 | } | ||
333 | 52 | } | ||
334 | 53 | #endif | ||
335 | 54 | |||
336 | 55 | return FALSE; | ||
337 | 56 | } | ||
338 | 57 | |||
339 | 58 | static void | ||
340 | 59 | on_local_menu_activated (GDBusProxy *proxy, | ||
341 | 60 | gchar *sender_name, | ||
342 | 61 | gchar *signal_name, | ||
343 | 62 | GVariant *parameters, | ||
344 | 63 | gpointer user_data) | ||
345 | 64 | { | ||
346 | 65 | #ifdef META_HAS_LOCAL_MENUS | ||
347 | 66 | if (g_strcmp0 (signal_name, "EntryActivated") == 0) | ||
348 | 67 | { | ||
349 | 68 | gchar *entry_id = NULL; | ||
350 | 69 | |||
351 | 70 | g_variant_get (parameters, "(s)", &entry_id, NULL); | ||
352 | 71 | |||
353 | 72 | gboolean empty = g_strcmp0 (entry_id, "") == 0; | ||
354 | 73 | |||
355 | 74 | if (empty) | ||
356 | 75 | { | ||
357 | 76 | show_local_menu_data *d = (show_local_menu_data *) user_data; | ||
358 | 77 | |||
359 | 78 | (*d->cb) (d->user_data); | ||
360 | 79 | |||
361 | 80 | g_signal_handlers_disconnect_by_func (d->proxy, on_local_menu_activated, d); | ||
362 | 81 | |||
363 | 82 | g_object_unref (d->proxy); | ||
364 | 83 | g_object_unref (d->conn); | ||
365 | 84 | g_free (d->entry_id); | ||
366 | 85 | } | ||
367 | 86 | } | ||
368 | 87 | #endif | ||
369 | 88 | } | ||
370 | 89 | |||
371 | 90 | void | ||
372 | 91 | gwd_show_local_menu (Display *xdisplay, | ||
373 | 92 | Window frame_xwindow, | ||
374 | 93 | int x, | ||
375 | 94 | int y, | ||
376 | 95 | int button, | ||
377 | 96 | guint32 timestamp, | ||
378 | 97 | show_window_menu_hidden_cb cb, | ||
379 | 98 | gpointer user_data) | ||
380 | 99 | { | ||
381 | 100 | #ifdef META_HAS_LOCAL_MENUS | ||
382 | 101 | GError *error = NULL; | ||
383 | 102 | GDBusConnection *conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); | ||
384 | 103 | |||
385 | 104 | XUngrabPointer (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), CurrentTime); | ||
386 | 105 | XUngrabKeyboard (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), CurrentTime); | ||
387 | 106 | XSync (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), FALSE); | ||
388 | 107 | |||
389 | 108 | if (!conn) | ||
390 | 109 | { | ||
391 | 110 | g_print ("error getting connection: %s\n", error->message); | ||
392 | 111 | return; | ||
393 | 112 | } | ||
394 | 113 | |||
395 | 114 | GDBusProxy *proxy = g_dbus_proxy_new_sync (conn, 0, NULL, "com.canonical.Unity.Panel.Service", | ||
396 | 115 | "/com/canonical/Unity/Panel/Service", | ||
397 | 116 | "com.canonical.Unity.Panel.Service", | ||
398 | 117 | NULL, &error); | ||
399 | 118 | |||
400 | 119 | if (proxy) | ||
401 | 120 | { | ||
402 | 121 | GVariant *message = g_variant_new ("(uiiu)", frame_xwindow, x, y, time); | ||
403 | 122 | GVariant *reply = g_dbus_proxy_call_sync (proxy, "ShowAppMenu", message, 0, 500, NULL, &error); | ||
404 | 123 | if (error) | ||
405 | 124 | { | ||
406 | 125 | g_print ("error calling ShowAppMenu: %s\n", error->message); | ||
407 | 126 | g_object_unref (proxy); | ||
408 | 127 | g_object_unref (conn); | ||
409 | 128 | return; | ||
410 | 129 | } | ||
411 | 130 | |||
412 | 131 | show_local_menu_data *data = g_new0 (show_local_menu_data, 1); | ||
413 | 132 | g_variant_get (reply, "(s)", data->entry_id, NULL); | ||
414 | 133 | |||
415 | 134 | data->conn = g_object_ref (conn); | ||
416 | 135 | data->proxy = g_object_ref (proxy); | ||
417 | 136 | data->cb = cb; | ||
418 | 137 | data->user_data = user_data; | ||
419 | 138 | |||
420 | 139 | g_signal_connect (proxy, "g-signal", G_CALLBACK (on_local_menu_activated), data); | ||
421 | 140 | |||
422 | 141 | g_object_unref (conn); | ||
423 | 142 | g_object_unref (proxy); | ||
424 | 143 | |||
425 | 144 | return; | ||
426 | 145 | } | ||
427 | 146 | else | ||
428 | 147 | { | ||
429 | 148 | g_print ("error getting proxy: %s\n", error->message); | ||
430 | 149 | } | ||
431 | 150 | |||
432 | 151 | g_object_unref (conn); | ||
433 | 152 | #endif | ||
434 | 153 | } | ||
435 | 154 | |||
436 | 155 | void | ||
437 | 156 | force_local_menus_on (WnckWindow *win, | ||
438 | 157 | MetaButtonLayout *button_layout) | ||
439 | 158 | { | ||
440 | 159 | #ifdef META_HAS_LOCAL_MENUS | ||
441 | 160 | if (gwd_window_should_have_local_menu (win)) | ||
442 | 161 | { | ||
443 | 162 | if (button_layout->left_buttons[0] != META_BUTTON_FUNCTION_LAST) | ||
444 | 163 | { | ||
445 | 164 | unsigned int i = 0; | ||
446 | 165 | for (; i < MAX_BUTTONS_PER_CORNER; i++) | ||
447 | 166 | { | ||
448 | 167 | if (button_layout->left_buttons[i] == META_BUTTON_FUNCTION_WINDOW_MENU) | ||
449 | 168 | break; | ||
450 | 169 | else if (button_layout->left_buttons[i] == META_BUTTON_FUNCTION_LAST) | ||
451 | 170 | { | ||
452 | 171 | if ((i + 1) < MAX_BUTTONS_PER_CORNER) | ||
453 | 172 | { | ||
454 | 173 | button_layout->left_buttons[i + 1] = META_BUTTON_FUNCTION_LAST; | ||
455 | 174 | button_layout->left_buttons[i] = META_BUTTON_FUNCTION_WINDOW_MENU; | ||
456 | 175 | } | ||
457 | 176 | } | ||
458 | 177 | } | ||
459 | 178 | } | ||
460 | 179 | if (button_layout->right_buttons[0] != META_BUTTON_FUNCTION_LAST) | ||
461 | 180 | { | ||
462 | 181 | unsigned int i = 0; | ||
463 | 182 | for (; i < MAX_BUTTONS_PER_CORNER; i++) | ||
464 | 183 | { | ||
465 | 184 | if (button_layout->right_buttons[i] == META_BUTTON_FUNCTION_WINDOW_MENU) | ||
466 | 185 | break; | ||
467 | 186 | else if (button_layout->right_buttons[i] == META_BUTTON_FUNCTION_LAST) | ||
468 | 187 | { | ||
469 | 188 | if ((i + 1) < MAX_BUTTONS_PER_CORNER) | ||
470 | 189 | { | ||
471 | 190 | button_layout->right_buttons[i + 1] = META_BUTTON_FUNCTION_LAST; | ||
472 | 191 | button_layout->right_buttons[i] = META_BUTTON_FUNCTION_WINDOW_MENU; | ||
473 | 192 | } | ||
474 | 193 | } | ||
475 | 194 | } | ||
476 | 195 | } | ||
477 | 196 | } | ||
478 | 197 | #endif | ||
479 | 198 | } | ||
480 | 199 | |||
481 | 200 | |||
482 | 0 | 201 | ||
483 | === added file 'gtk/window-decorator/local-menus/src/local-menus.h' | |||
484 | --- gtk/window-decorator/local-menus/src/local-menus.h 1970-01-01 00:00:00 +0000 | |||
485 | +++ gtk/window-decorator/local-menus/src/local-menus.h 2012-02-02 17:13:31 +0000 | |||
486 | @@ -0,0 +1,69 @@ | |||
487 | 1 | /* | ||
488 | 2 | * Copyright Ā© 2006 Novell, Inc. | ||
489 | 3 | * | ||
490 | 4 | * This library is free software; you can redistribute it and/or | ||
491 | 5 | * modify it under the terms of the GNU Lesser General Public | ||
492 | 6 | * License as published by the Free Software Foundation; either | ||
493 | 7 | * version 2 of the License, or (at your option) any later version. | ||
494 | 8 | * | ||
495 | 9 | * This library is distributed in the hope that it will be useful, | ||
496 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
497 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
498 | 12 | * Lesser General Public License for more details. | ||
499 | 13 | * | ||
500 | 14 | * You should have received a copy of the GNU Lesser General Public | ||
501 | 15 | * License along with this library; if not, write to the | ||
502 | 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
503 | 17 | * Boston, MA 02111-1307, USA. | ||
504 | 18 | * | ||
505 | 19 | * Author: David Reveman <davidr@novell.com> | ||
506 | 20 | * | ||
507 | 21 | * 2D Mode: Copyright Ā© 2010 Sam Spilsbury <smspillaz@gmail.com> | ||
508 | 22 | * Frames Management: Copright Ā© 2011 Canonical Ltd. | ||
509 | 23 | * Authored By: Sam Spilsbury <sam.spilsbury@canonical.com> | ||
510 | 24 | */ | ||
511 | 25 | |||
512 | 26 | #ifdef __cplusplus | ||
513 | 27 | extern "C" | ||
514 | 28 | { | ||
515 | 29 | #endif | ||
516 | 30 | |||
517 | 31 | #include <glib.h> | ||
518 | 32 | #include <gio/gio.h> | ||
519 | 33 | #ifndef WNCK_I_KNOW_THIS_IS_UNSTABLE | ||
520 | 34 | #define WNCK_I_KNOW_THIS_IS_UNSTABLE | ||
521 | 35 | #endif | ||
522 | 36 | #include <libwnck/libwnck.h> | ||
523 | 37 | #include <libwnck/window-action-menu.h> | ||
524 | 38 | #include <metacity-private/theme.h> | ||
525 | 39 | |||
526 | 40 | typedef void (*show_window_menu_hidden_cb) (gpointer); | ||
527 | 41 | |||
528 | 42 | typedef struct _show_local_menu_data | ||
529 | 43 | { | ||
530 | 44 | GDBusConnection *conn; | ||
531 | 45 | GDBusProxy *proxy; | ||
532 | 46 | gchar *entry_id; | ||
533 | 47 | show_window_menu_hidden_cb cb; | ||
534 | 48 | gpointer user_data; | ||
535 | 49 | } show_local_menu_data; | ||
536 | 50 | |||
537 | 51 | gboolean | ||
538 | 52 | gwd_window_should_have_local_menu (WnckWindow *win); | ||
539 | 53 | |||
540 | 54 | void | ||
541 | 55 | force_local_menus_on (WnckWindow *win, | ||
542 | 56 | MetaButtonLayout *layout); | ||
543 | 57 | |||
544 | 58 | void | ||
545 | 59 | gwd_show_local_menu (Display *xdisplay, | ||
546 | 60 | Window frame_xwindow, | ||
547 | 61 | int x, | ||
548 | 62 | int y, | ||
549 | 63 | int button, | ||
550 | 64 | guint32 timestamp, | ||
551 | 65 | show_window_menu_hidden_cb cb, | ||
552 | 66 | gpointer user_data); | ||
553 | 67 | #ifdef __cplusplus | ||
554 | 68 | } | ||
555 | 69 | #endif | ||
556 | 0 | 70 | ||
557 | === added directory 'gtk/window-decorator/local-menus/tests' | |||
558 | === added file 'gtk/window-decorator/local-menus/tests/CMakeLists.txt' | |||
559 | --- gtk/window-decorator/local-menus/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
560 | +++ gtk/window-decorator/local-menus/tests/CMakeLists.txt 2012-02-02 17:13:31 +0000 | |||
561 | @@ -0,0 +1,3 @@ | |||
562 | 1 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}) | ||
563 | 2 | add_subdirectory (check_local_menu_on_off) | ||
564 | 3 | add_subdirectory (force_local_menu_on) | ||
565 | 0 | 4 | ||
566 | === added directory 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off' | |||
567 | === added file 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off/CMakeLists.txt' | |||
568 | --- gtk/window-decorator/local-menus/tests/check_local_menu_on_off/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
569 | +++ gtk/window-decorator/local-menus/tests/check_local_menu_on_off/CMakeLists.txt 2012-02-02 17:13:31 +0000 | |||
570 | @@ -0,0 +1,21 @@ | |||
571 | 1 | include_directories (${CMAKE_CURRENT_SOURCE_DIR} | ||
572 | 2 | ${compiz_SOURCE_DIR}/gtk/window-decorator/local-menus/tests | ||
573 | 3 | ${compiz_SOURCE_DIR}/gtk/window-decorator | ||
574 | 4 | ${compiz_SOURCE_DIR}/gtk/window-decorator/local-menus/src) | ||
575 | 5 | |||
576 | 6 | add_executable( | ||
577 | 7 | gtk_window_decorator_check_local_menu_on_off_test | ||
578 | 8 | |||
579 | 9 | ${CMAKE_CURRENT_SOURCE_DIR}/test-local-menu-on-off.cpp | ||
580 | 10 | ) | ||
581 | 11 | |||
582 | 12 | target_link_libraries( | ||
583 | 13 | gtk_window_decorator_check_local_menu_on_off_test | ||
584 | 14 | |||
585 | 15 | gtk_window_decorator_local_menus | ||
586 | 16 | |||
587 | 17 | ${GTEST_BOTH_LIBRARIES} | ||
588 | 18 | ${CMAKE_THREAD_LIBS_INIT} # Link in pthread. | ||
589 | 19 | ) | ||
590 | 20 | |||
591 | 21 | add_test (gtk_window_decorator_local_menus_on_off gtk_window_decorator_check_local_menu_on_off_test) | ||
592 | 0 | 22 | ||
593 | === added directory 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off/check_local_menu_on_off' | |||
594 | === added directory 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off/check_local_menu_on_off/CMakeFiles' | |||
595 | === added file 'gtk/window-decorator/local-menus/tests/check_local_menu_on_off/test-local-menu-on-off.cpp' | |||
596 | --- gtk/window-decorator/local-menus/tests/check_local_menu_on_off/test-local-menu-on-off.cpp 1970-01-01 00:00:00 +0000 | |||
597 | +++ gtk/window-decorator/local-menus/tests/check_local_menu_on_off/test-local-menu-on-off.cpp 2012-02-02 17:13:31 +0000 | |||
598 | @@ -0,0 +1,17 @@ | |||
599 | 1 | #include "test-local-menu.h" | ||
600 | 2 | |||
601 | 3 | TEST_F (GtkWindowDecoratorTestLocalMenu, TestOn) | ||
602 | 4 | { | ||
603 | 5 | g_settings_set_boolean (getSettings (), "force-local-menus", TRUE); | ||
604 | 6 | gboolean result = gwd_window_should_have_local_menu (getWindow ()); | ||
605 | 7 | |||
606 | 8 | EXPECT_TRUE (result); | ||
607 | 9 | } | ||
608 | 10 | |||
609 | 11 | TEST_F (GtkWindowDecoratorTestLocalMenu, TestOff) | ||
610 | 12 | { | ||
611 | 13 | g_settings_set_boolean (getSettings (), "force-local-menus", FALSE); | ||
612 | 14 | gboolean result = gwd_window_should_have_local_menu (getWindow ()); | ||
613 | 15 | |||
614 | 16 | EXPECT_FALSE (result); | ||
615 | 17 | } | ||
616 | 0 | 18 | ||
617 | === added directory 'gtk/window-decorator/local-menus/tests/force_local_menu_on' | |||
618 | === added file 'gtk/window-decorator/local-menus/tests/force_local_menu_on/CMakeLists.txt' | |||
619 | --- gtk/window-decorator/local-menus/tests/force_local_menu_on/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
620 | +++ gtk/window-decorator/local-menus/tests/force_local_menu_on/CMakeLists.txt 2012-02-02 17:13:31 +0000 | |||
621 | @@ -0,0 +1,21 @@ | |||
622 | 1 | include_directories (${CMAKE_CURRENT_SOURCE_DIR} | ||
623 | 2 | ${compiz_SOURCE_DIR}/gtk/window-decorator/local-menus/tests | ||
624 | 3 | ${compiz_SOURCE_DIR}/gtk/window-decorator | ||
625 | 4 | ${compiz_SOURCE_DIR}/gtk/window-decorator/local-menus/src) | ||
626 | 5 | |||
627 | 6 | add_executable( | ||
628 | 7 | gtk_window_decorator_force_local_menu_on_test | ||
629 | 8 | |||
630 | 9 | ${CMAKE_CURRENT_SOURCE_DIR}/test-force-local-menu-on.cpp | ||
631 | 10 | ) | ||
632 | 11 | |||
633 | 12 | target_link_libraries( | ||
634 | 13 | gtk_window_decorator_force_local_menu_on_test | ||
635 | 14 | |||
636 | 15 | gtk_window_decorator_local_menus | ||
637 | 16 | |||
638 | 17 | ${GTEST_BOTH_LIBRARIES} | ||
639 | 18 | ${CMAKE_THREAD_LIBS_INIT} # Link in pthread. | ||
640 | 19 | ) | ||
641 | 20 | |||
642 | 21 | add_test (gtk_window_decorator_force_local_menu_on gtk_window_decorator_force_local_menu_on_test) | ||
643 | 0 | 22 | ||
644 | === added file 'gtk/window-decorator/local-menus/tests/force_local_menu_on/test-force-local-menu-on.cpp' | |||
645 | --- gtk/window-decorator/local-menus/tests/force_local_menu_on/test-force-local-menu-on.cpp 1970-01-01 00:00:00 +0000 | |||
646 | +++ gtk/window-decorator/local-menus/tests/force_local_menu_on/test-force-local-menu-on.cpp 2012-02-02 17:13:31 +0000 | |||
647 | @@ -0,0 +1,67 @@ | |||
648 | 1 | #include "test-local-menu.h" | ||
649 | 2 | #include <cstring> | ||
650 | 3 | |||
651 | 4 | namespace | ||
652 | 5 | { | ||
653 | 6 | void initializeMetaButtonLayout (MetaButtonLayout *layout) | ||
654 | 7 | { | ||
655 | 8 | memset (layout, 0, sizeof (MetaButtonLayout)); | ||
656 | 9 | |||
657 | 10 | unsigned int i; | ||
658 | 11 | |||
659 | 12 | for (i = 0; i < MAX_BUTTONS_PER_CORNER; i++) | ||
660 | 13 | { | ||
661 | 14 | layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST; | ||
662 | 15 | layout->left_buttons[i] = META_BUTTON_FUNCTION_LAST; | ||
663 | 16 | } | ||
664 | 17 | } | ||
665 | 18 | } | ||
666 | 19 | |||
667 | 20 | class GtkWindowDecoratorTestLocalMenuLayout : | ||
668 | 21 | public GtkWindowDecoratorTestLocalMenu | ||
669 | 22 | { | ||
670 | 23 | public: | ||
671 | 24 | |||
672 | 25 | MetaButtonLayout * getLayout () { return &mLayout; } | ||
673 | 26 | |||
674 | 27 | virtual void SetUp () | ||
675 | 28 | { | ||
676 | 29 | GtkWindowDecoratorTestLocalMenu::SetUp (); | ||
677 | 30 | ::initializeMetaButtonLayout (&mLayout); | ||
678 | 31 | g_settings_set_boolean (getSettings (), "force-local-menus", TRUE); | ||
679 | 32 | } | ||
680 | 33 | |||
681 | 34 | private: | ||
682 | 35 | |||
683 | 36 | MetaButtonLayout mLayout; | ||
684 | 37 | }; | ||
685 | 38 | |||
686 | 39 | TEST_F (GtkWindowDecoratorTestLocalMenuLayout, TestForceNoButtonsSet) | ||
687 | 40 | { | ||
688 | 41 | force_local_menus_on (getWindow (), getLayout ()); | ||
689 | 42 | |||
690 | 43 | EXPECT_EQ (getLayout ()->right_buttons[0], META_BUTTON_FUNCTION_LAST); | ||
691 | 44 | EXPECT_EQ (getLayout ()->left_buttons[0], META_BUTTON_FUNCTION_LAST); | ||
692 | 45 | } | ||
693 | 46 | |||
694 | 47 | TEST_F (GtkWindowDecoratorTestLocalMenuLayout, TestForceNoCloseButtonSet) | ||
695 | 48 | { | ||
696 | 49 | getLayout ()->right_buttons[0] = META_BUTTON_FUNCTION_CLOSE; | ||
697 | 50 | |||
698 | 51 | force_local_menus_on (getWindow (), getLayout ()); | ||
699 | 52 | |||
700 | 53 | EXPECT_EQ (getLayout ()->right_buttons[1], META_BUTTON_FUNCTION_WINDOW_MENU); | ||
701 | 54 | EXPECT_EQ (getLayout ()->left_buttons[0], META_BUTTON_FUNCTION_LAST); | ||
702 | 55 | } | ||
703 | 56 | |||
704 | 57 | TEST_F (GtkWindowDecoratorTestLocalMenuLayout, TestForceNoCloseMinimizeMaximizeButtonSet) | ||
705 | 58 | { | ||
706 | 59 | getLayout ()->left_buttons[0] = META_BUTTON_FUNCTION_CLOSE; | ||
707 | 60 | getLayout ()->left_buttons[1] = META_BUTTON_FUNCTION_CLOSE; | ||
708 | 61 | getLayout ()->left_buttons[2] = META_BUTTON_FUNCTION_CLOSE; | ||
709 | 62 | |||
710 | 63 | force_local_menus_on (getWindow (), getLayout ()); | ||
711 | 64 | |||
712 | 65 | EXPECT_EQ (getLayout ()->right_buttons[0], META_BUTTON_FUNCTION_LAST); | ||
713 | 66 | EXPECT_EQ (getLayout ()->left_buttons[3], META_BUTTON_FUNCTION_WINDOW_MENU); | ||
714 | 67 | } | ||
715 | 0 | 68 | ||
716 | === added directory 'gtk/window-decorator/local-menus/tests/show_hide_menu' | |||
717 | === added file 'gtk/window-decorator/local-menus/tests/test-local-menu.h' | |||
718 | --- gtk/window-decorator/local-menus/tests/test-local-menu.h 1970-01-01 00:00:00 +0000 | |||
719 | +++ gtk/window-decorator/local-menus/tests/test-local-menu.h 2012-02-02 17:13:31 +0000 | |||
720 | @@ -0,0 +1,48 @@ | |||
721 | 1 | #include <gtest/gtest.h> | ||
722 | 2 | #include <gmock/gmock.h> | ||
723 | 3 | #include "local-menus.h" | ||
724 | 4 | #include <X11/Xlib.h> | ||
725 | 5 | #include <gio/gio.h> | ||
726 | 6 | |||
727 | 7 | class GtkWindowDecoratorTestLocalMenu : | ||
728 | 8 | public ::testing::Test | ||
729 | 9 | { | ||
730 | 10 | public: | ||
731 | 11 | |||
732 | 12 | WnckWindow * getWindow () { return mWindow; } | ||
733 | 13 | GSettings * getSettings () { return mSettings; } | ||
734 | 14 | |||
735 | 15 | virtual void SetUp () | ||
736 | 16 | { | ||
737 | 17 | gtk_init (NULL, NULL); | ||
738 | 18 | |||
739 | 19 | mXDisplay = XOpenDisplay (NULL); | ||
740 | 20 | mXWindow = XCreateSimpleWindow (mXDisplay, DefaultRootWindow (mXDisplay), 0, 0, 100, 100, 0, 0, 0); | ||
741 | 21 | |||
742 | 22 | XMapRaised (mXDisplay, mXWindow); | ||
743 | 23 | |||
744 | 24 | XFlush (mXDisplay); | ||
745 | 25 | |||
746 | 26 | while (g_main_context_iteration (g_main_context_default (), FALSE)); | ||
747 | 27 | |||
748 | 28 | mWindow = wnck_window_get (mXWindow); | ||
749 | 29 | |||
750 | 30 | g_setenv("GSETTINGS_BACKEND", "memory", true); | ||
751 | 31 | mSettings = g_settings_new ("com.canonical.Unity.Menus"); | ||
752 | 32 | } | ||
753 | 33 | |||
754 | 34 | virtual void TearDown () | ||
755 | 35 | { | ||
756 | 36 | XDestroyWindow (mXDisplay, mXWindow); | ||
757 | 37 | XCloseDisplay (mXDisplay); | ||
758 | 38 | |||
759 | 39 | g_object_unref (mSettings); | ||
760 | 40 | } | ||
761 | 41 | |||
762 | 42 | private: | ||
763 | 43 | |||
764 | 44 | WnckWindow *mWindow; | ||
765 | 45 | Window mXWindow; | ||
766 | 46 | Display *mXDisplay; | ||
767 | 47 | GSettings *mSettings; | ||
768 | 48 | }; | ||
769 | 0 | 49 | ||
770 | === modified file 'gtk/window-decorator/metacity.c' | |||
771 | --- gtk/window-decorator/metacity.c 2012-01-12 06:48:58 +0000 | |||
772 | +++ gtk/window-decorator/metacity.c 2012-02-02 17:13:31 +0000 | |||
773 | @@ -24,6 +24,7 @@ | |||
774 | 24 | */ | 24 | */ |
775 | 25 | 25 | ||
776 | 26 | #include "gtk-window-decorator.h" | 26 | #include "gtk-window-decorator.h" |
777 | 27 | #include "local-menus.h" | ||
778 | 27 | 28 | ||
779 | 28 | #ifdef USE_METACITY | 29 | #ifdef USE_METACITY |
780 | 29 | 30 | ||
781 | @@ -488,6 +489,8 @@ | |||
782 | 488 | button_layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST; | 489 | button_layout->right_buttons[i] = META_BUTTON_FUNCTION_LAST; |
783 | 489 | } | 490 | } |
784 | 490 | 491 | ||
785 | 492 | force_local_menus_on (d->win, button_layout); | ||
786 | 493 | |||
787 | 491 | *flags = 0; | 494 | *flags = 0; |
788 | 492 | 495 | ||
789 | 493 | if (d->actions & WNCK_WINDOW_ACTION_CLOSE) | 496 | if (d->actions & WNCK_WINDOW_ACTION_CLOSE) |
790 | @@ -601,6 +604,11 @@ | |||
791 | 601 | GdkColor bg_color; | 604 | GdkColor bg_color; |
792 | 602 | double bg_alpha; | 605 | double bg_alpha; |
793 | 603 | 606 | ||
794 | 607 | memset (&button_layout, 0, sizeof (MetaButtonLayout)); | ||
795 | 608 | |||
796 | 609 | for (i = 0; i < MAX_BUTTONS_PER_CORNER; i++) | ||
797 | 610 | button_layout.left_buttons[i] = button_layout.right_buttons[i] = META_BUTTON_FUNCTION_LAST; | ||
798 | 611 | |||
799 | 604 | if (!d->pixmap || !d->picture) | 612 | if (!d->pixmap || !d->picture) |
800 | 605 | return; | 613 | return; |
801 | 606 | 614 | ||
802 | @@ -1078,6 +1086,15 @@ | |||
803 | 1078 | break; | 1086 | break; |
804 | 1079 | #endif | 1087 | #endif |
805 | 1080 | 1088 | ||
806 | 1089 | #ifdef META_HAS_LOCAL_MENUS | ||
807 | 1090 | case BUTTON_WINDOW_MENU: | ||
808 | 1091 | if (!meta_button_present (&button_layout, META_BUTTON_FUNCTION_WINDOW_MENU)) | ||
809 | 1092 | return FALSE; | ||
810 | 1093 | |||
811 | 1094 | space = &fgeom.window_menu_rect; | ||
812 | 1095 | break; | ||
813 | 1096 | #endif | ||
814 | 1097 | |||
815 | 1081 | default: | 1098 | default: |
816 | 1082 | return FALSE; | 1099 | return FALSE; |
817 | 1083 | } | 1100 | } |
818 | @@ -1490,6 +1507,11 @@ | |||
819 | 1490 | return META_BUTTON_FUNCTION_UNSTICK; | 1507 | return META_BUTTON_FUNCTION_UNSTICK; |
820 | 1491 | #endif | 1508 | #endif |
821 | 1492 | 1509 | ||
822 | 1510 | #ifdef META_HAS_LOCAL_MENUS | ||
823 | 1511 | else if (strcmp (str, "window_menu") == 0) | ||
824 | 1512 | return META_BUTTON_FUNCTION_WINDOW_MENU; | ||
825 | 1513 | #endif | ||
826 | 1514 | |||
827 | 1493 | else | 1515 | else |
828 | 1494 | return META_BUTTON_FUNCTION_LAST; | 1516 | return META_BUTTON_FUNCTION_LAST; |
829 | 1495 | } | 1517 | } |
830 | 1496 | 1518 | ||
831 | === modified file 'gtk/window-decorator/wnck.c' | |||
832 | --- gtk/window-decorator/wnck.c 2011-10-13 09:53:38 +0000 | |||
833 | +++ gtk/window-decorator/wnck.c 2012-02-02 17:13:31 +0000 | |||
834 | @@ -727,7 +727,8 @@ | |||
835 | 727 | stick_button_event, | 727 | stick_button_event, |
836 | 728 | unshade_button_event, | 728 | unshade_button_event, |
837 | 729 | unabove_button_event, | 729 | unabove_button_event, |
839 | 730 | unstick_button_event | 730 | unstick_button_event, |
840 | 731 | window_menu_button_event | ||
841 | 731 | }; | 732 | }; |
842 | 732 | 733 | ||
843 | 733 | d = calloc (1, sizeof (decor_t)); | 734 | d = calloc (1, sizeof (decor_t)); |
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; PER_CORNER; i++) PER_CORNER; i++) layout- >right_ buttons[ i] = META_BUTTON_ FUNCTION_ LAST;
297
298 - for (i = 3; i < MAX_BUTTONS_
299 + for (i = 4; i < MAX_BUTTONS_
300 button_
301 }
I'm not sure what the magic number "3"->"4" is. But we now seem to miss 3 entirely. Is that correct?