2
* Copyright © 2007 Fredrik Höglund <fredrik@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License version 2 as
6
* published by the Free Software Foundation
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details
13
* You should have received a copy of the GNU Library General Public
14
* License along with this program; if not, write to the
15
* Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include "cursornotificationhandler.h"
22
#include "cursornotificationhandler.moc"
24
#include <X11/extensions/Xfixes.h>
28
* This class is a QWidget because we need an X window to
29
* be able to receive XFixes events. We don't actually map
33
CursorNotificationHandler::CursorNotificationHandler()
34
: QWidget(), currentName(0)
36
Display *dpy = QX11Info::display();
40
// Request cursor change notification events
41
if (XFixesQueryExtension(dpy, &fixesEventBase, &errorBase))
44
XFixesQueryVersion(dpy, &major, &minor);
48
XFixesSelectCursorInput(dpy, winId(), XFixesDisplayCursorNotifyMask);
55
CursorNotificationHandler::~CursorNotificationHandler()
60
QString CursorNotificationHandler::cursorName()
67
// Xfixes doesn't have a request for getting the current cursor name,
68
// but it's included in the XFixesCursorImage struct.
69
XFixesCursorImage *image = XFixesGetCursorImage(QX11Info::display());
70
currentName = image->atom;
74
return cursorName(currentName);
78
QString CursorNotificationHandler::cursorName(Atom cursor)
82
// XGetAtomName() is a synchronous call, so we cache the name
83
// in an atom<->string map the first time we see a name
84
// to keep the X server round trips down.
85
if (names.contains(cursor))
89
char *data = XGetAtomName(QX11Info::display(), cursor);
90
name = QString::fromUtf8(data);
93
names.insert(cursor, name);
100
bool CursorNotificationHandler::x11Event(XEvent* event)
102
if (event->type != fixesEventBase + XFixesCursorNotify)
105
XFixesCursorNotifyEvent *xfe = reinterpret_cast<XFixesCursorNotifyEvent*>(event);
106
currentName = xfe->cursor_name;
108
emit cursorNameChanged(cursorName(currentName));