all: chase hyprland

This commit is contained in:
Vaxry 2024-06-08 11:12:34 +02:00
parent e0cad229c3
commit 8571aa9bad
5 changed files with 27 additions and 47 deletions

View file

@ -13,11 +13,9 @@
// Methods
inline CFunctionHook* g_pMouseMotionHook = nullptr;
inline CFunctionHook* g_pSurfaceSizeHook = nullptr;
inline CFunctionHook* g_pSurfaceDamageHook = nullptr;
inline CFunctionHook* g_pWLSurfaceDamageHook = nullptr;
typedef void (*origMotion)(CSeatManager*, uint32_t, const Vector2D&);
typedef void (*origSurfaceSize)(CXWaylandSurface*, const CBox&);
typedef void (*origSurfaceDamage)(wlr_surface*, pixman_region32_t*);
typedef CRegion (*origWLSurfaceDamage)(CWLSurface*);
// Do NOT change this function.
@ -51,7 +49,7 @@ void hkSetWindowSize(CXWaylandSurface* surface, const CBox& box) {
return;
}
const auto SURF = surface->surface;
const auto SURF = surface->surface.lock();
const auto PWINDOW = g_pCompositor->getWindowFromSurface(SURF);
CBox newBox = box;
@ -60,28 +58,12 @@ void hkSetWindowSize(CXWaylandSurface* surface, const CBox& box) {
newBox.w = **RESX;
newBox.h = **RESY;
CWLSurface::surfaceFromWlr(SURF)->m_bFillIgnoreSmall = true;
CWLSurface::fromResource(SURF)->m_bFillIgnoreSmall = true;
}
(*(origSurfaceSize)g_pSurfaceSizeHook->m_pOriginal)(surface, newBox);
}
void hkSurfaceDamage(wlr_surface* surface, pixman_region32_t* damage) {
(*(origSurfaceDamage)g_pSurfaceDamageHook->m_pOriginal)(surface, damage);
static auto* const PCLASS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:csgo-vulkan-fix:class")->getDataStaticPtr();
const auto SURF = CWLSurface::surfaceFromWlr(surface);
if (SURF && SURF->exists() && SURF->getWindow() && SURF->getWindow()->m_szInitialClass == *PCLASS) {
const auto PMONITOR = g_pCompositor->getMonitorFromID(SURF->getWindow()->m_iMonitorID);
if (PMONITOR)
g_pHyprRenderer->damageMonitor(PMONITOR);
else
g_pHyprRenderer->damageWindow(SURF->getWindow());
}
}
CRegion hkWLSurfaceDamage(CWLSurface* thisptr) {
const auto RG = (*(origWLSurfaceDamage)g_pWLSurfaceDamageHook->m_pOriginal)(thisptr);
@ -126,11 +108,6 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
}
success = success && g_pSurfaceSizeHook;
FNS = HyprlandAPI::findFunctionsByName(PHANDLE, "wlr_surface_get_effective_damage");
success = success && !FNS.empty();
if (success)
g_pSurfaceDamageHook = HyprlandAPI::createFunctionHook(PHANDLE, FNS[0].address, (void*)::hkSurfaceDamage);
FNS = HyprlandAPI::findFunctionsByName(PHANDLE, "logicalDamage");
for (auto& r : FNS) {
if (!r.demangled.contains("CWLSurface"))
@ -143,7 +120,6 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
success = success && g_pWLSurfaceDamageHook->hook();
success = success && g_pMouseMotionHook->hook();
success = success && g_pSurfaceSizeHook->hook();
success = success && g_pSurfaceDamageHook->hook();
if (success)
HyprlandAPI::addNotification(PHANDLE, "[csgo-vulkan-fix] Initialized successfully! (Anything version)", CColor{0.2, 1.0, 0.2, 1.0}, 5000);

View file

@ -17,6 +17,9 @@ CHyprBar::CHyprBar(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
m_pMouseMoveCallback =
HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseMove", [&](void* self, SCallbackInfo& info, std::any param) { onMouseMove(std::any_cast<Vector2D>(param)); });
m_pTextTex = makeShared<CTexture>();
m_pButtonsTex = makeShared<CTexture>();
}
CHyprBar::~CHyprBar() {
@ -134,7 +137,7 @@ void CHyprBar::onMouseMove(Vector2D coords) {
}
}
void CHyprBar::renderText(CTexture& out, const std::string& text, const CColor& color, const Vector2D& bufferSize, const float scale, const int fontSize) {
void CHyprBar::renderText(SP<CTexture> out, const std::string& text, const CColor& color, const Vector2D& bufferSize, const float scale, const int fontSize) {
const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y);
const auto CAIRO = cairo_create(CAIROSURFACE);
@ -174,8 +177,8 @@ void CHyprBar::renderText(CTexture& out, const std::string& text, const CColor&
// copy the data to an OpenGL texture we have
const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
out.allocate();
glBindTexture(GL_TEXTURE_2D, out.m_iTexID);
out->allocate();
glBindTexture(GL_TEXTURE_2D, out->m_iTexID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -260,8 +263,8 @@ void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) {
// copy the data to an OpenGL texture we have
const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
m_tTextTex.allocate();
glBindTexture(GL_TEXTURE_2D, m_tTextTex.m_iTexID);
m_pTextTex->allocate();
glBindTexture(GL_TEXTURE_2D, m_pTextTex->m_iTexID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -323,8 +326,8 @@ void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
// copy the data to an OpenGL texture we have
const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
m_tButtonsTex.allocate();
glBindTexture(GL_TEXTURE_2D, m_tButtonsTex.m_iTexID);
m_pButtonsTex->allocate();
glBindTexture(GL_TEXTURE_2D, m_pButtonsTex->m_iTexID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -355,7 +358,7 @@ void CHyprBar::renderBarButtonsText(CBox* barBox, const float scale, const float
auto drawButton = [&](SHyprButton& button) -> void {
const auto scaledButtonSize = button.size * scale;
if (button.iconTex.m_iTexID == 0 /* icon is not rendered */ && !button.icon.empty()) {
if (button.iconTex->m_iTexID == 0 /* icon is not rendered */ && !button.icon.empty()) {
// render icon
const Vector2D BUFSIZE = {scaledButtonSize, scaledButtonSize};
@ -364,7 +367,7 @@ void CHyprBar::renderBarButtonsText(CBox* barBox, const float scale, const float
renderText(button.iconTex, button.icon, LIGHT ? CColor(0xFFFFFFFF) : CColor(0xFF000000), BUFSIZE, scale, button.size * 0.62);
}
if (button.iconTex.m_iTexID == 0)
if (button.iconTex->m_iTexID == 0)
return;
CBox pos = {barBox->x + (BUTTONSRIGHT ? barBox->width - offset - scaledButtonSize : offset), barBox->y + (barBox->height - scaledButtonSize) / 2.0, scaledButtonSize,
@ -458,7 +461,7 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
g_pHyprOpenGL->renderRect(&titleBarBox, color, scaledRounding);
// render title
if (**PENABLETITLE && (m_szLastTitle != PWINDOW->m_szTitle || m_bWindowSizeChanged || m_tTextTex.m_iTexID == 0)) {
if (**PENABLETITLE && (m_szLastTitle != PWINDOW->m_szTitle || m_bWindowSizeChanged || m_pTextTex->m_iTexID == 0)) {
m_szLastTitle = PWINDOW->m_szTitle;
renderBarTitle(BARBUF, pMonitor->scale);
}
@ -474,14 +477,14 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
CBox textBox = {titleBarBox.x, titleBarBox.y, (int)BARBUF.x, (int)BARBUF.y};
if (**PENABLETITLE)
g_pHyprOpenGL->renderTexture(m_tTextTex, &textBox, a);
g_pHyprOpenGL->renderTexture(m_pTextTex, &textBox, a);
if (m_bButtonsDirty || m_bWindowSizeChanged) {
renderBarButtons(BARBUF, pMonitor->scale);
m_bButtonsDirty = false;
}
g_pHyprOpenGL->renderTexture(m_tButtonsTex, &textBox, a);
g_pHyprOpenGL->renderTexture(m_pButtonsTex, &textBox, a);
g_pHyprOpenGL->scissor((CBox*)nullptr);

View file

@ -43,8 +43,8 @@ class CHyprBar : public IHyprWindowDecoration {
CBox m_bAssignedBox;
CTexture m_tTextTex;
CTexture m_tButtonsTex;
SP<CTexture> m_pTextTex;
SP<CTexture> m_pButtonsTex;
bool m_bWindowSizeChanged = false;
bool m_bHidden = false;
@ -52,7 +52,7 @@ class CHyprBar : public IHyprWindowDecoration {
Vector2D cursorRelativeToBar();
void renderBarTitle(const Vector2D& bufferSize, const float scale);
void renderText(CTexture& out, const std::string& text, const CColor& color, const Vector2D& bufferSize, const float scale, const int fontSize);
void renderText(SP<CTexture> out, const std::string& text, const CColor& color, const Vector2D& bufferSize, const float scale, const int fontSize);
void renderBarButtons(const Vector2D& bufferSize, const float scale);
void renderBarButtonsText(CBox* barBox, const float scale, const float a);
void onMouseDown(SCallbackInfo& info, IPointer::SButtonEvent e);

View file

@ -1,6 +1,7 @@
#pragma once
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/render/Texture.hpp>
inline HANDLE PHANDLE = nullptr;
@ -9,7 +10,7 @@ struct SHyprButton {
CColor col = CColor(0, 0, 0, 0);
float size = 10;
std::string icon = "";
CTexture iconTex;
SP<CTexture> iconTex = makeShared<CTexture>();
};
class CHyprBar;

View file

@ -88,7 +88,7 @@ void onRenderStage(eRenderStage stage) {
}
void onCommitSubsurface(CSubsurface* thisptr) {
const auto PWINDOW = thisptr->m_sWLSurface.getWindow();
const auto PWINDOW = thisptr->m_pWLSurface->getWindow();
if (!PWINDOW || std::find_if(bgWindows.begin(), bgWindows.end(), [PWINDOW](const auto& ref) { return ref.lock() == PWINDOW; }) == bgWindows.end()) {
((origCommitSubsurface)subsurfaceHook->m_pOriginal)(thisptr);