1 /*****************************************************************************
2  *   Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
3  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
4  *                                                                           *
5  *   This program is free software; you can redistribute it and/or modify    *
6  *   it under the terms of the GNU Lesser General Public License as          *
7  *   published by the Free Software Foundation; either version 2.1 of the    *
8  *   License, or (at your option) version 3, or any later version accepted   *
9  *   by the membership of KDE e.V. (or its successor approved by the         *
10  *   membership of KDE e.V.), which shall act as a proxy defined in          *
11  *   Section 6 of version 3 of the license.                                  *
12  *                                                                           *
13  *   This program is distributed in the hope that it will be useful,         *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
16  *   Lesser General Public License for more details.                         *
17  *                                                                           *
18  *   You should have received a copy of the GNU Lesser General Public        *
19  *   License along with this library. If not,                                *
20  *   see <http://www.gnu.org/licenses/>.                                     *
21  *****************************************************************************/
22 /*
23   based on the window decoration "Plastik":
24   Copyright (C) 2003-2005 Sandro Giessl <sandro@giessl.com>
25 
26   based on the window decoration "Web":
27   Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
28  */
29 
30 #ifndef KWIN_QTCURVE_H
31 #define KWIN_QTCURVE_H
32 
33 #include <QFont>
34 #include <QApplication>
35 #include <QBitmap>
36 #include <kdeversion.h>
37 #include <kdecoration.h>
38 #include <kdecorationfactory.h>
39 #include "config.h"
40 #include "qtcurveconfig.h"
41 #include "qtcurveshadowcache.h"
42 
43 class QStyle;
44 
45 namespace QtCurve {
46 namespace KWin {
47 
48 enum ButtonIcon {
49     CloseIcon = 0,
50     CloseTabIcon,
51     MaxIcon,
52     MaxRestoreIcon,
53     MinIcon,
54     HelpIcon,
55     OnAllDesktopsIcon,
56     NotOnAllDesktopsIcon,
57     KeepAboveIcon,
58     NoKeepAboveIcon,
59     KeepBelowIcon,
60     NoKeepBelowIcon,
61     ShadeIcon,
62     UnShadeIcon,
63     MenuIcon,
64     NumButtonIcons
65 };
66 
67 class QtCurveClient;
68 class QtCurveDBus;
69 
70 #if !KDE_IS_VERSION(4, 11, 0)
71 // KDecorationFactoryUnstable already does nothing before 4.11 and
72 // is removed in kde5.
73 #define _KDecorationFactoryBase KDecorationFactoryUnstable
74 #else
75 #define _KDecorationFactoryBase KDecorationFactory
76 #endif
77 
78 class QtCurveHandler: public QObject, public _KDecorationFactoryBase {
79     Q_OBJECT
80 public:
81     QtCurveHandler();
82     ~QtCurveHandler();
83     void setStyle();
84     bool reset(unsigned long changed) override;
85     void setBorderSize();
86 
87     KDecoration *createDecoration(KDecorationBridge*) override;
88     bool supports(Ability ability) const override;
89 
90     const QBitmap &buttonBitmap(ButtonIcon type, const QSize &size,
91                                 bool toolWindow);
92     int
titleHeight()93     titleHeight() const
94     {
95         return m_titleHeight;
96     }
97     int
titleHeightTool()98     titleHeightTool() const
99     {
100         return m_titleHeightTool;
101     }
102     const QFont&
titleFont()103     titleFont()
104     {
105         return m_titleFont;
106     }
107     const QFont&
titleFontTool()108     titleFontTool()
109     {
110         return m_titleFontTool;
111     }
112     int borderSize(bool bot=false) const;
113     bool
showResizeGrip()114     showResizeGrip() const
115     {
116         return QtCurveConfig::BORDER_NONE == m_config.borderSize();
117     }
118     bool
haveBottomBorder()119     haveBottomBorder() const
120     {
121         return QtCurveConfig::BORDER_NONE!=m_config.borderSize();
122     }
123     bool
roundBottom()124     roundBottom() const
125     {
126         return (m_config.roundBottom() &&
127                 m_config.borderSize() > QtCurveConfig::BORDER_NONE);
128     }
129     QtCurveConfig::Shade
outerBorder()130     outerBorder() const
131     {
132         return m_config.outerBorder();
133     }
134     QtCurveConfig::Shade
innerBorder()135     innerBorder() const
136     {
137         return m_config.innerBorder();
138     }
139     QStyle*
wStyle()140     wStyle() const
141     {
142         return m_style ? m_style : QApplication::style();
143     }
144     int borderEdgeSize() const;
145     int
titleBarPad()146     titleBarPad() const
147     {
148         return m_config.titleBarPad();
149     }
150     int
edgePad()151     edgePad() const
152     {
153         return m_config.edgePad();
154     }
155     bool
borderlessMax()156     borderlessMax() const
157     {
158         return m_config.borderlessMax();
159     }
160     int
opacity(bool active)161     opacity(bool active) const
162     {
163         return m_config.opacity(active);
164     }
165     bool
opaqueBorder()166     opaqueBorder() const
167     {
168         return m_config.opaqueBorder();
169     }
170     bool
customShadows()171     customShadows() const
172     {
173         return m_config.customShadows();
174     }
175     QtCurveShadowCache&
shadowCache()176     shadowCache()
177     {
178         return m_shadowCache;
179     }
180     bool
grouping()181     grouping() const
182     {
183         return m_config.grouping();
184     }
185     void menuBarSize(unsigned int xid, int size);
186     void statusBarState(unsigned int xid, bool state);
187     void emitToggleMenuBar(int xid);
188     void emitToggleStatusBar(int xid);
189     void borderSizeChanged();
190     void
addClient(QtCurveClient * c)191     addClient(QtCurveClient *c)
192     {
193         m_clients.append(c);
194     }
195     void removeClient(QtCurveClient *c);
wasLastMenu(unsigned int id)196     bool wasLastMenu(unsigned int id)
197     {
198         return id == m_lastMenuXid;
199     }
200     bool
wasLastStatus(unsigned int id)201     wasLastStatus(unsigned int id)
202     {
203         return id == m_lastStatusXid;
204     }
205     const QColor&
hoverCol(bool active)206     hoverCol(bool active)
207     {
208         return m_hoverCols[active ? 1 : 0];
209     }
210 private:
211     bool readConfig(bool compositingToggled=false);
212 
213     int m_borderSize;
214     int m_titleHeight;
215     int m_titleHeightTool;
216     int m_timeStamp;
217     unsigned int m_lastMenuXid;
218     unsigned int m_lastStatusXid;
219     QFont m_titleFont;
220     QFont m_titleFontTool;
221     QStyle *m_style;
222     QBitmap m_bitmaps[2][NumButtonIcons];
223     QtCurveConfig m_config;
224     QList<QtCurveClient*> m_clients;
225     QtCurveDBus *m_dBus;
226     QColor m_hoverCols[2];
227     QtCurveShadowCache m_shadowCache;
228 };
229 QtCurveHandler *Handler();
230 }
231 }
232 
233 #endif
234