handle subsurfaces

This commit is contained in:
vaxerski 2022-03-21 16:13:43 +01:00
parent d06423c9d1
commit bcb02b9307
11 changed files with 215 additions and 32 deletions

View File

@ -36,6 +36,7 @@ target_link_libraries(Hyprland PkgConfig::deps)
target_link_libraries(Hyprland target_link_libraries(Hyprland
wlroots wlroots
pixman-1
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
) )

View File

@ -53,6 +53,7 @@ public:
std::list<SLayerPopup> m_lLayerPopups; std::list<SLayerPopup> m_lLayerPopups;
std::list<SXDGPopup> m_lXDGPopups; std::list<SXDGPopup> m_lXDGPopups;
std::list<SWorkspace> m_lWorkspaces; std::list<SWorkspace> m_lWorkspaces;
std::list<SSubsurface> m_lSubsurfaces;
void startCompositor(); void startCompositor();

View File

@ -14,6 +14,7 @@ public:
DYNLISTENER(setTitleWindow); DYNLISTENER(setTitleWindow);
DYNLISTENER(fullscreenWindow); DYNLISTENER(fullscreenWindow);
DYNLISTENER(newPopupXDG); DYNLISTENER(newPopupXDG);
DYNLISTENER(newSubsurfaceWindow);
union { union {
wlr_xdg_surface* xdg; wlr_xdg_surface* xdg;

View File

@ -13,6 +13,13 @@ namespace Events {
LISTENER(unmapLayerSurface); LISTENER(unmapLayerSurface);
LISTENER(commitLayerSurface); LISTENER(commitLayerSurface);
// Subsurfaces
LISTENER(newSubsurface);
LISTENER(mapSubsurface);
LISTENER(unmapSubsurface);
LISTENER(destroySubsurface);
LISTENER(commitSubsurface);
// Popups // Popups
LISTENER(newPopup); LISTENER(newPopup);
LISTENER(newPopupFromPopup); LISTENER(newPopupFromPopup);
@ -41,6 +48,9 @@ namespace Events {
LISTENER(activateX11); LISTENER(activateX11);
LISTENER(configureX11); LISTENER(configureX11);
// Window subsurfaces
LISTENER(newSubsurfaceWindow);
// Input events // Input events
LISTENER(mouseMove); LISTENER(mouseMove);
LISTENER(mouseMoveAbsolute); LISTENER(mouseMoveAbsolute);

View File

@ -44,6 +44,7 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) {
wl_signal_add(&WLRLAYERSURFACE->events.map, &layerSurface->listen_mapLayerSurface); wl_signal_add(&WLRLAYERSURFACE->events.map, &layerSurface->listen_mapLayerSurface);
wl_signal_add(&WLRLAYERSURFACE->events.unmap, &layerSurface->listen_unmapLayerSurface); wl_signal_add(&WLRLAYERSURFACE->events.unmap, &layerSurface->listen_unmapLayerSurface);
wl_signal_add(&WLRLAYERSURFACE->events.new_popup, &layerSurface->listen_newPopup); wl_signal_add(&WLRLAYERSURFACE->events.new_popup, &layerSurface->listen_newPopup);
wl_signal_add(&WLRLAYERSURFACE->surface->events.new_subsurface, &layerSurface->listen_newSubsurface);
layerSurface->layerSurface = WLRLAYERSURFACE; layerSurface->layerSurface = WLRLAYERSURFACE;
WLRLAYERSURFACE->data = layerSurface; WLRLAYERSURFACE->data = layerSurface;
@ -144,44 +145,72 @@ void Events::listener_commitLayerSurface(wl_listener* listener, void* data) {
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PMONITOR->ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PMONITOR->ID);
} }
void Events::listener_surfaceXWayland(wl_listener* listener, void* data) { //
const auto XWSURFACE = (wlr_xwayland_surface*)data; // Subsurfaces
//
g_pCompositor->m_lWindows.push_back(CWindow()); void createSubsurface(wlr_subsurface* pSubSurface, SLayerSurface* pLayerSurface) {
const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back(); if (!pSubSurface || !pLayerSurface)
return;
PNEWWINDOW->m_uSurface.xwayland = XWSURFACE; g_pCompositor->m_lSubsurfaces.push_back(SSubsurface());
PNEWWINDOW->m_iX11Type = XWSURFACE->override_redirect ? 2 : 1; const auto PNEWSUBSURFACE = &g_pCompositor->m_lSubsurfaces.back();
PNEWWINDOW->m_bIsX11 = true;
wl_signal_add(&XWSURFACE->events.map, &PNEWWINDOW->listen_mapWindow); PNEWSUBSURFACE->subsurface = pSubSurface;
wl_signal_add(&XWSURFACE->events.unmap, &PNEWWINDOW->listen_unmapWindow); PNEWSUBSURFACE->pParentSurface = pLayerSurface;
wl_signal_add(&XWSURFACE->events.request_activate, &PNEWWINDOW->listen_activateX11);
wl_signal_add(&XWSURFACE->events.request_configure, &PNEWWINDOW->listen_configureX11);
wl_signal_add(&XWSURFACE->events.set_title, &PNEWWINDOW->listen_setTitleWindow);
wl_signal_add(&XWSURFACE->events.destroy, &PNEWWINDOW->listen_destroyWindow);
wl_signal_add(&XWSURFACE->events.request_fullscreen, &PNEWWINDOW->listen_fullscreenWindow);
Debug::log(LOG, "New XWayland Surface created."); wl_signal_add(&pSubSurface->events.map, &PNEWSUBSURFACE->listen_mapSubsurface);
wl_signal_add(&pSubSurface->events.unmap, &PNEWSUBSURFACE->listen_unmapSubsurface);
wl_signal_add(&pSubSurface->events.destroy, &PNEWSUBSURFACE->listen_destroySubsurface);
wl_signal_add(&pSubSurface->surface->events.commit, &PNEWSUBSURFACE->listen_commitSubsurface);
} }
void Events::listener_newXDGSurface(wl_listener* listener, void* data) { void damageSubsurface(SSubsurface* subSurface, bool all = false) {
// A window got opened if (!subSurface->pParentSurface->layerSurface->output)
const auto XDGSURFACE = (wlr_xdg_surface*)data; return;
if (XDGSURFACE->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) const auto PMONITOR = g_pCompositor->getMonitorFromOutput(subSurface->pParentSurface->layerSurface->output);
return; // TODO: handle?
g_pCompositor->m_lWindows.push_back(CWindow()); if (!PMONITOR)
const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back(); return; // wut?
PNEWWINDOW->m_uSurface.xdg = XDGSURFACE;
wl_signal_add(&XDGSURFACE->surface->events.commit, &PNEWWINDOW->listen_commitWindow); int x = subSurface->subsurface->current.x + subSurface->pParentSurface->geometry.x;
wl_signal_add(&XDGSURFACE->events.map, &PNEWWINDOW->listen_mapWindow); int y = subSurface->subsurface->current.y + subSurface->pParentSurface->geometry.y;
wl_signal_add(&XDGSURFACE->events.unmap, &PNEWWINDOW->listen_unmapWindow);
wl_signal_add(&XDGSURFACE->events.destroy, &PNEWWINDOW->listen_destroyWindow);
wl_signal_add(&XDGSURFACE->toplevel->events.set_title, &PNEWWINDOW->listen_setTitleWindow);
wl_signal_add(&XDGSURFACE->toplevel->events.request_fullscreen, &PNEWWINDOW->listen_fullscreenWindow);
Debug::log(LOG, "New XDG Surface created."); g_pHyprRenderer->damageSurface(PMONITOR, x, y, subSurface->subsurface->surface, &all);
}
void Events::listener_newSubsurface(wl_listener* listener, void* data) {
SLayerSurface* layersurface = wl_container_of(listener, layersurface, listen_newSubsurface);
createSubsurface((wlr_subsurface*)data, layersurface);
}
void Events::listener_mapSubsurface(wl_listener* listener, void* data) {
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_mapSubsurface);
damageSubsurface(subsurface, true);
}
void Events::listener_unmapSubsurface(wl_listener* listener, void* data) {
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_unmapSubsurface);
damageSubsurface(subsurface, true);
}
void Events::listener_commitSubsurface(wl_listener* listener, void* data) {
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_commitSubsurface);
damageSubsurface(subsurface, false);
}
void Events::listener_destroySubsurface(wl_listener* listener, void* data) {
SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_destroySubsurface);
wl_list_remove(&subsurface->listen_mapSubsurface.link);
wl_list_remove(&subsurface->listen_unmapSubsurface.link);
wl_list_remove(&subsurface->listen_destroySubsurface.link);
wl_list_remove(&subsurface->listen_commitSubsurface.link);
g_pCompositor->m_lSubsurfaces.remove(*subsurface);
} }

