Multiple focus handling changes

This commit is contained in:
vaxerski 2022-04-02 18:57:09 +02:00
parent c923b4f075
commit 223beb8a82
10 changed files with 85 additions and 55 deletions

View File

@ -335,8 +335,6 @@ wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pW
if (PFOUND) { if (PFOUND) {
sl.x = subx; sl.x = subx;
sl.y = suby; sl.y = suby;
if (PFOUND != PSURFACE->surface)
Debug::log(LOG, "found non-base on window XDG %x", pWindow);
return PFOUND; return PFOUND;
} }
@ -356,16 +354,20 @@ SMonitor* CCompositor::getMonitorFromOutput(wlr_output* out) {
return nullptr; return nullptr;
} }
void CCompositor::focusWindow(CWindow* pWindow) { void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
if (!pWindow || !windowValidMapped(pWindow)) { if (!pWindow || !windowValidMapped(pWindow)) {
wlr_seat_keyboard_notify_clear_focus(m_sSeat.seat); wlr_seat_keyboard_notify_clear_focus(m_sSeat.seat);
return; return;
} }
const auto PWINDOWSURFACE = g_pXWaylandManager->getWindowSurface(pWindow); const auto PWINDOWSURFACE = pSurface ? pSurface : g_pXWaylandManager->getWindowSurface(pWindow);
focusSurface(PWINDOWSURFACE); focusSurface(PWINDOWSURFACE, pWindow);
g_pXWaylandManager->activateWindow(pWindow, true);
m_pLastWindow = pWindow;
} }
void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) { void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
@ -376,8 +378,8 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
return; return;
// Unfocus last surface if should // Unfocus last surface if should
if (m_pLastFocus && !wlr_surface_is_xwayland_surface(pSurface) && !m_pLastFocusWindow) if (m_pLastFocus && m_sSeat.seat->keyboard_state.focused_surface && wlr_surface_is_xdg_surface(m_pLastFocus))
g_pXWaylandManager->activateSurface(m_pLastFocus, false); wlr_xdg_toplevel_set_activated(wlr_xdg_surface_from_wlr_surface(m_pLastFocus)->toplevel, false);
const auto KEYBOARD = wlr_seat_get_keyboard(m_sSeat.seat); const auto KEYBOARD = wlr_seat_get_keyboard(m_sSeat.seat);
@ -386,16 +388,6 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
wlr_seat_keyboard_notify_enter(m_sSeat.seat, pSurface, KEYBOARD->keycodes, KEYBOARD->num_keycodes, &KEYBOARD->modifiers); wlr_seat_keyboard_notify_enter(m_sSeat.seat, pSurface, KEYBOARD->keycodes, KEYBOARD->num_keycodes, &KEYBOARD->modifiers);
m_pLastFocus = pSurface;
m_pLastFocusWindow = nullptr;
if (pWindowOwner) {
g_pXWaylandManager->activateSurface(g_pXWaylandManager->getWindowSurface(pWindowOwner), true);
m_pLastFocusWindow = pSurface;
}
else
g_pXWaylandManager->activateSurface(pSurface, true);
if (const auto PWINDOW = getWindowFromSurface(pSurface); PWINDOW) if (const auto PWINDOW = getWindowFromSurface(pSurface); PWINDOW)
Debug::log(LOG, "Set keyboard focus to surface %x, with window name: %s", pSurface, PWINDOW->m_szTitle.c_str()); Debug::log(LOG, "Set keyboard focus to surface %x, with window name: %s", pSurface, PWINDOW->m_szTitle.c_str());
else else
@ -527,7 +519,10 @@ bool CCompositor::doesSeatAcceptInput(wlr_surface* surface) {
} }
bool CCompositor::isWindowActive(CWindow* pWindow) { bool CCompositor::isWindowActive(CWindow* pWindow) {
if (!windowValidMapped(pWindow))
return false;
const auto PSURFACE = g_pXWaylandManager->getWindowSurface(pWindow); const auto PSURFACE = g_pXWaylandManager->getWindowSurface(pWindow);
return PSURFACE == m_pLastFocus || PSURFACE == m_pLastFocusWindow; return PSURFACE == m_pLastFocus || pWindow == m_pLastWindow;
} }

View File

