add more spacing
[personal-kdebase.git] / workspace / kcontrol / input / main.cpp
blob0f9f33a6035bcd807130793901897f8d010a038f
1 /*
2 * main.cpp
4 * Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
6 * Requires the Qt widget libraries, available at no cost at
7 * http://www.troll.no/
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.
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.
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.
24 #include <config-X11.h>
26 #include <klocale.h>
27 #include <kglobal.h>
28 #include <kconfig.h>
29 #include <QFile>
31 #include "mouse.h"
32 #include <QX11Info>
34 #include <ktoolinvocation.h>
35 #include <klauncher_iface.h>
37 #include <X11/Xlib.h>
38 #ifdef HAVE_XCURSOR
39 # include <X11/Xcursor/Xcursor.h>
40 #endif
42 extern "C"
44 KDE_EXPORT void kcminit_mouse()
46 KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals );
47 MouseSettings settings;
48 settings.load(config);
49 settings.apply(true); // force
51 #ifdef HAVE_XCURSOR
52 KConfigGroup group = config->group("Mouse");
53 QString theme = group.readEntry("cursorTheme", QString());
54 QString size = group.readEntry("cursorSize", QString());
56 // Note: If you update this code, update kapplymousetheme as well.
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())
63 theme = "default";
66 // Apply the KDE cursor theme to ourselves
67 if( !theme.isEmpty())
68 XcursorSetTheme(QX11Info::display(), QFile::encodeName(theme));
70 if (!size.isEmpty())
71 XcursorSetDefaultSize(QX11Info::display(), size.toUInt());
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
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);
85 #endif
87 delete config;