Merge lp:~muktupavels/compiz/gwd-theme-implement-update-border-extents into lp:compiz/0.9.12

Proposed by Alberts Muktupāvels
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 4032
Merged at revision: 4028
Proposed branch: lp:~muktupavels/compiz/gwd-theme-implement-update-border-extents
Merge into: lp:compiz/0.9.12
Prerequisite: lp:~muktupavels/compiz/gwd-theme-implement-get-shadow
Diff against target: 317 lines (+99/-88)
8 files modified
gtk/window-decorator/cairo.c (+0/-14)
gtk/window-decorator/frames.c (+2/-3)
gtk/window-decorator/gtk-window-decorator.c (+0/-3)
gtk/window-decorator/gtk-window-decorator.h (+0/-7)
gtk/window-decorator/gwd-theme-cairo.c (+20/-0)
gtk/window-decorator/gwd-theme-metacity.c (+76/-1)
gtk/window-decorator/metacity.c (+0/-59)
gtk/window-decorator/wnck.c (+1/-1)
To merge this branch: bzr merge lp:~muktupavels/compiz/gwd-theme-implement-update-border-extents
Reviewer Review Type Date Requested Status
Sam Spilsbury Approve
Review via email: mp+295207@code.launchpad.net

Commit message

GWDTheme: implement update_border_extents.

Description of the change

GWDTheme: implement update_border_extents.

To post a comment you must log in.
4027. By Alberts Muktupāvels

Add space.

4028. By Alberts Muktupāvels

Simplify code.

Revision history for this message
Alberts Muktupāvels (muktupavels) wrote :

Sam, did you look at this?

Revision history for this message
Sam Spilsbury (smspillaz) :
4029. By Alberts Muktupāvels

Merge changes from lp:~albertsmuktupavels/compiz/gwd-theme-implement-get-shadow.

4030. By Alberts Muktupāvels

Revert re-styling in wnck.c.

Revision history for this message
Alberts Muktupāvels (muktupavels) wrote :

1) "As I mentioned in another review - it may be better to have a mechanism in place to update this property when the metacity theme changes."

When metacity theme changes new GWDTheme will be created. Also in metacity 3.20 there will be no meta_theme_get_current.

2) Assign and declare... Is that required? I find code more readable this way. Also existing code first declare varible and only then assign.

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

> 1) "As I mentioned in another review - it may be better to have a mechanism in
> place to update this property when the metacity theme changes."
>
> When metacity theme changes new GWDTheme will be created. Also in metacity
> 3.20 there will be no meta_theme_get_current.

Ah okay, I've found it - g_set_object(&gwd_theme, g_object_new ...) in an older review.

Might be good to add a comment in the constructor there about how a GWDTheme exists only for a single MetaTheme and is destroyed and re-created on theme changes, since that threw me off initially.

>
> 2) Assign and declare... Is that required? I find code more readable this way.
> Also existing code first declare varible and only then assign.

The existing code does use the C89 style, though there's really no reason for it to, since we're not building on Windows ;-). C89 comes with a lot of serious disadvantages and switching to assign-and-declare has lots of advantages:

1. Eliminates a whole class of bugs where unassigned (and thus garbage) variables are used.
2. Keeps the declaration as close as possible to first use, so you can easily see where a particular variable becomes relevant.
3. Prevents readers from having to jump up and down in order to determine variable types (though admittedly this is more a symptom of excessively long functions. The C89 style just exacerbates the problem).

I don't mind if further refactors to clean all that up come in later revisions - its just low hanging fruit and something worth doing whilst the code is being touched.

4031. By Alberts Muktupāvels

Add comment.

4032. By Alberts Muktupāvels

Assign and declare.

Revision history for this message
Alberts Muktupāvels (muktupavels) wrote :

Added comment and fixed few "assign and declare" things. Can this branch we considered ready?

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

