1 //=========================================== 2 // Lumina-DE source code 3 // Copyright (c) 2017-2018, Ken Moore 4 // Available under the 3-clause BSD license 5 // See the LICENSE file for full details 6 //=========================================== 7 // This is a container object for setting/announcing changes 8 // in a native window's properties. 9 // The WM will usually run the "setProperty" function on this object, 10 // and any other classes/widgets which watch this window can act appropriatly after-the-fact 11 // Non-WM classes should use the "Request" signals to ask the WM to do something, and listen for changes later 12 //=========================================== 13 #ifndef _LUMINA_SOURCES_NATIVE_WINDOW_OBJECT_H 14 #define _LUMINA_SOURCES_NATIVE_WINDOW_OBJECT_H 15 #include "global-includes.h" 16 17 class NativeWindowObject : public QObject{ 18 Q_OBJECT 19 // QML-ACCESSIBLE PROPERTIES 20 Q_PROPERTY( QString winImage READ winImage NOTIFY winImageChanged) 21 Q_PROPERTY( QString name READ name NOTIFY nameChanged) 22 Q_PROPERTY( QString title READ title NOTIFY titleChanged) 23 Q_PROPERTY( QString shortTitle READ shortTitle NOTIFY shortTitleChanged) 24 Q_PROPERTY( QString icon READ icon NOTIFY iconChanged) 25 Q_PROPERTY( bool sticky READ isSticky NOTIFY stickyChanged) 26 Q_PROPERTY(bool isVisible READ isVisible NOTIFY visibilityChanged) 27 //Button/Titlebar visibility 28 Q_PROPERTY( bool showCloseButton READ showCloseButton NOTIFY winTypeChanged) 29 Q_PROPERTY( bool showMinButton READ showMinButton NOTIFY winTypeChanged) 30 Q_PROPERTY( bool showMaxButton READ showMaxButton NOTIFY winTypeChanged) 31 Q_PROPERTY( bool showTitlebar READ showTitlebar NOTIFY winTypeChanged) 32 Q_PROPERTY( bool showGenericButton READ showGenericButton NOTIFY winTypeChanged) 33 Q_PROPERTY( bool showWindowFrame READ showWindowFrame NOTIFY winTypeChanged) 34 //Geometry information 35 Q_PROPERTY( QRect frameGeometry READ frameGeometry NOTIFY geomChanged) 36 Q_PROPERTY( QRect imageGeometry READ imageGeometry NOTIFY geomChanged) 37 38 public: 39 enum State{ S_MODAL, S_STICKY, S_MAX_VERT, S_MAX_HORZ, S_SHADED, S_SKIP_TASKBAR, S_SKIP_PAGER, S_HIDDEN, S_FULLSCREEN, S_ABOVE, S_BELOW, S_ATTENTION }; 40 enum Type{T_DESKTOP, T_DOCK, T_TOOLBAR, T_MENU, T_UTILITY, T_SPLASH, T_DIALOG, T_DROPDOWN_MENU, T_POPUP_MENU, T_TOOLTIP, T_NOTIFICATION, T_COMBO, T_DND, T_NORMAL }; 41 enum Action {A_MOVE, A_RESIZE, A_MINIMIZE, A_SHADE, A_STICK, A_MAX_VERT, A_MAX_HORZ, A_FULLSCREEN, A_CHANGE_DESKTOP, A_CLOSE, A_ABOVE, A_BELOW}; 42 enum Location { TOP_LEFT, TOP, TOP_RIGHT, RIGHT, BOTTOM_RIGHT, BOTTOM, BOTTOM_LEFT, LEFT }; 43 Q_ENUM(Location) 44 45 enum Property{ /*QVariant Type*/ 46 None=0, /*null*/ 47 MinSize=1, /*QSize*/ 48 MaxSize=2, /*QSize*/ 49 Size=3, /*QSize*/ 50 GlobalPos=4, /*QPoint*/ 51 Title=5, /*QString*/ 52 ShortTitle=6, /*QString*/ 53 Icon=7, /*QIcon*/ 54 Name=8, /*QString*/ 55 Workspace=9, /*int*/ 56 States=10, /*QList<NativeWindowObject::State> : Current state of the window */ 57 WinTypes=11, /*QList<NativeWindowObject::Type> : Current type of window (typically does not change)*/ 58 WinActions=12, /*QList<NativeWindowObject::Action> : Current actions that the window allows (Managed/set by the WM)*/ 59 FrameExtents=13, /*QList<int> : [Left, Right, Top, Bottom] in pixels */ 60 RelatedWindows=14, /* QList<WId> - better to use the "isRelatedTo(WId)" function instead of reading this directly*/ 61 Active=15, /*bool*/ 62 Visible=16, /*bool*/ 63 WinImage=17 /*QImage*/ 64 }; 65 allProperties()66 static QList<NativeWindowObject::Property> allProperties(){ 67 //Return all the available properties (excluding "None" and "FrameExtents" (WM control only) ) 68 QList<NativeWindowObject::Property> props; 69 props << MinSize << MaxSize << Size << GlobalPos << Title << ShortTitle << Icon << Name << Workspace \ 70 << States << WinTypes << WinActions << RelatedWindows << Active << Visible; 71 return props; 72 }; 73 74 static void RegisterType(); 75 76 NativeWindowObject(WId id = 0); 77 ~NativeWindowObject(); 78 79 void addFrameWinID(WId); 80 void addDamageID(unsigned int); 81 bool isRelatedTo(WId); 82 83 WId id(); 84 WId frameId(); 85 unsigned int damageId(); 86 87 //QWindow* window(); 88 89 QVariant property(NativeWindowObject::Property); 90 void setProperty(NativeWindowObject::Property, QVariant, bool force = false); 91 void setProperties(QList<NativeWindowObject::Property>, QList<QVariant>, bool force = false); 92 void requestProperty(NativeWindowObject::Property, QVariant, bool force = false); 93 void requestProperties(QList<NativeWindowObject::Property>, QList<QVariant>, bool force = false); 94 95 Q_INVOKABLE QRect geometry(); //this returns the "full" geometry of the window (window + frame) 96 void setGeometryNow(QRect geom); 97 98 // QML ACCESS FUNCTIONS (shortcuts for particular properties in a format QML can use) 99 Q_INVOKABLE QString winImage(); 100 Q_INVOKABLE QString name(); 101 Q_INVOKABLE QString title(); 102 Q_INVOKABLE QString shortTitle(); 103 Q_INVOKABLE QString icon(); 104 //QML Button states 105 Q_INVOKABLE bool showCloseButton(); 106 Q_INVOKABLE bool showMaxButton(); 107 Q_INVOKABLE bool showMinButton(); 108 Q_INVOKABLE bool showTitlebar(); 109 Q_INVOKABLE bool showGenericButton(); 110 Q_INVOKABLE bool showWindowFrame(); 111 //QML Window States 112 Q_INVOKABLE bool isSticky(); 113 Q_INVOKABLE bool isVisible(); 114 Q_INVOKABLE int workspace(); 115 116 //QML Geometry reporting 117 Q_INVOKABLE QRect frameGeometry(); 118 Q_INVOKABLE QRect imageGeometry(); 119 Q_INVOKABLE void updateGeometry(int x, int y, int width, int height, bool now = false); //For QML to change the current window position 120 121 public slots: 122 Q_INVOKABLE void toggleVisibility(); 123 Q_INVOKABLE void toggleMaximize(); 124 Q_INVOKABLE void requestClose(); //ask the app to close the window (may/not depending on activity) 125 Q_INVOKABLE void requestKill(); //ask the WM to kill the app associated with this window (harsh - only use if not responding) 126 Q_INVOKABLE void requestPing(); //ask the app if it is still active (a WindowNotResponding signal will get sent out if there is no reply); 127 Q_INVOKABLE void requestActivate(); 128 Q_INVOKABLE void announceClosed(); 129 130 private: 131 QHash <NativeWindowObject::Property, QVariant> hash; 132 //QWindow *WIN; 133 WId winid, frameid; 134 QList<WId> relatedTo; 135 unsigned int dmgID, dmg, icodmg; 136 //Collation/Delay for window resize events 137 QTimer *geomTimer; 138 QRect newgeom, lastgeom; 139 140 void emitSinglePropChanged(NativeWindowObject::Property); 141 142 private slots: 143 void sendNewGeom(); 144 145 signals: 146 //General Notifications 147 void PropertiesChanged(QList<NativeWindowObject::Property>, QList<QVariant>); 148 void RequestPropertiesChange(WId, QList<NativeWindowObject::Property>, QList<QVariant>); 149 void WindowClosed(WId); 150 void WindowNotResponding(WId); //will be sent out if a window does not respond to a ping request 151 152 //Action Requests (not automatically emitted - typically used to ask the WM to do something) 153 //Note: "WId" should be the NativeWindowObject id() 154 void RequestClose(WId); //Close the window 155 void RequestKill(WId); //Kill the window/app (usually from being unresponsive) 156 void RequestPing(WId); //Verify that the window is still active (such as not closing after a request 157 void RequestReparent(WId, WId, QPoint); //client window, frame window, relative origin point in frame 158 void VerifyNewGeometry(WId); 159 // System Tray Icon Embed/Unembed Requests 160 //void RequestEmbed(WId, QWidget*); 161 //void RequestUnEmbed(WId, QWidget*); 162 163 // QML update signals 164 void winImageChanged(); 165 void nameChanged(); 166 void titleChanged(); 167 void shortTitleChanged(); 168 void iconChanged(); 169 void stickyChanged(); 170 void winTypeChanged(); 171 void geomChanged(); 172 void visibilityChanged(); 173 }; 174 175 // Declare the enumerations as Qt MetaTypes 176 Q_DECLARE_METATYPE(NativeWindowObject::Type); 177 Q_DECLARE_METATYPE(NativeWindowObject::Action); 178 Q_DECLARE_METATYPE(NativeWindowObject::State); 179 Q_DECLARE_METATYPE(NativeWindowObject::Property); 180 181 #endif 182