reduce code repetition, try to add tablet(pen) support but realise there is no proper interface (?) in hyprland api

This commit is contained in:
caffeine01 2024-12-10 23:54:48 +00:00
parent 8df140f040
commit 72fb6b55cb
2 changed files with 20 additions and 14 deletions

View file

@ -18,6 +18,9 @@ CHyprBar::CHyprBar(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
m_pTouchDownCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "touchDown", [&](void* self, SCallbackInfo& info, std::any param) { onTouchDown(info); }); m_pTouchDownCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "touchDown", [&](void* self, SCallbackInfo& info, std::any param) { onTouchDown(info); });
m_pTipDownCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "tabletTip",
[&](void* self, SCallbackInfo& info, std::any param) { onTipDown(info, std::any_cast<CTablet::STipEvent>(param)); });
m_pMouseMoveCallback = m_pMouseMoveCallback =
HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseMove", [&](void* self, SCallbackInfo& info, std::any param) { onMouseMove(std::any_cast<Vector2D>(param)); }); HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseMove", [&](void* self, SCallbackInfo& info, std::any param) { onMouseMove(std::any_cast<Vector2D>(param)); });
@ -29,6 +32,7 @@ CHyprBar::~CHyprBar() {
damageEntire(); damageEntire();
HyprlandAPI::unregisterCallback(PHANDLE, m_pMouseButtonCallback); HyprlandAPI::unregisterCallback(PHANDLE, m_pMouseButtonCallback);
HyprlandAPI::unregisterCallback(PHANDLE, m_pTouchDownCallback); HyprlandAPI::unregisterCallback(PHANDLE, m_pTouchDownCallback);
HyprlandAPI::unregisterCallback(PHANDLE, m_pTipDownCallback);
HyprlandAPI::unregisterCallback(PHANDLE, m_pMouseMoveCallback); HyprlandAPI::unregisterCallback(PHANDLE, m_pMouseMoveCallback);
std::erase(g_pGlobalState->bars, this); std::erase(g_pGlobalState->bars, this);
} }
@ -111,25 +115,23 @@ void CHyprBar::onMouseDown(SCallbackInfo& info, IPointer::SButtonEvent e) {
// check if on a button // check if on a button
float offset = **PBARPADDING; CHyprBar::doButtonPress();
for (auto& b : g_pGlobalState->buttons) {
const auto BARBUF = Vector2D{(int)assignedBoxGlobal().w, **PHEIGHT};
Vector2D currentPos = Vector2D{(BUTTONSRIGHT ? BARBUF.x - **PBARBUTTONPADDING - b.size - offset : offset), (BARBUF.y - b.size) / 2.0}.floor();
if (VECINRECT(COORDS, currentPos.x, currentPos.y, currentPos.x + b.size + **PBARBUTTONPADDING, currentPos.y + b.size)) {
// hit on close
g_pKeybindManager->m_mDispatchers["exec"](b.cmd);
return;
}
offset += **PBARBUTTONPADDING + b.size;
}
m_bDragPending = true; m_bDragPending = true;
} }
void CHyprBar::onTouchDown(SCallbackInfo& info) { void CHyprBar::onTouchDown(SCallbackInfo& info) {
CHyprBar::doButtonPress();
}
void CHyprBar::onTipDown(SCallbackInfo& info, CTablet::STipEvent e) {
HyprlandAPI::addNotification(PHANDLE, "[hyprbars] TIP DOWN", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000);
if (!e.in)
return;
CHyprBar::doButtonPress();
}
void CHyprBar::doButtonPress() {
const auto COORDS = cursorRelativeToBar(); const auto COORDS = cursorRelativeToBar();
static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr(); static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr();

View file

@ -6,6 +6,7 @@
#include <hyprland/src/render/OpenGL.hpp> #include <hyprland/src/render/OpenGL.hpp>
#include <hyprland/src/devices/IPointer.hpp> #include <hyprland/src/devices/IPointer.hpp>
#include <hyprland/src/devices/ITouch.hpp> #include <hyprland/src/devices/ITouch.hpp>
#include <hyprland/src/devices/Tablet.hpp>
#include "globals.hpp" #include "globals.hpp"
class CHyprBar : public IHyprWindowDecoration { class CHyprBar : public IHyprWindowDecoration {
@ -61,12 +62,15 @@ class CHyprBar : public IHyprWindowDecoration {
void renderBarButtons(const Vector2D& bufferSize, const float scale); void renderBarButtons(const Vector2D& bufferSize, const float scale);
void renderBarButtonsText(CBox* barBox, const float scale, const float a); void renderBarButtonsText(CBox* barBox, const float scale, const float a);
void onMouseDown(SCallbackInfo& info, IPointer::SButtonEvent e); void onMouseDown(SCallbackInfo& info, IPointer::SButtonEvent e);
void onTipDown(SCallbackInfo& info, CTablet::STipEvent e);
void onTouchDown(SCallbackInfo& info); void onTouchDown(SCallbackInfo& info);
void doButtonPress();
void onMouseMove(Vector2D coords); void onMouseMove(Vector2D coords);
CBox assignedBoxGlobal(); CBox assignedBoxGlobal();
SP<HOOK_CALLBACK_FN> m_pMouseButtonCallback; SP<HOOK_CALLBACK_FN> m_pMouseButtonCallback;
SP<HOOK_CALLBACK_FN> m_pTouchDownCallback; SP<HOOK_CALLBACK_FN> m_pTouchDownCallback;
SP<HOOK_CALLBACK_FN> m_pTipDownCallback;
SP<HOOK_CALLBACK_FN> m_pMouseMoveCallback; SP<HOOK_CALLBACK_FN> m_pMouseMoveCallback;
std::string m_szLastTitle; std::string m_szLastTitle;