LeechCraft  0.6.70-3565-g2d86529
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
38 #if QT_VERSION < 0x050000
39 #include <QAbstractEventDispatcher>
40 #else
41 #include <QAbstractNativeEventFilter>
42 #endif
43 
44 #include <X11/Xdefs.h>
45 #include "x11config.h"
46 #include "winflags.h"
47 
48 class QIcon;
49 class QWidget;
50 class QRect;
51 
52 typedef unsigned long Window;
53 #define _XTYPEDEF_XID
54 
55 typedef union _XEvent XEvent;
56 
57 namespace LeechCraft
58 {
59 namespace Util
60 {
61  class UTIL_X11_API XWrapper : public QObject
62 #if QT_VERSION >= 0x050000
63  , public QAbstractNativeEventFilter
64 #endif
65  {
66  Q_OBJECT
67 
68  Display *Display_;
69  Window AppWin_;
70 
71  QHash<QString, Atom> Atoms_;
72 
73 #if QT_VERSION < 0x050000
74  const QAbstractEventDispatcher::EventFilter PrevFilter_;
75 #endif
76 
77  XWrapper ();
78  public:
79  enum class Layer
80  {
81  Top,
82  Bottom,
83  Normal
84  };
85 
86  static XWrapper& Instance ();
87 
88  Display* GetDisplay () const;
89  Window GetRootWindow () const;
90 
91 #if QT_VERSION < 0x050000
92  bool Filter (XEvent*);
93 #else
94  bool nativeEventFilter (const QByteArray& eventType, void *message, long *result) override;
95 #endif
96 
97  void Sync ();
98 
99  QList<Window> GetWindows ();
100  QString GetWindowTitle (Window);
101  QIcon GetWindowIcon (Window);
102  WinStateFlags GetWindowState (Window);
103  AllowedActionFlags GetWindowActions (Window);
104 
105  Window GetActiveApp ();
106 
107  bool IsLCWindow (Window);
108  bool ShouldShow (Window);
109 
110  void Subscribe (Window);
111 
112  void SetStrut (QWidget*, Qt::ToolBarArea);
113  void ClearStrut (QWidget*);
114  void SetStrut (Window wid,
115  int left, int right, int top, int bottom,
116  int leftStartY, int leftEndY,
117  int rightStartY, int rightEndY,
118  int topStartX, int topEndX,
119  int bottomStartX, int bottomEndX);
120 
121  void RaiseWindow (Window);
122  void MinimizeWindow (Window);
123  void MaximizeWindow (Window);
124  void UnmaximizeWindow (Window);
125  void ShadeWindow (Window);
126  void UnshadeWindow (Window);
127  void MoveWindowTo (Window, Layer);
128  void CloseWindow (Window);
129 
130  void ResizeWindow (Window, int, int);
131 
132  int GetDesktopCount ();
133  int GetCurrentDesktop ();
134  void SetCurrentDesktop (int);
135  QStringList GetDesktopNames ();
136  QString GetDesktopName (int, const QString& = QString ());
137  int GetWindowDesktop (Window);
138  void MoveWindowToDesktop (Window, int);
139 
140  QRect GetAvailableGeometry (int screen = -1);
141  QRect GetAvailableGeometry (QWidget*);
142 
143  Atom GetAtom (const QString&);
144  private:
145  template<typename T>
146  void HandlePropNotify (T);
147 
148  Window GetActiveWindow ();
149 
150  bool GetWinProp (Window, Atom, ulong*, uchar**, Atom = static_cast<Atom> (0)) const;
151  bool GetRootWinProp (Atom, ulong*, uchar**, Atom = static_cast<Atom> (0)) const;
152  QList<Atom> GetWindowType (Window);
153 
154  bool SendMessage (Window, Atom, ulong, ulong = 0, ulong = 0, ulong = 0, ulong = 0);
155  private slots:
156  void initialize ();
157  signals:
158  void windowListChanged ();
159  void activeWindowChanged ();
160  void desktopChanged ();
161 
162  void windowNameChanged (ulong);
163  void windowIconChanged (ulong);
164  void windowDesktopChanged (ulong);
165  void windowStateChanged (ulong);
166  void windowActionsChanged (ulong);
167  };
168 }
169 }
union _XEvent XEvent
Definition: xwrapper.h:55
#define UTIL_X11_API
Definition: x11config.h:37
auto Filter(const Container< T > &c, F f) -> Container< T >
Definition: prelude.h:169
QWidget * Display_
Definition: util.cpp:85
unsigned long Window
Definition: xwrapper.h:50