Qt 4.8
qwaylandcursor.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 plugins 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 "qwaylandcursor.h"
43 
44 #include "qwaylanddisplay.h"
45 #include "qwaylandinputdevice.h"
46 #include "qwaylandshmsurface.h"
47 #include "qwaylandscreen.h"
48 
49 #include <QtGui/QImageReader>
50 
51 #define DATADIR "/usr/share"
52 
53 static const struct pointer_image {
54  const char *filename;
56 } pointer_images[] = {
57  /* FIXME: Half of these are wrong... */
58  /* Qt::ArrowCursor */
59  { DATADIR "/wayland/left_ptr.png", 10, 5 },
60  /* Qt::UpArrowCursor */
61  { DATADIR "/wayland/top_side.png", 18, 8 },
62  /* Qt::CrossCursor */
63  { DATADIR "/wayland/top_side.png", 18, 8 },
64  /* Qt::WaitCursor */
65  { DATADIR "/wayland/top_side.png", 18, 8 },
66  /* Qt::IBeamCursor */
67  { DATADIR "/wayland/xterm.png", 15, 15 },
68  /* Qt::SizeVerCursor */
69  { DATADIR "/wayland/top_side.png", 18, 8 },
70  /* Qt::SizeHorCursor */
71  { DATADIR "/wayland/bottom_left_corner.png", 6, 30 },
72  /* Qt::SizeBDiagCursor */
73  { DATADIR "/wayland/bottom_right_corner.png", 28, 28 },
74  /* Qt::SizeFDiagCursor */
75  { DATADIR "/wayland/bottom_side.png", 16, 20 },
76  /* Qt::SizeAllCursor */
77  { DATADIR "/wayland/left_side.png", 10, 20 },
78  /* Qt::BlankCursor */
79  { DATADIR "/wayland/right_side.png", 30, 19 },
80  /* Qt::SplitVCursor */
81  { DATADIR "/wayland/sb_v_double_arrow.png", 15, 15 },
82  /* Qt::SplitHCursor */
83  { DATADIR "/wayland/sb_h_double_arrow.png", 15, 15 },
84  /* Qt::PointingHandCursor */
85  { DATADIR "/wayland/hand2.png", 14, 8 },
86  /* Qt::ForbiddenCursor */
87  { DATADIR "/wayland/top_right_corner.png", 26, 8 },
88  /* Qt::WhatsThisCursor */
89  { DATADIR "/wayland/top_right_corner.png", 26, 8 },
90  /* Qt::BusyCursor */
91  { DATADIR "/wayland/top_right_corner.png", 26, 8 },
92  /* Qt::OpenHandCursor */
93  { DATADIR "/wayland/hand1.png", 18, 11 },
94  /* Qt::ClosedHandCursor */
95  { DATADIR "/wayland/grabbing.png", 20, 17 },
96  /* Qt::DragCopyCursor */
97  { DATADIR "/wayland/dnd-copy.png", 13, 13 },
98  /* Qt::DragMoveCursor */
99  { DATADIR "/wayland/dnd-move.png", 13, 13 },
100  /* Qt::DragLinkCursor */
101  { DATADIR "/wayland/dnd-link.png", 13, 13 },
102 };
103 
105  : QPlatformCursor(screen)
106  , mBuffer(0)
107  , mDisplay(screen->display())
108 {
109 }
110 
112 {
113  const struct pointer_image *p;
114 
115  if (widget == NULL)
116  return;
117 
118  p = NULL;
119 
120  switch (cursor->shape()) {
121  case Qt::ArrowCursor:
122  p = &pointer_images[cursor->shape()];
123  break;
124  case Qt::UpArrowCursor:
125  case Qt::CrossCursor:
126  case Qt::WaitCursor:
127  break;
128  case Qt::IBeamCursor:
129  p = &pointer_images[cursor->shape()];
130  break;
131  case Qt::SizeVerCursor: /* 5 */
132  case Qt::SizeHorCursor:
133  case Qt::SizeBDiagCursor:
134  case Qt::SizeFDiagCursor:
135  case Qt::SizeAllCursor:
136  case Qt::BlankCursor: /* 10 */
137  break;
138  case Qt::SplitVCursor:
139  case Qt::SplitHCursor:
141  p = &pointer_images[cursor->shape()];
142  break;
143  case Qt::ForbiddenCursor:
144  case Qt::WhatsThisCursor: /* 15 */
145  case Qt::BusyCursor:
146  break;
147  case Qt::OpenHandCursor:
149  case Qt::DragCopyCursor:
150  case Qt::DragMoveCursor: /* 20 */
151  case Qt::DragLinkCursor:
152  p = &pointer_images[cursor->shape()];
153  break;
154 
155  default:
156  case Qt::BitmapCursor:
157  break;
158  }
159 
160  if (!p) {
161  p = &pointer_images[0];
162  qWarning("unhandled cursor %d", cursor->shape());
163  }
164 
165  QImageReader reader(p->filename);
166 
167  if (!reader.canRead())
168  return;
169 
170  if (mBuffer == NULL || mBuffer->size() != reader.size()) {
171  if (mBuffer)
172  delete mBuffer;
173 
174  mBuffer = new QWaylandShmBuffer(mDisplay, reader.size(),
176  }
177 
178  reader.read(mBuffer->image());
179 
181 }
182 
183 void QWaylandDisplay::setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y)
184 {
185  /* Qt doesn't tell us which input device we should set the cursor
186  * for, so set it for all devices. */
187  for (int i = 0; i < mInputDevices.count(); i++) {
188  QWaylandInputDevice *inputDevice = mInputDevices.at(i);
189  inputDevice->attach(buffer, x, y);
190  }
191 }
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
QPointer< QWidget > widget
QWaylandShmBuffer * mBuffer
The QPlatformCursor class provides information about pointer device events (movement, buttons), and requests to change the currently displayed cursor.
QWaylandCursor(QWaylandScreen *screen)
static const struct pointer_image pointer_images[]
void attach(QWaylandBuffer *buffer, int x, int y)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
const char * filename
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
void setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y)
Q_CORE_EXPORT void qWarning(const char *,...)
#define DATADIR
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
void changeCursor(QCursor *cursor, QWidget *widget)
This method is called by Qt whenever the cursor graphic should be changed.
QWaylandDisplay * mDisplay
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition: qcursor.cpp:469