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 <KConfig> | ||
25 | 25 | #include <KConfigGroup> | |||
26 | #include <kconfig.h> | | |||
27 | #include <QFile> | 26 | #include <QFile> | ||
28 | 27 | | |||
29 | #include "mouse.h" | 28 | #include "mousesettings.h" | ||
30 | #include <QX11Info> | 29 | #include "mousebackend.h" | ||
31 | 30 | | |||
32 | #include <klauncher_iface.h> | 31 | #include <klauncher_iface.h> | ||
33 | 32 | | |||
34 | #include <X11/Xlib.h> | | |||
35 | #ifdef HAVE_XCURSOR | | |||
36 | # include <X11/Xcursor/Xcursor.h> | | |||
37 | #endif | | |||
38 | | ||||
39 | extern "C" | 33 | extern "C" | ||
40 | { | 34 | { | ||
41 | Q_DECL_EXPORT void kcminit_mouse() | 35 | Q_DECL_EXPORT void kcminit_mouse() | ||
42 | { | 36 | { | ||
43 | KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals ); | 37 | KConfig* config = new KConfig("kcminputrc", KConfig::NoGlobals); | ||
44 | 38 | | |||
45 | Display *dpy = nullptr; | 39 | auto backend = MouseBackend::implementation(); | ||
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 | 40 | | |||
54 | MouseSettings settings; | 41 | MouseSettings settings; | ||
55 | settings.load(config, dpy); | 42 | settings.load(config, backend); | ||
56 | settings.apply(true); // force | 43 | settings.apply(backend, true); // force | ||
57 | 44 | | |||
58 | #ifdef HAVE_XCURSOR | | |||
59 | KConfigGroup group = config->group("Mouse"); | 45 | KConfigGroup group = config->group("Mouse"); | ||
60 | QString theme = group.readEntry("cursorTheme", QString()); | 46 | QString theme = group.readEntry("cursorTheme", QString()); | ||
61 | QString size = group.readEntry("cursorSize", QString()); | 47 | QString size = group.readEntry("cursorSize", QString()); | ||
62 | 48 | if (backend) { | |||
49 | int intSize = -1; | ||||
50 | if (size.isEmpty()) { | ||||
51 | bool ok; | ||||
52 | uint value = size.toUInt(&ok); | ||||
53 | if (ok) { | ||||
54 | intSize = value; | ||||
55 | } | ||||
56 | } | ||||
63 | // Note: If you update this code, update kapplymousetheme as well. | 57 | // Note: If you update this code, update kapplymousetheme as well. | ||
64 | 58 | | |||
65 | // use a default value for theme only if it's not configured at all, not even in X resources | 59 | // use a default value for theme only if it's not configured at all, not even in X resources | ||
66 | if( theme.isEmpty() | 60 | if (theme.isEmpty() && backend->currentCursorTheme().isEmpty()) { | ||
67 | && (!dpy || | | |||
68 | (QByteArray( XGetDefault( dpy, "Xcursor", "theme" )).isEmpty() | | |||
69 | && QByteArray( XcursorGetTheme( dpy)).isEmpty()))) | | |||
70 | { | | |||
71 | theme = "breeze_cursors"; | 61 | theme = "breeze_cursors"; | ||
72 | } | 62 | } | ||
73 | 63 | backend->applyCursorTheme(theme, intSize); | |||
74 | // Apply the KDE cursor theme to ourselves | | |||
75 | if (dpy) { | | |||
76 | if( !theme.isEmpty()) | | |||
77 | XcursorSetTheme(dpy, QFile::encodeName(theme)); | | |||
78 | | ||||
79 | if (!size.isEmpty()) | | |||
80 | XcursorSetDefaultSize(dpy, size.toUInt()); | | |||
81 | | ||||
82 | // Load the default cursor from the theme and apply it to the root window. | | |||
83 | Cursor handle = XcursorLibraryLoadCursor(dpy, "left_ptr"); | | |||
84 | XDefineCursor(dpy, QX11Info::appRootWindow(), handle); | | |||
85 | XFreeCursor(dpy, handle); // Don't leak the cursor | | |||
86 | } | 64 | } | ||
87 | 65 | | |||
88 | // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment | 66 | // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment | ||
89 | // variables when launching applications. | 67 | // variables when launching applications. | ||
90 | OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), | 68 | OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), | ||
91 | QStringLiteral("/KLauncher"), | 69 | QStringLiteral("/KLauncher"), | ||
92 | QDBusConnection::sessionBus()); | 70 | QDBusConnection::sessionBus()); | ||
93 | if(!theme.isEmpty()) | 71 | if (!theme.isEmpty()) { | ||
94 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); | 72 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); | ||
95 | if( !size.isEmpty()) | 73 | } | ||
74 | if (!size.isEmpty()) { | ||||
96 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); | 75 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); | ||
97 | | ||||
98 | #endif | | |||
99 | | ||||
100 | if (!platformX11) { | | |||
101 | XFlush(dpy); | | |||
102 | XCloseDisplay(dpy); | | |||
103 | } | 76 | } | ||
104 | 77 | | |||
105 | delete config; | 78 | delete config; | ||
106 | } | 79 | } | ||
107 | } | 80 | } | ||
romangg: I know it's copy paste. But so we can directly clean it up: Coding style -> always use braces. | |||||
108 | | ||||
109 | |
I know it's copy paste. But so we can directly clean it up: Coding style -> always use braces.