Compare commits

...

3 Commits

Author SHA1 Message Date
70a11edea4 Support for DWL IPC v2
* More customizations for indicators
2024-02-18 11:27:44 -08:00
jeron
98ad3780b8 Fix status bar background color
I don't know if this is the best way to do it but this one-liner
makes it look exactly like dwm's.

Co-authored-by: Raphael Robatsch <raphael-git@tapesoftware.net>
2024-02-18 11:22:22 -08:00
Raphael Robatsch
7e91b3a514 Loosen required zwlr_layer_shell_v1 version
Version 1 is enough for somebar. dwl exports version 3 but we don't even
need to go that high.
2024-02-18 11:22:22 -08:00
5 changed files with 245 additions and 39 deletions

View File

@ -0,0 +1,181 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This is largely ripped from somebar's ipc patchset; just with some personal modifications.
I would probably just submit raphi's patchset but I don't think that would be polite.
-->
<protocol name="dwl_ipc_unstable_v2">
<description summary="inter-proccess-communication about dwl's state">
This protocol allows clients to update and get updates from dwl.
Warning! The protocol described in this file is experimental and
backward incompatible changes may be made. Backward compatible
changes may be added together with the corresponding interface
version bump.
Backward incompatible changes are done by bumping the version
number in the protocol and interface names and resetting the
interface version. Once the protocol is to be declared stable,
the 'z' prefix and the version number in the protocol and
interface names are removed and the interface version number is
reset.
</description>
<interface name="zdwl_ipc_manager_v2" version="2">
<description summary="manage dwl state">
This interface is exposed as a global in wl_registry.
Clients can use this interface to get a dwl_ipc_output.
After binding the client will recieve the dwl_ipc_manager.tags and dwl_ipc_manager.layout events.
The dwl_ipc_manager.tags and dwl_ipc_manager.layout events expose tags and layouts to the client.
</description>
<request name="release" type="destructor">
<description summary="release dwl_ipc_manager">
Indicates that the client will not the dwl_ipc_manager object anymore.
Objects created through this instance are not affected.
</description>
</request>
<request name="get_output">
<description summary="get a dwl_ipc_outout for a wl_output">
Get a dwl_ipc_outout for the specified wl_output.
</description>
<arg name="id" type="new_id" interface="zdwl_ipc_output_v2"/>
<arg name="output" type="object" interface="wl_output"/>
</request>
<event name="tags">
<description summary="Announces tag amount">
This event is sent after binding.
A roundtrip after binding guarantees the client recieved all tags.
</description>
<arg name="amount" type="uint"/>
</event>
<event name="layout">
<description summary="Announces a layout">
This event is sent after binding.
A roundtrip after binding guarantees the client recieved all layouts.
</description>
<arg name="name" type="string"/>
</event>
</interface>
<interface name="zdwl_ipc_output_v2" version="2">
<description summary="control dwl output">
Observe and control a dwl output.
Events are double-buffered:
Clients should cache events and redraw when a dwl_ipc_output.frame event is sent.
Request are not double-buffered:
The compositor will update immediately upon request.
</description>
<enum name="tag_state">
<entry name="none" value="0" summary="no state"/>
<entry name="active" value="1" summary="tag is active"/>
<entry name="urgent" value="2" summary="tag has at least one urgent client"/>
</enum>
<request name="release" type="destructor">
<description summary="release dwl_ipc_outout">
Indicates to that the client no longer needs this dwl_ipc_output.
</description>
</request>
<event name="toggle_visibility">
<description summary="Toggle client visibilty">
Indicates the client should hide or show themselves.
If the client is visible then hide, if hidden then show.
</description>
</event>
<event name="active">
<description summary="Update the selected output.">
Indicates if the output is active. Zero is invalid, nonzero is valid.
</description>
<arg name="active" type="uint"/>
</event>
<event name="tag">
<description summary="Update the state of a tag.">
Indicates that a tag has been updated.
</description>
<arg name="tag" type="uint" summary="Index of the tag"/>
<arg name="state" type="uint" enum="tag_state" summary="The state of the tag."/>
<arg name="clients" type="uint" summary="The number of clients in the tag."/>
<arg name="focused" type="uint" summary="If there is a focused client. Nonzero being valid, zero being invalid."/>
</event>
<event name="layout">
<description summary="Update the layout.">
Indicates a new layout is selected.
</description>
<arg name="layout" type="uint" summary="Index of the layout."/>
</event>
<event name="title">
<description summary="Update the title.">
Indicates the title has changed.
</description>
<arg name="title" type="string" summary="The new title name."/>
</event>
<event name="appid" since="1">
<description summary="Update the appid.">
Indicates the appid has changed.
</description>
<arg name="appid" type="string" summary="The new appid."/>
</event>
<event name="layout_symbol" since="1">
<description summary="Update the current layout symbol">
Indicates the layout has changed. Since layout symbols are dynamic.
As opposed to the zdwl_ipc_manager.layout event, this should take precendence when displaying.
You can ignore the zdwl_ipc_output.layout event.
</description>
<arg name="layout" type="string" summary="The new layout"/>
</event>
<event name="frame">
<description summary="The update sequence is done.">
Indicates that a sequence of status updates have finished and the client should redraw.
</description>
</event>
<request name="set_tags">
<description summary="Set the active tags of this output"/>
<arg name="tagmask" type="uint" summary="bitmask of the tags that should be set."/>
<arg name="toggle_tagset" type="uint" summary="toggle the selected tagset, zero for invalid, nonzero for valid."/>
</request>
<request name="set_client_tags">
<description summary="Set the tags of the focused client.">
The tags are updated as follows:
new_tags = (current_tags AND and_tags) XOR xor_tags
</description>
<arg name="and_tags" type="uint"/>
<arg name="xor_tags" type="uint"/>
</request>
<request name="set_layout">
<description summary="Set the layout of this output"/>
<arg name="index" type="uint" summary="index of a layout recieved by dwl_ipc_manager.layout"/>
</request>
<!-- Version 2 -->
<event name="fullscreen" since="2">
<description summary="Update fullscreen status">
Indicates if the selected client on this output is fullscreen.
</description>
<arg name="is_fullscreen" type="uint" summary="If the selected client is fullscreen. Nonzero is valid, zero invalid"/>
</event>
<event name="floating" since="2">
<description summary="Update the floating status">
Indicates if the selected client on this output is floating.
</description>
<arg name="is_floating" type="uint" summary="If the selected client is floating. Nonzero is valid, zero invalid"/>
</event>
</interface>
</protocol>

