source: trunk/src/gui/kernel/qcursor_x11.cpp@ 106

Last change on this file since 106 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 23.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <qdatastream.h>
43#include <private/qcursor_p.h>
44#include <private/qt_x11_p.h>
45#include <qbitmap.h>
46#include <qcursor.h>
47#include <X11/cursorfont.h>
48
49#include <qlibrary.h>
50
51#ifndef QT_NO_XCURSOR
52# include <X11/Xcursor/Xcursor.h>
53#endif // QT_NO_XCURSOR
54
55#ifndef QT_NO_XFIXES
56# include <X11/extensions/Xfixes.h>
57#endif // QT_NO_XFIXES
58
59#include "qx11info_x11.h"
60
61QT_BEGIN_NAMESPACE
62
63// Define QT_USE_APPROXIMATE_CURSORS when compiling if you REALLY want to
64// use the ugly X11 cursors.
65
66extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp
67
68/*****************************************************************************
69 Internal QCursorData class
70 *****************************************************************************/
71
72QCursorData::QCursorData(Qt::CursorShape s)
73 : cshape(s), bm(0), bmm(0), hx(0), hy(0), hcurs(0), pm(0), pmm(0)
74{
75 ref = 1;
76}
77
78QCursorData::~QCursorData()
79{
80 Display *dpy = X11 ? X11->display : (Display*)0;
81
82 // Add in checking for the display too as on HP-UX
83 // we seem to get a core dump as the cursor data is
84 // deleted again from main() on exit...
85 if (hcurs && dpy)
86 XFreeCursor(dpy, hcurs);
87 if (pm && dpy)
88 XFreePixmap(dpy, pm);
89 if (pmm && dpy)
90 XFreePixmap(dpy, pmm);
91 delete bm;
92 delete bmm;
93}
94
95#ifndef QT_NO_CURSOR
96QCursor::QCursor(Qt::HANDLE cursor)
97{
98 if (!QCursorData::initialized)
99 QCursorData::initialize();
100 d = new QCursorData(Qt::CustomCursor);
101 d->hcurs = cursor;
102}
103#endif
104
105QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
106{
107 if (!QCursorData::initialized)
108 QCursorData::initialize();
109 if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
110 qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
111 QCursorData *c = qt_cursorTable[0];
112 c->ref.ref();
113 return c;
114 }
115 QCursorData *d = new QCursorData;
116 d->ref = 1;
117
118 extern QPixmap qt_toX11Pixmap(const QPixmap &pixmap); // qpixmap_x11.cpp
119 d->bm = new QBitmap(qt_toX11Pixmap(bitmap));
120 d->bmm = new QBitmap(qt_toX11Pixmap(mask));
121
122 d->hcurs = 0;
123 d->cshape = Qt::BitmapCursor;
124 d->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
125 d->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
126 d->fg.red = 0x0000;
127 d->fg.green = 0x0000;
128 d->fg.blue = 0x0000;
129 d->bg.red = 0xffff;
130 d->bg.green = 0xffff;
131 d->bg.blue = 0xffff;
132 return d;
133}
134
135
136
137#ifndef QT_NO_CURSOR
138Qt::HANDLE QCursor::handle() const
139{
140 if (!QCursorData::initialized)
141 QCursorData::initialize();
142 if (!d->hcurs)
143 d->update();
144 return d->hcurs;
145}
146#endif
147
148QPoint QCursor::pos()
149{
150 Window root;
151 Window child;
152 int root_x, root_y, win_x, win_y;
153 uint buttons;
154 Display* dpy = X11->display;
155 for (int i = 0; i < ScreenCount(dpy); ++i) {
156 if (XQueryPointer(dpy, QX11Info::appRootWindow(i), &root, &child, &root_x, &root_y,
157 &win_x, &win_y, &buttons))
158
159 return QPoint(root_x, root_y);
160 }
161 return QPoint();
162}
163
164/*! \internal
165*/
166#ifndef QT_NO_CURSOR
167int QCursor::x11Screen()
168{
169 Window root;
170 Window child;
171 int root_x, root_y, win_x, win_y;
172 uint buttons;
173 Display* dpy = X11->display;
174 for (int i = 0; i < ScreenCount(dpy); ++i) {
175 if (XQueryPointer(dpy, QX11Info::appRootWindow(i), &root, &child, &root_x, &root_y,
176 &win_x, &win_y, &buttons))
177 return i;
178 }
179 return -1;
180}
181#endif
182
183void QCursor::setPos(int x, int y)
184{
185 QPoint current, target(x, y);
186
187 // this is copied from pos(), since we need the screen number for the correct
188 // root window in the XWarpPointer call
189 Window root;
190 Window child;
191 int root_x, root_y, win_x, win_y;
192 uint buttons;
193 Display* dpy = X11->display;
194 int screen;
195 for (screen = 0; screen < ScreenCount(dpy); ++screen) {
196 if (XQueryPointer(dpy, QX11Info::appRootWindow(screen), &root, &child, &root_x, &root_y,
197 &win_x, &win_y, &buttons)) {
198 current = QPoint(root_x, root_y);
199 break;
200 }
201 }
202
203 if (screen >= ScreenCount(dpy))
204 return;
205
206 // Need to check, since some X servers generate null mouse move
207 // events, causing looping in applications which call setPos() on
208 // every mouse move event.
209 //
210 if (current == target)
211 return;
212
213 XWarpPointer(X11->display, XNone, QX11Info::appRootWindow(screen), 0, 0, 0, 0, x, y);
214}
215
216
217/*!
218 \internal
219
220 Creates the cursor.
221*/
222
223void QCursorData::update()
224{
225 if (!QCursorData::initialized)
226 QCursorData::initialize();
227 if (hcurs)
228 return;
229
230 Display *dpy = X11->display;
231 Window rootwin = QX11Info::appRootWindow();
232
233 if (cshape == Qt::BitmapCursor) {
234 extern QPixmap qt_toX11Pixmap(const QPixmap &pixmap); // qpixmap_x11.cpp
235#ifndef QT_NO_XRENDER
236 if (!pixmap.isNull() && X11->use_xrender) {
237 pixmap = qt_toX11Pixmap(pixmap);
238 hcurs = XRenderCreateCursor (X11->display, pixmap.x11PictureHandle(), hx, hy);
239 } else
240#endif
241 {
242 hcurs = XCreatePixmapCursor(dpy, bm->handle(), bmm->handle(), &fg, &bg, hx, hy);
243 }
244 return;
245 }
246
247 static const char *cursorNames[] = {
248 "left_ptr",
249 "up_arrow",
250 "cross",
251 "wait",
252 "ibeam",
253 "size_ver",
254 "size_hor",
255 "size_bdiag",
256 "size_fdiag",
257 "size_all",
258 "blank",
259 "split_v",
260 "split_h",
261 "pointing_hand",
262 "forbidden",
263 "whats_this",
264 "left_ptr_watch",
265 "openhand",
266 "closedhand"
267 };
268
269#ifndef QT_NO_XCURSOR
270 if (X11->ptrXcursorLibraryLoadCursor)
271 hcurs = X11->ptrXcursorLibraryLoadCursor(dpy, cursorNames[cshape]);
272 if (hcurs)
273 return;
274#endif // QT_NO_XCURSOR
275
276 static const char cur_blank_bits[] = {
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
280
281 // Non-standard X11 cursors are created from bitmaps
282
283#ifndef QT_USE_APPROXIMATE_CURSORS
284 static const char cur_ver_bits[] = {
285 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
286 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xf0, 0x0f,
287 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00 };
288 static const char mcur_ver_bits[] = {
289 0x00, 0x00, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f,
290 0xfc, 0x7f, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xfc, 0x7f, 0xf8, 0x3f,
291 0xf0, 0x1f, 0xe0, 0x0f, 0xc0, 0x07, 0x80, 0x03 };
292 static const char cur_hor_bits[] = {
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x30, 0x18,
294 0x38, 0x38, 0xfc, 0x7f, 0xfc, 0x7f, 0x38, 0x38, 0x30, 0x18, 0x20, 0x08,
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
296 static const char mcur_hor_bits[] = {
297 0x00, 0x00, 0x00, 0x00, 0x40, 0x04, 0x60, 0x0c, 0x70, 0x1c, 0x78, 0x3c,
298 0xfc, 0x7f, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfc, 0x7f, 0x78, 0x3c,
299 0x70, 0x1c, 0x60, 0x0c, 0x40, 0x04, 0x00, 0x00 };
300 static const char cur_bdiag_bits[] = {
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e,
302 0x00, 0x37, 0x88, 0x23, 0xd8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0xf8, 0x00,
303 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
304 static const char mcur_bdiag_bits[] = {
305 0x00, 0x00, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7f, 0x00, 0x7e, 0x04, 0x7f,
306 0x8c, 0x7f, 0xdc, 0x77, 0xfc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01,
307 0xfc, 0x03, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00 };
308 static const char cur_fdiag_bits[] = {
309 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00,
310 0xf8, 0x00, 0xd8, 0x01, 0x88, 0x23, 0x00, 0x37, 0x00, 0x3e, 0x00, 0x3c,
311 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00 };
312 static const char mcur_fdiag_bits[] = {
313 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00,
314 0xfc, 0x41, 0xfc, 0x63, 0xdc, 0x77, 0x8c, 0x7f, 0x04, 0x7f, 0x00, 0x7e,
315 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x7f, 0x00, 0x00 };
316 static const char *cursor_bits16[] = {
317 cur_ver_bits, mcur_ver_bits, cur_hor_bits, mcur_hor_bits,
318 cur_bdiag_bits, mcur_bdiag_bits, cur_fdiag_bits, mcur_fdiag_bits,
319 0, 0, cur_blank_bits, cur_blank_bits };
320
321 static const char vsplit_bits[] = {
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00,
325 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
326 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
328 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
329 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00,
330 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
333 static const char vsplitm_bits[] = {
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
336 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
337 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
338 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
339 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
340 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
341 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00,
342 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
345 static const char hsplit_bits[] = {
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
348 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
349 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
350 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03,
351 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00,
352 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
353 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
357 static const char hsplitm_bits[] = {
358 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
360 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
361 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00,
362 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
363 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00,
364 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
365 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
369 static const char whatsthis_bits[] = {
370 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0xf0, 0x07, 0x00,
371 0x09, 0x18, 0x0e, 0x00, 0x11, 0x1c, 0x0e, 0x00, 0x21, 0x1c, 0x0e, 0x00,
372 0x41, 0x1c, 0x0e, 0x00, 0x81, 0x1c, 0x0e, 0x00, 0x01, 0x01, 0x07, 0x00,
373 0x01, 0x82, 0x03, 0x00, 0xc1, 0xc7, 0x01, 0x00, 0x49, 0xc0, 0x01, 0x00,
374 0x95, 0xc0, 0x01, 0x00, 0x93, 0xc0, 0x01, 0x00, 0x21, 0x01, 0x00, 0x00,
375 0x20, 0xc1, 0x01, 0x00, 0x40, 0xc2, 0x01, 0x00, 0x40, 0x02, 0x00, 0x00,
376 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
378 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
379 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
380 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
381 static const char whatsthism_bits[] = {
382 0x01, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x07, 0x00, 0x07, 0xf8, 0x0f, 0x00,
383 0x0f, 0xfc, 0x1f, 0x00, 0x1f, 0x3e, 0x1f, 0x00, 0x3f, 0x3e, 0x1f, 0x00,
384 0x7f, 0x3e, 0x1f, 0x00, 0xff, 0x3e, 0x1f, 0x00, 0xff, 0x9d, 0x0f, 0x00,
385 0xff, 0xc3, 0x07, 0x00, 0xff, 0xe7, 0x03, 0x00, 0x7f, 0xe0, 0x03, 0x00,
386 0xf7, 0xe0, 0x03, 0x00, 0xf3, 0xe0, 0x03, 0x00, 0xe1, 0xe1, 0x03, 0x00,
387 0xe0, 0xe1, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00,
388 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
393 static const char busy_bits[] = {
394 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
395 0x09, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
396 0x41, 0xe0, 0xff, 0x00, 0x81, 0x20, 0x80, 0x00, 0x01, 0xe1, 0xff, 0x00,
397 0x01, 0x42, 0x40, 0x00, 0xc1, 0x47, 0x40, 0x00, 0x49, 0x40, 0x55, 0x00,
398 0x95, 0x80, 0x2a, 0x00, 0x93, 0x00, 0x15, 0x00, 0x21, 0x01, 0x0a, 0x00,
399 0x20, 0x01, 0x11, 0x00, 0x40, 0x82, 0x20, 0x00, 0x40, 0x42, 0x44, 0x00,
400 0x80, 0x41, 0x4a, 0x00, 0x00, 0x40, 0x55, 0x00, 0x00, 0xe0, 0xff, 0x00,
401 0x00, 0x20, 0x80, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
405 static const char busym_bits[] = {
406 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
407 0x0f, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
408 0x7f, 0xe0, 0xff, 0x00, 0xff, 0xe0, 0xff, 0x00, 0xff, 0xe1, 0xff, 0x00,
409 0xff, 0xc3, 0x7f, 0x00, 0xff, 0xc7, 0x7f, 0x00, 0x7f, 0xc0, 0x7f, 0x00,
410 0xf7, 0x80, 0x3f, 0x00, 0xf3, 0x00, 0x1f, 0x00, 0xe1, 0x01, 0x0e, 0x00,
411 0xe0, 0x01, 0x1f, 0x00, 0xc0, 0x83, 0x3f, 0x00, 0xc0, 0xc3, 0x7f, 0x00,
412 0x80, 0xc1, 0x7f, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0xe0, 0xff, 0x00,
413 0x00, 0xe0, 0xff, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
414 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
415 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
417
418 static const char * const cursor_bits32[] = {
419 vsplit_bits, vsplitm_bits, hsplit_bits, hsplitm_bits,
420 0, 0, 0, 0, whatsthis_bits, whatsthism_bits, busy_bits, busym_bits
421 };
422
423 static const char forbidden_bits[] = {
424 0x00,0x00,0x00,0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xf0,0x00,0x38,0xc0,0x01,
425 0x7c,0x80,0x03,0xec,0x00,0x03,0xce,0x01,0x07,0x86,0x03,0x06,0x06,0x07,0x06,
426 0x06,0x0e,0x06,0x06,0x1c,0x06,0x0e,0x38,0x07,0x0c,0x70,0x03,0x1c,0xe0,0x03,
427 0x38,0xc0,0x01,0xf0,0xe0,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00,0x00,0x00,0x00 };
428
429 static const char forbiddenm_bits[] = {
430 0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xff,0x00,0xf8,0xff,0x01,0xfc,0xf0,0x03,
431 0xfe,0xc0,0x07,0xfe,0x81,0x07,0xff,0x83,0x0f,0xcf,0x07,0x0f,0x8f,0x0f,0x0f,
432 0x0f,0x1f,0x0f,0x0f,0x3e,0x0f,0x1f,0xfc,0x0f,0x1e,0xf8,0x07,0x3e,0xf0,0x07,
433 0xfc,0xe0,0x03,0xf8,0xff,0x01,0xf0,0xff,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00};
434
435 static const char openhand_bits[] = {
436 0x80,0x01,0x58,0x0e,0x64,0x12,0x64,0x52,0x48,0xb2,0x48,0x92,
437 0x16,0x90,0x19,0x80,0x11,0x40,0x02,0x40,0x04,0x40,0x04,0x20,
438 0x08,0x20,0x10,0x10,0x20,0x10,0x00,0x00};
439 static const char openhandm_bits[] = {
440 0x80,0x01,0xd8,0x0f,0xfc,0x1f,0xfc,0x5f,0xf8,0xff,0xf8,0xff,
441 0xf6,0xff,0xff,0xff,0xff,0x7f,0xfe,0x7f,0xfc,0x7f,0xfc,0x3f,
442 0xf8,0x3f,0xf0,0x1f,0xe0,0x1f,0x00,0x00};
443 static const char closedhand_bits[] = {
444 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0x48,0x32,0x08,0x50,
445 0x10,0x40,0x18,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10,
446 0x20,0x10,0x20,0x10,0x00,0x00,0x00,0x00};
447 static const char closedhandm_bits[] = {
448 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0xf8,0x3f,0xf8,0x7f,
449 0xf0,0x7f,0xf8,0x7f,0xfc,0x7f,0xfc,0x3f,0xf8,0x3f,0xf0,0x1f,
450 0xe0,0x1f,0xe0,0x1f,0x00,0x00,0x00,0x00};
451
452 static const char * const cursor_bits20[] = {
453 forbidden_bits, forbiddenm_bits
454 };
455
456 if ((cshape >= Qt::SizeVerCursor && cshape < Qt::SizeAllCursor)
457 || cshape == Qt::BlankCursor) {
458 XColor bg, fg;
459 bg.red = 255 << 8;
460 bg.green = 255 << 8;
461 bg.blue = 255 << 8;
462 fg.red = 0;
463 fg.green = 0;
464 fg.blue = 0;
465 int i = (cshape - Qt::SizeVerCursor) * 2;
466 pm = XCreateBitmapFromData(dpy, rootwin, cursor_bits16[i], 16, 16);
467 pmm = XCreateBitmapFromData(dpy, rootwin, cursor_bits16[i + 1], 16, 16);
468 hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8);
469 } else if ((cshape >= Qt::SplitVCursor && cshape <= Qt::SplitHCursor)
470 || cshape == Qt::WhatsThisCursor || cshape == Qt::BusyCursor) {
471 XColor bg, fg;
472 bg.red = 255 << 8;
473 bg.green = 255 << 8;
474 bg.blue = 255 << 8;
475 fg.red = 0;
476 fg.green = 0;
477 fg.blue = 0;
478 int i = (cshape - Qt::SplitVCursor) * 2;
479 pm = XCreateBitmapFromData(dpy, rootwin, cursor_bits32[i], 32, 32);
480 pmm = XCreateBitmapFromData(dpy, rootwin, cursor_bits32[i + 1], 32, 32);
481 int hs = (cshape == Qt::PointingHandCursor || cshape == Qt::WhatsThisCursor
482 || cshape == Qt::BusyCursor) ? 0 : 16;
483 hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, hs, hs);
484 } else if (cshape == Qt::ForbiddenCursor) {
485 XColor bg, fg;
486 bg.red = 255 << 8;
487 bg.green = 255 << 8;
488 bg.blue = 255 << 8;
489 fg.red = 0;
490 fg.green = 0;
491 fg.blue = 0;
492 int i = (cshape - Qt::ForbiddenCursor) * 2;
493 pm = XCreateBitmapFromData(dpy, rootwin, cursor_bits20[i], 20, 20);
494 pmm = XCreateBitmapFromData(dpy, rootwin, cursor_bits20[i + 1], 20, 20);
495 hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 10, 10);
496 } else if (cshape == Qt::OpenHandCursor || cshape == Qt::ClosedHandCursor) {
497 XColor bg, fg;
498 bg.red = 255 << 8;
499 bg.green = 255 << 8;
500 bg.blue = 255 << 8;
501 fg.red = 0;
502 fg.green = 0;
503 fg.blue = 0;
504 bool open = cshape == Qt::OpenHandCursor;
505 pm = XCreateBitmapFromData(dpy, rootwin, open ? openhand_bits : closedhand_bits, 16, 16);
506 pmm = XCreateBitmapFromData(dpy, rootwin, open ? openhandm_bits : closedhandm_bits, 16, 16);
507 hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8);
508 }
509
510 if (hcurs)
511 {
512#ifndef QT_NO_XFIXES
513 if (X11->use_xfixes && X11->ptrXFixesSetCursorName)
514 X11->ptrXFixesSetCursorName(dpy, hcurs, cursorNames[cshape]);
515#endif /* ! QT_NO_XFIXES */
516 return;
517 }
518
519#endif /* ! QT_USE_APPROXIMATE_CURSORS */
520
521 uint sh;
522 switch (cshape) { // map Q cursor to X cursor
523 case Qt::ArrowCursor:
524 sh = XC_left_ptr;
525 break;
526 case Qt::UpArrowCursor:
527 sh = XC_center_ptr;
528 break;
529 case Qt::CrossCursor:
530 sh = XC_crosshair;
531 break;
532 case Qt::WaitCursor:
533 sh = XC_watch;
534 break;
535 case Qt::IBeamCursor:
536 sh = XC_xterm;
537 break;
538 case Qt::SizeAllCursor:
539 sh = XC_fleur;
540 break;
541 case Qt::PointingHandCursor:
542 sh = XC_hand2;
543 break;
544#ifdef QT_USE_APPROXIMATE_CURSORS
545 case Qt::SizeBDiagCursor:
546 sh = XC_top_right_corner;
547 break;
548 case Qt::SizeFDiagCursor:
549 sh = XC_bottom_right_corner;
550 break;
551 case Qt::BlankCursor:
552 XColor bg, fg;
553 bg.red = 255 << 8;
554 bg.green = 255 << 8;
555 bg.blue = 255 << 8;
556 fg.red = 0;
557 fg.green = 0;
558 fg.blue = 0;
559 pm = XCreateBitmapFromData(dpy, rootwin, cur_blank_bits, 16, 16);
560 pmm = XCreateBitmapFromData(dpy, rootwin, cur_blank_bits, 16, 16);
561 hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8);
562 return;
563 break;
564 case Qt::SizeVerCursor:
565 case Qt::SplitVCursor:
566 sh = XC_sb_v_double_arrow;
567 break;
568 case Qt::SizeHorCursor:
569 case Qt::SplitHCursor:
570 sh = XC_sb_h_double_arrow;
571 break;
572 case Qt::WhatsThisCursor:
573 sh = XC_question_arrow;
574 break;
575 case Qt::ForbiddenCursor:
576 sh = XC_circle;
577 break;
578 case Qt::BusyCursor:
579 sh = XC_watch;
580 break;
581#endif /* QT_USE_APPROXIMATE_CURSORS */
582 default:
583 qWarning("QCursor::update: Invalid cursor shape %d", cshape);
584 return;
585 }
586 hcurs = XCreateFontCursor(dpy, sh);
587
588#ifndef QT_NO_XFIXES
589 if (X11->use_xfixes && X11->ptrXFixesSetCursorName)
590 X11->ptrXFixesSetCursorName(dpy, hcurs, cursorNames[cshape]);
591#endif /* ! QT_NO_XFIXES */
592}
593
594QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.