From b5d0cfdff726676b8c6df564fdb1732558d6c25b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 3 Sep 2023 16:40:39 +0200 Subject: [PATCH] csgo-vulkan-fix: some minor fixes --- csgo-vulkan-fix/main.cpp | 47 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/csgo-vulkan-fix/main.cpp b/csgo-vulkan-fix/main.cpp index f11c663..b723c54 100644 --- a/csgo-vulkan-fix/main.cpp +++ b/csgo-vulkan-fix/main.cpp @@ -9,29 +9,31 @@ #include "globals.hpp" // Methods -inline CFunctionHook* g_pMouseMotionHook = nullptr; -inline CFunctionHook* g_pSurfaceSizeHook = nullptr; +inline CFunctionHook* g_pMouseMotionHook = nullptr; +inline CFunctionHook* g_pSurfaceSizeHook = 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 (*origSurfaceDamage)(wlr_surface*, pixman_region32_t*); // store the surface for csgo. May be invalid, only compare against -inline wlr_surface* pCSGOSurface = nullptr; +inline wlr_surface* pCSGOSurface = nullptr; inline wlr_xwayland_surface* pCSGOXWSurface = nullptr; -inline int csgoMonitor = 0; +inline int csgoMonitor = 0; // Do NOT change this function. -APICALL EXPORT std::string PLUGIN_API_VERSION() { return HYPRLAND_API_VERSION; } +APICALL EXPORT std::string PLUGIN_API_VERSION() { + return HYPRLAND_API_VERSION; +} void onNewWindow(void* self, std::any data) { // data is guaranteed auto* const PWINDOW = std::any_cast(data); if (g_pXWaylandManager->getAppIDClass(PWINDOW) == "csgo_linux64") { - pCSGOSurface = g_pXWaylandManager->getWindowSurface(PWINDOW); + pCSGOSurface = g_pXWaylandManager->getWindowSurface(PWINDOW); pCSGOXWSurface = PWINDOW->m_uSurface.xwayland; - csgoMonitor = PWINDOW->m_iMonitorID; + csgoMonitor = PWINDOW->m_iMonitorID; } } @@ -39,7 +41,7 @@ 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_pLastFocus == pCSGOSurface && g_pCompositor->m_pLastMonitor) { + 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; @@ -52,8 +54,16 @@ void hkSetWindowSize(wlr_xwayland_surface* surface, int16_t x, int16_t y, uint16 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 (surface == pCSGOXWSurface) { - width = *RESX; + if (!surface) { + (*(origSurfaceSize)g_pSurfaceSizeHook->m_pOriginal)(surface, x, y, width, height); + return; + } + + const auto SURF = surface->surface; + const auto PWINDOW = g_pCompositor->getWindowFromSurface(SURF); + + if (PWINDOW && PWINDOW->m_szInitialClass == "csgo_linux64") { + width = *RESX; height = *RESY; } @@ -66,7 +76,8 @@ void hkSurfaceDamage(wlr_surface* surface, pixman_region32_t* damage) { if (surface == pCSGOSurface) { const auto PMONITOR = g_pCompositor->getMonitorFromID(csgoMonitor); - if (PMONITOR) pixman_region32_union_rect(damage, damage, 0, 0, PMONITOR->vecSize.x, PMONITOR->vecSize.y); + if (PMONITOR) + pixman_region32_union_rect(damage, damage, 0, 0, PMONITOR->vecSize.x, PMONITOR->vecSize.y); } } @@ -76,12 +87,12 @@ 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_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_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_pSurfaceDamageHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_surface_get_effective_damage, (void*)&hkSurfaceDamage); - bool hkResult = g_pMouseMotionHook->hook(); - hkResult = hkResult && g_pSurfaceSizeHook->hook(); - hkResult = hkResult && g_pSurfaceDamageHook->hook(); + bool hkResult = g_pMouseMotionHook->hook(); + hkResult = hkResult && g_pSurfaceSizeHook->hook(); + hkResult = hkResult && g_pSurfaceDamageHook->hook(); HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, std::any data) { onNewWindow(self, data); }); @@ -93,4 +104,6 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { return {"csgo-vulkan-fix", "A plugin to fix incorrect mouse offsets on csgo in Vulkan", "Vaxry", "1.0"}; } -APICALL EXPORT void PLUGIN_EXIT() { ; } \ No newline at end of file +APICALL EXPORT void PLUGIN_EXIT() { + ; +} \ No newline at end of file