Add shortcuts section to config UI, hook up "toggle effect" shortcut, change distance configs to sliders

This commit is contained in:
wheaney 2025-08-14 15:24:08 -07:00
parent 742fa0e4ca
commit d54954e188
8 changed files with 97 additions and 40 deletions

View File

@ -5,16 +5,16 @@
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kwinrc"/>
<group name="Effect-breezy_desktop_effect">
<entry name="FocusedDisplayDistance" type="Double">
<default>0.85</default>
<min>0.2</min>
<max>2.5</max>
<entry name="FocusedDisplayDistance" type="Int">
<default>85</default>
<min>20</min>
<max>250</max>
<label>Focused Display Distance</label>
</entry>
<entry name="AllDisplaysDistance" type="Double">
<default>1.05</default>
<min>0.2</min>
<max>2.5</max>
<entry name="AllDisplaysDistance" type="Int">
<default>105</default>
<min>20</min>
<max>250</max>
<label>All Displays Distance</label>
</entry>
</group>

View File

@ -66,17 +66,20 @@ BreezyDesktopEffect::BreezyDesktopEffect()
qCCritical(KWIN_XR) << "\t\t\tBreezy - constructor";
qmlRegisterUncreatableType<BreezyDesktopEffect>("org.kde.kwin.effect.breezy_desktop_effect", 1, 0, "BreezyDesktopEffect", QStringLiteral("BreezyDesktop cannot be created in QML"));
const QKeySequence defaultToggleShortcut = Qt::META | Qt::Key_B;
m_shutdownTimer->setSingleShot(true);
connect(m_shutdownTimer, &QTimer::timeout, this, &BreezyDesktopEffect::realDeactivate);
const QKeySequence defaultToggleShortcut = Qt::CTRL | Qt::META | Qt::Key_Backslash;
m_toggleAction = new QAction(this);
m_toggleAction->setObjectName(QStringLiteral("BreezyDesktop"));
m_toggleAction->setText(i18n("Toggle BreezyDesktop"));
m_toggleAction->setObjectName(QStringLiteral("Breezy Desktop"));
m_toggleAction->setText(i18n("Toggle Breezy Desktop"));
KGlobalAccel::self()->setDefaultShortcut(m_toggleAction, {defaultToggleShortcut});
KGlobalAccel::self()->setShortcut(m_toggleAction, {defaultToggleShortcut});
m_toggleShortcut = KGlobalAccel::self()->shortcut(m_toggleAction);
connect(m_toggleAction, &QAction::triggered, this, &BreezyDesktopEffect::toggle);
connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, [this](QAction *action, const QKeySequence &seq) {
if (action->objectName() == QStringLiteral("BreezyDesktop")) {
if (action->objectName() == QStringLiteral("Breezy Desktop")) {
m_toggleShortcut.clear();
m_toggleShortcut.append(seq);
}
@ -123,8 +126,8 @@ BreezyDesktopEffect::BreezyDesktopEffect()
void BreezyDesktopEffect::reconfigure(ReconfigureFlags)
{
BreezyDesktopConfig::self()->read();
setFocusedDisplayDistance(BreezyDesktopConfig::focusedDisplayDistance());
setAllDisplaysDistance(BreezyDesktopConfig::allDisplaysDistance());
setFocusedDisplayDistance(BreezyDesktopConfig::focusedDisplayDistance() / 100.0f);
setAllDisplaysDistance(BreezyDesktopConfig::allDisplaysDistance() / 100.0f);
}
QVariantMap BreezyDesktopEffect::initialProperties(Output *screen)
@ -142,7 +145,13 @@ int BreezyDesktopEffect::requestedEffectChainPosition() const
void BreezyDesktopEffect::toggle()
{
// TODO update this to use a persistent on/off value
if (isRunning()) {
qCCritical(KWIN_XR) << "\t\t\tBreezy - toggle - deactivating";
deactivate();
} else {
qCCritical(KWIN_XR) << "\t\t\tBreezy - toggle - activating";
activate();
}
}
void BreezyDesktopEffect::activate()
@ -165,11 +174,18 @@ void BreezyDesktopEffect::activate()
void BreezyDesktopEffect::deactivate()
{
if (m_shutdownTimer->isActive()) {
return;
}
qCCritical(KWIN_XR) << "\t\t\tBreezy - deactivate";
disconnect(effects, &EffectsHandler::cursorShapeChanged, this, &BreezyDesktopEffect::updateCursorImage);
m_cursorUpdateTimer->stop();
showCursor();
realDeactivate();
// this triggers realDeactivate with a delay so if it's triggered from QML it gives the QML function time to
// exit, avoiding a crash
m_shutdownTimer->start(250);
}
void BreezyDesktopEffect::realDeactivate()
@ -212,7 +228,7 @@ qreal BreezyDesktopEffect::focusedDisplayDistance() const {
void BreezyDesktopEffect::setFocusedDisplayDistance(qreal distance) {
if (distance != m_focusedDisplayDistance) {
m_focusedDisplayDistance = std::clamp(distance, 0.2, 2.5);
m_focusedDisplayDistance = std::clamp(distance, 0.2, m_allDisplaysDistance);
Q_EMIT displayDistanceChanged();
}
}
@ -223,7 +239,7 @@ qreal BreezyDesktopEffect::allDisplaysDistance() const {
void BreezyDesktopEffect::setAllDisplaysDistance(qreal distance) {
if (distance != m_allDisplaysDistance) {
m_allDisplaysDistance = std::clamp(distance, 0.2, 2.5);
m_allDisplaysDistance = std::clamp(distance, m_focusedDisplayDistance, 2.5);
Q_EMIT displayDistanceChanged();
}
}

View File

@ -85,8 +85,6 @@ namespace KWin
QTimer *m_shutdownTimer;
QAction *m_toggleAction = nullptr;
QList<QKeySequence> m_toggleShortcut;
QList<ElectricBorder> m_borderActivate;
QList<ElectricBorder> m_touchBorderActivate;
QString m_cursorImageSource;
bool m_enabled = false;

View File

@ -24,10 +24,27 @@ BreezyDesktopEffectConfig::BreezyDesktopEffectConfig(QObject *parent, const KPlu
{
ui.setupUi(widget());
addConfig(BreezyDesktopConfig::self(), widget());
auto actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
actionCollection->setComponentDisplayName(i18n("KWin"));
actionCollection->setConfigGroup(QStringLiteral("breezy_desktop_effect"));
actionCollection->setConfigGlobal(true);
const QKeySequence defaultToggleShortcut = Qt::CTRL | Qt::META | Qt::Key_Backslash;
QAction *toggleAction = actionCollection->addAction(QStringLiteral("Breezy Desktop"));
toggleAction->setText(i18n("Toggle Breezy Desktop"));
toggleAction->setProperty("isConfigurationAction", true);
KGlobalAccel::self()->setDefaultShortcut(toggleAction, {defaultToggleShortcut});
KGlobalAccel::self()->setShortcut(toggleAction, {defaultToggleShortcut});
ui.shortcutsEditor->addCollection(actionCollection);
connect(ui.shortcutsEditor, &KShortcutsEditor::keyChange, this, &BreezyDesktopEffectConfig::markAsChanged);
}
BreezyDesktopEffectConfig::~BreezyDesktopEffectConfig()
{
// If save() is called, undo() has no effect.
ui.shortcutsEditor->undo();
}
void BreezyDesktopEffectConfig::load()
@ -57,6 +74,7 @@ void BreezyDesktopEffectConfig::defaults()
void BreezyDesktopEffectConfig::updateConfigFromUi()
{
ui.shortcutsEditor->save();
}
void BreezyDesktopEffectConfig::updateUiFromConfig()
@ -65,6 +83,7 @@ void BreezyDesktopEffectConfig::updateUiFromConfig()
void BreezyDesktopEffectConfig::updateUiFromDefaultConfig()
{
ui.shortcutsEditor->allDefault();
}
void BreezyDesktopEffectConfig::updateUnmanagedState()

View File

@ -30,15 +30,24 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="kcfg_FocusedDisplayDistance">
<widget class="QSlider" name="kcfg_FocusedDisplayDistance">
<property name="minimum">
<double>0.2</double>
<double>20</double>
</property>
<property name="maximum">
<double>2.5</double>
<double>250</double>
</property>
<property name="singleStep">
<double>0.01</double>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<double>20</double>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tracking">
<bool>true</bool>
</property>
</widget>
</item>
@ -50,21 +59,46 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="kcfg_AllDisplaysDistance">
<widget class="QSlider" name="kcfg_AllDisplaysDistance">
<property name="minimum">
<double>0.2</double>
<double>20</double>
</property>
<property name="maximum">
<double>2.5</double>
<double>250</double>
</property>
<property name="singleStep">
<double>0.01</double>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<double>20</double>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tracking">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="KShortcutsEditor" name="shortcutsEditor" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KShortcutsEditor</class>
<extends>QWidget</extends>
<header>kshortcutseditor.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>

View File

@ -102,7 +102,6 @@ Node {
breezyDesktop.screens.map(screen => screen.geometry)
);
console.log(`\t\t\tBreezy - Next focused monitor index: ${focusedIndex}`);
if (focusedIndex !== breezyDesktop.focusedMonitorIndex) {
zoomOutAnimation.stop();
zoomInAnimation.stop();
@ -129,7 +128,6 @@ Node {
NumberAnimation {
id: zoomOutAnimation
property: "monitorDistance"
from: effect.focusedDisplayDistance
to: effect.allDisplaysDistance
duration: 150
running: false
@ -138,7 +136,6 @@ Node {
NumberAnimation {
id: zoomInAnimation
property: "monitorDistance"
from: effect.allDisplaysDistance
to: effect.focusedDisplayDistance
duration: 300
running: false
@ -151,7 +148,6 @@ Node {
NumberAnimation {
id: zoomOutSeqAnimation
property: "monitorDistance"
from: effect.focusedDisplayDistance
to: effect.allDisplaysDistance
duration: 150
}
@ -159,7 +155,6 @@ Node {
NumberAnimation {
id: zoomInSeqAnimation
property: "monitorDistance"
from: effect.allDisplaysDistance
to: effect.focusedDisplayDistance
duration: 300
}

View File

@ -371,8 +371,6 @@ QtObject {
westConversionFns.angleToLength
) * effect.focusedDisplayDistance / effect.allDisplaysDistance;
console.log(`\t\t\tBreezy - Focused monitor index: ${currentFocusedIndex}, distance: ${focusedDistance}`);
if (smoothFollowEnabled || focusedDistance < unfocusThreshold)
return currentFocusedIndex;
}
@ -390,7 +388,6 @@ QtObject {
upConversionFns.angleToLength,
westConversionFns.angleToLength
);
console.log(`\t\t\tBreezy - Monitor index: ${i}, distance: ${distance}`);
if (distance < closestDistance) {
closestIndex = i;

View File

@ -80,8 +80,6 @@ Item {
Component.onCompleted: {
const targetScreenSupported = supportedModels.some(model => root.targetScreen.model.endsWith(model));
console.log(`Breezy - initialized with target screen: ${root.targetScreen.model}, supported: ${targetScreenSupported}`);
viewLoader.sourceComponent = targetScreenSupported ? view3DComponent : desktopViewComponent;
}
}