View File

@ -15,7 +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',
'dwl-ipc-unstable-v2.xml',
]
wayland_sources = [
wayland_scanner_code.process(wayland_xmls),

View File

@ -87,8 +87,9 @@ Bar::Bar()
if (!_pangoContext) {
die("pango_font_map_create_context");
}
for (const auto& tagName : tagNames) {
_tags.push_back({ TagState::None, 0, 0, createComponent(tagName) });
//for (const auto& tagName : tagNames) {
for (int ti = 1; ti < 10; ti++ ) {
_tags.push_back({ TagState::None, 0, 0, createComponent(std::to_string(ti)) });
}
_layoutCmp = createComponent();
_titleCmp = createComponent();
@ -306,7 +307,11 @@ void Bar::renderStatus()
cairo_fill(_painter);
_x = start;
setColorScheme(colorInactive, false);
if (_statusCmp.width() > 0)
{
renderComponent(_statusCmp);
}
}
void Bar::setTagColorScheme(const Tag& t)

View File

@ -5,12 +5,14 @@
#include <memory>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <wayland-client.h>
#include <linux/input-event-codes.h>
#include <cairo/cairo.h>
#include <pango/pango.h>
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "net-tapesoftware-dwl-wm-unstable-v1-client-protocol.h"
#include "dwl-ipc-unstable-v2-client-protocol.h"
struct Color {
Color() {}
@ -39,8 +41,8 @@ extern wl_display* display;
extern wl_compositor* compositor;
extern wl_shm* shm;
extern zwlr_layer_shell_v1* wlrLayerShell;
extern std::vector<std::string> tagNames;
extern std::vector<std::string> layoutNames;
static std::vector<std::string> tagNames;
static std::vector<std::string> layoutNames;
void view(Monitor& m, const Arg& arg);
void toggleview(Monitor& m, const Arg& arg);
@ -74,7 +76,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(zdwl_ipc_output_v2, zdwl_ipc_output_v2_destroy);
WL_DELETER(zwlr_layer_surface_v1, zwlr_layer_surface_v1_destroy);
WL_DELETER(cairo_t, cairo_destroy);

View File

@ -21,7 +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 "dwl-ipc-unstable-v2-client-protocol.h"
#include "common.hpp"
#include "config.hpp"
#include "bar.hpp"
@ -35,7 +35,7 @@ struct Monitor {
bool desiredVisibility {true};
bool hasData;
uint32_t tags;
wl_unique_ptr<znet_tapesoftware_dwl_wm_monitor_v1> dwlMonitor;
wl_unique_ptr<zdwl_ipc_output_v2> dwlMonitor;
};
struct SeatPointer {
@ -69,9 +69,8 @@ wl_display* display;
wl_compositor* compositor;
wl_shm* shm;
zwlr_layer_shell_v1* wlrLayerShell;
znet_tapesoftware_dwl_wm_v1* dwlWm;
std::vector<std::string> tagNames;
std::vector<std::string> layoutNames;
zdwl_ipc_manager_v2* dwlWm;
char* log_txt;
static xdg_wm_base* xdgWmBase;
static zxdg_output_manager_v1* xdgOutputManager;
static wl_surface* cursorSurface;
@ -92,23 +91,23 @@ 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);
zdwl_ipc_output_v2_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);
zdwl_ipc_output_v2_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);
zdwl_ipc_output_v2_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);
zdwl_ipc_output_v2_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);
zdwl_ipc_output_v2_set_client_tags(m.dwlMonitor.get(), ~0, arg.ui);
}
void spawn(Monitor&, const Arg& arg)
{
@ -214,31 +213,35 @@ 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);
static const struct zdwl_ipc_manager_v2_listener dwlWmListener = {
.tags = [](void*, zdwl_ipc_manager_v2*, uint32_t tag_cnt) {
for (uint32_t ti=0; ti<=tag_cnt; ti++) {
tagNames.push_back(std::to_string(ti));
}
},
.layout = [](void*, znet_tapesoftware_dwl_wm_v1*, const char* name) {
.layout = [](void*, zdwl_ipc_manager_v2*, 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) {
static const struct zdwl_ipc_output_v2_listener dwlWmMonitorListener {
.toggle_visibility = [](void* mv, zdwl_ipc_output_v2*) {
},
.active = [](void* mv, zdwl_ipc_output_v2*, uint32_t active) {
auto mon = static_cast<Monitor*>(mv);
if (selected) {
if (active) {
selmon = mon;
} else if (selmon == mon) {
selmon = nullptr;
}
mon->bar.setSelected(selected);
mon->bar.setSelected(active);
},
.tag = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t tag, uint32_t state, uint32_t numClients, int32_t focusedClient) {
.tag = [](void* mv, zdwl_ipc_output_v2*, uint32_t tag, uint32_t state, uint32_t numClients, uint32_t focusedClient) {
auto mon = static_cast<Monitor*>(mv);
int tagState = TagState::None;
if (state & ZNET_TAPESOFTWARE_DWL_WM_MONITOR_V1_TAG_STATE_ACTIVE)
if (state & ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE)
tagState |= TagState::Active;
if (state & ZNET_TAPESOFTWARE_DWL_WM_MONITOR_V1_TAG_STATE_URGENT)
if (state & ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT)
tagState |= TagState::Urgent;
mon->bar.setTag(tag, tagState, numClients, focusedClient);
uint32_t mask = 1 << tag;
@ -248,7 +251,7 @@ static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorLis
mon->tags &= ~mask;
}
},
.layout = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t layout) {
.layout = [](void* mv, zdwl_ipc_output_v2*, uint32_t layout) {
auto mon = static_cast<Monitor*>(mv);
if (layout == 2) {
char lout[4] = "[M]";
@ -261,14 +264,27 @@ static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorLis
mon->bar.setLayout(layoutNames[layout]);
}
},
.title = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, const char* title) {
.title = [](void* mv, zdwl_ipc_output_v2*, const char* title) {
auto mon = static_cast<Monitor*>(mv);
mon->bar.setTitle(title);
},
.frame = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*) {
.appid = [](void* mv, zdwl_ipc_output_v2*, const char* appid) {
//auto mon = static_cast<Monitor*>(mv);
},
.layout_symbol = [](void* mv, zdwl_ipc_output_v2*, const char* layout) {
auto mon = static_cast<Monitor*>(mv);
mon->bar.setLayout(layout);
},
.frame = [](void* mv, zdwl_ipc_output_v2*) {
auto mon = static_cast<Monitor*>(mv);
mon->hasData = true;
updatemon(*mon);
},
.fullscreen = [](void* mv, zdwl_ipc_output_v2*, uint32_t is_fullscreen) {
// auto mon = static_cast<Monitor*>(mv);
},
.floating = [](void* mv, zdwl_ipc_output_v2*, uint32_t is_floating) {
//auto mon = static_cast<Monitor*>(mv);
}
};
@ -277,8 +293,8 @@ void setupMonitor(uint32_t name, wl_output* 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);
monitor.dwlMonitor.reset(zdwl_ipc_manager_v2_get_output(dwlWm, monitor.wlOutput.get()));
zdwl_ipc_output_v2_add_listener(monitor.dwlMonitor.get(), &dwlWmMonitorListener, &monitor);
}
void updatemon(Monitor& mon)
@ -304,7 +320,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");
requireGlobal(dwlWm, "zdwl_ipc_manager_v2_interface");
setupStatusFifo();
wl_display_roundtrip(display); // roundtrip so we receive all dwl tags etc.
@ -318,6 +334,7 @@ void onReady()
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) {
@ -362,6 +379,7 @@ void setupStatusFifo()
static LineBuffer<512> stdinBuffer;
static void onStdin()
{
return;
auto res = stdinBuffer.readLines(
[](void* p, size_t size) { return read(0, p, size); },
[](char* p, size_t size) { handleStdin({p, size}); });
@ -489,14 +507,14 @@ void onGlobalAdd(void*, wl_registry* registry, uint32_t name, const char* interf
auto reg = HandleGlobalHelper { registry, name, interface };
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;
if (reg.handle(wlrLayerShell, zwlr_layer_shell_v1_interface, 1)) return;
if (reg.handle(xdgOutputManager, zxdg_output_manager_v1_interface, 3)) return;
if (reg.handle(xdgWmBase, xdg_wm_base_interface, 2)) {
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);
if (reg.handle(dwlWm, zdwl_ipc_manager_v2_interface, 1)) {
zdwl_ipc_manager_v2_add_listener(dwlWm, &dwlWmListener, nullptr);
return;
}
if (wl_seat* wlSeat; reg.handle(wlSeat, wl_seat_interface, 7)) {
@ -526,6 +544,7 @@ static const struct wl_registry_listener registry_listener = {
int main(int argc, char* argv[])
{
int opt;
while ((opt = getopt(argc, argv, "chvs:")) != -1) {
switch (opt) {
case 's':
@ -701,4 +720,3 @@ void diesys(const char* why) {
cleanup();
exit(1);
}