~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcontrol/input/kapplymousetheme.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * main.cpp
 
3
 *
 
4
 * Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
 
5
 * Copyright (c) 2005 Lubos Lunak <l.lunak@kde.org>
 
6
 *
 
7
 * Requires the Qt widget libraries, available at no cost at
 
8
 * http://www.troll.no/
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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.
 
23
 */
 
24
 
 
25
#include <config-X11.h>
 
26
 
 
27
#include <QX11Info>
 
28
#include <stdlib.h>
 
29
#include <ctype.h>
 
30
#include <X11/Xlib.h>
 
31
 
 
32
#ifdef HAVE_XCURSOR
 
33
#  include <X11/Xcursor/Xcursor.h>
 
34
#endif
 
35
 
 
36
static Display* dpy;
 
37
Display* QX11Info::display() { return dpy; }
 
38
Qt::HANDLE QX11Info::appRootWindow(int) { return DefaultRootWindow( dpy ); }
 
39
 
 
40
static bool isEmpty( const char* str )
 
41
    {
 
42
    if( str == NULL )
 
43
        return true;
 
44
    while( isspace( *str ))
 
45
        ++str;
 
46
    return *str == '\0';
 
47
    }
 
48
 
 
49
int main( int argc, char* argv[] )
 
50
    {
 
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 ];
 
60
 
 
61
    // Note: If you update this code, update kapplymousetheme as well.
 
62
 
 
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())))
 
67
    {
 
68
        theme = "default";
 
69
        ret = 10; // means to switch to default
 
70
    }
 
71
 
 
72
     // Apply the KDE cursor theme to ourselves
 
73
    if( !isEmpty( theme ))
 
74
        XcursorSetTheme(QX11Info::display(), theme );
 
75
 
 
76
    if (!isEmpty( size ))
 
77
        XcursorSetDefaultSize(QX11Info::display(), atoi( size ));
 
78
 
 
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
 
83
 
 
84
#else
 
85
    ( void ) QX11Info::display();
 
86
    ( void ) QX11Info::appRootWindow();
 
87
    ( void ) argv;
 
88
#endif
 
89
    XCloseDisplay( dpy );
 
90
    return ret;
 
91
    }