Changeset View
Changeset View
Standalone View
Standalone View
kcms/input/kapplymousetheme.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * main.cpp | 2 | * main.cpp | ||
3 | * | 3 | * | ||
4 | * Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org> | 4 | * Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org> | ||
5 | * Copyright (c) 2005 Lubos Lunak <l.lunak@kde.org> | 5 | * Copyright (c) 2005 Lubos Lunak <l.lunak@kde.org> | ||
6 | * Copyright (c) 2017 Xuetian Weng <wengxt@gmail.com> | ||||
6 | * | 7 | * | ||
7 | * Requires the Qt widget libraries, available at no cost at | 8 | * Requires the Qt widget libraries, available at no cost at | ||
8 | * http://www.troll.no/ | 9 | * http://www.troll.no/ | ||
9 | * | 10 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | 11 | * 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 | * 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 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | 14 | * (at your option) any later version. | ||
14 | * | 15 | * | ||
15 | * This program is distributed in the hope that it will be useful, | 16 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | 19 | * GNU General Public License for more details. | ||
19 | * | 20 | * | ||
20 | * You should have received a copy of the GNU General Public License | 21 | * 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 | * 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 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
23 | */ | 24 | */ | ||
25 | #include <QGuiApplication> | ||||
26 | #include <QFile> | ||||
24 | 27 | | |||
25 | #include <config-X11.h> | 28 | #include "mousebackend.h" | ||
26 | | ||||
27 | #include <stdlib.h> | | |||
28 | #include <ctype.h> | | |||
29 | #include <X11/Xlib.h> | | |||
30 | | ||||
31 | #ifdef HAVE_XCURSOR | | |||
32 | # include <X11/Xcursor/Xcursor.h> | | |||
33 | #endif | | |||
34 | | ||||
35 | static Display* dpy; | | |||
36 | Display* display() { return dpy; } | | |||
37 | Window appRootWindow() { return DefaultRootWindow( dpy ); } | | |||
38 | | ||||
39 | static bool isEmpty( const char* str ) | | |||
40 | { | | |||
41 | if( str == NULL ) | | |||
42 | return true; | | |||
43 | while( isspace( *str )) | | |||
44 | ++str; | | |||
45 | return *str == '\0'; | | |||
46 | } | | |||
47 | 29 | | |||
48 | int main( int argc, char* argv[] ) | 30 | int main( int argc, char* argv[] ) | ||
49 | { | 31 | { | ||
32 | int ret = 0; | ||||
33 | QGuiApplication app(argc, argv); | ||||
50 | if( argc != 3 ) | 34 | if( argc != 3 ) | ||
51 | return 1; | 35 | return 1; | ||
52 | dpy = XOpenDisplay( NULL ); | 36 | QString theme = QFile::decodeName(argv[ 1 ]); | ||
53 | if( dpy == NULL ) | 37 | QString size = QFile::decodeName(argv[ 2 ]); | ||
38 | auto backend = MouseBackend::implementation(); | ||||
39 | if (!backend || !backend->isValid()) { | ||||
54 | return 2; | 40 | return 2; | ||
55 | int ret = 0; | 41 | } | ||
56 | #ifdef HAVE_XCURSOR | | |||
57 | const char* theme = argv[ 1 ]; | | |||
58 | const char* size = argv[ 2 ]; | | |||
59 | 42 | | |||
60 | // Note: If you update this code, update kapplymousetheme as well. | 43 | // Note: If you update this code, update main.cpp as well. | ||
61 | 44 | | |||
62 | // use a default value for theme only if it's not configured at all, not even in X resources | 45 | // use a default value for theme only if it's not configured at all, not even in X resources | ||
63 | if( isEmpty( theme ) | 46 | if(theme.isEmpty() && backend->currentCursorTheme().isEmpty()) | ||
64 | && isEmpty( XGetDefault( display(), "Xcursor", "theme" )) | | |||
65 | && isEmpty( XcursorGetTheme( display()))) | | |||
66 | { | 47 | { | ||
67 | theme = "breeze_cursors"; | 48 | theme = "breeze_cursors"; | ||
68 | ret = 10; // means to switch to default | 49 | ret = 10; // means to switch to default | ||
69 | } | 50 | } | ||
70 | 51 | | |||
71 | // Apply the KDE cursor theme to ourselves | 52 | backend->applyCursorTheme(theme, size.toInt()); | ||
72 | if( !isEmpty( theme )) | | |||
73 | XcursorSetTheme(display(), theme ); | | |||
74 | | ||||
75 | if (!isEmpty( size )) | | |||
76 | XcursorSetDefaultSize(display(), atoi( size )); | | |||
77 | | ||||
78 | // Load the default cursor from the theme and apply it to the root window. | | |||
79 | Cursor handle = XcursorLibraryLoadCursor(display(), "left_ptr"); | | |||
80 | XDefineCursor(display(), appRootWindow(), handle); | | |||
81 | XFreeCursor(display(), handle); // Don't leak the cursor | | |||
82 | | ||||
83 | #else | | |||
84 | ( void ) argv; | | |||
85 | #endif | | |||
86 | XCloseDisplay( dpy ); | | |||
87 | return ret; | 53 | return ret; | ||
88 | } | 54 | } |