Merge lp:~3v1n0/unity/fix-windowbuttons-crash into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1982
Proposed branch: lp:~3v1n0/unity/fix-windowbuttons-crash
Merge into: lp:unity
Diff against target: 167 lines (+39/-44)
3 files modified
plugins/unityshell/src/PanelStyle.cpp (+13/-3)
plugins/unityshell/src/PanelStyle.h (+3/-4)
plugins/unityshell/src/WindowButtons.cpp (+23/-37)
To merge this branch: bzr merge lp:~3v1n0/unity/fix-windowbuttons-crash
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+93524@code.launchpad.net

Description of the change

Fix crash on missing dash WindowButton files

Improved the PanelStyle code to support the Maximize window button and to draw the cairo fallback version.
WindowButtons now uses less code duplication.

Testcase
1) remove your $prefix/share/unity/5/unmaximize_dash* $prefix/share/unity/5/maximize_dash* and so
2) restart unity, but it will always crash.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Looks fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/PanelStyle.cpp'
--- plugins/unityshell/src/PanelStyle.cpp 2012-02-08 21:44:50 +0000
+++ plugins/unityshell/src/PanelStyle.cpp 2012-02-17 04:18:18 +0000
@@ -207,12 +207,12 @@
207 }207 }
208208
209 if (!texture)209 if (!texture)
210 texture = GetWindowButtonForTheme(type, state);210 texture = GetFallbackWindowButton(type, state);
211211
212 return texture;212 return texture;
213}213}
214214
215nux::BaseTexture* Style::GetWindowButtonForTheme(WindowButtonType type,215nux::BaseTexture* Style::GetFallbackWindowButton(WindowButtonType type,
216 WindowState state)216 WindowState state)
217{217{
218 int width = 18, height = 18;218 int width = 18, height = 18;
@@ -231,6 +231,8 @@
231 main = main * 1.2f;231 main = main * 1.2f;
232 else if (state == WindowState::PRESSED)232 else if (state == WindowState::PRESSED)
233 main = main * 0.8f;233 main = main * 0.8f;
234 else if (state == WindowState::DISABLED)
235 main = main * 0.5f;
234236
235 cr = cairo_graphics.GetContext();237 cr = cairo_graphics.GetContext();
236 cairo_translate(cr, 0.5, 0.5);238 cairo_translate(cr, 0.5, 0.5);
@@ -258,7 +260,15 @@
258 cairo_move_to(cr, w, height / 2.0f);260 cairo_move_to(cr, w, height / 2.0f);
259 cairo_line_to(cr, width - w, height / 2.0f);261 cairo_line_to(cr, width - w, height / 2.0f);
260 }262 }
261 else263 else if (type == WindowButtonType::UNMAXIMIZE)
264 {
265 cairo_move_to(cr, w, h + h/5.0f);
266 cairo_line_to(cr, width - w, h + h/5.0f);
267 cairo_line_to(cr, width - w, height - h - h/5.0f);
268 cairo_line_to(cr, w, height - h - h/5.0f);
269 cairo_close_path(cr);
270 }
271 else // if (type == WindowButtonType::MAXIMIZE)
262 {272 {
263 cairo_move_to(cr, w, h);273 cairo_move_to(cr, w, h);
264 cairo_line_to(cr, width - w, h);274 cairo_line_to(cr, width - w, h);
265275
=== modified file 'plugins/unityshell/src/PanelStyle.h'
--- plugins/unityshell/src/PanelStyle.h 2012-02-12 15:48:12 +0000
+++ plugins/unityshell/src/PanelStyle.h 2012-02-17 04:18:18 +0000
@@ -35,7 +35,8 @@
35{35{
36 CLOSE,36 CLOSE,
37 MINIMIZE,37 MINIMIZE,
38 UNMAXIMIZE38 UNMAXIMIZE,
39 MAXIMIZE
39};40};
4041
41enum class WindowState42enum class WindowState
@@ -59,6 +60,7 @@
59 nux::NBitmapData* GetBackground(int width, int height, float opacity);60 nux::NBitmapData* GetBackground(int width, int height, float opacity);
6061
61 nux::BaseTexture* GetWindowButton(WindowButtonType type, WindowState state);62 nux::BaseTexture* GetWindowButton(WindowButtonType type, WindowState state);
63 nux::BaseTexture* GetFallbackWindowButton(WindowButtonType type, WindowState state);
6264
63 GdkPixbuf* GetHomeButton();65 GdkPixbuf* GetHomeButton();
6466
@@ -74,9 +76,6 @@
74 static void OnGtkThemeChanged(GObject* gobject,76 static void OnGtkThemeChanged(GObject* gobject,
75 GParamSpec* pspec,77 GParamSpec* pspec,
76 gpointer data);78 gpointer data);
77
78 nux::BaseTexture* GetWindowButtonForTheme(WindowButtonType type,
79 WindowState state);
80private:79private:
81 GtkStyleContext* _style_context;80 GtkStyleContext* _style_context;
82 char* _theme_name;81 char* _theme_name;
8382
=== modified file 'plugins/unityshell/src/WindowButtons.cpp'
--- plugins/unityshell/src/WindowButtons.cpp 2012-02-12 15:48:12 +0000
+++ plugins/unityshell/src/WindowButtons.cpp 2012-02-17 04:18:18 +0000
@@ -190,6 +190,13 @@
190 if (_type != panel::WindowButtonType::UNMAXIMIZE)190 if (_type != panel::WindowButtonType::UNMAXIMIZE)
191 return;191 return;
192192
193 panel::WindowButtonType real_type = panel::WindowButtonType::UNMAXIMIZE;
194
195 if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)
196 {
197 real_type = panel::WindowButtonType::MAXIMIZE;
198 }
199
193 if (_normal_dash_tex)200 if (_normal_dash_tex)
194 _normal_dash_tex->UnReference();201 _normal_dash_tex->UnReference();
195 if (_prelight_dash_tex)202 if (_prelight_dash_tex)
@@ -198,22 +205,11 @@
198 _pressed_dash_tex->UnReference();205 _pressed_dash_tex->UnReference();
199206
200 //!!FIXME!! - don't have disabled instances of the (un)maximize buttons207 //!!FIXME!! - don't have disabled instances of the (un)maximize buttons
201 if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)208 // get (un)maximize buttons
202 {209 _normal_dash_tex = GetDashWindowButton(real_type, panel::WindowState::NORMAL);
203 // get maximize buttons210 _prelight_dash_tex = GetDashWindowButton(real_type, panel::WindowState::PRELIGHT);
204 _normal_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::NORMAL);211 _pressed_dash_tex = GetDashWindowButton(real_type, panel::WindowState::PRESSED);
205 _prelight_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::PRELIGHT);212 _disabled_dash_tex = GetDashWindowButton(real_type, panel::WindowState::DISABLED);
206 _pressed_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::PRESSED);
207 _disabled_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::DISABLED);
208 }
209 else
210 {
211 // get unmaximize buttons
212 _normal_dash_tex = GetDashWindowButton(_type, panel::WindowState::NORMAL);
213 _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT);
214 _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED);
215 _disabled_dash_tex = GetDashWindowButton(_type, panel::WindowState::DISABLED);
216 }
217213
218 // still check if the dash is really opened,214 // still check if the dash is really opened,
219 // someone could change the form factor through dconf215 // someone could change the form factor through dconf
@@ -292,7 +288,8 @@
292 nux::BaseTexture* GetDashWindowButton(panel::WindowButtonType type,288 nux::BaseTexture* GetDashWindowButton(panel::WindowButtonType type,
293 panel::WindowState state)289 panel::WindowState state)
294 {290 {
295 const char* names[] = { "close_dash", "minimize_dash", "unmaximize_dash" };291 nux::BaseTexture* texture = nullptr;
292 const char* names[] = { "close_dash", "minimize_dash", "unmaximize_dash", "maximize_dash" };
296 const char* states[] = { "", "_prelight", "_pressed", "_disabled" };293 const char* states[] = { "", "_prelight", "_pressed", "_disabled" };
297294
298 std::ostringstream subpath;295 std::ostringstream subpath;
@@ -302,26 +299,15 @@
302 glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));299 glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
303300
304 glib::Error error;301 glib::Error error;
305 glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));302 glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename, &error));
306303
307 // not handling broken texture or missing files304 if (pixbuf && !error)
308 return nux::CreateTexture2DFromPixbuf(pixbuf, true);305 texture = nux::CreateTexture2DFromPixbuf(pixbuf, true);
309 }306
310307 if (!texture)
311 nux::BaseTexture* GetDashMaximizeWindowButton(panel::WindowState state)308 texture = panel::Style::Instance().GetFallbackWindowButton(type, state);
312 {309
313 const char* states[] = { "", "_prelight", "_pressed", "_disabled" };310 return texture;
314
315 std::ostringstream subpath;
316 subpath << "maximize_dash" << states[static_cast<int>(state)] << ".png";
317
318 glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
319
320 glib::Error error;
321 glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
322
323 // not handling broken texture or missing files
324 return nux::CreateTexture2DFromPixbuf(pixbuf, true);
325 }311 }
326};312};
327313