View File

@ -103,3 +103,72 @@ void Events::listener_configureX11(wl_listener* listener, void* data) {
// TODO: ignore if tiled? // TODO: ignore if tiled?
wlr_xwayland_surface_configure(PWINDOW->m_uSurface.xwayland, E->x, E->y, E->width, E->height); wlr_xwayland_surface_configure(PWINDOW->m_uSurface.xwayland, E->x, E->y, E->width, E->height);
} }
void Events::listener_surfaceXWayland(wl_listener* listener, void* data) {
const auto XWSURFACE = (wlr_xwayland_surface*)data;
g_pCompositor->m_lWindows.push_back(CWindow());
const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back();
PNEWWINDOW->m_uSurface.xwayland = XWSURFACE;
PNEWWINDOW->m_iX11Type = XWSURFACE->override_redirect ? 2 : 1;
PNEWWINDOW->m_bIsX11 = true;
wl_signal_add(&XWSURFACE->events.map, &PNEWWINDOW->listen_mapWindow);
wl_signal_add(&XWSURFACE->events.unmap, &PNEWWINDOW->listen_unmapWindow);
wl_signal_add(&XWSURFACE->events.request_activate, &PNEWWINDOW->listen_activateX11);
wl_signal_add(&XWSURFACE->events.request_configure, &PNEWWINDOW->listen_configureX11);
wl_signal_add(&XWSURFACE->events.set_title, &PNEWWINDOW->listen_setTitleWindow);
wl_signal_add(&XWSURFACE->events.destroy, &PNEWWINDOW->listen_destroyWindow);
wl_signal_add(&XWSURFACE->events.request_fullscreen, &PNEWWINDOW->listen_fullscreenWindow);
wl_signal_add(&XWSURFACE->surface->events.new_subsurface, &PNEWWINDOW->listen_newSubsurfaceWindow);
Debug::log(LOG, "New XWayland Surface created.");
}
void Events::listener_newXDGSurface(wl_listener* listener, void* data) {
// A window got opened
const auto XDGSURFACE = (wlr_xdg_surface*)data;
if (XDGSURFACE->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL)
return; // TODO: handle?
g_pCompositor->m_lWindows.push_back(CWindow());
const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back();
PNEWWINDOW->m_uSurface.xdg = XDGSURFACE;
wl_signal_add(&XDGSURFACE->surface->events.commit, &PNEWWINDOW->listen_commitWindow);
wl_signal_add(&XDGSURFACE->events.map, &PNEWWINDOW->listen_mapWindow);
wl_signal_add(&XDGSURFACE->events.unmap, &PNEWWINDOW->listen_unmapWindow);
wl_signal_add(&XDGSURFACE->events.destroy, &PNEWWINDOW->listen_destroyWindow);
wl_signal_add(&XDGSURFACE->toplevel->events.set_title, &PNEWWINDOW->listen_setTitleWindow);
wl_signal_add(&XDGSURFACE->toplevel->events.request_fullscreen, &PNEWWINDOW->listen_fullscreenWindow);
wl_signal_add(&XDGSURFACE->surface->events.new_subsurface, &PNEWWINDOW->listen_newSubsurfaceWindow);
Debug::log(LOG, "New XDG Surface created.");
}
//
// Subsurfaces
//
void createSubsurface(CWindow* pWindow, wlr_subsurface* pSubsurface) {
if (!pWindow || !pSubsurface)
return;
g_pCompositor->m_lSubsurfaces.push_back(SSubsurface());
const auto PNEWSUBSURFACE = &g_pCompositor->m_lSubsurfaces.back();
wl_signal_add(&pSubsurface->events.destroy, &PNEWSUBSURFACE->listen_destroySubsurface);
wl_signal_add(&pSubsurface->events.map, &PNEWSUBSURFACE->listen_mapSubsurface);
wl_signal_add(&pSubsurface->events.unmap, &PNEWSUBSURFACE->listen_unmapSubsurface);
wl_signal_add(&pSubsurface->surface->events.commit, &PNEWSUBSURFACE->listen_commitSubsurface);
}
void Events::listener_newSubsurfaceWindow(wl_listener* listener, void* data) {
CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_newSubsurfaceWindow);
const auto PSUBSURFACE = (wlr_subsurface*)data;
createSubsurface(PWINDOW, PSUBSURFACE);
}

