File indexing completed on 2024-04-28 17:04:38

0001 /*****************************************************************************
0002  *   Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 /*
0023   based on the window decoration "Plastik":
0024   Copyright (C) 2003-2005 Sandro Giessl <sandro@giessl.com>
0025 
0026   based on the window decoration "Web":
0027   Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
0028  */
0029 
0030 #ifndef KWIN_QTCURVE_H
0031 #define KWIN_QTCURVE_H
0032 
0033 #include <QFont>
0034 #include <QApplication>
0035 #include <QBitmap>
0036 #include <kdeversion.h>
0037 #include <kdecoration.h>
0038 #include <kdecorationfactory.h>
0039 #include "config.h"
0040 #include "qtcurveconfig.h"
0041 #include "qtcurveshadowcache.h"
0042 
0043 class QStyle;
0044 
0045 namespace QtCurve {
0046 namespace KWin {
0047 
0048 enum ButtonIcon {
0049     CloseIcon = 0,
0050     CloseTabIcon,
0051     MaxIcon,
0052     MaxRestoreIcon,
0053     MinIcon,
0054     HelpIcon,
0055     OnAllDesktopsIcon,
0056     NotOnAllDesktopsIcon,
0057     KeepAboveIcon,
0058     NoKeepAboveIcon,
0059     KeepBelowIcon,
0060     NoKeepBelowIcon,
0061     ShadeIcon,
0062     UnShadeIcon,
0063     MenuIcon,
0064     NumButtonIcons
0065 };
0066 
0067 class QtCurveClient;
0068 class QtCurveDBus;
0069 
0070 #if !KDE_IS_VERSION(4, 11, 0)
0071 // KDecorationFactoryUnstable already does nothing before 4.11 and
0072 // is removed in kde5.
0073 #define _KDecorationFactoryBase KDecorationFactoryUnstable
0074 #else
0075 #define _KDecorationFactoryBase KDecorationFactory
0076 #endif
0077 
0078 class QtCurveHandler : public QObject, public _KDecorationFactoryBase {
0079     Q_OBJECT
0080 public:
0081     QtCurveHandler();
0082     ~QtCurveHandler();
0083     void setStyle();
0084     bool reset(unsigned long changed) override;
0085     void setBorderSize();
0086 
0087     KDecoration *createDecoration(KDecorationBridge*) override;
0088     bool supports(Ability ability) const override;
0089 
0090     const QBitmap &buttonBitmap(ButtonIcon type, const QSize &size,
0091                                 bool toolWindow);
0092     int
0093     titleHeight() const
0094     {
0095         return m_titleHeight;
0096     }
0097     int
0098     titleHeightTool() const
0099     {
0100         return m_titleHeightTool;
0101     }
0102     const QFont&
0103     titleFont()
0104     {
0105         return m_titleFont;
0106     }
0107     const QFont&
0108     titleFontTool()
0109     {
0110         return m_titleFontTool;
0111     }
0112     int borderSize(bool bot=false) const;
0113     bool
0114     showResizeGrip() const
0115     {
0116         return QtCurveConfig::BORDER_NONE == m_config.borderSize();
0117     }
0118     bool
0119     haveBottomBorder() const
0120     {
0121         return QtCurveConfig::BORDER_NONE!=m_config.borderSize();
0122     }
0123     bool
0124     roundBottom() const
0125     {
0126         return (m_config.roundBottom() &&
0127                 m_config.borderSize() > QtCurveConfig::BORDER_NONE);
0128     }
0129     QtCurveConfig::Shade
0130     outerBorder() const
0131     {
0132         return m_config.outerBorder();
0133     }
0134     QtCurveConfig::Shade
0135     innerBorder() const
0136     {
0137         return m_config.innerBorder();
0138     }
0139     QStyle*
0140     wStyle() const
0141     {
0142         return m_style ? m_style : QApplication::style();
0143     }
0144     int borderEdgeSize() const;
0145     int
0146     titleBarPad() const
0147     {
0148         return m_config.titleBarPad();
0149     }
0150     int
0151     edgePad() const
0152     {
0153         return m_config.edgePad();
0154     }
0155     bool
0156     borderlessMax() const
0157     {
0158         return m_config.borderlessMax();
0159     }
0160     int
0161     opacity(bool active) const
0162     {
0163         return m_config.opacity(active);
0164     }
0165     bool
0166     opaqueBorder() const
0167     {
0168         return m_config.opaqueBorder();
0169     }
0170     bool
0171     customShadows() const
0172     {
0173         return m_config.customShadows();
0174     }
0175     QtCurveShadowCache&
0176     shadowCache()
0177     {
0178         return m_shadowCache;
0179     }
0180     bool
0181     grouping() const
0182     {
0183         return m_config.grouping();
0184     }
0185     void menuBarSize(unsigned int xid, int size);
0186     void statusBarState(unsigned int xid, bool state);
0187     void emitToggleMenuBar(int xid);
0188     void emitToggleStatusBar(int xid);
0189     void borderSizeChanged();
0190     void
0191     addClient(QtCurveClient *c)
0192     {
0193         m_clients.append(c);
0194     }
0195     void removeClient(QtCurveClient *c);
0196     bool wasLastMenu(unsigned int id)
0197     {
0198         return id == m_lastMenuXid;
0199     }
0200     bool
0201     wasLastStatus(unsigned int id)
0202     {
0203         return id == m_lastStatusXid;
0204     }
0205     const QColor&
0206     hoverCol(bool active)
0207     {
0208         return m_hoverCols[active ? 1 : 0];
0209     }
0210 private:
0211     bool readConfig(bool compositingToggled=false);
0212 
0213     int m_borderSize;
0214     int m_titleHeight;
0215     int m_titleHeightTool;
0216     int m_timeStamp;
0217     unsigned int m_lastMenuXid;
0218     unsigned int m_lastStatusXid;
0219     QFont m_titleFont;
0220     QFont m_titleFontTool;
0221     QStyle *m_style;
0222     QBitmap m_bitmaps[2][NumButtonIcons];
0223     QtCurveConfig m_config;
0224     QList<QtCurveClient*> m_clients;
0225     QtCurveDBus *m_dBus;
0226     QColor m_hoverCols[2];
0227     QtCurveShadowCache m_shadowCache;
0228 };
0229 QtCurveHandler *Handler();
0230 }
0231 }
0232 
0233 #endif