From 8a5c52d2db563d9d2e5e0baea402beb084ea8f9a Mon Sep 17 00:00:00 2001 From: Raphael Robatsch Date: Mon, 25 Oct 2021 21:54:14 +0200 Subject: [PATCH] receive selected/layout/title --- .../net-tapesoftware-dwl-wm-unstable-v1.xml | 26 ++++++++++++++++++- src/bar.cpp | 18 ++++++------- src/bar.hpp | 7 ++++- src/common.hpp | 1 + src/config.hpp | 6 ++--- src/main.cpp | 16 ++++++++++++ 6 files changed, 59 insertions(+), 15 deletions(-) diff --git a/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml b/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml index 2c43631..ff53fbf 100644 --- a/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml +++ b/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml @@ -49,6 +49,12 @@ + + + + + + @@ -66,8 +72,14 @@ + + + + + + - + @@ -75,6 +87,18 @@ + + + + + + + + + + + + diff --git a/src/bar.cpp b/src/bar.cpp index 6f13a0a..896b3bd 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -55,9 +55,6 @@ void Bar::create(wl_output *output) zwlr_layer_surface_v1_set_size(_layerSurface.get(), 0, barSize); zwlr_layer_surface_v1_set_exclusive_zone(_layerSurface.get(), barSize); wl_surface_commit(_surface.get()); - - _windowTitle = "Window title"; - _status = "Status"; } void Bar::click(int x, int) @@ -87,10 +84,10 @@ void Bar::setTag(int tag, znet_tapesoftware_dwl_wm_monitor_v1_tag_state state, i t.focusedClient = focusedClient; } -void Bar::setStatus(const QString &status) -{ - _status = status; -} +void Bar::setSelected(bool selected) { _selected = selected; } +void Bar::setLayout(int layout) { _layout = layout; } +void Bar::setTitle(const char *title) { _title = title; } +void Bar::setStatus(const QString &status) { _status = status; } void Bar::layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height) { @@ -114,8 +111,9 @@ void Bar::render() painter.setFont(font); renderTags(); - setColorScheme(colorActive); - renderText(_windowTitle); + setColorScheme(_selected ? colorActive : colorInactive); + renderText(layoutNames[_layout]); + renderText(_title); renderStatus(); _painter = nullptr; @@ -161,7 +159,7 @@ void Bar::renderText(const QString &text) void Bar::renderStatus() { _painter->fillRect(_x, 0, _bufs->width-_x, _bufs->height, _painter->brush()); - auto size = textWidth(_status) + paddingX*2; + auto size = textWidth(_status) + paddingX; _x = _bufs->width - size; _painter->drawText(paddingX+_x, _textY, _status); _x = _bufs->width; diff --git a/src/bar.hpp b/src/bar.hpp index ad766de..00d156d 100644 --- a/src/bar.hpp +++ b/src/bar.hpp @@ -32,7 +32,9 @@ class Bar { bool _invalid {false}; std::vector _tags; - QString _windowTitle; + int _layout; + bool _selected; + QString _title; QString _status; void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height); @@ -46,7 +48,10 @@ public: Bar(); const wl_surface* surface() const; void create(wl_output *output); + void setSelected(bool selected); void setTag(int tag, znet_tapesoftware_dwl_wm_monitor_v1_tag_state state, int numClients, int focusedClient); + void setLayout(int layout); + void setTitle(const char *title); void setStatus(const QString &status); void invalidate(); void click(int x, int y); diff --git a/src/common.hpp b/src/common.hpp index a45bd5f..1b3c72c 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -15,6 +15,7 @@ extern wl_compositor *compositor; extern wl_shm *shm; extern zwlr_layer_shell_v1 *wlrLayerShell; extern std::vector tagNames; +extern std::vector layoutNames; struct ColorScheme { QColor fg, bg; diff --git a/src/config.hpp b/src/config.hpp index c9b5799..fc8ed32 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -11,8 +11,8 @@ constexpr int paddingY = 3; constexpr const char *fontFamily = "Source Sans Pro"; constexpr int fontSizePt = 12; -constexpr bool fontBold = true; +constexpr bool fontBold = false; -constexpr ColorScheme colorInactive = {QColor(255, 255, 255), QColor(0, 0, 0)}; -constexpr ColorScheme colorActive = {QColor(255, 255, 255), QColor(0, 0, 255)}; +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}; diff --git a/src/main.cpp b/src/main.cpp index 8814903..471ac70 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,6 +43,7 @@ wl_shm *shm; zwlr_layer_shell_v1 *wlrLayerShell; znet_tapesoftware_dwl_wm_v1 *dwlWm; std::vector tagNames; +std::vector layoutNames; static bool ready; static std::vector monitors; static QString lastStatus; @@ -131,13 +132,28 @@ static const struct znet_tapesoftware_dwl_wm_v1_listener dwlWmListener = { .tag = [](void*, znet_tapesoftware_dwl_wm_v1*, const char *name) { tagNames.push_back(name); }, + .layout = [](void*, znet_tapesoftware_dwl_wm_v1*, const char *name) { + layoutNames.push_back(name); + }, }; static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorListener { + .selected = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, int32_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) { 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) { + auto mon = static_cast(mv); + mon->bar->setLayout(layout); + }, + .title = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, const char *title) { + auto mon = static_cast(mv); + mon->bar->setTitle(title); + }, .frame = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*) { auto mon = static_cast(mv); if (mon->created) {