diff --git a/cupdatecursor/main.cpp b/cupdatecursor/main.cpp
index 8bcd746..2c5b44f 100644
--- a/cupdatecursor/main.cpp
+++ b/cupdatecursor/main.cpp
@@ -15,7 +15,7 @@ inline void applyTheme(const QString &theme, int size)
if (!theme.isEmpty())
XcursorSetTheme(display, QFile::encodeName(theme));
- if (size >= 0)
+ if (size > 0)
XcursorSetDefaultSize(display, size);
Cursor handle = XcursorLibraryLoadCursor(display, "left_ptr");
diff --git a/session/application.cpp b/session/application.cpp
index 7324d0d..ed65bc8 100644
--- a/session/application.cpp
+++ b/session/application.cpp
@@ -93,8 +93,7 @@ Application::Application(int &argc, char **argv)
createConfigDirectory();
initLanguage();
initScreenScaleFactors();
- initCursor();
- initFontDpi();
+ initXResource();
initEnvironments();
@@ -110,6 +109,9 @@ Application::Application(int &argc, char **argv)
// ref plasma
importSystemdEnvrionment();
+ qunsetenv("XCURSOR_THEME");
+ qunsetenv("XCURSOR_SIZE");
+
QTimer::singleShot(100, m_processManager, &ProcessManager::start);
}
@@ -141,39 +143,11 @@ void Application::initEnvironments()
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "0");
// IM Config
- qputenv("GTK_IM_MODULE", "fcitx5");
- qputenv("QT4_IM_MODULE", "fcitx5");
- qputenv("QT_IM_MODULE", "fcitx5");
- qputenv("CLUTTER_IM_MODULE", "fcitx5");
- qputenv("XMODIFIERS", "@im=fcitx");
-}
-
-void Application::initFontDpi()
-{
- QSettings settings(QSettings::UserScope, "cutefishos", "theme");
- qreal scaleFactor = settings.value("PixelRatio", 1.0).toReal();
- int fontDpi = 96 * scaleFactor;
-
- // TODO port to c++?
- const QByteArray input = "Xft.dpi: " + QByteArray::number(fontDpi);
- QProcess p;
- p.start(QStringLiteral("xrdb"), {QStringLiteral("-quiet"), QStringLiteral("-merge"), QStringLiteral("-nocpp")});
- p.setProcessChannelMode(QProcess::ForwardedChannels);
- p.write(input);
- p.closeWriteChannel();
- p.waitForFinished(-1);
-}
-
-void Application::initCursor()
-{
- QSettings settings(QSettings::UserScope, "cutefishos", "theme");
- qreal scaleFactor = settings.value("PixelRatio", 1.0).toReal();
- QString theme = settings.value("cursorTheme", "default").toString();
- int size = settings.value("cursorSize", 24).toInt();
-
- runSync("cupdatecursor", {theme, QString::number(size * scaleFactor)});
- qputenv("XCURSOR_THEME", theme.toLatin1());
- qputenv("XCURSOR_SIZE", QByteArray::number(size * scaleFactor));
+ // qputenv("GTK_IM_MODULE", "fcitx5");
+ // qputenv("QT4_IM_MODULE", "fcitx5");
+ // qputenv("QT_IM_MODULE", "fcitx5");
+ // qputenv("CLUTTER_IM_MODULE", "fcitx5");
+ // qputenv("XMODIFIERS", "@im=fcitx");
}
void Application::initLanguage()
@@ -215,6 +189,34 @@ void Application::initScreenScaleFactors()
}
}
+void Application::initXResource()
+{
+ QSettings settings(QSettings::UserScope, "cutefishos", "theme");
+ qreal scaleFactor = settings.value("PixelRatio", 1.0).toReal();
+ int fontDpi = 96 * scaleFactor;
+ QString cursorTheme = settings.value("CursorTheme", "default").toString();
+ int cursorSize = settings.value("CursorSize", 24).toInt() * scaleFactor;
+
+ const QString datas = QString("Xft.dpi: %1\n"
+ "Xcursor.theme: %2\n"
+ "Xcursor.size: %3")
+ .arg(fontDpi)
+ .arg(cursorTheme)
+ .arg(cursorSize);
+
+ QProcess p;
+ p.start(QStringLiteral("xrdb"), {QStringLiteral("-quiet"), QStringLiteral("-merge"), QStringLiteral("-nocpp")});
+ p.setProcessChannelMode(QProcess::ForwardedChannels);
+ p.write(datas.toLatin1());
+ p.closeWriteChannel();
+ p.waitForFinished(-1);
+
+ // Init cursor
+ runSync("cupdatecursor", {cursorTheme, QString::number(cursorSize * scaleFactor)});
+ // qputenv("XCURSOR_THEME", cursorTheme.toLatin1());
+ // qputenv("XCURSOR_SIZE", QByteArray::number(cursorSize * scaleFactor));
+}
+
bool Application::syncDBusEnvironment()
{
int exitCode = 0;
diff --git a/session/application.h b/session/application.h
index a16a87b..e65b667 100644
--- a/session/application.h
+++ b/session/application.h
@@ -63,10 +63,9 @@ public slots:
private:
void initEnvironments();
- void initFontDpi();
- void initCursor();
void initLanguage();
void initScreenScaleFactors();
+ void initXResource();
bool syncDBusEnvironment();
void importSystemdEnvrionment();
void createConfigDirectory();
diff --git a/settings-daemon/theme/org.cutefish.Theme.xml b/settings-daemon/theme/org.cutefish.Theme.xml
index ef5b89d..05ab62f 100644
--- a/settings-daemon/theme/org.cutefish.Theme.xml
+++ b/settings-daemon/theme/org.cutefish.Theme.xml
@@ -31,6 +31,12 @@
+
+
+
+
+
+
@@ -42,6 +48,8 @@
+
+
@@ -54,9 +62,9 @@
-
-
-
-
+
+
+
+
diff --git a/settings-daemon/theme/thememanager.cpp b/settings-daemon/theme/thememanager.cpp
index b56a199..6ad931b 100644
--- a/settings-daemon/theme/thememanager.cpp
+++ b/settings-daemon/theme/thememanager.cpp
@@ -64,6 +64,8 @@ ThemeManager::ThemeManager(QObject *parent)
m_accentColor = m_settings->value("AccentColor", 0).toInt();
m_backgroundType = m_settings->value("BackgroundType", 0).toInt();
m_backgroundColor = m_settings->value("BackgroundColor", "#2B8ADA").toString();
+ m_cursorTheme = m_settings->value("CursorTheme", "default").toString();
+ m_cursorSize = m_settings->value("CursorSize", 24).toInt();
// Start the DE and need to update the settings again.
initGtkConfig();
@@ -119,6 +121,38 @@ void ThemeManager::setAccentColor(int accentColor)
emit accentColorChanged(m_accentColor);
}
+QString ThemeManager::cursorTheme() const
+{
+ return m_cursorTheme;
+}
+
+void ThemeManager::setCursorTheme(const QString &theme)
+{
+ if (m_cursorTheme != theme) {
+ m_cursorTheme = theme;
+ m_settings->setValue("CursorTheme", m_cursorTheme);
+ applyXResource();
+ applyCursor();
+ emit cursorThemeChanged();
+ }
+}
+
+int ThemeManager::cursorSize() const
+{
+ return m_cursorSize;
+}
+
+void ThemeManager::setCursorSize(int size)
+{
+ if (m_cursorSize != size) {
+ m_cursorSize = size;
+ m_settings->setValue("CursorSize", m_cursorSize);
+ applyXResource();
+ applyCursor();
+ emit cursorSizeChanged();
+ }
+}
+
QString ThemeManager::systemFont()
{
return m_settings->value(s_systemFontName, "Noto Sans").toString();
@@ -158,18 +192,11 @@ qreal ThemeManager::devicePixelRatio()
void ThemeManager::setDevicePixelRatio(qreal ratio)
{
- int scaleDpi = qRound(ratio * 96.0);
- QProcess process;
- process.start(QStringLiteral("xrdb"), {QStringLiteral("-quiet"), QStringLiteral("-merge"), QStringLiteral("-nocpp")});
-
- if (process.waitForStarted()) {
- process.write(QByteArray("Xft.dpi: " + QString::number(scaleDpi).toLatin1()));
- process.closeWriteChannel();
- process.waitForFinished();
- }
-
+ int fontDpi = qRound(ratio * 96.0);
m_settings->setValue(s_devicePixelRatio, ratio);
- m_settings->setValue("forceFontDPI", scaleDpi);
+ m_settings->setValue("forceFontDPI", fontDpi);
+ m_settings->sync();
+ applyXResource();
}
QString ThemeManager::wallpaper()
@@ -231,6 +258,39 @@ void ThemeManager::initGtkConfig()
settings.sync();
}
+void ThemeManager::applyXResource()
+{
+ qreal scaleFactor = this->devicePixelRatio();
+ int fontDpi = 96 * scaleFactor;
+
+ const QString datas = QString("Xft.dpi: %1\n"
+ "Xcursor.theme: %2\n"
+ "Xcursor.size: %3")
+ .arg(fontDpi)
+ .arg(m_cursorTheme)
+ .arg(m_cursorSize * scaleFactor);
+
+ QProcess p;
+ p.start(QStringLiteral("xrdb"), {QStringLiteral("-quiet"), QStringLiteral("-merge"), QStringLiteral("-nocpp")});
+ p.setProcessChannelMode(QProcess::ForwardedChannels);
+ p.write(datas.toLatin1());
+ p.closeWriteChannel();
+ p.waitForFinished(-1);
+}
+
+void ThemeManager::applyCursor()
+{
+ QProcess p;
+ p.start("cupdatecursor", QStringList() << cursorTheme() << QString::number(cursorSize() * devicePixelRatio()));
+ p.waitForFinished(-1);
+
+ QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange");
+ // ChangeCursor
+ message << 5;
+ message << 0;
+ QDBusConnection::sessionBus().send(message);
+}
+
void ThemeManager::updateGtkFont()
{
QSettings settings(gtk3SettingsIniPath(), QSettings::IniFormat);
diff --git a/settings-daemon/theme/thememanager.h b/settings-daemon/theme/thememanager.h
index 0b6e473..9a6a99e 100644
--- a/settings-daemon/theme/thememanager.h
+++ b/settings-daemon/theme/thememanager.h
@@ -36,6 +36,8 @@ class ThemeManager : public QObject
Q_PROPERTY(int accentColor READ accentColor WRITE setAccentColor NOTIFY accentColorChanged)
Q_PROPERTY(int backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged)
Q_PROPERTY(QString backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
+ Q_PROPERTY(QString cursorTheme READ cursorTheme WRITE setCursorTheme NOTIFY cursorThemeChanged)
+ Q_PROPERTY(int cursorSize READ cursorSize WRITE setCursorSize NOTIFY cursorSizeChanged)
public:
ThemeManager(QObject *parent = nullptr);
@@ -70,7 +72,15 @@ public:
int accentColor();
void setAccentColor(int accentColor);
+ QString cursorTheme() const;
+ void setCursorTheme(const QString &theme);
+
+ int cursorSize() const;
+ void setCursorSize(int size);
+
void initGtkConfig();
+ void applyXResource();
+ void applyCursor();
signals:
void darkModeChanged(bool darkMode);
@@ -79,6 +89,8 @@ signals:
void accentColorChanged(int accentColor);
void backgroundTypeChanged();
void backgroundColorChanged();
+ void cursorThemeChanged();
+ void cursorSizeChanged();
private:
void updateGtkFont();
@@ -92,6 +104,9 @@ private:
int m_backgroundType;
QString m_backgroundColor;
int m_accentColor;
+
+ QString m_cursorTheme;
+ int m_cursorSize;
};
#endif