• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

cursornotificationhandler.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright © 2007 Fredrik Höglund <fredrik@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License version 2 as
00006  *   published by the Free Software Foundation
00007  *
00008  *   This program is distributed in the hope that it will be useful,
00009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *   GNU General Public License for more details
00012  *
00013  *   You should have received a copy of the GNU Library General Public
00014  *   License along with this program; if not, write to the
00015  *   Free Software Foundation, Inc.,
00016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017  */
00018 
00019 #include "cursornotificationhandler.h"
00020 
00021 #include <QX11Info>
00022 
00023 #include <X11/extensions/Xfixes.h>
00024 
00025 
00026 /*
00027  * This class is a QWidget because we need an X window to
00028  * be able to receive XFixes events. We don't actually map
00029  * the widget.
00030  */
00031 
00032 CursorNotificationHandler::CursorNotificationHandler()
00033     : QWidget(), currentName(0)
00034 {
00035     Display *dpy = QX11Info::display();
00036     int errorBase;
00037     haveXfixes = false;
00038 
00039     // Request cursor change notification events
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         // Xfixes doesn't have a request for getting the current cursor name,
00067         // but it's included in the XFixesCursorImage struct.
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     // XGetAtomName() is a synchronous call, so we cache the name
00082     // in an atom<->string map the first time we see a name
00083     // to keep the X server round trips down.
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 

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal