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.
19 #include "cursornotificationhandler.h"
23 #include <X11/extensions/Xfixes.h>
27 * This class is a QWidget because we need an X window to
28 * be able to receive XFixes events. We don't actually map
32 CursorNotificationHandler::CursorNotificationHandler()
33 : QWidget(), currentName(0)
35 Display
*dpy
= QX11Info::display();
39 // Request cursor change notification events
40 if (XFixesQueryExtension(dpy
, &fixesEventBase
, &errorBase
))
43 XFixesQueryVersion(dpy
, &major
, &minor
);
47 XFixesSelectCursorInput(dpy
, winId(), XFixesDisplayCursorNotifyMask
);
54 CursorNotificationHandler::~CursorNotificationHandler()
59 QString
CursorNotificationHandler::cursorName()
66 // Xfixes doesn't have a request for getting the current cursor name,
67 // but it's included in the XFixesCursorImage struct.
68 XFixesCursorImage
*image
= XFixesGetCursorImage(QX11Info::display());
69 currentName
= image
->atom
;
73 return cursorName(currentName
);
77 QString
CursorNotificationHandler::cursorName(Atom cursor
)
81 // XGetAtomName() is a synchronous call, so we cache the name
82 // in an atom<->string map the first time we see a name
83 // to keep the X server round trips down.
84 if (names
.contains(cursor
))
88 char *data
= XGetAtomName(QX11Info::display(), cursor
);
89 name
= QString::fromUtf8(data
);
92 names
.insert(cursor
, name
);
99 bool CursorNotificationHandler::x11Event(XEvent
* event
)
101 if (event
->type
!= fixesEventBase
+ XFixesCursorNotify
)
104 XFixesCursorNotifyEvent
*xfe
= reinterpret_cast<XFixesCursorNotifyEvent
*>(event
);
105 currentName
= xfe
->cursor_name
;
107 emit
cursorNameChanged(cursorName(currentName
));
112 #include "cursornotificationhandler.moc"