Skip to content

Commit 24915a3

Browse files
authored
windowrules: Add noscreenshare (#10482)
1 parent 90d0b8e commit 24915a3

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

src/desktop/Window.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct SWindowData {
104104
CWindowOverridableVar<bool> xray = false;
105105
CWindowOverridableVar<bool> renderUnfocused = false;
106106
CWindowOverridableVar<bool> noFollowMouse = false;
107+
CWindowOverridableVar<bool> noScreenShare = false;
107108

108109
CWindowOverridableVar<Hyprlang::INT> borderSize = {std::string("general:border_size"), Hyprlang::INT(0), std::nullopt};
109110
CWindowOverridableVar<Hyprlang::INT> rounding = {std::string("decoration:rounding"), Hyprlang::INT(0), std::nullopt};
@@ -489,6 +490,7 @@ namespace NWindowProperties {
489490
{"immediate", [](const PHLWINDOW& pWindow) { return &pWindow->m_windowData.tearing; }},
490491
{"xray", [](const PHLWINDOW& pWindow) { return &pWindow->m_windowData.xray; }},
491492
{"nofollowmouse", [](const PHLWINDOW& pWindow) { return &pWindow->m_windowData.noFollowMouse; }},
493+
{"noscreenshare", [](const PHLWINDOW& pWindow) { return &pWindow->m_windowData.noScreenShare; }},
492494
};
493495

494496
const std::unordered_map<std::string, std::function<CWindowOverridableVar<Hyprlang::INT>*(const PHLWINDOW&)>> intWindowProperties = {

src/protocols/Screencopy.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "types/Buffer.hpp"
1414
#include "../helpers/Format.hpp"
1515
#include "../helpers/time/Time.hpp"
16+
#include "XDGShell.hpp"
1617

1718
#include <algorithm>
1819
#include <functional>
@@ -200,6 +201,59 @@ void CScreencopyFrame::renderMon() {
200201
g_pHyprOpenGL->renderTexture(TEXTURE, monbox, 1);
201202
g_pHyprOpenGL->setRenderModifEnabled(true);
202203
g_pHyprOpenGL->setMonitorTransformEnabled(false);
204+
205+
for (auto const& w : g_pCompositor->m_windows) {
206+
if (!w->m_windowData.noScreenShare.valueOrDefault())
207+
continue;
208+
209+
if (!g_pHyprRenderer->shouldRenderWindow(w))
210+
continue;
211+
212+
const auto PWORKSPACE = w->m_workspace;
213+
214+
if UNLIKELY (!PWORKSPACE)
215+
continue;
216+
217+
const auto REALPOS = w->m_realPosition->value() + (w->m_pinned ? Vector2D{} : PWORKSPACE->m_renderOffset->value());
218+
const auto noScreenShareBox = CBox{REALPOS.x, REALPOS.y, std::max(w->m_realSize->value().x, 5.0), std::max(w->m_realSize->value().y, 5.0)}
219+
.scale(m_monitor->m_scale)
220+
.translate({-m_monitor->m_position.x, -m_monitor->m_position.y})
221+
.translate({-m_box.x, -m_box.y});
222+
223+
const auto dontRound = w->isEffectiveInternalFSMode(FSMODE_FULLSCREEN) || w->m_windowData.noRounding.valueOrDefault();
224+
const auto rounding = dontRound ? 0 : w->rounding() * m_monitor->m_scale;
225+
const auto roundingPower = dontRound ? 2.0f : w->roundingPower();
226+
227+
g_pHyprOpenGL->renderRect(noScreenShareBox, {0, 0, 0, 255}, rounding, roundingPower);
228+
229+
if (w->m_isX11 || !w->m_popupHead)
230+
continue;
231+
232+
const auto geom = w->m_xdgSurface->m_current.geometry;
233+
const Vector2D popupBaseOffset = REALPOS - Vector2D{geom.pos().x, geom.pos().y};
234+
235+
w->m_popupHead->breadthfirst(
236+
[&](WP<CPopup> popup, void*) {
237+
if (!popup->m_wlSurface || !popup->m_wlSurface->resource() || !popup->m_mapped)
238+
return;
239+
240+
const auto popRel = popup->coordsRelativeToParent();
241+
popup->m_wlSurface->resource()->breadthfirst(
242+
[&](SP<CWLSurfaceResource> surf, const Vector2D& localOff, void*) {
243+
const auto size = surf->m_current.size;
244+
const auto surfBox = CBox{popupBaseOffset.x + popRel.x + localOff.x, popupBaseOffset.y + popRel.y + localOff.y, size.x, size.y}
245+
.scale(m_monitor->m_scale)
246+
.translate({-m_monitor->m_position.x, -m_monitor->m_position.y})
247+
.translate({-m_box.x, -m_box.y});
248+
249+
if LIKELY (surfBox.w > 0 && surfBox.h > 0)
250+
g_pHyprOpenGL->renderRect(surfBox, {0, 0, 0, 255});
251+
},
252+
nullptr);
253+
},
254+
nullptr);
255+
}
256+
203257
if (m_overlayCursor)
204258
g_pPointerManager->renderSoftwareCursorsFor(m_monitor.lock(), Time::steadyNow(), fakeDamage,
205259
g_pInputManager->getMouseCoordsInternal() - m_monitor->m_position - m_box.pos(), true);

src/protocols/ToplevelExport.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ bool CToplevelExportFrame::copyShm(const Time::steady_tp& now) {
257257

258258
// render client at 0,0
259259
if (PERM == PERMISSION_RULE_ALLOW_MODE_ALLOW) {
260-
g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(m_window); // block the feedback to avoid spamming the surface if it's visible
261-
g_pHyprRenderer->renderWindow(m_window, PMONITOR, now, false, RENDER_PASS_ALL, true, true);
262-
g_pHyprRenderer->m_bBlockSurfaceFeedback = false;
263-
260+
if (!m_window->m_windowData.noScreenShare.valueOrDefault()) {
261+
g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(m_window); // block the feedback to avoid spamming the surface if it's visible
262+
g_pHyprRenderer->renderWindow(m_window, PMONITOR, now, false, RENDER_PASS_ALL, true, true);
263+
g_pHyprRenderer->m_bBlockSurfaceFeedback = false;
264+
}
264265
if (overlayCursor)
265266
g_pPointerManager->renderSoftwareCursorsFor(PMONITOR->m_self.lock(), now, fakeDamage, g_pInputManager->getMouseCoordsInternal() - m_window->m_realPosition->value());
266267
} else if (PERM == PERMISSION_RULE_ALLOW_MODE_DENY) {
@@ -338,9 +339,11 @@ bool CToplevelExportFrame::copyDmabuf(const Time::steady_tp& now) {
338339

339340
g_pHyprOpenGL->clear(CHyprColor(0, 0, 0, 1.0));
340341
if (PERM == PERMISSION_RULE_ALLOW_MODE_ALLOW) {
341-
g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(m_window); // block the feedback to avoid spamming the surface if it's visible
342-
g_pHyprRenderer->renderWindow(m_window, PMONITOR, now, false, RENDER_PASS_ALL, true, true);
343-
g_pHyprRenderer->m_bBlockSurfaceFeedback = false;
342+
if (!m_window->m_windowData.noScreenShare.valueOrDefault()) {
343+
g_pHyprRenderer->m_bBlockSurfaceFeedback = g_pHyprRenderer->shouldRenderWindow(m_window); // block the feedback to avoid spamming the surface if it's visible
344+
g_pHyprRenderer->renderWindow(m_window, PMONITOR, now, false, RENDER_PASS_ALL, true, true);
345+
g_pHyprRenderer->m_bBlockSurfaceFeedback = false;
346+
}
344347

345348
if (overlayCursor)
346349
g_pPointerManager->renderSoftwareCursorsFor(PMONITOR->m_self.lock(), now, fakeDamage, g_pInputManager->getMouseCoordsInternal() - m_window->m_realPosition->value());

0 commit comments

Comments
 (0)