Merge lp:~agateau/unity-2d/themed-window-buttons into lp:unity-2d

Proposed by Aurélien Gâteau
Status: Superseded
Proposed branch: lp:~agateau/unity-2d/themed-window-buttons
Merge into: lp:unity-2d
Prerequisite: lp:~agateau/unity-2d/use-gtk-rendering
Diff against target: 256 lines (+124/-17)
3 files modified
panel/applets/appname/appnameapplet.cpp (+21/-17)
panel/applets/common/panelstyle.cpp (+87/-0)
panel/applets/common/panelstyle.h (+16/-0)
To merge this branch: bzr merge lp:~agateau/unity-2d/themed-window-buttons
Reviewer Review Type Date Requested Status
Florian Boucault Pending
Review via email: mp+69490@code.launchpad.net

This proposal supersedes a proposal from 2011-07-25.

This proposal has been superseded by a proposal from 2011-07-27.

Description of the change

This branch gets the window button pixmaps from the active window manager theme instead of using the hardcoded Ambiance theme. It also provides a fallback in case the theme is not Ambiance or Radiance.

To post a comment you must log in.
700. By Aurélien Gâteau

Sync with unity-2d/4.0

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'panel/applets/appname/appnameapplet.cpp'
--- panel/applets/appname/appnameapplet.cpp 2011-07-27 15:51:45 +0000
+++ panel/applets/appname/appnameapplet.cpp 2011-07-27 15:51:45 +0000
@@ -25,6 +25,7 @@
25// Local25// Local
26#include "croppedlabel.h"26#include "croppedlabel.h"
27#include "menubarwidget.h"27#include "menubarwidget.h"
28#include "panelstyle.h"
28#include "windowhelper.h"29#include "windowhelper.h"
2930
30// Unity-2d31// Unity-2d
@@ -46,8 +47,6 @@
46#include <QApplication>47#include <QApplication>
47#include <QDesktopWidget>48#include <QDesktopWidget>
4849
49static const char* METACITY_DIR = "/usr/share/themes/Ambiance/metacity-1";
50
51static const int WINDOW_BUTTONS_RIGHT_MARGIN = 4;50static const int WINDOW_BUTTONS_RIGHT_MARGIN = 4;
5251
53static const int APPNAME_LABEL_LEFT_MARGIN = 6;52static const int APPNAME_LABEL_LEFT_MARGIN = 6;
@@ -58,13 +57,11 @@
58class WindowButton : public QAbstractButton57class WindowButton : public QAbstractButton
59{58{
60public:59public:
61 WindowButton(const QString& prefix, QWidget* parent = 0)60 WindowButton(const PanelStyle::WindowButtonType& buttonType, QWidget* parent = 0)
62 : QAbstractButton(parent)61 : QAbstractButton(parent)
63 , m_prefix(prefix)62 , m_buttonType(buttonType)
64 , m_normalPix(loadPix("normal"))
65 , m_hoverPix(loadPix("prelight"))
66 , m_downPix(loadPix("pressed"))
67 {63 {
64 loadPixmaps();
68 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);65 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
69 setAttribute(Qt::WA_Hover);66 setAttribute(Qt::WA_Hover);
70 }67 }
@@ -75,6 +72,14 @@
75 }72 }
7673
77protected:74protected:
75 bool event(QEvent* ev)
76 {
77 if (ev->type() == QEvent::PaletteChange) {
78 loadPixmaps();
79 }
80 return QAbstractButton::event(ev);
81 }
82
78 void paintEvent(QPaintEvent*)83 void paintEvent(QPaintEvent*)
79 {84 {
80 QPainter painter(this);85 QPainter painter(this);
@@ -90,18 +95,17 @@
90 }95 }
9196
92private:97private:
93 QString m_prefix;98 PanelStyle::WindowButtonType m_buttonType;
94 QPixmap m_normalPix;99 QPixmap m_normalPix;
95 QPixmap m_hoverPix;100 QPixmap m_hoverPix;
96 QPixmap m_downPix;101 QPixmap m_downPix;
97102
98 QPixmap loadPix(const QString& name)103 void loadPixmaps()
99 {104 {
100 QString path = QString("%1/%2_focused_%3.png")105 PanelStyle* style = PanelStyle::instance();
101 .arg(METACITY_DIR)106 m_normalPix = style->windowButtonPixmap(m_buttonType, PanelStyle::NormalState);
102 .arg(m_prefix)107 m_hoverPix = style->windowButtonPixmap(m_buttonType, PanelStyle::PrelightState);
103 .arg(name);108 m_downPix = style->windowButtonPixmap(m_buttonType, PanelStyle::PressedState);
104 return QPixmap(path);
105 }109 }
106};110};
107111
@@ -135,9 +139,9 @@
135 QHBoxLayout* layout = new QHBoxLayout(m_windowButtonWidget);139 QHBoxLayout* layout = new QHBoxLayout(m_windowButtonWidget);
136 layout->setContentsMargins(0, 0, WINDOW_BUTTONS_RIGHT_MARGIN, 0);140 layout->setContentsMargins(0, 0, WINDOW_BUTTONS_RIGHT_MARGIN, 0);
137 layout->setSpacing(0);141 layout->setSpacing(0);
138 m_closeButton = new WindowButton("close");142 m_closeButton = new WindowButton(PanelStyle::CloseWindowButton);
139 m_minimizeButton = new WindowButton("minimize");143 m_minimizeButton = new WindowButton(PanelStyle::MinimizeWindowButton);
140 m_maximizeButton = new WindowButton("unmaximize");144 m_maximizeButton = new WindowButton(PanelStyle::UnmaximizeWindowButton);
141 layout->addWidget(m_closeButton);145 layout->addWidget(m_closeButton);
142 layout->addWidget(m_minimizeButton);146 layout->addWidget(m_minimizeButton);
143 layout->addWidget(m_maximizeButton);147 layout->addWidget(m_maximizeButton);
144148
=== modified file 'panel/applets/common/panelstyle.cpp'
--- panel/applets/common/panelstyle.cpp 2011-07-27 15:51:45 +0000
+++ panel/applets/common/panelstyle.cpp 2011-07-27 15:51:45 +0000
@@ -30,10 +30,13 @@
30// Qt30// Qt
31#include <QApplication>31#include <QApplication>
32#include <QPalette>32#include <QPalette>
33#include <QStyle>
3334
34// GTK35// GTK
35#include <gtk/gtk.h>36#include <gtk/gtk.h>
3637
38static const char* METACITY_THEME_DIR = "/usr/share/themes/%1/metacity-1";
39
37class PanelStylePrivate40class PanelStylePrivate
38{41{
39public:42public:
@@ -41,6 +44,8 @@
41 GObjectScopedPointer<GtkStyleContext> m_styleContext;44 GObjectScopedPointer<GtkStyleContext> m_styleContext;
42 GConnector m_gConnector;45 GConnector m_gConnector;
4346
47 QString m_themeName;
48
44 static void onThemeChanged(GObject*, GParamSpec*, gpointer data)49 static void onThemeChanged(GObject*, GParamSpec*, gpointer data)
45 {50 {
46 PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);51 PanelStylePrivate* priv = reinterpret_cast<PanelStylePrivate*>(data);
@@ -49,6 +54,11 @@
4954
50 void updatePalette()55 void updatePalette()
51 {56 {
57 gchar* themeName = 0;
58 g_object_get(gtk_settings_get_default(), "gtk-theme-name", &themeName, NULL);
59 m_themeName = QString::fromUtf8(themeName);
60 g_free(themeName);
61
52 GtkStyleContext* context = m_styleContext.data();62 GtkStyleContext* context = m_styleContext.data();
53 gtk_style_context_invalidate(context);63 gtk_style_context_invalidate(context);
5464
@@ -71,6 +81,71 @@
71 gtk_render_background(m_styleContext.data(), cr.data(), 0, 0, image.width(), image.height());81 gtk_render_background(m_styleContext.data(), cr.data(), 0, 0, image.width(), image.height());
72 return QBrush(image);82 return QBrush(image);
73 }83 }
84
85 QPixmap windowButtonPixmapFromWMTheme(PanelStyle::WindowButtonType type, PanelStyle::WindowButtonState state)
86 {
87 QString dir = QString(METACITY_THEME_DIR).arg(m_themeName);
88
89 QString typeString, stateString;
90 switch (type) {
91 case PanelStyle::CloseWindowButton:
92 typeString = "close";
93 break;
94 case PanelStyle::MinimizeWindowButton:
95 typeString = "minimize";
96 break;
97 case PanelStyle::UnmaximizeWindowButton:
98 typeString = "unmaximize";
99 break;
100 }
101
102 switch (state) {
103 case PanelStyle::NormalState:
104 stateString = "";
105 break;
106 case PanelStyle::PrelightState:
107 stateString = "_focused_prelight";
108 break;
109 case PanelStyle::PressedState:
110 stateString = "_focused_pressed";
111 break;
112 }
113
114 QString path = QString("%1/%2%3.png")
115 .arg(dir)
116 .arg(typeString)
117 .arg(stateString);
118 return QPixmap(path);
119 }
120
121 QPixmap genericWindowButtonPixmap(PanelStyle::WindowButtonType type, PanelStyle::WindowButtonState state)
122 {
123 QStyle::StandardPixmap standardIcon;
124 switch (type) {
125 case PanelStyle::CloseWindowButton:
126 standardIcon = QStyle::SP_TitleBarCloseButton;
127 break;
128 case PanelStyle::MinimizeWindowButton:
129 standardIcon = QStyle::SP_TitleBarMinButton;
130 break;
131 case PanelStyle::UnmaximizeWindowButton:
132 standardIcon = QStyle::SP_TitleBarNormalButton;
133 break;
134 }
135
136 QIcon icon = QApplication::style()->standardIcon(standardIcon);
137 const int extent = 22;
138 switch (state) {
139 case PanelStyle::NormalState:
140 return icon.pixmap(extent);
141 case PanelStyle::PrelightState:
142 return icon.pixmap(extent, QIcon::Active);
143 case PanelStyle::PressedState:
144 return icon.pixmap(extent, QIcon::Active, QIcon::On);
145 }
146 // Silence compiler
147 return QPixmap();
148 }
74};149};
75150
76PanelStyle::PanelStyle(QObject* parent)151PanelStyle::PanelStyle(QObject* parent)
@@ -111,4 +186,16 @@
111 return d->m_styleContext.data();186 return d->m_styleContext.data();
112}187}
113188
189QPixmap PanelStyle::windowButtonPixmap(PanelStyle::WindowButtonType type, PanelStyle::WindowButtonState state)
190{
191 // According to Unity PanelStyle code, the buttons of some WM themes do not
192 // match well with the panel background. So except for themes we provide,
193 // fallback to generic button pixmaps.
194 if (d->m_themeName == "Ambiance" || d->m_themeName == "Radiance") {
195 return d->windowButtonPixmapFromWMTheme(type, state);
196 } else {
197 return d->genericWindowButtonPixmap(type, state);
198 }
199}
200
114#include "panelstyle.moc"201#include "panelstyle.moc"
115202
=== modified file 'panel/applets/common/panelstyle.h'
--- panel/applets/common/panelstyle.h 2011-07-27 15:51:45 +0000
+++ panel/applets/common/panelstyle.h 2011-07-27 15:51:45 +0000
@@ -26,6 +26,8 @@
26// Qt26// Qt
27#include <QObject>27#include <QObject>
2828
29class QPixmap;
30
29struct _GtkStyleContext;31struct _GtkStyleContext;
3032
31class PanelStylePrivate;33class PanelStylePrivate;
@@ -43,10 +45,24 @@
43 PanelStyle(QObject* parent = 0);45 PanelStyle(QObject* parent = 0);
44 ~PanelStyle();46 ~PanelStyle();
4547
48 enum WindowButtonType {
49 CloseWindowButton,
50 MinimizeWindowButton,
51 UnmaximizeWindowButton
52 };
53
54 enum WindowButtonState {
55 NormalState,
56 PrelightState,
57 PressedState
58 };
59
46 static PanelStyle* instance();60 static PanelStyle* instance();
4761
48 struct _GtkStyleContext* styleContext() const;62 struct _GtkStyleContext* styleContext() const;
4963
64 QPixmap windowButtonPixmap(WindowButtonType, WindowButtonState);
65
50private:66private:
51 friend class PanelStylePrivate;67 friend class PanelStylePrivate;
52 // Use a pimpl to avoid the need for gtk includes here68 // Use a pimpl to avoid the need for gtk includes here

Subscribers

People subscribed via source and target branches