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
1=== modified file 'plugins/unityshell/src/PanelStyle.cpp'
2--- plugins/unityshell/src/PanelStyle.cpp 2012-02-08 21:44:50 +0000
3+++ plugins/unityshell/src/PanelStyle.cpp 2012-02-17 04:18:18 +0000
4@@ -207,12 +207,12 @@
5 }
6
7 if (!texture)
8- texture = GetWindowButtonForTheme(type, state);
9+ texture = GetFallbackWindowButton(type, state);
10
11 return texture;
12 }
13
14-nux::BaseTexture* Style::GetWindowButtonForTheme(WindowButtonType type,
15+nux::BaseTexture* Style::GetFallbackWindowButton(WindowButtonType type,
16 WindowState state)
17 {
18 int width = 18, height = 18;
19@@ -231,6 +231,8 @@
20 main = main * 1.2f;
21 else if (state == WindowState::PRESSED)
22 main = main * 0.8f;
23+ else if (state == WindowState::DISABLED)
24+ main = main * 0.5f;
25
26 cr = cairo_graphics.GetContext();
27 cairo_translate(cr, 0.5, 0.5);
28@@ -258,7 +260,15 @@
29 cairo_move_to(cr, w, height / 2.0f);
30 cairo_line_to(cr, width - w, height / 2.0f);
31 }
32- else
33+ else if (type == WindowButtonType::UNMAXIMIZE)
34+ {
35+ cairo_move_to(cr, w, h + h/5.0f);
36+ cairo_line_to(cr, width - w, h + h/5.0f);
37+ cairo_line_to(cr, width - w, height - h - h/5.0f);
38+ cairo_line_to(cr, w, height - h - h/5.0f);
39+ cairo_close_path(cr);
40+ }
41+ else // if (type == WindowButtonType::MAXIMIZE)
42 {
43 cairo_move_to(cr, w, h);
44 cairo_line_to(cr, width - w, h);
45
46=== modified file 'plugins/unityshell/src/PanelStyle.h'
47--- plugins/unityshell/src/PanelStyle.h 2012-02-12 15:48:12 +0000
48+++ plugins/unityshell/src/PanelStyle.h 2012-02-17 04:18:18 +0000
49@@ -35,7 +35,8 @@
50 {
51 CLOSE,
52 MINIMIZE,
53- UNMAXIMIZE
54+ UNMAXIMIZE,
55+ MAXIMIZE
56 };
57
58 enum class WindowState
59@@ -59,6 +60,7 @@
60 nux::NBitmapData* GetBackground(int width, int height, float opacity);
61
62 nux::BaseTexture* GetWindowButton(WindowButtonType type, WindowState state);
63+ nux::BaseTexture* GetFallbackWindowButton(WindowButtonType type, WindowState state);
64
65 GdkPixbuf* GetHomeButton();
66
67@@ -74,9 +76,6 @@
68 static void OnGtkThemeChanged(GObject* gobject,
69 GParamSpec* pspec,
70 gpointer data);
71-
72- nux::BaseTexture* GetWindowButtonForTheme(WindowButtonType type,
73- WindowState state);
74 private:
75 GtkStyleContext* _style_context;
76 char* _theme_name;
77
78=== modified file 'plugins/unityshell/src/WindowButtons.cpp'
79--- plugins/unityshell/src/WindowButtons.cpp 2012-02-12 15:48:12 +0000
80+++ plugins/unityshell/src/WindowButtons.cpp 2012-02-17 04:18:18 +0000
81@@ -190,6 +190,13 @@
82 if (_type != panel::WindowButtonType::UNMAXIMIZE)
83 return;
84
85+ panel::WindowButtonType real_type = panel::WindowButtonType::UNMAXIMIZE;
86+
87+ if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)
88+ {
89+ real_type = panel::WindowButtonType::MAXIMIZE;
90+ }
91+
92 if (_normal_dash_tex)
93 _normal_dash_tex->UnReference();
94 if (_prelight_dash_tex)
95@@ -198,22 +205,11 @@
96 _pressed_dash_tex->UnReference();
97
98 //!!FIXME!! - don't have disabled instances of the (un)maximize buttons
99- if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)
100- {
101- // get maximize buttons
102- _normal_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::NORMAL);
103- _prelight_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::PRELIGHT);
104- _pressed_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::PRESSED);
105- _disabled_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::DISABLED);
106- }
107- else
108- {
109- // get unmaximize buttons
110- _normal_dash_tex = GetDashWindowButton(_type, panel::WindowState::NORMAL);
111- _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT);
112- _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED);
113- _disabled_dash_tex = GetDashWindowButton(_type, panel::WindowState::DISABLED);
114- }
115+ // get (un)maximize buttons
116+ _normal_dash_tex = GetDashWindowButton(real_type, panel::WindowState::NORMAL);
117+ _prelight_dash_tex = GetDashWindowButton(real_type, panel::WindowState::PRELIGHT);
118+ _pressed_dash_tex = GetDashWindowButton(real_type, panel::WindowState::PRESSED);
119+ _disabled_dash_tex = GetDashWindowButton(real_type, panel::WindowState::DISABLED);
120
121 // still check if the dash is really opened,
122 // someone could change the form factor through dconf
123@@ -292,7 +288,8 @@
124 nux::BaseTexture* GetDashWindowButton(panel::WindowButtonType type,
125 panel::WindowState state)
126 {
127- const char* names[] = { "close_dash", "minimize_dash", "unmaximize_dash" };
128+ nux::BaseTexture* texture = nullptr;
129+ const char* names[] = { "close_dash", "minimize_dash", "unmaximize_dash", "maximize_dash" };
130 const char* states[] = { "", "_prelight", "_pressed", "_disabled" };
131
132 std::ostringstream subpath;
133@@ -302,26 +299,15 @@
134 glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
135
136 glib::Error error;
137- glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
138-
139- // not handling broken texture or missing files
140- return nux::CreateTexture2DFromPixbuf(pixbuf, true);
141- }
142-
143- nux::BaseTexture* GetDashMaximizeWindowButton(panel::WindowState state)
144- {
145- const char* states[] = { "", "_prelight", "_pressed", "_disabled" };
146-
147- std::ostringstream subpath;
148- subpath << "maximize_dash" << states[static_cast<int>(state)] << ".png";
149-
150- glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
151-
152- glib::Error error;
153- glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
154-
155- // not handling broken texture or missing files
156- return nux::CreateTexture2DFromPixbuf(pixbuf, true);
157+ glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename, &error));
158+
159+ if (pixbuf && !error)
160+ texture = nux::CreateTexture2DFromPixbuf(pixbuf, true);
161+
162+ if (!texture)
163+ texture = panel::Style::Instance().GetFallbackWindowButton(type, state);
164+
165+ return texture;
166 }
167 };
168