LeechCraft  0.6.70-13729-g7046a9d2a7
Modular cross-platform feature rich live environment.
xwrapper.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #include <QX11Info>
33 #include <QList>
34 #include <QString>
35 #include <QHash>
36 #include <QObject>
37 #include <QAbstractNativeEventFilter>
38 #include <X11/Xdefs.h>
39 #include "x11config.h"
40 #include "winflags.h"
41 
42 class QIcon;
43 class QWidget;
44 class QRect;
45 
46 typedef unsigned long Window;
47 #define _XTYPEDEF_XID
48 
49 typedef union _XEvent XEvent;
50 
51 namespace LC
52 {
53 namespace Util
54 {
55  class UTIL_X11_API XWrapper : public QObject
56  , public QAbstractNativeEventFilter
57  {
58  Q_OBJECT
59 
60  Display *Display_;
61  Window AppWin_;
62 
63  QHash<QString, Atom> Atoms_;
64 
65  XWrapper ();
66  public:
67  enum class Layer
68  {
69  Top,
70  Bottom,
71  Normal
72  };
73 
74  static XWrapper& Instance ();
75 
76  Display* GetDisplay () const;
77  Window GetRootWindow () const;
78 
79  bool nativeEventFilter (const QByteArray& eventType, void *message, long *result) override;
80 
81  void Sync ();
82 
83  QList<Window> GetWindows ();
84  QString GetWindowTitle (Window);
85  QIcon GetWindowIcon (Window);
86  WinStateFlags GetWindowState (Window);
87  AllowedActionFlags GetWindowActions (Window);
88 
89  Window GetActiveApp ();
90 
91  bool IsLCWindow (Window);
92  bool ShouldShow (Window);
93 
94  void Subscribe (Window);
95 
96  void SetStrut (QWidget*, Qt::ToolBarArea);
97  void ClearStrut (QWidget*);
98  void SetStrut (Window wid,
99  int left, int right, int top, int bottom,
100  int leftStartY, int leftEndY,
101  int rightStartY, int rightEndY,
102  int topStartX, int topEndX,
103  int bottomStartX, int bottomEndX);
104 
105  void RaiseWindow (Window);
106  void MinimizeWindow (Window);
107  void MaximizeWindow (Window);
108  void UnmaximizeWindow (Window);
109  void ShadeWindow (Window);
110  void UnshadeWindow (Window);
111  void MoveWindowTo (Window, Layer);
112  void CloseWindow (Window);
113 
114  void ResizeWindow (Window, int, int);
115 
116  int GetDesktopCount ();
117  int GetCurrentDesktop ();
118  void SetCurrentDesktop (int);
119  QStringList GetDesktopNames ();
120  QString GetDesktopName (int, const QString& = QString ());
121  int GetWindowDesktop (Window);
122  void MoveWindowToDesktop (Window, int);
123 
124  QRect GetAvailableGeometry (int screen = -1);
125  QRect GetAvailableGeometry (QWidget*);
126 
127  Atom GetAtom (const QString&);
128  private:
129  template<typename T>
130  void HandlePropNotify (T);
131 
132  Window GetActiveWindow ();
133 
134  bool GetWinProp (Window, Atom, ulong*, uchar**, Atom = static_cast<Atom> (0)) const;
135  bool GetRootWinProp (Atom, ulong*, uchar**, Atom = static_cast<Atom> (0)) const;
136  QList<Atom> GetWindowType (Window);
137 
138  bool SendMessage (Window, Atom, ulong, ulong = 0, ulong = 0, ulong = 0, ulong = 0);
139  private slots:
140  void initialize ();
141  signals:
142  void windowListChanged ();
143  void activeWindowChanged ();
144  void desktopChanged ();
145 
146  void windowNameChanged (ulong);
147  void windowIconChanged (ulong);
148  void windowDesktopChanged (ulong);
149  void windowStateChanged (ulong);
150  void windowActionsChanged (ulong);
151  };
152 }
153 }
union _XEvent XEvent
Definition: xwrapper.h:49
#define UTIL_X11_API
Definition: x11config.h:37
unsigned long Window
Definition: xwrapper.h:44
Definition: constants.h:35