• Skip to content
  • Skip to link menu
KDE 4.4 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 #include <fixx11h.h>
00025 
00026 
00027 /*
00028  * This class is a QWidget because we need an X window to
00029  * be able to receive XFixes events. We don't actually map
00030  * the widget.
00031  */
00032 
00033 CursorNotificationHandler::CursorNotificationHandler()
00034     : QWidget(), currentName(0)
00035 {
00036     Display *dpy = QX11Info::display();
00037     int errorBase;
00038     haveXfixes = false;
00039 
00040     // Request cursor change notification events
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         // Xfixes doesn't have a request for getting the current cursor name,
00068         // but it's included in the XFixesCursorImage struct.
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     // XGetAtomName() is a synchronous call, so we cache the name
00083     // in an atom<->string map the first time we see a name
00084     // to keep the X server round trips down.
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 

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
  • System Settings
  •   SystemSettingsView
Generated for API Reference by doxygen 1.5.9-20090814
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