Q_DECL_EXPORT void kcminit_mouse() { KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals ); MouseSettings settings; settings.load(config); settings.apply(true); // force #ifdef HAVE_XCURSOR KConfigGroup group = config->group("Mouse"); QString theme = group.readEntry("cursorTheme", QString()); QString size = group.readEntry("cursorSize", QString()); // Note: If you update this code, update kapplymousetheme as well. // use a default value for theme only if it's not configured at all, not even in X resources if( theme.isEmpty() && QByteArray( XGetDefault( QX11Info::display(), "Xcursor", "theme" )).isEmpty() && QByteArray( XcursorGetTheme( QX11Info::display())).isEmpty()) { theme = "default"; } // Apply the KDE cursor theme to ourselves if( !theme.isEmpty()) XcursorSetTheme(QX11Info::display(), QFile::encodeName(theme)); if (!size.isEmpty()) XcursorSetDefaultSize(QX11Info::display(), size.toUInt()); // Load the default cursor from the theme and apply it to the root window. Cursor handle = XcursorLibraryLoadCursor(QX11Info::display(), "left_ptr"); XDefineCursor(QX11Info::display(), QX11Info::appRootWindow(), handle); XFreeCursor(QX11Info::display(), handle); // Don't leak the cursor // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment // variables when launching applications. OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); if(!theme.isEmpty()) klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); if( !size.isEmpty()) klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); #endif delete config; }
int main( int argc, char* argv[] ) { if( argc != 3 ) return 1; dpy = XOpenDisplay( NULL ); if( dpy == NULL ) return 2; int ret = 0; #ifdef HAVE_XCURSOR const char* theme = argv[ 1 ]; const char* size = argv[ 2 ]; // Note: If you update this code, update kapplymousetheme as well. // use a default value for theme only if it's not configured at all, not even in X resources if( isEmpty( theme ) && isEmpty( XGetDefault( trinity_qt_xdisplay(), "Xcursor", "theme" )) && isEmpty( XcursorGetTheme( trinity_qt_xdisplay()))) { theme = "default"; ret = 10; // means to switch to default } // Apply the KDE cursor theme to ourselves if( !isEmpty( theme )) XcursorSetTheme(trinity_qt_xdisplay(), theme ); if (!isEmpty( size )) XcursorSetDefaultSize(trinity_qt_xdisplay(), atoi( size )); // Load the default cursor from the theme and apply it to the root window. Cursor handle = XcursorLibraryLoadCursor(trinity_qt_xdisplay(), "left_ptr"); XDefineCursor(trinity_qt_xdisplay(), trinity_qt_xrootwin(), handle); XFreeCursor(trinity_qt_xdisplay(), handle); // Don't leak the cursor #else ( void ) trinity_qt_xdisplay(); ( void ) trinity_qt_xrootwin(); ( void ) argv; #endif XCloseDisplay( dpy ); return ret; }
Q_DECL_EXPORT void kcminit_mouse() { KConfig *config = new KConfig("kcminputrc", KConfig::NoGlobals ); Display *dpy = nullptr; const bool platformX11 = QX11Info::isPlatformX11(); if (platformX11) { dpy = QX11Info::display(); } else { // let's hope we have a compatibility system like Xwayland ready dpy = XOpenDisplay(nullptr); } MouseSettings settings; settings.load(config, dpy); settings.apply(true); // force #ifdef HAVE_XCURSOR KConfigGroup group = config->group("Mouse"); QString theme = group.readEntry("cursorTheme", QString()); QString size = group.readEntry("cursorSize", QString()); // Note: If you update this code, update kapplymousetheme as well. // use a default value for theme only if it's not configured at all, not even in X resources if( theme.isEmpty() && (!dpy || (QByteArray( XGetDefault( dpy, "Xcursor", "theme" )).isEmpty() && QByteArray( XcursorGetTheme( dpy)).isEmpty()))) { theme = "breeze_cursors"; } // Apply the KDE cursor theme to ourselves if (dpy) { if( !theme.isEmpty()) XcursorSetTheme(dpy, QFile::encodeName(theme)); if (!size.isEmpty()) XcursorSetDefaultSize(dpy, size.toUInt()); // Load the default cursor from the theme and apply it to the root window. Cursor handle = XcursorLibraryLoadCursor(dpy, "left_ptr"); XDefineCursor(dpy, QX11Info::appRootWindow(), handle); XFreeCursor(dpy, handle); // Don't leak the cursor } // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment // variables when launching applications. OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); if(!theme.isEmpty()) klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); if( !size.isEmpty()) klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); #endif if (!platformX11) { XFlush(dpy); XCloseDisplay(dpy); } delete config; }