diff --git a/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml b/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml
index 7c957bc..2c43631 100644
--- a/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml
+++ b/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml
@@ -55,6 +55,12 @@
+
+
+
+
+
+
@@ -64,9 +70,9 @@
-
+
-
+
diff --git a/src/bar.cpp b/src/bar.cpp
index c61154e..6f13a0a 100644
--- a/src/bar.cpp
+++ b/src/bar.cpp
@@ -30,7 +30,16 @@ static QFont getFont()
static QFont font = getFont();
static QFontMetrics fontMetrics = QFontMetrics {font};
-Bar::Bar(const wl_output *output)
+const wl_surface* Bar::surface() const { return _surface.get(); }
+
+Bar::Bar()
+{
+ for (auto tag : tagNames) {
+ _tags.push_back({ tag, ZNET_TAPESOFTWARE_DWL_WM_MONITOR_V1_TAG_STATE_NONE, 0, 0, 0 });
+ }
+}
+
+void Bar::create(wl_output *output)
{
_surface.reset(wl_compositor_create_surface(compositor));
_layerSurface.reset(zwlr_layer_shell_v1_get_layer_surface(wlrLayerShell,
@@ -47,21 +56,15 @@ Bar::Bar(const wl_output *output)
zwlr_layer_surface_v1_set_exclusive_zone(_layerSurface.get(), barSize);
wl_surface_commit(_surface.get());
- for (auto tag : tagNames) {
- _tags.push_back({ tag, false });
- }
_windowTitle = "Window title";
_status = "Status";
}
-const wl_surface* Bar::surface() const { return _surface.get(); }
-
void Bar::click(int x, int)
{
for (auto tag=_tags.rbegin(); tag != _tags.rend(); tag++) {
if (x > tag->x) {
- tag->active = !tag->active;
- invalidate();
+ // todo toggle
return;
}
}
@@ -76,10 +79,17 @@ void Bar::invalidate()
wl_surface_commit(_surface.get());
}
+void Bar::setTag(int tag, znet_tapesoftware_dwl_wm_monitor_v1_tag_state state, int numClients, int focusedClient)
+{
+ auto& t = _tags[tag];
+ t.state = state;
+ t.numClients = numClients;
+ t.focusedClient = focusedClient;
+}
+
void Bar::setStatus(const QString &status)
{
_status = status;
- invalidate();
}
void Bar::layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height)
@@ -103,8 +113,6 @@ void Bar::render()
_x = 0;
painter.setFont(font);
- setColorScheme(colorActive);
- painter.fillRect(0, 0, img.width(), img.height(), painter.brush());
renderTags();
setColorScheme(colorActive);
renderText(_windowTitle);
@@ -128,8 +136,17 @@ void Bar::renderTags()
{
for (auto &tag : _tags) {
tag.x = _x;
- setColorScheme(tag.active ? colorActive : colorInactive);
+ setColorScheme(tag.state & ZNET_TAPESOFTWARE_DWL_WM_MONITOR_V1_TAG_STATE_URGENT ? colorUrgent
+ : tag.state & ZNET_TAPESOFTWARE_DWL_WM_MONITOR_V1_TAG_STATE_ACTIVE ? colorActive : colorInactive);
renderText(tag.name);
+ auto indicators = qMin(tag.numClients, _bufs->height/2);
+ for (auto ind = 0; ind < indicators; ind++) {
+ if (ind == tag.focusedClient) {
+ _painter->drawLine(tag.x, ind*2, tag.x+5, ind*2);
+ } else {
+ _painter->drawPoint(tag.x, ind*2);
+ }
+ }
}
}
@@ -143,9 +160,9 @@ 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;
_x = _bufs->width - size;
- _painter->fillRect(_x, 0, size, _bufs->height, _painter->brush());
_painter->drawText(paddingX+_x, _textY, _status);
_x = _bufs->width;
}
diff --git a/src/bar.hpp b/src/bar.hpp
index f904e2f..ad766de 100644
--- a/src/bar.hpp
+++ b/src/bar.hpp
@@ -14,7 +14,9 @@
struct Tag {
QString name;
- bool active;
+ znet_tapesoftware_dwl_wm_monitor_v1_tag_state state;
+ int numClients;
+ int focusedClient;
int x;
};
@@ -40,10 +42,12 @@ class Bar {
void renderText(const QString &text);
int textWidth(const QString &text);
void setColorScheme(const ColorScheme &scheme);
- void invalidate();
public:
- explicit Bar(const wl_output *output);
+ Bar();
const wl_surface* surface() const;
+ void create(wl_output *output);
+ void setTag(int tag, znet_tapesoftware_dwl_wm_monitor_v1_tag_state state, int numClients, int focusedClient);
void setStatus(const QString &status);
+ void invalidate();
void click(int x, int y);
};
diff --git a/src/config.hpp b/src/config.hpp
index a38ce87..c9b5799 100644
--- a/src/config.hpp
+++ b/src/config.hpp
@@ -4,7 +4,7 @@
#pragma once
#include "common.hpp"
-constexpr bool topbar = 1;
+constexpr bool topbar = true;
constexpr int paddingX = 10;
constexpr int paddingY = 3;
@@ -15,3 +15,4 @@ constexpr bool fontBold = true;
constexpr ColorScheme colorInactive = {QColor(255, 255, 255), QColor(0, 0, 0)};
constexpr ColorScheme colorActive = {QColor(255, 255, 255), QColor(0, 0, 255)};
+constexpr ColorScheme colorUrgent = {colorActive.bg, colorActive.fg};
diff --git a/src/main.cpp b/src/main.cpp
index e2db4af..8814903 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -27,6 +27,7 @@ struct Monitor {
wl_unique_ptr wlOutput;
wl_unique_ptr dwlMonitor;
std::optional bar;
+ bool created;
};
static void waylandFlush();
@@ -44,6 +45,7 @@ znet_tapesoftware_dwl_wm_v1 *dwlWm;
std::vector tagNames;
static bool ready;
static std::vector monitors;
+static QString lastStatus;
static std::string statusFifoName;
static int statusFifoFd {-1};
static int statusFifoWriter {-1};
@@ -68,10 +70,10 @@ struct SeatState {
static SeatState seatState;
static Bar* barFromSurface(const wl_surface *surface)
{
- auto fbar = std::find_if(begin(monitors), end(monitors), [surface](const Monitor &mon) {
+ auto mon = std::find_if(begin(monitors), end(monitors), [surface](const Monitor &mon) {
return mon.bar && mon.bar->surface() == surface;
});
- return fbar != end(monitors) && fbar->bar ? &*fbar->bar : nullptr;
+ return mon != end(monitors) && mon->bar ? &*mon->bar : nullptr;
}
static const struct wl_pointer_listener pointerListener = {
.enter = [](void*, wl_pointer *pointer, uint32_t serial,
@@ -132,19 +134,24 @@ static const struct znet_tapesoftware_dwl_wm_v1_listener dwlWmListener = {
};
static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorListener {
- .tag = [](void*, znet_tapesoftware_dwl_wm_monitor_v1*, int tag, int active, int numClients, int urgent) {
- printf("tag %s: active=%d, num_clients=%d, urgent=%d\n", qPrintable(tagNames[tag]), active, numClients, urgent);
+ .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);
},
.frame = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*) {
auto mon = static_cast(mv);
- if (!mon->bar) {
- mon->bar.emplace(mon->wlOutput.get());
+ if (mon->created) {
+ mon->bar->invalidate();
+ } else {
+ mon->bar->create(mon->wlOutput.get());
}
}
};
static void setupMonitor(Monitor &monitor) {
monitor.dwlMonitor.reset(znet_tapesoftware_dwl_wm_v1_get_monitor(dwlWm, monitor.wlOutput.get()));
+ monitor.bar.emplace();
+ monitor.bar->setStatus(lastStatus);
znet_tapesoftware_dwl_wm_monitor_v1_add_listener(monitor.dwlMonitor.get(), &dwlWmMonitorListener, &monitor);
}
@@ -208,10 +215,11 @@ static void onStatus()
{
char buffer[512];
auto n = read(statusFifoFd, buffer, sizeof(buffer));
- auto str = QString::fromUtf8(buffer, n);
+ lastStatus = QString::fromUtf8(buffer, n);
for (auto &monitor : monitors) {
if (monitor.bar) {
- monitor.bar->setStatus(str);
+ monitor.bar->setStatus(lastStatus);
+ monitor.bar->invalidate();
}
}
}