20 Commits

Author SHA1 Message Date
6e2dd755d0 Don't die if status FIFO exists 2023-10-14 10:41:30 -07:00
7b6e33ff43 Merge ../somebar_good_20221119_backed 2023-10-08 11:15:58 -07:00
Ben Collerson
8c52d4704c clickable tags patch improvement 2023-08-02 20:18:08 +02:00
mortezadadgar
e1f8c63064 Fix possible OOB access for clicking tags
specify the signed type for indexing tags as intended
for `tag >= 0` check.

Signed-off-by: mortezadadgar <mortezadadgar97@gmail.com>
2023-08-01 21:24:08 +02:00
ea42a8bc8e Merge remote-tracking branch 'refs/remotes/origin/master' 2023-04-15 17:21:28 -07:00
Ben Collerson
b069830640 patch: clickable tags using wtype 2023-04-08 19:30:30 +02:00
Sam Nystrom
af73bc3996 add patch to disable window title 2023-03-05 14:05:57 +01:00
Raphael Robatsch
9cdbf5f56f rebase ipc.patch 2023-02-25 09:06:44 +01:00
81d8afd365 Merge remote-tracking branch 'origin/master' 2023-01-15 14:08:52 -08:00
medanisjbara
624e92927b hide-vacant-tags: fix tag 0 is hiding all 2022-12-30 14:14:03 +01:00
Henrique Possatto
ea9dbfe022 patch to show square tag indicator like dwm 2022-12-30 14:11:14 +01:00
Raphael Robatsch
7d8c2f8b8c release v1.0.3 2022-12-11 19:30:30 +01:00
Raphael Robatsch
5bb988bc80 add changelog 2022-12-10 13:52:54 +01:00
Ben Collerson
c36d1f2957 patch to show status only on selected monitor 2022-12-10 13:44:13 +01:00
Raphael Robatsch
83f59945a6 fix crash when an output goes away
happens e.g. when a monitor is powered off.
The wl_output interface published by dwl has version 1, but the
wl_output_release request is only supported since version 3.
2022-12-04 19:05:35 +01:00
Ben Collerson
c076d343fc markup in status message patch 2022-11-30 19:07:33 +01:00
Raphael Robatsch
fb2c8e5f42 fix bug where hidden bar cannot be shown anymore 2022-11-27 10:41:05 +01:00
Ben Collerson
6e464bf35d trim spaces from title and layout symbol 2022-11-25 11:19:52 +01:00
41b2b04121 Added support for single indicators
And indicator configuration
2022-11-24 21:01:06 -08:00
fe3654cde3 Customizations
* Increased size of tag indication of clients
* In monocle mode, layout symbol shows number of clients in the tag
2022-11-24 17:59:57 -08:00
13 changed files with 474 additions and 42 deletions

19
CHANGELOG.md Normal file
View File

@@ -0,0 +1,19 @@
## [1.0.3] - 2022-12-11
### Added
- New patches: markup-in-status-messages, show-status-on-selected-monitor (benc)
### Fixed
- Fixed crash when an output disappears
## [1.0.2] - 2022-11-27
### Fixed
- Fixed bug where hidden bar could not be shown anymore
## [1.0.1] - 2022-11-25
### Added
- Manpage
- New patches: indicator-size-props, hide-vacant-tags, colorless-status (medanisjbara)
### Fixed
- Remove spaces from title and layout symbol (benc)
## [1.0.0] - 2022-04-23
Initial release

View File

