mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-11 12:05:57 +01:00
58 lines
2.2 KiB
C++
58 lines
2.2 KiB
C++
|
#include "Renderer.hpp"
|
||
|
#include "../Compositor.hpp"
|
||
|
|
||
|
void scaleBox(wlr_box* box, float scale) {
|
||
|
box->width = std::round((box->x + box->width) * scale) - std::round(box->x * scale);
|
||
|
box->height = std::round((box->y + box->height) * scale) - std::round(box->y * scale);
|
||
|
box->x = std::round(box->x * scale);
|
||
|
box->y = std::round(box->y * scale);
|
||
|
}
|
||
|
|
||
|
void renderSurface(struct wlr_surface* surface, int x, int y, void* data) {
|
||
|
const auto TEXTURE = wlr_surface_get_texture(surface);
|
||
|
const auto RDATA = (SRenderData*)data;
|
||
|
|
||
|
if (!TEXTURE)
|
||
|
return;
|
||
|
|
||
|
double outputX = 0, outputY = 0;
|
||
|
wlr_output_layout_output_coords(g_pCompositor->m_sWLROutputLayout, RDATA->output, &outputX, &outputY);
|
||
|
|
||
|
wlr_box windowBox = {outputX + RDATA->x + x, outputY + RDATA->y + y, surface->current.width, surface->current.height};
|
||
|
scaleBox(&windowBox, RDATA->output->scale);
|
||
|
|
||
|
const auto TRANSFORM = wlr_output_transform_invert(surface->current.transform);
|
||
|
float matrix[9];
|
||
|
wlr_matrix_project_box(matrix, &windowBox, TRANSFORM, 0, RDATA->output->transform_matrix);
|
||
|
|
||
|
wlr_render_texture_with_matrix(g_pCompositor->m_sWLRRenderer, TEXTURE, matrix, 1); // TODO: fadein/out
|
||
|
|
||
|
wlr_surface_send_frame_done(surface, RDATA->when);
|
||
|
|
||
|
wlr_presentation_surface_sampled_on_output(g_pCompositor->m_sWLRPresentation, surface, RDATA->output);
|
||
|
}
|
||
|
|
||
|
void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) {
|
||
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(ID);
|
||
|
|
||
|
if (!PMONITOR)
|
||
|
return;
|
||
|
|
||
|
for (auto& w : g_pCompositor->m_vWindows) {
|
||
|
|
||
|
const wlr_box geom = { w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y };
|
||
|
|
||
|
if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, PMONITOR->output, &geom))
|
||
|
continue;
|
||
|
|
||
|
// render the bad boy
|
||
|
|
||
|
wlr_output_layout_output_coords(g_pCompositor->m_sWLROutputLayout, PMONITOR->output, &w.m_vPosition.x, &w.m_vPosition.y);
|
||
|
|
||
|
SRenderData renderdata = {PMONITOR->output, time, w.m_vSize.x, w.m_vSize.y};
|
||
|
|
||
|
wlr_surface_for_each_surface(w.m_uSurface.xdg->surface, renderSurface, &renderdata);
|
||
|
wlr_xdg_surface_for_each_popup_surface(w.m_uSurface.xdg, renderSurface, &renderdata);
|
||
|
}
|
||
|
}
|