mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-07 21:05:58 +01:00
Draw the drag icon
This commit is contained in:
parent
2ca834479f
commit
3e614f2c1e
10 changed files with 133 additions and 2 deletions
|
@ -108,6 +108,7 @@ void CCompositor::initAllSignals() {
|
||||||
addWLSignal(&m_sSeat.seat->events.request_set_cursor, &Events::listen_requestMouse, &m_sSeat, "Seat");
|
addWLSignal(&m_sSeat.seat->events.request_set_cursor, &Events::listen_requestMouse, &m_sSeat, "Seat");
|
||||||
addWLSignal(&m_sSeat.seat->events.request_set_selection, &Events::listen_requestSetSel, &m_sSeat, "Seat");
|
addWLSignal(&m_sSeat.seat->events.request_set_selection, &Events::listen_requestSetSel, &m_sSeat, "Seat");
|
||||||
addWLSignal(&m_sSeat.seat->events.request_start_drag, &Events::listen_requestDrag, &m_sSeat, "Seat");
|
addWLSignal(&m_sSeat.seat->events.request_start_drag, &Events::listen_requestDrag, &m_sSeat, "Seat");
|
||||||
|
addWLSignal(&m_sSeat.seat->events.start_drag, &Events::listen_startDrag, &m_sSeat, "Seat");
|
||||||
addWLSignal(&m_sWLRLayerShell->events.new_surface, &Events::listen_newLayerSurface, m_sWLRLayerShell, "LayerShell");
|
addWLSignal(&m_sWLRLayerShell->events.new_surface, &Events::listen_newLayerSurface, m_sWLRLayerShell, "LayerShell");
|
||||||
addWLSignal(&m_sWLROutputLayout->events.change, &Events::listen_change, m_sWLROutputLayout, "OutputLayout");
|
addWLSignal(&m_sWLROutputLayout->events.change, &Events::listen_change, m_sWLROutputLayout, "OutputLayout");
|
||||||
addWLSignal(&m_sWLROutputMgr->events.apply, &Events::listen_outputMgrApply, m_sWLROutputMgr, "OutputMgr");
|
addWLSignal(&m_sWLROutputMgr->events.apply, &Events::listen_outputMgrApply, m_sWLROutputMgr, "OutputMgr");
|
||||||
|
|
|
@ -73,7 +73,7 @@ std::string layersRequest() {
|
||||||
result += getFormat("\tLayer level %i:\n", layerLevel);
|
result += getFormat("\tLayer level %i:\n", layerLevel);
|
||||||
|
|
||||||
for (auto& layer : level) {
|
for (auto& layer : level) {
|
||||||
result += getFormat("\t\tLayer %x -> %s: xywh: %i %i %i %i\n", layer, (layer->layerSurface ? layer->layerSurface->_namespace : "null"), layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height);
|
result += getFormat("\t\tLayer %x: xywh: %i %i %i %i\n", layer, layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
layerLevel++;
|
layerLevel++;
|
||||||
|
|
|
@ -87,6 +87,12 @@ namespace Events {
|
||||||
// Drag & Drop
|
// Drag & Drop
|
||||||
LISTENER(requestDrag);
|
LISTENER(requestDrag);
|
||||||
LISTENER(startDrag);
|
LISTENER(startDrag);
|
||||||
|
DYNLISTENFUNC(destroyDrag);
|
||||||
|
|
||||||
|
DYNLISTENFUNC(mapDragIcon);
|
||||||
|
DYNLISTENFUNC(unmapDragIcon);
|
||||||
|
DYNLISTENFUNC(destroyDragIcon);
|
||||||
|
DYNLISTENFUNC(commitDragIcon);
|
||||||
|
|
||||||
// Inhibit
|
// Inhibit
|
||||||
LISTENER(InhibitActivate);
|
LISTENER(InhibitActivate);
|
||||||
|
|
|
@ -78,7 +78,67 @@ void Events::listener_requestDrag(wl_listener* listener, void* data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::listener_startDrag(wl_listener* listener, void* data) {
|
void Events::listener_startDrag(wl_listener* listener, void* data) {
|
||||||
// TODO: draw the drag icon
|
|
||||||
|
if (g_pInputManager->m_sDrag.drag)
|
||||||
|
return; // don't handle multiple drags
|
||||||
|
|
||||||
|
g_pInputManager->m_sDrag.drag = (wlr_drag*)data;
|
||||||
|
|
||||||
|
wlr_drag* wlrDrag = (wlr_drag*)data;
|
||||||
|
|
||||||
|
Debug::log(LOG, "Started drag %x", wlrDrag);
|
||||||
|
|
||||||
|
wlrDrag->data = data;
|
||||||
|
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_destroy.initCallback(&wlrDrag->events.destroy, &Events::listener_destroyDrag, &g_pInputManager->m_sDrag, "Drag");
|
||||||
|
|
||||||
|
if (wlrDrag->icon) {
|
||||||
|
Debug::log(LOG, "Drag started with an icon %x", wlrDrag->icon);
|
||||||
|
|
||||||
|
g_pInputManager->m_sDrag.dragIcon = wlrDrag->icon;
|
||||||
|
wlrDrag->icon->data = g_pInputManager->m_sDrag.dragIcon;
|
||||||
|
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_mapIcon.initCallback(&wlrDrag->icon->events.map, &Events::listener_mapDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_unmapIcon.initCallback(&wlrDrag->icon->events.unmap, &Events::listener_unmapDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_destroyIcon.initCallback(&wlrDrag->icon->events.destroy, &Events::listener_destroyDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_commitIcon.initCallback(&wlrDrag->icon->surface->events.commit, &Events::listener_commitDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Events::listener_destroyDrag(void* owner, void* data) {
|
||||||
|
Debug::log(LOG, "Drag destroyed.");
|
||||||
|
|
||||||
|
g_pInputManager->m_sDrag.drag = nullptr;
|
||||||
|
g_pInputManager->m_sDrag.dragIcon = nullptr;
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_destroy.removeCallback();
|
||||||
|
|
||||||
|
g_pInputManager->refocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Events::listener_mapDragIcon(void* owner, void* data) {
|
||||||
|
Debug::log(LOG, "Drag icon mapped.");
|
||||||
|
g_pInputManager->m_sDrag.iconMapped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Events::listener_unmapDragIcon(void* owner, void* data) {
|
||||||
|
Debug::log(LOG, "Drag icon unmapped.");
|
||||||
|
g_pInputManager->m_sDrag.iconMapped = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Events::listener_destroyDragIcon(void* owner, void* data) {
|
||||||
|
Debug::log(LOG, "Drag icon destroyed.");
|
||||||
|
|
||||||
|
g_pInputManager->m_sDrag.dragIcon = nullptr;
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_commitIcon.removeCallback();
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_destroyIcon.removeCallback();
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_mapIcon.removeCallback();
|
||||||
|
g_pInputManager->m_sDrag.hyprListener_unmapIcon.removeCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Events::listener_commitDragIcon(void* owner, void* data) {
|
||||||
|
g_pInputManager->updateDragIcon();
|
||||||
|
|
||||||
|
Debug::log(LOG, "Drag icon committed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::listener_InhibitActivate(wl_listener* listener, void* data) {
|
void Events::listener_InhibitActivate(wl_listener* listener, void* data) {
|
||||||
|
|
|
@ -78,3 +78,22 @@ struct SSeat {
|
||||||
wlr_seat* seat = nullptr;
|
wlr_seat* seat = nullptr;
|
||||||
wl_client* exclusiveClient = nullptr;
|
wl_client* exclusiveClient = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SDrag {
|
||||||
|
wlr_drag* drag = nullptr;
|
||||||
|
|
||||||
|
DYNLISTENER(destroy);
|
||||||
|
|
||||||
|
// Icon
|
||||||
|
|
||||||
|
bool iconMapped = false;
|
||||||
|
|
||||||
|
wlr_drag_icon* dragIcon = nullptr;
|
||||||
|
|
||||||
|
Vector2D pos;
|
||||||
|
|
||||||
|
DYNLISTENER(destroyIcon);
|
||||||
|
DYNLISTENER(mapIcon);
|
||||||
|
DYNLISTENER(unmapIcon);
|
||||||
|
DYNLISTENER(commitIcon);
|
||||||
|
};
|
|
@ -1,6 +1,7 @@
|
||||||
#include "WLListener.hpp"
|
#include "WLListener.hpp"
|
||||||
#include "MiscFunctions.hpp"
|
#include "MiscFunctions.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "../debug/Log.hpp"
|
||||||
|
|
||||||
void handleWrapped(wl_listener* listener, void* data) {
|
void handleWrapped(wl_listener* listener, void* data) {
|
||||||
CHyprWLListener* pListener = wl_container_of(listener, pListener, m_sListener);
|
CHyprWLListener* pListener = wl_container_of(listener, pListener, m_sListener);
|
||||||
|
@ -22,6 +23,7 @@ CHyprWLListener::~CHyprWLListener() {
|
||||||
|
|
||||||
void CHyprWLListener::removeCallback() {
|
void CHyprWLListener::removeCallback() {
|
||||||
if (m_bIsConnected) {
|
if (m_bIsConnected) {
|
||||||
|
Debug::log(LOG, "Callback %x -> %x, %s removed.", m_pCallback, m_pOwner, m_szAuthor.c_str());
|
||||||
wl_list_remove(&m_sListener.link);
|
wl_list_remove(&m_sListener.link);
|
||||||
wl_list_init(&m_sListener.link);
|
wl_list_init(&m_sListener.link);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,18 @@ void CInputManager::onMouseWarp(wlr_pointer_motion_absolute_event* e) {
|
||||||
|
|
||||||
void CInputManager::mouseMoveUnified(uint32_t time) {
|
void CInputManager::mouseMoveUnified(uint32_t time) {
|
||||||
|
|
||||||
|
// update stuff
|
||||||
|
updateDragIcon();
|
||||||
|
|
||||||
|
|
||||||
|
// focus
|
||||||
wlr_surface* foundSurface = nullptr;
|
wlr_surface* foundSurface = nullptr;
|
||||||
Vector2D mouseCoords = getMouseCoordsInternal();
|
Vector2D mouseCoords = getMouseCoordsInternal();
|
||||||
|
|
||||||
const auto PMONITOR = g_pCompositor->getMonitorFromCursor();
|
const auto PMONITOR = g_pCompositor->getMonitorFromCursor();
|
||||||
if (PMONITOR)
|
if (PMONITOR)
|
||||||
g_pCompositor->m_pLastMonitor = PMONITOR;
|
g_pCompositor->m_pLastMonitor = PMONITOR;
|
||||||
|
|
||||||
Vector2D surfaceCoords;
|
Vector2D surfaceCoords;
|
||||||
Vector2D surfacePos = Vector2D(-1337, -1337);
|
Vector2D surfacePos = Vector2D(-1337, -1337);
|
||||||
|
|
||||||
|
@ -256,3 +263,18 @@ void CInputManager::onKeyboardMod(void* data, SKeyboard* pKeyboard) {
|
||||||
void CInputManager::refocus() {
|
void CInputManager::refocus() {
|
||||||
mouseMoveUnified(0);
|
mouseMoveUnified(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInputManager::updateDragIcon() {
|
||||||
|
if (!g_pInputManager->m_sDrag.dragIcon)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (g_pInputManager->m_sDrag.dragIcon->drag->grab_type) {
|
||||||
|
case WLR_DRAG_GRAB_KEYBOARD:
|
||||||
|
break;
|
||||||
|
case WLR_DRAG_GRAB_KEYBOARD_POINTER:
|
||||||
|
g_pInputManager->m_sDrag.pos = g_pInputManager->getMouseCoordsInternal();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,11 +24,15 @@ public:
|
||||||
|
|
||||||
void setKeyboardLayout();
|
void setKeyboardLayout();
|
||||||
|
|
||||||
|
void updateDragIcon();
|
||||||
|
|
||||||
|
|
||||||
// for dragging floating windows
|
// for dragging floating windows
|
||||||
CWindow* currentlyDraggedWindow = nullptr;
|
CWindow* currentlyDraggedWindow = nullptr;
|
||||||
int dragButton = -1;
|
int dragButton = -1;
|
||||||
|
|
||||||
|
SDrag m_sDrag;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::list<SKeyboard> m_lKeyboards;
|
std::list<SKeyboard> m_lKeyboards;
|
||||||
|
|
|
@ -78,6 +78,8 @@ void CHyprRenderer::renderWorkspaceWithFullscreenWindow(SMonitor* pMonitor, SWor
|
||||||
|
|
||||||
renderWindow(&w, pMonitor, time, true);
|
renderWindow(&w, pMonitor, time, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderDragIcon(pMonitor, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprRenderer::renderWindow(CWindow* pWindow, SMonitor* pMonitor, timespec* time, bool decorate) {
|
void CHyprRenderer::renderWindow(CWindow* pWindow, SMonitor* pMonitor, timespec* time, bool decorate) {
|
||||||
|
@ -167,6 +169,8 @@ void CHyprRenderer::renderAllClientsForMonitor(const int& ID, timespec* time) {
|
||||||
SRenderData renderdata = {PMONITOR->output, time, ls->geometry.x, ls->geometry.y};
|
SRenderData renderdata = {PMONITOR->output, time, ls->geometry.x, ls->geometry.y};
|
||||||
wlr_surface_for_each_surface(ls->layerSurface->surface, renderSurface, &renderdata);
|
wlr_surface_for_each_surface(ls->layerSurface->surface, renderSurface, &renderdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderDragIcon(PMONITOR, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprRenderer::outputMgrApplyTest(wlr_output_configuration_v1* config, bool test) {
|
void CHyprRenderer::outputMgrApplyTest(wlr_output_configuration_v1* config, bool test) {
|
||||||
|
@ -462,3 +466,15 @@ void CHyprRenderer::damageSurface(SMonitor* pMonitor, double x, double y, wlr_su
|
||||||
|
|
||||||
wlr_surface_for_each_surface(pSurface, damageSurfaceIter, &renderData);
|
wlr_surface_for_each_surface(pSurface, damageSurfaceIter, &renderData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CHyprRenderer::renderDragIcon(SMonitor* pMonitor, timespec* time) {
|
||||||
|
if (!(g_pInputManager->m_sDrag.dragIcon && g_pInputManager->m_sDrag.iconMapped && g_pInputManager->m_sDrag.dragIcon->surface))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SRenderData renderdata = {pMonitor->output, time, g_pInputManager->m_sDrag.pos.x, g_pInputManager->m_sDrag.pos.y};
|
||||||
|
renderdata.surface = g_pInputManager->m_sDrag.dragIcon->surface;
|
||||||
|
renderdata.w = g_pInputManager->m_sDrag.dragIcon->surface->current.width;
|
||||||
|
renderdata.h = g_pInputManager->m_sDrag.dragIcon->surface->current.height;
|
||||||
|
|
||||||
|
wlr_surface_for_each_surface(g_pInputManager->m_sDrag.dragIcon->surface, renderSurface, &renderdata);
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ private:
|
||||||
void drawBorderForWindow(CWindow*, SMonitor*);
|
void drawBorderForWindow(CWindow*, SMonitor*);
|
||||||
void renderWorkspaceWithFullscreenWindow(SMonitor*, SWorkspace*, timespec*);
|
void renderWorkspaceWithFullscreenWindow(SMonitor*, SWorkspace*, timespec*);
|
||||||
void renderWindow(CWindow*, SMonitor*, timespec*, bool);
|
void renderWindow(CWindow*, SMonitor*, timespec*, bool);
|
||||||
|
void renderDragIcon(SMonitor*, timespec*);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CHyprRenderer> g_pHyprRenderer;
|
inline std::unique_ptr<CHyprRenderer> g_pHyprRenderer;
|
||||||
|
|
Loading…
Reference in a new issue