mirror of
https://github.com/hyprwm/hyprland-plugins.git
synced 2024-11-22 02:35:57 +01:00
hyprbars: add configurable padding
This commit is contained in:
parent
d744330811
commit
340ade398e
3 changed files with 42 additions and 27 deletions
|
@ -40,6 +40,10 @@ plugin {
|
||||||
|
|
||||||
`bar_precedence_over_border` -> (bool) whether the bar should have a higher priority than the border (border will be around the bar)
|
`bar_precedence_over_border` -> (bool) whether the bar should have a higher priority than the border (border will be around the bar)
|
||||||
|
|
||||||
|
`bar_padding` -> (int) left / right edge padding (default `7`)
|
||||||
|
|
||||||
|
`bar_button_padding` -> (int) padding between the buttons (default `5`)
|
||||||
|
|
||||||
## Buttons Config
|
## Buttons Config
|
||||||
|
|
||||||
Use the `hyprbars-button` keyword.
|
Use the `hyprbars-button` keyword.
|
||||||
|
|
|
@ -6,9 +6,6 @@
|
||||||
|
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
|
|
||||||
constexpr int BAR_PADDING = 10;
|
|
||||||
constexpr int BUTTONS_PAD = 5;
|
|
||||||
|
|
||||||
CHyprBar::CHyprBar(CWindow* pWindow) : IHyprWindowDecoration(pWindow) {
|
CHyprBar::CHyprBar(CWindow* pWindow) : IHyprWindowDecoration(pWindow) {
|
||||||
m_pWindow = pWindow;
|
m_pWindow = pWindow;
|
||||||
|
|
||||||
|
@ -55,8 +52,9 @@ void CHyprBar::onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e) {
|
||||||
|
|
||||||
const auto COORDS = cursorRelativeToBar();
|
const auto COORDS = cursorRelativeToBar();
|
||||||
|
|
||||||
static auto* const PHEIGHT = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->intValue;
|
static auto* const PHEIGHT = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->intValue;
|
||||||
const auto BORDERSIZE = m_pWindow->getRealBorderSize();
|
static auto* const PBARBUTTONPADDING = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->intValue;
|
||||||
|
const auto BORDERSIZE = m_pWindow->getRealBorderSize();
|
||||||
|
|
||||||
if (!VECINRECT(COORDS, 0, 0, assignedBoxGlobal().w + BORDERSIZE * 2, *PHEIGHT)) {
|
if (!VECINRECT(COORDS, 0, 0, assignedBoxGlobal().w + BORDERSIZE * 2, *PHEIGHT)) {
|
||||||
|
|
||||||
|
@ -98,15 +96,15 @@ void CHyprBar::onMouseDown(SCallbackInfo& info, wlr_pointer_button_event* e) {
|
||||||
|
|
||||||
for (auto& b : g_pGlobalState->buttons) {
|
for (auto& b : g_pGlobalState->buttons) {
|
||||||
const auto BARBUF = Vector2D{(int)assignedBoxGlobal().w, *PHEIGHT + BORDERSIZE};
|
const auto BARBUF = Vector2D{(int)assignedBoxGlobal().w, *PHEIGHT + BORDERSIZE};
|
||||||
Vector2D currentPos = Vector2D{BARBUF.x - 2 * BUTTONS_PAD - b.size - offset, (BARBUF.y - b.size) / 2.0}.floor();
|
Vector2D currentPos = Vector2D{BARBUF.x - 2 * *PBARBUTTONPADDING - b.size - offset, (BARBUF.y - b.size) / 2.0}.floor();
|
||||||
|
|
||||||
if (VECINRECT(COORDS, currentPos.x, currentPos.y, currentPos.x + b.size + BUTTONS_PAD, currentPos.y + b.size)) {
|
if (VECINRECT(COORDS, currentPos.x, currentPos.y, currentPos.x + b.size + *PBARBUTTONPADDING, currentPos.y + b.size)) {
|
||||||
// hit on close
|
// hit on close
|
||||||
g_pKeybindManager->m_mDispatchers["exec"](b.cmd);
|
g_pKeybindManager->m_mDispatchers["exec"](b.cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += BUTTONS_PAD + b.size;
|
offset += *PBARBUTTONPADDING + b.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bDragPending = true;
|
m_bDragPending = true;
|
||||||
|
@ -182,26 +180,28 @@ void CHyprBar::renderText(CTexture& out, const std::string& text, const CColor&
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) {
|
void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) {
|
||||||
static auto* const PCOLOR = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:col.text")->intValue;
|
static auto* const PCOLOR = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:col.text")->intValue;
|
||||||
static auto* const PSIZE = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_size")->intValue;
|
static auto* const PSIZE = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_size")->intValue;
|
||||||
static auto* const PFONT = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_font")->strValue;
|
static auto* const PFONT = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_font")->strValue;
|
||||||
static auto* const PALIGN = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_align")->strValue;
|
static auto* const PALIGN = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_align")->strValue;
|
||||||
static auto* const PALIGNBUTTONS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->strValue;
|
static auto* const PALIGNBUTTONS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->strValue;
|
||||||
|
static auto* const PBARPADDING = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_padding")->intValue;
|
||||||
|
static auto* const PBARBUTTONPADDING = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->intValue;
|
||||||
|
|
||||||
const bool BUTTONSRIGHT = *PALIGNBUTTONS != "left";
|
const bool BUTTONSRIGHT = *PALIGNBUTTONS != "left";
|
||||||
|
|
||||||
const auto BORDERSIZE = m_pWindow->getRealBorderSize();
|
const auto BORDERSIZE = m_pWindow->getRealBorderSize();
|
||||||
|
|
||||||
float buttonSizes = BUTTONS_PAD;
|
float buttonSizes = *PBARBUTTONPADDING;
|
||||||
for (auto& b : g_pGlobalState->buttons) {
|
for (auto& b : g_pGlobalState->buttons) {
|
||||||
buttonSizes += b.size + BUTTONS_PAD;
|
buttonSizes += b.size + *PBARBUTTONPADDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto scaledSize = *PSIZE * scale;
|
const auto scaledSize = *PSIZE * scale;
|
||||||
const auto scaledBorderSize = BORDERSIZE * scale;
|
const auto scaledBorderSize = BORDERSIZE * scale;
|
||||||
const auto scaledButtonsSize = buttonSizes * scale;
|
const auto scaledButtonsSize = buttonSizes * scale;
|
||||||
const auto scaledButtonsPad = BUTTONS_PAD * scale;
|
const auto scaledButtonsPad = *PBARBUTTONPADDING * scale;
|
||||||
const auto scaledBarPadding = BAR_PADDING * scale;
|
const auto scaledBarPadding = *PBARPADDING * scale;
|
||||||
|
|
||||||
const CColor COLOR = *PCOLOR;
|
const CColor COLOR = *PCOLOR;
|
||||||
|
|
||||||
|
@ -264,7 +264,11 @@ void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
|
void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
|
||||||
const auto scaledButtonsPad = BUTTONS_PAD * scale;
|
static auto* const PBARBUTTONPADDING = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->intValue;
|
||||||
|
static auto* const PBARPADDING = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_padding")->intValue;
|
||||||
|
|
||||||
|
const auto scaledButtonsPad = *PBARBUTTONPADDING * scale;
|
||||||
|
const auto scaledBarPadding = *PBARPADDING * scale;
|
||||||
|
|
||||||
const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y);
|
const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y);
|
||||||
const auto CAIRO = cairo_create(CAIROSURFACE);
|
const auto CAIRO = cairo_create(CAIROSURFACE);
|
||||||
|
@ -280,16 +284,17 @@ void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
|
||||||
cairo_restore(CAIRO);
|
cairo_restore(CAIRO);
|
||||||
|
|
||||||
// draw buttons
|
// draw buttons
|
||||||
int offset = scaledButtonsPad;
|
int offset = scaledBarPadding;
|
||||||
|
|
||||||
auto drawButton = [&](SHyprButton& button) -> void {
|
auto drawButton = [&](SHyprButton& button) -> void {
|
||||||
const auto scaledButtonSize = button.size * scale;
|
const auto scaledButtonSize = button.size * scale;
|
||||||
|
|
||||||
Vector2D currentPos = Vector2D{BUTTONSRIGHT ? bufferSize.x - offset - scaledButtonSize : offset + scaledButtonSize, (bufferSize.y - scaledButtonSize) / 2.0}.floor();
|
Vector2D currentPos =
|
||||||
|
Vector2D{BUTTONSRIGHT ? bufferSize.x - offset - scaledButtonSize / 2.0 : offset + scaledButtonSize / 2.0, (bufferSize.y - scaledButtonSize) / 2.0}.floor();
|
||||||
|
|
||||||
const int X = currentPos.x;
|
const int X = currentPos.x;
|
||||||
const int Y = currentPos.y;
|
const int Y = currentPos.y;
|
||||||
const int RADIUS = static_cast<int>(std::ceil(scaledButtonSize / 2.0));
|
const int RADIUS = static_cast<int>(std::ceil(scaledButtonSize / 2.0));
|
||||||
|
|
||||||
cairo_set_source_rgba(CAIRO, button.col.r, button.col.g, button.col.b, button.col.a);
|
cairo_set_source_rgba(CAIRO, button.col.r, button.col.g, button.col.b, button.col.a);
|
||||||
cairo_arc(CAIRO, X, Y + RADIUS, RADIUS, 0, 2 * M_PI);
|
cairo_arc(CAIRO, X, Y + RADIUS, RADIUS, 0, 2 * M_PI);
|
||||||
|
@ -322,8 +327,12 @@ void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprBar::renderBarButtonsText(CBox* barBox, const float scale, const float a) {
|
void CHyprBar::renderBarButtonsText(CBox* barBox, const float scale, const float a) {
|
||||||
const auto scaledButtonsPad = BUTTONS_PAD * scale;
|
static auto* const PBARBUTTONPADDING = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->intValue;
|
||||||
int offset = scaledButtonsPad;
|
static auto* const PBARPADDING = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_padding")->intValue;
|
||||||
|
|
||||||
|
const auto scaledButtonsPad = *PBARBUTTONPADDING * scale;
|
||||||
|
const auto scaledBarPad = *PBARPADDING * scale;
|
||||||
|
int offset = scaledBarPad;
|
||||||
|
|
||||||
static auto* const PALIGNBUTTONS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->strValue;
|
static auto* const PALIGNBUTTONS = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->strValue;
|
||||||
|
|
||||||
|
@ -344,8 +353,8 @@ void CHyprBar::renderBarButtonsText(CBox* barBox, const float scale, const float
|
||||||
if (button.iconTex.m_iTexID == 0)
|
if (button.iconTex.m_iTexID == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CBox pos = {barBox->x + (BUTTONSRIGHT ? barBox->width - offset - scaledButtonSize * 1.5 : offset + scaledButtonSize * 0.5),
|
CBox pos = {barBox->x + (BUTTONSRIGHT ? barBox->width - offset - scaledButtonSize : offset), barBox->y + (barBox->height - scaledButtonSize) / 2.0, scaledButtonSize,
|
||||||
barBox->y + (barBox->height - scaledButtonSize) / 2.0, scaledButtonSize, scaledButtonSize};
|
scaledButtonSize};
|
||||||
|
|
||||||
g_pHyprOpenGL->renderTexture(button.iconTex, &pos, a);
|
g_pHyprOpenGL->renderTexture(button.iconTex, &pos, a);
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,8 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
||||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_part_of_window", SConfigValue{.intValue = 1});
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_part_of_window", SConfigValue{.intValue = 1});
|
||||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_precedence_over_border", SConfigValue{.intValue = 0});
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_precedence_over_border", SConfigValue{.intValue = 0});
|
||||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment", SConfigValue{.strValue = "right"});
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment", SConfigValue{.strValue = "right"});
|
||||||
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_padding", SConfigValue{.intValue = 7});
|
||||||
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding", SConfigValue{.intValue = 5});
|
||||||
|
|
||||||
HyprlandAPI::addConfigKeyword(PHANDLE, "hyprbars-button", [&](const std::string& k, const std::string& v) { onNewButton(k, v); });
|
HyprlandAPI::addConfigKeyword(PHANDLE, "hyprbars-button", [&](const std::string& k, const std::string& v) { onNewButton(k, v); });
|
||||||
HyprlandAPI::registerCallbackDynamic(PHANDLE, "preConfigReload", [&](void* self, SCallbackInfo& info, std::any data) { onPreConfigReload(); });
|
HyprlandAPI::registerCallbackDynamic(PHANDLE, "preConfigReload", [&](void* self, SCallbackInfo& info, std::any data) { onPreConfigReload(); });
|
||||||
|
|
Loading…
Reference in a new issue