2023-02-27 15:02:21 +01:00
# define WLR_USE_UNSTABLE
# include <unistd.h>
2023-04-27 00:44:12 +02:00
# include <hyprland/src/Compositor.hpp>
2024-03-20 04:02:10 +01:00
# include <hyprland/src/desktop/Window.hpp>
2023-04-27 00:44:12 +02:00
# include <hyprland/src/config/ConfigManager.hpp>
2024-05-30 19:09:23 +02:00
# include <hyprland/src/xwayland/XSurface.hpp>
2024-05-31 18:08:07 +02:00
# include <hyprland/src/managers/SeatManager.hpp>
2023-02-27 15:02:21 +01:00
# include "globals.hpp"
// Methods
2024-03-02 18:10:59 +01:00
inline CFunctionHook * g_pMouseMotionHook = nullptr ;
inline CFunctionHook * g_pSurfaceSizeHook = nullptr ;
inline CFunctionHook * g_pWLSurfaceDamageHook = nullptr ;
2024-05-31 18:08:07 +02:00
typedef void ( * origMotion ) ( CSeatManager * , uint32_t , const Vector2D & ) ;
2024-05-30 19:09:23 +02:00
typedef void ( * origSurfaceSize ) ( CXWaylandSurface * , const CBox & ) ;
2024-03-02 18:10:59 +01:00
typedef CRegion ( * origWLSurfaceDamage ) ( CWLSurface * ) ;
2023-02-27 15:02:21 +01:00
// Do NOT change this function.
2023-09-03 16:40:39 +02:00
APICALL EXPORT std : : string PLUGIN_API_VERSION ( ) {
return HYPRLAND_API_VERSION ;
}
2023-02-27 15:02:21 +01:00
2024-05-31 18:08:07 +02:00
void hkNotifyMotion ( CSeatManager * thisptr , uint32_t time_msec , const Vector2D & local ) {
2024-02-18 16:30:21 +01:00
static auto * const RESX = ( Hyprlang : : INT * const * ) HyprlandAPI : : getConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:res_w " ) - > getDataStaticPtr ( ) ;
static auto * const RESY = ( Hyprlang : : INT * const * ) HyprlandAPI : : getConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:res_h " ) - > getDataStaticPtr ( ) ;
static auto * const PCLASS = ( Hyprlang : : STRING const * ) HyprlandAPI : : getConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:class " ) - > getDataStaticPtr ( ) ;
2024-08-03 23:03:24 +02:00
static auto * const PFIX = ( Hyprlang : : INT * const * ) HyprlandAPI : : getConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:fix_mouse " ) - > getDataStaticPtr ( ) ;
2023-09-28 23:21:37 +02:00
2024-05-31 18:08:07 +02:00
Vector2D newCoords = local ;
2024-08-03 23:03:24 +02:00
if ( * * PFIX & & ! g_pCompositor - > m_pLastWindow . expired ( ) & & g_pCompositor - > m_pLastWindow - > m_szInitialClass = = * PCLASS & & g_pCompositor - > m_pLastMonitor ) {
2023-09-28 23:21:37 +02:00
// fix the coords
2024-08-03 23:03:24 +02:00
newCoords . x * = ( * * RESX / g_pCompositor - > m_pLastMonitor - > vecSize . x ) / g_pCompositor - > m_pLastWindow - > m_fX11SurfaceScaledBy ;
newCoords . y * = ( * * RESY / g_pCompositor - > m_pLastMonitor - > vecSize . y ) / g_pCompositor - > m_pLastWindow - > m_fX11SurfaceScaledBy ;
2023-09-28 23:21:37 +02:00
}
2024-05-31 18:08:07 +02:00
( * ( origMotion ) g_pMouseMotionHook - > m_pOriginal ) ( thisptr , time_msec , newCoords ) ;
2023-09-28 23:21:37 +02:00
}
2024-05-30 19:09:23 +02:00
void hkSetWindowSize ( CXWaylandSurface * surface , const CBox & box ) {
2024-02-18 16:30:21 +01:00
static auto * const RESX = ( Hyprlang : : INT * const * ) HyprlandAPI : : getConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:res_w " ) - > getDataStaticPtr ( ) ;
static auto * const RESY = ( Hyprlang : : INT * const * ) HyprlandAPI : : getConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:res_h " ) - > getDataStaticPtr ( ) ;
static auto * const PCLASS = ( Hyprlang : : STRING const * ) HyprlandAPI : : getConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:class " ) - > getDataStaticPtr ( ) ;
2023-02-27 15:02:21 +01:00
2023-09-03 16:40:39 +02:00
if ( ! surface ) {
2024-05-30 19:09:23 +02:00
( * ( origSurfaceSize ) g_pSurfaceSizeHook - > m_pOriginal ) ( surface , box ) ;
2023-09-03 16:40:39 +02:00
return ;
}
2024-06-08 11:12:34 +02:00
const auto SURF = surface - > surface . lock ( ) ;
2023-09-03 16:40:39 +02:00
const auto PWINDOW = g_pCompositor - > getWindowFromSurface ( SURF ) ;
2024-05-30 19:09:23 +02:00
CBox newBox = box ;
2023-10-31 18:45:55 +01:00
if ( PWINDOW & & PWINDOW - > m_szInitialClass = = * PCLASS ) {
2024-05-30 19:09:23 +02:00
newBox . w = * * RESX ;
newBox . h = * * RESY ;
2023-10-20 21:22:37 +02:00
2024-06-08 11:12:34 +02:00
CWLSurface : : fromResource ( SURF ) - > m_bFillIgnoreSmall = true ;
2023-02-27 15:02:21 +01:00
}
2024-05-30 19:09:23 +02:00
( * ( origSurfaceSize ) g_pSurfaceSizeHook - > m_pOriginal ) ( surface , newBox ) ;
2023-02-27 15:02:21 +01:00
}
2024-03-02 18:10:59 +01:00
CRegion hkWLSurfaceDamage ( CWLSurface * thisptr ) {
2024-03-02 18:15:35 +01:00
const auto RG = ( * ( origWLSurfaceDamage ) g_pWLSurfaceDamageHook - > m_pOriginal ) ( thisptr ) ;
2024-03-02 18:10:59 +01:00
static auto * const PCLASS = ( Hyprlang : : STRING const * ) HyprlandAPI : : getConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:class " ) - > getDataStaticPtr ( ) ;
if ( thisptr - > exists ( ) & & thisptr - > getWindow ( ) & & thisptr - > getWindow ( ) - > m_szInitialClass = = * PCLASS ) {
2024-10-28 15:25:34 +01:00
const auto PMONITOR = thisptr - > getWindow ( ) - > m_pMonitor . lock ( ) ;
2024-03-02 18:10:59 +01:00
if ( PMONITOR )
g_pHyprRenderer - > damageMonitor ( PMONITOR ) ;
else
g_pHyprRenderer - > damageWindow ( thisptr - > getWindow ( ) ) ;
}
return RG ;
}
2023-02-27 15:02:21 +01:00
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT ( HANDLE handle ) {
PHANDLE = handle ;
2024-03-19 23:18:47 +01:00
const std : : string HASH = __hyprland_api_get_hash ( ) ;
if ( HASH ! = GIT_COMMIT_HASH ) {
HyprlandAPI : : addNotification ( PHANDLE , " [csgo-vulkan-fix] Failure in initialization: Version mismatch (headers ver is not equal to running hyprland ver) " ,
2024-12-04 15:58:09 +01:00
CHyprColor { 1.0 , 0.2 , 0.2 , 1.0 } , 5000 ) ;
2024-03-19 23:18:47 +01:00
throw std : : runtime_error ( " [vkfix] Version mismatch " ) ;
}
2024-02-18 16:30:21 +01:00
HyprlandAPI : : addConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:res_w " , Hyprlang : : INT { 1680 } ) ;
HyprlandAPI : : addConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:res_h " , Hyprlang : : INT { 1050 } ) ;
2024-08-03 23:03:24 +02:00
HyprlandAPI : : addConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:fix_mouse " , Hyprlang : : INT { 1 } ) ;
2024-02-18 16:30:21 +01:00
HyprlandAPI : : addConfigValue ( PHANDLE , " plugin:csgo-vulkan-fix:class " , Hyprlang : : STRING { " cs2 " } ) ;
2023-02-27 15:02:21 +01:00
2024-08-03 23:03:24 +02:00
auto FNS = HyprlandAPI : : findFunctionsByName ( PHANDLE , " sendPointerMotion " ) ;
for ( auto & fn : FNS ) {
if ( ! fn . demangled . contains ( " CSeatManager " ) )
continue ;
g_pMouseMotionHook = HyprlandAPI : : createFunctionHook ( PHANDLE , fn . address , ( void * ) : : hkNotifyMotion ) ;
break ;
}
2024-05-30 19:09:23 +02:00
FNS = HyprlandAPI : : findFunctionsByName ( PHANDLE , " configure " ) ;
for ( auto & fn : FNS ) {
2024-08-03 23:03:24 +02:00
if ( ! fn . demangled . contains ( " XWaylandSurface " ) )
2024-05-30 19:09:23 +02:00
continue ;
g_pSurfaceSizeHook = HyprlandAPI : : createFunctionHook ( PHANDLE , fn . address , ( void * ) : : hkSetWindowSize ) ;
2024-08-03 23:03:24 +02:00
break ;
2024-05-30 19:09:23 +02:00
}
2024-07-22 19:10:51 +02:00
FNS = HyprlandAPI : : findFunctionsByName ( PHANDLE , " computeDamage " ) ;
2024-03-15 15:16:03 +01:00
for ( auto & r : FNS ) {
2024-03-02 18:10:59 +01:00
if ( ! r . demangled . contains ( " CWLSurface " ) )
continue ;
g_pWLSurfaceDamageHook = HyprlandAPI : : createFunctionHook ( PHANDLE , r . address , ( void * ) : : hkWLSurfaceDamage ) ;
break ;
}
2024-08-03 23:03:24 +02:00
bool success = g_pSurfaceSizeHook & & g_pWLSurfaceDamageHook & & g_pMouseMotionHook ;
2024-07-22 19:13:25 +02:00
if ( ! success ) {
2024-12-04 15:58:09 +01:00
HyprlandAPI : : addNotification ( PHANDLE , " [csgo-vulkan-fix] Failure in initialization: Failed to find required hook fns " , CHyprColor { 1.0 , 0.2 , 0.2 , 1.0 } , 5000 ) ;
2024-07-22 19:13:25 +02:00
throw std : : runtime_error ( " [vkfix] Hooks fn init failed " ) ;
}
2024-03-15 15:16:03 +01:00
success = success & & g_pWLSurfaceDamageHook - > hook ( ) ;
success = success & & g_pMouseMotionHook - > hook ( ) ;
success = success & & g_pSurfaceSizeHook - > hook ( ) ;
2023-02-27 15:02:21 +01:00
2024-03-15 15:16:03 +01:00
if ( success )
2024-12-04 15:58:09 +01:00
HyprlandAPI : : addNotification ( PHANDLE , " [csgo-vulkan-fix] Initialized successfully! (Anything version) " , CHyprColor { 0.2 , 1.0 , 0.2 , 1.0 } , 5000 ) ;
2023-10-29 22:25:17 +01:00
else {
2024-12-04 15:58:09 +01:00
HyprlandAPI : : addNotification ( PHANDLE , " [csgo-vulkan-fix] Failure in initialization (hook failed)! " , CHyprColor { 1.0 , 0.2 , 0.2 , 1.0 } , 5000 ) ;
2023-10-29 22:25:17 +01:00
throw std : : runtime_error ( " [csgo-vk-fix] Hooks failed " ) ;
}
2023-02-27 15:02:21 +01:00
2023-10-31 18:45:55 +01:00
return { " csgo-vulkan-fix " , " A plugin to force specific apps to a fake resolution " , " Vaxry " , " 1.2 " } ;
2023-02-27 15:02:21 +01:00
}
2023-09-03 16:40:39 +02:00
APICALL EXPORT void PLUGIN_EXIT ( ) {
;
2024-03-02 18:15:35 +01:00
}