@@ -0,0 +1,91 @@
From: Ben Collerson <benc@benc.cc>
Date: Sat, 1 Apr 2023 09:16:19 +1000
Subject: [PATCH somebar] clickable tags using wtype
---
src/bar.cpp | 3 ++-
src/common.hpp | 2 ++
src/config.def.hpp | 5 +++++
src/main.cpp | 15 +++++++++++++++
4 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/bar.cpp b/src/bar.cpp
index af92f49..8b68759 100644
--- a/src/bar.cpp
+++ b/src/bar.cpp
@@ -182,9 +182,10 @@ void Bar::click(Monitor* mon, int x, int, int btn)
} else if (x > _layoutCmp.x) {
control = ClkLayoutSymbol;
} else for (int tag = _tags.size()-1; tag >= 0; tag--) {
+ // you may need logic to skip tags if they are hidden elsewhere.
if (x > _tags[tag].component.x) {
control = ClkTagBar;
- arg.ui = 1<<tag;
+ arg.ui = tag;
argp = &arg;
break;
}
diff --git a/src/common.hpp b/src/common.hpp
index c905358..a386029 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -39,6 +39,8 @@ extern wl_compositor* compositor;
extern wl_shm* shm;
extern zwlr_layer_shell_v1* wlrLayerShell;
+void view(Monitor& m, const Arg& arg);
+void tag(Monitor& m, const Arg& arg);
void spawn(Monitor&, const Arg& arg);
void setCloexec(int fd);
[[noreturn]] void die(const char* why);
diff --git a/src/config.def.hpp b/src/config.def.hpp
index 40a8c95..de193ea 100644
--- a/src/config.def.hpp
+++ b/src/config.def.hpp
@@ -4,6 +4,9 @@
#pragma once
#include "common.hpp"
+#define WTYPE "/usr/bin/wtype"
+#define MODKEY "alt"
+
constexpr bool topbar = true;
constexpr int paddingX = 10;
@@ -23,5 +26,7 @@ static std::vector<std::string> tagNames = {
};
constexpr Button buttons[] = {
+ { ClkTagBar, BTN_LEFT, view, {0} },
+ { ClkTagBar, BTN_RIGHT, tag, {0} },
{ ClkStatusText, BTN_RIGHT, spawn, {.v = termcmd} },
};
diff --git a/src/main.cpp b/src/main.cpp
index 6274959..3c35b20 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -85,6 +85,21 @@ static int statusFifoFd {-1};
static int statusFifoWriter {-1};
static bool quitting {false};
+// update keybindings to match your dwl
+void view(Monitor& m, const Arg& arg)
+{
+ char tag[2];
+ snprintf(tag, 2, "%i", arg.ui + 1);
+ if(fork() == 0)
+ execl(WTYPE, "wtype", "-M", MODKEY, tag, (char*)NULL);
+}
+void tag(Monitor& m, const Arg& arg)
+{
+ char tag[2];
+ snprintf(tag, 2, "%i", arg.ui + 1);
+ if(fork() == 0)
+ execl(WTYPE, "wtype", "-M", MODKEY, "-M", "shift", tag, (char*)NULL);
+}
void spawn(Monitor&, const Arg& arg)
{
if (fork() == 0) {
--
2.40.1

View File

@@ -0,0 +1,15 @@
From: Sam Nystrom <samuel.l.nystrom@gmail.com>
Date: Sat, 4 Mar 2023 17:38:12 -0500
Description: disable window title
diff --git a/src/bar.cpp b/src/bar.cpp
index 507ce62..1b6f771 100644
--- a/src/bar.cpp
+++ b/src/bar.cpp
@@ -227,7 +227,6 @@ void Bar::render()
renderTags();
setColorScheme(_selected ? colorActive : colorInactive);
renderComponent(_layoutCmp);
- renderComponent(_titleCmp);
renderStatus();
_painter = nullptr;

View File

@@ -0,0 +1,34 @@
From: Henrique Possatto <henriquempossatto@gmail.com>
Date: Mon, 26 Dec 2022 18:01:35 -0300
Subject: [PATCH somebar] patch to show square tag indicator like dwm
diff --git a/src/bar.cpp b/src/bar.cpp
index 507ce62..4fda8b0 100644
--- a/src/bar.cpp
+++ b/src/bar.cpp
@@ -245,12 +245,17 @@ void Bar::renderTags()
tag.state & TagState::Active ? colorActive : colorInactive,
tag.state & TagState::Urgent);
renderComponent(tag.component);
- auto indicators = std::min(tag.numClients, static_cast<int>(_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);
+
+ if(!tag.numClients)
+ continue;
+
+ int s = barfont.height / 9;
+ int w = barfont.height / 6 + 2;
+ if (tag.focusedClient != -1) {
+ cairo_rectangle(_painter, tag.component.x + s, s, w, w);
+ cairo_fill(_painter);
+ } else {
+ cairo_rectangle(_painter, (double)(tag.component.x + s) + 0.5, (double)(s) + 0.5, w, w);
cairo_set_line_width(_painter, 1);
cairo_stroke(_painter);
}
--
2.39.0

View File

@@ -5,30 +5,50 @@ diff --git a/src/bar.cpp b/src/bar.cpp
index fab5a8f..38e7b5f 100644
--- a/src/bar.cpp
+++ b/src/bar.cpp
@@ -240,12 +240,22 @@ void Bar::render()
@@ -240,13 +240,36 @@ void Bar::render()
void Bar::renderTags()
{
+ bool focused;
+ // Check if all tags are active (Mod+0)
+ bool allActive = true;
for (auto &tag : _tags) {
- setColorScheme(
- tag.state & TagState::Active ? colorActive : colorInactive,
- tag.state & TagState::Urgent);
- renderComponent(tag.component);
+ focused = false;
auto indicators = std::min(tag.numClients, static_cast<int>(_bufs->height/2));
+ for (auto ind = 0; ind < indicators; ind++) {
+ if (tag.focusedClient){
+ focused = true;
+ if (tag.state & TagState::Active){
+ if (!allActive){
+ allActive = true;
+ break;
+ }
+ allActive = false;
+ }
+ }
+
+ if (tag.state & TagState::Active || focused){
+ setColorScheme(
+ tag.state & TagState::Active ? colorActive : colorInactive,
+ tag.state & TagState::Urgent);
+ renderComponent(tag.component);
+ }
+ bool renderThis;
+ for (auto &tag : _tags) {
+ renderThis = false;
setColorScheme(
tag.state & TagState::Active ? colorActive : colorInactive,
tag.state & TagState::Urgent);
- renderComponent(tag.component);
+ // Reder active tag if it's the only one active
+ if (!allActive && tag.state & TagState::Active)
+ renderThis = true;
auto indicators = std::min(tag.numClients, static_cast<int>(_bufs->height/2));
for (auto ind = 0; ind < indicators; ind++) {
+ // render tags having indicators
+ if (tag.focusedClient == -1)
+ renderThis = true;
+ // render tags having the focused client
+ if (tag.focusedClient == 0){
+ renderThis = true;
+ }
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);
@@ -254,6 +277,8 @@ void Bar::renderTags()
cairo_set_line_width(_painter, 1);
cairo_stroke(_painter);
}
+ if (renderThis)
+ renderComponent(tag.component);
}
}

View File

@@ -193,7 +193,7 @@ index 0000000..390f5a1
+ </interface>
+</protocol>
diff --git a/src/common.hpp b/src/common.hpp
index aed4480..12a3e2e 100644
index c905358..9b62a94 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -10,6 +10,7 @@
@@ -219,7 +219,7 @@ index aed4480..12a3e2e 100644
void spawn(Monitor&, const Arg& arg);
void setCloexec(int fd);
[[noreturn]] void die(const char* why);
@@ -59,6 +67,7 @@ WL_DELETER(wl_output, wl_output_release);
@@ -65,6 +73,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);
@@ -250,7 +250,7 @@ index 40a8c95..a9560cb 100644
{ ClkStatusText, BTN_RIGHT, spawn, {.v = termcmd} },
};
diff --git a/src/main.cpp b/src/main.cpp
index 6198d8b..9e7549a 100644
index 6274959..01be870 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,7 +3,6 @@
@@ -403,8 +403,8 @@ index 6198d8b..9e7549a 100644
- wl_display_roundtrip(display); // wait for xdg_output names before we read stdin
}
void setupStatusFifo()
@@ -259,66 +331,6 @@ void setupStatusFifo()
bool createFifo(std::string path)
@@ -273,68 +345,6 @@ void setupStatusFifo()
}
}
@@ -435,7 +435,8 @@ index 6198d8b..9e7549a 100644
- return;
- if (command == "title") {
- auto title = std::string {};
- std::getline(stream, title);
- stream >> std::ws;
- std::getline(stream, title);
- mon->bar.setTitle(title);
- } else if (command == "selmon") {
- uint32_t selected;
@@ -461,6 +462,7 @@ index 6198d8b..9e7549a 100644
- mon->tags = tags;
- } else if (command == "layout") {
- auto layout = std::string {};
- stream >> std::ws;
- std::getline(stream, layout);
- mon->bar.setLayout(layout);
- }
@@ -471,7 +473,7 @@ index 6198d8b..9e7549a 100644
const std::string prefixStatus = "status ";
const std::string prefixShow = "show ";
const std::string prefixHide = "hide ";
@@ -393,6 +405,10 @@ void onGlobalAdd(void*, wl_registry* registry, uint32_t name, const char* interf
@@ -409,6 +419,10 @@ void onGlobalAdd(void*, wl_registry* registry, uint32_t name, const char* interf
xdg_wm_base_add_listener(xdgWmBase, &xdgWmBaseListener, nullptr);
return;
}
@@ -482,7 +484,7 @@ index 6198d8b..9e7549a 100644
if (wl_seat* wlSeat; reg.handle(wlSeat, wl_seat_interface, 7)) {
auto& seat = seats.emplace_back(Seat {name, wl_unique_ptr<wl_seat> {wlSeat}});
wl_seat_add_listener(wlSeat, &seatListener, &seat);
@@ -494,10 +510,6 @@ int main(int argc, char* argv[])
@@ -522,10 +536,6 @@ int main(int argc, char* argv[])
.fd = displayFd,
.events = POLLIN,
});
@@ -493,7 +495,7 @@ index 6198d8b..9e7549a 100644
if (fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK) < 0) {
diesys("fcntl F_SETFL");
}
@@ -522,8 +534,6 @@ int main(int argc, char* argv[])
@@ -550,8 +560,6 @@ int main(int argc, char* argv[])
ev.events = POLLIN;
waylandFlush();
}

