2022-03-18 20:03:39 +01:00
|
|
|
#include "XWaylandManager.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
#include "../events/Events.hpp"
|
2024-03-03 19:39:20 +01:00
|
|
|
#include "../config/ConfigValue.hpp"
|
2024-05-11 00:28:33 +02:00
|
|
|
#include "../protocols/XDGShell.hpp"
|
2023-06-23 21:14:04 +02:00
|
|
|
|
|
|
|
#define OUTPUT_MANAGER_VERSION 3
|
|
|
|
#define OUTPUT_DONE_DEPRECATED_SINCE_VERSION 3
|
|
|
|
#define OUTPUT_DESCRIPTION_MUTABLE_SINCE_VERSION 3
|
2022-03-18 20:03:39 +01:00
|
|
|
|
|
|
|
CHyprXWaylandManager::CHyprXWaylandManager() {
|
2022-10-27 12:26:35 +02:00
|
|
|
#ifndef NO_XWAYLAND
|
|
|
|
m_sWLRXWayland = wlr_xwayland_create(g_pCompositor->m_sWLDisplay, g_pCompositor->m_sWLRCompositor, 1);
|
2022-03-18 20:03:39 +01:00
|
|
|
|
2022-10-27 12:26:35 +02:00
|
|
|
if (!m_sWLRXWayland) {
|
|
|
|
Debug::log(ERR, "Couldn't start up the XWaylandManager because wlr_xwayland_create returned a nullptr!");
|
|
|
|
return;
|
|
|
|
}
|
2022-03-18 20:03:39 +01:00
|
|
|
|
2022-10-27 12:26:35 +02:00
|
|
|
addWLSignal(&m_sWLRXWayland->events.ready, &Events::listen_readyXWayland, m_sWLRXWayland, "XWayland Manager");
|
|
|
|
addWLSignal(&m_sWLRXWayland->events.new_surface, &Events::listen_surfaceXWayland, m_sWLRXWayland, "XWayland Manager");
|
2022-03-18 20:03:39 +01:00
|
|
|
|
2022-10-27 12:26:35 +02:00
|
|
|
setenv("DISPLAY", m_sWLRXWayland->display_name, 1);
|
2022-03-18 20:03:39 +01:00
|
|
|
|
2023-09-06 12:51:36 +02:00
|
|
|
Debug::log(LOG, "CHyprXWaylandManager started on display {}", m_sWLRXWayland->display_name);
|
2022-10-27 12:26:35 +02:00
|
|
|
#else
|
2022-12-16 18:17:31 +01:00
|
|
|
unsetenv("DISPLAY"); // unset DISPLAY so that X11 apps do not try to start on a different/invalid DISPLAY
|
2022-10-27 12:26:35 +02:00
|
|
|
#endif
|
2022-03-18 20:03:39 +01:00
|
|
|
}
|
|
|
|
|
2024-05-08 19:11:08 +02:00
|
|
|
CHyprXWaylandManager::~CHyprXWaylandManager() {
|
|
|
|
#ifndef NO_XWAYLAND
|
|
|
|
unsetenv("DISPLAY");
|
|
|
|
#endif
|
|
|
|
}
|
2022-03-18 20:03:39 +01:00
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
wlr_surface* CHyprXWaylandManager::getWindowSurface(PHLWINDOW pWindow) {
|
2024-05-11 00:28:33 +02:00
|
|
|
return pWindow->m_pWLSurface.wlr();
|
2022-03-18 20:03:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHyprXWaylandManager::activateSurface(wlr_surface* pSurface, bool activate) {
|
2022-08-31 11:12:46 +02:00
|
|
|
if (!pSurface)
|
|
|
|
return;
|
|
|
|
|
2024-05-11 00:28:33 +02:00
|
|
|
if (wlr_xwayland_surface_try_from_wlr_surface(pSurface)) {
|
2023-11-24 11:54:21 +01:00
|
|
|
const auto XSURF = wlr_xwayland_surface_try_from_wlr_surface(pSurface);
|
|
|
|
wlr_xwayland_surface_activate(XSURF, activate);
|
2022-07-07 21:47:59 +02:00
|
|
|
|
2023-11-24 11:54:21 +01:00
|
|
|
if (activate && !XSURF->override_redirect)
|
|
|
|
wlr_xwayland_surface_restack(XSURF, nullptr, XCB_STACK_MODE_ABOVE);
|
2022-04-05 18:29:58 +02:00
|
|
|
}
|
2024-05-11 00:28:33 +02:00
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// this cannot be nicely done until we rewrite wlr_surface
|
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
|
|
|
if (w->m_bIsX11 || !w->m_bIsMapped)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (w->m_pWLSurface.wlr() != pSurface)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
w->m_pXDGSurface->toplevel->setActive(activate);
|
|
|
|
}
|
2022-03-18 20:03:39 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CHyprXWaylandManager::activateWindow(PHLWINDOW pWindow, bool activate) {
|
2022-04-05 18:29:58 +02:00
|
|
|
if (pWindow->m_bIsX11) {
|
2024-03-02 01:35:17 +01:00
|
|
|
setWindowSize(pWindow, pWindow->m_vRealSize.value()); // update xwayland output pos
|
2022-05-11 15:03:31 +02:00
|
|
|
|
2022-10-28 20:18:10 +02:00
|
|
|
if (activate) {
|
|
|
|
wlr_xwayland_surface_set_minimized(pWindow->m_uSurface.xwayland, false);
|
2023-11-24 11:54:21 +01:00
|
|
|
if (!pWindow->m_uSurface.xwayland->override_redirect)
|
|
|
|
wlr_xwayland_surface_restack(pWindow->m_uSurface.xwayland, nullptr, XCB_STACK_MODE_ABOVE);
|
2022-10-28 20:18:10 +02:00
|
|
|
}
|
2022-12-16 18:17:31 +01:00
|
|
|
|
2022-04-02 18:57:09 +02:00
|
|
|
wlr_xwayland_surface_activate(pWindow->m_uSurface.xwayland, activate);
|
2024-05-11 00:28:33 +02:00
|
|
|
} else if (pWindow->m_pXDGSurface && pWindow->m_pXDGSurface->toplevel)
|
|
|
|
pWindow->m_pXDGSurface->toplevel->setActive(activate);
|
2022-04-02 18:57:09 +02:00
|
|
|
|
2022-10-25 15:19:24 +02:00
|
|
|
if (activate) {
|
2022-12-16 18:17:31 +01:00
|
|
|
g_pCompositor->m_pLastFocus = getWindowSurface(pWindow);
|
2022-10-25 15:19:24 +02:00
|
|
|
g_pCompositor->m_pLastWindow = pWindow;
|
|
|
|
}
|
2022-08-31 17:02:44 +02:00
|
|
|
|
2022-09-10 13:11:02 +02:00
|
|
|
if (!pWindow->m_bPinned)
|
2024-04-02 21:32:39 +02:00
|
|
|
pWindow->m_pWorkspace->m_pLastFocusedWindow = pWindow;
|
2022-04-02 18:57:09 +02:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CHyprXWaylandManager::getGeometryForWindow(PHLWINDOW pWindow, CBox* pbox) {
|
2022-03-18 20:03:39 +01:00
|
|
|
if (pWindow->m_bIsX11) {
|
2022-10-17 12:18:45 +02:00
|
|
|
const auto SIZEHINTS = pWindow->m_uSurface.xwayland->size_hints;
|
|
|
|
|
2022-10-17 15:26:18 +02:00
|
|
|
if (SIZEHINTS && pWindow->m_iX11Type != 2) {
|
2022-12-16 18:17:31 +01:00
|
|
|
pbox->x = SIZEHINTS->x;
|
|
|
|
pbox->y = SIZEHINTS->y;
|
|
|
|
pbox->width = SIZEHINTS->width;
|
2022-10-17 12:18:45 +02:00
|
|
|
pbox->height = SIZEHINTS->height;
|
|
|
|
} else {
|
2022-12-16 18:17:31 +01:00
|
|
|
pbox->x = pWindow->m_uSurface.xwayland->x;
|
|
|
|
pbox->y = pWindow->m_uSurface.xwayland->y;
|
|
|
|
pbox->width = pWindow->m_uSurface.xwayland->width;
|
2022-10-17 12:18:45 +02:00
|
|
|
pbox->height = pWindow->m_uSurface.xwayland->height;
|
|
|
|
}
|
2024-05-11 00:28:33 +02:00
|
|
|
} else if (pWindow->m_pXDGSurface)
|
|
|
|
*pbox = pWindow->m_pXDGSurface->current.geometry;
|
2022-03-18 20:03:39 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CHyprXWaylandManager::sendCloseWindow(PHLWINDOW pWindow) {
|
2023-06-18 18:14:48 +02:00
|
|
|
if (pWindow->m_bIsX11)
|
2022-03-18 20:03:39 +01:00
|
|
|
wlr_xwayland_surface_close(pWindow->m_uSurface.xwayland);
|
2024-05-11 00:28:33 +02:00
|
|
|
else if (pWindow->m_pXDGSurface && pWindow->m_pXDGSurface->toplevel)
|
|
|
|
pWindow->m_pXDGSurface->toplevel->close();
|
2022-03-18 20:03:39 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CHyprXWaylandManager::setWindowSize(PHLWINDOW pWindow, Vector2D size, bool force) {
|
2023-02-28 20:36:36 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");
|
2023-08-15 19:15:37 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
2022-07-28 23:55:00 +02:00
|
|
|
|
2024-02-05 21:56:20 +01:00
|
|
|
size = size.clamp(Vector2D{0, 0}, Vector2D{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()});
|
2024-02-05 15:08:08 +01:00
|
|
|
|
2023-08-15 19:15:37 +02:00
|
|
|
// calculate pos
|
|
|
|
// TODO: this should be decoupled from setWindowSize IMO
|
2024-03-02 01:35:17 +01:00
|
|
|
Vector2D windowPos = pWindow->m_vRealPosition.value();
|
2022-07-28 23:55:00 +02:00
|
|
|
|
2023-12-17 20:58:11 +01:00
|
|
|
if (pWindow->m_bIsX11 && PMONITOR) {
|
2023-08-15 19:15:37 +02:00
|
|
|
windowPos = windowPos - PMONITOR->vecPosition; // normalize to monitor
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PXWLFORCESCALEZERO)
|
2023-08-15 19:15:37 +02:00
|
|
|
windowPos = windowPos * PMONITOR->scale; // scale if applicable
|
|
|
|
windowPos = windowPos + PMONITOR->vecXWaylandPosition; // move to correct position for xwayland
|
|
|
|
}
|
|
|
|
|
2023-11-10 01:13:22 +01:00
|
|
|
if (!force && ((pWindow->m_vPendingReportedSize == size && windowPos == pWindow->m_vReportedPosition) || (pWindow->m_vPendingReportedSize == size && !pWindow->m_bIsX11)))
|
2023-08-15 19:15:37 +02:00
|
|
|
return;
|
|
|
|
|
2023-10-20 21:15:41 +02:00
|
|
|
pWindow->m_vReportedPosition = windowPos;
|
|
|
|
pWindow->m_vPendingReportedSize = size;
|
2023-06-11 21:52:13 +02:00
|
|
|
|
|
|
|
pWindow->m_fX11SurfaceScaledBy = 1.f;
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11 && PMONITOR) {
|
2023-12-17 20:58:11 +01:00
|
|
|
size = size * PMONITOR->scale;
|
|
|
|
pWindow->m_fX11SurfaceScaledBy = PMONITOR->scale;
|
2023-06-11 21:52:13 +02:00
|
|
|
}
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
if (pWindow->m_bIsX11)
|
2023-09-03 12:51:48 +02:00
|
|
|
wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, windowPos.x, windowPos.y, size.x, size.y);
|
2024-05-11 00:28:33 +02:00
|
|
|
else if (pWindow->m_pXDGSurface->toplevel)
|
|
|
|
pWindow->m_vPendingSizeAcks.push_back(std::make_pair<>(pWindow->m_pXDGSurface->toplevel->setSize(size), size.floor()));
|
2022-03-18 20:03:39 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
wlr_surface* CHyprXWaylandManager::surfaceAt(PHLWINDOW pWindow, const Vector2D& client, Vector2D& surface) {
|
2024-05-11 00:28:33 +02:00
|
|
|
return wlr_surface_surface_at(pWindow->m_pWLSurface.wlr(), client.x, client.y, &surface.x, &surface.y);
|
2022-03-20 13:37:07 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
bool CHyprXWaylandManager::shouldBeFloated(PHLWINDOW pWindow, bool pending) {
|
2022-03-20 13:37:07 +01:00
|
|
|
if (pWindow->m_bIsX11) {
|
|
|
|
for (size_t i = 0; i < pWindow->m_uSurface.xwayland->window_type_len; i++)
|
2022-12-16 18:17:31 +01:00
|
|
|
if (pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_DIALOG"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_SPLASH"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_TOOLBAR"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_UTILITY"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_TOOLTIP"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_POPUP_MENU"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_DOCK"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"] ||
|
2023-04-22 23:20:48 +02:00
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_MENU"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_KDE_NET_WM_WINDOW_TYPE_OVERRIDE"]) {
|
2022-12-20 00:43:47 +01:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_MENU"])
|
|
|
|
pWindow->m_bX11ShouldntFocus = true;
|
|
|
|
|
2024-03-03 01:18:53 +01:00
|
|
|
pWindow->m_bNoInitialFocus = true;
|
2022-12-16 18:17:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
2022-03-20 19:26:16 +01:00
|
|
|
|
2022-04-24 17:53:50 +02:00
|
|
|
if (pWindow->m_uSurface.xwayland->role) {
|
|
|
|
try {
|
|
|
|
std::string winrole = std::string(pWindow->m_uSurface.xwayland->role);
|
2022-07-06 16:50:11 +02:00
|
|
|
if (winrole.contains("pop-up") || winrole.contains("task_dialog")) {
|
2022-04-24 17:53:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
2023-09-06 12:51:36 +02:00
|
|
|
} catch (std::exception& e) { Debug::log(ERR, "Error in shouldBeFloated, winrole threw {}", e.what()); }
|
2022-04-24 17:53:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 18:29:13 +01:00
|
|
|
if (pWindow->m_uSurface.xwayland->modal) {
|
|
|
|
pWindow->m_bIsModal = true;
|
2022-03-20 19:26:16 +01:00
|
|
|
return true;
|
2022-03-22 18:29:13 +01:00
|
|
|
}
|
2022-03-20 19:26:16 +01:00
|
|
|
|
2023-06-18 18:14:48 +02:00
|
|
|
if (pWindow->m_iX11Type == 2)
|
2022-04-18 13:10:58 +02:00
|
|
|
return true; // override_redirect
|
|
|
|
|
2022-03-20 19:26:16 +01:00
|
|
|
const auto SIZEHINTS = pWindow->m_uSurface.xwayland->size_hints;
|
2022-03-22 21:28:57 +01:00
|
|
|
if (SIZEHINTS && (pWindow->m_uSurface.xwayland->parent || ((SIZEHINTS->min_width == SIZEHINTS->max_width) && (SIZEHINTS->min_height == SIZEHINTS->max_height))))
|
2022-03-20 19:26:16 +01:00
|
|
|
return true;
|
2022-03-21 17:24:41 +01:00
|
|
|
} else {
|
2024-05-11 00:28:33 +02:00
|
|
|
const auto PSTATE = pending ? &pWindow->m_pXDGSurface->toplevel->pending : &pWindow->m_pXDGSurface->toplevel->current;
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2024-05-11 00:28:33 +02:00
|
|
|
if (pWindow->m_pXDGSurface->toplevel->parent ||
|
|
|
|
(PSTATE->minSize.x != 0 && PSTATE->minSize.y != 0 && (PSTATE->minSize.x == PSTATE->maxSize.x || PSTATE->minSize.y == PSTATE->maxSize.y)))
|
2022-03-21 17:24:41 +01:00
|
|
|
return true;
|
2022-03-20 13:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-03-20 19:14:17 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CHyprXWaylandManager::moveXWaylandWindow(PHLWINDOW pWindow, const Vector2D& pos) {
|
|
|
|
if (!validMapped(pWindow))
|
2022-04-07 18:54:31 +02:00
|
|
|
return;
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2023-06-18 18:14:48 +02:00
|
|
|
if (!pWindow->m_bIsX11)
|
|
|
|
return;
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.value().x, pWindow->m_vRealSize.value().y);
|
2022-03-22 17:31:19 +01:00
|
|
|
}
|
2022-03-22 21:28:57 +01:00
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CHyprXWaylandManager::checkBorders(PHLWINDOW pWindow) {
|
2022-03-22 21:28:57 +01:00
|
|
|
if (!pWindow->m_bIsX11)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < pWindow->m_uSurface.xwayland->window_type_len; i++) {
|
2022-12-16 18:17:31 +01:00
|
|
|
if (pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_POPUP_MENU"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_NOTIFICATION"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_COMBO"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_MENU"] ||
|
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_SPLASH"] ||
|
2022-03-22 21:28:57 +01:00
|
|
|
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_TOOLTIP"]) {
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-03-22 21:28:57 +01:00
|
|
|
pWindow->m_bX11DoesntWantBorders = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 13:06:13 +01:00
|
|
|
if (pWindow->m_iX11Type == 2) {
|
2022-03-22 21:28:57 +01:00
|
|
|
pWindow->m_bX11DoesntWantBorders = true;
|
|
|
|
}
|
2022-03-30 17:39:04 +02:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
void CHyprXWaylandManager::setWindowFullscreen(PHLWINDOW pWindow, bool fullscreen) {
|
2023-06-18 18:14:48 +02:00
|
|
|
if (pWindow->m_bIsX11)
|
2022-03-30 17:39:04 +02:00
|
|
|
wlr_xwayland_surface_set_fullscreen(pWindow->m_uSurface.xwayland, fullscreen);
|
2024-05-11 00:28:33 +02:00
|
|
|
else if (pWindow->m_pXDGSurface && pWindow->m_pXDGSurface->toplevel)
|
|
|
|
pWindow->m_pXDGSurface->toplevel->setFullscreen(fullscreen);
|
2022-08-05 18:10:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
Vector2D CHyprXWaylandManager::getMaxSizeForWindow(PHLWINDOW pWindow) {
|
|
|
|
if (!validMapped(pWindow))
|
2022-08-05 19:41:50 +02:00
|
|
|
return Vector2D(99999, 99999);
|
|
|
|
|
2024-05-11 00:28:33 +02:00
|
|
|
if ((pWindow->m_bIsX11 && !pWindow->m_uSurface.xwayland->size_hints) || (!pWindow->m_bIsX11 && !pWindow->m_pXDGSurface->toplevel) || pWindow->m_sAdditionalConfigData.noMaxSize)
|
2022-08-05 19:41:50 +02:00
|
|
|
return Vector2D(99999, 99999);
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
auto MAXSIZE = pWindow->m_bIsX11 ? Vector2D(pWindow->m_uSurface.xwayland->size_hints->max_width, pWindow->m_uSurface.xwayland->size_hints->max_height) :
|
2024-05-11 00:28:33 +02:00
|
|
|
pWindow->m_pXDGSurface->toplevel->current.maxSize;
|
2022-08-05 18:10:59 +02:00
|
|
|
|
|
|
|
if (MAXSIZE.x < 5)
|
|
|
|
MAXSIZE.x = 99999;
|
|
|
|
if (MAXSIZE.y < 5)
|
|
|
|
MAXSIZE.y = 99999;
|
|
|
|
|
|
|
|
return MAXSIZE;
|
2023-08-15 20:09:32 +02:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
Vector2D CHyprXWaylandManager::getMinSizeForWindow(PHLWINDOW pWindow) {
|
|
|
|
if (!validMapped(pWindow))
|
2024-03-02 16:25:32 +01:00
|
|
|
return Vector2D(0, 0);
|
|
|
|
|
2024-05-11 00:28:33 +02:00
|
|
|
if ((pWindow->m_bIsX11 && !pWindow->m_uSurface.xwayland->size_hints) || (!pWindow->m_bIsX11 && !pWindow->m_pXDGSurface->toplevel))
|
2024-03-02 16:25:32 +01:00
|
|
|
return Vector2D(0, 0);
|
|
|
|
|
|
|
|
auto MINSIZE = pWindow->m_bIsX11 ? Vector2D(pWindow->m_uSurface.xwayland->size_hints->min_width, pWindow->m_uSurface.xwayland->size_hints->min_height) :
|
2024-05-11 00:28:33 +02:00
|
|
|
pWindow->m_pXDGSurface->toplevel->current.minSize;
|
2024-03-02 16:25:32 +01:00
|
|
|
|
|
|
|
MINSIZE = MINSIZE.clamp({1, 1});
|
|
|
|
|
|
|
|
return MINSIZE;
|
|
|
|
}
|
|
|
|
|
2023-08-15 20:09:32 +02:00
|
|
|
Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) {
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");
|
2023-08-15 20:09:32 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
CMonitor* pMonitor = nullptr;
|
|
|
|
double bestDistance = __FLT_MAX__;
|
2023-08-15 20:09:32 +02:00
|
|
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto SIZ = *PXWLFORCESCALEZERO ? m->vecTransformedSize : m->vecSize;
|
2023-09-04 17:30:44 +02:00
|
|
|
|
|
|
|
double distance =
|
2023-09-10 21:19:06 +02:00
|
|
|
vecToRectDistanceSquared(coord, {m->vecXWaylandPosition.x, m->vecXWaylandPosition.y}, {m->vecXWaylandPosition.x + SIZ.x - 1, m->vecXWaylandPosition.y + SIZ.y - 1});
|
2023-09-04 17:30:44 +02:00
|
|
|
|
|
|
|
if (distance < bestDistance) {
|
|
|
|
bestDistance = distance;
|
|
|
|
pMonitor = m.get();
|
2023-08-15 20:09:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pMonitor)
|
|
|
|
return Vector2D{};
|
|
|
|
|
|
|
|
// get local coords
|
|
|
|
Vector2D result = coord - pMonitor->vecXWaylandPosition;
|
|
|
|
// if scaled, unscale
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PXWLFORCESCALEZERO)
|
2023-08-15 20:09:32 +02:00
|
|
|
result = result / pMonitor->scale;
|
|
|
|
// add pos
|
|
|
|
result = result + pMonitor->vecPosition;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|