File indexing completed on 2024-04-14 15:36:04

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
0006     SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #pragma once
0012 
0013 // cmake stuff
0014 #include <config-kwin.h>
0015 #include <kwinconfig.h>
0016 // kwin
0017 #include <kwinglobals.h>
0018 // Qt
0019 #include <QList>
0020 #include <QLoggingCategory>
0021 #include <QMatrix4x4>
0022 #include <QPoint>
0023 #include <QRect>
0024 // system
0025 #include <climits>
0026 Q_DECLARE_LOGGING_CATEGORY(KWIN_CORE)
0027 Q_DECLARE_LOGGING_CATEGORY(KWIN_OPENGL)
0028 Q_DECLARE_LOGGING_CATEGORY(KWIN_QPAINTER)
0029 Q_DECLARE_LOGGING_CATEGORY(KWIN_VIRTUALKEYBOARD)
0030 namespace KWin
0031 {
0032 Q_NAMESPACE
0033 
0034 const QPoint invalidPoint(INT_MIN, INT_MIN);
0035 
0036 enum Layer {
0037     UnknownLayer = -1,
0038     FirstLayer = 0,
0039     DesktopLayer = FirstLayer,
0040     BelowLayer,
0041     NormalLayer,
0042     DockLayer,
0043     AboveLayer,
0044     NotificationLayer, // layer for windows of type notification
0045     ActiveLayer, // active fullscreen, or active dialog
0046     PopupLayer, // tooltips, sub- and context menus
0047     CriticalNotificationLayer, // layer for notifications that should be shown even on top of fullscreen
0048     OnScreenDisplayLayer, // layer for On Screen Display windows such as volume feedback
0049     UnmanagedLayer, // layer for override redirect windows.
0050     NumLayers, // number of layers, must be last
0051 };
0052 Q_ENUM_NS(Layer)
0053 
0054 enum StrutArea {
0055     StrutAreaInvalid = 0, // Null
0056     StrutAreaTop = 1 << 0,
0057     StrutAreaRight = 1 << 1,
0058     StrutAreaBottom = 1 << 2,
0059     StrutAreaLeft = 1 << 3,
0060     StrutAreaAll = StrutAreaTop | StrutAreaRight | StrutAreaBottom | StrutAreaLeft,
0061 };
0062 Q_DECLARE_FLAGS(StrutAreas, StrutArea)
0063 
0064 class KWIN_EXPORT StrutRect : public QRect
0065 {
0066 public:
0067     explicit StrutRect(QRect rect = QRect(), StrutArea area = StrutAreaInvalid);
0068     StrutRect(int x, int y, int width, int height, StrutArea area = StrutAreaInvalid);
0069     StrutRect(const StrutRect &other);
0070     StrutRect &operator=(const StrutRect &other);
0071     inline StrutArea area() const
0072     {
0073         return m_area;
0074     }
0075 
0076 private:
0077     StrutArea m_area;
0078 };
0079 typedef QVector<StrutRect> StrutRects;
0080 
0081 enum ShadeMode {
0082     ShadeNone, // not shaded
0083     ShadeNormal, // normally shaded - isShade() is true only here
0084     ShadeHover, // "shaded", but visible due to hover unshade
0085     ShadeActivated // "shaded", but visible due to alt+tab to the window
0086 };
0087 
0088 /**
0089  * Maximize mode. These values specify how a window is maximized.
0090  *
0091  * @note these values are written to session files, don't change the order
0092  */
0093 enum MaximizeMode {
0094     MaximizeRestore = 0, ///< The window is not maximized in any direction.
0095     MaximizeVertical = 1, ///< The window is maximized vertically.
0096     MaximizeHorizontal = 2, ///< The window is maximized horizontally.
0097     /// Equal to @p MaximizeVertical | @p MaximizeHorizontal
0098     MaximizeFull = MaximizeVertical | MaximizeHorizontal,
0099 };
0100 
0101 inline MaximizeMode operator^(MaximizeMode m1, MaximizeMode m2)
0102 {
0103     return MaximizeMode(int(m1) ^ int(m2));
0104 }
0105 
0106 // TODO: could this be in Tile itself?
0107 enum class QuickTileFlag {
0108     None = 0,
0109     Left = 1 << 0,
0110     Right = 1 << 1,
0111     Top = 1 << 2,
0112     Bottom = 1 << 3,
0113     Custom = 1 << 4,
0114     Horizontal = Left | Right,
0115     Vertical = Top | Bottom,
0116     Maximize = Left | Right | Top | Bottom,
0117 };
0118 Q_ENUM_NS(QuickTileFlag);
0119 Q_DECLARE_FLAGS(QuickTileMode, QuickTileFlag)
0120 
0121 void KWIN_EXPORT grabXServer();
0122 void KWIN_EXPORT ungrabXServer();
0123 bool KWIN_EXPORT grabXKeyboard(xcb_window_t w = XCB_WINDOW_NONE);
0124 void KWIN_EXPORT ungrabXKeyboard();
0125 
0126 static inline QRegion mapRegion(const QMatrix4x4 &matrix, const QRegion &region)
0127 {
0128     QRegion result;
0129     for (const QRect &rect : region) {
0130         result += matrix.mapRect(rect);
0131     }
0132     return result;
0133 }
0134 
0135 /**
0136  * Small helper class which performs grabXServer in the ctor and
0137  * ungrabXServer in the dtor. Use this class to ensure that grab and
0138  * ungrab are matched.
0139  */
0140 class XServerGrabber
0141 {
0142 public:
0143     XServerGrabber()
0144     {
0145         grabXServer();
0146     }
0147     ~XServerGrabber()
0148     {
0149         ungrabXServer();
0150     }
0151 };
0152 
0153 // converting between X11 mouse/keyboard state mask and Qt button/keyboard states
0154 Qt::MouseButton x11ToQtMouseButton(int button);
0155 Qt::MouseButton KWIN_EXPORT x11ToQtMouseButton(int button);
0156 Qt::MouseButtons KWIN_EXPORT x11ToQtMouseButtons(int state);
0157 Qt::KeyboardModifiers KWIN_EXPORT x11ToQtKeyboardModifiers(int state);
0158 
0159 KWIN_EXPORT QPointF popupOffset(const QRectF &anchorRect, const Qt::Edges anchorEdge, const Qt::Edges gravity, const QSizeF popupSize);
0160 KWIN_EXPORT QRectF gravitateGeometry(const QRectF &rect, const QRectF &bounds, Gravity gravity);
0161 
0162 } // namespace
0163 
0164 // Must be outside namespace
0165 Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::StrutAreas)
0166 Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::QuickTileMode)