@ -60,7 +60,7 @@ public:
void startCompositor(); void startCompositor();
wlr_surface* m_pLastFocus = nullptr; wlr_surface* m_pLastFocus = nullptr;
wlr_surface* m_pLastFocusWindow = nullptr; CWindow* m_pLastWindow = nullptr;
SMonitor* m_pLastMonitor = nullptr; SMonitor* m_pLastMonitor = nullptr;
SSeat m_sSeat; SSeat m_sSeat;
@ -71,7 +71,7 @@ public:
SMonitor* getMonitorFromCursor(); SMonitor* getMonitorFromCursor();
SMonitor* getMonitorFromVector(const Vector2D&); SMonitor* getMonitorFromVector(const Vector2D&);
void removeWindowFromVectorSafe(CWindow*); void removeWindowFromVectorSafe(CWindow*);
void focusWindow(CWindow*); void focusWindow(CWindow*, wlr_surface* pSurface = nullptr);
void focusSurface(wlr_surface*, CWindow* pWindowOwner = nullptr); void focusSurface(wlr_surface*, CWindow* pWindowOwner = nullptr);
bool windowExists(CWindow*); bool windowExists(CWindow*);
bool windowValidMapped(CWindow*); bool windowValidMapped(CWindow*);

View File

@ -2,6 +2,8 @@
#include "Compositor.hpp" #include "Compositor.hpp"
CWindow::~CWindow() { CWindow::~CWindow() {
if ((this->m_uSurface.xdg || this->m_uSurface.xwayland) && g_pCompositor->m_pLastFocus == g_pXWaylandManager->getWindowSurface(this)) if (g_pCompositor->isWindowActive(this)) {
g_pCompositor->m_pLastFocus = nullptr; g_pCompositor->m_pLastFocus = nullptr;
g_pCompositor->m_pLastWindow = nullptr;
}
} }

View File

@ -54,7 +54,7 @@ std::string workspacesRequest() {
} }
std::string activeWindowRequest() { std::string activeWindowRequest() {
const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus); const auto PWINDOW = g_pCompositor->m_pLastWindow;
if (!g_pCompositor->windowValidMapped(PWINDOW)) if (!g_pCompositor->windowValidMapped(PWINDOW))
return "Invalid"; return "Invalid";

View File

@ -156,8 +156,10 @@ void Events::listener_unmapWindow(void* owner, void* data) {
PWINDOW->hyprListener_setTitleWindow.removeCallback(); PWINDOW->hyprListener_setTitleWindow.removeCallback();
} }
if (g_pXWaylandManager->getWindowSurface(PWINDOW) == g_pCompositor->m_pLastFocus) if (PWINDOW == g_pCompositor->m_pLastWindow) {
g_pCompositor->m_pLastWindow = nullptr;
g_pCompositor->m_pLastFocus = nullptr; g_pCompositor->m_pLastFocus = nullptr;
}
PWINDOW->m_bMappedX11 = false; PWINDOW->m_bMappedX11 = false;
@ -175,7 +177,7 @@ void Events::listener_unmapWindow(void* owner, void* data) {
// refocus on a new window // refocus on a new window
g_pInputManager->refocus(); g_pInputManager->refocus();
Debug::log(LOG, "Destroying the SubSurface tree of unmapped window %x", PWINDOW);
SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree); SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree);
PWINDOW->m_pSurfaceTree = nullptr; PWINDOW->m_pSurfaceTree = nullptr;
@ -192,8 +194,10 @@ void Events::listener_destroyWindow(void* owner, void* data) {
Debug::log(LOG, "Window %x destroyed", PWINDOW); Debug::log(LOG, "Window %x destroyed", PWINDOW);
if (g_pXWaylandManager->getWindowSurface(PWINDOW) == g_pCompositor->m_pLastFocus) if (PWINDOW == g_pCompositor->m_pLastWindow) {
g_pCompositor->m_pLastWindow = nullptr;
g_pCompositor->m_pLastFocus = nullptr; g_pCompositor->m_pLastFocus = nullptr;
}
PWINDOW->hyprListener_mapWindow.removeCallback(); PWINDOW->hyprListener_mapWindow.removeCallback();
PWINDOW->hyprListener_unmapWindow.removeCallback(); PWINDOW->hyprListener_unmapWindow.removeCallback();
@ -202,6 +206,7 @@ void Events::listener_destroyWindow(void* owner, void* data) {
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
if (PWINDOW->m_pSurfaceTree) { if (PWINDOW->m_pSurfaceTree) {
Debug::log(LOG, "Destroying Subsurface tree of %x in destroyWindow", PWINDOW);
SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree); SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree);
PWINDOW->m_pSurfaceTree = nullptr; PWINDOW->m_pSurfaceTree = nullptr;
} }

