Hyprland/src/managers/XWaylandManager.cpp

177 lines
7.5 KiB
C++
Raw Normal View History

2022-03-18 20:03:39 +01:00
#include "XWaylandManager.hpp"
#include "../Compositor.hpp"
#include "../events/Events.hpp"
CHyprXWaylandManager::CHyprXWaylandManager() {
m_sWLRXWayland = wlr_xwayland_create(g_pCompositor->m_sWLDisplay, g_pCompositor->m_sWLRCompositor, 1);
if (!m_sWLRXWayland) {
Debug::log(ERR, "Couldn't start up the XWaylandManager because wlr_xwayland_create returned a nullptr!");
return;
}
2022-03-28 16:10:30 +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
setenv("DISPLAY", m_sWLRXWayland->display_name, 1);
Debug::log(LOG, "CHyprXWaylandManager started on display %s", m_sWLRXWayland->display_name);
}
CHyprXWaylandManager::~CHyprXWaylandManager() {
}
wlr_surface* CHyprXWaylandManager::getWindowSurface(CWindow* pWindow) {
if (pWindow->m_bIsX11)
return pWindow->m_uSurface.xwayland->surface;
return pWindow->m_uSurface.xdg->surface;
}
void CHyprXWaylandManager::activateSurface(wlr_surface* pSurface, bool activate) {
if (wlr_surface_is_xdg_surface(pSurface))
wlr_xdg_toplevel_set_activated(wlr_xdg_surface_from_wlr_surface(pSurface)->toplevel, activate);
else if (wlr_surface_is_xwayland_surface(pSurface))
wlr_xwayland_surface_activate(wlr_xwayland_surface_from_wlr_surface(pSurface), activate);
}
void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) {
if (pWindow->m_bIsX11) {
pbox->x = pWindow->m_uSurface.xwayland->x;
pbox->y = pWindow->m_uSurface.xwayland->y;
pbox->width = pWindow->m_uSurface.xwayland->width;
pbox->height = pWindow->m_uSurface.xwayland->height;
} else {
wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, pbox);
}
}
std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) {
2022-03-22 17:41:23 +01:00
try {
if (pWindow->m_bIsX11) {
2022-03-29 15:30:08 +02:00
if (pWindow->m_uSurface.xwayland && pWindow->m_uSurface.xwayland->title) {
2022-03-22 17:41:23 +01:00
return std::string(pWindow->m_uSurface.xwayland->title);
}
2022-03-24 18:22:01 +01:00
} else if (pWindow->m_uSurface.xdg) {
2022-03-29 15:30:08 +02:00
if (pWindow->m_uSurface.xdg->toplevel && pWindow->m_uSurface.xdg->toplevel->title) {
2022-03-24 18:22:01 +01:00
return std::string(pWindow->m_uSurface.xdg->toplevel->title);
}
2022-03-22 17:41:23 +01:00
} else {
return "";
2022-03-22 17:31:19 +01:00
}
2022-03-29 15:30:08 +02:00
} catch (std::exception& e) {
if (e.what())
Debug::log(ERR, "Error in getTitle: %s", e.what());
else
Debug::log(ERR, "Error in getTitle [e.what() nullptr]");
2022-03-24 18:22:01 +01:00
}
2022-03-22 17:41:23 +01:00
2022-03-24 18:22:01 +01:00
return "";
}
std::string CHyprXWaylandManager::getAppIDClass(CWindow* pWindow) {
try {
if (pWindow->m_bIsX11) {
if (pWindow->m_uSurface.xwayland) {
return std::string(pWindow->m_uSurface.xwayland->_class);
}
} else if (pWindow->m_uSurface.xdg) {
2022-03-22 17:41:23 +01:00
if (pWindow->m_uSurface.xdg->toplevel) {
2022-03-24 18:22:01 +01:00
return std::string(pWindow->m_uSurface.xdg->toplevel->app_id);
2022-03-22 17:41:23 +01:00
}
} else {
return "";
2022-03-22 17:31:19 +01:00
}
2022-03-22 17:41:23 +01:00
} catch (std::logic_error& e) {
2022-03-24 18:22:01 +01:00
Debug::log(ERR, "Error in getAppIDClass: %s", e.what());
2022-03-22 17:31:19 +01:00
}
2022-03-18 20:03:39 +01:00
2022-03-22 17:31:19 +01:00
return "";
2022-03-18 20:03:39 +01:00
}
void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) {
if (pWindow->m_bIsX11) {
wlr_xwayland_surface_close(pWindow->m_uSurface.xwayland);
} else {
wlr_xdg_toplevel_send_close(pWindow->m_uSurface.xdg->toplevel);
}
2022-03-19 20:30:21 +01:00
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow);
g_pCompositor->removeWindowFromVectorSafe(pWindow);
2022-03-18 20:03:39 +01:00
}
void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, const Vector2D& size) {
if (pWindow->m_bIsX11)
wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vRealPosition.x, pWindow->m_vRealPosition.y, size.x, size.y);
2022-03-18 20:03:39 +01:00
else
wlr_xdg_toplevel_set_size(pWindow->m_uSurface.xdg->toplevel, size.x, size.y);
}
void CHyprXWaylandManager::setWindowStyleTiled(CWindow* pWindow, uint32_t edgez) {
if (!pWindow->m_bIsX11)
wlr_xdg_toplevel_set_tiled(pWindow->m_uSurface.xdg->toplevel, edgez);
}
2022-03-19 10:53:39 +01:00
wlr_surface* CHyprXWaylandManager::surfaceAt(CWindow* pWindow, const Vector2D& client, Vector2D& surface) {
if (pWindow->m_bIsX11)
return wlr_surface_surface_at(pWindow->m_uSurface.xwayland->surface, client.x, client.y, &surface.x, &surface.y);
2022-03-18 20:03:39 +01:00
2022-03-19 10:53:39 +01:00
return wlr_xdg_surface_surface_at(pWindow->m_uSurface.xdg, client.x, client.y, &surface.x, &surface.y);
2022-03-20 13:37:07 +01:00
}
bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow) {
if (pWindow->m_bIsX11) {
for (size_t i = 0; i < pWindow->m_uSurface.xwayland->window_type_len; i++)
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"])
2022-03-22 21:28:57 +01:00
{
return true;
}
2022-03-20 19:26:16 +01: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
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 {
const auto PSTATE = &pWindow->m_uSurface.xdg->toplevel->current;
if ((PSTATE->min_width != 0 && PSTATE->min_height != 0 && (PSTATE->min_width == PSTATE->max_width || PSTATE->min_height == PSTATE->max_height)) || pWindow->m_uSurface.xdg->toplevel->parent)
return true;
2022-03-20 13:37:07 +01:00
}
return false;
}
void CHyprXWaylandManager::moveXWaylandWindow(CWindow* pWindow, const Vector2D& pos) {
if (pWindow->m_bIsX11) {
wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.x, pWindow->m_vRealSize.y);
}
2022-03-22 17:31:19 +01:00
}
2022-03-22 21:28:57 +01:00
void CHyprXWaylandManager::checkBorders(CWindow* pWindow) {
if (!pWindow->m_bIsX11)
return;
for (size_t i = 0; i < pWindow->m_uSurface.xwayland->window_type_len; i++) {
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"] ||
pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_TOOLTIP"]) {
pWindow->m_bX11DoesntWantBorders = true;
return;
}
}
if (pWindow->m_uSurface.xwayland->parent) {
pWindow->m_bX11DoesntWantBorders = true;
}
}