mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-02 08:05:59 +01:00
handle subsurfaces
This commit is contained in:
parent
d06423c9d1
commit
bcb02b9307
11 changed files with 215 additions and 32 deletions
|
@ -36,6 +36,7 @@ target_link_libraries(Hyprland PkgConfig::deps)
|
|||
|
||||
target_link_libraries(Hyprland
|
||||
wlroots
|
||||
pixman-1
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
)
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
std::list<SLayerPopup> m_lLayerPopups;
|
||||
std::list<SXDGPopup> m_lXDGPopups;
|
||||
std::list<SWorkspace> m_lWorkspaces;
|
||||
std::list<SSubsurface> m_lSubsurfaces;
|
||||
|
||||
void startCompositor();
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ public:
|
|||
DYNLISTENER(setTitleWindow);
|
||||
DYNLISTENER(fullscreenWindow);
|
||||
DYNLISTENER(newPopupXDG);
|
||||
DYNLISTENER(newSubsurfaceWindow);
|
||||
|
||||
union {
|
||||
wlr_xdg_surface* xdg;
|
||||
|
|
|
@ -13,6 +13,13 @@ namespace Events {
|
|||
LISTENER(unmapLayerSurface);
|
||||
LISTENER(commitLayerSurface);
|
||||
|
||||
// Subsurfaces
|
||||
LISTENER(newSubsurface);
|
||||
LISTENER(mapSubsurface);
|
||||
LISTENER(unmapSubsurface);
|
||||
LISTENER(destroySubsurface);
|
||||
LISTENER(commitSubsurface);
|
||||
|
||||
// Popups
|
||||
LISTENER(newPopup);
|
||||
LISTENER(newPopupFromPopup);
|
||||
|
@ -41,6 +48,9 @@ namespace Events {
|
|||
LISTENER(activateX11);
|
||||
LISTENER(configureX11);
|
||||
|
||||
// Window subsurfaces
|
||||
LISTENER(newSubsurfaceWindow);
|
||||
|
||||
// Input events
|
||||
LISTENER(mouseMove);
|
||||
LISTENER(mouseMoveAbsolute);
|
||||
|
|
|
@ -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.unmap, &layerSurface->listen_unmapLayerSurface);
|
||||
wl_signal_add(&WLRLAYERSURFACE->events.new_popup, &layerSurface->listen_newPopup);
|
||||
wl_signal_add(&WLRLAYERSURFACE->surface->events.new_subsurface, &layerSurface->listen_newSubsurface);
|
||||
|
||||
layerSurface->layerSurface = WLRLAYERSURFACE;
|
||||
WLRLAYERSURFACE->data = layerSurface;
|
||||
|
@ -144,44 +145,72 @@ void Events::listener_commitLayerSurface(wl_listener* listener, void* data) {
|
|||
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());
|
||||
const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back();
|
||||
void createSubsurface(wlr_subsurface* pSubSurface, SLayerSurface* pLayerSurface) {
|
||||
if (!pSubSurface || !pLayerSurface)
|
||||
return;
|
||||
|
||||
PNEWWINDOW->m_uSurface.xwayland = XWSURFACE;
|
||||
PNEWWINDOW->m_iX11Type = XWSURFACE->override_redirect ? 2 : 1;
|
||||
PNEWWINDOW->m_bIsX11 = true;
|
||||
g_pCompositor->m_lSubsurfaces.push_back(SSubsurface());
|
||||
const auto PNEWSUBSURFACE = &g_pCompositor->m_lSubsurfaces.back();
|
||||
|
||||
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);
|
||||
PNEWSUBSURFACE->subsurface = pSubSurface;
|
||||
PNEWSUBSURFACE->pParentSurface = pLayerSurface;
|
||||
|
||||
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) {
|
||||
// A window got opened
|
||||
const auto XDGSURFACE = (wlr_xdg_surface*)data;
|
||||
void damageSubsurface(SSubsurface* subSurface, bool all = false) {
|
||||
if (!subSurface->pParentSurface->layerSurface->output)
|
||||
return;
|
||||
|
||||
if (XDGSURFACE->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL)
|
||||
return; // TODO: handle?
|
||||
const auto PMONITOR = g_pCompositor->getMonitorFromOutput(subSurface->pParentSurface->layerSurface->output);
|
||||
|
||||
g_pCompositor->m_lWindows.push_back(CWindow());
|
||||
const auto PNEWWINDOW = &g_pCompositor->m_lWindows.back();
|
||||
PNEWWINDOW->m_uSurface.xdg = XDGSURFACE;
|
||||
if (!PMONITOR)
|
||||
return; // wut?
|
||||
|
||||
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);
|
||||
int x = subSurface->subsurface->current.x + subSurface->pParentSurface->geometry.x;
|
||||
int y = subSurface->subsurface->current.y + subSurface->pParentSurface->geometry.y;
|
||||
|
||||
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);
|
||||
}
|
|
@ -102,4 +102,73 @@ void Events::listener_configureX11(wl_listener* listener, void* data) {
|
|||
|
||||
// TODO: ignore if tiled?
|
||||
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);
|
||||
}
|
|
@ -23,6 +23,7 @@ struct SMonitor {
|
|||
// WLR stuff
|
||||
wlr_output* output = nullptr;
|
||||
float refreshRate = 60;
|
||||
wlr_output_damage* damage = nullptr;
|
||||
|
||||
// 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
|
||||
|
|
|
@ -14,6 +14,7 @@ struct SLayerSurface {
|
|||
DYNLISTENER(unmapLayerSurface);
|
||||
DYNLISTENER(commitLayerSurface);
|
||||
DYNLISTENER(newPopup);
|
||||
DYNLISTENER(newSubsurface);
|
||||
|
||||
wlr_box geometry;
|
||||
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 {
|
||||
wlr_output* output;
|
||||
timespec* when;
|
||||
int x;
|
||||
int y;
|
||||
int x, y;
|
||||
|
||||
// for iters
|
||||
void* data = nullptr;
|
||||
wlr_surface* surface = nullptr;
|
||||
int w, h;
|
||||
};
|
||||
|
||||
struct SKeyboard {
|
||||
|
|
|
@ -66,8 +66,10 @@ extern "C" {
|
|||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/types/wlr_subcompositor.h>
|
||||
#include <wlr/types/wlr_scene.h>
|
||||
#include <wlr/types/wlr_output_damage.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/xwayland.h>
|
||||
#include <wlr/util/region.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <X11/Xproto.h>
|
||||
}
|
||||
|
|
|
@ -263,4 +263,51 @@ void CHyprRenderer::drawBorderForWindow(CWindow* pWindow, SMonitor* pMonitor) {
|
|||
// right
|
||||
border.x = correctPos.x + pWindow->m_vRealSize.x;
|
||||
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);
|
||||
}
|
|
@ -11,6 +11,7 @@ public:
|
|||
void renderAllClientsForMonitor(const int&, timespec*);
|
||||
void outputMgrApplyTest(wlr_output_configuration_v1*, bool);
|
||||
void arrangeLayersForMonitor(const int&);
|
||||
void damageSurface(SMonitor*, double, double, wlr_surface*, void*);
|
||||
|
||||
private:
|
||||
void arrangeLayerArray(SMonitor*, const std::list<SLayerSurface*>&);
|
||||
|
|
Loading…
Reference in a new issue