View File

@ -154,6 +154,10 @@ void Events::listener_destroySubsurface(void* owner, void* data) {
Debug::log(LOG, "Subsurface %x destroyed", subsurface); Debug::log(LOG, "Subsurface %x destroyed", subsurface);
subsurface->hyprListener_destroy.removeCallback();
subsurface->hyprListener_map.removeCallback();
subsurface->hyprListener_unmap.removeCallback();
subsurface->pParent->childSubsurfaces.remove(*subsurface); subsurface->pParent->childSubsurfaces.remove(*subsurface);
} }

View File

@ -34,26 +34,30 @@ void CInputManager::mouseMoveUnified(uint32_t time) {
Vector2D surfaceCoords; Vector2D surfaceCoords;
Vector2D surfacePos = Vector2D(-1337, -1337); Vector2D surfacePos = Vector2D(-1337, -1337);
CWindow* pFoundWindow = nullptr;
// first, we check if the workspace doesnt have a fullscreen window // first, we check if the workspace doesnt have a fullscreen window
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
if (PWORKSPACE->hasFullscreenWindow) { if (PWORKSPACE->hasFullscreenWindow) {
const auto PFULLSCREENWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->ID); pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->ID);
// should never ever happen but who knows for (auto w = g_pCompositor->m_lWindows.rbegin(); w != g_pCompositor->m_lWindows.rend(); ++w) {
if (PFULLSCREENWINDOW) { wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y};
foundSurface = g_pXWaylandManager->getWindowSurface(PFULLSCREENWINDOW); if (w->m_iWorkspaceID == pFoundWindow->m_iWorkspaceID && w->m_bIsMapped && w->m_bCreatedOverFullscreen && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) {
if (foundSurface) foundSurface = g_pXWaylandManager->getWindowSurface(&(*w));
surfacePos = PFULLSCREENWINDOW->m_vRealPosition; if (foundSurface)
surfacePos = w->m_vRealPosition;
break;
}
}
for (auto& w : g_pCompositor->m_lWindows) { if (pFoundWindow && !foundSurface) {
wlr_box box = {w.m_vRealPosition.x, w.m_vRealPosition.y, w.m_vRealSize.x, w.m_vRealSize.y}; if (pFoundWindow->m_bIsX11) {
if (w.m_iWorkspaceID == PFULLSCREENWINDOW->m_iWorkspaceID && w.m_bIsMapped && w.m_bCreatedOverFullscreen && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) { foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow);
foundSurface = g_pXWaylandManager->getWindowSurface(&w); if (foundSurface)
if (foundSurface) surfacePos = pFoundWindow->m_vRealPosition;
surfacePos = w.m_vRealPosition; } else {
break; foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords);
}
} }
} }
} }
@ -66,13 +70,13 @@ void CInputManager::mouseMoveUnified(uint32_t time) {
foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords); foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords);
// then windows // then windows
const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowIdeal(mouseCoords); pFoundWindow = g_pCompositor->vectorToWindowIdeal(mouseCoords);
if (!foundSurface && PWINDOWIDEAL) { if (!foundSurface && pFoundWindow) {
if (!PWINDOWIDEAL->m_bIsX11) { if (!pFoundWindow->m_bIsX11) {
foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, PWINDOWIDEAL, surfaceCoords); foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords);
} else { } else {
foundSurface = g_pXWaylandManager->getWindowSurface(PWINDOWIDEAL); foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow);
surfacePos = PWINDOWIDEAL->m_vRealPosition; surfacePos = pFoundWindow->m_vRealPosition;
} }
} }
@ -100,7 +104,10 @@ void CInputManager::mouseMoveUnified(uint32_t time) {
wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y); wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, foundSurface, surfaceLocal.x, surfaceLocal.y);
wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, time, surfaceLocal.x, surfaceLocal.y);
g_pCompositor->focusSurface(foundSurface, PWINDOWIDEAL ? PWINDOWIDEAL : nullptr); if (pFoundWindow)
g_pCompositor->focusWindow(pFoundWindow, foundSurface);
else
g_pCompositor->focusSurface(foundSurface);
g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal()); g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal());
} }

