Engines
cursornotificationhandler.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "cursornotificationhandler.h"
00020
00021 #include <QX11Info>
00022
00023 #include <X11/extensions/Xfixes.h>
00024
00025
00026
00027
00028
00029
00030
00031
00032 CursorNotificationHandler::CursorNotificationHandler()
00033 : QWidget(), currentName(0)
00034 {
00035 Display *dpy = QX11Info::display();
00036 int errorBase;
00037 haveXfixes = false;
00038
00039
00040 if (XFixesQueryExtension(dpy, &fixesEventBase, &errorBase))
00041 {
00042 int major, minor;
00043 XFixesQueryVersion(dpy, &major, &minor);
00044
00045 if (major >= 2)
00046 {
00047 XFixesSelectCursorInput(dpy, winId(), XFixesDisplayCursorNotifyMask);
00048 haveXfixes = true;
00049 }
00050 }
00051 }
00052
00053
00054 CursorNotificationHandler::~CursorNotificationHandler()
00055 {
00056 }
00057
00058
00059 QString CursorNotificationHandler::cursorName()
00060 {
00061 if (!haveXfixes)
00062 return QString();
00063
00064 if (!currentName)
00065 {
00066
00067
00068 XFixesCursorImage *image = XFixesGetCursorImage(QX11Info::display());
00069 currentName = image->atom;
00070 XFree(image);
00071 }
00072
00073 return cursorName(currentName);
00074 }
00075
00076
00077 QString CursorNotificationHandler::cursorName(Atom cursor)
00078 {
00079 QString name;
00080
00081
00082
00083
00084 if (names.contains(cursor))
00085 name = names[cursor];
00086 else
00087 {
00088 char *data = XGetAtomName(QX11Info::display(), cursor);
00089 name = QString::fromUtf8(data);
00090 XFree(data);
00091
00092 names.insert(cursor, name);
00093 }
00094
00095 return name;
00096 }
00097
00098
00099 bool CursorNotificationHandler::x11Event(XEvent* event)
00100 {
00101 if (event->type != fixesEventBase + XFixesCursorNotify)
00102 return false;
00103
00104 XFixesCursorNotifyEvent *xfe = reinterpret_cast<XFixesCursorNotifyEvent*>(event);
00105 currentName = xfe->cursor_name;
00106
00107 emit cursorNameChanged(cursorName(currentName));
00108
00109 return false;
00110 }
00111
00112 #include "cursornotificationhandler.moc"
00113