hyprland-plugins/hyprbars/barDeco.hpp

120 lines
4.6 KiB
C++
Raw Normal View History

2023-02-28 20:30:51 +00:00
#pragma once
#define WLR_USE_UNSTABLE
2023-05-01 02:57:48 +01:00
#include <hyprland/src/render/decorations/IHyprWindowDecoration.hpp>
#include <hyprland/src/render/OpenGL.hpp>
2024-05-14 22:40:06 +01:00
#include <hyprland/src/devices/IPointer.hpp>
#include <hyprland/src/devices/ITouch.hpp>
2025-11-19 20:07:46 +01:00
#include <hyprland/src/desktop/rule/windowRule/WindowRule.hpp>
#include <hyprland/src/helpers/AnimatedVariable.hpp>
#include <hyprland/src/helpers/time/Time.hpp>
2023-02-28 21:59:58 +00:00
#include "globals.hpp"
2023-02-28 20:30:51 +00:00
#define private public
#include <hyprland/src/managers/input/InputManager.hpp>
#undef private
2023-02-28 20:30:51 +00:00
class CHyprBar : public IHyprWindowDecoration {
public:
2024-04-27 13:03:46 +01:00
CHyprBar(PHLWINDOW);
2023-02-28 20:30:51 +00:00
virtual ~CHyprBar();
2023-11-11 14:39:46 +00:00
virtual SDecorationPositioningInfo getPositioningInfo();
2023-02-28 20:30:51 +00:00
2023-11-11 14:39:46 +00:00
virtual void onPositioningReply(const SDecorationPositioningReply& reply);
2023-02-28 20:30:51 +00:00
2024-10-31 11:18:29 +00:00
virtual void draw(PHLMONITOR, float const& a);
2023-02-28 20:30:51 +00:00
2023-11-11 14:39:46 +00:00
virtual eDecorationType getDecorationType();
2023-02-28 20:30:51 +00:00
2024-04-27 13:03:46 +01:00
virtual void updateWindow(PHLWINDOW);
2023-02-28 20:30:51 +00:00
2023-11-11 14:39:46 +00:00
virtual void damageEntire();
2023-02-28 20:30:51 +00:00
2023-11-11 14:39:46 +00:00
virtual eDecorationLayer getDecorationLayer();
2023-11-04 13:15:30 +00:00
2023-11-11 14:39:46 +00:00
virtual uint64_t getDecorationFlags();
2023-02-28 22:53:49 +00:00
2023-11-11 14:39:46 +00:00
bool m_bButtonsDirty = true;
virtual std::string getDisplayName();
2024-04-27 13:03:46 +01:00
PHLWINDOW getOwner();
void updateRules();
2025-01-24 01:30:43 +00:00
WP<CHyprBar> m_self;
2023-02-28 20:30:51 +00:00
private:
2024-12-04 09:58:09 -05:00
SBoxExtents m_seExtents;
2023-02-28 20:30:51 +00:00
2024-12-04 09:58:09 -05:00
PHLWINDOWREF m_pWindow;
2023-02-28 20:30:51 +00:00
2024-12-04 09:58:09 -05:00
CBox m_bAssignedBox;
2023-02-28 20:30:51 +00:00
2024-12-04 09:58:09 -05:00
SP<CTexture> m_pTextTex;
SP<CTexture> m_pButtonsTex;
2023-02-28 20:30:51 +00:00
2024-12-04 09:58:09 -05:00
bool m_bWindowSizeChanged = false;
2025-05-17 15:08:30 +02:00
bool m_hidden = false;
2024-12-04 09:58:09 -05:00
bool m_bTitleColorChanged = false;
bool m_bButtonHovered = false;
2025-05-17 15:08:30 +02:00
bool m_bLastEnabledState = false;
bool m_bWindowHasFocus = false;
2024-12-04 09:58:09 -05:00
std::optional<CHyprColor> m_bForcedBarColor;
std::optional<CHyprColor> m_bForcedTitleColor;
2023-02-28 21:17:46 +00:00
Time::steady_tp m_lastMouseDown = Time::steadyNow();
PHLANIMVAR<CHyprColor> m_cRealBarColor;
2024-12-04 09:58:09 -05:00
Vector2D cursorRelativeToBar();
2023-02-28 21:59:58 +00:00
2024-12-22 16:33:07 +00:00
void renderPass(PHLMONITOR, float const& a);
2024-12-04 09:58:09 -05:00
void renderBarTitle(const Vector2D& bufferSize, const float scale);
void renderText(SP<CTexture> out, const std::string& text, const CHyprColor& 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 damageOnButtonHover();
bool inputIsValid();
void onMouseButton(SCallbackInfo& info, IPointer::SButtonEvent e);
void onTouchDown(SCallbackInfo& info, ITouch::SDownEvent e);
2025-10-13 07:44:31 -04:00
void onTouchUp(SCallbackInfo& info, ITouch::SUpEvent e);
2024-12-04 09:58:09 -05:00
void onMouseMove(Vector2D coords);
void onTouchMove(SCallbackInfo& info, ITouch::SMotionEvent e);
void handleDownEvent(SCallbackInfo& info, std::optional<ITouch::SDownEvent> touchEvent);
void handleUpEvent(SCallbackInfo& info);
void handleMovement();
2025-05-17 15:08:30 +02:00
bool doButtonPress(Hyprlang::INT* const* PBARPADDING, Hyprlang::INT* const* PBARBUTTONPADDING, Hyprlang::INT* const* PHEIGHT, Vector2D COORDS, bool BUTTONSRIGHT);
2025-05-17 15:08:30 +02:00
CBox assignedBoxGlobal();
2023-02-28 21:59:58 +00:00
2025-05-17 15:08:30 +02:00
SP<HOOK_CALLBACK_FN> m_pMouseButtonCallback;
SP<HOOK_CALLBACK_FN> m_pTouchDownCallback;
SP<HOOK_CALLBACK_FN> m_pTouchUpCallback;
2025-05-17 15:08:30 +02:00
SP<HOOK_CALLBACK_FN> m_pTouchMoveCallback;
SP<HOOK_CALLBACK_FN> m_pMouseMoveCallback;
2023-02-28 21:59:58 +00:00
2025-05-17 15:08:30 +02:00
std::string m_szLastTitle;
2023-02-28 22:53:49 +00:00
2025-05-17 15:08:30 +02:00
bool m_bDraggingThis = false;
bool m_bTouchEv = false;
bool m_bDragPending = false;
bool m_bCancelledDown = false;
2025-10-13 07:44:31 -04:00
int m_touchId = 0;
// store hover state for buttons as a bitfield
unsigned int m_iButtonHoverState = 0;
// for dynamic updates
int m_iLastHeight = 0;
size_t getVisibleButtonCount(Hyprlang::INT* const* PBARBUTTONPADDING, Hyprlang::INT* const* PBARPADDING, const Vector2D& bufferSize, const float scale);
2024-12-22 16:33:07 +00:00
friend class CBarPassElement;
};