Commit ebfc7139 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Improve cursor size setup

Centralise resolution-dependent computation into the leaf cursor class.
Listen to scale changes and update the cursor when it happens

Reviewed by David Edmundson
parent 6adc7851
......@@ -66,16 +66,7 @@ void Cursor::loadThemeSettings()
QString themeName = QString::fromUtf8(qgetenv("XCURSOR_THEME"));
bool ok = false;
// XCURSOR_SIZE might not be set (e.g. by startkde)
uint themeSize = 0;
if (qEnvironmentVariableIsSet("XCURSOR_SIZE")) {
themeSize = qgetenv("XCURSOR_SIZE").toUInt(&ok);
}
if (!ok) {
if (QScreen *s = QGuiApplication::primaryScreen()) {
themeSize = s->logicalDotsPerInchY() * 16 / 72;
ok = true;
}
}
const uint themeSize = qEnvironmentVariableIntValue("XCURSOR_SIZE", &ok);
if (!themeName.isEmpty() && ok) {
updateTheme(themeName, themeSize);
return;
......@@ -88,11 +79,7 @@ void Cursor::loadThemeFromKConfig()
{
KConfigGroup mousecfg(kwinApp()->inputConfig(), "Mouse");
const QString themeName = mousecfg.readEntry("cursorTheme", "default");
bool ok = false;
uint themeSize = mousecfg.readEntry("cursorSize", QString("24")).toUInt(&ok);
if (!ok) {
themeSize = 24;
}
const uint themeSize = mousecfg.readEntry("cursorSize", 0);
updateTheme(themeName, themeSize);
}
......
......@@ -56,13 +56,15 @@ void WaylandCursorTheme::loadTheme()
// as we don't support per screen cursor sizes yet, we use the first screen
KWayland::Server::Display *display = waylandServer()->display();
auto output = display->outputs().first();
// calculate dots per inch, multiplied with magic constants from Cursor::loadThemeSettings()
// calculate dots per inch, multiplied with magic constants
if (output->physicalSize().height()) {
size = qreal(output->pixelSize().height()) / (qreal(output->physicalSize().height()) * 0.0393701) * 16.0 / 72.0;
} else {
// use sensible default
size = 24;
}
size *= output->scale();
connect(output, &KWayland::Server::OutputInterface::scaleChanged, this, &WaylandCursorTheme::loadTheme, Qt::UniqueConnection);
}
auto theme = wl_cursor_theme_load(c->themeName().toUtf8().constData(),
size, m_shm->shm());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment