mirror of
https://github.com/hyprwm/hyprland-plugins.git
synced 2024-11-22 02:35:57 +01:00
Add dragging support
This commit is contained in:
parent
5f48afd655
commit
18ebaa7189
2 changed files with 39 additions and 1 deletions
|
@ -19,6 +19,8 @@ CHyprBar::CHyprBar(CWindow* pWindow) {
|
|||
|
||||
m_pMouseButtonCallback =
|
||||
HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseButton", [&](void* self, std::any param) { onMouseDown(std::any_cast<wlr_pointer_button_event*>(param)); });
|
||||
|
||||
m_pMouseMoveCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseMove", [&](void* self, std::any param) { onMouseMove(std::any_cast<Vector2D>(param)); });
|
||||
}
|
||||
|
||||
CHyprBar::~CHyprBar() {
|
||||
|
@ -26,6 +28,10 @@ CHyprBar::~CHyprBar() {
|
|||
HyprlandAPI::unregisterCallback(PHANDLE, m_pMouseButtonCallback);
|
||||
}
|
||||
|
||||
bool CHyprBar::allowsInput() {
|
||||
return true;
|
||||
}
|
||||
|
||||
SWindowDecorationExtents CHyprBar::getWindowDecorationExtents() {
|
||||
return m_seExtents;
|
||||
}
|
||||
|
@ -36,8 +42,16 @@ void CHyprBar::onMouseDown(wlr_pointer_button_event* e) {
|
|||
|
||||
const auto COORDS = cursorRelativeToBar();
|
||||
|
||||
if (e->state != WLR_BUTTON_PRESSED)
|
||||
if (e->state != WLR_BUTTON_PRESSED) {
|
||||
if (m_bDraggingThis) {
|
||||
g_pKeybindManager->m_mDispatchers["mouse"]("0movewindow");
|
||||
m_bDraggingThis = false;
|
||||
|
||||
Debug::log(LOG, "[hyprbars] Dragging ended on %x", m_pWindow);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// check if on a button
|
||||
static auto* const PBORDERSIZE = &HyprlandAPI::getConfigValue(PHANDLE, "general:border_size")->intValue;
|
||||
|
@ -61,6 +75,23 @@ void CHyprBar::onMouseDown(wlr_pointer_button_event* e) {
|
|||
g_pKeybindManager->m_mDispatchers["fullscreen"]("1");
|
||||
return;
|
||||
}
|
||||
|
||||
// if we do this here the handler later will remove our mouse bind
|
||||
m_bDragPending = true;
|
||||
}
|
||||
|
||||
void CHyprBar::onMouseMove(Vector2D coords) {
|
||||
static auto* const PHEIGHT = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->intValue;
|
||||
|
||||
if (m_bDragPending) {
|
||||
m_bDragPending = false;
|
||||
g_pKeybindManager->m_mDispatchers["mouse"]("1movewindow");
|
||||
m_bDraggingThis = true;
|
||||
|
||||
Debug::log(LOG, "[hyprbars] Dragging initiated on %x", m_pWindow);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CHyprBar::renderBarTitle(const Vector2D& bufferSize) {
|
||||
|
|
|
@ -23,6 +23,8 @@ class CHyprBar : public IHyprWindowDecoration {
|
|||
|
||||
virtual SWindowDecorationExtents getWindowDecorationReservedArea();
|
||||
|
||||
virtual bool allowsInput();
|
||||
|
||||
private:
|
||||
SWindowDecorationExtents m_seExtents;
|
||||
|
||||
|
@ -41,8 +43,13 @@ class CHyprBar : public IHyprWindowDecoration {
|
|||
void renderBarTitle(const Vector2D& bufferSize);
|
||||
void renderBarButtons(const Vector2D& bufferSize);
|
||||
void onMouseDown(wlr_pointer_button_event* e);
|
||||
void onMouseMove(Vector2D coords);
|
||||
|
||||
HOOK_CALLBACK_FN* m_pMouseButtonCallback;
|
||||
HOOK_CALLBACK_FN* m_pMouseMoveCallback;
|
||||
|
||||
std::string m_szLastTitle;
|
||||
|
||||
bool m_bDraggingThis = false;
|
||||
bool m_bDragPending = false;
|
||||
};
|
Loading…
Reference in a new issue