summaryrefslogtreecommitdiff
path: root/src/events/Windows.cpp
diff options
context:
space:
mode:
authorNikolai Nechaev <nikolay_nechaev@mail.ru>2025-11-26 07:44:26 +0900
committerGitHub <noreply@github.com>2025-11-25 22:44:26 +0000
commit40d8fa84919c6d0e9fcb1536f4bc09710d4c031c (patch)
treee45044c92e5d8f716f2aa15668c61fed5aaf5895 /src/events/Windows.cpp
parent1c1746de61a90dbbae072f3fc618c45af33fdd59 (diff)
compositor: Configurable behavior when window to be focused conflicts with fullscreen (#12033)
Renames `misc:new_window_takes_over_fullscreen` into `misc:on_focus_under_fullscreen` and implements the following behavior: - By default, when a tiling window is being focused on a workspace where a fullscreen/maximized window exists, respect the `misc:on_focus_under_fullscreen` config variable.
Diffstat (limited to 'src/events/Windows.cpp')
-rw-r--r--src/events/Windows.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp
index dfbb9f2e..9a1c07d9 100644
--- a/src/events/Windows.cpp
+++ b/src/events/Windows.cpp
@@ -20,6 +20,7 @@
#include "managers/animation/DesktopAnimationManager.hpp"
#include "managers/PointerManager.hpp"
#include "../desktop/LayerSurface.hpp"
+#include "../desktop/state/FocusState.hpp"
#include "../managers/LayoutManager.hpp"
#include "../managers/EventManager.hpp"
#include "../managers/animation/AnimationManager.hpp"
@@ -57,13 +58,13 @@ void Events::listener_mapWindow(void* owner, void* data) {
static auto PINACTIVEALPHA = CConfigValue<Hyprlang::FLOAT>("decoration:inactive_opacity");
static auto PACTIVEALPHA = CConfigValue<Hyprlang::FLOAT>("decoration:active_opacity");
static auto PDIMSTRENGTH = CConfigValue<Hyprlang::FLOAT>("decoration:dim_strength");
- static auto PNEWTAKESOVERFS = CConfigValue<Hyprlang::INT>("misc:new_window_takes_over_fullscreen");
+ static auto PNEWTAKESOVERFS = CConfigValue<Hyprlang::INT>("misc:on_focus_under_fullscreen");
static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking");
- auto PMONITOR = g_pCompositor->m_lastMonitor.lock();
- if (!g_pCompositor->m_lastMonitor) {
- g_pCompositor->setActiveMonitor(g_pCompositor->getMonitorFromVector({}));
- PMONITOR = g_pCompositor->m_lastMonitor.lock();
+ auto PMONITOR = Desktop::focusState()->monitor();
+ if (!Desktop::focusState()->monitor()) {
+ Desktop::focusState()->rawMonitorFocus(g_pCompositor->getMonitorFromVector({}));
+ PMONITOR = Desktop::focusState()->monitor();
}
auto PWORKSPACE = PMONITOR->m_activeSpecialWorkspace ? PMONITOR->m_activeSpecialWorkspace : PMONITOR->m_activeWorkspace;
PWINDOW->m_monitor = PMONITOR;
@@ -323,7 +324,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
else if (PMONITOR->activeWorkspaceID() != requestedWorkspaceID && !PWINDOW->m_noInitialFocus)
g_pKeybindManager->m_dispatchers["workspace"](requestedWorkspaceName);
- PMONITOR = g_pCompositor->m_lastMonitor.lock();
+ PMONITOR = Desktop::focusState()->monitor();
}
requestedFSMonitor = MONITOR_INVALID;
@@ -368,6 +369,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
// emit the IPC event before the layout might focus the window to avoid a focus event first
g_pEventManager->postEvent(SHyprIPCEvent{"openwindow", std::format("{:x},{},{},{}", PWINDOW, PWORKSPACE->m_name, PWINDOW->m_class, PWINDOW->m_title)});
+ EMIT_HOOK_EVENT("openWindowEarly", PWINDOW);
if (PWINDOW->m_isFloating) {
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW);
@@ -423,7 +425,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
PWINDOW->m_pseudoSize = PWINDOW->m_realSize->goal() - Vector2D(10, 10);
}
- const auto PFOCUSEDWINDOWPREV = g_pCompositor->m_lastWindow.lock();
+ const auto PFOCUSEDWINDOWPREV = Desktop::focusState()->window();
if (PWINDOW->m_ruleApplicator->allowsInput().valueOrDefault()) { // if default value wasn't set to false getPriority() would throw an exception
PWINDOW->m_ruleApplicator->noFocusOverride(Desktop::Types::COverridableVar(false, PWINDOW->m_ruleApplicator->allowsInput().getPriority()));
@@ -433,7 +435,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
// check LS focus grab
const auto PFORCEFOCUS = g_pCompositor->getForceFocus();
- const auto PLSFROMFOCUS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_lastFocus.lock());
+ const auto PLSFROMFOCUS = g_pCompositor->getLayerSurfaceFromSurface(Desktop::focusState()->surface());
if (PLSFROMFOCUS && PLSFROMFOCUS->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE)
PWINDOW->m_noInitialFocus = true;
@@ -449,7 +451,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
if (!PWINDOW->m_ruleApplicator->noFocus().valueOrDefault() && !PWINDOW->m_noInitialFocus &&
(!PWINDOW->isX11OverrideRedirect() || (PWINDOW->m_isX11 && PWINDOW->m_xwaylandSurface->wantsFocus())) && !workspaceSilent && (!PFORCEFOCUS || PFORCEFOCUS == PWINDOW) &&
!g_pInputManager->isConstrained()) {
- g_pCompositor->focusWindow(PWINDOW);
+ Desktop::focusState()->fullWindowFocus(PWINDOW);
PWINDOW->m_activeInactiveAlpha->setValueAndWarp(*PACTIVEALPHA);
PWINDOW->m_dimPercent->setValueAndWarp(PWINDOW->m_ruleApplicator->noDim().valueOrDefault() ? 0.f : *PDIMSTRENGTH);
} else {
@@ -488,10 +490,10 @@ void Events::listener_mapWindow(void* owner, void* data) {
if (workspaceSilent) {
if (validMapped(PFOCUSEDWINDOWPREV)) {
- g_pCompositor->focusWindow(PFOCUSEDWINDOWPREV);
+ Desktop::focusState()->rawWindowFocus(PFOCUSEDWINDOWPREV);
PFOCUSEDWINDOWPREV->updateWindowDecos(); // need to for some reason i cba to find out why
} else if (!PFOCUSEDWINDOWPREV)
- g_pCompositor->focusWindow(nullptr);
+ Desktop::focusState()->rawWindowFocus(nullptr);
}
// swallow
@@ -601,10 +603,10 @@ void Events::listener_unmapWindow(void* owner, void* data) {
bool wasLastWindow = false;
- if (PWINDOW == g_pCompositor->m_lastWindow.lock()) {
+ if (PWINDOW == Desktop::focusState()->window()) {
wasLastWindow = true;
- g_pCompositor->m_lastWindow.reset();
- g_pCompositor->m_lastFocus.reset();
+ Desktop::focusState()->window().reset();
+ Desktop::focusState()->surface().reset();
g_pInputManager->releaseAllMouseButtons();
}
@@ -636,8 +638,8 @@ void Events::listener_unmapWindow(void* owner, void* data) {
Debug::log(LOG, "On closed window, new focused candidate is {}", PWINDOWCANDIDATE);
- if (PWINDOWCANDIDATE != g_pCompositor->m_lastWindow.lock() && PWINDOWCANDIDATE) {
- g_pCompositor->focusWindow(PWINDOWCANDIDATE);
+ if (PWINDOWCANDIDATE != Desktop::focusState()->window() && PWINDOWCANDIDATE) {
+ Desktop::focusState()->fullWindowFocus(PWINDOWCANDIDATE);
if (*PEXITRETAINSFS && CURRENTWINDOWFSSTATE)
g_pCompositor->setWindowFullscreenInternal(PWINDOWCANDIDATE, CURRENTFSMODE);
}
@@ -648,7 +650,7 @@ void Events::listener_unmapWindow(void* owner, void* data) {
g_pInputManager->sendMotionEventsToFocused();
// CWindow::onUnmap will remove this window's active status, but we can't really do it above.
- if (PWINDOW == g_pCompositor->m_lastWindow.lock() || !g_pCompositor->m_lastWindow.lock()) {
+ if (PWINDOW == Desktop::focusState()->window() || !Desktop::focusState()->window()) {
g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","});
g_pEventManager->postEvent(SHyprIPCEvent{"activewindowv2", ""});
EMIT_HOOK_EVENT("activeWindow", PHLWINDOW{nullptr});
@@ -751,9 +753,9 @@ void Events::listener_destroyWindow(void* owner, void* data) {
Debug::log(LOG, "{:c} destroyed, queueing.", PWINDOW);
- if (PWINDOW == g_pCompositor->m_lastWindow.lock()) {
- g_pCompositor->m_lastWindow.reset();
- g_pCompositor->m_lastFocus.reset();
+ if (PWINDOW == Desktop::focusState()->window()) {
+ Desktop::focusState()->window().reset();
+ Desktop::focusState()->surface().reset();
}
PWINDOW->m_wlSurface->unassign();
@@ -786,17 +788,17 @@ void Events::listener_activateX11(void* owner, void* data) {
Debug::log(LOG, "Unmanaged X11 {} requests activate", PWINDOW);
- if (g_pCompositor->m_lastWindow.lock() && g_pCompositor->m_lastWindow->getPID() != PWINDOW->getPID())
+ if (Desktop::focusState()->window() && Desktop::focusState()->window()->getPID() != PWINDOW->getPID())
return;
if (!PWINDOW->m_xwaylandSurface->wantsFocus())
return;
- g_pCompositor->focusWindow(PWINDOW);
+ Desktop::focusState()->fullWindowFocus(PWINDOW);
return;
}
- if (PWINDOW == g_pCompositor->m_lastWindow.lock() || (PWINDOW->m_suppressedEvents & SUPPRESS_ACTIVATE))
+ if (PWINDOW == Desktop::focusState()->window() || (PWINDOW->m_suppressedEvents & SUPPRESS_ACTIVATE))
return;
PWINDOW->activate();