From 52afb2a52b17b82fd85150f40200b186517e49f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20M=C3=BCller?= Date: Wed, 23 Oct 2024 18:45:46 +0200 Subject: [PATCH 2/3] tabbox: Only skip active window if it is in the client list When invoking the tabbox we initially advance the selection by one, assuming the first item in the client list is the active window which we'd like to skip. However, since we allow the user to apply a filter to the clients displayed in the list, we might end up with the active window missing from the current client list and skipping over an unrelated client. When using focus chain switching this means we skip over the last focused window, making quick switching between two windows impossible. Instead of advancing the selection unconditionally, make sure not to advance if the client list does not contain the active window and we are in the initial invocation of the tabbox in navigatingThroughWindows(). --- src/tabbox/tabbox.cpp | 25 +++++++++++++++++++------ src/tabbox/tabbox.h | 7 ++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/tabbox/tabbox.cpp b/src/tabbox/tabbox.cpp index f3bbfa99bc..5d6b2cb569 100644 --- a/src/tabbox/tabbox.cpp +++ b/src/tabbox/tabbox.cpp @@ -478,6 +478,11 @@ void TabBox::setCurrentIndex(QModelIndex index, bool notifyEffects) } } +bool TabBox::haveActiveClient() +{ + return m_tabBox->index(m_tabBox->activeClient()).isValid(); +} + void TabBox::show() { Q_EMIT tabBoxAdded(m_tabBoxMode); @@ -808,9 +813,7 @@ void TabBox::navigatingThroughWindows(bool forward, const QKeySequence &shortcut CDEWalkThroughWindows(forward); } else { if (areModKeysDepressed(shortcut)) { - if (startKDEWalkThroughWindows(mode)) { - KDEWalkThroughWindows(forward); - } + startKDEWalkThroughWindows(forward, mode); } else { // if the shortcut has no modifiers, don't show the tabbox, // don't grab, but simply go to the next window @@ -898,7 +901,7 @@ bool TabBox::toggleMode(TabBoxMode mode) return true; } -bool TabBox::startKDEWalkThroughWindows(TabBoxMode mode) +bool TabBox::startKDEWalkThroughWindows(bool forward, TabBoxMode mode) { if (!establishTabBoxGrab()) { return false; @@ -911,13 +914,19 @@ bool TabBox::startKDEWalkThroughWindows(TabBoxMode mode) setMode(mode); reset(); + + if (haveActiveClient()) { + nextPrev(forward); + } + + delayedShow(); + return true; } void TabBox::KDEWalkThroughWindows(bool forward) { nextPrev(forward); - delayedShow(); } void TabBox::CDEWalkThroughWindows(bool forward) @@ -979,7 +988,11 @@ void TabBox::KDEOneStepThroughWindows(bool forward, TabBoxMode mode) { setMode(mode); reset(); - nextPrev(forward); + + if (haveActiveClient()) { + nextPrev(forward); + } + if (Window *c = currentClient()) { Workspace::self()->activateWindow(c); shadeActivate(c); diff --git a/src/tabbox/tabbox.h b/src/tabbox/tabbox.h index ec4ca2ba28..72e43b3a2e 100644 --- a/src/tabbox/tabbox.h +++ b/src/tabbox/tabbox.h @@ -93,6 +93,11 @@ public: */ void setCurrentClient(Window *newClient); + /** + * Return whether the active client is present in the client list. + */ + bool haveActiveClient(); + void setMode(TabBoxMode mode); TabBoxMode mode() const { @@ -228,7 +233,7 @@ private: explicit TabBox(QObject *parent); void loadConfig(const KConfigGroup &config, TabBoxConfig &tabBoxConfig); - bool startKDEWalkThroughWindows(TabBoxMode mode); // TabBoxWindowsMode | TabBoxWindowsAlternativeMode + bool startKDEWalkThroughWindows(bool forward, TabBoxMode mode); // TabBoxWindowsMode | TabBoxWindowsAlternativeMode void navigatingThroughWindows(bool forward, const QKeySequence &shortcut, TabBoxMode mode); // TabBoxWindowsMode | TabBoxWindowsAlternativeMode void KDEWalkThroughWindows(bool forward); void CDEWalkThroughWindows(bool forward); -- 2.47.0