Looks good to me :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gtk/window-decorator/cairo.c'
2--- gtk/window-decorator/cairo.c 2016-02-29 13:41:59 +0000
3+++ gtk/window-decorator/cairo.c 2016-05-20 10:29:03 +0000
4@@ -954,17 +954,3 @@
5 {
6 return 1.0f;
7 }
8-
9-void
10-update_border_extents (decor_frame_t *frame)
11-{
12- frame = gwd_decor_frame_ref (frame);
13-
14- gwd_cairo_window_decoration_get_extents (&frame->win_extents,
15- &frame->max_win_extents);
16-
17- frame->titlebar_height = frame->max_titlebar_height =
18- (frame->text_height < 17) ? 17 : frame->text_height;
19-
20- gwd_decor_frame_unref (frame);
21-}
22
23=== modified file 'gtk/window-decorator/frames.c'
24--- gtk/window-decorator/frames.c 2016-05-20 10:29:02 +0000
25+++ gtk/window-decorator/frames.c 2016-05-20 10:29:03 +0000
26@@ -280,9 +280,8 @@
27
28 frame_update_titlebar_font (frame);
29
30- if (strcmp (frame->type, "switcher") != 0 &&
31- strcmp (frame->type, "bare") != 0)
32- (*theme_update_border_extents) (frame);
33+ if (strcmp (frame->type, "switcher") != 0 && strcmp (frame->type, "bare") != 0)
34+ gwd_theme_update_border_extents (gwd_theme, frame);
35
36 gwd_theme_get_shadow (gwd_theme, frame, &active_o, TRUE);
37 gwd_theme_get_shadow (gwd_theme, frame, &inactive_o, FALSE);
38
39=== modified file 'gtk/window-decorator/gtk-window-decorator.c'
40--- gtk/window-decorator/gtk-window-decorator.c 2016-05-20 10:29:02 +0000
41+++ gtk/window-decorator/gtk-window-decorator.c 2016-05-20 10:29:03 +0000
42@@ -173,7 +173,6 @@
43
44 theme_draw_window_decoration = meta_draw_window_decoration;
45 theme_calc_decoration_size = meta_calc_decoration_size;
46- theme_update_border_extents = meta_update_border_extents;
47 theme_get_event_window_position = meta_get_event_window_position;
48 theme_get_button_position = meta_get_button_position;
49 theme_get_title_scale = meta_get_title_scale;
50@@ -184,7 +183,6 @@
51
52 theme_draw_window_decoration = draw_window_decoration;
53 theme_calc_decoration_size = calc_decoration_size;
54- theme_update_border_extents = update_border_extents;
55 theme_get_event_window_position = get_event_window_position;
56 theme_get_button_position = get_button_position;
57 theme_get_title_scale = get_title_scale;
58@@ -194,7 +192,6 @@
59
60 theme_draw_window_decoration = draw_window_decoration;
61 theme_calc_decoration_size = calc_decoration_size;
62- theme_update_border_extents = update_border_extents;
63 theme_get_event_window_position = get_event_window_position;
64 theme_get_button_position = get_button_position;
65 theme_get_title_scale = get_title_scale;
66
67=== modified file 'gtk/window-decorator/gtk-window-decorator.h'
68--- gtk/window-decorator/gtk-window-decorator.h 2016-05-20 10:29:02 +0000
69+++ gtk/window-decorator/gtk-window-decorator.h 2016-05-20 10:29:03 +0000
70@@ -314,7 +314,6 @@
71 int text_width,
72 int *width,
73 int *height);
74-void (*theme_update_border_extents) (decor_frame_t *frame);
75 void (*theme_get_event_window_position) (decor_t *d,
76
77 gint i,
78@@ -565,9 +564,6 @@
79 gint *width,
80 gint *height);
81
82-void
83-update_border_extents ();
84-
85 gboolean
86 get_button_position (decor_t *d,
87 gint i,
88@@ -656,9 +652,6 @@
89 meta_get_title_scale (decor_frame_t *);
90
91 void
92-meta_update_border_extents ();
93-
94-void
95 meta_update_button_layout (const char *value);
96
97 #endif
98
99=== modified file 'gtk/window-decorator/gwd-theme-cairo.c'
100--- gtk/window-decorator/gwd-theme-cairo.c 2016-05-20 10:29:02 +0000
101+++ gtk/window-decorator/gwd-theme-cairo.c 2016-05-20 10:29:03 +0000
102@@ -18,6 +18,8 @@
103 */
104
105 #include "config.h"
106+#include "gtk-window-decorator.h"
107+#include "gwd-cairo-window-decoration-util.h"
108 #include "gwd-theme-cairo.h"
109
110 struct _GWDThemeCairo
111@@ -28,8 +30,26 @@
112 G_DEFINE_TYPE (GWDThemeCairo, gwd_theme_cairo, GWD_TYPE_THEME)
113
114 static void
115+gwd_theme_cairo_update_border_extents (GWDTheme *theme,
116+ decor_frame_t *frame)
117+{
118+ frame = gwd_decor_frame_ref (frame);
119+
120+ gwd_cairo_window_decoration_get_extents (&frame->win_extents,
121+ &frame->max_win_extents);
122+
123+ frame->titlebar_height = frame->max_titlebar_height =
124+ (frame->text_height < 17) ? 17 : frame->text_height;
125+
126+ gwd_decor_frame_unref (frame);
127+}
128+
129+static void
130 gwd_theme_cairo_class_init (GWDThemeCairoClass *cairo_class)
131 {
132+ GWDThemeClass *theme_class = GWD_THEME_CLASS (cairo_class);
133+
134+ theme_class->update_border_extents = gwd_theme_cairo_update_border_extents;
135 }
136
137 static void
138
139=== modified file 'gtk/window-decorator/gwd-theme-metacity.c'
140--- gtk/window-decorator/gwd-theme-metacity.c 2016-05-20 10:29:02 +0000
141+++ gtk/window-decorator/gwd-theme-metacity.c 2016-05-20 10:29:03 +0000
142@@ -18,18 +18,93 @@
143 */
144
145 #include "config.h"
146+
147+#include <metacity-private/theme.h>
148+
149+#include "gtk-window-decorator.h"
150 #include "gwd-theme-metacity.h"
151
152 struct _GWDThemeMetacity
153 {
154- GObject parent;
155+ GObject parent;
156+
157+ MetaTheme *theme;
158 };
159
160 G_DEFINE_TYPE (GWDThemeMetacity, gwd_theme_metacity, GWD_TYPE_THEME)
161
162+static GObject *
163+gwd_theme_metacity_constructor (GType type,
164+ guint n_properties,
165+ GObjectConstructParam *properties)
166+{
167+ GObject *object;
168+ GWDThemeMetacity *metacity;
169+
170+ object = G_OBJECT_CLASS (gwd_theme_metacity_parent_class)->constructor (type, n_properties, properties);
171+ metacity = GWD_THEME_METACITY (object);
172+
173+ /* Always valid and current MetaTheme! On theme change new GWDThemeMetacity
174+ * object will be created and old one destroyed. If Metacity theme is not
175+ * valid (gwd_metacity_window_decoration_update_meta_theme returns FALSE)
176+ * then GWDThemeCairo will be created.
177+ */
178+ metacity->theme = meta_theme_get_current ();
179+
180+ return object;
181+}
182+
183+static void
184+gwd_theme_metacity_update_border_extents (GWDTheme *theme,
185+ decor_frame_t *frame)
186+{
187+ GWDThemeMetacity *metacity = GWD_THEME_METACITY (theme);
188+ GdkScreen *screen = gtk_widget_get_screen (frame->style_window_rgba);
189+ MetaStyleInfo *style_info = meta_theme_create_style_info (screen, NULL);
190+ MetaFrameType frame_type;
191+ MetaFrameBorders borders;
192+
193+ gwd_decor_frame_ref (frame);
194+
195+ frame_type = meta_frame_type_from_string (frame->type);
196+ if (!(frame_type < META_FRAME_TYPE_LAST))
197+ frame_type = META_FRAME_TYPE_NORMAL;
198+
199+ meta_theme_get_frame_borders (metacity->theme, style_info, frame_type,
200+ frame->text_height, 0, &borders);
201+
202+ frame->win_extents.top = frame->win_extents.top;
203+ frame->win_extents.bottom = borders.visible.bottom;
204+ frame->win_extents.left = borders.visible.left;
205+ frame->win_extents.right = borders.visible.right;
206+
207+ frame->titlebar_height = borders.visible.top - frame->win_extents.top;
208+
209+ meta_theme_get_frame_borders (metacity->theme, style_info, frame_type,
210+ frame->text_height, META_FRAME_MAXIMIZED,
211+ &borders);
212+
213+ frame->max_win_extents.top = frame->win_extents.top;
214+ frame->max_win_extents.bottom = borders.visible.bottom;
215+ frame->max_win_extents.left = borders.visible.left;
216+ frame->max_win_extents.right = borders.visible.right;
217+
218+ frame->max_titlebar_height = borders.visible.top - frame->max_win_extents.top;
219+
220+ meta_style_info_unref (style_info);
221+
222+ gwd_decor_frame_unref (frame);
223+}
224+
225 static void
226 gwd_theme_metacity_class_init (GWDThemeMetacityClass *metacity_class)
227 {
228+ GObjectClass *object_class = G_OBJECT_CLASS (metacity_class);
229+ GWDThemeClass *theme_class = GWD_THEME_CLASS (metacity_class);
230+
231+ object_class->constructor = gwd_theme_metacity_constructor;
232+
233+ theme_class->update_border_extents = gwd_theme_metacity_update_border_extents;
234 }
235
236 static void
237
238=== modified file 'gtk/window-decorator/metacity.c'
239--- gtk/window-decorator/metacity.c 2016-03-17 17:47:36 +0000
240+++ gtk/window-decorator/metacity.c 2016-05-20 10:29:03 +0000
241@@ -1491,63 +1491,4 @@
242 meta_button_layout = new_layout;
243 }
244
245-void
246-meta_update_border_extents (decor_frame_t *frame)
247-{
248- MetaTheme *theme;
249- GdkScreen *screen;
250- MetaStyleInfo *style_info;
251- MetaFrameBorders borders;
252- MetaFrameType frame_type;
253- gint top_height;
254- gint bottom_height;
255- gint left_width;
256- gint right_width;
257-
258- gwd_decor_frame_ref (frame);
259-
260- frame_type = meta_frame_type_from_string (frame->type);
261- if (!(frame_type < META_FRAME_TYPE_LAST))
262- frame_type = META_FRAME_TYPE_NORMAL;
263-
264- theme = meta_theme_get_current ();
265-
266- screen = gtk_widget_get_screen (frame->style_window_rgba);
267- style_info = meta_theme_create_style_info (screen, NULL);
268-
269- meta_theme_get_frame_borders (theme, style_info, frame_type, frame->text_height,
270- 0, &borders);
271-
272- top_height = borders.visible.top;
273- bottom_height = borders.visible.bottom;
274- left_width = borders.visible.left;
275- right_width = borders.visible.right;
276-
277- frame->win_extents.top = frame->win_extents.top;
278- frame->win_extents.bottom = bottom_height;
279- frame->win_extents.left = left_width;
280- frame->win_extents.right = right_width;
281-
282- frame->titlebar_height = top_height - frame->win_extents.top;
283-
284- meta_theme_get_frame_borders (theme, style_info, frame_type, frame->text_height,
285- META_FRAME_MAXIMIZED, &borders);
286-
287- top_height = borders.visible.top;
288- bottom_height = borders.visible.bottom;
289- left_width = borders.visible.left;
290- right_width = borders.visible.right;
291-
292- frame->max_win_extents.top = frame->win_extents.top;
293- frame->max_win_extents.bottom = bottom_height;
294- frame->max_win_extents.left = left_width;
295- frame->max_win_extents.right = right_width;
296-
297- frame->max_titlebar_height = top_height - frame->max_win_extents.top;
298-
299- meta_style_info_unref (style_info);
300-
301- gwd_decor_frame_unref (frame);
302-}
303-
304 #endif
305
306=== modified file 'gtk/window-decorator/wnck.c'
307--- gtk/window-decorator/wnck.c 2016-03-17 17:47:36 +0000
308+++ gtk/window-decorator/wnck.c 2016-05-20 10:29:03 +0000
309@@ -169,7 +169,7 @@
310 {
311 decor_frame_t *frame = (decor_frame_t *) value;
312
313- (*theme_update_border_extents) (frame);
314+ gwd_theme_update_border_extents (gwd_theme, frame);
315 }
316
317 void

Subscribers

People subscribed via source and target branches