Skip to content

Commit

Permalink
wayland_backend: Fix cursor position with display scaling
Browse files Browse the repository at this point in the history
Co-authored-by: Byte Northbridge <[email protected]>
  • Loading branch information
misyltoad and BrknRobot committed Jun 3, 2024
1 parent 2ada4a4 commit 7f3f82b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/wayland_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ namespace gamescope
int32_t nDstHeight;
GamescopeAppTextureColorspace eColorspace;
bool bOpaque;
uint32_t uFractionalScale;
};

inline WaylandPlaneState ClipPlane( const WaylandPlaneState &state )
Expand Down Expand Up @@ -908,7 +909,7 @@ namespace gamescope
}

// Fraction with denominator of 120 per. spec
const uint32_t uScale = GetScale();
const uint32_t uScale = oState->uFractionalScale;

wp_viewport_set_source(
m_pViewport,
Expand Down Expand Up @@ -982,6 +983,7 @@ namespace gamescope
.nDstHeight = int32_t( pLayer->tex->height() / double( pLayer->scale.y ) ),
.eColorspace = pLayer->colorspace,
.bOpaque = pLayer->zpos == g_zposBase,
.uFractionalScale = m_uFractionalScale,
} ) );
}
else
Expand Down Expand Up @@ -1346,7 +1348,8 @@ namespace gamescope
{
m_BlackFb->OnCompositorAcquire();

m_Planes[uCurrentPlane++].Present(
CWaylandPlane *pPlane = &m_Planes[uCurrentPlane++];
pPlane->Present(
WaylandPlaneState
{
.pBuffer = m_BlackFb->GetHostBuffer(),
Expand All @@ -1356,6 +1359,7 @@ namespace gamescope
.nDstHeight = int32_t( g_nOutputHeight ),
.eColorspace = GAMESCOPE_APP_TEXTURE_COLORSPACE_PASSTHRU,
.bOpaque = true,
.uFractionalScale = pPlane->GetScale(),
} );
}

Expand Down Expand Up @@ -2265,8 +2269,10 @@ namespace gamescope
if ( !oState )
return;

double flX = ( wl_fixed_to_double( fSurfaceX ) + oState->nDestX ) / g_nOutputWidth;
double flY = ( wl_fixed_to_double( fSurfaceY ) + oState->nDestY ) / g_nOutputHeight;
uint32_t uScale = oState->uFractionalScale;

double flX = ( wl_fixed_to_double( fSurfaceX ) * uScale / 120.0 + oState->nDestX ) / g_nOutputWidth;
double flY = ( wl_fixed_to_double( fSurfaceY ) * uScale / 120.0 + oState->nDestY ) / g_nOutputHeight;

wlserver_lock();
wlserver_touchmotion( flX, flY, 0, ++m_uFakeTimestamp );
Expand Down

0 comments on commit 7f3f82b

Please sign in to comment.