Commit 13e74d87 authored by Arjen Hiemstra's avatar Arjen Hiemstra Committed by Nate Graham
Browse files

Use KWin's tablet mode to increase decoration button size using touch

On touch devices, the default decoration button size is rather hard
to use. We have a thing to detect this however, KWin's Tablet Mode.
Using that, we can change button sizes based on this. Rather than
changing which size to use, change the base unit so we don't mess
around with config values.
parent 3fe906b0
Pipeline #157056 passed with stage
in 3 minutes and 9 seconds
......@@ -30,6 +30,9 @@
#include <QTextStream>
#include <QTimer>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingReply>
#include <QDBusPendingCallWatcher>
#if BREEZE_HAVE_X11
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
......@@ -239,6 +242,27 @@ namespace Breeze
QStringLiteral( "org.kde.KGlobalSettings" ),
QStringLiteral( "notifyChange" ), this, SLOT(reconfigure()) );
dbus.connect( QStringLiteral("org.kde.KWin"),
QStringLiteral( "/org/kde/KWin" ),
QStringLiteral( "org.kde.KWin.TabletModeManager" ),
QStringLiteral( "tabletModeChanged" ), QStringLiteral( "b" ), this, SLOT(onTabletModeChanged(bool)) );
auto message = QDBusMessage::createMethodCall( QStringLiteral("org.kde.KWin"),
QStringLiteral( "/org/kde/KWin" ),
QStringLiteral( "org.freedesktop.DBus.Properties" ),
QStringLiteral( "Get" )
);
message.setArguments({QStringLiteral("org.kde.KWin.TabletModeManager"), QStringLiteral("tabletMode")});
auto call = new QDBusPendingCallWatcher(dbus.asyncCall(message), this);
connect(call, &QDBusPendingCallWatcher::finished, this, [this, call]() {
QDBusPendingReply<QVariant> reply = *call;
if (!reply.isError()) {
onTabletModeChanged(reply.value().toBool());
}
call->deleteLater();
});
reconfigure();
updateTitleBar();
auto s = settings();
......@@ -667,7 +691,7 @@ namespace Breeze
//________________________________________________________________
int Decoration::buttonHeight() const
{
const int baseSize = settings()->gridUnit();
const int baseSize = m_tabletMode ? settings()->gridUnit() * 2 : settings()->gridUnit();
switch( m_internalSettings->buttonSize() )
{
case InternalSettings::ButtonTiny: return baseSize;
......@@ -677,7 +701,13 @@ namespace Breeze
case InternalSettings::ButtonLarge: return baseSize*2.5;
case InternalSettings::ButtonVeryLarge: return baseSize*3.5;
}
}
void Decoration::onTabletModeChanged(bool mode)
{
m_tabletMode = mode;
recalculateBorders();
updateButtonsGeometry();
}
//________________________________________________________________
......
......@@ -98,6 +98,7 @@ namespace Breeze
void updateTitleBar();
void updateAnimationState();
void updateSizeGripVisibility();
void onTabletModeChanged(bool mode);
private:
......@@ -144,6 +145,8 @@ namespace Breeze
//*frame corner radius, scaled according to DPI
qreal m_scaledCornerRadius = 3;
bool m_tabletMode = false;
};
bool Decoration::hasBorders() const
......
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