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

« back to all changes in this revision

Viewing changes to kcontrol/input/main.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
 *
 
6
 * Requires the Qt widget libraries, available at no cost at
 
7
 * http://www.troll.no/
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program; if not, write to the Free Software
 
21
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
22
 */
 
23
 
 
24
#include <config-X11.h>
 
25
 
 
26
#include <klocale.h>
 
27
#include <kglobal.h>
 
28
#include <kconfig.h>
 
29
#include <QFile>
 
30
 
 
31
#include "mouse.h"
 
32
#include <QX11Info>
 
33
 
 
34
#include <ktoolinvocation.h>
 
35
#include <klauncher_iface.h>
 
36
 
 
37
#include <X11/Xlib.h>
 
38
#ifdef HAVE_XCURSOR
 
39
#  include <X11/Xcursor/Xcursor.h>
 
40
#endif
 
41
 
 
42
extern "C"
 
43
{
 
44
  KDE_EXPORT void kcminit_mouse()
 
45
  {
 
46
      KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals );
 
47
    MouseSettings settings;
 
48
    settings.load(config);
 
49
    settings.apply(true); // force
 
50
 
 
51
#ifdef HAVE_XCURSOR
 
52
    KConfigGroup group = config->group("Mouse");
 
53
    QString theme = group.readEntry("cursorTheme", QString());
 
54
    QString size = group.readEntry("cursorSize", QString());
 
55
 
 
56
    // Note: If you update this code, update kapplymousetheme as well.
 
57
 
 
58
    // use a default value for theme only if it's not configured at all, not even in X resources
 
59
    if( theme.isEmpty()
 
60
        && QByteArray( XGetDefault( QX11Info::display(), "Xcursor", "theme" )).isEmpty()
 
61
        && QByteArray( XcursorGetTheme( QX11Info::display())).isEmpty())
 
62
    {
 
63
        theme = "default";
 
64
    }
 
65
 
 
66
     // Apply the KDE cursor theme to ourselves
 
67
    if( !theme.isEmpty())
 
68
        XcursorSetTheme(QX11Info::display(), QFile::encodeName(theme));
 
69
 
 
70
    if (!size.isEmpty())
 
71
        XcursorSetDefaultSize(QX11Info::display(), size.toUInt());
 
72
 
 
73
    // Load the default cursor from the theme and apply it to the root window.
 
74
    Cursor handle = XcursorLibraryLoadCursor(QX11Info::display(), "left_ptr");
 
75
    XDefineCursor(QX11Info::display(), QX11Info::appRootWindow(), handle);
 
76
    XFreeCursor(QX11Info::display(), handle); // Don't leak the cursor
 
77
 
 
78
    // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment
 
79
    // variables when launching applications.
 
80
    if(!theme.isEmpty())
 
81
       KToolInvocation::klauncher()->setLaunchEnv("XCURSOR_THEME", theme);
 
82
    if( !size.isEmpty())
 
83
       KToolInvocation::klauncher()->setLaunchEnv("XCURSOR_SIZE", size);
 
84
 
 
85
#endif
 
86
 
 
87
    delete config;
 
88
  }
 
89
}
 
90
 
 
91