Plasma
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 #include <fixx11h.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033 CursorNotificationHandler::CursorNotificationHandler()
00034 : QWidget(), currentName(0)
00035 {
00036 Display *dpy = QX11Info::display();
00037 int errorBase;
00038 haveXfixes = false;
00039
00040
00041 if (XFixesQueryExtension(dpy, &fixesEventBase, &errorBase))
00042 {
00043 int major, minor;
00044 XFixesQueryVersion(dpy, &major, &minor);
00045
00046 if (major >= 2)
00047 {
00048 XFixesSelectCursorInput(dpy, winId(), XFixesDisplayCursorNotifyMask);
00049 haveXfixes = true;
00050 }
00051 }
00052 }
00053
00054
00055 CursorNotificationHandler::~CursorNotificationHandler()
00056 {
00057 }
00058
00059
00060 QString CursorNotificationHandler::cursorName()
00061 {
00062 if (!haveXfixes)
00063 return QString();
00064
00065 if (!currentName)
00066 {
00067
00068
00069 XFixesCursorImage *image = XFixesGetCursorImage(QX11Info::display());
00070 currentName = image->atom;
00071 XFree(image);
00072 }
00073
00074 return cursorName(currentName);
00075 }
00076
00077
00078 QString CursorNotificationHandler::cursorName(Atom cursor)
00079 {
00080 QString name;
00081
00082
00083
00084
00085 if (names.contains(cursor))
00086 name = names[cursor];
00087 else
00088 {
00089 char *data = XGetAtomName(QX11Info::display(), cursor);
00090 name = QString::fromUtf8(data);
00091 XFree(data);
00092
00093 names.insert(cursor, name);
00094 }
00095
00096 return name;
00097 }
00098
00099
00100 bool CursorNotificationHandler::x11Event(XEvent* event)
00101 {
00102 if (event->type != fixesEventBase + XFixesCursorNotify)
00103 return false;
00104
00105 XFixesCursorNotifyEvent *xfe = reinterpret_cast<XFixesCursorNotifyEvent*>(event);
00106 currentName = xfe->cursor_name;
00107
00108 emit cursorNameChanged(cursorName(currentName));
00109
00110 return false;
00111 }
00112
00113 #include "cursornotificationhandler.moc"
00114