summaryrefslogtreecommitdiff
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2012-02-17 05:13:33 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2012-02-17 05:13:33 +0100
commit8bc3ae0338daa14a174df75443398169199c37ca (patch)
tree4ed288c46c90915687781a1c3437142e2066d37e
parentc9bd88a6f909a7115844463b5e8e7b79b89ffe42 (diff)
WindowButtonType: use fallback buttons if no one is valid, fix crash.
Fixes LP: #921130, code improved to avoid duplication. (bzr r1979.1.4)
-rw-r--r--plugins/unityshell/src/WindowButtons.cpp54
1 files changed, 20 insertions, 34 deletions
diff --git a/plugins/unityshell/src/WindowButtons.cpp b/plugins/unityshell/src/WindowButtons.cpp
index a9c7310dc..bbc61ecb3 100644
--- a/plugins/unityshell/src/WindowButtons.cpp
+++ b/plugins/unityshell/src/WindowButtons.cpp
@@ -190,6 +190,13 @@ public:
if (_type != panel::WindowButtonType::UNMAXIMIZE)
return;
+ panel::WindowButtonType real_type = panel::WindowButtonType::UNMAXIMIZE;
+
+ if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)
+ {
+ real_type = panel::WindowButtonType::MAXIMIZE;
+ }
+
if (_normal_dash_tex)
_normal_dash_tex->UnReference();
if (_prelight_dash_tex)
@@ -198,22 +205,11 @@ public:
_pressed_dash_tex->UnReference();
//!!FIXME!! - don't have disabled instances of the (un)maximize buttons
- if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)
- {
- // get maximize buttons
- _normal_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::NORMAL);
- _prelight_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::PRELIGHT);
- _pressed_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::PRESSED);
- _disabled_dash_tex = GetDashMaximizeWindowButton(panel::WindowState::DISABLED);
- }
- else
- {
- // get unmaximize buttons
- _normal_dash_tex = GetDashWindowButton(_type, panel::WindowState::NORMAL);
- _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT);
- _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED);
- _disabled_dash_tex = GetDashWindowButton(_type, panel::WindowState::DISABLED);
- }
+ // get (un)maximize buttons
+ _normal_dash_tex = GetDashWindowButton(real_type, panel::WindowState::NORMAL);
+ _prelight_dash_tex = GetDashWindowButton(real_type, panel::WindowState::PRELIGHT);
+ _pressed_dash_tex = GetDashWindowButton(real_type, panel::WindowState::PRESSED);
+ _disabled_dash_tex = GetDashWindowButton(real_type, panel::WindowState::DISABLED);
// still check if the dash is really opened,
// someone could change the form factor through dconf
@@ -292,7 +288,8 @@ private:
nux::BaseTexture* GetDashWindowButton(panel::WindowButtonType type,
panel::WindowState state)
{
- const char* names[] = { "close_dash", "minimize_dash", "unmaximize_dash" };
+ nux::BaseTexture* texture = nullptr;
+ const char* names[] = { "close_dash", "minimize_dash", "unmaximize_dash", "maximize_dash" };
const char* states[] = { "", "_prelight", "_pressed", "_disabled" };
std::ostringstream subpath;
@@ -302,26 +299,15 @@ private:
glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
glib::Error error;
- glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
-
- // not handling broken texture or missing files
- return nux::CreateTexture2DFromPixbuf(pixbuf, true);
- }
-
- nux::BaseTexture* GetDashMaximizeWindowButton(panel::WindowState state)
- {
- const char* states[] = { "", "_prelight", "_pressed", "_disabled" };
+ glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename, &error));
- std::ostringstream subpath;
- subpath << "maximize_dash" << states[static_cast<int>(state)] << ".png";
+ if (pixbuf && !error)
+ texture = nux::CreateTexture2DFromPixbuf(pixbuf, true);
- glib::String filename(g_build_filename(PKGDATADIR, subpath.str().c_str(), NULL));
-
- glib::Error error;
- glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file(filename.Value(), &error));
+ if (!texture)
+ texture = panel::Style::Instance().GetFallbackWindowButton(type, state);
- // not handling broken texture or missing files
- return nux::CreateTexture2DFromPixbuf(pixbuf, true);
+ return texture;
}
};