bool CursorThemeModel::applyCursorTheme(const CursorTheme *theme, const int size) { // Require the Xcursor version that shipped with X11R6.9 or greater, since // in previous versions the Xfixes code wasn't enabled due to a bug in the // build system (freedesktop bug #975). #if HAVE_XFIXES && XFIXES_MAJOR >= 2 && XCURSOR_LIB_VERSION >= 10105 if (!theme) return false; if (!CursorTheme::haveXfixes()) return false; QByteArray themeName = QFile::encodeName(theme->name()); // Set up the proper launch environment for newly started apps OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), themeName); // Update the Xcursor X resources runRdb(0); // Notify all applications that the cursor theme has changed KGlobalSettings::self()->emitChange(KGlobalSettings::CursorChanged); // Reload the standard cursors QStringList names; // Qt cursors names << QStringLiteral("left_ptr") << QStringLiteral("up_arrow") << QStringLiteral("cross") << QStringLiteral("wait") << QStringLiteral("left_ptr_watch") << QStringLiteral("ibeam") << QStringLiteral("size_ver") << QStringLiteral("size_hor") << QStringLiteral("size_bdiag") << QStringLiteral("size_fdiag") << QStringLiteral("size_all") << QStringLiteral("split_v") << QStringLiteral("split_h") << QStringLiteral("pointing_hand") << QStringLiteral("openhand") << QStringLiteral("closedhand") << QStringLiteral("forbidden") << QStringLiteral("whats_this") << QStringLiteral("copy") << QStringLiteral("move") << QStringLiteral("link"); // X core cursors names << QStringLiteral("X_cursor") << QStringLiteral("right_ptr") << QStringLiteral("hand1") << QStringLiteral("hand2") << QStringLiteral("watch") << QStringLiteral("xterm") << QStringLiteral("crosshair") << QStringLiteral("left_ptr_watch") << QStringLiteral("center_ptr") << QStringLiteral("sb_h_double_arrow") << QStringLiteral("sb_v_double_arrow") << QStringLiteral("fleur") << QStringLiteral("top_left_corner") << QStringLiteral("top_side") << QStringLiteral("top_right_corner") << QStringLiteral("right_side") << QStringLiteral("bottom_right_corner") << QStringLiteral("bottom_side") << QStringLiteral("bottom_left_corner") << QStringLiteral("left_side") << QStringLiteral("question_arrow") << QStringLiteral("pirate"); foreach (const QString &name, names) { XFixesChangeCursorByName(QX11Info::display(), theme->loadCursor(name, size), QFile::encodeName(name)); }
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; }
/*! Utility function to execute a command on the local machine. Used * to restart applications. */ KProcess* KSMServer::startApplication( const QStringList& cmd, const QString& clientMachine, const QString& userId, bool wm ) { QStringList command = cmd; if ( command.isEmpty() ) return NULL; if ( !userId.isEmpty()) { struct passwd* pw = getpwuid( getuid()); if( pw != NULL && userId != QString::fromLocal8Bit( pw->pw_name )) { command.prepend( "--" ); command.prepend( userId ); command.prepend( "-u" ); command.prepend( KStandardDirs::findExe("kdesu") ); } } if ( !clientMachine.isEmpty() && clientMachine != "localhost" ) { command.prepend( clientMachine ); command.prepend( xonCommand ); // "xon" by default } // TODO this function actually should not use KProcess at all and use klauncher (kdeinit) instead. // Klauncher should also have support for tracking whether the launched process is still alive // or not, so this should be redone. For now, use KProcess for wm's, as they need to be tracked, // klauncher for the rest where ksmserver doesn't care. if( wm ) { KProcess* process = new KProcess( this ); *process << command; // make it auto-delete connect( process, SIGNAL(error(QProcess::ProcessError)), process, SLOT(deleteLater())); connect( process, SIGNAL(finished(int,QProcess::ExitStatus)), process, SLOT(deleteLater())); process->start(); return process; } else { int n = command.count(); org::kde::KLauncher klauncher("org.kde.klauncher", "/KLauncher", QDBusConnection::sessionBus()); QString app = command[0]; QStringList argList; for ( int i=1; i < n; i++) argList.append( command[i]); klauncher.exec_blind(app, argList ); return NULL; } }
// ----------------------------------------------------------------------------- static void applyGtkStyles(bool active, int version) { QString gtkkde = KStandardDirs::locateLocal("config", 2==version?"gtkrc-2.0":"gtkrc"); QByteArray gtkrc = getenv(gtkEnvVar(version)); QStringList list = QFile::decodeName(gtkrc).split( ':'); QString userHomeGtkrc = QDir::homePath()+userGtkrc(version); if (!list.contains(userHomeGtkrc)) list.prepend(userHomeGtkrc); QLatin1String systemGtkrc = QLatin1String(sysGtkrc(version)); if (!list.contains(systemGtkrc)) list.prepend(systemGtkrc); list.removeAll(""); list.removeAll(gtkkde); list.append(gtkkde); // Pass env. var to kdeinit. QString name = gtkEnvVar(version); QString value = list.join(":"); org::kde::KLauncher klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); klauncher.setLaunchEnv(name, value); }
KSMServer::KSMServer( const QString& windowManager, bool _only_local, bool lockscreen ) : wmProcess( NULL ) , sessionGroup( "" ) , logoutEffectWidget( NULL ) { #ifdef COMPILE_SCREEN_LOCKER KGlobal::locale()->insertCatalog(QLatin1String( "libkworkspace" )); ScreenLocker::KSldApp::self(); if (lockscreen) { ScreenLocker::KSldApp::self()->lock(); } #else Q_UNUSED(lockscreen) #endif new KSMServerInterfaceAdaptor( this ); QDBusConnection::sessionBus().registerObject("/KSMServer", this); klauncherSignals = new OrgKdeKLauncherInterface(QLatin1String("org.kde.klauncher"), QLatin1String("/KLauncher"), QDBusConnection::sessionBus()); kcminitSignals = NULL; the_server = this; clean = false; shutdownType = KWorkSpace::ShutdownTypeNone; state = Idle; dialogActive = false; saveSession = false; wmPhase1WaitingCount = 0; KConfigGroup config(KGlobal::config(), "General"); clientInteracting = 0; xonCommand = config.readEntry( "xonCommand", "xon" ); KGlobal::dirs()->addResourceType( "windowmanagers", "data", "ksmserver/windowmanagers" ); selectWm( windowManager ); connect( &startupSuspendTimeoutTimer, SIGNAL(timeout()), SLOT(startupSuspendTimeout())); connect( &pendingShutdown, SIGNAL(timeout()), SLOT(pendingShutdownTimeout())); only_local = _only_local; #ifdef HAVE__ICETRANSNOLISTEN if (only_local) _IceTransNoListen("tcp"); #else only_local = false; #endif char errormsg[256]; if (!SmsInitialize ( (char*) KSMVendorString, (char*) KSMReleaseString, KSMNewClientProc, (SmPointer) this, HostBasedAuthProc, 256, errormsg ) ) { qWarning("KSMServer: could not register XSM protocol"); } if (!IceListenForConnections (&numTransports, &listenObjs, 256, errormsg)) { qWarning("KSMServer: Error listening for connections: %s", errormsg); qWarning("KSMServer: Aborting."); exit(1); } { // publish available transports. QByteArray fName = QFile::encodeName(KStandardDirs::locateLocal("socket", "KSMserver")); QString display = ::getenv("DISPLAY"); // strip the screen number from the display display.replace(QRegExp("\\.[0-9]+$"), ""); int i; while( (i = display.indexOf(':')) >= 0) display[i] = '_'; while( (i = display.indexOf('/')) >= 0) display[i] = '_'; fName += '_'+display.toLocal8Bit(); FILE *f; f = ::fopen(fName.data(), "w+"); if (!f) { qWarning("KSMServer: cannot open %s: %s", fName.data(), strerror(errno)); qWarning("KSMServer: Aborting."); exit(1); } char* session_manager = IceComposeNetworkIdList(numTransports, listenObjs); fprintf(f, "%s\n%i\n", session_manager, getpid()); fclose(f); setenv( "SESSION_MANAGER", session_manager, true ); // Pass env. var to kdeinit. org::kde::KLauncher klauncher("org.kde.klauncher", "/KLauncher", QDBusConnection::sessionBus()); klauncher.setLaunchEnv( "SESSION_MANAGER", (const char*) session_manager ); free(session_manager); } if (only_local) { if (!SetAuthentication_local(numTransports, listenObjs)) qFatal("KSMSERVER: authentication setup failed."); } else { if (!SetAuthentication(numTransports, listenObjs, &authDataEntries)) qFatal("KSMSERVER: authentication setup failed."); } IceAddConnectionWatch (KSMWatchProc, (IcePointer) this); KSMListener* con; for ( int i = 0; i < numTransports; i++) { fcntl( IceGetListenConnectionNumber( listenObjs[i] ), F_SETFD, FD_CLOEXEC ); con = new KSMListener( listenObjs[i] ); listener.append( con ); connect( con, SIGNAL(activated(int)), this, SLOT(newConnection(int)) ); } signal(SIGHUP, sighandler); signal(SIGTERM, sighandler); signal(SIGINT, sighandler); signal(SIGPIPE, SIG_IGN); connect( &protectionTimer, SIGNAL(timeout()), this, SLOT(protectionTimeout()) ); connect( &restoreTimer, SIGNAL(timeout()), this, SLOT(tryRestoreNext()) ); connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanUp()) ); }
void KCMLookandFeel::setCursorTheme(const QString themeName) { //TODO: use pieces of cursor kcm when moved to plasma-desktop if (themeName.isEmpty()) { return; } KConfig config(QStringLiteral("kcminputrc")); KConfigGroup cg(&config, "Mouse"); cg.writeEntry("cursorTheme", themeName); cg.sync(); // Require the Xcursor version that shipped with X11R6.9 or greater, since // in previous versions the Xfixes code wasn't enabled due to a bug in the // build system (freedesktop bug #975). #if HAVE_XFIXES && XFIXES_MAJOR >= 2 && XCURSOR_LIB_VERSION >= 10105 QDir themeDir = cursorThemeDir(themeName, 0); if (!themeDir.exists()) { return; } XCursorTheme theme(themeDir); if (!CursorTheme::haveXfixes()) { return; } // Set up the proper launch environment for newly started apps OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), QStringLiteral("/KLauncher"), QDBusConnection::sessionBus()); klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), themeName); // Update the Xcursor X resources runRdb(0); // Notify all applications that the cursor theme has changed KGlobalSettings::self()->emitChange(KGlobalSettings::CursorChanged); // Reload the standard cursors QStringList names; // Qt cursors names << QStringLiteral("left_ptr") << QStringLiteral("up_arrow") << QStringLiteral("cross") << QStringLiteral("wait") << QStringLiteral("left_ptr_watch") << QStringLiteral("ibeam") << QStringLiteral("size_ver") << QStringLiteral("size_hor") << QStringLiteral("size_bdiag") << QStringLiteral("size_fdiag") << QStringLiteral("size_all") << QStringLiteral("split_v") << QStringLiteral("split_h") << QStringLiteral("pointing_hand") << QStringLiteral("openhand") << QStringLiteral("closedhand") << QStringLiteral("forbidden") << QStringLiteral("whats_this") << QStringLiteral("copy") << QStringLiteral("move") << QStringLiteral("link"); // X core cursors names << QStringLiteral("X_cursor") << QStringLiteral("right_ptr") << QStringLiteral("hand1") << QStringLiteral("hand2") << QStringLiteral("watch") << QStringLiteral("xterm") << QStringLiteral("crosshair") << QStringLiteral("left_ptr_watch") << QStringLiteral("center_ptr") << QStringLiteral("sb_h_double_arrow") << QStringLiteral("sb_v_double_arrow") << QStringLiteral("fleur") << QStringLiteral("top_left_corner") << QStringLiteral("top_side") << QStringLiteral("top_right_corner") << QStringLiteral("right_side") << QStringLiteral("bottom_right_corner") << QStringLiteral("bottom_side") << QStringLiteral("bottom_left_corner") << QStringLiteral("left_side") << QStringLiteral("question_arrow") << QStringLiteral("pirate"); foreach (const QString &name, names) { XFixesChangeCursorByName(QX11Info::display(), theme.loadCursor(name, 0), QFile::encodeName(name)); }
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; }