1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
54 QT_BEGIN_HEADER
55 
56 QT_BEGIN_NAMESPACE
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 
76 class QWSInternalWindowInfo
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 
winId()103     int winId() const { return id; }
name()104     const QString &name() const { return rgnName; }
caption()105     const QString &caption() const { return rgnCaption; }
client()106     QWSClient* client() const { return c; }
requestedRegion()107     const QRegion &requestedRegion() const { return requested_region; }
108     QRegion allocatedRegion() const;
109     QRegion paintedRegion() const;
isVisible()110     bool isVisible() const { return !requested_region.isEmpty(); }
isPartiallyObscured()111     bool isPartiallyObscured() const { return requested_region != allocatedRegion(); }
isFullyObscured()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 
isOpaque()125     bool isOpaque() const {return opaque && _opacity == 255;}
opacity()126     uint opacity() const { return _opacity; }
127 
windowSurface()128     QWSWindowSurface* windowSurface() const { return surface; }
129 
130 private:
hidden()131     bool hidden() const { return requested_region.isEmpty(); }
forClient(const QWSClient * cl)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);
focusPriority()138     int focusPriority() const { return last_focus_time; }
139     void operation(QWSWindowOperationEvent::Operation o);
shuttingDown()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
requested()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 
instance()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
246     class KeyboardFilter
247     {
248     public:
~KeyboardFilter()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 
309     static QPoint mousePosition;
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
setKeyboardFilter(QWSServer::KeyboardFilter * f)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 
sendEvent(const QInputMethodEvent * ime)408 inline void QWSInputMethod::sendEvent(const QInputMethodEvent *ime)
409 {
410     qwsServer->sendIMEvent(ime);
411 }
412 #ifdef QT3_SUPPORT
sendIMEvent(QWSServer::IMState state,const QString & txt,int cpos,int selLen)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 
sendQuery(int property)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 
435 struct QWSMouseEvent;
436 
437 typedef QMap<int, QWSCursor*> QWSCursorMap;
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&);
identity()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 
clientId()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 
504 QT_END_NAMESPACE
505 
506 QT_END_HEADER
507 
508 #endif // QWINDOWSYSTEM_QWS_H
509