diff --git a/doc/windowbehaviour/index.docbook b/doc/windowbehaviour/index.docbook index bebe41253e..606897c5ec 100644 --- a/doc/windowbehaviour/index.docbook +++ b/doc/windowbehaviour/index.docbook @@ -16,8 +16,8 @@ -2021-04-09 -Plasma 5.20 +2022-08-31 +Plasma 5.26 KDE @@ -699,6 +699,21 @@ with the proper window type for this feature to work. + +Virtual Desktop behavior +Sometimes calling an application will activate an existing window rather than opening a new window. This setting controls what should happen if that activated window is located on a Virtual Desktop other than the current one. + + +Switch to that Virtual Desktop +Will switch to the Virtual Desktop where the window is currently located. Choose this option if you would like the active desktop to automatically follow windows to their assigned desktop. + + +Bring window to current Virtual Desktop +Will cause the window to jump to the active Virtual Desktop. Choose this option if you would like windows to always open on the current Virtual Desktop, and the active Virtual Desktop to only switch when navigating there manually. + + + + diff --git a/src/activation.cpp b/src/activation.cpp index 36256d98f9..fe31de2513 100644 --- a/src/activation.cpp +++ b/src/activation.cpp @@ -290,7 +290,14 @@ void Workspace::activateWindow(Window *window, bool force) raiseWindow(window); if (!window->isOnCurrentDesktop()) { ++block_focus; - VirtualDesktopManager::self()->setCurrent(window->desktops().constLast()); + switch (options->activationDesktopPolicy()) { + case Options::ActivationDesktopPolicy::SwitchToOtherDesktop: + VirtualDesktopManager::self()->setCurrent(window->desktops().constLast()); + break; + case Options::ActivationDesktopPolicy::BringToCurrentDesktop: + window->enterDesktop(VirtualDesktopManager::self()->currentDesktop()); + break; + } --block_focus; } #if KWIN_BUILD_ACTIVITIES diff --git a/src/kcmkwin/kwinoptions/advanced.ui b/src/kcmkwin/kwinoptions/advanced.ui index ae519802a9..f4e3f00c45 100644 --- a/src/kcmkwin/kwinoptions/advanced.ui +++ b/src/kcmkwin/kwinoptions/advanced.ui @@ -6,8 +6,8 @@ 0 0 - 600 - 500 + 1001 + 297 @@ -142,6 +142,40 @@ + + + + Virtual Desktop behavior: + + + kcfg_ActivationDesktopPolicy + + + + + + + When activating a window on a different Virtual Desktop: + + + + + + + <html><head/><body><p>This setting controls what happens when an open window located on a Virtual Desktop other than the current one is activated. </p><p><span style=" font-style:italic;">Switch to other Virtual Desktop</span> will switch to the Virtual Desktop where the window is currently located. </p><p><span style=" font-style:italic;">Bring window to current Virtual Desktop</span> will cause the window to jump to the active Virtual Desktop. </p></body></html> + + + + Switch to that Virtual Desktop + + + + + Bring window to current Virtual Desktop + + + + diff --git a/src/kcmkwin/kwinoptions/kwinoptions_settings.kcfg b/src/kcmkwin/kwinoptions/kwinoptions_settings.kcfg index 2ac7e8bebe..2057f94299 100644 --- a/src/kcmkwin/kwinoptions/kwinoptions_settings.kcfg +++ b/src/kcmkwin/kwinoptions/kwinoptions_settings.kcfg @@ -54,6 +54,14 @@ true + + + + + + SwitchToOtherDesktop + + Maximize diff --git a/src/kcmkwin/kwinoptions/windows.cpp b/src/kcmkwin/kwinoptions/windows.cpp index f8fbac3dd8..2a95ebbc5a 100644 --- a/src/kcmkwin/kwinoptions/windows.cpp +++ b/src/kcmkwin/kwinoptions/windows.cpp @@ -257,6 +257,9 @@ void KAdvancedConfig::initialize(KWinOptionsSettings *settings, KWinOptionsKDEGl // This option lives in the kdeglobals file because it is consumed by // kxmlgui. m_ui->kcfg_AllowKDEAppsToRememberWindowPositions->setVisible(KWindowSystem::isPlatformX11()); + + m_ui->kcfg_ActivationDesktopPolicy->setItemData(KWinOptionsSettings::ActivationDesktopPolicyChoices::SwitchToOtherDesktop, "SwitchToOtherDesktop"); + m_ui->kcfg_ActivationDesktopPolicy->setItemData(KWinOptionsSettings::ActivationDesktopPolicyChoices::BringToCurrentDesktop, "BringToCurrentDesktop"); } void KAdvancedConfig::showEvent(QShowEvent *ev) diff --git a/src/kwin.kcfg b/src/kwin.kcfg index 624b9a27c8..05d6b1dcbd 100644 --- a/src/kwin.kcfg +++ b/src/kwin.kcfg @@ -133,6 +133,13 @@ #endif }() + + + + + + KWin::Options::ActivationDesktopPolicy::SwitchToOtherDesktop + false diff --git a/src/options.cpp b/src/options.cpp index 27555a9c19..ec2b41ba84 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -44,6 +44,7 @@ Options::Options(QObject *parent) , m_separateScreenFocus(false) , m_activeMouseScreen(false) , m_placement(Placement::NoPlacement) + , m_activationDesktopPolicy(Options::defaultActivationDesktopPolicy()) , m_borderSnapZone(0) , m_windowSnapZone(0) , m_centerSnapZone(0) @@ -243,6 +244,15 @@ void Options::setPlacement(int placement) Q_EMIT placementChanged(); } +void Options::setActivationDesktopPolicy(ActivationDesktopPolicy activationDesktopPolicy) +{ + if (m_activationDesktopPolicy == activationDesktopPolicy) { + return; + } + m_activationDesktopPolicy = activationDesktopPolicy; + Q_EMIT activationDesktopPolicyChanged(); +} + void Options::setBorderSnapZone(int borderSnapZone) { if (m_borderSnapZone == borderSnapZone) { @@ -759,6 +769,7 @@ void Options::syncFromKcfgc() setActiveMouseScreen(m_settings->activeMouseScreen()); setRollOverDesktops(m_settings->rollOverDesktops()); setFocusStealingPreventionLevel(m_settings->focusStealingPreventionLevel()); + setActivationDesktopPolicy(m_settings->activationDesktopPolicy()); setXwaylandCrashPolicy(m_settings->xwaylandCrashPolicy()); setXwaylandMaxCrashCount(m_settings->xwaylandMaxCrashCount()); setPlacement(m_settings->placement()); diff --git a/src/options.h b/src/options.h index 3d2615530b..cc2ac3c626 100644 --- a/src/options.h +++ b/src/options.h @@ -105,6 +105,7 @@ class KWIN_EXPORT Options : public QObject Q_PROPERTY(bool separateScreenFocus READ isSeparateScreenFocus WRITE setSeparateScreenFocus NOTIFY separateScreenFocusChanged) Q_PROPERTY(bool activeMouseScreen READ activeMouseScreen WRITE setActiveMouseScreen NOTIFY activeMouseScreenChanged) Q_PROPERTY(int placement READ placement WRITE setPlacement NOTIFY placementChanged) + Q_PROPERTY(ActivationDesktopPolicy activationDesktopPolicy READ activationDesktopPolicy WRITE setActivationDesktopPolicy NOTIFY activationDesktopPolicyChanged) Q_PROPERTY(bool focusPolicyIsReasonable READ focusPolicyIsReasonable NOTIFY focusPolicyIsResonableChanged) /** * The size of the zone that triggers snapping on desktop borders. @@ -327,6 +328,17 @@ public: return m_focusPolicy == ClickToFocus || m_focusPolicy == FocusFollowsMouse; } + enum ActivationDesktopPolicy { + SwitchToOtherDesktop, + BringToCurrentDesktop + }; + Q_ENUM(ActivationDesktopPolicy) + + ActivationDesktopPolicy activationDesktopPolicy() const + { + return m_activationDesktopPolicy; + } + /** * The size of the zone that triggers snapping on desktop borders. */ @@ -688,6 +700,7 @@ public: void setSeparateScreenFocus(bool separateScreenFocus); void setActiveMouseScreen(bool activeMouseScreen); void setPlacement(int placement); + void setActivationDesktopPolicy(ActivationDesktopPolicy activationDesktopPolicy); void setBorderSnapZone(int borderSnapZone); void setWindowSnapZone(int windowSnapZone); void setCenterSnapZone(int centerSnapZone); @@ -861,6 +874,10 @@ public: { return RenderTimeEstimatorMaximum; } + static ActivationDesktopPolicy defaultActivationDesktopPolicy() + { + return ActivationDesktopPolicy::SwitchToOtherDesktop; + } /** * Performs loading all settings except compositing related. */ @@ -888,6 +905,7 @@ Q_SIGNALS: void separateScreenFocusChanged(bool); void activeMouseScreenChanged(); void placementChanged(); + void activationDesktopPolicyChanged(); void borderSnapZoneChanged(); void windowSnapZoneChanged(); void centerSnapZoneChanged(); @@ -950,6 +968,7 @@ private: bool m_separateScreenFocus; bool m_activeMouseScreen; Placement::Policy m_placement; + ActivationDesktopPolicy m_activationDesktopPolicy; int m_borderSnapZone; int m_windowSnapZone; int m_centerSnapZone;