Merge lp:~muktupavels/compiz/gwd-improve-metacity into lp:compiz/0.9.12

Proposed by Alberts Muktupāvels
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 4075
Merged at revision: 4058
Proposed branch: lp:~muktupavels/compiz/gwd-improve-metacity
Merge into: lp:compiz/0.9.12
Prerequisite: lp:~muktupavels/compiz/gwd-theme-style-window
Diff against target: 233 lines (+59/-47)
1 file modified
gtk/window-decorator/gwd-theme-metacity.c (+59/-47)
To merge this branch: bzr merge lp:~muktupavels/compiz/gwd-improve-metacity
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+296868@code.launchpad.net

Commit message

gtk-window-decorator: improve Metacity theme.

- Don't re-create MetaStyleInfo every time, we need to do this only when we get style-updated signal. Also with Metacity theme style info is almost unused - so creating / destroying was unneeded work. Style info only is used to create titlebar font and in meta_theme_draw_frame.

- Update invisible grab area size calculation. MetaFrameBorders might not be same between maximized and non-maximized windows.

Description of the change

- Don't re-create MetaStyleInfo every time, we need to do this only when we get style-updated signal. Also with Metacity theme style info is almost unused - so creating / destroying was unneeded work. Style info only is used to create titlebar font and in meta_theme_draw_frame.

- Update invisible grab area size calculation. MetaFrameBorders might not be same between maximized and non-maximized windows.

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

LGTM otherwise

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

"Is there any reason why these blocks which are both contingent on the same if statement aren't in the same block anymore? (e.g. flags & META_FRAME_ALLOWS_VERTICAL_RESIZE)"

Invisible border size between normal and maximized window can be different. So we need first get borders for normal window and then for maximized window.

Probably `if (flags & META_FRAME_ALLOWS_*_RESIZE)` can be removed. If resize is not allowed then invisible border will be 0.

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

