From f7174acc4850ac93feb291707de9d9861c9fab56 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 28 Oct 2022 19:18:10 +0100 Subject: [PATCH] minor fixes for xwayland refocus --- src/Compositor.cpp | 9 +++---- src/events/Windows.cpp | 43 +++++++++++++++++++++++++------- src/managers/XWaylandManager.cpp | 8 +++--- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 1bab19ab..fccd43c2 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -715,6 +715,8 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { if (windowValidMapped(PLASTWINDOW)) { updateWindowAnimatedDecorationValues(PLASTWINDOW); + g_pXWaylandManager->activateWindow(PLASTWINDOW, false); + if (PLASTWINDOW->m_phForeignToplevel) wlr_foreign_toplevel_handle_v1_set_activated(PLASTWINDOW->m_phForeignToplevel, false); } @@ -750,10 +752,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { if (windowValidMapped(PLASTWINDOW)) { updateWindowAnimatedDecorationValues(PLASTWINDOW); - if (PLASTWINDOW->m_bIsX11) { - wlr_seat_keyboard_notify_clear_focus(m_sSeat.seat); - wlr_seat_pointer_clear_focus(m_sSeat.seat); - } + g_pXWaylandManager->activateWindow(PLASTWINDOW, false); if (PLASTWINDOW->m_phForeignToplevel) wlr_foreign_toplevel_handle_v1_set_activated(PLASTWINDOW->m_phForeignToplevel, false); @@ -788,7 +787,7 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) { return; // Don't focus when already focused on this. // Unfocus last surface if should - if (m_pLastFocus && ((m_sSeat.seat->keyboard_state.focused_surface && wlr_surface_is_xdg_surface(m_pLastFocus)) || !pSurface)) + if (m_pLastFocus && !pWindowOwner) g_pXWaylandManager->activateSurface(m_pLastFocus, false); if (!pSurface) { diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index cf31a0f0..07835543 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -413,6 +413,8 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->hyprListener_activateX11.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_activate, &Events::listener_activateX11, PWINDOW, "XWayland Window Late"); PWINDOW->hyprListener_configureX11.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_configure, &Events::listener_configureX11, PWINDOW, "XWayland Window Late"); PWINDOW->hyprListener_setTitleWindow.initCallback(&PWINDOW->m_uSurface.xwayland->events.set_title, &Events::listener_setTitleWindow, PWINDOW, "XWayland Window Late"); + PWINDOW->hyprListener_requestMinimize.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_minimize, &Events::listener_requestMinimize, PWINDOW, "Xwayland Window Late"); + PWINDOW->hyprListener_requestMinimize.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_maximize, &Events::listener_requestMaximize, PWINDOW, "Xwayland Window Late"); if (PWINDOW->m_iX11Type == 2) PWINDOW->hyprListener_setGeometryX11U.initCallback(&PWINDOW->m_uSurface.xwayland->events.set_geometry, &Events::listener_unmanagedSetGeometry, PWINDOW, "XWayland Window Late"); @@ -548,6 +550,8 @@ void Events::listener_unmapWindow(void* owner, void* data) { PWINDOW->hyprListener_configureX11.removeCallback(); PWINDOW->hyprListener_setTitleWindow.removeCallback(); PWINDOW->hyprListener_setGeometryX11U.removeCallback(); + PWINDOW->hyprListener_requestMaximize.removeCallback(); + PWINDOW->hyprListener_requestMinimize.removeCallback(); } if (PWINDOW->m_bIsFullscreen) { @@ -714,14 +718,15 @@ void Events::listener_fullscreenWindow(void* owner, void* data) { wlr_xdg_surface_schedule_configure(PWINDOW->m_uSurface.xdg); } else { - g_pCompositor->setWindowFullscreen(PWINDOW, !PWINDOW->m_bIsFullscreen, FULLSCREEN_FULL); + if (!PWINDOW->m_uSurface.xwayland->mapped) + return; + + g_pCompositor->setWindowFullscreen(PWINDOW, PWINDOW->m_uSurface.xwayland->fullscreen, FULLSCREEN_FULL); } PWINDOW->updateToplevel(); Debug::log(LOG, "Window %x fullscreen to %i", PWINDOW, PWINDOW->m_bIsFullscreen); - - g_pXWaylandManager->setWindowFullscreen(PWINDOW, PWINDOW->m_bIsFullscreen); } void Events::listener_activateXDG(wl_listener* listener, void* data) { @@ -775,7 +780,7 @@ void Events::listener_configureX11(void* owner, void* data) { return; } - if (!PWINDOW->m_uSurface.xwayland->mapped) { + if (!PWINDOW->m_uSurface.xwayland->mapped || !PWINDOW->m_bMappedX11) { wlr_xwayland_surface_configure(PWINDOW->m_uSurface.xwayland, E->x, E->y, E->width, E->height); return; } @@ -882,15 +887,35 @@ void Events::listener_NewXDGDeco(wl_listener* listener, void* data) { void Events::listener_requestMaximize(void* owner, void* data) { const auto PWINDOW = (CWindow*)owner; - const auto EV = (wlr_foreign_toplevel_handle_v1_maximized_event*)data; + Debug::log(LOG, "Maximize request for %x", PWINDOW); - g_pCompositor->setWindowFullscreen(PWINDOW, EV ? EV->maximized : !PWINDOW->m_bIsFullscreen, FULLSCREEN_MAXIMIZED); // this will be rejected if there already is a fullscreen window - - wlr_xdg_surface_schedule_configure(PWINDOW->m_uSurface.xdg); + if (!PWINDOW->m_bIsX11) { + const auto EV = (wlr_foreign_toplevel_handle_v1_maximized_event*)data; + + g_pCompositor->setWindowFullscreen(PWINDOW, EV ? EV->maximized : !PWINDOW->m_bIsFullscreen, FULLSCREEN_MAXIMIZED); // this will be rejected if there already is a fullscreen window + + wlr_xdg_surface_schedule_configure(PWINDOW->m_uSurface.xdg); + } else { + if (!PWINDOW->m_bMappedX11 || PWINDOW->m_iX11Type != 1) + return; + + g_pCompositor->setWindowFullscreen(PWINDOW, !PWINDOW->m_bIsFullscreen, FULLSCREEN_MAXIMIZED); + } } void Events::listener_requestMinimize(void* owner, void* data) { - // ignore + const auto PWINDOW = (CWindow*)owner; + + Debug::log(LOG, "Minimize request for %x", PWINDOW); + + // if (PWINDOW->m_bIsX11) { + // if (!PWINDOW->m_bMappedX11 || PWINDOW->m_iX11Type != 1) + // return; + + // const auto E = (wlr_xwayland_minimize_event*)data; + + // wlr_xwayland_surface_set_minimized(PWINDOW->m_uSurface.xwayland, E->minimize && g_pCompositor->m_pLastWindow != PWINDOW); // fucking DXVK + // } } void Events::listener_requestMove(void* owner, void* data) { diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 89bb6871..3f6c2371 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -53,11 +53,13 @@ void CHyprXWaylandManager::activateSurface(wlr_surface* pSurface, bool activate) void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) { if (pWindow->m_bIsX11) { - if (pWindow->m_uSurface.xwayland->minimized) - wlr_xwayland_surface_set_minimized(pWindow->m_uSurface.xwayland, false); + if (activate) { + wlr_xwayland_surface_set_minimized(pWindow->m_uSurface.xwayland, false); + wlr_xwayland_surface_restack(pWindow->m_uSurface.xwayland, NULL, XCB_STACK_MODE_ABOVE); + } + wlr_xwayland_surface_activate(pWindow->m_uSurface.xwayland, activate); - wlr_xwayland_surface_restack(pWindow->m_uSurface.xwayland, NULL, XCB_STACK_MODE_ABOVE); } else wlr_xdg_toplevel_set_activated(pWindow->m_uSurface.xdg->toplevel, activate);