diff options
| author | Marco Trevisan (TreviƱo) <mail@3v1n0.net> | 2012-02-17 00:38:44 -0500 |
|---|---|---|
| committer | Tarmac <> | 2012-02-17 00:38:44 -0500 |
| commit | c581492df96e68fa82c896b1a3d2efbaa5751632 (patch) | |
| tree | 067b5bef56c58e2cf1758b53a41c7044c77d6d29 | |
| parent | ae4945283482cb6db49081464303955045af0a31 (diff) | |
| parent | 8bc3ae0338daa14a174df75443398169199c37ca (diff) | |
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.. Fixes: https://bugs.launchpad.net/bugs/921130. Approved by Tim Penhey. (bzr r1982)
| -rw-r--r-- | plugins/unityshell/src/PanelStyle.cpp | 16 | ||||
| -rw-r--r-- | plugins/unityshell/src/PanelStyle.h | 7 | ||||
| -rw-r--r-- | plugins/unityshell/src/WindowButtons.cpp | 54 |
3 files changed, 36 insertions, 41 deletions
diff --git a/plugins/unityshell/src/PanelStyle.cpp b/plugins/unityshell/src/PanelStyle.cpp index affa79f65..472ead613 100644 --- a/plugins/unityshell/src/PanelStyle.cpp +++ b/plugins/unityshell/src/PanelStyle.cpp @@ -207,12 +207,12 @@ nux::BaseTexture* Style::GetWindowButton(WindowButtonType type, WindowState stat } if (!texture) - texture = GetWindowButtonForTheme(type, state); + texture = GetFallbackWindowButton(type, state); return texture; } -nux::BaseTexture* Style::GetWindowButtonForTheme(WindowButtonType type, +nux::BaseTexture* Style::GetFallbackWindowButton(WindowButtonType type, WindowState state) { int width = 18, height = 18; @@ -231,6 +231,8 @@ nux::BaseTexture* Style::GetWindowButtonForTheme(WindowButtonType type, main = main * 1.2f; else if (state == WindowState::PRESSED) main = main * 0.8f; + else if (state == WindowState::DISABLED) + main = main * 0.5f; cr = cairo_graphics.GetContext(); cairo_translate(cr, 0.5, 0.5); @@ -258,7 +260,15 @@ nux::BaseTexture* Style::GetWindowButtonForTheme(WindowButtonType type, cairo_move_to(cr, w, height / 2.0f); cairo_line_to(cr, width - w, height / 2.0f); } - else + else if (type == WindowButtonType::UNMAXIMIZE) + { + cairo_move_to(cr, w, h + h/5.0f); + cairo_line_to(cr, width - w, h + h/5.0f); + cairo_line_to(cr, width - w, height - h - h/5.0f); + cairo_line_to(cr, w, height - h - h/5.0f); + cairo_close_path(cr); + } + else // if (type == WindowButtonType::MAXIMIZE) { cairo_move_to(cr, w, h); cairo_line_to(cr, width - w, h); diff --git a/plugins/unityshell/src/PanelStyle.h b/plugins/unityshell/src/PanelStyle.h index 524caaccf..4a44e4ef4 100644 --- a/plugins/unityshell/src/PanelStyle.h +++ b/plugins/unityshell/src/PanelStyle.h @@ -35,7 +35,8 @@ enum class WindowButtonType { CLOSE, MINIMIZE, - UNMAXIMIZE + UNMAXIMIZE, + MAXIMIZE }; enum class WindowState @@ -59,6 +60,7 @@ public: nux::NBitmapData* GetBackground(int width, int height, float opacity); nux::BaseTexture* GetWindowButton(WindowButtonType type, WindowState state); + nux::BaseTexture* GetFallbackWindowButton(WindowButtonType type, WindowState state); GdkPixbuf* GetHomeButton(); @@ -74,9 +76,6 @@ private: static void OnGtkThemeChanged(GObject* gobject, GParamSpec* pspec, gpointer data); - - nux::BaseTexture* GetWindowButtonForTheme(WindowButtonType type, - WindowState state); private: GtkStyleContext* _style_context; char* _theme_name; 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; } }; |