Good for 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/gwd-theme-metacity.c'
2--- gtk/window-decorator/gwd-theme-metacity.c 2016-06-09 15:21:40 +0000
3+++ gtk/window-decorator/gwd-theme-metacity.c 2016-06-09 15:21:40 +0000
4@@ -40,6 +40,8 @@
5
6 MetaTheme *theme;
7
8+ GHashTable *style_variants;
9+
10 gulong button_layout_id;
11 MetaButtonLayout button_layout;
12
13@@ -48,6 +50,27 @@
14
15 G_DEFINE_TYPE (GWDThemeMetacity, gwd_theme_metacity, GWD_TYPE_THEME)
16
17+static MetaStyleInfo *
18+get_style_info (GWDThemeMetacity *metacity,
19+ decor_t *decor)
20+{
21+ const gchar *variant = decor != NULL ? decor->gtk_theme_variant : NULL;
22+ const gchar *key = variant != NULL ? variant : "default";
23+ MetaStyleInfo *style = g_hash_table_lookup (metacity->style_variants, key);
24+
25+ if (style == NULL) {
26+ GWDTheme *theme = GWD_THEME (metacity);
27+ GtkWidget *style_window = gwd_theme_get_style_window (theme);
28+ GdkScreen *screen = gtk_widget_get_screen (style_window);
29+
30+ style = meta_theme_create_style_info (screen, variant);
31+
32+ g_hash_table_insert (metacity->style_variants, g_strdup (key), style);
33+ }
34+
35+ return style;
36+}
37+
38 static MetaFrameType
39 frame_type_from_string (const gchar *str)
40 {
41@@ -581,19 +604,17 @@
42 Region left,
43 Region right)
44 {
45- long *data;
46- GdkDisplay *display;
47- Display *xdisplay;
48- gint nQuad;
49+ GdkDisplay *display = gdk_display_get_default ();
50+ Display *xdisplay = gdk_x11_display_get_xdisplay (display);
51+ unsigned int frame_type = populate_frame_type (d);
52+ unsigned int frame_state = populate_frame_state (d);
53+ unsigned int frame_actions = populate_frame_actions (d);
54+ unsigned int nOffset = 1;
55 decor_extents_t win_extents;
56 decor_extents_t frame_win_extents;
57 decor_extents_t max_win_extents;
58 decor_extents_t frame_max_win_extents;
59 decor_quad_t quads[N_QUADS_MAX];
60- unsigned int nOffset;
61- unsigned int frame_type;
62- unsigned int frame_state;
63- unsigned int frame_actions;
64 gint w;
65 gint lh;
66 gint rh;
67@@ -601,46 +622,44 @@
68 gint bottom_stretch_offset;
69 gint left_stretch_offset;
70 gint right_stretch_offset;
71-
72- display = gdk_display_get_default ();
73- xdisplay = gdk_x11_display_get_xdisplay (display);
74-
75- nOffset = 1;
76-
77- frame_type = populate_frame_type (d);
78- frame_state = populate_frame_state (d);
79- frame_actions = populate_frame_actions (d);
80+ gint nQuad;
81+ long *data;
82
83 win_extents = frame_win_extents = d->frame->win_extents;
84 max_win_extents = frame_max_win_extents = d->frame->max_win_extents;
85
86 /* Add the invisible grab area padding */
87 {
88- GWDTheme *theme = GWD_THEME (metacity);
89- GtkWidget *style_window = gwd_theme_get_style_window (theme);
90- GdkScreen *screen = gtk_widget_get_screen (style_window);
91- MetaStyleInfo *style_info = meta_theme_create_style_info (screen, d->gtk_theme_variant);
92+ MetaFrameFlags tmp_flags;
93 MetaFrameBorders borders;
94
95- meta_theme_get_frame_borders (metacity->theme, style_info, type,
96- d->frame->text_height,
97- flags, &borders);
98+ tmp_flags = flags & ~META_FRAME_MAXIMIZED;
99+ meta_theme_get_frame_borders (metacity->theme, get_style_info (metacity, d),
100+ type, d->frame->text_height, tmp_flags, &borders);
101
102 if (flags & META_FRAME_ALLOWS_HORIZONTAL_RESIZE) {
103 frame_win_extents.left += borders.invisible.left;
104 frame_win_extents.right += borders.invisible.right;
105+ }
106+
107+ if (flags & META_FRAME_ALLOWS_VERTICAL_RESIZE) {
108+ frame_win_extents.bottom += borders.invisible.bottom;
109+ frame_win_extents.top += borders.invisible.top;
110+ }
111+
112+ tmp_flags = flags | META_FRAME_MAXIMIZED;
113+ meta_theme_get_frame_borders (metacity->theme, get_style_info (metacity, d),
114+ type, d->frame->text_height, tmp_flags, &borders);
115+
116+ if (flags & META_FRAME_ALLOWS_HORIZONTAL_RESIZE) {
117 frame_max_win_extents.left += borders.invisible.left;
118 frame_max_win_extents.right += borders.invisible.right;
119 }
120
121 if (flags & META_FRAME_ALLOWS_VERTICAL_RESIZE) {
122- frame_win_extents.bottom += borders.invisible.bottom;
123- frame_win_extents.top += borders.invisible.top;
124 frame_max_win_extents.bottom += borders.invisible.bottom;
125 frame_max_win_extents.top += borders.invisible.top;
126 }
127-
128- meta_style_info_unref (style_info);
129 }
130
131 w = d->border_layout.top.x2 - d->border_layout.top.x1 -
132@@ -698,10 +717,6 @@
133 MetaFrameGeometry *fgeom,
134 MetaFrameType frame_type)
135 {
136- GWDTheme *theme = GWD_THEME (metacity);
137- GtkWidget *style_window = gwd_theme_get_style_window (theme);
138- GdkScreen *screen = gtk_widget_get_screen (style_window);
139- MetaStyleInfo *style_info = meta_theme_create_style_info (screen, decor->gtk_theme_variant);
140 gint client_width;
141 gint client_height;
142
143@@ -764,11 +779,9 @@
144 else
145 client_height = decor->border_layout.left.y2 - decor->border_layout.left.y1;
146
147- meta_theme_calc_geometry (metacity->theme, style_info, frame_type,
148- decor->frame->text_height, *flags, client_width,
149+ meta_theme_calc_geometry (metacity->theme, get_style_info (metacity, decor),
150+ frame_type, decor->frame->text_height, *flags, client_width,
151 client_height, &metacity->button_layout, fgeom);
152-
153- meta_style_info_unref (style_info);
154 }
155
156 static void
157@@ -927,6 +940,8 @@
158 {
159 GWDThemeMetacity *metacity = GWD_THEME_METACITY (object);
160
161+ g_clear_pointer (&metacity->style_variants, g_hash_table_destroy);
162+
163 if (metacity->button_layout_id != 0) {
164 GWDSettings *settings = gwd_theme_get_settings (GWD_THEME (metacity));
165
166@@ -942,6 +957,9 @@
167 static void
168 gwd_theme_metacity_style_updated (GWDTheme *theme)
169 {
170+ GWDThemeMetacity *metacity = GWD_THEME_METACITY (theme);
171+
172+ g_hash_table_remove_all (metacity->style_variants);
173 }
174
175 static void
176@@ -953,8 +971,7 @@
177 GdkDisplay *display = gdk_display_get_default ();
178 Display *xdisplay = gdk_x11_display_get_xdisplay (display);
179 GtkWidget *style_window = gwd_theme_get_style_window (theme);
180- GdkScreen *screen = gtk_widget_get_screen (style_window);
181- MetaStyleInfo *style_info = meta_theme_create_style_info (screen, decor->gtk_theme_variant);
182+ MetaStyleInfo *style_info = get_style_info (metacity, decor);
183 GtkStyleContext *context = gtk_widget_get_style_context (style_window);
184 cairo_surface_t *surface;
185 Picture src;
186@@ -1044,7 +1061,6 @@
187 decor->layout, decor->frame->text_height, &metacity->button_layout,
188 button_states, decor->icon_pixbuf, NULL);
189
190- meta_style_info_unref (style_info);
191
192 if (fgeom.borders.visible.top) {
193 top_region = get_top_border_region (&fgeom, fgeom.width);
194@@ -1180,9 +1196,7 @@
195 decor_frame_t *frame)
196 {
197 GWDThemeMetacity *metacity = GWD_THEME_METACITY (theme);
198- GtkWidget *style_window = gwd_theme_get_style_window (theme);
199- GdkScreen *screen = gtk_widget_get_screen (style_window);
200- MetaStyleInfo *style_info = meta_theme_create_style_info (screen, NULL);
201+ MetaStyleInfo *style_info = get_style_info (metacity, NULL);
202 MetaFrameType frame_type = frame_type_from_string (frame->type);
203 MetaFrameBorders borders;
204
205@@ -1205,8 +1219,6 @@
206 frame->max_win_extents.left = borders.visible.left;
207 frame->max_win_extents.right = borders.visible.right;
208
209- meta_style_info_unref (style_info);
210-
211 gwd_decor_frame_unref (frame);
212 }
213
214@@ -1423,9 +1435,7 @@
215 decor_frame_t *frame)
216 {
217 GWDThemeMetacity *metacity = GWD_THEME_METACITY (theme);
218- GtkWidget *style_window = gwd_theme_get_style_window (theme);
219- GdkScreen *screen = gtk_widget_get_screen (style_window);
220- MetaStyleInfo *style_info = meta_theme_create_style_info (screen, NULL);
221+ MetaStyleInfo *style_info = get_style_info (metacity, NULL);
222 PangoFontDescription *font_desc = meta_style_info_create_font_desc (style_info);
223 MetaFrameType type = frame_type_from_string (frame->type);
224 MetaFrameFlags flags = 0xc33; /* FIXME */
225@@ -1459,6 +1469,8 @@
226 static void
227 gwd_theme_metacity_init (GWDThemeMetacity *metacity)
228 {
229+ metacity->style_variants = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
230+ (GDestroyNotify) meta_style_info_unref);
231 }
232
233 /**

Subscribers

People subscribed via source and target branches