diff --git a/csgo-vulkan-fix/main.cpp b/csgo-vulkan-fix/main.cpp index b3da891..2d15c91 100644 --- a/csgo-vulkan-fix/main.cpp +++ b/csgo-vulkan-fix/main.cpp @@ -21,9 +21,6 @@ extern "C" { #include } -#include -using namespace Hyprutils::String; - // Methods inline CFunctionHook* g_pMouseMotionHook = nullptr; inline CFunctionHook* g_pSurfaceSizeHook = nullptr; @@ -178,39 +175,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { static auto P = Event::bus()->m_events.config.preReload.listen([&] { g_appConfigs.clear(); }); - if (Config::mgr()->type() == Config::CONFIG_LEGACY) { - HyprlandAPI::addConfigKeyword( - PHANDLE, "vkfix-app", - [](const char* l, const char* r) -> Hyprlang::CParseResult { - const std::string str = r; - CConstVarList data(str, 0, ',', true); - - Hyprlang::CParseResult result; - - if (data.size() != 3) { - result.setError("vkfix-app requires 3 params"); - return result; - } - - try { - SAppConfig config; - config.szClass = data[0]; - config.res = Vector2D{std::stoi(std::string{data[1]}), std::stoi(std::string{data[2]})}; - g_appConfigs.emplace_back(std::move(config)); - } catch (std::exception& e) { - result.setError("failed to parse line"); - return result; - } - - return result; - }, - Hyprlang::SHandlerOptions{}); - } else if (Config::mgr()->type() == Config::CONFIG_LUA) { - HyprlandAPI::addLuaFunction(PHANDLE, "csgo_vulkan_fix", "vkfix_app", ::vkfixAppLua); - } else { - HyprlandAPI::addNotification(PHANDLE, "[csgo-vulkan-fix] Failure in initialization: Failed to get a valid config manager", CHyprColor{1.0, 0.2, 0.2, 1.0}, 5000); - throw std::runtime_error("[vkfix] Config manager bad"); - } + HyprlandAPI::addLuaFunction(PHANDLE, "csgo_vulkan_fix", "vkfix_app", ::vkfixAppLua); configValues.fixMouse = makeShared("plugin:csgo_vulkan_fix:fix_mouse", "Whether to fix the mouse position. A select few apps might be wonky with this.", true); diff --git a/hyprbars/barDeco.cpp b/hyprbars/barDeco.cpp index c27653d..993c8f3 100644 --- a/hyprbars/barDeco.cpp +++ b/hyprbars/barDeco.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,7 @@ using namespace Render::GL; static CHyprColor configColor(Config::INTEGER color) { - return CHyprColor{static_cast(color)}; + return CHyprColor{sc(color)}; } CHyprBar::CHyprBar(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) { @@ -68,7 +69,7 @@ SDecorationPositioningInfo CHyprBar::getPositioningInfo() { info.edges = DECORATION_EDGE_TOP; info.priority = PRECEDENCE ? 10005 : 5000; info.reserved = true; - info.desiredExtents = {{0, m_hidden || !ENABLED ? 0 : HEIGHT}, {0, 0}}; + info.desiredExtents = {{0, sc(m_hidden || !ENABLED ? 0 : HEIGHT)}, {0, 0}}; return info; } @@ -165,19 +166,15 @@ void CHyprBar::onTouchMove(Event::SCallbackInfo& info, ITouch::SMotionEvent e) { if (!m_bDragPending || !m_bTouchEv || !validMapped(m_pWindow) || e.touchID != m_touchId) return; - auto PMONITOR = m_pWindow->m_monitor.lock(); - PMONITOR = PMONITOR ? PMONITOR : Desktop::focusState()->monitor(); - const auto COORDS = Vector2D(PMONITOR->m_position.x + e.pos.x * PMONITOR->m_size.x, PMONITOR->m_position.y + e.pos.y * PMONITOR->m_size.y); - if (!m_bDraggingThis) { // Initial setup for dragging a window. - g_pKeybindManager->m_dispatchers["setfloating"]("activewindow"); - g_pKeybindManager->m_dispatchers["resizewindowpixel"]("exact 50% 50%,activewindow"); - // pin it so you can change workspaces while dragging a window - g_pKeybindManager->m_dispatchers["pin"]("activewindow"); + (void)Config::Actions::floatWindow(Config::Actions::eTogglableAction::TOGGLE_ACTION_ENABLE, m_pWindow.lock()); + // Pin it so you can change workspaces while dragging a window + (void)Config::Actions::pinWindow(Config::Actions::eTogglableAction::TOGGLE_ACTION_ENABLE, m_pWindow.lock()); + + g_pKeybindManager->changeMouseBindMode(MBIND_MOVE); + m_bDraggingThis = true; } - g_pKeybindManager->m_dispatchers["movewindowpixel"](std::format("exact {} {},activewindow", (int)(COORDS.x - (assignedBoxGlobal().w / 2)), (int)COORDS.y)); - m_bDraggingThis = true; } void CHyprBar::handleDownEvent(Event::SCallbackInfo& info, std::optional touchEvent) { @@ -213,8 +210,8 @@ void CHyprBar::handleDownEvent(Event::SCallbackInfo& info, std::optionalm_dispatchers["settiled"]("activewindow"); - g_pKeybindManager->m_dispatchers["mouse"]("0movewindow"); + (void)Config::Actions::floatWindow(Config::Actions::eTogglableAction::TOGGLE_ACTION_DISABLE); + g_pKeybindManager->changeMouseBindMode(MBIND_INVALID); Log::logger->log(Log::DEBUG, "[hyprbars] Dragging ended on {:x}", (uintptr_t)PWINDOW.get()); } @@ -281,12 +278,12 @@ bool CHyprBar::doButtonPress(Config::INTEGER barPadding, Config::INTEGER barButt float offset = barPadding; for (auto& b : g_pGlobalState->buttons) { - const auto BARBUF = Vector2D{(int)assignedBoxGlobal().w, barHeight}; + const auto BARBUF = Vector2D{assignedBoxGlobal().w, sc(barHeight)}; Vector2D currentPos = Vector2D{(BUTTONSRIGHT ? BARBUF.x - barButtonPadding - b.size - offset : offset), (BARBUF.y - b.size) / 2.0}.floor(); if (VECINRECT(COORDS, currentPos.x, currentPos.y, currentPos.x + b.size + barButtonPadding, currentPos.y + b.size)) { // hit on close - g_pKeybindManager->m_dispatchers["exec"](b.cmd); + Config::Supplementary::executor()->spawn(b.cmd); return true; } @@ -313,7 +310,7 @@ void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) { const auto scaledButtonsSize = buttonSizes * scale; const auto scaledBarPadding = BARPADDING * scale; const int paddingTotal = scaledBarPadding * 2 + scaledButtonsSize + (ALIGN != "left" ? scaledButtonsSize : 0); - const int maxWidth = std::clamp(static_cast(bufferSize.x - paddingTotal), 0, INT_MAX); + const int maxWidth = std::clamp(sc(bufferSize.x - paddingTotal), 0, INT_MAX); if (m_szLastTitle.empty() || maxWidth < 1) { m_pTextTex = nullptr; @@ -370,7 +367,7 @@ void CHyprBar::renderBarButtons(CBox* barBox, const float scale, const float a) scaledButtonSize}; buttonBox.round(); - g_pHyprOpenGL->renderRect(buttonBox, color, {.round = static_cast(std::round(scaledButtonSize / 2.0)), .roundingPower = 2.F}); + g_pHyprOpenGL->renderRect(buttonBox, color, {.round = sc(std::round(scaledButtonSize / 2.0)), .roundingPower = 2.F}); offset += scaledButtonsPad + scaledButtonSize; } @@ -396,7 +393,7 @@ void CHyprBar::renderBarButtonsText(CBox* barBox, const float scale, const float const auto scaledButtonsPad = BARBUTTONPADDING * scale; // check if hovering here - const auto BARBUF = Vector2D{(int)assignedBoxGlobal().w, HEIGHT}; + const auto BARBUF = Vector2D{assignedBoxGlobal().w, sc(HEIGHT)}; Vector2D currentPos = Vector2D{(BUTTONSRIGHT ? BARBUF.x - BARBUTTONPADDING - button.size - noScaleOffset : noScaleOffset), (BARBUF.y - button.size) / 2.0}.floor(); bool hovering = VECINRECT(COORDS, currentPos.x, currentPos.y, currentPos.x + button.size + BARBUTTONPADDING, currentPos.y + button.size); noScaleOffset += BARBUTTONPADDING + button.size; @@ -490,7 +487,7 @@ void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) { const auto scaledRounding = ROUNDING > 0 ? ROUNDING * pMonitor->m_scale - 2 /* idk why but otherwise it looks bad due to the gaps */ : 0; - m_seExtents = {{0, HEIGHT}, {}}; + m_seExtents = {{0, sc(HEIGHT)}, {}}; const auto DECOBOX = assignedBoxGlobal(); @@ -526,7 +523,7 @@ void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) { glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); windowBox.translate(WORKSPACEOFFSET).scale(pMonitor->m_scale).round(); - g_pHyprOpenGL->renderRect(windowBox, CHyprColor(0, 0, 0, 0), {.round = scaledRounding, .roundingPower = m_pWindow->roundingPower()}); + g_pHyprOpenGL->renderRect(windowBox, CHyprColor(0, 0, 0, 0), {.round = sc(scaledRounding), .roundingPower = m_pWindow->roundingPower()}); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilFunc(GL_NOTEQUAL, 1, -1); @@ -534,9 +531,9 @@ void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) { } if (SHOULDBLUR) - g_pHyprOpenGL->renderRect(titleBarBox, color, {.round = scaledRounding, .roundingPower = m_pWindow->roundingPower(), .blur = true, .blurA = a}); + g_pHyprOpenGL->renderRect(titleBarBox, color, {.round = sc(scaledRounding), .roundingPower = m_pWindow->roundingPower(), .blur = true, .blurA = a}); else - g_pHyprOpenGL->renderRect(titleBarBox, color, {.round = scaledRounding, .roundingPower = m_pWindow->roundingPower()}); + g_pHyprOpenGL->renderRect(titleBarBox, color, {.round = sc(scaledRounding), .roundingPower = m_pWindow->roundingPower()}); // render title if (ENABLETITLE && (m_szLastTitle != PWINDOW->m_title || m_bWindowSizeChanged || !m_pTextTex || m_pTextTex->m_texID == 0 || m_bTitleColorChanged)) { @@ -553,7 +550,7 @@ void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) { glStencilFunc(GL_ALWAYS, 1, 0xFF); } - CBox textBox = {titleBarBox.x, titleBarBox.y, (int)BARBUF.x, (int)BARBUF.y}; + CBox textBox = {titleBarBox.x, titleBarBox.y, BARBUF.x, BARBUF.y}; if (ENABLETITLE && m_pTextTex) { const auto BARPADDING = g_pGlobalState->config.barPadding->value(); const auto BARBUTTONPADDING = g_pGlobalState->config.barButtonPadding->value(); @@ -676,7 +673,7 @@ void CHyprBar::damageOnButtonHover() { const auto COORDS = cursorRelativeToBar(); for (auto& b : g_pGlobalState->buttons) { - const auto BARBUF = Vector2D{(int)assignedBoxGlobal().w, HEIGHT}; + const auto BARBUF = Vector2D{assignedBoxGlobal().w, sc(HEIGHT)}; Vector2D currentPos = Vector2D{(BUTTONSRIGHT ? BARBUF.x - BARBUTTONPADDING - b.size - offset : offset), (BARBUF.y - b.size) / 2.0}.floor(); bool hover = VECINRECT(COORDS, currentPos.x, currentPos.y, currentPos.x + b.size + BARBUTTONPADDING, currentPos.y + b.size); diff --git a/hyprbars/main.cpp b/hyprbars/main.cpp index ae9c90b..76add8c 100644 --- a/hyprbars/main.cpp +++ b/hyprbars/main.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -15,8 +14,6 @@ #include #include -#include - #include #include "barDeco.hpp" @@ -67,55 +64,6 @@ static void onUpdateWindowRules(PHLWINDOW window) { window->updateWindowDecos(); } -Hyprlang::CParseResult onNewButton(const char* K, const char* V) { - std::string v = V; - Hyprutils::String::CVarList vars(v); - - Hyprlang::CParseResult result; - - // hyprbars-button = bgcolor, size, icon, action, fgcolor - - if (vars[0].empty() || vars[1].empty()) { - result.setError("bgcolor and size cannot be empty"); - return result; - } - - float size = 10; - try { - size = std::stof(vars[1]); - } catch (std::exception& e) { - result.setError("failed to parse size"); - return result; - } - - bool userfg = false; - auto fgcolor = Config::ParserUtils::parseColor("rgb(ffffff)"); - auto bgcolor = Config::ParserUtils::parseColor(vars[0]); - - if (!bgcolor) { - result.setError("invalid bgcolor"); - return result; - } - - if (vars.size() == 5) { - userfg = true; - fgcolor = Config::ParserUtils::parseColor(vars[4]); - } - - if (!fgcolor) { - result.setError("invalid fgcolor"); - return result; - } - - g_pGlobalState->buttons.push_back(SHyprButton{vars[3], userfg, *fgcolor, *bgcolor, size, vars[2]}); - - for (auto& b : g_pGlobalState->bars) { - b->m_bButtonsDirty = true; - } - - return result; -} - int newLuaButton(lua_State* L) { if (!lua_istable(L, 1)) return Config::Lua::Bindings::Internal::configError(L, "add_button: expected a table { bg_color, fg_color, size, icon, action }"); @@ -252,10 +200,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { HyprlandAPI::addConfigValueV2(PHANDLE, g_pGlobalState->config.iconOnHover); HyprlandAPI::addConfigValueV2(PHANDLE, g_pGlobalState->config.onDoubleClick); - if (Config::mgr()->type() == Config::CONFIG_LEGACY) - HyprlandAPI::addConfigKeyword(PHANDLE, "plugin:hyprbars:hyprbars-button", onNewButton, Hyprlang::SHandlerOptions{}); - else - HyprlandAPI::addLuaFunction(PHANDLE, "hyprbars", "add_button", ::newLuaButton); + HyprlandAPI::addLuaFunction(PHANDLE, "hyprbars", "add_button", ::newLuaButton); + static auto P4 = Event::bus()->m_events.config.preReload.listen([&] { onPreConfigReload(); }); static auto P5 = Event::bus()->m_events.config.reloaded.listen([&] { onConfigReloaded(); });