Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
xwayland: add force_zero_scaling
  • Loading branch information
vaxerski committed Jun 11, 2023
1 parent 64ce06a commit 6beb79f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Window.hpp
Expand Up @@ -217,6 +217,7 @@ class CWindow {
bool m_bIsModal = false;
bool m_bX11DoesntWantBorders = false;
bool m_bX11ShouldntFocus = false;
float m_fX11SurfaceScaledBy = 1.f;
//

// For nofocus
Expand Down
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Expand Up @@ -207,6 +207,7 @@ void CConfigManager::setDefaultVars() {
configValues["gestures:workspace_swipe_numbered"].intValue = 0;

configValues["xwayland:use_nearest_neighbor"].intValue = 1;
configValues["xwayland:force_zero_scaling"].intValue = 0;

configValues["autogenerated"].intValue = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/events/Windows.cpp
Expand Up @@ -739,7 +739,8 @@ void Events::listener_commitWindow(void* owner, void* data) {

PWINDOW->updateSurfaceOutputs();

g_pHyprRenderer->damageSurface(PWINDOW->m_pWLSurface.wlr(), PWINDOW->m_vRealPosition.goalv().x, PWINDOW->m_vRealPosition.goalv().y);
g_pHyprRenderer->damageSurface(PWINDOW->m_pWLSurface.wlr(), PWINDOW->m_vRealPosition.goalv().x, PWINDOW->m_vRealPosition.goalv().y,
PWINDOW->m_bIsX11 ? 1.0 / PWINDOW->m_fX11SurfaceScaledBy : 1.0);

if (PWINDOW->m_bIsX11 || !PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen)
return;
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/SubsurfaceTree.cpp
Expand Up @@ -229,6 +229,8 @@ void Events::listener_commitSubsurface(void* owner, void* data) {

addSurfaceGlobalOffset(pNode, &lx, &ly);

const double SCALE = pNode->pWindowOwner && pNode->pWindowOwner->m_bIsX11 ? 1.0 / pNode->pWindowOwner->m_fX11SurfaceScaledBy : 1.0;

// I do not think this is correct, but it solves a lot of issues with some apps (e.g. firefox)
// What this does is that basically, if the pNode is a child of some other node, on commit,
// it will also damage (check & damage if needed) all its siblings.
Expand All @@ -237,12 +239,12 @@ void Events::listener_commitSubsurface(void* owner, void* data) {
const auto NODECOORDS = pNode->pSubsurface ? Vector2D(pNode->pSubsurface->pSubsurface->current.x, pNode->pSubsurface->pSubsurface->current.y) : Vector2D();

if (&cs != pNode->pSubsurface && cs.pSubsurface) {
g_pHyprRenderer->damageSurface(cs.pSubsurface->surface, lx - NODECOORDS.x + cs.pSubsurface->current.x, ly - NODECOORDS.y + cs.pSubsurface->current.y);
g_pHyprRenderer->damageSurface(cs.pSubsurface->surface, lx - NODECOORDS.x + cs.pSubsurface->current.x, ly - NODECOORDS.y + cs.pSubsurface->current.y, SCALE);
}
}

if (pNode->pSurface && pNode->pSurface->exists())
g_pHyprRenderer->damageSurface(pNode->pSurface->wlr(), lx, ly);
g_pHyprRenderer->damageSurface(pNode->pSurface->wlr(), lx, ly, SCALE);
}

void Events::listener_destroySubsurface(void* owner, void* data) {
Expand Down
11 changes: 11 additions & 0 deletions src/managers/XWaylandManager.cpp
Expand Up @@ -148,6 +148,17 @@ void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, Vector2D size, bool f
pWindow->m_vReportedPosition = pWindow->m_vRealPosition.vec();
pWindow->m_vReportedSize = size;

static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue;

pWindow->m_fX11SurfaceScaledBy = 1.f;

if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11) {
if (const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); PMONITOR) {
size = size * PMONITOR->scale;
pWindow->m_fX11SurfaceScaledBy = PMONITOR->scale;
}
}

if (pWindow->m_bIsX11)
wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pWindow->m_vRealPosition.vec().x, pWindow->m_vRealPosition.vec().y, size.x, size.y);
else
Expand Down
3 changes: 3 additions & 0 deletions src/managers/input/InputManager.cpp
Expand Up @@ -330,6 +330,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
surfaceLocal = mouseCoords - surfacePos + Vector2D(geom.x, geom.y);
}

if (pFoundWindow && pFoundWindow->m_bIsX11) // for x11 force scale zero
surfaceLocal = surfaceLocal * pFoundWindow->m_fX11SurfaceScaledBy;

bool allowKeyboardRefocus = true;

if (*PHOGFOCUS && !refocus && g_pCompositor->m_pLastFocus) {
Expand Down
4 changes: 3 additions & 1 deletion src/render/Renderer.cpp
Expand Up @@ -1355,7 +1355,7 @@ void CHyprRenderer::arrangeLayersForMonitor(const int& monitor) {
PMONITOR->vecReservedBottomRight.x, PMONITOR->vecReservedBottomRight.y);
}

void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y) {
void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y, double scale) {
if (!pSurface)
return; // wut?

Expand All @@ -1365,6 +1365,8 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y) {
pixman_region32_t damageBox;
pixman_region32_init(&damageBox);
wlr_surface_get_effective_damage(pSurface, &damageBox);
if (scale != 1.0)
wlr_region_scale(&damageBox, &damageBox, scale);

// schedule frame events
if (!wl_list_empty(&pSurface->current.frame_callback_list)) {
Expand Down
8 changes: 3 additions & 5 deletions src/render/Renderer.hpp
Expand Up @@ -11,16 +11,14 @@
struct SMonitorRule;

// TODO: add fuller damage tracking for updating only parts of a window
enum DAMAGETRACKINGMODES
{
enum DAMAGETRACKINGMODES {
DAMAGE_TRACKING_INVALID = -1,
DAMAGE_TRACKING_NONE = 0,
DAMAGE_TRACKING_MONITOR,
DAMAGE_TRACKING_FULL
};

enum eRenderPassMode
{
enum eRenderPassMode {
RENDER_PASS_ALL = 0,
RENDER_PASS_MAIN,
RENDER_PASS_POPUP
Expand All @@ -35,7 +33,7 @@ class CHyprRenderer {
void renderMonitor(CMonitor* pMonitor);
void outputMgrApplyTest(wlr_output_configuration_v1*, bool);
void arrangeLayersForMonitor(const int&);
void damageSurface(wlr_surface*, double, double);
void damageSurface(wlr_surface*, double, double, double scale = 1.0);
void damageWindow(CWindow*);
void damageBox(wlr_box*);
void damageBox(const int& x, const int& y, const int& w, const int& h);
Expand Down

0 comments on commit 6beb79f

Please sign in to comment.