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) {
sl.x = subx;
sl.y = suby;
if (PFOUND != PSURFACE->surface)
Debug::log(LOG, "found non-base on window XDG %x", pWindow);
return PFOUND;
}
@ -356,16 +354,20 @@ SMonitor* CCompositor::getMonitorFromOutput(wlr_output* out) {
return nullptr;
}
void CCompositor::focusWindow(CWindow* pWindow) {
void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
if (!pWindow || !windowValidMapped(pWindow)) {
wlr_seat_keyboard_notify_clear_focus(m_sSeat.seat);
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) {
@ -376,8 +378,8 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
return;
// Unfocus last surface if should
if (m_pLastFocus && !wlr_surface_is_xwayland_surface(pSurface) && !m_pLastFocusWindow)
g_pXWaylandManager->activateSurface(m_pLastFocus, false);
if (m_pLastFocus && m_sSeat.seat->keyboard_state.focused_surface && wlr_surface_is_xdg_surface(m_pLastFocus))
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);
@ -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);
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)
Debug::log(LOG, "Set keyboard focus to surface %x, with window name: %s", pSurface, PWINDOW->m_szTitle.c_str());
else
@ -527,7 +519,10 @@ bool CCompositor::doesSeatAcceptInput(wlr_surface* surface) {
}
bool CCompositor::isWindowActive(CWindow* pWindow) {
if (!windowValidMapped(pWindow))
return false;
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();
wlr_surface* m_pLastFocus = nullptr;
wlr_surface* m_pLastFocusWindow = nullptr;
CWindow* m_pLastWindow = nullptr;
SMonitor* m_pLastMonitor = nullptr;
SSeat m_sSeat;
@ -71,7 +71,7 @@ public:
SMonitor* getMonitorFromCursor();
SMonitor* getMonitorFromVector(const Vector2D&);
void removeWindowFromVectorSafe(CWindow*);
void focusWindow(CWindow*);
void focusWindow(CWindow*, wlr_surface* pSurface = nullptr);
void focusSurface(wlr_surface*, CWindow* pWindowOwner = nullptr);
bool windowExists(CWindow*);
bool windowValidMapped(CWindow*);

View File

@ -2,6 +2,8 @@
#include "Compositor.hpp"
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_pLastWindow = nullptr;
}
}

View File

@ -54,7 +54,7 @@ std::string workspacesRequest() {
}
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))
return "Invalid";

View File

@ -156,8 +156,10 @@ void Events::listener_unmapWindow(void* owner, void* data) {
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;
}
PWINDOW->m_bMappedX11 = false;
@ -175,7 +177,7 @@ void Events::listener_unmapWindow(void* owner, void* data) {
// refocus on a new window
g_pInputManager->refocus();
Debug::log(LOG, "Destroying the SubSurface tree of unmapped window %x", PWINDOW);
SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree);
PWINDOW->m_pSurfaceTree = nullptr;
@ -192,8 +194,10 @@ void Events::listener_destroyWindow(void* owner, void* data) {
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;
}
PWINDOW->hyprListener_mapWindow.removeCallback();
PWINDOW->hyprListener_unmapWindow.removeCallback();
@ -202,6 +206,7 @@ void Events::listener_destroyWindow(void* owner, void* data) {
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
if (PWINDOW->m_pSurfaceTree) {
Debug::log(LOG, "Destroying Subsurface tree of %x in destroyWindow", PWINDOW);
SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree);
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);
subsurface->hyprListener_destroy.removeCallback();
subsurface->hyprListener_map.removeCallback();
subsurface->hyprListener_unmap.removeCallback();
subsurface->pParent->childSubsurfaces.remove(*subsurface);
}

View File

@ -34,27 +34,31 @@ void CInputManager::mouseMoveUnified(uint32_t time) {
Vector2D surfaceCoords;
Vector2D surfacePos = Vector2D(-1337, -1337);
CWindow* pFoundWindow = nullptr;
// first, we check if the workspace doesnt have a fullscreen window
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
if (PWORKSPACE->hasFullscreenWindow) {
const auto PFULLSCREENWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->ID);
pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->ID);
// should never ever happen but who knows
if (PFULLSCREENWINDOW) {
foundSurface = g_pXWaylandManager->getWindowSurface(PFULLSCREENWINDOW);
for (auto w = g_pCompositor->m_lWindows.rbegin(); w != g_pCompositor->m_lWindows.rend(); ++w) {
wlr_box box = {w->m_vRealPosition.x, w->m_vRealPosition.y, w->m_vRealSize.x, w->m_vRealSize.y};
if (w->m_iWorkspaceID == pFoundWindow->m_iWorkspaceID && w->m_bIsMapped && w->m_bCreatedOverFullscreen && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) {
foundSurface = g_pXWaylandManager->getWindowSurface(&(*w));
if (foundSurface)
surfacePos = PFULLSCREENWINDOW->m_vRealPosition;
for (auto& w : g_pCompositor->m_lWindows) {
wlr_box box = {w.m_vRealPosition.x, w.m_vRealPosition.y, w.m_vRealSize.x, w.m_vRealSize.y};
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(&w);
if (foundSurface)
surfacePos = w.m_vRealPosition;
surfacePos = w->m_vRealPosition;
break;
}
}
if (pFoundWindow && !foundSurface) {
if (pFoundWindow->m_bIsX11) {
foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow);
if (foundSurface)
surfacePos = pFoundWindow->m_vRealPosition;
} else {
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);
// then windows
const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowIdeal(mouseCoords);
if (!foundSurface && PWINDOWIDEAL) {
if (!PWINDOWIDEAL->m_bIsX11) {
foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, PWINDOWIDEAL, surfaceCoords);
pFoundWindow = g_pCompositor->vectorToWindowIdeal(mouseCoords);
if (!foundSurface && pFoundWindow) {
if (!pFoundWindow->m_bIsX11) {
foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords);
} else {
foundSurface = g_pXWaylandManager->getWindowSurface(PWINDOWIDEAL);
surfacePos = PWINDOWIDEAL->m_vRealPosition;
foundSurface = g_pXWaylandManager->getWindowSurface(pFoundWindow);
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_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());
}

View File

@ -88,8 +88,11 @@ void CKeybindManager::spawn(std::string args) {
}
void CKeybindManager::killActive(std::string args) {
if (g_pCompositor->m_pLastFocus && g_pCompositor->windowValidMapped(g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus)))
g_pXWaylandManager->sendCloseWindow(g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus));
if (g_pCompositor->m_pLastWindow && g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) {
g_pXWaylandManager->sendCloseWindow(g_pCompositor->m_pLastWindow);
g_pCompositor->m_pLastFocus = nullptr;
g_pCompositor->m_pLastWindow = nullptr;
}
g_pCompositor->focusWindow(g_pCompositor->windowFromCursor());
}
@ -99,7 +102,7 @@ void CKeybindManager::clearKeybinds() {
}
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)) {
ACTIVEWINDOW->m_bIsFloating = !ACTIVEWINDOW->m_bIsFloating;
@ -170,7 +173,7 @@ void CKeybindManager::changeworkspace(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))
return;
@ -187,7 +190,7 @@ void CKeybindManager::fullscreenActive(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))
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);
}
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) {
if (pWindow->m_bIsX11) {
pbox->x = pWindow->m_uSurface.xwayland->x;

View File

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