From 8c959d60a18ffc10522e9fd43ffef27543521359 Mon Sep 17 00:00:00 2001 From: Raphael Robatsch Date: Tue, 26 Oct 2021 11:40:46 +0200 Subject: [PATCH] click handling (without modifiers) --- .../net-tapesoftware-dwl-wm-unstable-v1.xml | 21 ++++++++-- src/bar.cpp | 41 +++++++++++++++---- src/bar.hpp | 8 ++-- src/common.hpp | 27 ++++++++++-- src/config.hpp | 8 ++++ src/main.cpp | 41 +++++++++++++------ 6 files changed, 115 insertions(+), 31 deletions(-) diff --git a/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml b/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml index ff53fbf..53bb910 100644 --- a/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml +++ b/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml @@ -75,22 +75,22 @@ - + - + - + - + @@ -103,5 +103,18 @@ + + + + + + + + + + + + + diff --git a/src/bar.cpp b/src/bar.cpp index 896b3bd..bd0b272 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -32,10 +32,11 @@ static QFontMetrics fontMetrics = QFontMetrics {font}; const wl_surface* Bar::surface() const { return _surface.get(); } -Bar::Bar() +Bar::Bar(Monitor *mon) { - for (auto tag : tagNames) { - _tags.push_back({ tag, ZNET_TAPESOFTWARE_DWL_WM_MONITOR_V1_TAG_STATE_NONE, 0, 0, 0 }); + _mon = mon; + for (auto i=0u; i tag->x) { - // todo toggle + Arg arg = {0}; + Arg *argp = nullptr; + Control control = Control::None; + if (x > _statusX) { + control = Control::StatusText; + } else if (x > _titleX) { + control = Control::WinTitle; + } else if (x > _layoutX) { + control = Control::LayoutSymbol; + } else for (auto tag = _tags.size()-1; tag >= 0; tag--) { + if (x > _tags[tag].x) { + control = Control::TagBar; + arg.ui = 1<height/2); for (auto ind = 0; ind < indicators; ind++) { if (ind == tag.focusedClient) { diff --git a/src/bar.hpp b/src/bar.hpp index 00d156d..2a137c1 100644 --- a/src/bar.hpp +++ b/src/bar.hpp @@ -13,22 +13,24 @@ #include "shm_buffer.hpp" struct Tag { - QString name; znet_tapesoftware_dwl_wm_monitor_v1_tag_state state; int numClients; int focusedClient; int x; }; +struct Monitor; class Bar { static const zwlr_layer_surface_v1_listener _layerSurfaceListener; static const wl_callback_listener _frameListener; wl_unique_ptr _surface; wl_unique_ptr _layerSurface; + Monitor *_mon; QPainter *_painter {nullptr}; std::optional _bufs; int _textY, _x; + int _statusX, _titleX, _layoutX; bool _invalid {false}; std::vector _tags; @@ -45,7 +47,7 @@ class Bar { int textWidth(const QString &text); void setColorScheme(const ColorScheme &scheme); public: - Bar(); + Bar(Monitor *mon); const wl_surface* surface() const; void create(wl_output *output); void setSelected(bool selected); @@ -54,5 +56,5 @@ public: void setTitle(const char *title); void setStatus(const QString &status); void invalidate(); - void click(int x, int y); + void click(int x, int y, int btn, unsigned int modifiers); }; diff --git a/src/common.hpp b/src/common.hpp index 1b3c72c..870784e 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -2,14 +2,26 @@ // See LICENSE file for copyright and license details. #pragma once -#include #include #include +#include +#include #include #include #include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "net-tapesoftware-dwl-wm-unstable-v1-client-protocol.h" +struct ColorScheme { + QColor fg, bg; +}; +union Arg { + int i; + unsigned int ui; + float f; + const void *v; +}; +struct Monitor; + extern wl_display *display; extern wl_compositor *compositor; extern wl_shm *shm; @@ -17,8 +29,17 @@ extern zwlr_layer_shell_v1 *wlrLayerShell; extern std::vector tagNames; extern std::vector layoutNames; -struct ColorScheme { - QColor fg, bg; +void toggleview(Monitor &m, const Arg &arg); +void view(Monitor &m, const Arg &arg); +void setlayout(Monitor &m, const Arg &arg); + +enum class Control { None, TagBar, LayoutSymbol, WinTitle, StatusText }; +struct Button { + Control control; + unsigned int modifiers; // todo xkbcommon + int btn; // + void (*func)(Monitor &mon, const Arg &arg); + const Arg arg; }; // wayland smart pointers diff --git a/src/config.hpp b/src/config.hpp index fc8ed32..103a07e 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -16,3 +16,11 @@ constexpr bool fontBold = false; constexpr ColorScheme colorInactive = {QColor(0xbb, 0xbb, 0xbb), QColor(0x22, 0x22, 0x22)}; constexpr ColorScheme colorActive = {QColor(0xee, 0xee, 0xee), QColor(0x00, 0x55, 0x77)}; constexpr ColorScheme colorUrgent = {colorActive.bg, colorActive.fg}; + +constexpr Button buttons[] = { + { Control::TagBar, 0, BTN_LEFT, toggleview, {0} }, + { Control::TagBar, 0, BTN_MIDDLE, view, {0} }, + //{ Control::TagBar, 0, BTN_RIGHT, tag, {0} }, + { Control::LayoutSymbol, 0, BTN_LEFT, setlayout, {.ui = 0} }, + { Control::LayoutSymbol, 0, BTN_RIGHT, setlayout, {.ui = 2} }, +}; diff --git a/src/main.cpp b/src/main.cpp index 471ac70..316a192 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ zwlr_layer_shell_v1 *wlrLayerShell; znet_tapesoftware_dwl_wm_v1 *dwlWm; std::vector tagNames; std::vector layoutNames; +static xdg_wm_base *xdgWmBase; static bool ready; static std::vector monitors; static QString lastStatus; @@ -53,7 +55,19 @@ static int statusFifoWriter {-1}; static QSocketNotifier *displayWriteNotifier; static bool quitting {false}; -static xdg_wm_base *xdgWmBase; +void toggleview(Monitor &m, const Arg &arg) +{ + znet_tapesoftware_dwl_wm_monitor_v1_set_tags(m.dwlMonitor.get(), arg.ui, 0); +} +void view(Monitor &m, const Arg &arg) +{ + znet_tapesoftware_dwl_wm_monitor_v1_set_tags(m.dwlMonitor.get(), arg.ui, 1); +} +void setlayout(Monitor &m, const Arg &arg) +{ + znet_tapesoftware_dwl_wm_monitor_v1_set_layout(m.dwlMonitor.get(), arg.ui); +} + static const struct xdg_wm_base_listener xdgWmBaseListener = { [](void*, xdg_wm_base *sender, uint32_t serial) { xdg_wm_base_pong(sender, serial); @@ -66,7 +80,7 @@ struct SeatState { wl_cursor_image *cursorImage; Bar *focusedBar; int x, y; - bool leftButtonClick; + std::vector btns; }; static SeatState seatState; static Bar* barFromSurface(const wl_surface *surface) @@ -92,17 +106,20 @@ static const struct wl_pointer_listener pointerListener = { seatState.y = wl_fixed_to_int(y); }, .button = [](void*, wl_pointer*, uint32_t, uint32_t, uint32_t button, uint32_t pressed) { - if (button == BTN_LEFT) { - seatState.leftButtonClick = pressed == WL_POINTER_BUTTON_STATE_PRESSED; + auto it = std::find(begin(seatState.btns), end(seatState.btns), button); + if (pressed == WL_POINTER_BUTTON_STATE_PRESSED && it == end(seatState.btns)) { + seatState.btns.push_back(button); + } else if (pressed == WL_POINTER_BUTTON_STATE_RELEASED && it != end(seatState.btns)) { + seatState.btns.erase(it); } }, .axis = [](void*, wl_pointer*, uint32_t, uint32_t, wl_fixed_t) { }, .frame = [](void*, wl_pointer*) { if (!seatState.focusedBar) return; - if (seatState.leftButtonClick) { - seatState.leftButtonClick = false; - seatState.focusedBar->click(seatState.x, seatState.y); + for (auto btn : seatState.btns) { + seatState.focusedBar->click(seatState.x, seatState.y, btn, 0); } + seatState.btns.clear(); }, .axis_source = [](void*, wl_pointer*, uint32_t) { }, .axis_stop = [](void*, wl_pointer*, uint32_t, uint32_t) { }, @@ -138,15 +155,15 @@ static const struct znet_tapesoftware_dwl_wm_v1_listener dwlWmListener = { }; static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorListener { - .selected = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, int32_t selected) { + .selected = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t selected) { auto mon = static_cast(mv); mon->bar->setSelected(selected); }, - .tag = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, int32_t tag, uint32_t state, int32_t numClients, int32_t focusedClient) { + .tag = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t tag, uint32_t state, uint32_t numClients, int32_t focusedClient) { auto mon = static_cast(mv); mon->bar->setTag(tag, static_cast(state), numClients, focusedClient); }, - .layout = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, int32_t layout) { + .layout = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t layout) { auto mon = static_cast(mv); mon->bar->setLayout(layout); }, @@ -160,13 +177,14 @@ static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorLis mon->bar->invalidate(); } else { mon->bar->create(mon->wlOutput.get()); + mon->created = true; } } }; static void setupMonitor(Monitor &monitor) { monitor.dwlMonitor.reset(znet_tapesoftware_dwl_wm_v1_get_monitor(dwlWm, monitor.wlOutput.get())); - monitor.bar.emplace(); + monitor.bar.emplace(&monitor); monitor.bar->setStatus(lastStatus); znet_tapesoftware_dwl_wm_monitor_v1_add_listener(monitor.dwlMonitor.get(), &dwlWmMonitorListener, &monitor); } @@ -255,7 +273,6 @@ struct HandleGlobalHelper { static void registryHandleGlobal(void*, wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { auto reg = HandleGlobalHelper { registry, name, interface }; - printf("got global: %s v%d\n", interface, version); if (reg.handle(compositor, wl_compositor_interface, 4)) return; if (reg.handle(shm, wl_shm_interface, 1)) return; if (reg.handle(wlrLayerShell, zwlr_layer_shell_v1_interface, 4)) return;