QtGui/qwindowsystem_qws.h Source File

qwindowsystem_qws.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QWINDOWSYSTEM_QWS_H
43 #define QWINDOWSYSTEM_QWS_H
44 
45 #include <QtCore/qbytearray.h>
46 #include <QtCore/qmap.h>
47 #include <QtCore/qdatetime.h>
48 #include <QtCore/qlist.h>
49 
50 #include <QtGui/qwsevent_qws.h>
51 #include <QtGui/qkbd_qws.h>
52 #include <QtGui/qregion.h>
53 
55 
57 
58 QT_MODULE(Gui)
59 
60 struct QWSWindowPrivate;
61 class QWSCursor;
62 class QWSClient;
63 class QWSRegionManager;
64 class QBrush;
65 class QVariant;
66 class QInputMethodEvent;
67 class QWSInputMethod;
68 class QWSBackingStore;
69 class QWSWindowSurface;
70 
71 #ifdef QT3_SUPPORT
72 class QImage;
73 class QColor;
74 #endif
75 
77 {
78 public:
79  int winid;
80  unsigned int clientid;
81  QString name; // Corresponds to QObject name of top-level widget
82 };
83 
84 
85 class Q_GUI_EXPORT QWSScreenSaver
86 {
87 public:
88  virtual ~QWSScreenSaver();
89  virtual void restore()=0;
90  virtual bool save(int level)=0;
91 };
92 
93 
94 class Q_GUI_EXPORT QWSWindow
95 {
96  friend class QWSServer;
97  friend class QWSServerPrivate;
98 
99 public:
100  QWSWindow(int i, QWSClient* client);
101  ~QWSWindow();
102 
103  int winId() const { return id; }
104  const QString &name() const { return rgnName; }
105  const QString &caption() const { return rgnCaption; }
106  QWSClient* client() const { return c; }
107  const QRegion &requestedRegion() const { return requested_region; }
108  QRegion allocatedRegion() const;
109  QRegion paintedRegion() const;
110  bool isVisible() const { return !requested_region.isEmpty(); }
111  bool isPartiallyObscured() const { return requested_region != allocatedRegion(); }
112  bool isFullyObscured() const { return allocatedRegion().isEmpty(); }
113 
114  enum State { NoState, Hidden, Showing, Visible, Hiding, Raising, Lowering, Moving, ChangingGeometry, Destroyed };
115  State state() const;
116  Qt::WindowFlags windowFlags() const;
117  QRegion dirtyOnScreen() const;
118 
119  void raise();
120  void lower();
121  void show();
122  void hide();
123  void setActiveWindow();
124 
125  bool isOpaque() const {return opaque && _opacity == 255;}
126  uint opacity() const { return _opacity; }
127 
128  QWSWindowSurface* windowSurface() const { return surface; }
129 
130 private:
131  bool hidden() const { return requested_region.isEmpty(); }
132  bool forClient(const QWSClient* cl) const { return cl==c; }
133 
134  void setName(const QString &n);
135  void setCaption(const QString &c);
136 
137  void focus(bool get);
138  int focusPriority() const { return last_focus_time; }
139  void operation(QWSWindowOperationEvent::Operation o);
140  void shuttingDown() { last_focus_time=0; }
141 
142 #ifdef QT_QWS_CLIENTBLIT
143  QRegion directPaintRegion() const;
144  inline void setDirectPaintRegion(const QRegion &topmost);
145 #endif
146  inline void setAllocatedRegion(const QRegion &region);
147 
148  void createSurface(const QString &key, const QByteArray &data);
149 
150 #ifndef QT_NO_QWSEMBEDWIDGET
151  void startEmbed(QWSWindow *window);
152  void stopEmbed(QWSWindow *window);
153 #endif
154 
155 private:
156  int id;
157  QString rgnName;
158  QString rgnCaption;
159  bool modified;
160  bool onTop;
161  QWSClient* c;
162  QRegion requested_region;
163  QRegion exposed;
164  int last_focus_time;
165  QWSWindowSurface *surface;
166  uint _opacity;
167  bool opaque;
168  QWSWindowPrivate *d;
169 #ifdef QT3_SUPPORT
170  inline QT3_SUPPORT QRegion requested() const { return requested_region; }
171 // inline QT3_SUPPORT QRegion allocation() const { return allocated_region; }
172 #endif
173 };
174 
175 
176 #ifndef QT_NO_SOUND
177 class QWSSoundServer;
178 #ifdef QT_USE_OLD_QWS_SOUND
179 class QWSSoundServerData;
180 
181 class Q_GUI_EXPORT QWSSoundServer : public QObject {
182  Q_OBJECT
183 public:
184  QWSSoundServer(QObject* parent);
185  ~QWSSoundServer();
186  void playFile(const QString& filename);
187 private Q_SLOTS:
188  void feedDevice(int fd);
189 private:
190  QWSSoundServerData* d;
191 };
192 #endif
193 #endif
194 
195 
196 /*********************************************************************
197  *
198  * Class: QWSServer
199  *
200  *********************************************************************/
201 
202 class QWSMouseHandler;
203 struct QWSCommandStruct;
204 class QWSServerPrivate;
205 class QWSServer;
206 
207 extern Q_GUI_EXPORT QWSServer *qwsServer;
208 
209 class Q_GUI_EXPORT QWSServer : public QObject
210 {
211  friend class QCopChannel;
212  friend class QWSMouseHandler;
213  friend class QWSWindow;
214  friend class QWSDisplay;
215  friend class QWSInputMethod;
216  Q_OBJECT
217  Q_DECLARE_PRIVATE(QWSServer)
218 public:
219  explicit QWSServer(int flags = 0, QObject *parent=0);
220 #ifdef QT3_SUPPORT
221  QT3_SUPPORT_CONSTRUCTOR QWSServer(int flags, QObject *parent, const char *name);
222 #endif
223  ~QWSServer();
224  enum ServerFlags { DisableKeyboard = 0x01,
225  DisableMouse = 0x02 };
226 
227  static void sendKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
228  bool isPress, bool autoRepeat);
229 #ifndef QT_NO_QWS_KEYBOARD
230  static void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
231  bool isPress, bool autoRepeat);
232 #endif
233 
234  static QWSServer* instance() { return qwsServer; }
235 
236 #ifndef QT_NO_QWS_INPUTMETHODS
237 #ifdef QT3_SUPPORT
238  enum IMState { IMCompose, IMEnd, IMStart = IMCompose };
239 #endif
240  enum IMMouse { MousePress, MouseRelease, MouseMove, MouseOutside }; //MouseMove reserved but not used
241  void sendIMEvent(const QInputMethodEvent*);
242  void sendIMQuery(int property);
243 #endif
244 
245 #ifndef QT_NO_QWS_KEYBOARD
247  {
248  public:
249  virtual ~KeyboardFilter() {}
250  virtual bool filter(int unicode, int keycode, int modifiers,
251  bool isPress, bool autoRepeat)=0;
252  };
253  static void addKeyboardFilter(KeyboardFilter *f);
254  static void removeKeyboardFilter();
255 #endif
256 
257 #ifndef QT_NO_QWS_INPUTMETHODS
258  static void setCurrentInputMethod(QWSInputMethod *im);
259  static void resetInputMethod();
260 #endif
261 
262  static void setDefaultMouse(const char *);
263  static void setDefaultKeyboard(const char *);
264  static void setMaxWindowRect(const QRect&);
265  static void sendMouseEvent(const QPoint& pos, int state, int wheel = 0);
266 
267  static void setBackground(const QBrush &);
268 #ifdef QT3_SUPPORT
269  static QT3_SUPPORT void setDesktopBackground(const QImage &img);
270  static QT3_SUPPORT void setDesktopBackground(const QColor &);
271 #endif
272  static QWSMouseHandler *mouseHandler();
273  static const QList<QWSMouseHandler*>& mouseHandlers();
274  static void setMouseHandler(QWSMouseHandler*);
275 #ifndef QT_NO_QWS_KEYBOARD
276  static QWSKeyboardHandler* keyboardHandler();
277  static void setKeyboardHandler(QWSKeyboardHandler* kh);
278 #endif
279  QWSWindow *windowAt(const QPoint& pos);
280 
281  const QList<QWSWindow*> &clientWindows();
282 
283  void openMouse();
284  void closeMouse();
285  void suspendMouse();
286  void resumeMouse();
287 #ifndef QT_NO_QWS_KEYBOARD
288  void openKeyboard();
289  void closeKeyboard();
290 #endif
291 
292  static void setScreenSaver(QWSScreenSaver*);
293  static void setScreenSaverIntervals(int* ms);
294  static void setScreenSaverInterval(int);
295  static void setScreenSaverBlockLevel(int);
296  static bool screenSaverActive();
297  static void screenSaverActivate(bool);
298 
299  // the following are internal.
300  void refresh();
301  void refresh(QRegion &);
302 
303  void enablePainting(bool);
304  static void processEventQueue();
305  static QList<QWSInternalWindowInfo*> * windowList();
306 
307  void sendPropertyNotifyEvent(int property, int state);
308 
310 
311  static void startup(int flags);
312  static void closedown();
313 
314  static void beginDisplayReconfigure();
315  static void endDisplayReconfigure();
316 
317 #ifndef QT_NO_QWS_CURSOR
318  static void setCursorVisible(bool);
319  static bool isCursorVisible();
320 #endif
321 
322  const QBrush &backgroundBrush() const;
323 
324  enum WindowEvent { Create=0x0001, Destroy=0x0002, Hide=0x0004, Show=0x0008,
325  Raise=0x0010, Lower=0x0020, Geometry=0x0040, Active = 0x0080,
326  Name=0x0100 };
327 
328 Q_SIGNALS:
329  void windowEvent(QWSWindow *w, QWSServer::WindowEvent e);
330 
331 #ifndef QT_NO_COP
332  void newChannel(const QString& channel);
333  void removedChannel(const QString& channel);
334 
335 #endif
336 #ifndef QT_NO_QWS_INPUTMETHODS
337  void markedText(const QString &);
338 #endif
339 
340 protected:
341  void timerEvent(QTimerEvent *e);
342 
343 private:
344  friend class QApplicationPrivate;
345  void updateWindowRegions() const;
346 
347 #ifdef QT3_SUPPORT
348 #ifndef QT_NO_QWS_KEYBOARD
349  static inline QT3_SUPPORT void setKeyboardFilter(QWSServer::KeyboardFilter *f)
350  { if (f) addKeyboardFilter(f); else removeKeyboardFilter(); }
351 #endif
352 #endif
353 
354 private:
355 #ifndef QT_NO_QWS_MULTIPROCESS
356  Q_PRIVATE_SLOT(d_func(), void _q_clientClosed())
357  Q_PRIVATE_SLOT(d_func(), void _q_doClient())
358  Q_PRIVATE_SLOT(d_func(), void _q_deleteWindowsLater())
359 #endif
360 
361  Q_PRIVATE_SLOT(d_func(), void _q_screenSaverWake())
362  Q_PRIVATE_SLOT(d_func(), void _q_screenSaverSleep())
363  Q_PRIVATE_SLOT(d_func(), void _q_screenSaverTimeout())
364 
365 #ifndef QT_NO_QWS_MULTIPROCESS
366  Q_PRIVATE_SLOT(d_func(), void _q_newConnection())
367 #endif
368 };
369 
370 #ifndef QT_NO_QWS_INPUTMETHODS
371 class Q_GUI_EXPORT QWSInputMethod : public QObject
372 {
373  Q_OBJECT
374 public:
375  QWSInputMethod();
376  virtual ~QWSInputMethod();
377 
378  enum UpdateType {Update, FocusIn, FocusOut, Reset, Destroyed};
379 
380  virtual bool filter(int unicode, int keycode, int modifiers,
381  bool isPress, bool autoRepeat);
382 
383  virtual bool filter(const QPoint &, int state, int wheel);
384 
385  virtual void reset();
386  virtual void updateHandler(int type);
387  virtual void mouseHandler(int pos, int state);
388  virtual void queryResponse(int property, const QVariant&);
389 
390 protected:
391  uint setInputResolution(bool isHigh);
392  uint inputResolutionShift() const;
393  // needed for required transform
394  void sendMouseEvent(const QPoint &pos, int state, int wheel);
395 
396  void sendEvent(const QInputMethodEvent*);
397  void sendPreeditString(const QString &preeditString, int cursorPosition, int selectionLength = 0);
398  void sendCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0);
399  void sendQuery(int property);
400 
401 #ifdef QT3_SUPPORT
402  inline void sendIMEvent(QWSServer::IMState, const QString& txt, int cpos, int selLen = 0);
403 #endif
404 private:
405  bool mIResolution;
406 };
407 
408 inline void QWSInputMethod::sendEvent(const QInputMethodEvent *ime)
409 {
410  qwsServer->sendIMEvent(ime);
411 }
412 #ifdef QT3_SUPPORT
413 inline void QWSInputMethod::sendIMEvent(QWSServer::IMState state, const QString& txt, int cpos, int selLen)
414 {
415  if (state == QWSServer::IMCompose) sendPreeditString(txt, cpos, selLen); else sendCommitString(txt);
416 }
417 #endif
418 
419 inline void QWSInputMethod::sendQuery(int property)
420 {
421  qwsServer->sendIMQuery(property);
422 }
423 
424 // mouse events not inline as involve transformations.
425 #endif // QT_NO_QWS_INPUTMETHODS
426 
427 
428 
429 /*********************************************************************
430  *
431  * Class: QWSClient
432  *
433  *********************************************************************/
434 
436 
438 
439 class QWSClientPrivate;
440 class QWSCommand;
441 class QWSConvertSelectionCommand;
442 
443 class Q_GUI_EXPORT QWSClient : public QObject
444 {
445  Q_OBJECT
446  Q_DECLARE_PRIVATE(QWSClient)
447 public:
448  QWSClient(QObject* parent, QWS_SOCK_BASE *, int id);
449  ~QWSClient();
450 
451  int socket() const;
452 
453  void setIdentity(const QString&);
454  QString identity() const { return id; }
455 
456  void sendEvent(QWSEvent* event);
457  void sendConnectedEvent(const char *display_spec);
458  void sendMaxWindowRectEvent(const QRect &rect);
459  void sendPropertyNotifyEvent(int property, int state);
460  void sendPropertyReplyEvent(int property, int len, const char *data);
461  void sendSelectionClearEvent(int windowid);
462  void sendSelectionRequestEvent(QWSConvertSelectionCommand *cmd, int windowid);
463 #ifndef QT_QWS_CLIENTBLIT
464  void sendRegionEvent(int winid, QRegion rgn, int type);
465 #else
466  void sendRegionEvent(int winid, QRegion rgn, int type, int id = 0);
467 #endif
468 #ifndef QT_NO_QWSEMBEDWIDGET
469  void sendEmbedEvent(int winid, QWSEmbedEvent::Type type,
470  const QRegion &region = QRegion());
471 #endif
472  QWSCommand* readMoreCommand();
473 
474  int clientId() const { return cid; }
475 
476  QWSCursorMap cursors; // cursors defined by this client
477 Q_SIGNALS:
478  void connectionClosed();
479  void readyRead();
480 private Q_SLOTS:
481  void closeHandler();
482  void errorHandler();
483 
484 private:
485 #ifndef QT_NO_QWS_MULTIPROCESS
486  friend class QWSWindow;
487  void removeUnbufferedSurface();
488  void addUnbufferedSurface();
489 #endif
490 
491 private:
492  int socketDescriptor;
493 #ifndef QT_NO_QWS_MULTIPROCESS
494  QWSSocket *csocket;
495 #endif
496  QWSCommand* command;
497  uint isClosed : 1;
498  QString id;
499  int cid;
500 
501  friend class QWSServerPrivate;
502 };
503 
505 
507 
508 #endif // QWINDOWSYSTEM_QWS_H
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
GLint level
Definition: GLee.h:905
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
State
The state the media producing object is in at the moment.
uint opacity() const
QWSCursorMap cursors
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
Definition: qcolor.h:67
#define Q_SLOTS
Definition: qobjectdefs.h:71
int clientId() const
#define Q_SIGNALS
Definition: qobjectdefs.h:72
const QString & name() const
void sendPreeditString(const QString &preeditString, int cursorPosition, int selectionLength=0)
Definition: qpoint.h:53
virtual void timerEvent(QTimerEvent *)
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:880
GLint GLvoid * img
Definition: GLee.h:1216
const QRegion & requestedRegion() const
Definition: qimage.h:87
static QPoint mousePosition
bool isVisible() const
QObject * parent() const
Definition: qobject.h:273
bool isFullyObscured() const
GLenum GLsizei n
Definition: GLee.h:3432
#define Q_OBJECT
Definition: qobjectdefs.h:157
static QWSServer * instance()
bool isPartiallyObscured() const
Definition: qrect.h:58
Window window
Definition: GLee.h:10520
#define QWS_SOCK_BASE
Definition: qwsutils_qws.h:54
const GLubyte * c
Definition: GLee.h:5419
void sendEvent(const QInputMethodEvent *)
int int channel
Definition: GLee.h:10533
GLuint const GLchar * name
Definition: GLee.h:1704
const QString & caption() const
QWSWindowSurface * windowSurface() const
GLenum filter
Definition: GLee.h:3431
GLboolean reset
Definition: GLee.h:895
QVariant property(const char *name) const
Definition: qbrush.h:76
Q_GUI_EXPORT QWSServer * qwsServer
GLubyte GLubyte GLubyte GLubyte w
Definition: GLee.h:1775
int winId() const
bool isOpaque() const
GLuint id
Definition: GLee.h:1552
void sendQuery(int property)
GLenum GLsizei len
Definition: GLee.h:2695
QString identity() const
#define QT_END_HEADER
Definition: qglobal.h:142
QWSClient * client() const
GLclampf f
Definition: GLee.h:9303
void sendCommitString(const QString &commitString, int replaceFrom=0, int replaceLength=0)
QMap< int, QWSCursor * > QWSCursorMap