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
icc-effect-5.14.5
Aleix Pol 2018-04-24 16:25:57 +02:00
parent 6adc785168
commit ebfc713936
2 changed files with 5 additions and 16 deletions

View File

@ -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);
}

View File

@ -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());