View File

@@ -0,0 +1,65 @@
From: Ben Collerson <benc@benc.cc>
Date: Tue, 29 Nov 2022 11:29:15 +1000
Subject: [PATCH] markup in status messages
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Allows pango markup to be used in status messages which allow colours to
be used to highlight parts of status bar messages. eg:
battery: full <span color="#ffff00">🔇0</span> Tue 11-20 20:10
---
src/bar.cpp | 16 +++++++++++++++-
src/bar.hpp | 1 +
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/bar.cpp b/src/bar.cpp
index 507ce62..a96c547 100644
--- a/src/bar.cpp
+++ b/src/bar.cpp
@@ -81,6 +81,11 @@ void BarComponent::setText(const std::string& text)
pango_layout_set_text(pangoLayout.get(), _text->c_str(), _text->size());
}
+void BarComponent::setAttributes(PangoAttrList *attrs)
+{
+ pango_layout_set_attributes(pangoLayout.get(), attrs);
+}
+
Bar::Bar()
{
_pangoContext.reset(pango_font_map_create_context(pango_cairo_font_map_get_default()));
@@ -156,7 +161,16 @@ void Bar::setTitle(const std::string& title)
}
void Bar::setStatus(const std::string& status)
{
- _statusCmp.setText(status);
+ char *buf;
+ GError *error = NULL;
+ PangoAttrList *attrs;
+ if (pango_parse_markup(status.c_str(), -1, 0, &attrs, &buf, NULL, &error)) {
+ _statusCmp.setText(buf);
+ _statusCmp.setAttributes(attrs);
+ }
+ else {
+ _statusCmp.setText(error->message);
+ }
}
void Bar::invalidate()
diff --git a/src/bar.hpp b/src/bar.hpp
index 176a1bc..dfc2043 100644
--- a/src/bar.hpp
+++ b/src/bar.hpp
@@ -17,6 +17,7 @@ public:
explicit BarComponent(wl_unique_ptr<PangoLayout> layout);
int width() const;
void setText(const std::string& text);
+ void setAttributes(PangoAttrList *attrs);
wl_unique_ptr<PangoLayout> pangoLayout;
int x {0};
};
--
2.38.1

