Merge lp:~muktupavels/compiz/gwd-support-metacity-3-22 into lp:compiz/0.9.13

Proposed by Alberts Muktupāvels
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 4086
Merged at revision: 4094
Proposed branch: lp:~muktupavels/compiz/gwd-support-metacity-3-22
Merge into: lp:compiz/0.9.13
Prerequisite: lp:~muktupavels/compiz/gwd-use-resize-border
Diff against target: 303 lines (+154/-18)
3 files modified
gtk/CMakeLists.txt (+2/-0)
gtk/config.h.gtk.in (+3/-0)
gtk/window-decorator/gwd-theme-metacity.c (+149/-18)
To merge this branch: bzr merge lp:~muktupavels/compiz/gwd-support-metacity-3-22
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+304690@code.launchpad.net

Commit message

GWD: add support for metacity 3.22

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) :
4085. By Alberts Muktupāvels

Rename button_to_meta_button_type to button_type_to_meta_button_type.

4086. By Alberts Muktupāvels

Simplify code.

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

I'm ok with this

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gtk/CMakeLists.txt'
2--- gtk/CMakeLists.txt 2016-10-26 18:31:46 +0000
3+++ gtk/CMakeLists.txt 2016-10-26 18:31:46 +0000
4@@ -28,6 +28,8 @@
5 pkg_check_modules (LIBMETACITY libmetacity>=3.20.0)
6
7 if (LIBMETACITY_FOUND)
8+ compiz_pkg_check_modules (HAVE_METACITY_3_22_0 libmetacity>=3.22.0)
9+
10 set (METACITY_INCLUDE_DIRS ${LIBMETACITY_INCLUDE_DIRS})
11 set (METACITY_LIBRARIES ${LIBMETACITY_LIBRARIES})
12 else (LIBMETACITY_FOUND)
13
14=== modified file 'gtk/config.h.gtk.in'
15--- gtk/config.h.gtk.in 2016-10-26 18:31:46 +0000
16+++ gtk/config.h.gtk.in 2016-10-26 18:31:46 +0000
17@@ -1,4 +1,7 @@
18 /* Define to 1 if Metacity support is enabled */
19 #cmakedefine USE_METACITY 1
20
21+/* Define to 1 if Metacity version >= 3.22.0 */
22+#cmakedefine HAVE_METACITY_3_22_0 1
23+
24 #define GETTEXT_PACKAGE "${GETTEXT_PACKAGE}"
25
26=== modified file 'gtk/window-decorator/gwd-theme-metacity.c'
27--- gtk/window-decorator/gwd-theme-metacity.c 2016-10-26 18:31:46 +0000
28+++ gtk/window-decorator/gwd-theme-metacity.c 2016-10-26 18:31:46 +0000
29@@ -40,7 +40,10 @@
30 MetaTheme *theme;
31
32 gulong button_layout_id;
33+
34+#ifndef HAVE_METACITY_3_22_0
35 MetaButtonLayout button_layout;
36+#endif
37 };
38
39 G_DEFINE_TYPE (GWDThemeMetacity, gwd_theme_metacity, GWD_TYPE_THEME)
40@@ -67,9 +70,70 @@
41 {
42 gboolean invert = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL;
43
44+#ifdef HAVE_METACITY_3_22_0
45+ meta_theme_set_button_layout (metacity->theme, button_layout, invert);
46+#else
47 metacity->button_layout = meta_button_layout_new (button_layout, invert);
48-}
49-
50+#endif
51+}
52+
53+static MetaButtonState
54+meta_button_state (gint state)
55+{
56+ if (state & IN_EVENT_WINDOW) {
57+ if (state & PRESSED_EVENT_WINDOW)
58+ return META_BUTTON_STATE_PRESSED;
59+
60+ return META_BUTTON_STATE_PRELIGHT;
61+ }
62+
63+ return META_BUTTON_STATE_NORMAL;
64+}
65+
66+#ifdef HAVE_METACITY_3_22_0
67+static MetaButtonState
68+meta_button_state_for_button_type (decor_t *decor,
69+ MetaButtonType type)
70+{
71+ switch (type) {
72+ case META_BUTTON_TYPE_CLOSE:
73+ return meta_button_state (decor->button_states[BUTTON_CLOSE]);
74+ case META_BUTTON_TYPE_MAXIMIZE:
75+ return meta_button_state (decor->button_states[BUTTON_MAX]);
76+ case META_BUTTON_TYPE_MINIMIZE:
77+ return meta_button_state (decor->button_states[BUTTON_MIN]);
78+ case META_BUTTON_TYPE_MENU:
79+ return meta_button_state (decor->button_states[BUTTON_MENU]);
80+ case META_BUTTON_TYPE_SHADE:
81+ return meta_button_state (decor->button_states[BUTTON_SHADE]);
82+ case META_BUTTON_TYPE_ABOVE:
83+ return meta_button_state (decor->button_states[BUTTON_ABOVE]);
84+ case META_BUTTON_TYPE_STICK:
85+ return meta_button_state (decor->button_states[BUTTON_STICK]);
86+ case META_BUTTON_TYPE_UNSHADE:
87+ return meta_button_state (decor->button_states[BUTTON_UNSHADE]);
88+ case META_BUTTON_TYPE_UNABOVE:
89+ return meta_button_state (decor->button_states[BUTTON_UNABOVE]);
90+ case META_BUTTON_TYPE_UNSTICK:
91+ return meta_button_state (decor->button_states[BUTTON_UNSTICK]);
92+ default:
93+ break;
94+ }
95+
96+ return META_BUTTON_STATE_NORMAL;
97+}
98+
99+static MetaButtonState
100+update_button_state (MetaButtonType type,
101+ GdkRectangle rect,
102+ gpointer user_data)
103+{
104+ decor_t *decor = (decor_t *) user_data;
105+
106+ return meta_button_state_for_button_type (decor, type);
107+}
108+
109+#else
110 static MetaButtonType
111 meta_function_to_type (MetaButtonFunction function)
112 {
113@@ -102,19 +166,6 @@
114 }
115
116 static MetaButtonState
117-meta_button_state (gint state)
118-{
119- if (state & IN_EVENT_WINDOW) {
120- if (state & PRESSED_EVENT_WINDOW)
121- return META_BUTTON_STATE_PRESSED;
122-
123- return META_BUTTON_STATE_PRELIGHT;
124- }
125-
126- return META_BUTTON_STATE_NORMAL;
127-}
128-
129-static MetaButtonState
130 meta_button_state_for_button_type (GWDThemeMetacity *metacity,
131 decor_t *decor,
132 MetaButtonType type)
133@@ -168,6 +219,7 @@
134
135 return META_BUTTON_STATE_NORMAL;
136 }
137+#endif
138
139 static gint
140 radius_to_width (gint radius,
141@@ -537,9 +589,15 @@
142 else
143 client_height = decor->border_layout.left.y2 - decor->border_layout.left.y1;
144
145+#ifdef HAVE_METACITY_3_22_0
146+ meta_theme_calc_geometry (metacity->theme, decor->gtk_theme_variant,
147+ frame_type, *flags, client_width, client_height,
148+ fgeom);
149+#else
150 meta_theme_calc_geometry (metacity->theme, decor->gtk_theme_variant,
151 frame_type, *flags, client_width, client_height,
152 &metacity->button_layout, fgeom);
153+#endif
154 }
155
156 static void
157@@ -586,6 +644,38 @@
158 decor->button_width = width - min_x;
159 }
160
161+#ifdef HAVE_METACITY_3_22_0
162+static MetaButtonType
163+button_type_to_meta_button_type (gint button_type)
164+{
165+ switch (button_type) {
166+ case BUTTON_MENU:
167+ return META_BUTTON_TYPE_MENU;
168+ case BUTTON_MIN:
169+ return META_BUTTON_TYPE_MINIMIZE;
170+ case BUTTON_MAX:
171+ return META_BUTTON_TYPE_MAXIMIZE;
172+ case BUTTON_CLOSE:
173+ return META_BUTTON_TYPE_CLOSE;
174+ case BUTTON_SHADE:
175+ return META_BUTTON_TYPE_SHADE;
176+ case BUTTON_ABOVE:
177+ return META_BUTTON_TYPE_ABOVE;
178+ case BUTTON_STICK:
179+ return META_BUTTON_TYPE_STICK;
180+ case BUTTON_UNSHADE:
181+ return META_BUTTON_TYPE_UNSHADE;
182+ case BUTTON_UNABOVE:
183+ return META_BUTTON_TYPE_UNABOVE;
184+ case BUTTON_UNSTICK:
185+ return META_BUTTON_TYPE_UNSTICK;
186+ default:
187+ break;
188+ }
189+
190+ return META_BUTTON_TYPE_LAST;
191+}
192+#else
193 static gboolean
194 button_present (GWDThemeMetacity *metacity,
195 MetaButtonFunction function)
196@@ -633,6 +723,7 @@
197
198 return META_BUTTON_FUNCTION_LAST;
199 }
200+#endif
201
202 static gboolean
203 setup_theme (GWDThemeMetacity *metacity)
204@@ -728,12 +819,10 @@
205 GtkWidget *style_window = gwd_theme_get_style_window (theme);
206 cairo_surface_t *surface;
207 Picture src;
208- MetaButtonState button_states [META_BUTTON_TYPE_LAST];
209 MetaFrameGeometry fgeom;
210 MetaFrameFlags flags;
211 MetaFrameType frame_type;
212 cairo_t *cr;
213- gint i;
214 Region top_region;
215 Region bottom_region;
216 Region left_region;
217@@ -773,8 +862,12 @@
218 draw_shadow_background (decor, cr, decor->shadow, decor->context);
219 }
220
221- for (i = 0; i < META_BUTTON_TYPE_LAST; ++i)
222+#ifndef HAVE_METACITY_3_22_0
223+ MetaButtonState button_states [META_BUTTON_TYPE_LAST];
224+
225+ for (gint i = 0; i < META_BUTTON_TYPE_LAST; ++i)
226 button_states[i] = meta_button_state_for_button_type (metacity, decor, i);
227+#endif
228
229 /* Draw something that will be almost invisible to user. This is hacky way
230 * to fix invisible decorations. */
231@@ -791,11 +884,18 @@
232 src = XRenderCreatePicture (xdisplay, cairo_xlib_surface_get_drawable (surface),
233 xformat_rgba, 0, NULL);
234
235+#ifdef HAVE_METACITY_3_22_0
236+ meta_theme_draw_frame (metacity->theme, decor->gtk_theme_variant, cr, frame_type, flags,
237+ fgeom.width - fgeom.borders.total.left - fgeom.borders.total.right,
238+ fgeom.height - fgeom.borders.total.top - fgeom.borders.total.bottom,
239+ decor->name, update_button_state, decor, decor->icon_pixbuf, NULL);
240+#else
241 meta_theme_draw_frame (metacity->theme, decor->gtk_theme_variant, cr, frame_type, flags,
242 fgeom.width - fgeom.borders.total.left - fgeom.borders.total.right,
243 fgeom.height - fgeom.borders.total.top - fgeom.borders.total.bottom,
244 decor->name, &metacity->button_layout,
245 button_states, decor->icon_pixbuf, NULL);
246+#endif
247
248 if (fgeom.borders.visible.top + fgeom.borders.shadow.top) {
249 top_region = get_top_border_region (&fgeom, !decor->frame->has_shadow_extents);
250@@ -1123,8 +1223,10 @@
251 MetaFrameGeometry fgeom;
252 MetaFrameType frame_type;
253 MetaFrameFlags flags;
254+#ifndef HAVE_METACITY_3_22_0
255 MetaButtonFunction button_function;
256 MetaButtonSpace *space;
257+#endif
258
259 if (!decor->context) {
260 /* undecorated windows implicitly have no buttons */
261@@ -1135,6 +1237,34 @@
262
263 get_decoration_geometry (metacity, decor, &flags, &fgeom, frame_type);
264
265+#ifdef HAVE_METACITY_3_22_0
266+ MetaButtonType button_type = button_type_to_meta_button_type (i);
267+ MetaButton **buttons = meta_theme_get_buttons (metacity->theme);
268+
269+ for (gint index = 0; buttons[index]; index++) {
270+ if (meta_button_get_type (buttons[index]) == button_type) {
271+ GdkRectangle rect;
272+
273+ meta_button_get_event_rect (buttons[index], &rect);
274+
275+ if (rect.width != 0 && rect.height != 0) {
276+ *x = rect.x;
277+ *y = rect.y;
278+ *w = rect.width;
279+ *h = rect.height;
280+
281+ *x = *x - fgeom.borders.invisible.left + fgeom.borders.resize.left;
282+ *y = *y - fgeom.borders.invisible.top + fgeom.borders.resize.top;
283+
284+ g_free (buttons);
285+ return TRUE;
286+ }
287+ }
288+ }
289+
290+ g_free (buttons);
291+ return FALSE;
292+#else
293 button_function = button_to_meta_button_function (i);
294 if (!button_present (metacity, button_function))
295 return FALSE;
296@@ -1186,6 +1316,7 @@
297 *y = *y - fgeom.borders.invisible.top + fgeom.borders.resize.top;
298
299 return TRUE;
300+#endif
301 }
302
303 static void

Subscribers

People subscribed via source and target branches