Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kcontrol / input / kapplymousetheme.cpp
blobc9bc511b7e60d95f29fceaab6a89ef9e7c1a90e8
1 /*
2 * main.cpp
4 * Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
5 * Copyright (c) 2005 Lubos Lunak <l.lunak@kde.org>
7 * Requires the Qt widget libraries, available at no cost at
8 * http://www.troll.no/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <config-X11.h>
27 #include <QX11Info>
28 #include <stdlib.h>
29 #include <ctype.h>
30 #include <X11/Xlib.h>
32 #ifdef HAVE_XCURSOR
33 # include <X11/Xcursor/Xcursor.h>
34 #endif
36 static Display* dpy;
37 Display* QX11Info::display() { return dpy; }
38 Qt::HANDLE QX11Info::appRootWindow(int) { return DefaultRootWindow( dpy ); }
40 static bool isEmpty( const char* str )
42 if( str == NULL )
43 return true;
44 while( isspace( *str ))
45 ++str;
46 return *str == '\0';
49 int main( int argc, char* argv[] )
51 if( argc != 3 )
52 return 1;
53 dpy = XOpenDisplay( NULL );
54 if( dpy == NULL )
55 return 2;
56 int ret = 0;
57 #ifdef HAVE_XCURSOR
58 const char* theme = argv[ 1 ];
59 const char* size = argv[ 2 ];
61 // Note: If you update this code, update kapplymousetheme as well.
63 // use a default value for theme only if it's not configured at all, not even in X resources
64 if( isEmpty( theme )
65 && isEmpty( XGetDefault( QX11Info::display(), "Xcursor", "theme" ))
66 && isEmpty( XcursorGetTheme( QX11Info::display())))
68 theme = "default";
69 ret = 10; // means to switch to default
72 // Apply the KDE cursor theme to ourselves
73 if( !isEmpty( theme ))
74 XcursorSetTheme(QX11Info::display(), theme );
76 if (!isEmpty( size ))
77 XcursorSetDefaultSize(QX11Info::display(), atoi( size ));
79 // Load the default cursor from the theme and apply it to the root window.
80 Cursor handle = XcursorLibraryLoadCursor(QX11Info::display(), "left_ptr");
81 XDefineCursor(QX11Info::display(), QX11Info::appRootWindow(), handle);
82 XFreeCursor(QX11Info::display(), handle); // Don't leak the cursor
84 #else
85 ( void ) QX11Info::display();
86 ( void ) QX11Info::appRootWindow();
87 ( void ) argv;
88 #endif
89 XCloseDisplay( dpy );
90 return ret;