View File

@@ -0,0 +1,43 @@
From 1ca4603b79e888980fb46d5dc6aa0d6f8afa2b3c Mon Sep 17 00:00:00 2001
From: Ben Collerson <benc@benc.cc>
Date: Mon, 28 Nov 2022 13:22:16 +1000
Subject: [PATCH] show status on selected monitor
---
src/bar.cpp | 7 ++++++-
src/main.cpp | 1 +
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/bar.cpp b/src/bar.cpp
index 507ce62..f962927 100644
--- a/src/bar.cpp
+++ b/src/bar.cpp
@@ -156,7 +156,12 @@ void Bar::setTitle(const std::string& title)
}
void Bar::setStatus(const std::string& status)
{
- _statusCmp.setText(status);
+ if (_selected) {
+ _statusCmp.setText(status);
+ }
+ else {
+ _statusCmp.setText("");
+ }
}
void Bar::invalidate()
diff --git a/src/main.cpp b/src/main.cpp
index 6274959..c6fd401 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -307,6 +307,7 @@ static void handleStdin(const std::string& line)
uint32_t selected;
stream >> selected;
mon->bar.setSelected(selected);
+ mon->bar.setStatus(lastStatus);
if (selected) {
selmon = &*mon;
} else if (selmon == &*mon) {
--
2.38.1

View File

@@ -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;
@@ -181,7 +191,7 @@ void Bar::click(Monitor* mon, int x, int, int btn)
control = ClkWinTitle;
} else if (x > _layoutCmp.x) {
control = ClkLayoutSymbol;
} else for (auto tag = _tags.size()-1; tag >= 0; tag--) {
} else for (int tag = _tags.size()-1; tag >= 0; tag--) {
if (x > _tags[tag].component.x) {
control = ClkTagBar;
arg.ui = 1<<tag;
@@ -200,7 +210,7 @@ void Bar::click(Monitor* mon, int x, int, int btn)
void Bar::layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height)
{
zwlr_layer_surface_v1_ack_configure(_layerSurface.get(), serial);
if (width == _bufs->width && height == _bufs->height) {
if (_bufs && width == _bufs->width && height == _bufs->height) {
return;
}
_bufs.emplace(width, height, WL_SHM_FORMAT_XRGB8888);
@@ -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<int>(_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

View File

@@ -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);

View File

@@ -63,8 +63,14 @@ struct WlDeleter;
template<typename T>
using wl_unique_ptr = std::unique_ptr<T, WlDeleter<T>>;
inline void wl_output_release_checked(wl_output* output) {
if (wl_output_get_version(output) >= WL_OUTPUT_RELEASE_SINCE_VERSION) {
wl_output_release(output);
}
}
WL_DELETER(wl_buffer, wl_buffer_destroy);
WL_DELETER(wl_output, wl_output_release);
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);

View File

@@ -14,8 +14,11 @@ 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} },

