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
This commit is contained in:
parent
6adc785168
commit
ebfc713936
2 changed files with 5 additions and 16 deletions
17
cursor.cpp
17
cursor.cpp
|
@ -66,16 +66,7 @@ void Cursor::loadThemeSettings()
|
||||||
QString themeName = QString::fromUtf8(qgetenv("XCURSOR_THEME"));
|
QString themeName = QString::fromUtf8(qgetenv("XCURSOR_THEME"));
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
// XCURSOR_SIZE might not be set (e.g. by startkde)
|
// XCURSOR_SIZE might not be set (e.g. by startkde)
|
||||||
uint themeSize = 0;
|
const uint themeSize = qEnvironmentVariableIntValue("XCURSOR_SIZE", &ok);
|
||||||
if (qEnvironmentVariableIsSet("XCURSOR_SIZE")) {
|
|
||||||
themeSize = qgetenv("XCURSOR_SIZE").toUInt(&ok);
|
|
||||||
}
|
|
||||||
if (!ok) {
|
|
||||||
if (QScreen *s = QGuiApplication::primaryScreen()) {
|
|
||||||
themeSize = s->logicalDotsPerInchY() * 16 / 72;
|
|
||||||
ok = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!themeName.isEmpty() && ok) {
|
if (!themeName.isEmpty() && ok) {
|
||||||
updateTheme(themeName, themeSize);
|
updateTheme(themeName, themeSize);
|
||||||
return;
|
return;
|
||||||
|
@ -88,11 +79,7 @@ void Cursor::loadThemeFromKConfig()
|
||||||
{
|
{
|
||||||
KConfigGroup mousecfg(kwinApp()->inputConfig(), "Mouse");
|
KConfigGroup mousecfg(kwinApp()->inputConfig(), "Mouse");
|
||||||
const QString themeName = mousecfg.readEntry("cursorTheme", "default");
|
const QString themeName = mousecfg.readEntry("cursorTheme", "default");
|
||||||
bool ok = false;
|
const uint themeSize = mousecfg.readEntry("cursorSize", 0);
|
||||||
uint themeSize = mousecfg.readEntry("cursorSize", QString("24")).toUInt(&ok);
|
|
||||||
if (!ok) {
|
|
||||||
themeSize = 24;
|
|
||||||
}
|
|
||||||
updateTheme(themeName, themeSize);
|
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
|
// as we don't support per screen cursor sizes yet, we use the first screen
|
||||||
KWayland::Server::Display *display = waylandServer()->display();
|
KWayland::Server::Display *display = waylandServer()->display();
|
||||||
auto output = display->outputs().first();
|
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()) {
|
if (output->physicalSize().height()) {
|
||||||
size = qreal(output->pixelSize().height()) / (qreal(output->physicalSize().height()) * 0.0393701) * 16.0 / 72.0;
|
size = qreal(output->pixelSize().height()) / (qreal(output->physicalSize().height()) * 0.0393701) * 16.0 / 72.0;
|
||||||
} else {
|
} else {
|
||||||
// use sensible default
|
// use sensible default
|
||||||
size = 24;
|
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(),
|
auto theme = wl_cursor_theme_load(c->themeName().toUtf8().constData(),
|
||||||
size, m_shm->shm());
|
size, m_shm->shm());
|
||||||
|
|
Loading…
Reference in a new issue