diff --git a/protocols/meson.build b/protocols/meson.build
index 7bd222b..5752608 100644
--- a/protocols/meson.build
+++ b/protocols/meson.build
@@ -15,6 +15,7 @@ wayland_xmls = [
wl_protocol_dir + '/stable/xdg-shell/xdg-shell.xml',
wl_protocol_dir + '/unstable/xdg-output/xdg-output-unstable-v1.xml',
'wlr-layer-shell-unstable-v1.xml',
+ 'net-tapesoftware-dwl-wm-unstable-v1.xml',
]
wayland_sources = [
wayland_scanner_code.process(wayland_xmls),
diff --git a/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml b/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml
new file mode 100644
index 0000000..390f5a1
--- /dev/null
+++ b/protocols/net-tapesoftware-dwl-wm-unstable-v1.xml
@@ -0,0 +1,164 @@
+
+
+
+ Copyright (c) 2021 Raphael Robatsch
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice (including the
+ next paragraph) shall be included in all copies or substantial portions
+ of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+
+
+ This interface is exposed as a global in the wl_registry.
+
+ Clients can use this protocol to receive updates of the window manager
+ state (active tags, active layout, and focused window).
+ Clients can also control this state.
+
+ After binding, the client will receive the available tags and layouts
+ with the 'tag' and 'layout' events. These can be used in subsequent
+ dwl_wm_monitor_v1.set_tags/set_layout requests, and to interpret the
+ dwl_wm_monitor_v1.layout/tag events.
+
+
+
+
+ This request indicates that the client will not use the dwl_wm
+ object any more. Objects that have been created through this instance
+ are not affected.
+
+
+
+
+
+ Gets a dwl monitor for the specified output. The window manager
+ state on the output can be controlled using the monitor.
+
+
+
+
+
+
+
+ This event is sent immediately after binding.
+ A roundtrip after binding guarantees that the client has received all tags.
+
+
+
+
+
+
+ This event is sent immediately after binding.
+ A roundtrip after binding guarantees that the client has received all layouts.
+
+
+
+
+
+
+
+ Observes and controls one monitor.
+
+ Events are double-buffered: Clients should cache all events and only
+ redraw themselves once the 'frame' event is sent.
+
+ Requests are not double-buffered: The compositor will update itself
+ immediately.
+
+
+
+
+
+
+
+
+
+
+ This request indicates that the client is done with this dwl_monitor.
+ All further requests are ignored.
+
+
+
+
+
+ If 'selected' is nonzero, this monitor is the currently selected one.
+
+
+
+
+
+
+ Announces the update of a tag. num_clients and focused_client can be
+ used to draw client indicators.
+
+
+
+
+
+
+
+
+
+ Announces the update of the selected layout.
+
+
+
+
+
+
+ Announces the update of the selected client.
+
+
+
+
+
+
+ Sent after all other events belonging to the status update has been sent.
+ Clients should redraw themselves now.
+
+
+
+
+
+ Changes are applied immediately.
+
+
+
+
+
+
+
+ tags are updated as follows:
+ new_tags = (current_tags AND and_tags) XOR xor_tags
+
+ Changes are applied immediately.
+
+
+
+
+
+
+
+ Changes are applied immediately.
+
+
+
+
+
diff --git a/src/bar.cpp b/src/bar.cpp
index af92f49..b6331dc 100644
--- a/src/bar.cpp
+++ b/src/bar.cpp
@@ -142,6 +142,16 @@ void Bar::setTag(int tag, int state, int numClients, int focusedClient)
t.focusedClient = focusedClient;
}
+uint32_t Bar::getSelectedTagNumClients()
+{
+ for (auto &tag : _tags) {
+ if (tag.state == TagState::Active) {
+ return tag.numClients;
+ }
+ }
+ return 0;
+}
+
void Bar::setSelected(bool selected)
{
_selected = selected;
@@ -241,22 +251,52 @@ void Bar::render()
void Bar::renderTags()
{
for (auto &tag : _tags) {
- setColorScheme(
- tag.state & TagState::Active ? colorActive : colorInactive,
- tag.state & TagState::Urgent);
+ setTagColorScheme(tag);
renderComponent(tag.component);
auto indicators = std::min(tag.numClients, static_cast(_bufs->height/2));
- for (auto ind = 0; ind < indicators; ind++) {
- auto w = ind == tag.focusedClient ? 7 : 1;
- cairo_move_to(_painter, tag.component.x, ind*2+0.5);
- cairo_rel_line_to(_painter, w, 0);
- cairo_close_path(_painter);
- cairo_set_line_width(_painter, 1);
- cairo_stroke(_painter);
+ if (showIndicators == 1) {
+ renderSingleIndicator(tag, indicators);
+ } else if (showIndicators == 2) {
+ renderMultiIndicators(tag, indicators);
}
}
}
+void Bar::renderMultiIndicators(const Tag& t, int inds)
+{
+ for (auto ind = 0; ind < inds; ind++) {
+ auto w = ind == t.focusedClient ? 7 : 3;
+ cairo_move_to(_painter, t.component.x, ind*2+0.5);
+ cairo_rel_line_to(_painter, w, 0);
+ cairo_close_path(_painter);
+ cairo_set_line_width(_painter, 3);
+ cairo_stroke(_painter);
+ }
+}
+
+void Bar::renderSingleIndicator(const Tag& t, int inds)
+{
+ if (inds > 0) {
+ auto w = 4;
+ setColorScheme(colorIndicator);
+ cairo_move_to(_painter, t.component.x+1, 1);
+ cairo_rel_line_to(_painter, w, 0);
+ cairo_rel_line_to(_painter, 0, w);
+ cairo_rel_line_to(_painter, -w, 0);
+ cairo_close_path(_painter);
+ cairo_set_line_width(_painter, 1);
+ beginFg();
+ cairo_stroke_preserve(_painter);
+ if (t.state == TagState::Active) {
+ beginBg();
+ } else {
+ setTagColorScheme(t);
+ beginBg();
+ }
+ cairo_fill(_painter);
+ }
+}
+
void Bar::renderStatus()
{
pango_cairo_update_layout(_painter, _statusCmp.pangoLayout.get());
@@ -269,6 +309,13 @@ void Bar::renderStatus()
renderComponent(_statusCmp);
}
+void Bar::setTagColorScheme(const Tag& t)
+{
+ setColorScheme(
+ t.state & TagState::Active ? colorActive : colorInactive,
+ t.state & TagState::Urgent);
+}
+
void Bar::setColorScheme(const ColorScheme& scheme, bool invert)
{
_colorScheme = invert
diff --git a/src/bar.hpp b/src/bar.hpp
index 176a1bc..1c45961 100644
--- a/src/bar.hpp
+++ b/src/bar.hpp
@@ -50,9 +50,12 @@ class Bar {
void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height);
void render();
void renderTags();
+ void renderMultiIndicators(const Tag& t, int inds);
+ void renderSingleIndicator(const Tag& t, int inds);
void renderStatus();
// low-level rendering
+ void setTagColorScheme(const Tag& t);
void setColorScheme(const ColorScheme& scheme, bool invert = false);
void beginFg();
void beginBg();
@@ -65,6 +68,7 @@ public:
void show(wl_output* output);
void hide();
void setTag(int tag, int state, int numClients, int focusedClient);
+ uint32_t getSelectedTagNumClients();
void setSelected(bool selected);
void setLayout(const std::string& layout);
void setTitle(const std::string& title);
diff --git a/src/common.hpp b/src/common.hpp
index c905358..a27ca74 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -10,6 +10,7 @@
#include
#include
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
+#include "net-tapesoftware-dwl-wm-unstable-v1-client-protocol.h"
struct Color {
Color() {}
@@ -38,6 +39,14 @@ extern wl_display* display;
extern wl_compositor* compositor;
extern wl_shm* shm;
extern zwlr_layer_shell_v1* wlrLayerShell;
+extern std::vector tagNames;
+extern std::vector layoutNames;
+
+void view(Monitor& m, const Arg& arg);
+void toggleview(Monitor& m, const Arg& arg);
+void setlayout(Monitor& m, const Arg& arg);
+void tag(Monitor& m, const Arg& arg);
+void toggletag(Monitor& m, const Arg& arg);
void spawn(Monitor&, const Arg& arg);
void setCloexec(int fd);
@@ -65,6 +74,7 @@ WL_DELETER(wl_output, wl_output_release_checked);
WL_DELETER(wl_pointer, wl_pointer_release);
WL_DELETER(wl_seat, wl_seat_release);
WL_DELETER(wl_surface, wl_surface_destroy);
+WL_DELETER(znet_tapesoftware_dwl_wm_monitor_v1, znet_tapesoftware_dwl_wm_monitor_v1_release);
WL_DELETER(zwlr_layer_surface_v1, zwlr_layer_surface_v1_destroy);
WL_DELETER(cairo_t, cairo_destroy);
diff --git a/src/config.def.hpp b/src/config.def.hpp
index 40a8c95..a9560cb 100644
--- a/src/config.def.hpp
+++ b/src/config.def.hpp
@@ -16,12 +16,11 @@ constexpr ColorScheme colorInactive = {Color(0xbb, 0xbb, 0xbb), Color(0x22, 0x22
constexpr ColorScheme colorActive = {Color(0xee, 0xee, 0xee), Color(0x00, 0x55, 0x77)};
constexpr const char* termcmd[] = {"foot", nullptr};
-static std::vector tagNames = {
- "1", "2", "3",
- "4", "5", "6",
- "7", "8", "9",
-};
-
constexpr Button buttons[] = {
+ { ClkTagBar, BTN_LEFT, view, {0} },
+ { ClkTagBar, BTN_RIGHT, tag, {0} },
+ { ClkTagBar, BTN_MIDDLE, toggletag, {0} },
+ { ClkLayoutSymbol, BTN_LEFT, setlayout, {.ui = 0} },
+ { ClkLayoutSymbol, BTN_RIGHT, setlayout, {.ui = 2} },
{ ClkStatusText, BTN_RIGHT, spawn, {.v = termcmd} },
};
diff --git a/src/config.hpp b/src/config.hpp
new file mode 100644
index 0000000..3596657
--- /dev/null
+++ b/src/config.hpp
@@ -0,0 +1,29 @@
+// somebar - dwl bar
+// See LICENSE file for copyright and license details.
+
+#pragma once
+#include "common.hpp"
+
+constexpr bool topbar = true;
+
+constexpr int paddingX = 10;
+constexpr int paddingY = 3;
+
+// See https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html
+constexpr const char* font = "Iosevka 11";
+
+constexpr ColorScheme colorInactive = {Color(0xff, 0xff, 0xff), Color(0x88, 0x88, 0x88)};
+constexpr ColorScheme colorActive = {Color(0xff, 0xff, 0xff), Color(0xaa, 0x44, 0x44)};
+constexpr ColorScheme colorIndicator = {Color(0xff, 0xff, 0xff), Color(0xff, 0xff, 0xff)};
+constexpr const char* termcmd[] = {"dwl_term", nullptr};
+constexpr int showIndicators = 1; // 0 = no indicators
+ // 1 = single indicator
+ // 2 = multiple indicators
+constexpr Button buttons[] = {
+ { ClkTagBar, BTN_LEFT, view, {0} },
+ { ClkTagBar, BTN_RIGHT, tag, {0} },
+ { ClkTagBar, BTN_MIDDLE, toggletag, {0} },
+ { ClkLayoutSymbol, BTN_LEFT, setlayout, {.ui = 0} },
+ { ClkLayoutSymbol, BTN_RIGHT, setlayout, {.ui = 2} },
+ { ClkStatusText, BTN_RIGHT, spawn, {.v = termcmd} },
+};
diff --git a/src/main.cpp b/src/main.cpp
index 6274959..774c9e7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,6 +21,7 @@
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
+#include "net-tapesoftware-dwl-wm-unstable-v1-client-protocol.h"
#include "common.hpp"
#include "config.hpp"
#include "bar.hpp"
@@ -34,6 +35,7 @@ struct Monitor {
bool desiredVisibility {true};
bool hasData;
uint32_t tags;
+ wl_unique_ptr dwlMonitor;
};
struct SeatPointer {
@@ -67,6 +69,9 @@ wl_display* display;
wl_compositor* compositor;
wl_shm* shm;
zwlr_layer_shell_v1* wlrLayerShell;
+znet_tapesoftware_dwl_wm_v1* dwlWm;
+std::vector tagNames;
+std::vector layoutNames;
static xdg_wm_base* xdgWmBase;
static zxdg_output_manager_v1* xdgOutputManager;
static wl_surface* cursorSurface;
@@ -85,6 +90,26 @@ static int statusFifoFd {-1};
static int statusFifoWriter {-1};
static bool quitting {false};
+void view(Monitor& m, const Arg& arg)
+{
+ znet_tapesoftware_dwl_wm_monitor_v1_set_tags(m.dwlMonitor.get(), arg.ui, 1);
+}
+void toggleview(Monitor& m, const Arg& arg)
+{
+ znet_tapesoftware_dwl_wm_monitor_v1_set_tags(m.dwlMonitor.get(), m.tags ^ arg.ui, 0);
+}
+void setlayout(Monitor& m, const Arg& arg)
+{
+ znet_tapesoftware_dwl_wm_monitor_v1_set_layout(m.dwlMonitor.get(), arg.ui);
+}
+void tag(Monitor& m, const Arg& arg)
+{
+ znet_tapesoftware_dwl_wm_monitor_v1_set_client_tags(m.dwlMonitor.get(), 0, arg.ui);
+}
+void toggletag(Monitor& m, const Arg& arg)
+{
+ znet_tapesoftware_dwl_wm_monitor_v1_set_client_tags(m.dwlMonitor.get(), ~0, arg.ui);
+}
void spawn(Monitor&, const Arg& arg)
{
if (fork() == 0) {
@@ -189,11 +214,71 @@ static const struct wl_seat_listener seatListener = {
.name = [](void*, wl_seat*, const char* name) { }
};
+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*, uint32_t selected) {
+ auto mon = static_cast(mv);
+ if (selected) {
+ selmon = mon;
+ } else if (selmon == mon) {
+ selmon = nullptr;
+ }
+ mon->bar.setSelected(selected);
+ },
+ .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);
+ int tagState = TagState::None;
+ if (state & ZNET_TAPESOFTWARE_DWL_WM_MONITOR_V1_TAG_STATE_ACTIVE)
+ tagState |= TagState::Active;
+ if (state & ZNET_TAPESOFTWARE_DWL_WM_MONITOR_V1_TAG_STATE_URGENT)
+ tagState |= TagState::Urgent;
+ mon->bar.setTag(tag, tagState, numClients, focusedClient);
+ uint32_t mask = 1 << tag;
+ if (tagState & TagState::Active) {
+ mon->tags |= mask;
+ } else {
+ mon->tags &= ~mask;
+ }
+ },
+ .layout = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t layout) {
+ auto mon = static_cast(mv);
+ if (layout == 2) {
+ char lout[4] = "[M]";
+ uint32_t numc = mon->bar.getSelectedTagNumClients();
+ if (numc > 0) {
+ sprintf(lout, "[%d]", numc);
+ }
+ mon->bar.setLayout(lout);
+ } else {
+ mon->bar.setLayout(layoutNames[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);
+ mon->hasData = true;
+ updatemon(*mon);
+ }
+};
+
void setupMonitor(uint32_t name, wl_output* output) {
auto& monitor = monitors.emplace_back(Monitor {name, {}, wl_unique_ptr {output}});
monitor.bar.setStatus(lastStatus);
auto xdgOutput = zxdg_output_manager_v1_get_xdg_output(xdgOutputManager, monitor.wlOutput.get());
zxdg_output_v1_add_listener(xdgOutput, &xdgOutputListener, &monitor);
+ monitor.dwlMonitor.reset(znet_tapesoftware_dwl_wm_v1_get_monitor(dwlWm, monitor.wlOutput.get()));
+ znet_tapesoftware_dwl_wm_monitor_v1_add_listener(monitor.dwlMonitor.get(), &dwlWmMonitorListener, &monitor);
}
void updatemon(Monitor& mon)
@@ -219,6 +304,7 @@ void onReady()
requireGlobal(shm, "wl_shm");
requireGlobal(wlrLayerShell, "zwlr_layer_shell_v1");
requireGlobal(xdgOutputManager, "zxdg_output_manager_v1");
+ requireGlobal(dwlWm, "znet_tapesoftware_dwl_wm_v1");
setupStatusFifo();
wl_display_roundtrip(display); // roundtrip so we receive all dwl tags etc.
@@ -409,6 +495,10 @@ void onGlobalAdd(void*, wl_registry* registry, uint32_t name, const char* interf
xdg_wm_base_add_listener(xdgWmBase, &xdgWmBaseListener, nullptr);
return;
}
+ if (reg.handle(dwlWm, znet_tapesoftware_dwl_wm_v1_interface, 1)) {
+ znet_tapesoftware_dwl_wm_v1_add_listener(dwlWm, &dwlWmListener, nullptr);
+ return;
+ }
if (wl_seat* wlSeat; reg.handle(wlSeat, wl_seat_interface, 7)) {
auto& seat = seats.emplace_back(Seat {name, wl_unique_ptr {wlSeat}});
wl_seat_add_listener(wlSeat, &seatListener, &seat);
@@ -611,3 +701,4 @@ void diesys(const char* why) {
cleanup();
exit(1);
}
+