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>
|
|
|
|
#include <hyprland/src/Window.hpp>
|
|
|
|
#include <hyprland/src/config/ConfigManager.hpp>
|
2023-02-27 15:02:21 +01:00
|
|
|
|
|
|
|
#include "globals.hpp"
|
|
|
|
|
|
|
|
// Methods
|
2023-09-28 23:21:37 +02:00
|
|
|
inline CFunctionHook* g_pMouseMotionHook = nullptr;
|
2023-09-03 16:40:39 +02:00
|
|
|
inline CFunctionHook* g_pSurfaceSizeHook = nullptr;
|
2023-02-27 15:02:21 +01:00
|
|
|
inline CFunctionHook* g_pSurfaceDamageHook = nullptr;
|
2023-09-28 23:21:37 +02:00
|
|
|
typedef void (*origMotion)(wlr_seat*, uint32_t, double, double);
|
2023-02-27 15:02:21 +01:00
|
|
|
typedef void (*origSurfaceSize)(wlr_xwayland_surface*, int16_t, int16_t, uint16_t, uint16_t);
|
|
|
|
typedef void (*origSurfaceDamage)(wlr_surface*, pixman_region32_t*);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2023-09-28 23:21:37 +02:00
|
|
|
void hkNotifyMotion(wlr_seat* wlr_seat, uint32_t time_msec, double sx, double sy) {
|
2023-10-31 18:45:55 +01:00
|
|
|
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 PCLASS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:class")->strValue;
|
2023-09-28 23:21:37 +02:00
|
|
|
|
2023-10-31 18:45:55 +01:00
|
|
|
if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_szInitialClass == *PCLASS && g_pCompositor->m_pLastMonitor) {
|
2023-09-28 23:21:37 +02:00
|
|
|
// fix the coords
|
2023-10-31 18:45:55 +01:00
|
|
|
sx *= (*RESX / g_pCompositor->m_pLastMonitor->vecSize.x) / g_pCompositor->m_pLastWindow->m_fX11SurfaceScaledBy;
|
|
|
|
sy *= (*RESY / g_pCompositor->m_pLastMonitor->vecSize.y) / g_pCompositor->m_pLastWindow->m_fX11SurfaceScaledBy;
|
2023-09-28 23:21:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(*(origMotion)g_pMouseMotionHook->m_pOriginal)(wlr_seat, time_msec, sx, sy);
|
|
|
|
}
|
|
|
|
|
2023-02-27 15:02:21 +01:00
|
|
|
void hkSetWindowSize(wlr_xwayland_surface* surface, int16_t x, int16_t y, uint16_t width, uint16_t height) {
|
2023-10-31 18:45:55 +01:00
|
|
|
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 PCLASS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:class")->strValue;
|
2023-02-27 15:02:21 +01:00
|
|
|
|
2023-09-03 16:40:39 +02:00
|
|
|
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);
|
|
|
|
|
2023-10-31 18:45:55 +01:00
|
|
|
if (PWINDOW && PWINDOW->m_szInitialClass == *PCLASS) {
|
2023-09-03 16:40:39 +02:00
|
|
|
width = *RESX;
|
2023-02-27 15:02:21 +01:00
|
|
|
height = *RESY;
|
2023-10-20 21:22:37 +02:00
|
|
|
|
|
|
|
CWLSurface::surfaceFromWlr(SURF)->m_bFillIgnoreSmall = true;
|
2023-02-27 15:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
(*(origSurfaceSize)g_pSurfaceSizeHook->m_pOriginal)(surface, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hkSurfaceDamage(wlr_surface* surface, pixman_region32_t* damage) {
|
|
|
|
(*(origSurfaceDamage)g_pSurfaceDamageHook->m_pOriginal)(surface, damage);
|
|
|
|
|
2023-10-31 18:45:55 +01:00
|
|
|
static auto* const PCLASS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:class")->strValue;
|
2023-02-27 15:02:21 +01:00
|
|
|
|
2023-10-31 18:45:55 +01:00
|
|
|
const auto SURF = CWLSurface::surfaceFromWlr(surface);
|
|
|
|
|
|
|
|
if (SURF && SURF->exists() && SURF->m_pOwner && SURF->m_pOwner->m_szInitialClass == *PCLASS)
|
|
|
|
g_pHyprRenderer->damageWindow(SURF->m_pOwner);
|
2023-02-27 15:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
|
|
|
PHANDLE = 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});
|
2023-10-31 18:45:55 +01:00
|
|
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:class", SConfigValue{.strValue = "cs2"});
|
2023-02-27 15:02:21 +01:00
|
|
|
|
2023-09-28 23:21:37 +02:00
|
|
|
g_pMouseMotionHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_seat_pointer_notify_motion, (void*)&hkNotifyMotion);
|
2023-09-03 16:40:39 +02:00
|
|
|
g_pSurfaceSizeHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_xwayland_surface_configure, (void*)&hkSetWindowSize);
|
2023-02-27 15:02:21 +01:00
|
|
|
g_pSurfaceDamageHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&wlr_surface_get_effective_damage, (void*)&hkSurfaceDamage);
|
2023-09-28 23:21:37 +02:00
|
|
|
bool hkResult = g_pMouseMotionHook->hook();
|
|
|
|
hkResult = hkResult && g_pSurfaceSizeHook->hook();
|
2023-09-03 16:40:39 +02:00
|
|
|
hkResult = hkResult && g_pSurfaceDamageHook->hook();
|
2023-02-27 15:02:21 +01:00
|
|
|
|
|
|
|
if (hkResult)
|
2023-10-31 18:45:55 +01:00
|
|
|
HyprlandAPI::addNotification(PHANDLE, "[csgo-vulkan-fix] Initialized successfully! (Anything version)", CColor{0.2, 1.0, 0.2, 1.0}, 5000);
|
2023-10-29 22:25:17 +01:00
|
|
|
else {
|
2023-02-27 15:02:21 +01:00
|
|
|
HyprlandAPI::addNotification(PHANDLE, "[csgo-vulkan-fix] Failure in initialization (hook failed)!", CColor{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() {
|
|
|
|
;
|
|
|
|
}
|