Changeset View
Changeset View
Standalone View
Standalone View
kcms/input/main.cpp
Show All 15 Lines | |||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | 17 | * GNU General Public License for more details. | ||
18 | * | 18 | * | ||
19 | * You should have received a copy of the GNU General Public License | 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 | 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. | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include <config-X11.h> | 24 | #include "klauncher_iface.h" | ||
25 | #include "mouse.h" | ||||
25 | 26 | | |||
26 | #include <kconfig.h> | | |||
27 | #include <QFile> | 27 | #include <QFile> | ||
28 | | ||||
29 | #include "mouse.h" | | |||
30 | #include <QX11Info> | 28 | #include <QX11Info> | ||
31 | 29 | | |||
32 | #include <klauncher_iface.h> | 30 | #include <KConfig> | ||
33 | 31 | | |||
32 | #include <config-X11.h> | ||||
34 | #include <X11/Xlib.h> | 33 | #include <X11/Xlib.h> | ||
35 | #ifdef HAVE_XCURSOR | 34 | #ifdef HAVE_XCURSOR | ||
36 | # include <X11/Xcursor/Xcursor.h> | 35 | # include <X11/Xcursor/Xcursor.h> | ||
37 | #endif | 36 | #endif | ||
38 | 37 | | |||
39 | extern "C" | 38 | extern "C" Q_DECL_EXPORT void kcminit_mouse() | ||
40 | { | 39 | { | ||
41 | Q_DECL_EXPORT void kcminit_mouse() | 40 | KConfig config("kcminputrc", KConfig::NoGlobals); | ||
42 | { | | |||
43 | KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals ); | | |||
44 | | ||||
45 | Display *dpy = nullptr; | | |||
46 | const bool platformX11 = QX11Info::isPlatformX11(); | | |||
47 | if (platformX11) { | | |||
48 | dpy = QX11Info::display(); | | |||
49 | } else { | | |||
50 | // let's hope we have a compatibility system like Xwayland ready | | |||
51 | dpy = XOpenDisplay(nullptr); | | |||
52 | } | | |||
53 | 41 | | |||
54 | MouseSettings settings; | 42 | MouseSettings settings; | ||
55 | settings.load(config, dpy); | 43 | settings.load(&config); | ||
56 | settings.apply(true); // force | 44 | settings.apply(true); // force | ||
57 | 45 | | |||
58 | #ifdef HAVE_XCURSOR | 46 | #ifdef HAVE_XCURSOR | ||
59 | KConfigGroup group = config->group("Mouse"); | 47 | // let's hope we have a compatibility system like Xwayland ready | ||
48 | Display *dpy = QX11Info::isPlatformX11() ? QX11Info::display() : XOpenDisplay(nullptr); | ||||
49 | | ||||
50 | KConfigGroup group = config.group("Mouse"); | ||||
60 | QString theme = group.readEntry("cursorTheme", QString()); | 51 | QString theme = group.readEntry("cursorTheme", QString()); | ||
61 | QString size = group.readEntry("cursorSize", QString()); | 52 | QString size = group.readEntry("cursorSize", QString()); | ||
62 | 53 | | |||
63 | // Note: If you update this code, update kapplymousetheme as well. | 54 | // Note: If you update this code, update kapplymousetheme as well. | ||
64 | 55 | | |||
65 | // use a default value for theme only if it's not configured at all, not even in X resources | 56 | // use a default value for theme only if it's not configured at all, not even in X resources | ||
66 | if( theme.isEmpty() | 57 | if (theme.isEmpty() | ||
67 | && (!dpy || | 58 | && (!dpy || | ||
68 | (QByteArray( XGetDefault( dpy, "Xcursor", "theme" )).isEmpty() | 59 | (QByteArray(XGetDefault(dpy, "Xcursor", "theme")).isEmpty() | ||
69 | && QByteArray( XcursorGetTheme( dpy)).isEmpty()))) | 60 | && QByteArray(XcursorGetTheme(dpy)).isEmpty()))) | ||
70 | { | 61 | { | ||
71 | theme = "breeze_cursors"; | 62 | theme = "breeze_cursors"; | ||
72 | } | 63 | } | ||
73 | 64 | | |||
74 | // Apply the KDE cursor theme to ourselves | 65 | // Apply the KDE cursor theme to ourselves | ||
75 | if (dpy) { | 66 | if (dpy) { | ||
76 | if( !theme.isEmpty()) | 67 | if(!theme.isEmpty()) | ||
77 | XcursorSetTheme(dpy, QFile::encodeName(theme)); | 68 | XcursorSetTheme(dpy, QFile::encodeName(theme)); | ||
78 | 69 | | |||
79 | if (!size.isEmpty()) | 70 | if (!size.isEmpty()) | ||
80 | XcursorSetDefaultSize(dpy, size.toUInt()); | 71 | XcursorSetDefaultSize(dpy, size.toInt()); | ||
81 | 72 | | |||
82 | // Load the default cursor from the theme and apply it to the root window. | 73 | // Load the default cursor from the theme and apply it to the root window. | ||
83 | Cursor handle = XcursorLibraryLoadCursor(dpy, "left_ptr"); | 74 | Cursor handle = XcursorLibraryLoadCursor(dpy, "left_ptr"); | ||
84 | XDefineCursor(dpy, QX11Info::appRootWindow(), handle); | 75 | XDefineCursor(dpy, QX11Info::appRootWindow(), handle); | ||
85 | XFreeCursor(dpy, handle); // Don't leak the cursor | 76 | XFreeCursor(dpy, handle); // Don't leak the cursor | ||
86 | } | 77 | } | ||
87 | 78 | | |||
88 | // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment | 79 | // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment | ||
89 | // variables when launching applications. | 80 | // variables when launching applications. | ||
90 | OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), | 81 | OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), | ||
91 | QStringLiteral("/KLauncher"), | 82 | QStringLiteral("/KLauncher"), | ||
92 | QDBusConnection::sessionBus()); | 83 | QDBusConnection::sessionBus()); | ||
93 | if(!theme.isEmpty()) | 84 | if(!theme.isEmpty()) | ||
94 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); | 85 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); | ||
95 | if( !size.isEmpty()) | 86 | if( !size.isEmpty()) | ||
96 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); | 87 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); | ||
97 | 88 | | |||
98 | #endif | 89 | if (!QX11Info::isPlatformX11()) { | ||
99 | | ||||
100 | if (!platformX11) { | | |||
101 | XFlush(dpy); | 90 | XFlush(dpy); | ||
102 | XCloseDisplay(dpy); | 91 | XCloseDisplay(dpy); | ||
103 | } | 92 | } | ||
104 | 93 | #endif | |||
105 | delete config; | | |||
106 | } | | |||
107 | } | 94 | } | ||
108 | | ||||
109 | |