View File

@@ -3,6 +3,7 @@
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <list>
#include <optional>
#include <utility>
@@ -22,6 +23,7 @@
#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"
#include "line_buffer.hpp"
@@ -54,6 +56,8 @@ static void updatemon(Monitor &mon);
static void onReady();
static void setupStatusFifo();
static void onStatus();
static void onStdin();
static void handleStdin(const std::string& line);
static void updateVisibility(const std::string& name, bool(*updater)(bool));
static void onGlobalAdd(void*, wl_registry* registry, uint32_t name, const char* interface, uint32_t version);
static void onGlobalRemove(void*, wl_registry* registry, uint32_t name);
@@ -246,7 +250,16 @@ static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorLis
},
.layout = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t layout) {
auto mon = static_cast<Monitor*>(mv);
mon->bar.setLayout(layoutNames[layout]);
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<Monitor*>(mv);
@@ -299,12 +312,13 @@ void onReady()
for (auto output : uninitializedOutputs) {
setupMonitor(output.first, output.second);
}
wl_display_roundtrip(display); // wait for xdg_output names before we read stdin
}
bool createFifo(std::string path)
{
auto result = mkfifo(path.c_str(), 0666);
if (result == 0) {
if ((result == 0) || (errno == EEXIST)) {
auto fd = open(path.c_str(), O_CLOEXEC | O_NONBLOCK | O_RDONLY);
if (fd < 0) {
diesys("open status fifo reader");
@@ -345,6 +359,68 @@ void setupStatusFifo()
}
}
static LineBuffer<512> stdinBuffer;
static void onStdin()
{
auto res = stdinBuffer.readLines(
[](void* p, size_t size) { return read(0, p, size); },
[](char* p, size_t size) { handleStdin({p, size}); });
if (res == 0) {
quitting = true;
}
}
static void handleStdin(const std::string& line)
{
// this parses the lines that dwl sends in printstatus()
std::string monName, command;
auto stream = std::istringstream {line};
stream >> monName >> command;
if (!stream.good()) {
return;
}
auto mon = std::find_if(begin(monitors), end(monitors), [&](const Monitor& mon) {
return mon.xdgName == monName;
});
if (mon == end(monitors))
return;
if (command == "title") {
auto title = std::string {};
stream >> std::ws;
std::getline(stream, title);
mon->bar.setTitle(title);
} else if (command == "selmon") {
uint32_t selected;
stream >> selected;
mon->bar.setSelected(selected);
if (selected) {
selmon = &*mon;
} else if (selmon == &*mon) {
selmon = nullptr;
}
} else if (command == "tags") {
uint32_t occupied, tags, clientTags, urgent;
stream >> occupied >> tags >> clientTags >> urgent;
for (auto i=0u; i<tagNames.size(); i++) {
auto tagMask = 1 << i;
int state = TagState::None;
if (tags & tagMask)
state |= TagState::Active;
if (urgent & tagMask)
state |= TagState::Urgent;
mon->bar.setTag(i, state, occupied & tagMask ? 1 : 0, clientTags & tagMask ? 0 : -1);
}
mon->tags = tags;
} else if (command == "layout") {
auto layout = std::string {};
stream >> std::ws;
std::getline(stream, layout);
mon->bar.setLayout(layout);
}
mon->hasData = true;
updatemon(*mon);
}
const std::string prefixStatus = "status ";
const std::string prefixShow = "show ";
const std::string prefixHide = "hide ";
@@ -536,6 +612,10 @@ int main(int argc, char* argv[])
.fd = displayFd,
.events = POLLIN,
});
pollfds.push_back({
.fd = STDIN_FILENO,
.events = POLLIN,
});
if (fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK) < 0) {
diesys("fcntl F_SETFL");
}
@@ -560,6 +640,8 @@ int main(int argc, char* argv[])
ev.events = POLLIN;
waylandFlush();
}
} else if (ev.fd == STDIN_FILENO && (ev.revents & POLLIN)) {
onStdin();
} else if (ev.fd == statusFifoFd && (ev.revents & POLLIN)) {
onStatus();
} else if (ev.fd == signalSelfPipe[0] && (ev.revents & POLLIN)) {
@@ -619,3 +701,4 @@ void diesys(const char* why) {
cleanup();
exit(1);
}