Qt 4.8
qwindowsystem_qws.cpp
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 #include "qplatformdefs.h"
43 
44 #include "qwindowsystem_qws.h"
45 #include "qwsevent_qws.h"
46 #include "qwscommand_qws_p.h"
47 #include "qtransportauth_qws_p.h"
48 #include "qwsutils_qws.h"
49 #include "qwscursor_qws.h"
50 #include "qwsdisplay_qws.h"
51 #include "qmouse_qws.h"
52 #include "qcopchannel_qws.h"
53 #include "qwssocket_qws.h"
54 
55 #include "qapplication.h"
56 #include "private/qapplication_p.h"
57 #include "qsocketnotifier.h"
58 #include "qpolygon.h"
59 #include "qimage.h"
60 #include "qcursor.h"
61 #include <private/qpaintengine_raster_p.h>
62 #include "qscreen_qws.h"
63 #include "qwindowdefs.h"
64 #include "private/qlock_p.h"
65 #include "qwslock_p.h"
66 #include "qfile.h"
67 #include "qtimer.h"
68 #include "qpen.h"
69 #include "qdesktopwidget.h"
70 #include "qevent.h"
71 #include "qinputcontext.h"
72 #include "qpainter.h"
73 
74 #include <qdebug.h>
75 
76 #include "qkbddriverfactory_qws.h"
78 
79 #include <qbuffer.h>
80 #include <qdir.h>
81 
82 #include <private/qwindowsurface_qws_p.h>
83 #include <private/qfontengine_qpf_p.h>
84 
85 #include "qwindowsystem_p.h"
86 
87 
88 #include <stdlib.h>
89 #include <stdio.h>
90 #include <errno.h>
91 
92 #ifndef QT_NO_QWS_MULTIPROCESS
93 #include <sys/param.h>
94 #include <sys/mount.h>
95 #endif
96 
97 #if !defined(QT_NO_SOUND) && !defined(Q_OS_DARWIN)
98 #ifdef QT_USE_OLD_QWS_SOUND
99 #include <sys/types.h>
100 #include <sys/stat.h>
101 #include <sys/ioctl.h>
102 #include <sys/soundcard.h>
103 #else
104 #include "qsoundqss_qws.h"
105 #endif
106 #endif
107 
108 //#define QWS_DEBUG_FONTCLEANUP
109 
111 
114 
115 #define MOUSE 0
116 #define KEY 1
117 //#define EVENT_BLOCK_DEBUG
118 
120 {
121 }
122 
124 extern void qt_init_display(); //qapplication_qws.cpp
126 
127 extern void qt_client_enqueue(const QWSEvent *); //qapplication_qws.cpp
129 
130 Q_GLOBAL_STATIC_WITH_ARGS(QString, defaultMouse, (QLatin1String("Auto")))
132 static const int FontCleanupInterval = 60 * 1000;
133 
134 static int qws_keyModifiers = 0;
135 
137 static bool keyboardGrabbing;
138 
139 static int get_object_id(int count = 1)
140 {
141  static int next=1000;
142  int n = next;
143  next += count;
144  return n;
145 }
146 #ifndef QT_NO_QWS_INPUTMETHODS
148 
150 static int current_IM_winId = -1;
151 static bool force_reject_strokeIM = false;
152 #endif
153 
154 static void cleanupFontsDir();
155 
156 //#define QWS_REGION_DEBUG
157 
231 {
232 public:
234 
235 #ifdef QT_QWS_CLIENTBLIT
236  QRegion directPaintRegion;
237 #endif
239 #ifndef QT_NO_QWSEMBEDWIDGET
242 #endif
244  Qt::WindowFlags windowFlags;
246  bool painted;
247 };
248 
250  :
251 #ifndef QT_NO_QWSEMBEDWIDGET
252  embedder(0), state(QWSWindow::NoState),
253 #endif
254  painted(false)
255 {
256 }
257 
410  : id(i), modified(false),
411  onTop(false), c(client), last_focus_time(0), _opacity(255),
412  opaque(true), d(new QWSWindowPrivate)
413 {
414  surface = 0;
415 }
416 
417 
448 {
449  return d->state;
450 }
451 
458 Qt::WindowFlags QWSWindow::windowFlags() const
459 {
460  return d->windowFlags;
461 }
462 
469 {
470  return d->dirtyOnScreen;
471 }
472 
474 {
475 #ifndef QT_NO_QWS_MULTIPROCESS
476  if (surface && !surface->isBuffered())
478 #endif
479 
480  delete surface;
482  surface->setPermanentState(data);
483 
484 #ifndef QT_NO_QWS_MULTIPROCESS
485  if (!surface->isBuffered())
487 #endif
488 }
489 
498 {
499  qwsServerPrivate->raiseWindow(this);
500 #ifndef QT_NO_QWSEMBEDWIDGET
501  const int n = d->embedded.size();
502  for (int i = 0; i < n; ++i)
503  d->embedded.at(i)->raise();
504 #endif
505 }
506 
515 {
516  qwsServerPrivate->lowerWindow(this);
517 #ifndef QT_NO_QWSEMBEDWIDGET
518  const int n = d->embedded.size();
519  for (int i = 0; i < n; ++i)
520  d->embedded.at(i)->lower();
521 #endif
522 }
523 
532 {
534 #ifndef QT_NO_QWSEMBEDWIDGET
535  const int n = d->embedded.size();
536  for (int i = 0; i < n; ++i)
537  d->embedded.at(i)->show();
538 #endif
539 }
540 
549 {
551 #ifndef QT_NO_QWSEMBEDWIDGET
552  const int n = d->embedded.size();
553  for (int i = 0; i < n; ++i)
554  d->embedded.at(i)->hide();
555 #endif
556 }
557 
567 {
568  qwsServerPrivate->setFocus(this, true);
569 #ifndef QT_NO_QWSEMBEDWIDGET
570  const int n = d->embedded.size();
571  for (int i = 0; i < n; ++i)
572  d->embedded.at(i)->setActiveWindow();
573 #endif
574 }
575 
577 {
578  rgnName = n;
579 }
580 
589 {
590  rgnCaption = c;
591 }
592 
593 
595 
596 void QWSWindow::focus(bool get)
597 {
598  if (get)
600  if (c) {
602  event.simpleData.window = id;
603  event.simpleData.get_focus = get;
604  c->sendEvent(&event);
605  }
606 }
607 
609 {
610  if (!c)
611  return;
613  event.simpleData.window = id;
614  event.simpleData.op = o;
615  c->sendEvent(&event);
616 }
617 
626 {
627 #ifndef QT_NO_QWS_INPUTMETHODS
628  if (current_IM_composing_win == this)
629  current_IM_composing_win = 0;
630 #endif
631 #ifndef QT_NO_QWSEMBEDWIDGET
632  QWSWindow *embedder = d->embedder;
633  if (embedder) {
634  embedder->d->embedded.removeAll(this);
635  d->embedder = 0;
636  }
637  while (!d->embedded.isEmpty())
639 #endif
640 
641 #ifndef QT_NO_QWS_MULTIPROCESS
642  if (surface && !surface->isBuffered()) {
643  if (c && c->d_func()) // d_func() will be 0 if client is deleted
645  }
646 #endif
647 
648  delete surface;
649  delete d;
650 }
651 
665 {
666  return d->allocatedRegion;
667 }
668 
669 #ifdef QT_QWS_CLIENTBLIT
670 QRegion QWSWindow::directPaintRegion() const
671 {
672  return d->directPaintRegion;
673 }
674 
675 inline void QWSWindow::setDirectPaintRegion(const QRegion &r)
676 {
677  d->directPaintRegion = r;
678 }
679 #endif
680 
692 {
693  return (d->painted ? d->allocatedRegion : QRegion());
694 }
695 
696 inline void QWSWindow::setAllocatedRegion(const QRegion &region)
697 {
698  d->allocatedRegion = region;
699 }
700 
701 #ifndef QT_NO_QWSEMBEDWIDGET
703 {
704  d->embedded.append(w);
705  w->d->embedder = this;
706 }
707 
709 {
710  w->d->embedder = 0;
712  d->embedded.removeAll(w);
713 }
714 #endif // QT_NO_QWSEMBEDWIDGET
715 
716 /*********************************************************************
717  *
718  * Class: QWSClient
719  *
720  *********************************************************************/
721 
723 {
725 
726 public:
728  ~QWSClientPrivate();
729 
730  void setLockId(int id);
731  void unlockCommunication();
732 
733 private:
734 #ifndef QT_NO_QWS_MULTIPROCESS
736  bool shutdown;
738 #endif
740  friend class QWSServerPrivate;
741 };
742 
744 {
745 #ifndef QT_NO_QWS_MULTIPROCESS
746  clientLock = 0;
747  shutdown = false;
748  numUnbufferedSurfaces = 0;
749 #endif
750 }
751 
753 {
754 #ifndef QT_NO_QWS_MULTIPROCESS
755  delete clientLock;
756 #endif
757 }
758 
760 {
761 #ifdef QT_NO_QWS_MULTIPROCESS
762  Q_UNUSED(id);
763 #else
764  clientLock = new QWSLock(id);
765 #endif
766 }
767 
769 {
770 #ifndef QT_NO_QWS_MULTIPROCESS
771  if (clientLock)
772  clientLock->unlock(QWSLock::Communication);
773 #endif
774 }
775 
813 //always use frame buffer
815  : QObject(*new QWSClientPrivate, parent), command(0), cid(id)
816 {
817 #ifdef QT_NO_QWS_MULTIPROCESS
818  Q_UNUSED(sock);
819  isClosed = false;
820 #else
821  csocket = 0;
822  if (!sock) {
823  socketDescriptor = -1;
824  isClosed = false;
825  } else {
826  csocket = static_cast<QWSSocket*>(sock); //###
827  isClosed = false;
828 
829  csocket->flush();
830  socketDescriptor = csocket->socketDescriptor();
832  connect(csocket, SIGNAL(disconnected()), this, SLOT(closeHandler()));
834  }
835 #endif //QT_NO_QWS_MULTIPROCESS
836 }
837 
842 {
844  delete command;
845 #ifndef QT_NO_QWS_MULTIPROCESS
846  delete csocket;
847 #endif
848 }
849 
850 #ifndef QT_NO_QWS_MULTIPROCESS
852 {
853  Q_D(QWSClient);
854  --d->numUnbufferedSurfaces;
855 }
856 
858 {
859  Q_D(QWSClient);
860  ++d->numUnbufferedSurfaces;
861 }
862 #endif // QT_NO_QWS_MULTIPROCESS
863 
868 {
869  id = i;
870 }
871 
873 {
874  isClosed = true;
876 }
877 
879 {
880 #if defined(QWS_SOCKET_DEBUG)
881  qDebug("Client %p error %s", this, csocket ? csocket->errorString().toLatin1().constData() : "(no socket)");
882 #endif
883  isClosed = true;
884 //####Do we need to clean out the pipes?
885 
887 }
888 
892 int QWSClient::socket() const
893 {
894  return socketDescriptor;
895 }
896 
901 {
902 #ifndef QT_NO_QWS_MULTIPROCESS
903  if (csocket) {
904  // qDebug() << "QWSClient::sendEvent type " << event->type << " socket state " << csocket->state();
906  event->write(csocket);
907  }
908  }
909  else
910 #endif
911  {
912  qt_client_enqueue(event);
913  }
914 }
915 
919 void QWSClient::sendRegionEvent(int winid, QRegion rgn, int type
920 #ifdef QT_QWS_CLIENTBLIT
921  , int id
922 #endif
923  )
924 {
925 #ifndef QT_NO_QWS_MULTIPROCESS
926  Q_D(QWSClient);
927  if (d->clientLock)
928  d->clientLock->lock(QWSLock::RegionEvent);
929 #endif
930 
932  event.setData(winid, rgn, type);
933 #ifdef QT_QWS_CLIENTBLIT
934  event.simpleData.id = id;
935 #endif
936 
937 // qDebug() << "Sending Region event to" << winid << "rgn" << rgn << "type" << type;
938 
939  sendEvent(&event);
940 }
941 
942 extern int qt_servershmid;
943 
947 void QWSClient::sendConnectedEvent(const char *display_spec)
948 {
950  event.simpleData.window = 0;
951  event.simpleData.len = strlen(display_spec) + 1;
952  event.simpleData.clientId = cid;
953  event.simpleData.servershmid = qt_servershmid;
954  char * tmp=(char *)display_spec;
955  event.setData(tmp, event.simpleData.len);
956  sendEvent(&event);
957 }
958 
963 {
965  event.simpleData.window = 0;
966  event.simpleData.rect = rect;
967  sendEvent(&event);
968 }
969 
973 #ifndef QT_NO_QWS_PROPERTIES
975 {
977  event.simpleData.window = 0; // not used yet
978  event.simpleData.property = property;
979  event.simpleData.state = state;
980  sendEvent(&event);
981 }
982 
986 void QWSClient::sendPropertyReplyEvent(int property, int len, const char *data)
987 {
989  event.simpleData.window = 0; // not used yet
990  event.simpleData.property = property;
991  event.simpleData.len = len;
992  event.setData(data, len);
993  sendEvent(&event);
994 }
995 #endif //QT_NO_QWS_PROPERTIES
996 
1001 {
1003  event.simpleData.window = windowid;
1004  sendEvent(&event);
1005 }
1006 
1011 {
1013  event.simpleData.window = windowid;
1014  event.simpleData.requestor = cmd->simpleData.requestor;
1015  event.simpleData.property = cmd->simpleData.selection;
1016  event.simpleData.mimeTypes = cmd->simpleData.mimeTypes;
1017  sendEvent(&event);
1018 }
1019 
1020 #ifndef QT_NO_QWSEMBEDWIDGET
1021 
1025  const QRegion &region)
1026 {
1028  event.setData(windowid, type, region);
1029  sendEvent(&event);
1030 }
1031 #endif // QT_NO_QWSEMBEDWIDGET
1032 
1060 /*********************************************************************
1061  *
1062  * Class: QWSServer
1063  *
1064  *********************************************************************/
1065 
1390 {
1393 
1396 
1397 };
1398 
1400  QObject(*new QWSServerPrivate, parent)
1401 {
1402  Q_D(QWSServer);
1403  QT_TRY {
1404  d->initServer(flags);
1405  } QT_CATCH(...) {
1406  qwsServer = 0;
1407  qwsServerPrivate = 0;
1408  QT_RETHROW;
1409  }
1410 }
1411 
1412 #ifdef QT3_SUPPORT
1413 
1417 QWSServer::QWSServer(int flags, QObject *parent, const char *name) :
1418  QObject(*new QWSServerPrivate, parent)
1419 {
1420  Q_D(QWSServer);
1422  d->initServer(flags);
1423 }
1424 #endif
1425 
1426 
1427 #ifndef QT_NO_QWS_MULTIPROCESS
1428 static void ignoreSignal(int) {} // Used to eat SIGPIPE signals below
1429 #endif
1430 
1431 bool QWSServerPrivate::screensaverblockevent( int index, int *screensaverinterval, bool isDown )
1432 {
1433  static bool ignoreEvents[2] = { false, false };
1434  if ( isDown ) {
1435  if ( !ignoreEvents[index] ) {
1436  bool wake = false;
1437  if ( screensaverintervals ) {
1438  if ( screensaverinterval != screensaverintervals ) {
1439  wake = true;
1440  }
1441  }
1442  if ( screensaverblockevents && wake ) {
1443 #ifdef EVENT_BLOCK_DEBUG
1444  qDebug( "waking the screen" );
1445 #endif
1446  ignoreEvents[index] = true;
1447  } else if ( !screensaverblockevents ) {
1448 #ifdef EVENT_BLOCK_DEBUG
1449  qDebug( "the screen was already awake" );
1450 #endif
1451  ignoreEvents[index] = false;
1452  }
1453  }
1454  } else {
1455  if ( ignoreEvents[index] ) {
1456 #ifdef EVENT_BLOCK_DEBUG
1457  qDebug( "mouseup?" );
1458 #endif
1459  ignoreEvents[index] = false;
1460  return true;
1461  }
1462  }
1463  return ignoreEvents[index];
1464 }
1465 
1467 {
1468  Q_Q(QWSServer);
1469  Q_ASSERT(!qwsServer);
1470  qwsServer = q;
1471  qwsServerPrivate = this;
1472  disablePainting = false;
1473 #ifndef QT_NO_QWS_MULTIPROCESS
1474  ssocket = new QWSServerSocket(qws_qtePipeFilename(), q);
1475  QObject::connect(ssocket, SIGNAL(newConnection()), q, SLOT(_q_newConnection()));
1476 
1477  if ( !ssocket->isListening()) {
1478  perror("QWSServerPrivate::initServer: server socket not listening");
1479  qFatal("Failed to bind to %s", qws_qtePipeFilename().toLatin1().constData());
1480  }
1481 
1482  struct linger tmp;
1483  tmp.l_onoff=1;
1484  tmp.l_linger=0;
1485  setsockopt(ssocket->socketDescriptor(),SOL_SOCKET,SO_LINGER,(char *)&tmp,sizeof(tmp));
1486 
1487 
1488  signal(SIGPIPE, ignoreSignal); //we get it when we read
1489 #endif
1490  focusw = 0;
1491  mouseGrabber = 0;
1492  mouseGrabbing = false;
1493  inputMethodMouseGrabbed = false;
1494  keyboardGrabber = 0;
1495  keyboardGrabbing = false;
1496 #ifndef QT_NO_QWS_CURSOR
1497  haveviscurs = false;
1498  cursor = 0;
1499  nextCursor = 0;
1500 #endif
1501 
1502 #ifndef QT_NO_QWS_MULTIPROCESS
1503 
1504  if (!geteuid()) {
1505 #if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE)
1506  if(mount(0,"/var/shm", "shm", 0, 0)) {
1507  /* This just confuses people with 2.2 kernels
1508  if (errno != EBUSY)
1509  qDebug("Failed mounting shm fs on /var/shm: %s",strerror(errno));
1510  */
1511  }
1512 #endif
1513  }
1514 #endif
1515 
1516  // no selection yet
1517  selectionOwner.windowid = -1;
1518  selectionOwner.time.set(-1, -1, -1, -1);
1519 
1520  cleanupFontsDir();
1521 
1522  // initialize the font database
1523  // from qfontdatabase_qws.cpp
1524  extern void qt_qws_init_fontdb();
1526 
1527  openDisplay();
1528 
1529  screensavertimer = new QTimer(q);
1530  screensavertimer->setSingleShot(true);
1531  QObject::connect(screensavertimer, SIGNAL(timeout()), q, SLOT(_q_screenSaverTimeout()));
1532  _q_screenSaverWake();
1533 
1534  clientMap[-1] = new QWSClient(q, 0, 0);
1535 
1536  if (!bgBrush)
1537  bgBrush = new QBrush(QColor(0x20, 0xb0, 0x50));
1538 
1539  initializeCursor();
1540 
1541  // input devices
1542  if (!(flags&QWSServer::DisableMouse)) {
1543  q->openMouse();
1544  }
1545 #ifndef QT_NO_QWS_KEYBOARD
1546  if (!(flags&QWSServer::DisableKeyboard)) {
1547  q->openKeyboard();
1548  }
1549 #endif
1550 
1551 #if !defined(QT_NO_SOUND) && !defined(QT_EXTERNAL_SOUND_SERVER) && !defined(Q_OS_DARWIN)
1552  soundserver = new QWSSoundServer(q);
1553 #endif
1554 }
1555 
1564 {
1565  closeMouse();
1566 #ifndef QT_NO_QWS_KEYBOARD
1567  closeKeyboard();
1568 #endif
1569  d_func()->cleanupFonts(/*force =*/true);
1570 }
1571 
1576 {
1577  Q_D(QWSServer);
1578  if (e->timerId() == d->fontCleanupTimer.timerId()) {
1579  d->cleanupFonts();
1580  d->fontCleanupTimer.stop();
1581  } else {
1583  }
1584 }
1585 
1587 {
1588  Q_D(QWSServer);
1589  return d->windows;
1590 }
1591 
1596 {
1597  if (w && mouseGrabber == w) {
1598  mouseGrabber = 0;
1599  mouseGrabbing = false;
1600 #ifndef QT_NO_QWS_CURSOR
1601  if (nextCursor) {
1602  // Not grabbing -> set the correct cursor
1603  setCursor(nextCursor);
1604  nextCursor = 0;
1605  }
1606 #endif
1607  }
1608 }
1609 
1614 {
1615  if (keyboardGrabber == w) {
1616  keyboardGrabber = 0;
1617  keyboardGrabbing = false;
1618  }
1619 }
1620 
1622 {
1623  w->shuttingDown();
1624  if (focusw == w)
1625  setFocus(w,false);
1626  if (mouseGrabber == w)
1627  releaseMouse(w);
1628  if (keyboardGrabber == w)
1629  releaseKeyboard(w);
1630 }
1631 
1632 
1633 #ifndef QT_NO_QWS_MULTIPROCESS
1634 
1638 {
1639  Q_Q(QWSServer);
1640  while (QWS_SOCK_BASE *sock = ssocket->nextPendingConnection()) {
1641  int socket = sock->socketDescriptor();
1642  sock->setParent(0);
1643 
1644  QWSClient *client = new QWSClient(q,sock, get_object_id());
1645  clientMap[socket] = client;
1646 
1647 #ifndef QT_NO_SXE
1648 #ifdef QTRANSPORTAUTH_DEBUG
1649  qDebug( "Transport auth connected: unix stream socket %d", socket );
1650 #endif
1651  // get a handle to the per-process authentication service
1653 
1654  // assert that this transport is trusted
1657  QTransportAuth::Trusted, socket );
1658 
1659  QAuthDevice *ad = a->recvBuf( d, sock );
1660  ad->setClient(client);
1661 
1662  QObject::connect(ad, SIGNAL(readyRead()),
1663  q, SLOT(_q_doClient()));
1664 
1665  QObject::connect(client, SIGNAL(connectionClosed()),
1666  q, SLOT(_q_clientClosed()));
1667 #else
1668  QObject::connect(client, SIGNAL(readyRead()),
1669  q, SLOT(_q_doClient()));
1670  QObject::connect(client, SIGNAL(connectionClosed()),
1671  q, SLOT(_q_clientClosed()));
1672 #endif // QT_NO_SXE
1673 
1674  client->sendConnectedEvent(qws_display_spec.constData());
1675 
1676  if (clientMap.contains(socket)) {
1677  QList<QScreen*> screens = qt_screen->subScreens();
1678  if (screens.isEmpty())
1679  screens.append(qt_screen);
1680  for (int i = 0; i < screens.size(); ++i) {
1682  QScreen *screen = screens.at(i);
1683  const QRect rect = ap->maxWindowRect(screen);
1684  if (!rect.isEmpty())
1685  client->sendMaxWindowRectEvent(rect);
1686  if (screen->isTransformed()) {
1688  event.simpleData.screen = i;
1689  event.simpleData.transformation = screen->transformOrientation();
1690  client->sendEvent(&event);
1691  }
1692  }
1693  }
1694 
1695  // pre-provide some object id's
1696  QWSCreateCommand cmd(30);
1697  invokeCreate(&cmd, client);
1698  }
1699 }
1704 {
1705  Q_Q(QWSServer);
1706  QWSClient* cl = (QWSClient*)q->sender();
1707 
1708  // Remove any queued commands for this client
1709  int i = 0;
1710  while (i < commandQueue.size()) {
1711  QWSCommandStruct *cs = commandQueue.at(i);
1712  if (cs->client == cl) {
1713  commandQueue.removeAt(i);
1714  delete cs;
1715  } else {
1716  ++i;
1717  }
1718  }
1719 
1720 #ifndef QT_NO_COP
1721  // Enfore unsubscription from all channels.
1722  QCopChannel::detach(cl);
1723 #endif
1724 
1725  // Shut down all windows for this client
1726  for (int i = 0; i < windows.size(); ++i) {
1727  QWSWindow* w = windows.at(i);
1728  if (w->forClient(cl))
1729  w->shuttingDown();
1730  }
1731 
1732  // Delete all windows for this client
1733  QRegion exposed;
1734  i = 0;
1735  while (i < windows.size()) {
1736  QWSWindow* w = windows.at(i);
1737  if (w->forClient(cl)) {
1738  windows.takeAt(i);
1739  w->c = 0; //so we don't send events to it anymore
1740  releaseMouse(w);
1741  releaseKeyboard(w);
1742  exposed += w->allocatedRegion();
1743 // rgnMan->remove(w->allocationIndex());
1744  if (focusw == w)
1745  setFocus(focusw,0);
1746  if (mouseGrabber == w)
1747  releaseMouse(w);
1748  if (i < nReserved)
1749  --nReserved;
1750 #ifndef QT_NO_QWS_PROPERTIES
1751  propertyManager.removeProperties(w->winId());
1752 #endif
1753  emit q->windowEvent(w, QWSServer::Destroy);
1754  w->d->state = QWSWindow::Destroyed; //???
1755  deletedWindows.append(w);
1756  } else {
1757  ++i;
1758  }
1759  }
1760  if (deletedWindows.count())
1761  QTimer::singleShot(0, q, SLOT(_q_deleteWindowsLater()));
1762 
1763  QWSClientPrivate *clientPrivate = cl->d_func();
1764  if (!clientPrivate->shutdown) {
1765 #if defined(QWS_DEBUG_FONTCLEANUP)
1766  qDebug() << "client" << cl->clientId() << "crashed";
1767 #endif
1768  // this would be the place to emit a signal to notify about the
1769  // crash of a client
1770  crashedClientIds.append(cl->clientId());
1771  fontCleanupTimer.start(10, q_func());
1772  }
1773  clientPrivate->shutdown = true;
1774 
1775  while (!clientPrivate->usedFonts.isEmpty()) {
1776  const QByteArray font = *clientPrivate->usedFonts.begin();
1777 #if defined(QWS_DEBUG_FONTCLEANUP)
1778  qDebug() << "dereferencing font" << font << "from disconnected client";
1779 #endif
1780  dereferenceFont(clientPrivate, font);
1781  }
1782  clientPrivate->usedFonts.clear();
1783 
1784  //qDebug("removing client %d with socket %d", cl->clientId(), cl->socket());
1785  clientMap.remove(cl->socket());
1786  if (cl == cursorClient)
1787  cursorClient = 0;
1789  (qt_screen->clearCacheFunc)(qt_screen, cl->clientId()); // remove any remaining cache entries.
1790  cl->deleteLater();
1791 
1792  update_regions();
1793  exposeRegion(exposed);
1794 }
1795 
1797 {
1798  qDeleteAll(deletedWindows);
1799  deletedWindows.clear();
1800 }
1801 
1802 #endif //QT_NO_QWS_MULTIPROCESS
1803 
1805 {
1806  if (!client->usedFonts.contains(font)) {
1807  client->usedFonts.insert(font);
1808 
1809  ++fontReferenceCount[font];
1810 #if defined(QWS_DEBUG_FONTCLEANUP)
1811  qDebug() << "Client" << client->q_func()->clientId() << "added font" << font;
1812  qDebug() << "Refcount is" << fontReferenceCount[font];
1813 #endif
1814  }
1815 }
1816 
1818 {
1819  if (client->usedFonts.contains(font)) {
1820  client->usedFonts.remove(font);
1821 
1822  Q_ASSERT(fontReferenceCount[font]);
1823  if (!--fontReferenceCount[font] && !fontCleanupTimer.isActive())
1824  fontCleanupTimer.start(FontCleanupInterval, q_func());
1825 
1826 #if defined(QWS_DEBUG_FONTCLEANUP)
1827  qDebug() << "Client" << client->q_func()->clientId() << "removed font" << font;
1828  qDebug() << "Refcount is" << fontReferenceCount[font];
1829 #endif
1830  }
1831 }
1832 
1833 static void cleanupFontsDir()
1834 {
1835  static bool dontDelete = !qgetenv("QWS_KEEP_FONTS").isEmpty();
1836  if (dontDelete)
1837  return;
1838 
1839  extern QString qws_fontCacheDir();
1840  QDir dir(qws_fontCacheDir(), QLatin1String("*.qsf"));
1841  for (uint i = 0; i < dir.count(); ++i) {
1842 #if defined(QWS_DEBUG_FONTCLEANUP)
1843  qDebug() << "removing stale font file" << dir[i];
1844 #endif
1845  dir.remove(dir[i]);
1846  }
1847 }
1848 
1850 {
1851  static bool dontDelete = !qgetenv("QWS_KEEP_FONTS").isEmpty();
1852  if (dontDelete)
1853  return;
1854 
1855 #if defined(QWS_DEBUG_FONTCLEANUP)
1856  qDebug() << "cleanupFonts()";
1857 #endif
1858  if (!fontReferenceCount.isEmpty()) {
1859  QMap<QByteArray, int>::Iterator it = fontReferenceCount.begin();
1860  while (it != fontReferenceCount.end()) {
1861  if (it.value() && !force) {
1862  ++it;
1863  continue;
1864  }
1865 
1866  const QByteArray &fontName = it.key();
1867 #if defined(QWS_DEBUG_FONTCLEANUP)
1868  qDebug() << "removing unused font file" << fontName;
1869 #endif
1870  QT_TRY {
1871  QFile::remove(QFile::decodeName(fontName));
1872  sendFontRemovedEvent(fontName);
1873 
1874  it = fontReferenceCount.erase(it);
1875  } QT_CATCH(...) {
1876  // so we were not able to remove the font.
1877  // don't be angry and just continue with the next ones.
1878  ++it;
1879  }
1880  }
1881  }
1882 
1883  if (crashedClientIds.isEmpty())
1884  return;
1885 
1886  QList<QByteArray> removedFonts;
1887 #if !defined(QT_NO_QWS_QPF2) && !defined(QT_FONTS_ARE_RESOURCES)
1888  removedFonts = QFontEngineQPF::cleanUpAfterClientCrash(crashedClientIds);
1889 #endif
1890  crashedClientIds.clear();
1891 
1892  for (int i = 0; i < removedFonts.count(); ++i)
1893  sendFontRemovedEvent(removedFonts.at(i));
1894 }
1895 
1897 {
1899  event.simpleData.type = QWSFontEvent::FontRemoved;
1900  event.setData(font.constData(), font.length(), false);
1901 
1902  QMap<int,QWSClient*>::const_iterator it = clientMap.constBegin();
1903  for (; it != clientMap.constEnd(); ++it)
1904  (*it)->sendEvent(&event);
1905 }
1906 
1911 {
1912 #ifndef QT_NO_QWS_MULTIPROCESS
1913  QIODevice *socket = 0;
1914 #endif
1915 #ifndef QT_NO_SXE
1916  if (socketDescriptor != -1) // not server socket
1918 #if QTRANSPORTAUTH_DEBUG
1919  if (socket) {
1920  char displaybuf[1024];
1921  qint64 bytes = socket->bytesAvailable();
1922  if ( bytes > 511 ) bytes = 511;
1923  hexstring( displaybuf, ((unsigned char *)(reinterpret_cast<QAuthDevice*>(socket)->buffer().constData())), bytes );
1924  qDebug( "readMoreCommand: %lli bytes - %s", socket->bytesAvailable(), displaybuf );
1925  }
1926 #endif
1927 #endif // QT_NO_SXE
1928 
1929 #ifndef QT_NO_QWS_MULTIPROCESS
1930  if (!socket)
1931  socket = csocket; // server socket
1932  if (socket) {
1933  // read next command
1934  if (!command) {
1935  int command_type = qws_read_uint(socket);
1936 
1937  if (command_type >= 0)
1938  command = QWSCommand::factory(command_type);
1939  }
1940  if (command) {
1941  if (command->read(socket)) {
1942  // Finished reading a whole command.
1943  QWSCommand* result = command;
1944  command = 0;
1945  return result;
1946  }
1947  }
1948 
1949  // Not finished reading a whole command.
1950  return 0;
1951  } else
1952 #endif // QT_NO_QWS_MULTIPROCESS
1953  {
1954  QList<QWSCommand*> *serverQueue = qt_get_server_queue();
1955  return serverQueue->isEmpty() ? 0 : serverQueue->takeFirst();
1956  }
1957 }
1958 
1959 
1964 {
1965  if (qwsServerPrivate)
1966  qwsServerPrivate->doClient(qwsServerPrivate->clientMap.value(-1));
1967 }
1968 
1969 
1970 #ifndef QT_NO_QWS_MULTIPROCESS
1972 {
1973  Q_Q(QWSServer);
1974 
1975  QWSClient* client;
1976 #ifndef QT_NO_SXE
1977  QAuthDevice *ad = qobject_cast<QAuthDevice*>(q->sender());
1978  if (ad)
1979  client = (QWSClient*)ad->client();
1980  else
1981 #endif
1982  client = (QWSClient*)q->sender();
1983 
1984  if (doClientIsActive) {
1985  pendingDoClients.append(client);
1986  return;
1987  }
1988  doClientIsActive = true;
1989 
1990  doClient(client);
1991 
1992  while (!pendingDoClients.isEmpty()) {
1993  doClient(pendingDoClients.takeFirst());
1994  }
1995 
1996  doClientIsActive = false;
1997 }
1998 #endif // QT_NO_QWS_MULTIPROCESS
1999 
2001 {
2002  QWSCommand* command=client->readMoreCommand();
2003 
2004  while (command) {
2005  QWSCommandStruct *cs = new QWSCommandStruct(command, client);
2006  commandQueue.append(cs);
2007  // Try for some more...
2008  command=client->readMoreCommand();
2009  }
2010 
2011  while (!commandQueue.isEmpty()) {
2012  QWSCommandStruct *cs = commandQueue.takeAt(0);
2013  switch (cs->command->type) {
2014  case QWSCommand::Identify:
2015  invokeIdentify((QWSIdentifyCommand*)cs->command, cs->client);
2016  break;
2017  case QWSCommand::Create:
2018  invokeCreate((QWSCreateCommand*)cs->command, cs->client);
2019  break;
2020 #ifndef QT_NO_QWS_MULTIPROCESS
2021  case QWSCommand::Shutdown:
2022  cs->client->d_func()->shutdown = true;
2023  break;
2024 #endif
2026  invokeRegionName((QWSRegionNameCommand*)cs->command, cs->client);
2027  break;
2028  case QWSCommand::Region:
2029  invokeRegion((QWSRegionCommand*)cs->command, cs->client);
2030  cs->client->d_func()->unlockCommunication();
2031  break;
2033  invokeRegionMove((QWSRegionMoveCommand*)cs->command, cs->client);
2034  cs->client->d_func()->unlockCommunication();
2035  break;
2037  invokeRegionDestroy((QWSRegionDestroyCommand*)cs->command, cs->client);
2038  break;
2039 #ifndef QT_NO_QWS_PROPERTIES
2041  invokeAddProperty((QWSAddPropertyCommand*)cs->command);
2042  break;
2044  invokeSetProperty((QWSSetPropertyCommand*)cs->command);
2045  break;
2047  invokeRemoveProperty((QWSRemovePropertyCommand*)cs->command);
2048  break;
2050  invokeGetProperty((QWSGetPropertyCommand*)cs->command, cs->client);
2051  break;
2052 #endif
2054  invokeSetSelectionOwner((QWSSetSelectionOwnerCommand*)cs->command);
2055  break;
2057  invokeSetFocus((QWSRequestFocusCommand*)cs->command, cs->client);
2058  break;
2060  invokeSetAltitude((QWSChangeAltitudeCommand*)cs->command,
2061  cs->client);
2062  cs->client->d_func()->unlockCommunication();
2063  break;
2065  invokeSetOpacity((QWSSetOpacityCommand*)cs->command,
2066  cs->client);
2067  break;
2068 
2069 #ifndef QT_NO_QWS_CURSOR
2071  invokeDefineCursor((QWSDefineCursorCommand*)cs->command, cs->client);
2072  break;
2074  invokeSelectCursor((QWSSelectCursorCommand*)cs->command, cs->client);
2075  break;
2077  invokePositionCursor((QWSPositionCursorCommand*)cs->command, cs->client);
2078  break;
2079 #endif
2080  case QWSCommand::GrabMouse:
2081  invokeGrabMouse((QWSGrabMouseCommand*)cs->command, cs->client);
2082  break;
2084  invokeGrabKeyboard((QWSGrabKeyboardCommand*)cs->command, cs->client);
2085  break;
2086 #if !defined(QT_NO_SOUND) && !defined(Q_OS_DARWIN)
2087  case QWSCommand::PlaySound:
2088  invokePlaySound((QWSPlaySoundCommand*)cs->command, cs->client);
2089  break;
2090 #endif
2091 #ifndef QT_NO_COP
2093  invokeRegisterChannel((QWSQCopRegisterChannelCommand*)cs->command,
2094  cs->client);
2095  break;
2096  case QWSCommand::QCopSend:
2097  invokeQCopSend((QWSQCopSendCommand*)cs->command, cs->client);
2098  break;
2099 #endif
2100 #ifndef QT_NO_QWS_INPUTMETHODS
2101  case QWSCommand::IMUpdate:
2102  invokeIMUpdate((QWSIMUpdateCommand*)cs->command, cs->client);
2103  break;
2105  invokeIMResponse((QWSIMResponseCommand*)cs->command, cs->client);
2106  break;
2107  case QWSCommand::IMMouse:
2108  {
2109  if (current_IM) {
2111  current_IM->mouseHandler(cmd->simpleData.index,
2112  cmd->simpleData.state);
2113  }
2114  }
2115  break;
2116 #endif
2117  case QWSCommand::Font:
2118  invokeFont((QWSFontCommand *)cs->command, cs->client);
2119  break;
2121  invokeRepaintRegion((QWSRepaintRegionCommand*)cs->command,
2122  cs->client);
2123  cs->client->d_func()->unlockCommunication();
2124  break;
2125 #ifndef QT_NO_QWSEMBEDWIDGET
2126  case QWSCommand::Embed:
2127  invokeEmbed(static_cast<QWSEmbedCommand*>(cs->command),
2128  cs->client);
2129  break;
2130 #endif
2132  invokeScreenTransform(static_cast<QWSScreenTransformCommand*>(cs->command),
2133  cs->client);
2134  break;
2135  }
2136  delete cs;
2137  }
2138 }
2139 
2140 
2142 {
2143 #ifndef QT_NO_QWS_CURSOR
2144  if (qt_screencursor)
2145  qt_screencursor->show();
2146 #endif
2147 }
2148 
2150 {
2151 #ifndef QT_NO_QWS_CURSOR
2152  if (qt_screencursor)
2153  qt_screencursor->hide();
2154 #endif
2155 }
2156 
2169 void QWSServer::enablePainting(bool enable)
2170 {
2171  Q_D(QWSServer);
2172 
2173  if (d->disablePainting == !enable)
2174  return;
2175 
2176  d->disablePainting = !enable;
2177 
2178  if (enable) {
2179  // Reset the server side allocated regions to ensure update_regions()
2180  // will send out region events.
2181  for (int i = 0; i < d->windows.size(); ++i) {
2182  QWSWindow *w = d->windows.at(i);
2184 #ifdef QT_QWS_CLIENTBLIT
2185  w->setDirectPaintRegion(QRegion());
2186 #endif
2187  }
2188  d->update_regions();
2189  d->showCursor();
2190  } else {
2191  // Disable painting by clients by taking away their allocated region.
2192  // To ensure mouse events are still delivered to the correct windows,
2193  // the allocated regions are not modified on the server.
2194  for (int i = 0; i < d->windows.size(); ++i) {
2195  QWSWindow *w = d->windows.at(i);
2196  w->client()->sendRegionEvent(w->winId(), QRegion(),
2198 #ifdef QT_QWS_CLIENTBLIT
2199  w->client()->sendRegionEvent(w->winId(), QRegion(),
2200  QWSRegionEvent::DirectPaint);
2201 #endif
2202  }
2203  d->hideCursor();
2204  }
2205 }
2206 
2214 {
2215  Q_D(QWSServer);
2216  d->exposeRegion(QScreen::instance()->region());
2217 //### send repaint to non-buffered windows
2218 }
2219 
2230 {
2231  Q_D(QWSServer);
2232  d->exposeRegion(r);
2233 //### send repaint to non-buffered windows
2234 }
2235 
2250 {
2251  QList<QScreen*> subScreens = qt_screen->subScreens();
2252  if (subScreens.isEmpty() && qt_screen != 0)
2253  subScreens.append(qt_screen);
2254 
2255  for (int i = 0; i < subScreens.size(); ++i) {
2256  const QScreen *screen = subScreens.at(i);
2257  const QRect r = (screen->region() & rect).boundingRect();
2258  if (r.isEmpty())
2259  continue;
2260 
2262  if (ap->maxWindowRect(screen) != r) {
2263  ap->setMaxWindowRect(screen, i, r);
2264  qwsServerPrivate->sendMaxWindowRectEvents(r);
2265  }
2266  }
2267 }
2268 
2273 {
2274  QMap<int,QWSClient*>::const_iterator it = clientMap.constBegin();
2275  for (; it != clientMap.constEnd(); ++it)
2276  (*it)->sendMaxWindowRectEvent(rect);
2277 }
2278 
2292 void QWSServer::setDefaultMouse(const char *m)
2293 {
2294  *defaultMouse() = QString::fromAscii(m);
2295 }
2296 
2310 {
2312 }
2313 
2314 #ifndef QT_NO_QWS_CURSOR
2315 static bool prevWin;
2316 #endif
2317 
2318 
2319 extern int *qt_last_x,*qt_last_y;
2320 
2321 
2334 void QWSServer::sendMouseEvent(const QPoint& pos, int state, int wheel)
2335 {
2336  bool block = qwsServerPrivate->screensaverblockevent(MOUSE, qwsServerPrivate->screensaverinterval, state);
2337 #ifdef EVENT_BLOCK_DEBUG
2338  qDebug() << "sendMouseEvent" << pos.x() << pos.y() << state << (block ? "block" : "pass");
2339 #endif
2340 
2341  if (state || wheel)
2342  qwsServerPrivate->_q_screenSaverWake();
2343 
2344  if ( block )
2345  return;
2346 
2347  QPoint tpos;
2348  // transformations
2349  if (qt_screen->isTransformed()) {
2351  tpos = qt_screen->mapFromDevice(pos, s);
2352  } else {
2353  tpos = pos;
2354  }
2355 
2356  if (qt_last_x) {
2357  *qt_last_x = tpos.x();
2358  *qt_last_y = tpos.y();
2359  }
2360  QWSServer::mousePosition = tpos;
2361  qwsServerPrivate->mouseState = state;
2362 
2363 #ifndef QT_NO_QWS_INPUTMETHODS
2364  const int btnMask = Qt::LeftButton | Qt::RightButton | Qt::MidButton;
2365  int stroke_count; // number of strokes to keep shown.
2366  if (force_reject_strokeIM || !current_IM)
2367  {
2368  stroke_count = 0;
2369  } else {
2370  stroke_count = current_IM->filter(tpos, state, wheel);
2371  }
2372 
2373  if (stroke_count == 0) {
2374  if (state&btnMask)
2375  force_reject_strokeIM = true;
2376  QWSServerPrivate::sendMouseEventUnfiltered(tpos, state, wheel);
2377  }
2378  // stop force reject after stroke ends.
2379  if (state&btnMask && force_reject_strokeIM)
2380  force_reject_strokeIM = false;
2381  // on end of stroke, force_rejct
2382  // and once a stroke is rejected, do not try again till pen is lifted
2383 #else
2384  QWSServerPrivate::sendMouseEventUnfiltered(tpos, state, wheel);
2385 #endif // end QT_NO_QWS_FSIM
2386 }
2387 
2388 void QWSServerPrivate::sendMouseEventUnfiltered(const QPoint &pos, int state, int wheel)
2389 {
2390  const int btnMask = Qt::LeftButton | Qt::RightButton | Qt::MidButton;
2392 
2393  QWSWindow *win = qwsServer->windowAt(pos);
2394 
2395  QWSClient *serverClient = qwsServerPrivate->clientMap.value(-1);
2396  QWSClient *winClient = win ? win->client() : 0;
2397 
2398 
2399  bool imMouse = false;
2400 #ifndef QT_NO_QWS_INPUTMETHODS
2401  // check for input method window
2402  if (current_IM && current_IM_winId != -1) {
2404  qwsServerPrivate->focusw;
2405 
2406  imMouse = kbw == win;
2407  if ( !imMouse ) {
2408  QWidget *target = winClient == serverClient ?
2409  QApplication::widgetAt(pos) : 0;
2410  imMouse = target && (target->testAttribute(Qt::WA_InputMethodTransparent));
2411  }
2412  }
2413 #endif
2414 
2415  //If grabbing window disappears, grab is still active until
2416  //after mouse release.
2417  if ( qwsServerPrivate->mouseGrabber && (!imMouse || qwsServerPrivate->inputMethodMouseGrabbed)) {
2418  win = qwsServerPrivate->mouseGrabber;
2419  winClient = win ? win->client() : 0;
2420  }
2421  event.simpleData.window = win ? win->id : 0;
2422 
2423 #ifndef QT_NO_QWS_CURSOR
2424  if (qt_screencursor)
2425  qt_screencursor->move(pos.x(),pos.y());
2426 
2427  // Arrow cursor over desktop
2428  // prevWin remembers if the last event was over a window
2429  if (!win && prevWin) {
2430  if (!qwsServerPrivate->mouseGrabber)
2432  else
2433  qwsServerPrivate->nextCursor = QWSCursor::systemCursor(Qt::ArrowCursor);
2434  prevWin = false;
2435  }
2436  // reset prevWin
2437  if (win && !prevWin)
2438  prevWin = true;
2439 #endif
2440 
2441  if ((state&btnMask) && !qwsServerPrivate->mouseGrabbing) {
2442  qwsServerPrivate->mouseGrabber = win;
2443  if (imMouse)
2444  qwsServerPrivate->inputMethodMouseGrabbed = true;
2445  }
2446  if (!(state&btnMask))
2447  qwsServerPrivate->inputMethodMouseGrabbed = false;
2448 
2449  event.simpleData.x_root=pos.x();
2450  event.simpleData.y_root=pos.y();
2451  event.simpleData.state=state | qws_keyModifiers;
2452  event.simpleData.delta = wheel;
2453  event.simpleData.time=qwsServerPrivate->timer.elapsed();
2454 
2455  static int oldstate = 0;
2456 
2457 #ifndef QT_NO_QWS_INPUTMETHODS
2458  //tell the input method if we click on a different window that is not IM transparent
2459  bool isPress = state > oldstate;
2460  if (isPress && !imMouse && current_IM && current_IM_winId != -1)
2461  current_IM->mouseHandler(-1, QWSServer::MouseOutside);
2462 #endif
2463 
2464  if (serverClient)
2465  serverClient->sendEvent(&event);
2466  if (winClient && winClient != serverClient)
2467  winClient->sendEvent(&event);
2468 
2469  if ( !imMouse ) {
2470  // Make sure that if we leave a window, that window gets one last mouse
2471  // event so that it knows the mouse has left.
2472  QWSClient *oldClient = qwsServer->d_func()->cursorClient;
2473  if (oldClient && oldClient != winClient && oldClient != serverClient) {
2474  event.simpleData.state = oldstate | qws_keyModifiers;
2475  oldClient->sendEvent(&event);
2476  }
2477  }
2478 
2479  oldstate = state;
2480  if ( !imMouse )
2481  qwsServer->d_func()->cursorClient = winClient;
2482 
2483  if (!(state&btnMask) && !qwsServerPrivate->mouseGrabbing)
2484  qwsServerPrivate->releaseMouse(qwsServerPrivate->mouseGrabber);
2485 }
2486 
2495 {
2496  if (qwsServerPrivate->mousehandlers.empty())
2497  return 0;
2498  return qwsServerPrivate->mousehandlers.first();
2499 }
2500 
2514 {
2515  return qwsServerPrivate->mousehandlers;
2516 }
2517 
2518 
2519 // called by QWSMouseHandler constructor, not user code.
2535 {
2536  if (!mh)
2537  return;
2538  qwsServerPrivate->mousehandlers.removeAll(mh);
2539  qwsServerPrivate->mousehandlers.prepend(mh);
2540 }
2541 
2548 {
2550  for (int i=0; i < qwsServerPrivate->windows.size(); ++i) {
2551  QWSWindow *window = qwsServerPrivate->windows.at(i);
2553  qwi->winid=window->winId();
2554  qwi->clientid=window->client()->clientId();
2555  ret->append(qwi);
2556  }
2557  return ret;
2558 }
2559 
2560 #ifndef QT_NO_COP
2561 
2565  const QString &msg, const QByteArray &data,
2566  bool response)
2567 {
2568  Q_ASSERT(c);
2569 
2571  event.channel = ch.toLatin1();
2572  event.message = msg.toLatin1();
2573  event.data = data;
2574  event.simpleData.is_response = response;
2575  event.simpleData.lchannel = ch.length();
2576  event.simpleData.lmessage = msg.length();
2577  event.simpleData.ldata = data.size();
2578  int l = event.simpleData.lchannel + event.simpleData.lmessage +
2579  event.simpleData.ldata;
2580 
2581  // combine channel, message and data into one block of raw bytes
2582  char *tmp = new char [l];
2583  char *d = tmp;
2584  memcpy(d, event.channel.constData(), event.simpleData.lchannel);
2585  d += event.simpleData.lchannel;
2586  memcpy(d, event.message.constData(), event.simpleData.lmessage);
2587  d += event.simpleData.lmessage;
2588  memcpy(d, data.constData(), event.simpleData.ldata);
2589 
2590  event.setDataDirect(tmp, l);
2591 
2592  c->sendEvent(&event);
2593 }
2594 #endif
2595 
2607 {
2608  Q_D(QWSServer);
2609  for (int i=0; i<d->windows.size(); ++i) {
2610  QWSWindow* w = d->windows.at(i);
2611  if (w->allocatedRegion().contains(pos))
2612  return w;
2613  }
2614  return 0;
2615 }
2616 
2617 #ifndef QT_NO_QWS_KEYBOARD
2618 static inline int keyUnicode(int keycode)
2619 {
2620  int code = 0xffff;
2621 
2622  if (keycode >= Qt::Key_A && keycode <= Qt::Key_Z)
2623  code = keycode - Qt::Key_A + 'a';
2624  else if (keycode >= Qt::Key_0 && keycode <= Qt::Key_9)
2625  code = keycode - Qt::Key_0 + '0';
2626 
2627  return code;
2628 }
2629 #endif
2630 
2652 void QWSServer::sendKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
2653  bool isPress, bool autoRepeat)
2654 {
2655  qws_keyModifiers = modifiers;
2656 
2657  if (isPress) {
2658  if (keycode != Qt::Key_F34 && keycode != Qt::Key_F35)
2659  qwsServerPrivate->_q_screenSaverWake();
2660  }
2661 
2662 #ifndef QT_NO_QWS_INPUTMETHODS
2663 
2664  if (!current_IM || !current_IM->filter(unicode, keycode, modifiers, isPress, autoRepeat))
2665  QWSServerPrivate::sendKeyEventUnfiltered(unicode, keycode, modifiers, isPress, autoRepeat);
2666 #else
2667  QWSServerPrivate::sendKeyEventUnfiltered(unicode, keycode, modifiers, isPress, autoRepeat);
2668 #endif
2669 }
2670 
2671 void QWSServerPrivate::sendKeyEventUnfiltered(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
2672  bool isPress, bool autoRepeat)
2673 {
2674  QWSWindow *win = keyboardGrabber ? keyboardGrabber : qwsServerPrivate->focusw;
2675 
2676 #ifndef QT_NO_QWS_KEYBOARD
2677  if (unicode < 0)
2678  unicode = keyUnicode(keycode);
2679 #endif
2680 
2682  event.simpleData.window = win ? win->winId() : 0;
2683  event.simpleData.unicode = unicode;
2684  event.simpleData.keycode = keycode;
2685  event.simpleData.modifiers = modifiers;
2686  event.simpleData.is_press = isPress;
2687  event.simpleData.is_auto_repeat = autoRepeat;
2688 
2689  QWSClient *serverClient = qwsServerPrivate->clientMap.value(-1);
2690  QWSClient *winClient = win ? win->client() : 0;
2691  if (serverClient)
2692  serverClient->sendEvent(&event);
2693  if (winClient && winClient != serverClient)
2694  winClient->sendEvent(&event);
2695 }
2696 
2701 {
2702  qwsServer->enablePainting(false);
2703 #ifndef QT_NO_QWS_CURSOR
2704  if (qt_screencursor)
2705  qt_screencursor->hide();
2706 #endif
2707  QWSDisplay::grab(true);
2708  qt_screen->disconnect();
2709 }
2710 
2715 {
2717  qwsServerPrivate->swidth = qt_screen->deviceWidth();
2718  qwsServerPrivate->sheight = qt_screen->deviceHeight();
2719 
2721 #ifndef QT_NO_QWS_CURSOR
2722  if (qt_screencursor)
2723  qt_screencursor->show();
2724 #endif
2726  ap->setMaxWindowRect(qt_screen, 0,
2727  QRect(0, 0, qt_screen->width(), qt_screen->height()));
2728  QSize olds = qApp->desktop()->size();
2729  qApp->desktop()->resize(qt_screen->width(), qt_screen->height());
2730  qApp->postEvent(qApp->desktop(), new QResizeEvent(qApp->desktop()->size(), olds));
2731  qwsServer->enablePainting(true);
2732  qwsServer->refresh();
2733  qDebug("Desktop size: %dx%d", qApp->desktop()->width(), qApp->desktop()->height());
2734 }
2735 
2737 {
2738 #ifndef QT_NO_QWS_CURSOR
2739  if (!qt_screencursor)
2740  return;
2741  qt_screencursor->hide();
2742  qt_screencursor->show();
2743 #endif
2744 }
2745 
2746 
2747 #ifndef QT_NO_QWS_CURSOR
2748 
2762 {
2763  if (qwsServerPrivate && qwsServerPrivate->haveviscurs != vis) {
2764  QWSCursor* c = qwsServerPrivate->cursor;
2766  qwsServerPrivate->haveviscurs = vis;
2767  qwsServerPrivate->setCursor(c);
2768  }
2769 }
2770 
2779 {
2780  return qwsServerPrivate ? qwsServerPrivate->haveviscurs : true;
2781 }
2782 #endif
2783 
2784 #ifndef QT_NO_QWS_INPUTMETHODS
2785 
2786 
2802 {
2803  QWSIMEvent event;
2804 
2806  qwsServerPrivate->focusw;
2807 
2808  //if currently composing then event must go to the composing window
2809 
2810  if (current_IM_composing_win)
2812 
2813  event.simpleData.window = win ? win->winId() : 0;
2814  event.simpleData.replaceFrom = ime->replacementStart();;
2815  event.simpleData.replaceLength = ime->replacementLength();
2816 
2817  QBuffer buffer;
2818  buffer.open(QIODevice::WriteOnly);
2819  QDataStream out(&buffer);
2820 
2821  out << ime->preeditString();
2822  out << ime->commitString();
2823 
2824  const QList<QInputMethodEvent::Attribute> &attributes = ime->attributes();
2825  for (int i = 0; i < attributes.count(); ++i) {
2826  const QInputMethodEvent::Attribute &a = attributes.at(i);
2827  out << a.type << a.start << a.length << a.value;
2828  }
2829  event.setData(buffer.data(), buffer.size());
2830  QWSClient *serverClient = qwsServerPrivate->clientMap.value(-1);
2831  if (serverClient)
2832  serverClient->sendEvent(&event);
2833  if (win && win->client() && win->client() != serverClient)
2834  win->client()->sendEvent(&event);
2835 
2836  current_IM_composing_win = ime->preeditString().isEmpty() ? 0 : win;
2837  current_IM_winId = win ? win->winId() : 0;
2838 }
2839 
2840 
2852 {
2854 
2856  qwsServerPrivate->focusw;
2857  if (current_IM_composing_win)
2859 
2860  event.simpleData.window = win ? win->winId() : 0;
2861  event.simpleData.property = property;
2862  if (win && win->client())
2863  win->client()->sendEvent(&event);
2864 }
2865 
2866 
2867 
2878 {
2879  if (current_IM)
2880  current_IM->reset(); //??? send an update event instead ?
2881  current_IM = im;
2882 }
2883 
2890 #endif //QT_NO_QWS_INPUTMETHODS
2891 
2892 #ifndef QT_NO_QWS_PROPERTIES
2893 
2897 {
2898  Q_D(QWSServer);
2899  QWSServerPrivate::ClientIterator it = d->clientMap.begin();
2900  while (it != d->clientMap.end()) {
2901  QWSClient *cl = *it;
2902  ++it;
2903  cl->sendPropertyNotifyEvent(property, state);
2904  }
2905 }
2906 #endif
2907 
2909 {
2910  client->setIdentity(cmd->id);
2911 #ifndef QT_NO_QWS_MULTIPROCESS
2912  if (client->clientId() > 0)
2913  client->d_func()->setLockId(cmd->simpleData.idLock);
2914 #endif
2915 }
2916 
2918 {
2920  event.simpleData.objectid = get_object_id(cmd->count);
2921  event.simpleData.count = cmd->count;
2922  client->sendEvent(&event);
2923 }
2924 
2926 {
2927  Q_Q(QWSServer);
2928  QWSWindow* changingw = findWindow(cmd->simpleData.windowid, client);
2929  if (changingw && (changingw->name() != cmd->name || changingw->caption() !=cmd->caption)) {
2930  changingw->setName(cmd->name);
2931  changingw->setCaption(cmd->caption);
2932  emit q->windowEvent(changingw, QWSServer::Name);
2933  }
2934 }
2935 
2937 {
2938 #ifdef QWS_REGION_DEBUG
2939  qDebug("QWSServer::invokeRegion %d rects (%d)",
2941 #endif
2942 
2943  QWSWindow* changingw = findWindow(cmd->simpleData.windowid, 0);
2944  if (!changingw) {
2945  qWarning("Invalid window handle %08x",cmd->simpleData.windowid);
2946  return;
2947  }
2948  if (!changingw->forClient(client)) {
2949  qWarning("Disabled: clients changing other client's window region");
2950  return;
2951  }
2952 
2953  request_region(cmd->simpleData.windowid, cmd->surfaceKey, cmd->surfaceData,
2954  cmd->region);
2955 }
2956 
2958 {
2959  Q_Q(QWSServer);
2960  QWSWindow* changingw = findWindow(cmd->simpleData.windowid, 0);
2961  if (!changingw) {
2962  qWarning("invokeRegionMove: Invalid window handle %d",cmd->simpleData.windowid);
2963  return;
2964  }
2965  if (!changingw->forClient(client)) {
2966  qWarning("Disabled: clients changing other client's window region");
2967  return;
2968  }
2969 
2970 // changingw->setNeedAck(true);
2971  moveWindowRegion(changingw, cmd->simpleData.dx, cmd->simpleData.dy);
2972  emit q->windowEvent(changingw, QWSServer::Geometry);
2973 }
2974 
2976 {
2977  Q_Q(QWSServer);
2978  QWSWindow* changingw = findWindow(cmd->simpleData.windowid, 0);
2979  if (!changingw) {
2980  qWarning("invokeRegionDestroy: Invalid window handle %d",cmd->simpleData.windowid);
2981  return;
2982  }
2983  if (!changingw->forClient(client)) {
2984  qWarning("Disabled: clients changing other client's window region");
2985  return;
2986  }
2987 
2988  setWindowRegion(changingw, QRegion());
2989 // rgnMan->remove(changingw->allocationIndex());
2990  for (int i = 0; i < windows.size(); ++i) {
2991  if (windows.at(i) == changingw) {
2992  windows.takeAt(i);
2993  if (i < nReserved)
2994  --nReserved;
2995  break;
2996  }
2997  }
2998 
2999  handleWindowClose(changingw);
3000 #ifndef QT_NO_QWS_PROPERTIES
3001  propertyManager.removeProperties(changingw->winId());
3002 #endif
3003  emit q->windowEvent(changingw, QWSServer::Destroy);
3004  delete changingw;
3005 }
3006 
3008 {
3009  int winId = cmd->simpleData.windowid;
3010  int gain = cmd->simpleData.flag;
3011 
3012  if (gain != 0 && gain != 1) {
3013  qWarning("Only 0(lose) and 1(gain) supported");
3014  return;
3015  }
3016 
3017  QWSWindow* changingw = findWindow(winId, 0);
3018  if (!changingw)
3019  return;
3020 
3021  if (!changingw->forClient(client)) {
3022  qWarning("Disabled: clients changing other client's focus");
3023  return;
3024  }
3025 
3026  setFocus(changingw, gain);
3027 }
3028 
3029 void QWSServerPrivate::setFocus(QWSWindow* changingw, bool gain)
3030 {
3031  Q_Q(QWSServer);
3032 #ifndef QT_NO_QWS_INPUTMETHODS
3033  /*
3034  This is the logic:
3035  QWSWindow *loser = 0;
3036  if (gain && focusw != changingw)
3037  loser = focusw;
3038  else if (!gain && focusw == changingw)
3039  loser = focusw;
3040  But these five lines can be reduced to one:
3041  */
3042  if (current_IM) {
3043  QWSWindow *loser = (!gain == (focusw==changingw)) ? focusw : 0;
3044  if (loser && loser->winId() == current_IM_winId)
3046  }
3047 #endif
3048  if (gain) {
3049  if (focusw != changingw) {
3050  if (focusw) focusw->focus(0);
3051  focusw = changingw;
3052  focusw->focus(1);
3053  emit q->windowEvent(focusw, QWSServer::Active);
3054  }
3055  } else if (focusw == changingw) {
3056  if (changingw->client())
3057  changingw->focus(0);
3058  focusw = 0;
3059  // pass focus to window which most recently got it...
3060  QWSWindow* bestw=0;
3061  for (int i=0; i<windows.size(); ++i) {
3062  QWSWindow* w = windows.at(i);
3063  if (w != changingw && !w->hidden() &&
3064  (!bestw || bestw->focusPriority() < w->focusPriority()))
3065  bestw = w;
3066  }
3067  if (!bestw && changingw->focusPriority()) { // accept focus back?
3068  bestw = changingw; // must be the only one
3069  }
3070  focusw = bestw;
3071  if (focusw) {
3072  focusw->focus(1);
3073  emit q->windowEvent(focusw, QWSServer::Active);
3074  }
3075  }
3076 }
3077 
3078 
3079 
3081 {
3082  Q_UNUSED( client );
3083  int winId = cmd->simpleData.windowid;
3084  int opacity = cmd->simpleData.opacity;
3085 
3086  QWSWindow* changingw = findWindow(winId, 0);
3087 
3088  if (!changingw) {
3089  qWarning("invokeSetOpacity: Invalid window handle %d", winId);
3090  return;
3091  }
3092 
3093  int altitude = windows.indexOf(changingw);
3094  const bool wasOpaque = changingw->isOpaque();
3095  changingw->_opacity = opacity;
3096  if (wasOpaque != changingw->isOpaque())
3097  update_regions();
3098  exposeRegion(changingw->allocatedRegion(), altitude);
3099 }
3100 
3102  QWSClient *client)
3103 {
3104  Q_UNUSED(client);
3105 
3106  int winId = cmd->simpleData.windowid;
3107  int alt = cmd->simpleData.altitude;
3108  bool fixed = cmd->simpleData.fixed;
3109 #if 0
3110  qDebug("QWSServer::invokeSetAltitude winId %d alt %d)", winId, alt);
3111 #endif
3112 
3113  if (alt < -1 || alt > 1) {
3114  qWarning("QWSServer::invokeSetAltitude Only lower, raise and stays-on-top supported");
3115  return;
3116  }
3117 
3118  QWSWindow* changingw = findWindow(winId, 0);
3119  if (!changingw) {
3120  qWarning("invokeSetAltitude: Invalid window handle %d", winId);
3121  return;
3122  }
3123 
3124  if (fixed && alt >= 1) {
3125  changingw->onTop = true;
3126  }
3128  changingw->lower();
3129  else
3130  changingw->raise();
3131 
3132 // if (!changingw->forClient(client)) {
3133 // refresh();
3134 // }
3135 }
3136 
3137 #ifndef QT_NO_QWS_PROPERTIES
3139 {
3140  propertyManager.addProperty(cmd->simpleData.windowid, cmd->simpleData.property);
3141 }
3142 
3144 {
3145  Q_Q(QWSServer);
3146  if (propertyManager.setProperty(cmd->simpleData.windowid,
3147  cmd->simpleData.property,
3148  cmd->simpleData.mode,
3149  cmd->data,
3150  cmd->rawLen)) {
3151  q->sendPropertyNotifyEvent(cmd->simpleData.property,
3153 #ifndef QT_NO_QWS_INPUTMETHODS
3155  QString s((const QChar*)cmd->data, cmd->rawLen/2);
3156  emit q->markedText(s);
3157  }
3158 #endif
3159  }
3160 }
3161 
3163 {
3164  Q_Q(QWSServer);
3165  if (propertyManager.removeProperty(cmd->simpleData.windowid,
3166  cmd->simpleData.property)) {
3167  q->sendPropertyNotifyEvent(cmd->simpleData.property,
3169  }
3170 }
3171 
3172 
3173 bool QWSServerPrivate:: get_property(int winId, int property, const char *&data, int &len)
3174 {
3175  return propertyManager.getProperty(winId, property, data, len);
3176 }
3177 
3178 
3180 {
3181  const char *data;
3182  int len;
3183 
3184  if (propertyManager.getProperty(cmd->simpleData.windowid,
3185  cmd->simpleData.property,
3186  data, len)) {
3187  client->sendPropertyReplyEvent(cmd->simpleData.property, len, data);
3188  } else {
3189  client->sendPropertyReplyEvent(cmd->simpleData.property, -1, 0);
3190  }
3191 }
3192 #endif //QT_NO_QWS_PROPERTIES
3193 
3195 {
3196  qDebug("QWSServer::invokeSetSelectionOwner");
3197 
3198  SelectionOwner so;
3199  so.windowid = cmd->simpleData.windowid;
3200  so.time.set(cmd->simpleData.hour, cmd->simpleData.minute,
3201  cmd->simpleData.sec, cmd->simpleData.ms);
3202 
3203  if (selectionOwner.windowid != -1) {
3204  QWSWindow *win = findWindow(selectionOwner.windowid, 0);
3205  if (win)
3206  win->client()->sendSelectionClearEvent(selectionOwner.windowid);
3207  else
3208  qDebug("couldn't find window %d", selectionOwner.windowid);
3209  }
3210 
3211  selectionOwner = so;
3212 }
3213 
3215 {
3216  qDebug("QWSServer::invokeConvertSelection");
3217 
3218  if (selectionOwner.windowid != -1) {
3219  QWSWindow *win = findWindow(selectionOwner.windowid, 0);
3220  if (win)
3221  win->client()->sendSelectionRequestEvent(cmd, selectionOwner.windowid);
3222  else
3223  qDebug("couldn't find window %d", selectionOwner.windowid);
3224  }
3225 }
3226 
3227 #ifndef QT_NO_QWS_CURSOR
3229 {
3230  if (cmd->simpleData.height > 64 || cmd->simpleData.width > 64) {
3231  qDebug("Cannot define cursor size > 64x64");
3232  return;
3233  }
3234 
3235  delete client->cursors.take(cmd->simpleData.id);
3236 
3237  int dataLen = cmd->simpleData.height * ((cmd->simpleData.width+7) / 8);
3238 
3239  if (dataLen > 0 && cmd->data) {
3240  QWSCursor *curs = new QWSCursor(cmd->data, cmd->data + dataLen,
3241  cmd->simpleData.width, cmd->simpleData.height,
3242  cmd->simpleData.hotX, cmd->simpleData.hotY);
3243  client->cursors.insert(cmd->simpleData.id, curs);
3244  }
3245 }
3246 
3248 {
3249  int id = cmd->simpleData.id;
3250  QWSCursor *curs = 0;
3251  if (id <= Qt::LastCursor) {
3252  curs = QWSCursor::systemCursor(id);
3253  }
3254  else {
3255  QWSCursorMap cursMap = client->cursors;
3256  QWSCursorMap::Iterator it = cursMap.find(id);
3257  if (it != cursMap.end()) {
3258  curs = it.value();
3259  }
3260  }
3261  if (curs == 0) {
3263  }
3264 
3265  QWSWindow* win = findWindow(cmd->simpleData.windowid, 0);
3266  if (mouseGrabber) {
3267  // If the mouse is being grabbed, we don't want just anyone to
3268  // be able to change the cursor. We do want the cursor to be set
3269  // correctly once mouse grabbing is stopped though.
3270  if (win != mouseGrabber)
3271  nextCursor = curs;
3272  else
3273  setCursor(curs);
3274  } else if (win && win->allocatedRegion().contains(QWSServer::mousePosition)) { //##################### cursor
3275  // A non-grabbing window can only set the cursor shape if the
3276  // cursor is within its allocated region.
3277  setCursor(curs);
3278  }
3279 }
3280 
3282 {
3283  Q_Q(QWSServer);
3284  QPoint newPos(cmd->simpleData.newX, cmd->simpleData.newY);
3285  if (newPos != QWSServer::mousePosition)
3286  q->sendMouseEvent(newPos, qwsServer->d_func()->mouseState);
3287 }
3288 #endif
3289 
3291 {
3292  QWSWindow* win = findWindow(cmd->simpleData.windowid, 0);
3293  if (!win)
3294  return;
3295 
3296  if (cmd->simpleData.grab) {
3297  if (!mouseGrabber || mouseGrabber->client() == client) {
3298  mouseGrabbing = true;
3299  mouseGrabber = win;
3300  }
3301  } else {
3302  releaseMouse(mouseGrabber);
3303  }
3304 }
3305 
3307 {
3308  QWSWindow* win = findWindow(cmd->simpleData.windowid, 0);
3309  if (!win)
3310  return;
3311 
3312  if (cmd->simpleData.grab) {
3313  if (!keyboardGrabber || (keyboardGrabber->client() == client)) {
3314  keyboardGrabbing = true;
3315  keyboardGrabber = win;
3316  }
3317  } else {
3318  releaseKeyboard(keyboardGrabber);
3319  }
3320 }
3321 
3322 #if !defined(QT_NO_SOUND)
3324 {
3325 #if !defined(QT_EXTERNAL_SOUND_SERVER) && !defined(Q_OS_DARWIN)
3326  soundserver->playFile( 1, cmd->filename );
3327 #else
3328  Q_UNUSED(cmd);
3329 #endif
3330 }
3331 #endif
3332 
3333 #ifndef QT_NO_COP
3335  QWSClient *client)
3336 {
3337  // QCopChannel will force us to emit the newChannel signal if this channel
3338  // didn't already exist.
3339  QCopChannel::registerChannel(cmd->channel, client);
3340 }
3341 
3343 {
3344  QCopChannel::answer(client, cmd->channel, cmd->message, cmd->data);
3345 }
3346 
3347 #endif
3348 
3349 #ifndef QT_NO_QWS_INPUTMETHODS
3351 {
3352  if (current_IM && qwsServer) {
3353  current_IM->reset();
3354  }
3355 }
3356 
3358  QWSClient *)
3359 {
3360  if (current_IM)
3361  current_IM->queryResponse(cmd->simpleData.property, cmd->result);
3362 }
3363 
3365  QWSClient *)
3366 {
3369 
3370  if (current_IM && (current_IM_winId == cmd->simpleData.windowid || cmd->simpleData.windowid == -1))
3371  current_IM->updateHandler(cmd->simpleData.type);
3372 }
3373 
3374 #endif
3375 
3377 {
3378  QWSClientPrivate *priv = client->d_func();
3380  referenceFont(priv, cmd->fontName);
3381  } else if (cmd->simpleData.type == QWSFontCommand::StoppedUsingFont) {
3382  dereferenceFont(priv, cmd->fontName);
3383  }
3384 }
3385 
3387  QWSClient *)
3388 {
3389  QRegion r;
3391  repaint_region(cmd->simpleData.windowid, cmd->simpleData.windowFlags, cmd->simpleData.opaque, r);
3392 }
3393 
3394 #ifndef QT_NO_QWSEMBEDWIDGET
3396 {
3397  // Should find these two windows in a single loop
3398  QWSWindow *embedder = findWindow(cmd->simpleData.embedder, client);
3399  QWSWindow *embedded = findWindow(cmd->simpleData.embedded);
3400 
3401  if (!embedder) {
3402  qWarning("QWSServer: Embed command from window %i failed: No such id.",
3403  static_cast<int>(cmd->simpleData.embedder));
3404  return;
3405  }
3406 
3407  if (!embedded) {
3408  qWarning("QWSServer: Embed command on window %i failed: No such id.",
3409  static_cast<int>(cmd->simpleData.embedded));
3410  return;
3411  }
3412 
3413  switch (cmd->simpleData.type) {
3415  embedder->startEmbed(embedded);
3416  windows.removeAll(embedded);
3417  windows.insert(windows.indexOf(embedder), embedded);
3418  break;
3420  embedder->stopEmbed(embedded);
3421  break;
3422  case QWSEmbedEvent::Region:
3423  break;
3424  }
3425 
3426  embedded->client()->sendEmbedEvent(embedded->winId(),
3427  cmd->simpleData.type, cmd->region);
3428  const QRegion oldAllocated = embedded->allocatedRegion();
3429  update_regions();
3430  exposeRegion(oldAllocated - embedded->allocatedRegion(),
3431  windows.indexOf(embedded));
3432 }
3433 #endif // QT_NO_QWSEMBEDWIDGET
3434 
3436  QWSClient *client)
3437 {
3438  Q_UNUSED(client);
3439 
3441  event.simpleData.screen = cmd->simpleData.screen;
3442  event.simpleData.transformation = cmd->simpleData.transformation;
3443 
3444  QMap<int, QWSClient*>::const_iterator it = clientMap.constBegin();
3445  for (; it != clientMap.constEnd(); ++it)
3446  (*it)->sendEvent(&event);
3447 }
3448 
3450 {
3451  Q_Q(QWSServer);
3452  // Make a new window, put it on top.
3453  QWSWindow* w = new QWSWindow(id,client);
3454 
3455  // insert after "stays on top" windows
3456  bool added = false;
3457  for (int i = nReserved; i < windows.size(); ++i) {
3458  QWSWindow *win = windows.at(i);
3459  if (!win->onTop) {
3460  windows.insert(i, w);
3461  added = true;
3462  break;
3463  }
3464  }
3465  if (!added)
3466  windows.append(w);
3467  emit q->windowEvent(w, QWSServer::Create);
3468  return w;
3469 }
3470 
3472 {
3473  for (int i=0; i<windows.size(); ++i) {
3474  QWSWindow* w = windows.at(i);
3475  if (w->winId() == windowid)
3476  return w;
3477  }
3478  if (client)
3479  return newWindow(windowid,client);
3480  else
3481  return 0;
3482 }
3483 
3484 void QWSServerPrivate::raiseWindow(QWSWindow *changingw, int /*alt*/)
3485 {
3486  Q_Q(QWSServer);
3487  if (changingw == windows.first())
3488  return;
3489  QWSWindow::State oldstate = changingw->d->state;
3490  changingw->d->state = QWSWindow::Raising;
3491  // Expose regions previously overlapped by transparent windows
3492  const QRegion bound = changingw->allocatedRegion();
3493  QRegion expose;
3494  int windowPos = 0;
3495 
3496  //change position in list:
3497  for (int i = 0; i < windows.size(); ++i) {
3498  QWSWindow *w = windows.at(i);
3499  if (w == changingw) {
3500  windowPos = i;
3501  windows.takeAt(i);
3502  break;
3503  }
3504  if (!w->isOpaque())
3505  expose += (w->allocatedRegion() & bound);
3506  }
3507 
3508  bool onTop = changingw->onTop;
3509 
3510 #ifndef QT_NO_QWSEMBEDWIDGET
3511  // an embedded window is on top if the embedder is on top
3512  QWSWindow *embedder = changingw->d->embedder;
3513  while (!onTop && embedder) {
3514  onTop = embedder->onTop;
3515  embedder = embedder->d->embedder;
3516  }
3517 #endif
3518 
3519  int newPos = -1;
3520  if (onTop) {
3521  windows.insert(nReserved, changingw);
3522  newPos = nReserved;
3523  } else {
3524  // insert after "stays on top" windows
3525  bool in = false;
3526  for (int i = nReserved; i < windows.size(); ++i) {
3527  QWSWindow *w = windows.at(i);
3528  if (!w->onTop) {
3529  windows.insert(i, changingw);
3530  in = true;
3531  newPos = i;
3532  break;
3533  }
3534  }
3535  if (!in) {
3536  windows.append(changingw);
3537  newPos = windows.size()-1;
3538  }
3539  }
3540 
3541  if (windowPos != newPos) {
3542  update_regions();
3543  if (!expose.isEmpty())
3544  exposeRegion(expose, newPos);
3545  }
3546  changingw->d->state = oldstate;
3547  emit q->windowEvent(changingw, QWSServer::Raise);
3548 }
3549 
3550 void QWSServerPrivate::lowerWindow(QWSWindow *changingw, int /*alt*/)
3551 {
3552  Q_Q(QWSServer);
3553  if (changingw == windows.last())
3554  return;
3555  QWSWindow::State oldstate = changingw->d->state;
3556  changingw->d->state = QWSWindow::Lowering;
3557 
3558  int i = windows.indexOf(changingw);
3559  int newIdx = windows.size()-1;
3560  windows.move(i, newIdx);
3561 
3562  const QRegion bound = changingw->allocatedRegion();
3563 
3564  update_regions();
3565 
3566  // Expose regions previously overlapped by transparent window
3567  if (!changingw->isOpaque()) {
3568  QRegion expose;
3569  for (int j = i; j < windows.size() - 1; ++j)
3570  expose += (windows.at(j)->allocatedRegion() & bound);
3571  if (!expose.isEmpty())
3572  exposeRegion(expose, newIdx);
3573  }
3574 
3575  changingw->d->state = oldstate;
3576  emit q->windowEvent(changingw, QWSServer::Lower);
3577 }
3578 
3580 {
3581  if (disablePainting)
3582  return;
3583 
3584  QRegion available = QRect(0, 0, qt_screen->width(), qt_screen->height());
3585  QRegion transparentRegion;
3586 
3587  // only really needed if there are unbuffered surfaces...
3588  const bool doLock = (clientMap.size() > 1);
3589  if (doLock)
3590  QWSDisplay::grab(true);
3591 
3592  for (int i = 0; i < windows.count(); ++i) {
3593  QWSWindow *w = windows.at(i);
3594  QRegion r = (w->requested_region & available);
3595 
3596 #ifndef QT_NO_QWSEMBEDWIDGET
3597  // Subtract regions needed for embedded windows
3598  const int n = w->d->embedded.size();
3599  for (int i = 0; i < n; ++i)
3600  r -= w->d->embedded.at(i)->allocatedRegion();
3601 
3602  // Limited to the embedder region
3603  if (w->d->embedder)
3604  r &= w->d->embedder->requested_region;
3605 #endif // QT_NO_QWSEMBEDWIDGET
3606 
3607  QWSWindowSurface *surface = w->windowSurface();
3608  const bool opaque = w->isOpaque()
3609  && (w->d->painted || !surface || !surface->isBuffered());
3610 
3611  if (!opaque) {
3612  transparentRegion += r;
3613  } else {
3614  if (surface && (surface->isRegionReserved() || !surface->isBuffered()))
3615  r -= transparentRegion;
3616  available -= r;
3617  }
3618 
3619  if (r != w->allocatedRegion()) {
3620  w->setAllocatedRegion(r);
3621  w->client()->sendRegionEvent(w->winId(), r,
3623  }
3624 
3625 #ifdef QT_QWS_CLIENTBLIT
3626 #ifdef QT_NO_QWS_CURSOR
3627  // This optimization only really works when there isn't a crazy cursor
3628  // wizzing around.
3629  QRegion directPaint = (r - transparentRegion); // in gloal coords
3630  if(directPaint != w->directPaintRegion()) {
3631  w->setDirectPaintRegion(directPaint);
3632  static int id = 0;
3633  surface->setDirectRegion(directPaint, ++id);
3634  w->client()->sendRegionEvent(w->winId(), directPaint,
3635  QWSRegionEvent::DirectPaint, id);
3636  }
3637 #endif
3638 #endif
3639  }
3640 
3641  if (doLock)
3643 }
3644 
3645 void QWSServerPrivate::moveWindowRegion(QWSWindow *changingw, int dx, int dy)
3646 {
3647  if (!changingw)
3648  return;
3649 
3650  QWSWindow::State oldState = changingw->d->state;
3651  changingw->d->state = QWSWindow::Moving;
3652  const QRegion oldRegion(changingw->allocatedRegion());
3653  changingw->requested_region.translate(dx, dy);
3654 
3655  // hw: Even if the allocated region doesn't change, the requested region
3656  // region has changed and we need to send region events.
3657  // Resetting the allocated region to force update_regions to send events.
3658  changingw->setAllocatedRegion(QRegion());
3659  update_regions();
3660  const QRegion newRegion(changingw->allocatedRegion());
3661 
3662  QWSWindowSurface *surface = changingw->windowSurface();
3663  QRegion expose;
3664  if (surface)
3665  expose = surface->move(QPoint(dx, dy), changingw->allocatedRegion());
3666  else
3667  expose = oldRegion + newRegion;
3668 
3669  if (!changingw->d->painted && !expose.isEmpty())
3670  expose = oldRegion - newRegion;
3671 
3672  int idx = windows.indexOf(changingw);
3673  exposeRegion(expose, idx);
3674  changingw->d->state = oldState;
3675 }
3676 
3682 {
3683  if (!changingw) {
3684  qWarning("Not implemented in this release");
3685  return;
3686  }
3687 
3688  if (changingw->requested_region == r)
3689  return;
3690 
3691  const QRegion oldRegion(changingw->allocatedRegion());
3692  changingw->requested_region = r;
3693  update_regions();
3694  const QRegion newRegion(changingw->allocatedRegion());
3695 
3696  int idx = windows.indexOf(changingw);
3697  exposeRegion(oldRegion - newRegion, idx);
3698 }
3699 
3700 
3701 void QWSServerPrivate::exposeRegion(const QRegion &r, int changing)
3702 {
3703  if (disablePainting)
3704  return;
3705 
3706  if (r.isEmpty())
3707  return;
3708 
3709  static bool initial = true;
3710  if (initial) {
3711  changing = 0;
3712  initial = false;
3713  qt_screen->exposeRegion(qt_screen->region(), changing);
3714  } else {
3715  qt_screen->exposeRegion(r, changing);
3716  }
3717 }
3718 
3726 {
3727  Q_D(QWSServer);
3728  qDeleteAll(d->mousehandlers);
3729  d->mousehandlers.clear();
3730 }
3731 
3741 {
3742  Q_D(QWSServer);
3743  QString mice = QString::fromLatin1(qgetenv("QWS_MOUSE_PROTO"));
3744 #if defined(QT_QWS_CASSIOPEIA)
3745  if (mice.isEmpty())
3746  mice = QLatin1String("TPanel:/dev/tpanel");
3747 #endif
3748  if (mice.isEmpty())
3749  mice = *defaultMouse();
3750  closeMouse();
3751  bool needviscurs = true;
3752  if (mice != QLatin1String("None")) {
3753  const QStringList mouse = mice.split(QLatin1Char(' '));
3754  for (int i = mouse.size() - 1; i >= 0; --i) {
3755  QWSMouseHandler *handler = d->newMouseHandler(mouse.at(i));
3756  setMouseHandler(handler);
3757  /* XXX handle mouse cursor visibility sensibly
3758  if (!h->inherits("QCalibratedMouseHandler"))
3759  needviscurs = true;
3760  */
3761  }
3762  }
3763 #ifndef QT_NO_QWS_CURSOR
3764  setCursorVisible(needviscurs);
3765 #else
3766  Q_UNUSED(needviscurs)
3767 #endif
3768 }
3769 
3778 {
3779  Q_D(QWSServer);
3780  for (int i=0; i < d->mousehandlers.size(); ++i)
3781  d->mousehandlers.at(i)->suspend();
3782 }
3783 
3791 {
3792  Q_D(QWSServer);
3793  for (int i=0; i < d->mousehandlers.size(); ++i)
3794  d->mousehandlers.at(i)->resume();
3795 }
3796 
3797 
3798 
3800 {
3801  int c = spec.indexOf(QLatin1Char(':'));
3802  QString mouseProto;
3803  QString mouseDev;
3804  if (c >= 0) {
3805  mouseProto = spec.left(c);
3806  mouseDev = spec.mid(c+1);
3807  } else {
3808  mouseProto = spec;
3809  }
3810 
3811  int screen = -1;
3812  const QList<QRegExp> regexps = QList<QRegExp>()
3813  << QRegExp(QLatin1String(":screen=(\\d+)\\b"))
3814  << QRegExp(QLatin1String("\\bscreen=(\\d+):"));
3815  for (int i = 0; i < regexps.size(); ++i) {
3816  QRegExp regexp = regexps.at(i);
3817  if (regexp.indexIn(mouseDev) == -1)
3818  continue;
3819  screen = regexp.cap(1).toInt();
3820  mouseDev.remove(regexp.pos(0), regexp.matchedLength());
3821  break;
3822  }
3823 
3824  QWSMouseHandler *handler = 0;
3825  handler = QMouseDriverFactory::create(mouseProto, mouseDev);
3826  if (screen != -1)
3827  handler->setScreen(qt_screen->subScreens().at(screen));
3828 
3829  return handler;
3830 }
3831 
3832 #ifndef QT_NO_QWS_KEYBOARD
3833 
3842 {
3843  Q_D(QWSServer);
3844  qDeleteAll(d->keyboardhandlers);
3845  d->keyboardhandlers.clear();
3846 }
3847 
3856 {
3857  return qwsServerPrivate->keyboardhandlers.first();
3858 }
3859 
3875 {
3876  if (!kh)
3877  return;
3878  qwsServerPrivate->keyboardhandlers.removeAll(kh);
3879  qwsServerPrivate->keyboardhandlers.prepend(kh);
3880 }
3881 
3889 {
3890  QString keyboards = QString::fromLatin1(qgetenv("QWS_KEYBOARD"));
3891 #if defined(QT_QWS_CASSIOPEIA)
3892  if (keyboards.isEmpty())
3893  keyboards = QLatin1String("Buttons");
3894 #endif
3895  if (keyboards.isEmpty())
3896  keyboards = *defaultKeyboard();
3897 
3898  closeKeyboard();
3899  if (keyboards == QLatin1String("None"))
3900  return;
3901 
3902  QString device;
3903  QString type;
3904  QStringList keyboard = keyboards.split(QLatin1Char(' '));
3905  for (int i = keyboard.size() - 1; i >= 0; --i) {
3906  const QString spec = keyboard.at(i);
3907  int colon=spec.indexOf(QLatin1Char(':'));
3908  if (colon>=0) {
3909  type = spec.left(colon);
3910  device = spec.mid(colon+1);
3911  } else {
3912  type = spec;
3913  device = QString();
3914  }
3916  setKeyboardHandler(handler);
3917  }
3918 }
3919 
3920 #endif //QT_NO_QWS_KEYBOARD
3921 
3924 
3926 {
3927  QWSClient *serverClient = clientMap.value(-1);
3928  invokeRegionMove(cmd, serverClient);
3929 }
3930 
3932 {
3933  QWSClient *serverClient = clientMap.value(-1);
3934  invokeSetAltitude(cmd, serverClient);
3935 }
3936 
3938 {
3939  QWSClient *serverClient = clientMap.value(-1);
3940  invokeSetOpacity(cmd, serverClient);
3941 }
3942 
3943 
3945 {
3946  invokeSetFocus(cmd, clientMap.value(-1));
3947 }
3948 
3950 {
3951  invokeIdentify(cmd, clientMap.value(-1));
3952 }
3953 
3954 void QWSServerPrivate::repaint_region(int wid, int windowFlags, bool opaque,
3955  const QRegion &region)
3956 {
3957  QWSWindow* changingw = findWindow(wid, 0);
3958  if (!changingw) {
3959  return;
3960  }
3961 
3962  const bool isOpaque = changingw->opaque;
3963  const bool wasPainted = changingw->d->painted;
3964  changingw->opaque = opaque;
3965  changingw->d->windowFlags = QFlag(windowFlags);
3966  changingw->d->dirtyOnScreen |= region;
3967  changingw->d->painted = true;
3968  if (isOpaque != opaque || !wasPainted)
3969  update_regions();
3970 
3971  int level = windows.indexOf(changingw);
3972  exposeRegion(region, level);
3973  changingw->d->dirtyOnScreen = QRegion();
3974 }
3975 
3977 {
3978  QRegion r = region;
3979 
3980  int oldPos = windows.indexOf(win);
3981  int newPos = oldPos < nReserved ? nReserved - 1 : nReserved;
3982  for (int i = 0; i < nReserved; ++i) {
3983  if (i != oldPos) {
3984  QWSWindow *w = windows.at(i);
3985  r -= w->requested_region;
3986  }
3987  }
3988  windows.move(oldPos, newPos);
3989  nReserved = newPos + 1;
3990 
3991  return r;
3992 }
3993 
3994 void QWSServerPrivate::request_region(int wid, const QString &surfaceKey,
3995  const QByteArray &surfaceData,
3996  const QRegion &region)
3997 {
3998  QWSWindow *changingw = findWindow(wid, 0);
3999  if (!changingw)
4000  return;
4001 
4002  Q_Q(QWSServer);
4003  QWSWindow::State windowState = QWSWindow::NoState;
4004 
4005  if (region.isEmpty()) {
4006  windowState = QWSWindow::Hiding;
4007  emit q->windowEvent(changingw, QWSServer::Hide);
4008  }
4009 
4010  const bool wasOpaque = changingw->opaque;
4011 
4012  QWSWindowSurface *surface = changingw->windowSurface();
4013  if (!surface) {
4014  changingw->createSurface(surfaceKey, surfaceData);
4015  surface = changingw->windowSurface();
4016  } else {
4017  surface->setPermanentState(surfaceData);
4018  }
4019 
4020  changingw->opaque = surface->isOpaque();
4021 
4022  QRegion r;
4023  if (surface->isRegionReserved())
4024  r = reserve_region(changingw, region);
4025  else
4026  r = region;
4027 
4028  if (!region.isEmpty()) {
4029  if (changingw->isVisible())
4030  windowState = QWSWindow::ChangingGeometry;
4031  else
4032  windowState = QWSWindow::Showing;
4033  }
4034  changingw->d->state = windowState;
4035 
4036  if (!r.isEmpty() && wasOpaque != changingw->opaque && surface->isBuffered())
4037  changingw->requested_region = QRegion(); // XXX: force update_regions
4038 
4039  const QRegion oldAllocated = changingw->allocatedRegion();
4040  setWindowRegion(changingw, r);
4041  if (oldAllocated == changingw->allocatedRegion()) {
4042  // Always send region event to the requesting window even if the
4043  // region didn't change. This is necessary as the client will reset
4044  // the clip region until an event is received.
4045  changingw->client()->sendRegionEvent(wid, changingw->allocatedRegion(),
4047  }
4048 
4049  surface->QWindowSurface::setGeometry(r.boundingRect());
4050 
4051  if (windowState == QWSWindow::Showing)
4052  emit q->windowEvent(changingw, QWSServer::Show);
4053  else if (windowState == QWSWindow::ChangingGeometry)
4054  emit q->windowEvent(changingw, QWSServer::Geometry);
4055  if (windowState == QWSWindow::Hiding) {
4056  handleWindowClose(changingw);
4057  changingw->d->state = QWSWindow::Hidden;
4058  changingw->d->painted = false;
4059  } else {
4060  changingw->d->state = QWSWindow::Visible;
4061  }
4062 }
4063 
4065 {
4066  invokeRegionDestroy(cmd, clientMap.value(-1));
4067 }
4068 
4070 {
4071  invokeRegionName(cmd, clientMap.value(-1));
4072 }
4073 
4074 #ifndef QT_NO_QWS_INPUTMETHODS
4076  {
4077  invokeIMResponse(cmd, clientMap.value(-1));
4078 }
4079 
4081 {
4082  invokeIMUpdate(cmd, clientMap.value(-1));
4083 }
4084 
4086 {
4087  if (current_IM)
4088  current_IM->mouseHandler(cmd->simpleData.index, cmd->simpleData.state);
4089 }
4090 #endif
4091 
4093 {
4094  qt_init_display();
4095 
4096 // rgnMan = qt_fbdpy->regionManager();
4097  swidth = qt_screen->deviceWidth();
4098  sheight = qt_screen->deviceHeight();
4099 }
4100 
4102 {
4103  if (qt_screen)
4105 }
4106 
4114 {
4115  return *QWSServerPrivate::bgBrush;
4116 }
4117 
4127 {
4128  if (!QWSServerPrivate::bgBrush)
4129  QWSServerPrivate::bgBrush = new QBrush(brush);
4130  else
4131  *QWSServerPrivate::bgBrush = brush;
4132  if (!qwsServer)
4133  return;
4135 }
4136 
4137 
4138 #ifdef QT3_SUPPORT
4139 
4158 void QWSServer::setDesktopBackground(const QImage &img)
4159 {
4160  if (img.isNull())
4162  else
4164 }
4165 
4186 void QWSServer::setDesktopBackground(const QColor &c)
4187 {
4188  setBackground(QBrush(c));
4189 }
4190 #endif //QT3_SUPPORT
4191 
4195 void QWSServer::startup(int flags)
4196 {
4197  if (qwsServer)
4198  return;
4199  unlink(qws_qtePipeFilename().toLatin1().constData());
4200  (void)new QWSServer(flags);
4201 }
4202 
4208 {
4210  qwsServer = 0;
4211  QT_TRY {
4212  unlink(qws_qtePipeFilename().toLatin1().constData());
4213  } QT_CATCH(const std::bad_alloc &) {
4214  // ### TODO - what to do when we run out of memory
4215  // when calling toLatin1?
4216  }
4217 }
4218 
4220 {
4221 #ifndef QT_NO_QWS_KEYBOARD
4222  if (qwsServer)
4224 #endif
4225 }
4226 
4227 #ifndef QT_NO_QWS_KEYBOARD
4229 
4248 void QWSServer::processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers,
4249  bool isPress, bool autoRepeat)
4250 {
4251  bool block;
4252  // Don't block the POWER or LIGHT keys
4253  if ( keycode == Qt::Key_F34 || keycode == Qt::Key_F35 )
4254  block = false;
4255  else
4256  block = qwsServerPrivate->screensaverblockevent(KEY, qwsServerPrivate->screensaverinterval, isPress);
4257 
4258 #ifdef EVENT_BLOCK_DEBUG
4259  qDebug() << "processKeyEvent" << unicode << keycode << modifiers << isPress << autoRepeat << (block ? "block" : "pass");
4260 #endif
4261 
4262  // If we press a key and it's going to be blocked, wake up the screen
4263  if (block) {
4264  if (isPress)
4265  qwsServerPrivate->_q_screenSaverWake();
4266  return;
4267  }
4268 
4269  if (keyFilters) {
4270  for (int i = 0; i < keyFilters->size(); ++i) {
4271  QWSServer::KeyboardFilter *keyFilter = keyFilters->at(i);
4272  if (keyFilter->filter(unicode, keycode, modifiers, isPress, autoRepeat))
4273  return;
4274  }
4275  }
4276  sendKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat);
4277 }
4278 
4295 {
4296  if (!keyFilters)
4297  keyFilters = new QList<QWSServer::KeyboardFilter*>;
4298  if (f) {
4299  keyFilters->prepend(f);
4300  }
4301 }
4302 
4303 /*
4304 //#######
4305  We should probably obsolete the whole keyboard filter thing since
4306  it's not useful for input methods anyway
4307 
4308  We could do removeKeyboardFilter(KeyboardFilter *f), but
4309  the "remove and delete the filter" concept does not match "user
4310  remembers the pointer".
4311 */
4312 
4324 {
4325  if (!keyFilters || keyFilters->isEmpty())
4326  return;
4327  delete keyFilters->takeAt(0);
4328 }
4329 #endif // QT_NO_QWS_KEYBOARD
4330 
4351 {
4352  if (!qwsServerPrivate)
4353  return;
4354 
4355  delete [] qwsServerPrivate->screensaverintervals;
4356  if (ms) {
4357  int* t=ms;
4358  int n=0;
4359  while (*t++) n++;
4360  if (n) {
4361  n++; // the 0
4362  qwsServerPrivate->screensaverintervals = new int[n];
4363  memcpy(qwsServerPrivate->screensaverintervals, ms, n*sizeof(int));
4364  } else {
4365  qwsServerPrivate->screensaverintervals = 0;
4366  }
4367  } else {
4368  qwsServerPrivate->screensaverintervals = 0;
4369  }
4370  qwsServerPrivate->screensaverinterval = 0;
4371 
4372  qwsServerPrivate->screensavertimer->stop();
4373  qt_screen->blank(false);
4374  qwsServerPrivate->_q_screenSaverWake();
4375 }
4376 
4392 {
4393  int v[2];
4394  v[0] = ms;
4395  v[1] = 0;
4397 }
4398 
4417 void QWSServer::setScreenSaverBlockLevel(int eventBlockLevel)
4418 {
4419  if (!qwsServerPrivate)
4420  return;
4421  qwsServerPrivate->screensavereventblocklevel = eventBlockLevel;
4422 #ifdef EVENT_BLOCK_DEBUG
4423  qDebug() << "QWSServer::setScreenSaverBlockLevel() " << eventBlockLevel;
4424 #endif
4425 }
4426 
4427 extern bool qt_disable_lowpriority_timers; //in qeventloop_unix.cpp
4428 
4430 {
4431  if (screensaverintervals) {
4432  if (screensaverinterval != screensaverintervals) {
4433  if (saver) saver->restore();
4434  screensaverinterval = screensaverintervals;
4435  screensaverblockevents = false;
4436  } else {
4437  if (!screensavertimer->isActive()) {
4438  qt_screen->blank(false);
4439  if (saver) saver->restore();
4440  }
4441  }
4442  screensavertimer->start(*screensaverinterval);
4443  screensavertime.start();
4444  }
4446 }
4447 
4449 {
4450  qt_screen->blank(true);
4451 #if !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX)
4452  screensavertimer->stop();
4453 #else
4454  if (screensaverinterval) {
4455  screensavertimer->start(*screensaverinterval);
4456  screensavertime.start();
4457  } else {
4458  screensavertimer->stop();
4459  }
4460 #endif
4462 }
4463 
4475 {
4476  QWSServerPrivate *qd = qwsServer->d_func();
4477  delete qd->saver;
4478  qd->saver = ss;
4479 }
4480 
4482 {
4483  if (saver) {
4484  // saver->save() may call QCoreApplication::processEvents,
4485  // block event before calling saver->save().
4486  bool oldScreensaverblockevents = screensaverblockevents;
4487  if (*screensaverinterval >= 1000) {
4488  screensaverblockevents = (screensavereventblocklevel >= 0 && screensavereventblocklevel <= level);
4489 #ifdef EVENT_BLOCK_DEBUG
4490  if (screensaverblockevents)
4491  qDebug("ready to block events");
4492 #endif
4493  }
4494  int *oldScreensaverinterval = screensaverinterval;
4495  if (saver->save(level)) {
4496  // only update screensaverinterval if it hasn't already changed
4497  if (oldScreensaverinterval == screensaverinterval) {
4498  if (screensaverinterval && screensaverinterval[1]) {
4499  screensavertimer->start(*++screensaverinterval);
4500  screensavertime.start();
4501  } else {
4502  screensaverinterval = 0;
4503  }
4504  }
4505  } else {
4506  // restore previous state
4507  screensaverblockevents = oldScreensaverblockevents;
4508 
4509  // for some reason, the saver don't want us to change to the
4510  // next level, so we'll stay at this level for another interval
4511  if (screensaverinterval && *screensaverinterval) {
4512  screensavertimer->start(*screensaverinterval);
4513  screensavertime.start();
4514  }
4515  }
4516  } else {
4517  screensaverinterval = 0;//screensaverintervals;
4518  screensaverblockevents = false;
4519  _q_screenSaverSleep();
4520  }
4521 }
4522 
4524 {
4525  if (screensaverinterval) {
4526  if (screensavertime.elapsed() > *screensaverinterval*2) {
4527  // bogus (eg. unsuspend, system time changed)
4528  _q_screenSaverWake(); // try again
4529  return;
4530  }
4531  screenSave(screensaverinterval - screensaverintervals);
4532  }
4533 }
4534 
4544 {
4545  return qwsServerPrivate->screensaverinterval
4546  && !qwsServerPrivate->screensavertimer->isActive();
4547 }
4548 
4553 {
4554  qwsServerPrivate->update_regions();
4555 }
4556 
4566 {
4567  if (activate)
4568  qwsServerPrivate->_q_screenSaverSleep();
4569  else
4570  qwsServerPrivate->_q_screenSaverWake();
4571 }
4572 
4574 {
4575  QTimer::singleShot(0, c, SLOT(closeHandler()));
4576 }
4577 
4579 {
4580  Q_Q(QWSServer);
4581  QWSWindow *win = qwsServerPrivate->mouseGrabber ? qwsServerPrivate->mouseGrabber : qwsServer->windowAt(QWSServer::mousePosition);
4582  QWSClient *winClient = win ? win->client() : 0;
4583  if (winClient && winClient != cursorClient)
4584  q->sendMouseEvent(QWSServer::mousePosition, mouseState);
4585 }
4586 
4587 #ifndef QT_NO_QWS_INPUTMETHODS
4588 
4673 {
4674 
4675 }
4676 
4681 {
4682  if (current_IM == this)
4683  current_IM = 0;
4684 }
4685 
4707 bool QWSInputMethod::filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat)
4708 {
4709  Q_UNUSED(unicode);
4710  Q_UNUSED(keycode);
4711  Q_UNUSED(modifiers);
4712  Q_UNUSED(isPress);
4713  Q_UNUSED(autoRepeat);
4714  return false;
4715 }
4716 
4726 bool QWSInputMethod::filter(const QPoint &position, int state, int wheel)
4727 {
4728  Q_UNUSED(position);
4729  Q_UNUSED(state);
4730  Q_UNUSED(wheel);
4731  return false;
4732 }
4733 
4745 {
4746  if (current_IM_composing_win) {
4747  QInputMethodEvent ime;
4748  sendEvent(&ime);
4749  }
4750 }
4751 
4782 {
4783  switch (type) {
4784  case FocusOut:
4785  case Reset:
4786  reset();
4787  break;
4788 
4789  default:
4790  break;
4791  }
4792 }
4793 
4794 
4808 {
4809  Q_UNUSED(property);
4810  Q_UNUSED(result);
4811 }
4812 
4813 
4814 
4836 void QWSInputMethod::mouseHandler(int, int state)
4837 {
4838  if (state == QWSServer::MousePress || state == QWSServer::MouseOutside)
4839  reset();
4840 }
4841 
4842 
4868 void QWSInputMethod::sendPreeditString(const QString &preeditString, int cursorPosition, int selectionLength)
4869 {
4871 
4872  int selPos = cursorPosition;
4873  if (selectionLength == 0) {
4874  selPos = 0;
4875  } else if (selectionLength < 0) {
4876  selPos += selectionLength;
4877  selectionLength = -selectionLength;
4878  }
4879  if (selPos > 0)
4882 
4883  if (selectionLength)
4884  attributes += QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, selPos, selectionLength,
4886 
4887  if (selPos + selectionLength < preeditString.length())
4889  selPos + selectionLength,
4890  preeditString.length() - selPos - selectionLength,
4892 
4893  attributes += QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPosition, 0, QVariant());
4894 
4895  QInputMethodEvent ime(preeditString, attributes);
4896  qwsServer->sendIMEvent(&ime);
4897 }
4898 
4923 void QWSInputMethod::sendCommitString(const QString &commitString, int replaceFrom, int replaceLength)
4924 {
4925  QInputMethodEvent ime;
4926  ime.setCommitString(commitString, replaceFrom, replaceLength);
4927  qwsServer->sendIMEvent(&ime);
4928 }
4929 
4991 {
4992  mIResolution = isHigh;
4993  return inputResolutionShift();
4994 }
4995 
5003 {
5004  return 0; // default for devices with single resolution.
5005 }
5006 
5025 void QWSInputMethod::sendMouseEvent( const QPoint &pos, int state, int wheel )
5026 {
5027  if (qt_last_x) {
5028  *qt_last_x = pos.x();
5029  *qt_last_y = pos.y();
5030  }
5031  QWSServer::mousePosition = pos;
5032  qwsServerPrivate->mouseState = state;
5033  QWSServerPrivate::sendMouseEventUnfiltered(pos, state, wheel);
5034 }
5035 #endif // QT_NO_QWS_INPUTMETHODS
5036 
5123 
5124 #include "moc_qwindowsystem_qws.cpp"
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void invokeIMUpdate(const QWSIMUpdateCommand *cmd, QWSClient *client)
void setAllocatedRegion(const QRegion &region)
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
struct QWSAddPropertyCommand::SimpleData simpleData
#define QT_QWS_PROPERTY_MARKEDTEXT
void sendEvent(QWSEvent *event)
struct QWSRepaintRegionCommand::SimpleData simpleData
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void show()
Shows the window.
const QString & preeditString() const
Returns the preedit text, i.
Definition: qevent.h:455
struct QWSIMResponseCommand::SimpleData simpleData
void setWindowRegion(QWSWindow *, const QRegion &r)
Changes the requested region of window changingw to r If changingw is 0, the server&#39;s reserved region...
void sendMouseEvent(const QPoint &pos, int state, int wheel)
Sends a mouse event specified by the given position, state and wheel parameters.
The QWSWindowSurface class provides the drawing area for top-level windows in Qt for Embedded Linux...
virtual void move(int x, int y)
Moves the mouse cursor to the given position, i.e., (x, y).
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
The QWSKeyboardHandler class is a base class for keyboard drivers in Qt for Embedded Linux...
Definition: qkbd_qws.h:57
void setMaxWindowRect(const QScreen *screen, int screenNo, const QRect &rect)
void set_altitude(const QWSChangeAltitudeCommand *)
QWSCursor * nextCursor
QRect maxWindowRect(const QScreen *screen) const
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
void invokeRegionMove(const QWSRegionMoveCommand *cmd, QWSClient *client)
void invokeGetProperty(QWSGetPropertyCommand *cmd, QWSClient *client)
int type
Definition: qmetatype.cpp:239
The KeyboardFilter class is a base class for global keyboard event filters in Qt for Embedded Linux...
int height() const
Returns the logical height of the framebuffer in pixels.
Definition: qscreen_qws.h:228
#define QT_NO_QWSEMBEDWIDGET
static void sendMouseEvent(const QPoint &pos, int state, int wheel=0)
Send a mouse event.
unsigned char c[8]
Definition: qnumeric_p.h:62
void invokeAddProperty(QWSAddPropertyCommand *cmd)
struct QWSRegionMoveCommand::SimpleData simpleData
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
Definition: qregexp.cpp:4310
int replacementStart() const
Returns the position at which characters are to be replaced relative from the start of the preedit st...
Definition: qevent.h:458
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const Key key(const T &value) const
Returns the first key with value value.
Definition: qmap.h:844
virtual void queryResponse(int property, const QVariant &)
Receive replies to an input method query.
EventRef event
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
The QInputMethodEvent::Attribute class stores an input method attribute.
Definition: qevent.h:441
QWSWindowSurface * surface
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
int keycode
const QByteArray & data() const
Returns the data contained in the buffer.
Definition: qbuffer.cpp:301
static void sendQCopEvent(QWSClient *c, const QString &ch, const QString &msg, const QByteArray &data, bool response=false)
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
void refresh()
Refreshes the display by making the screen driver update the entire display.
static QWSCommand * factory(int type)
#define it(className, varName)
The QFlag class is a helper data type for QFlags.
Definition: qglobal.h:2289
static void setDefaultMouse(const char *)
Sets the mouse driver that will be used if the QWS_MOUSE_PROTO environment variable is not defined...
static QWSCursor * systemCursor(int id)
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
void invokeRemoveProperty(QWSRemovePropertyCommand *cmd)
QTransportAuth::Data * connectTransport(unsigned char, int)
Record a new transport connection with properties and descriptor.
void invokeIMResponse(const QWSIMResponseCommand *cmd, QWSClient *client)
struct QWSPositionCursorCommand::SimpleData simpleData
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
#define error(msg)
void removeUnbufferedSurface()
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QObject * client() const
bool remove(const T &value)
Definition: qset.h:89
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
The QWSMouseHandler class is a base class for mouse drivers in Qt for Embedded Linux.
Definition: qmouse_qws.h:66
bool isEmpty() const
Definition: qset.h:77
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void invokeGrabMouse(QWSGrabMouseCommand *cmd, QWSClient *client)
State
This enum describes the state of a window.
#define SLOT(a)
Definition: qobjectdefs.h:226
bool empty() const
This function is provided for STL compatibility.
Definition: qlist.h:304
QWSClient * client() const
Returns a reference to the QWSClient object that owns this window.
virtual bool connect(const QString &displaySpec)=0
This function is called by every Qt for Embedded Linux application on startup, and must be implemente...
void setIdentity(const QString &)
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
void sendPropertyNotifyEvent(int property, int state)
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static bool prevWin
static int current_IM_winId
QSet< QByteArray > usedFonts
QList< QWSCommand * > * qt_get_server_queue()
Pass-through QIODevice sub-class for authentication.
int pos(int nth=0) const
Returns the position of the nth captured text in the searched string.
Definition: qregexp.cpp:4337
void setCommitString(const QString &commitString, int replaceFrom=0, int replaceLength=0)
Sets the commit string to commitString.
Definition: qevent.cpp:2042
int matchedLength() const
Returns the length of the last matched string, or -1 if there was no match.
Definition: qregexp.cpp:4193
int qws_read_uint(QIODevice *socket)
Definition: qwsutils_qws.h:73
QString qws_fontCacheDir()
qint64 size() const
Reimplemented Function
Definition: qbuffer.cpp:375
struct QWSRequestFocusCommand::SimpleData simpleData
static QApplicationPrivate * instance()
int deviceWidth() const
Returns the physical width of the framebuffer device in pixels.
Definition: qscreen_qws.h:233
The QWSScreenSaver class is a base class for screensavers in Qt for Embedded Linux.
struct QWSScreenTransformCommand::SimpleData simpleData
void referenceFont(QWSClientPrivate *client, const QByteArray &font)
QByteArray surfaceData
long ASN1_INTEGER_get ASN1_INTEGER * a
Q_GLOBAL_STATIC_WITH_ARGS(QString, defaultMouse,(QLatin1String("Auto"))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
virtual QSize mapFromDevice(const QSize &) const
Maps the given size from the framebuffer coordinate system to the coordinate space used by the applic...
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
void raise()
Raises the window above all other windows except "Stay on top" windows.
void im_response(const QWSIMResponseCommand *)
bool qt_disable_lowpriority_timers
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
QRegion allocatedRegion() const
Returns the region that the window is allowed to draw onto, including any window decorations but excl...
bool isBuffered() const
Returns true if the QWSWindowSurface::Buffered is set; otherwise returns false.
void disconnectClient(QWSClient *)
static ClearCacheFunc clearCacheFunc
Definition: qscreen_qws.h:344
QWSWindow * focusw
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
static void setCursorVisible(bool)
Shows the cursor if visible is true: otherwise the cursor is hidden.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QRegion requested_region
static bool screenSaverActive()
Returns true if the screen saver is active; otherwise returns false.
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual bool filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat)
Filters the key input identified by the given unicode, keycode, modifiers, isPress and autoRepeat par...
static void sendMouseEventUnfiltered(const QPoint &pos, int state, int wheel=0)
QWSEmbedEvent::Type type
uint count() const
Returns the total number of directories and files in the directory.
Definition: qdir.cpp:1247
static void screenSaverActivate(bool)
Activates the screen saver if activate is true; otherwise it is deactivated.
struct QWSIMMouseCommand::SimpleData simpleData
void invokeDefineCursor(QWSDefineCursorCommand *cmd, QWSClient *client)
void updateWindowRegions() const
#define KEY
QWSCommand * readMoreCommand()
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void exposeRegion(const QRegion &, int index=0)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
struct QWSSetPropertyCommand::SimpleData simpleData
iterator begin()
Definition: qset.h:166
#define Q_D(Class)
Definition: qglobal.h:2482
void sendSelectionClearEvent(int windowid)
void sendPropertyReplyEvent(int property, int len, const char *data)
struct QWSSetSelectionOwnerCommand::SimpleData simpleData
void closeMouse()
Closes all pointer devices (specified by the QWS_MOUSE_PROTO environment variable) by deleting the as...
void im_update(const QWSIMUpdateCommand *)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void createSurface(const QString &key, const QByteArray &data)
static void setScreenSaverBlockLevel(int)
Block the key or mouse event that wakes the system from level eventBlockLevel or higher.
static void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
Processes the given key event.
void sendSelectionRequestEvent(QWSConvertSelectionCommand *cmd, int windowid)
static void closedown()
bool hidden() const
void invokeEmbed(QWSEmbedCommand *cmd, QWSClient *client)
static QWSInputMethod * current_IM
static void processEventQueue()
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static void removeKeyboardFilter()
Removes and deletes the most recently added filter.
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
void invokeSetSelectionOwner(QWSSetSelectionOwnerCommand *cmd)
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
void closeKeyboard()
Closes all the keyboard devices (specified by the QWS_KEYBOARD environment variable) by deleting the ...
QString rgnCaption
Q_CORE_EXPORT QTextStream & fixed(QTextStream &s)
The QWSEvent class encapsulates an event in Qt for Embedded Linux.
Definition: qwsevent_qws.h:59
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
void set(int h, int m, int s, int s2)
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qmap.h:251
struct QWSRegionDestroyCommand::SimpleData simpleData
bool screensaverblockevent(int index, int *screensaverinterval, bool isDown)
struct QWSSetOpacityCommand::SimpleData simpleData
SocketState
This enum describes the different states in which a socket can be.
static const QRectF boundingRect(const QPointF *points, int pointCount)
virtual void mouseHandler(int pos, int state)
Handles mouse events within the preedit text.
Q_CORE_EXPORT void qDebug(const char *,...)
The QWSWindow class encapsulates a top-level window in Qt for Embedded Linux.
void readyRead()
static QWidget * widgetAt(const QPoint &p)
Returns the widget at global screen position point, or 0 if there is no Qt widget there...
virtual void disconnect()=0
This function is called by every Qt for Embedded Linux application before exiting, and must be implemented to unmap the framebuffer.
struct QWSChangeAltitudeCommand::SimpleData simpleData
static void beginDisplayReconfigure()
#define SIGNAL(a)
Definition: qobjectdefs.h:227
virtual QRegion region() const
Returns the region covered by this screen driver.
Definition: qscreen_qws.h:284
void openKeyboard()
Opens the keyboard devices specified by the QWS_KEYBOARD environment variable.
#define QT_RETHROW
Definition: qglobal.h:1539
void cleanupFonts(bool force=false)
int width() const
Returns the logical width of the framebuffer in pixels.
Definition: qscreen_qws.h:227
void hide()
Hides the window.
NSWindow * window
defaultKeyboard
static int keyUnicode(int keycode)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
int socket() const
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget...
Definition: qevent.h:457
void moveWindowRegion(QWSWindow *, int dx, int dy)
static bool keyboardGrabbing
QList< QWSMouseHandler * > mousehandlers
void invokeRegion(QWSRegionCommand *cmd, QWSClient *client)
void setName(const QString &n)
QLatin1String("TTY"))) static const int FontCleanupInterval
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void invokeRegionDestroy(const QWSRegionDestroyCommand *cmd, QWSClient *client)
int * qt_last_x
void invokeRegisterChannel(QWSQCopRegisterChannelCommand *cmd, QWSClient *client)
uint inputResolutionShift() const
Returns the number of bits shifted to go from pointer resolution to screen resolution when filtering ...
void timerEvent(QTimerEvent *e)
~QWSWindow()
Destructor.
uint setInputResolution(bool isHigh)
Sets and returns the number of bits shifted to go from pointer resolution to screen resolution when f...
void sendPreeditString(const QString &preeditString, int cursorPosition, int selectionLength=0)
Sends an event encapsulating the given preeditString, to the focus widget.
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
Definition: qregexp.cpp:4136
static void setBackground(const QBrush &)
Sets the brush used as background in the absence of obscuring windows, to be the given brush...
void invokeRegionName(const QWSRegionNameCommand *cmd, QWSClient *client)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
void enablePainting(bool)
Enables painting onto the screen if enable is true; otherwise painting is disabled.
QWSWindow * newWindow(int id, QWSClient *client)
void focus(bool get)
bool contains(const T &value) const
Definition: qset.h:91
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
static void sendKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
Sends the given key event.
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static void setScreenSaver(QWSScreenSaver *)
Installs the given screenSaver, deleting the current screen saver.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
Qt::WindowFlags windowFlags
#define qApp
QWSWindow * findWindow(int windowid, QWSClient *client=0)
void resumeMouse()
Resumes pointer handling by reactivating all the mouse drivers registered by the QWS_MOUSE_PROTO envi...
int qt_servershmid
static QWSKeyboardHandler * create(const QString &, const QString &)
QWSWindow(int i, QWSClient *client)
static QBrush * bgBrush
void sendEmbedEvent(int winid, QWSEmbedEvent::Type type, const QRegion &region=QRegion())
static void setCurrentInputMethod(QWSInputMethod *im)
Sets the current input method to be the given method.
const char * name
void move_region(const QWSRegionMoveCommand *)
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
void invokeSetOpacity(const QWSSetOpacityCommand *cmd, QWSClient *client)
QWSSocket * csocket
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
void sendMaxWindowRectEvents(const QRect &rect)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
SocketError
This enum describes the socket errors that can occur.
static bool isCursorVisible()
Returns true if the cursor is visible; otherwise returns false.
void handleWindowClose(QWSWindow *w)
void set_identity(const QWSIdentifyCommand *)
QWSCursorMap cursors
void qt_qws_init_fontdb()
void lowerWindow(QWSWindow *, int=-1)
Qt::WindowFlags windowFlags() const
Returns the window flags of the window.
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Q_CORE_EXPORT void qWarning(const char *,...)
const_iterator insert(const T &value)
Definition: qset.h:179
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static QList< QByteArray > cleanUpAfterClientCrash(const QList< int > &crashedClientIds)
void sendIMQuery(int property)
Sends an input method query for the given property.
bool contains(const QPoint &p) const
Returns true if the region contains the point p; otherwise returns false.
Definition: qregion.cpp:4104
static const char * data(const QByteArray &arr)
QString qws_qtePipeFilename()
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
struct QWSSelectCursorCommand::SimpleData simpleData
QTimer * screensavertimer
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
Definition: qtimer.h:69
void clear()
Definition: qset.h:87
void sendMaxWindowRectEvent(const QRect &rect)
static QScreen * instance()
Returns a pointer to the application&#39;s QScreen instance.
Definition: qscreen_qws.h:201
static void answer(QWSClient *cl, const QString &ch, const QString &msg, const QByteArray &data)
Server side: transmit the message to all clients registered to the specified channel.
virtual void reset()
Resets the state of the input method.
int * qt_last_y
QWSCommand * command
void invokeConvertSelection(QWSConvertSelectionCommand *cmd)
void setActiveWindow()
Make this the active window (i.
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
const QList< Attribute > & attributes() const
Returns the list of attributes passed to the QInputMethodEvent constructor.
Definition: qevent.h:454
void raiseWindow(QWSWindow *, int=0)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
__int64 qint64
Definition: qglobal.h:942
struct QWSRegionNameCommand::SimpleData simpleData
QAuthDevice * recvBuf(QTransportAuth::Data *, QIODevice *)
Return a QIODevice pointer (to an internal QBuffer) which can be used to receive data after authoriza...
static int qws_keyModifiers
static void grab()
struct QWSEmbedCommand::@168 simpleData
int focusPriority() const
void request_focus(const QWSRequestFocusCommand *)
static void cleanupFontsDir()
static void startup(int flags)
QWSInputMethod()
Constructs a new input method.
void releaseMouse(QWSWindow *w)
#define QT_CATCH(A)
Definition: qglobal.h:1537
QWSWindow * windowAt(const QPoint &pos)
Returns the window containing the given position.
void invokePositionCursor(QWSPositionCursorCommand *cmd, QWSClient *client)
void invokeCreate(QWSCreateCommand *cmd, QWSClient *client)
static void detach(QWSClient *cl)
Server side: unsubscribe cl from all channels.
void startEmbed(QWSWindow *window)
QWSWindowPrivate * d
static QWSMouseHandler * create(const QString &, const QString &)
static QWSServerPrivate * qwsServerPrivate
QWSCommandStruct(QWSCommand *c, QWSClient *cl)
static void setDefaultKeyboard(const char *)
Sets the keyboard driver that will be used if the QWS_KEYBOARD environment variable is not defined...
QList< QWSKeyboardHandler * > keyboardhandlers
void invokeGrabKeyboard(QWSGrabKeyboardCommand *cmd, QWSClient *client)
void invokeQCopSend(QWSQCopSendCommand *cmd, QWSClient *client)
virtual void hide()
Hides the cursor from the screen.
QList< QWSWindow * > embedded
void suspendMouse()
Suspends pointer handling by deactivating all the mouse drivers registered by the QWS_MOUSE_PROTO env...
void sendRegionEvent(int winid, QRegion rgn, int type)
virtual QWSWindowSurface * createSurface(QWidget *widget) const
Creates and returns a new window surface for the given widget.
virtual bool filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat)=0
Implement this function to return true if a given key event should be stopped from being processed an...
int length() const
Same as size().
Definition: qbytearray.h:356
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void sendIMEvent(const QInputMethodEvent *)
Sends the given input method event.
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
static void setScreenSaverIntervals(int *ms)
Specifies the time intervals (in milliseconds) between the different levels of screen responsiveness...
QWSScreenSaver * saver
bool isVisible() const
Returns true if the window is visible; otherwise returns false.
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
QRegion reserve_region(QWSWindow *window, const QRegion &region)
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
virtual void updateHandler(int type)
Handles update events including resets and focus changes.
static QWSKeyboardHandler * keyboardHandler()
Returns the primary keyboard driver.
int elapsed() const
Returns the number of milliseconds that have elapsed since the last time start() or restart() was cal...
Definition: qdatetime.cpp:2123
void invokeSelectCursor(QWSSelectCursorCommand *cmd, QWSClient *client)
void addUnbufferedSurface()
void sendPropertyNotifyEvent(int property, int state)
void name_region(const QWSRegionNameCommand *)
static QAuServer & server()
Definition: qsound.cpp:79
void invokePlaySound(QWSPlaySoundCommand *cmd, QWSClient *client)
Q_CORE_EXPORT void qFatal(const char *,...)
void dereferenceFont(QWSClientPrivate *client, const QByteArray &font)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
~QWSServer()
Destructs this server.
static void setMaxWindowRect(const QRect &)
Sets the maximum area of the screen that Qt for Embedded Linux applications can use, to be the given rectangle.
virtual void blank(bool on)
Prevents the screen driver form displaying any content on the screen.
QWSCursor * cursor
int winId() const
Returns the window&#39;s ID.
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void setRects(const QRect *rect, int num)
Sets the region using the array of rectangles specified by rects and number.
Definition: qregion.cpp:4424
void invokeFont(const QWSFontCommand *cmd, QWSClient *client)
void releaseKeyboard(QWSWindow *w)
static void addKeyboardFilter(KeyboardFilter *f)
Activates the given keyboard filter all key events generated by physical keyboard drivers (i...
QByteArray qws_display_spec
virtual ~QWSScreenSaver()
Reimplement this function to destroy the screensaver.
void doClient(QWSClient *)
void initServer(int flags)
State state() const
Returns the current state of the window.
The QWSServer class encapsulates a server process in Qt for Embedded Linux.
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
static const QList< QWSMouseHandler * > & mouseHandlers()
Returns list of all mouse handlers.
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
static void setKeyboardHandler(QWSKeyboardHandler *kh)
Sets the primary keyboard driver to be the given driver.
#define QWS_SOCK_BASE
Definition: qwsutils_qws.h:54
QRegion dirtyOnScreen() const
Returns the region that has been repainted since the previous QScreen::exposeRegion(), and needs to be copied to the screen.
int deviceHeight() const
Returns the full height of the framebuffer device in pixels.
Definition: qscreen_qws.h:234
const QBrush & backgroundBrush() const
Returns the brush used as background in the absence of obscuring windows.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
bool isOpaque() const
Returns true if the QWSWindowSurface::Opaque is set; otherwise returns false.
void set_opacity(const QWSSetOpacityCommand *)
virtual ~QWSInputMethod()
Destroys this input method, uninstalling it if it is installed.
void invokeSetProperty(QWSSetPropertyCommand *cmd)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void invokeSetFocus(const QWSRequestFocusCommand *cmd, QWSClient *client)
int clientId() const
Returns an integer uniquely identfying this client.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QList< QWSWindow * > windows
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
virtual bool isTransformed() const
Returns true if the screen is transformed (for instance, rotated 90 degrees); otherwise returns false...
struct QWSDefineCursorCommand::SimpleData simpleData
QWSClient * c
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
bool isRegionReserved() const
Returns true if the QWSWindowSurface::RegionReserved is set; otherwise returns false.
static void ignoreSignal(int)
void shuttingDown()
void qt_client_enqueue(const QWSEvent *)
#define MOUSE
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QList< QWSInternalWindowInfo * > * windowList()
struct QWSServerPrivate::SelectionOwner::Time time
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
static QWSWindow * current_IM_composing_win
static const QMetaObjectPrivate * priv(const uint *data)
void invokeIdentify(const QWSIdentifyCommand *cmd, QWSClient *client)
static int global_focus_time_counter
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setClient(QObject *)
QFactoryLoader * l
QWSWindowSurface * windowSurface() const
void sendFontRemovedEvent(const QByteArray &font)
QWSWindow * mouseGrabber
struct QWSGrabMouseCommand::SimpleData simpleData
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
virtual void shutdownDevice()
This function is called by the Qt for Embedded Linux server before it calls the disconnect() function...
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
void destroy_region(const QWSRegionDestroyCommand *)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
static void resetInputMethod()
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
quint16 index
void screenSave(int level)
virtual int transformOrientation() const
Returns the current rotation as an integer value.
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QObject * parent
Definition: qobject.h:92
static void setScreenSaverInterval(int)
Sets the timeout interval for the screensaver to the specified milliseconds.
void sendCommitString(const QString &commitString, int replaceFrom=0, int replaceLength=0)
Sends an event encapsulating the given commitString, to the focus widget.
static QPoint mousePosition
static QWSWindow * keyboardGrabber
QByteArray fontName
void repaint_region(int winId, int windowFlags, bool opaque, const QRegion &)
static void endDisplayReconfigure()
void lower()
Lowers the window below other windows.
void stopEmbed(QWSWindow *window)
void connectionClosed()
void invokeSetAltitude(const QWSChangeAltitudeCommand *cmd, QWSClient *client)
friend class QWSWindow
QString errorString()
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
bool get_property(int winId, int property, const char *&data, int &len)
const QString & caption() const
Returns the window&#39;s caption.
void operation(QWSWindowOperationEvent::Operation o)
void sendConnectedEvent(const char *display_spec)
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
Definition: qregion.cpp:4116
bool remove(const QString &fileName)
Removes the file, fileName.
Definition: qdir.cpp:1751
T take(const Key &key)
Removes the item with the key key from the map and returns the value associated with it...
Definition: qmap.h:692
struct QWSConvertSelectionCommand::SimpleData simpleData
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QWSWindow::State state
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
Authenticate a message transport.
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
virtual void setPermanentState(const QByteArray &state)
Implement this function to attach a server-side surface instance to the corresponding client side ins...
void qt_init_display()
const QString & name() const
Returns the window&#39;s name, which is taken from the QWidget::objectName() at the time of QWidget::show...
int replacementLength() const
Returns the number of characters to be replaced in the preedit string.
Definition: qevent.h:459
QWSMouseHandler * newMouseHandler(const QString &spec)
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
struct QWSFontCommand::SimpleData simpleData
static void emergency_cleanup()
Q_GUI_EXPORT QScreenCursor * qt_screencursor
Definition: qscreen_qws.cpp:67
static void registerChannel(const QString &ch, QWSClient *cl)
Server side: subscribe client cl on channel ch.
The QTimer class provides repetitive and single-shot timers.
Definition: qtimer.h:56
struct QWSGrabKeyboardCommand::SimpleData simpleData
static void ungrab()
QWSServer(int flags=0, QObject *parent=0)
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
bool isOpaque() const
Returns true if the window is opaque, i.
virtual void exposeRegion(QRegion r, int changing)
This function is called by the Qt for Embedded Linux server whenever a screen update is required...
struct QWSIdentifyCommand::SimpleData simpleData
QImageIOHandler * handler
bool forClient(const QWSClient *cl) const
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
static int get_object_id(int count=1)
QIODevice * passThroughByClient(QWSClient *) const
virtual void show()
Shows the mouse cursor.
void stop()
Stops the timer.
Definition: qtimer.cpp:284
struct QWSRemovePropertyCommand::SimpleData simpleData
static bool force_reject_strokeIM
void openMouse()
Opens the mouse devices specified by the QWS_MOUSE_PROTO environment variable.
QWSClient(QObject *parent, QWS_SOCK_BASE *, int id)
void invokeRepaintRegion(QWSRepaintRegionCommand *cmd, QWSClient *client)
QRegion paintedRegion() const
Returns the region that the window is known to have drawn into.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
#define QT_TRY
Definition: qglobal.h:1536
The QWSClient class encapsulates a client process in Qt for Embedded Linux.
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
struct QWSGetPropertyCommand::SimpleData simpleData
void setCaption(const QString &c)
Sets the window&#39;s caption to c.
static void sendKeyEventUnfiltered(int unicode, int keycode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
struct QWSIMUpdateCommand::SimpleData simpleData
void setFocus(QWSWindow *, bool gain)
static void setMouseHandler(QWSMouseHandler *)
Sets the primary mouse driver to be the given driver.
struct QWSRegionCommand::SimpleData simpleData
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
static QList< QWSServer::KeyboardFilter * > * keyFilters
QWSServer Q_GUI_EXPORT * qwsServer
static QTransportAuth * getInstance()
Return a pointer to the instance of this process&#39;s QTransportAuth object.
void request_region(int winId, const QString &surfaceKey, const QByteArray &surfaceData, const QRegion &region)
void setScreen(const QScreen *screen)
Sets the screen for this mouse driver to be the given screen.
Definition: qmouse_qws.cpp:264
const QList< QWSWindow * > & clientWindows()
Returns the list of current top-level windows.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static Qt::KeyboardModifiers oldstate
Definition: qdnd_qws.cpp:87
void send_im_mouse(const QWSIMMouseCommand *)
The QWSInputMethod class provides international input methods in Qt for Embedded Linux.
void setCursor(QWSCursor *curs)
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
struct QWSConnectedEvent::SimpleData simpleData
void invokeScreenTransform(const QWSScreenTransformCommand *cmd, QWSClient *client)
static QWSMouseHandler * mouseHandler()
Returns the primary mouse driver.