hyprbars: add on_double_click

fixes #384
This commit is contained in:
Vaxry 2025-06-13 15:14:02 +02:00
parent 5111562c62
commit a2cc080386
No known key found for this signature in database
GPG Key ID: 665806380871D640
4 changed files with 24 additions and 4 deletions

View File

@ -18,6 +18,9 @@ plugin {
# hyprbars-button = color, size, on-click
hyprbars-button = rgb(ff4040), 10, 󰖭, hyprctl dispatch killactive
hyprbars-button = rgb(eeee11), 10, , hyprctl dispatch fullscreen 1
# cmd to run on double click of the bar
on_double_click = hyprctl dispatch fullscreen 1
}
}
```
@ -52,6 +55,8 @@ plugin {
`icon_on_hover` -> (bool) whether the icons show on mouse hovering over the buttons (default `false`)
`on_double_click` -> (str) command to run on double click of the bar (not on a button)
## Buttons Config
Use the `hyprbars-button` keyword.

View File

@ -167,8 +167,10 @@ void CHyprBar::handleDownEvent(SCallbackInfo& info, std::optional<ITouch::SDownE
static auto* const PBARBUTTONPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->getDataStaticPtr();
static auto* const PBARPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_padding")->getDataStaticPtr();
static auto* const PALIGNBUTTONS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->getDataStaticPtr();
static auto* const PONDOUBLECLICK = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:on_double_click")->getDataStaticPtr();
const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left";
const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left";
const std::string ON_DOUBLE_CLICK = *PONDOUBLECLICK;
if (!VECINRECT(COORDS, 0, 0, assignedBoxGlobal().w, **PHEIGHT - 1)) {
@ -197,8 +199,17 @@ void CHyprBar::handleDownEvent(SCallbackInfo& info, std::optional<ITouch::SDownE
info.cancelled = true;
m_bCancelledDown = true;
if (!doButtonPress(PBARPADDING, PBARBUTTONPADDING, PHEIGHT, COORDS, BUTTONSRIGHT))
m_bDragPending = true;
if (doButtonPress(PBARPADDING, PBARBUTTONPADDING, PHEIGHT, COORDS, BUTTONSRIGHT))
return;
if (!ON_DOUBLE_CLICK.empty() &&
std::chrono::duration_cast<std::chrono::milliseconds>(Time::steadyNow() - m_lastMouseDown).count() < 400 /* Arbitrary delay I found suitable */) {
g_pKeybindManager->m_dispatchers["exec"](ON_DOUBLE_CLICK);
m_bDragPending = false;
} else {
m_lastMouseDown = Time::steadyNow();
m_bDragPending = true;
}
}
void CHyprBar::handleUpEvent(SCallbackInfo& info) {

View File

@ -8,6 +8,7 @@
#include <hyprland/src/devices/ITouch.hpp>
#include <hyprland/src/desktop/WindowRule.hpp>
#include <hyprland/src/helpers/AnimatedVariable.hpp>
#include <hyprland/src/helpers/time/Time.hpp>
#include "globals.hpp"
#define private public
@ -64,6 +65,8 @@ class CHyprBar : public IHyprWindowDecoration {
std::optional<CHyprColor> m_bForcedBarColor;
std::optional<CHyprColor> m_bForcedTitleColor;
Time::steady_tp m_lastMouseDown = Time::steadyNow();
PHLANIMVAR<CHyprColor> m_cRealBarColor;
Vector2D cursorRelativeToBar();

View File

@ -122,7 +122,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
g_pGlobalState = makeUnique<SGlobalState>();
static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); });
static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); });
// static auto P2 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(self, data); });
static auto P3 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "windowUpdateRules",
[&](void* self, SCallbackInfo& info, std::any data) { onUpdateWindowRules(std::any_cast<PHLWINDOW>(data)); });
@ -142,6 +142,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding", Hyprlang::INT{5});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:enabled", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:icon_on_hover", Hyprlang::INT{0});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:on_double_click", Hyprlang::STRING{""});
HyprlandAPI::addConfigKeyword(PHANDLE, "hyprbars-button", onNewButton, Hyprlang::SHandlerOptions{});
static auto P4 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "preConfigReload", [&](void* self, SCallbackInfo& info, std::any data) { onPreConfigReload(); });