View File

@ -88,8 +88,11 @@ void CKeybindManager::spawn(std::string args) {
} }
void CKeybindManager::killActive(std::string args) { void CKeybindManager::killActive(std::string args) {
if (g_pCompositor->m_pLastFocus && g_pCompositor->windowValidMapped(g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus))) if (g_pCompositor->m_pLastWindow && g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) {
g_pXWaylandManager->sendCloseWindow(g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus)); g_pXWaylandManager->sendCloseWindow(g_pCompositor->m_pLastWindow);
g_pCompositor->m_pLastFocus = nullptr;
g_pCompositor->m_pLastWindow = nullptr;
}
g_pCompositor->focusWindow(g_pCompositor->windowFromCursor()); g_pCompositor->focusWindow(g_pCompositor->windowFromCursor());
} }
@ -99,7 +102,7 @@ void CKeybindManager::clearKeybinds() {
} }
void CKeybindManager::toggleActiveFloating(std::string args) { void CKeybindManager::toggleActiveFloating(std::string args) {
const auto ACTIVEWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus); const auto ACTIVEWINDOW = g_pCompositor->m_pLastWindow;
if (g_pCompositor->windowValidMapped(ACTIVEWINDOW)) { if (g_pCompositor->windowValidMapped(ACTIVEWINDOW)) {
ACTIVEWINDOW->m_bIsFloating = !ACTIVEWINDOW->m_bIsFloating; ACTIVEWINDOW->m_bIsFloating = !ACTIVEWINDOW->m_bIsFloating;
@ -170,7 +173,7 @@ void CKeybindManager::changeworkspace(std::string args) {
} }
void CKeybindManager::fullscreenActive(std::string args) { void CKeybindManager::fullscreenActive(std::string args) {
const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus); const auto PWINDOW = g_pCompositor->m_pLastWindow;
if (!g_pCompositor->windowValidMapped(PWINDOW)) if (!g_pCompositor->windowValidMapped(PWINDOW))
return; return;
@ -187,7 +190,7 @@ void CKeybindManager::fullscreenActive(std::string args) {
} }
void CKeybindManager::moveActiveToWorkspace(std::string args) { void CKeybindManager::moveActiveToWorkspace(std::string args) {
const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus); const auto PWINDOW = g_pCompositor->m_pLastWindow;
if (!g_pCompositor->windowValidMapped(PWINDOW)) if (!g_pCompositor->windowValidMapped(PWINDOW))
return; return;

View File

@ -37,6 +37,19 @@ void CHyprXWaylandManager::activateSurface(wlr_surface* pSurface, bool activate)
wlr_xwayland_surface_activate(wlr_xwayland_surface_from_wlr_surface(pSurface), activate); wlr_xwayland_surface_activate(wlr_xwayland_surface_from_wlr_surface(pSurface), activate);
} }
void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) {
if (pWindow == g_pCompositor->m_pLastWindow)
return;
if (pWindow->m_bIsX11)
wlr_xwayland_surface_activate(pWindow->m_uSurface.xwayland, activate);
else
wlr_xdg_toplevel_set_activated(pWindow->m_uSurface.xdg->toplevel, activate);
g_pCompositor->m_pLastFocus = getWindowSurface(pWindow);
g_pCompositor->m_pLastWindow = pWindow;
}
void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) { void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) {
if (pWindow->m_bIsX11) { if (pWindow->m_bIsX11) {
pbox->x = pWindow->m_uSurface.xwayland->x; pbox->x = pWindow->m_uSurface.xwayland->x;

View File

@ -12,6 +12,7 @@ public:
wlr_surface* getWindowSurface(CWindow*); wlr_surface* getWindowSurface(CWindow*);
void activateSurface(wlr_surface*, bool); void activateSurface(wlr_surface*, bool);
void activateWindow(CWindow*, bool);
void getGeometryForWindow(CWindow*, wlr_box*); void getGeometryForWindow(CWindow*, wlr_box*);
std::string getTitle(CWindow*); std::string getTitle(CWindow*);
std::string getAppIDClass(CWindow*); std::string getAppIDClass(CWindow*);