csgo-vulkan-fix: bring back mouse patch

This commit is contained in:
vaxerski 2023-09-28 22:21:37 +01:00
parent 35ca302ff7
commit 33c3ced2c2

View file

@ -9,8 +9,10 @@
#include "globals.hpp" #include "globals.hpp"
// Methods // Methods
inline CFunctionHook* g_pMouseMotionHook = nullptr;
inline CFunctionHook* g_pSurfaceSizeHook = nullptr; inline CFunctionHook* g_pSurfaceSizeHook = nullptr;
inline CFunctionHook* g_pSurfaceDamageHook = nullptr; inline CFunctionHook* g_pSurfaceDamageHook = nullptr;
typedef void (*origMotion)(wlr_seat*, uint32_t, double, double);
typedef void (*origSurfaceSize)(wlr_xwayland_surface*, int16_t, int16_t, uint16_t, uint16_t); typedef void (*origSurfaceSize)(wlr_xwayland_surface*, int16_t, int16_t, uint16_t, uint16_t);
typedef void (*origSurfaceDamage)(wlr_surface*, pixman_region32_t*); typedef void (*origSurfaceDamage)(wlr_surface*, pixman_region32_t*);
@ -35,6 +37,19 @@ void onNewWindow(void* self, std::any data) {
} }
} }
void hkNotifyMotion(wlr_seat* wlr_seat, uint32_t time_msec, double sx, double sy) {
static auto* const RESX = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_w")->intValue;
static auto* const RESY = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_h")->intValue;
if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_szInitialClass == "csgo_linux64" && g_pCompositor->m_pLastMonitor) {
// fix the coords
sx *= *RESX / g_pCompositor->m_pLastMonitor->vecSize.x;
sy *= *RESY / g_pCompositor->m_pLastMonitor->vecSize.y;
}
(*(origMotion)g_pMouseMotionHook->m_pOriginal)(wlr_seat, time_msec, sx, sy);
}
void hkSetWindowSize(wlr_xwayland_surface* surface, int16_t x, int16_t y, uint16_t width, uint16_t height) { void hkSetWindowSize(wlr_xwayland_surface* surface, int16_t x, int16_t y, uint16_t width, uint16_t height) {
static auto* const RESX = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_w")->intValue; static auto* const RESX = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_w")->intValue;
static auto* const RESY = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_h")->intValue; static auto* const RESY = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_h")->intValue;
@ -72,9 +87,11 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_w", SConfigValue{.intValue = 1680}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_w", SConfigValue{.intValue = 1680});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_h", SConfigValue{.intValue = 1050}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:res_h", SConfigValue{.intValue = 1050});
g_pMouseMotionHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_seat_pointer_notify_motion, (void*)&hkNotifyMotion);
g_pSurfaceSizeHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_xwayland_surface_configure, (void*)&hkSetWindowSize); g_pSurfaceSizeHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_xwayland_surface_configure, (void*)&hkSetWindowSize);
g_pSurfaceDamageHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_surface_get_effective_damage, (void*)&hkSurfaceDamage); g_pSurfaceDamageHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_surface_get_effective_damage, (void*)&hkSurfaceDamage);
bool hkResult = g_pSurfaceSizeHook->hook(); bool hkResult = g_pMouseMotionHook->hook();
hkResult = hkResult && g_pSurfaceSizeHook->hook();
hkResult = hkResult && g_pSurfaceDamageHook->hook(); hkResult = hkResult && g_pSurfaceDamageHook->hook();
HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, std::any data) { onNewWindow(self, data); }); HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, std::any data) { onNewWindow(self, data); });