View File

@ -23,6 +23,7 @@ struct SMonitor {
// WLR stuff // WLR stuff
wlr_output* output = nullptr; wlr_output* output = nullptr;
float refreshRate = 60; float refreshRate = 60;
wlr_output_damage* damage = nullptr;
// Double-linked list because we need to have constant mem addresses for signals // Double-linked list because we need to have constant mem addresses for signals
// We have to store pointers and use raw new/delete because they might be moved between them // We have to store pointers and use raw new/delete because they might be moved between them

View File

@ -14,6 +14,7 @@ struct SLayerSurface {
DYNLISTENER(unmapLayerSurface); DYNLISTENER(unmapLayerSurface);
DYNLISTENER(commitLayerSurface); DYNLISTENER(commitLayerSurface);
DYNLISTENER(newPopup); DYNLISTENER(newPopup);
DYNLISTENER(newSubsurface);
wlr_box geometry; wlr_box geometry;
zwlr_layer_shell_v1_layer layer; zwlr_layer_shell_v1_layer layer;
@ -27,11 +28,31 @@ struct SLayerSurface {
} }
}; };
struct SSubsurface {
wlr_subsurface* subsurface = nullptr;
SLayerSurface* pParentSurface = nullptr;
DYNLISTENER(mapSubsurface);
DYNLISTENER(unmapSubsurface);
DYNLISTENER(destroySubsurface);
DYNLISTENER(commitSubsurface);
DYNLISTENER(newSubsurface);
// For the list lookup
bool operator==(const SSubsurface& rhs) {
return subsurface == rhs.subsurface && pParentSurface == rhs.pParentSurface;
}
};
struct SRenderData { struct SRenderData {
wlr_output* output; wlr_output* output;
timespec* when; timespec* when;
int x; int x, y;
int y;
// for iters
void* data = nullptr;
wlr_surface* surface = nullptr;
int w, h;
}; };
struct SKeyboard { struct SKeyboard {

View File

@ -66,8 +66,10 @@ extern "C" {
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_subcompositor.h> #include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_scene.h> #include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/xwayland.h> #include <wlr/xwayland.h>
#include <wlr/util/region.h>
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
} }

View File

@ -264,3 +264,50 @@ void CHyprRenderer::drawBorderForWindow(CWindow* pWindow, SMonitor* pMonitor) {
border.x = correctPos.x + pWindow->m_vRealSize.x; border.x = correctPos.x + pWindow->m_vRealSize.x;
wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix);
} }
void damageSurfaceIter(struct wlr_surface* surface, int x, int y, void* data) {
auto* renderdata = (SRenderData*)data;
bool entire = (bool*)renderdata->data;
wlr_box box = {.x = renderdata->x, .y = renderdata->y, .width = renderdata->w, .height = renderdata->h};
scaleBox(&box, renderdata->output->scale);
pixman_region32_t damageRegion;
pixman_region32_init(&damageRegion);
wlr_surface_get_effective_damage(renderdata->surface, &damageRegion);
wlr_region_scale(&damageRegion, &damageRegion, renderdata->output->scale);
if (std::ceil(renderdata->output->scale) > renderdata->surface->current.scale) {
wlr_region_expand(&damageRegion, &damageRegion, std::ceil(renderdata->output->scale) - renderdata->surface->current.scale);
}
const auto PMONITOR = g_pCompositor->getMonitorFromOutput(renderdata->output);
pixman_region32_translate(&damageRegion, box.x, box.y);
wlr_output_damage_add(PMONITOR->damage, &damageRegion);
pixman_region32_fini(&damageRegion);
if (entire)
wlr_output_damage_add_box(PMONITOR->damage, &box);
if (!wl_list_empty(&surface->current.frame_callback_list)) {
wlr_output_schedule_frame(renderdata->output);
}
}
void CHyprRenderer::damageSurface(SMonitor* pMonitor, double x, double y, wlr_surface* pSurface, void* data) {
if (!pSurface || !pMonitor)
return; // wut?
SRenderData renderData = {
.output = pMonitor->output,
.x = x,
.y = y,
.data = data,
.surface = pSurface,
.w = pSurface->current.width,
.h = pSurface->current.height
};
wlr_surface_for_each_surface(pSurface, damageSurfaceIter, &renderData);
}

View File

@ -11,6 +11,7 @@ public:
void renderAllClientsForMonitor(const int&, timespec*); void renderAllClientsForMonitor(const int&, timespec*);
void outputMgrApplyTest(wlr_output_configuration_v1*, bool); void outputMgrApplyTest(wlr_output_configuration_v1*, bool);
void arrangeLayersForMonitor(const int&); void arrangeLayersForMonitor(const int&);
void damageSurface(SMonitor*, double, double, wlr_surface*, void*);
private: private:
void arrangeLayerArray(SMonitor*, const std::list<SLayerSurface*>&); void arrangeLayerArray(SMonitor*, const std::list<SLayerSurface*>&);