receive selected/layout/title

This commit is contained in:
Raphael Robatsch 2021-10-25 21:54:14 +02:00
parent 629e8f6e1c
commit 8a5c52d2db
6 changed files with 59 additions and 15 deletions

View file

@ -49,6 +49,12 @@
</description> </description>
<arg name="name" type="string"/> <arg name="name" type="string"/>
</event> </event>
<event name="layout">
<description summary="announces the presence of a layout">
</description>
<arg name="name" type="string"/>
</event>
</interface> </interface>
<interface name="znet_tapesoftware_dwl_wm_monitor_v1" version="1"> <interface name="znet_tapesoftware_dwl_wm_monitor_v1" version="1">
@ -66,8 +72,14 @@
</description> </description>
</request> </request>
<event name="selected">
<description summary="updates the selected state of the monitor">
</description>
<arg name="selected" type="int"/>
</event>
<event name="tag"> <event name="tag">
<description summary="sent every time a tag state gets updated"> <description summary="updates the state of one tag">
</description> </description>
<arg name="tag" type="int"/> <arg name="tag" type="int"/>
<arg name="state" type="uint" enum="tag_state"/> <arg name="state" type="uint" enum="tag_state"/>
@ -75,6 +87,18 @@
<arg name="focused_client" type="int" summary="-1 if there is no focused client"/> <arg name="focused_client" type="int" summary="-1 if there is no focused client"/>
</event> </event>
<event name="layout">
<description summary="updates the selected layout">
</description>
<arg name="layout" type="int"/>
</event>
<event name="title">
<description summary="updates the focused client">
</description>
<arg name="title" type="string"/>
</event>
<event name="frame"> <event name="frame">
<description summary="sent after all other events have been sent. allows for atomic updates."> <description summary="sent after all other events have been sent. allows for atomic updates.">
</description> </description>

View file

@ -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_size(_layerSurface.get(), 0, barSize);
zwlr_layer_surface_v1_set_exclusive_zone(_layerSurface.get(), barSize); zwlr_layer_surface_v1_set_exclusive_zone(_layerSurface.get(), barSize);
wl_surface_commit(_surface.get()); wl_surface_commit(_surface.get());
_windowTitle = "Window title";
_status = "Status";
} }
void Bar::click(int x, int) 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; t.focusedClient = focusedClient;
} }
void Bar::setStatus(const QString &status) void Bar::setSelected(bool selected) { _selected = selected; }
{ void Bar::setLayout(int layout) { _layout = layout; }
_status = status; 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) void Bar::layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height)
{ {
@ -114,8 +111,9 @@ void Bar::render()
painter.setFont(font); painter.setFont(font);
renderTags(); renderTags();
setColorScheme(colorActive); setColorScheme(_selected ? colorActive : colorInactive);
renderText(_windowTitle); renderText(layoutNames[_layout]);
renderText(_title);
renderStatus(); renderStatus();
_painter = nullptr; _painter = nullptr;
@ -161,7 +159,7 @@ void Bar::renderText(const QString &text)
void Bar::renderStatus() void Bar::renderStatus()
{ {
_painter->fillRect(_x, 0, _bufs->width-_x, _bufs->height, _painter->brush()); _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; _x = _bufs->width - size;
_painter->drawText(paddingX+_x, _textY, _status); _painter->drawText(paddingX+_x, _textY, _status);
_x = _bufs->width; _x = _bufs->width;

View file

@ -32,7 +32,9 @@ class Bar {
bool _invalid {false}; bool _invalid {false};
std::vector<Tag> _tags; std::vector<Tag> _tags;
QString _windowTitle; int _layout;
bool _selected;
QString _title;
QString _status; QString _status;
void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height); void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height);
@ -46,7 +48,10 @@ public:
Bar(); Bar();
const wl_surface* surface() const; const wl_surface* surface() const;
void create(wl_output *output); 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 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 setStatus(const QString &status);
void invalidate(); void invalidate();
void click(int x, int y); void click(int x, int y);

View file

@ -15,6 +15,7 @@ extern wl_compositor *compositor;
extern wl_shm *shm; extern wl_shm *shm;
extern zwlr_layer_shell_v1 *wlrLayerShell; extern zwlr_layer_shell_v1 *wlrLayerShell;
extern std::vector<QString> tagNames; extern std::vector<QString> tagNames;
extern std::vector<QString> layoutNames;
struct ColorScheme { struct ColorScheme {
QColor fg, bg; QColor fg, bg;

View file

@ -11,8 +11,8 @@ constexpr int paddingY = 3;
constexpr const char *fontFamily = "Source Sans Pro"; constexpr const char *fontFamily = "Source Sans Pro";
constexpr int fontSizePt = 12; 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 colorInactive = {QColor(0xbb, 0xbb, 0xbb), QColor(0x22, 0x22, 0x22)};
constexpr ColorScheme colorActive = {QColor(255, 255, 255), QColor(0, 0, 255)}; constexpr ColorScheme colorActive = {QColor(0xee, 0xee, 0xee), QColor(0x00, 0x55, 0x77)};
constexpr ColorScheme colorUrgent = {colorActive.bg, colorActive.fg}; constexpr ColorScheme colorUrgent = {colorActive.bg, colorActive.fg};

View file

@ -43,6 +43,7 @@ wl_shm *shm;
zwlr_layer_shell_v1 *wlrLayerShell; zwlr_layer_shell_v1 *wlrLayerShell;
znet_tapesoftware_dwl_wm_v1 *dwlWm; znet_tapesoftware_dwl_wm_v1 *dwlWm;
std::vector<QString> tagNames; std::vector<QString> tagNames;
std::vector<QString> layoutNames;
static bool ready; static bool ready;
static std::vector<Monitor> monitors; static std::vector<Monitor> monitors;
static QString lastStatus; 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) { .tag = [](void*, znet_tapesoftware_dwl_wm_v1*, const char *name) {
tagNames.push_back(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 { 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<Monitor*>(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) { .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<Monitor*>(mv); auto mon = static_cast<Monitor*>(mv);
mon->bar->setTag(tag, static_cast<znet_tapesoftware_dwl_wm_monitor_v1_tag_state>(state), numClients, focusedClient); mon->bar->setTag(tag, static_cast<znet_tapesoftware_dwl_wm_monitor_v1_tag_state>(state), numClients, focusedClient);
}, },
.layout = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, int32_t layout) {
auto mon = static_cast<Monitor*>(mv);
mon->bar->setLayout(layout);
},
.title = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, const char *title) {
auto mon = static_cast<Monitor*>(mv);
mon->bar->setTitle(title);
},
.frame = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*) { .frame = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*) {
auto mon = static_cast<Monitor*>(mv); auto mon = static_cast<Monitor*>(mv);
if (mon->created) { if (mon->created) {