File indexing completed on 2024-04-28 05:47:26
0001 /***************************************************************************** 0002 * Copyright 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 #ifndef __WINDOW_MANAGER_H__ 0024 #define __WINDOW_MANAGER_H__ 0025 0026 // Copied from oxygenwindowmanager.h svnversion: 1137195 0027 0028 ////////////////////////////////////////////////////////////////////////////// 0029 // windowmanager.h 0030 // pass some window mouse press/release/move event actions to window manager 0031 // ------------------- 0032 // 0033 // Copyright (c) 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org> 0034 // 0035 // Largely inspired from BeSpin style 0036 // Copyright (C) 2007 Thomas Luebking <thomas.luebking@web.de> 0037 // 0038 // Permission is hereby granted, free of charge, to any person obtaining a copy 0039 // of this software and associated documentation files (the "Software"), to 0040 // deal in the Software without restriction, including without limitation the 0041 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 0042 // sell copies of the Software, and to permit persons to whom the Software is 0043 // furnished to do so, subject to the following conditions: 0044 // 0045 // The above copyright notice and this permission notice shall be included in 0046 // all copies or substantial portions of the Software. 0047 // 0048 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0049 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0050 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0051 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0052 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 0053 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 0054 // IN THE SOFTWARE. 0055 ////////////////////////////////////////////////////////////////////////////// 0056 0057 #include <QEvent> 0058 #include <QBasicTimer> 0059 #include <QSet> 0060 #include <QString> 0061 #include <QPointer> 0062 #include <QWidget> 0063 0064 namespace QtCurve { 0065 class WindowManager: public QObject { 0066 Q_OBJECT 0067 public: 0068 explicit WindowManager(QObject*); 0069 0070 //! initialize 0071 /*! read relevant options from OxygenStyleConfigData */ 0072 void initialize( int windowDrag, const QStringList &whiteList=QStringList(), 0073 const QStringList &blackList=QStringList()); 0074 0075 //! register widget 0076 void registerWidget(QWidget*); 0077 0078 //! unregister widget 0079 void unregisterWidget(QWidget*); 0080 0081 //! event filter [reimplemented] 0082 bool eventFilter(QObject*, QEvent*) override; 0083 0084 protected: 0085 //! timer event, 0086 /*! used to start drag if button is pressed for a long enough time */ 0087 void timerEvent(QTimerEvent*) override; 0088 //! mouse press event 0089 bool mousePressEvent( QObject*, QEvent* ); 0090 //! mouse move event 0091 bool mouseMoveEvent( QObject*, QEvent* ); 0092 //! mouse release event 0093 bool mouseReleaseEvent( QObject*, QEvent* ); 0094 //!@name configuration 0095 //@{ 0096 //! enable state 0097 bool 0098 enabled() const 0099 { 0100 return _enabled; 0101 } 0102 0103 //! enable state 0104 void 0105 setEnabled(bool value) 0106 { 0107 _enabled = value; 0108 } 0109 0110 //! returns true if window manager is used for moving 0111 bool 0112 useWMMoveResize() const 0113 { 0114 return _useWMMoveResize; 0115 } 0116 0117 //! drag mode 0118 int dragMode() const 0119 { 0120 return _dragMode; 0121 } 0122 0123 //! drag mode 0124 void setDragMode(int value) 0125 { 0126 _dragMode = value; 0127 } 0128 0129 //! drag distance (pixels) 0130 void setDragDistance(int value) 0131 { 0132 _dragDistance = value; 0133 } 0134 0135 //! drag delay (msec) 0136 void setDragDelay(int value) 0137 { 0138 _dragDelay = value; 0139 } 0140 0141 //! set list of whiteListed widgets 0142 /*! 0143 white list is read from options and is used to adjust 0144 per-app window dragging issues 0145 */ 0146 void initializeWhiteList(const QStringList &list); 0147 0148 //! set list of blackListed widgets 0149 /*! 0150 black list is read from options and is used to adjust 0151 per-app window dragging issues 0152 */ 0153 void initializeBlackList(const QStringList &list); 0154 0155 //@} 0156 0157 //! returns true if widget is dragable 0158 bool isDragable(QWidget*); 0159 0160 //! returns true if widget is dragable 0161 bool isBlackListed(QWidget*); 0162 0163 //! returns true if widget is dragable 0164 bool isWhiteListed(QWidget*) const; 0165 0166 //! returns true if drag can be started from current widget 0167 bool canDrag(QWidget*); 0168 0169 //! returns true if drag can be started from current widget and position 0170 /*! child at given position is passed as second argument */ 0171 bool canDrag(QWidget*, QWidget*, const QPoint&); 0172 0173 //! reset drag 0174 void resetDrag(); 0175 0176 //! start drag 0177 void startDrag(QWidget*, const QPoint&); 0178 0179 //! utility function 0180 bool isDockWidgetTitle(const QWidget*) const; 0181 0182 //!@name lock 0183 //@{ 0184 0185 void 0186 setLocked(bool value) 0187 { 0188 _locked = value; 0189 } 0190 0191 //! lock 0192 bool 0193 isLocked() const 0194 { 0195 return _locked; 0196 } 0197 0198 //@} 0199 0200 private: 0201 //! enability 0202 bool _enabled; 0203 0204 //! use WM moveResize 0205 bool _useWMMoveResize; 0206 0207 //! drag mode 0208 int _dragMode; 0209 0210 //! drag distance 0211 /*! this is copied from kwin::geometry */ 0212 int _dragDistance; 0213 0214 //! drag delay 0215 /*! this is copied from kwin::geometry */ 0216 int _dragDelay; 0217 0218 //! wrapper for exception id 0219 class ExceptionId: public QPair<QString, QString> { 0220 public: 0221 //! constructor 0222 ExceptionId(const QString &value) 0223 { 0224 const QStringList args(value.split("@")); 0225 if (args.isEmpty()) 0226 return; 0227 second = args[0].trimmed(); 0228 if (args.size() > 1) { 0229 first = args[1].trimmed(); 0230 } 0231 } 0232 0233 const QString& 0234 appName() const 0235 { 0236 return first; 0237 } 0238 0239 const QString& 0240 className() const 0241 { 0242 return second; 0243 } 0244 }; 0245 0246 //! exception set 0247 typedef QSet<ExceptionId> ExceptionSet; 0248 0249 //! list of white listed special widgets 0250 /*! 0251 it is read from options and is used to adjust 0252 per-app window dragging issues 0253 */ 0254 ExceptionSet _whiteList; 0255 0256 //! list of black listed special widgets 0257 /*! 0258 it is read from options and is used to adjust 0259 per-app window dragging issues 0260 */ 0261 ExceptionSet _blackList; 0262 0263 //! drag point 0264 QPoint _dragPoint; 0265 QPoint _globalDragPoint; 0266 0267 //! drag timer 0268 QBasicTimer _dragTimer; 0269 0270 //! target being dragged 0271 /*! QPointer is used in case the target gets deleted while drag 0272 is in progress */ 0273 QPointer<QWidget> _target; 0274 0275 //! true if drag is about to start 0276 bool _dragAboutToStart; 0277 0278 //! true if drag is in progress 0279 bool _dragInProgress; 0280 0281 //! true if drag is locked 0282 bool _locked; 0283 0284 //! cursor override 0285 /*! used to keep track of application cursor being overridden when dragging in non-WM mode */ 0286 bool _cursorOverride; 0287 0288 //! provide application-wise event filter 0289 /*! 0290 it us used to unlock dragging and make sure event look is properly restored 0291 after a drag has occurred 0292 */ 0293 class AppEventFilter: public QObject { 0294 public: 0295 //! constructor 0296 AppEventFilter(WindowManager* parent): 0297 QObject(parent), 0298 _parent(parent) 0299 {} 0300 0301 //! event filter 0302 bool eventFilter( QObject*, QEvent* ) override; 0303 0304 protected: 0305 //! application-wise event. 0306 /*! needed to catch end of XMoveResize events */ 0307 bool appMouseEvent( QObject*, QEvent* ); 0308 0309 private: 0310 //! parent 0311 WindowManager* _parent; 0312 }; 0313 0314 //! application event filter 0315 AppEventFilter* _appEventFilter; 0316 0317 //! allow access of all private members to the app event filter 0318 friend class AppEventFilter; 0319 }; 0320 0321 } 0322 0323 #endif