Update status from pipe
This commit is contained in:
parent
9c08a11b32
commit
58d004ec59
24
src/bar.cpp
24
src/bar.cpp
|
@ -13,6 +13,13 @@ const zwlr_layer_surface_v1_listener Bar::_layerSurfaceListener = {
|
||||||
static_cast<Bar*>(owner)->layerSurfaceConfigure(serial, width, height);
|
static_cast<Bar*>(owner)->layerSurfaceConfigure(serial, width, height);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const wl_callback_listener Bar::_frameListener = {
|
||||||
|
[](void *owner, wl_callback *cb, uint32_t)
|
||||||
|
{
|
||||||
|
static_cast<Bar*>(owner)->render();
|
||||||
|
wl_callback_destroy(cb);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static QFont getFont()
|
static QFont getFont()
|
||||||
{
|
{
|
||||||
|
@ -53,6 +60,21 @@ Bar::~Bar()
|
||||||
zwlr_layer_surface_v1_destroy(_layerSurface);
|
zwlr_layer_surface_v1_destroy(_layerSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bar::invalidate()
|
||||||
|
{
|
||||||
|
if (_invalid) return;
|
||||||
|
_invalid = true;
|
||||||
|
auto frame = wl_surface_frame(_surface);
|
||||||
|
wl_callback_add_listener(frame, &_frameListener, this);
|
||||||
|
wl_surface_commit(_surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Bar::setStatus(const QString &status)
|
||||||
|
{
|
||||||
|
_status = status;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
void Bar::layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height)
|
void Bar::layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
zwlr_layer_surface_v1_ack_configure(_layerSurface, serial);
|
zwlr_layer_surface_v1_ack_configure(_layerSurface, serial);
|
||||||
|
@ -83,8 +105,10 @@ void Bar::render()
|
||||||
|
|
||||||
_painter = nullptr;
|
_painter = nullptr;
|
||||||
wl_surface_attach(_surface, _bufs->buffer(), 0, 0);
|
wl_surface_attach(_surface, _bufs->buffer(), 0, 0);
|
||||||
|
wl_surface_damage(_surface, 0, 0, INT_MAX, INT_MAX);
|
||||||
wl_surface_commit(_surface);
|
wl_surface_commit(_surface);
|
||||||
_bufs->flip();
|
_bufs->flip();
|
||||||
|
_invalid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bar::setColorScheme(const ColorScheme &scheme)
|
void Bar::setColorScheme(const ColorScheme &scheme)
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct Tag {
|
||||||
|
|
||||||
class Bar {
|
class Bar {
|
||||||
static const zwlr_layer_surface_v1_listener _layerSurfaceListener;
|
static const zwlr_layer_surface_v1_listener _layerSurfaceListener;
|
||||||
|
static const wl_callback_listener _frameListener;
|
||||||
|
|
||||||
wl_surface *_surface {nullptr};
|
wl_surface *_surface {nullptr};
|
||||||
zwlr_layer_surface_v1 *_layerSurface {nullptr};
|
zwlr_layer_surface_v1 *_layerSurface {nullptr};
|
||||||
|
@ -27,6 +28,7 @@ class Bar {
|
||||||
QFontMetrics _fontMetrics;
|
QFontMetrics _fontMetrics;
|
||||||
std::optional<ShmBuffer> _bufs;
|
std::optional<ShmBuffer> _bufs;
|
||||||
int _textY, _x;
|
int _textY, _x;
|
||||||
|
bool _invalid {false};
|
||||||
|
|
||||||
std::vector<Tag> _tags;
|
std::vector<Tag> _tags;
|
||||||
QString _windowTitle;
|
QString _windowTitle;
|
||||||
|
@ -39,7 +41,9 @@ class Bar {
|
||||||
void renderText(const QString &text);
|
void renderText(const QString &text);
|
||||||
int textWidth(const QString &text);
|
int textWidth(const QString &text);
|
||||||
void setColorScheme(const ColorScheme &scheme);
|
void setColorScheme(const ColorScheme &scheme);
|
||||||
|
void invalidate();
|
||||||
public:
|
public:
|
||||||
explicit Bar(const wl_output *output);
|
explicit Bar(const wl_output *output);
|
||||||
|
void setStatus(const QString &status);
|
||||||
~Bar();
|
~Bar();
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <optional>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
@ -28,6 +29,7 @@ wl_display *display;
|
||||||
wl_compositor *compositor;
|
wl_compositor *compositor;
|
||||||
wl_shm *shm;
|
wl_shm *shm;
|
||||||
zwlr_layer_shell_v1 *wlrLayerShell;
|
zwlr_layer_shell_v1 *wlrLayerShell;
|
||||||
|
static std::optional<Bar> bar;
|
||||||
static std::string statusFifoName;
|
static std::string statusFifoName;
|
||||||
static int statusFifoFd {-1};
|
static int statusFifoFd {-1};
|
||||||
static int statusFifoWriter {-1};
|
static int statusFifoWriter {-1};
|
||||||
|
@ -48,7 +50,7 @@ static void onReady()
|
||||||
requireGlobal(shm, "wl_shm");
|
requireGlobal(shm, "wl_shm");
|
||||||
requireGlobal(wlrLayerShell, "zwlr_layer_shell_v1");
|
requireGlobal(wlrLayerShell, "zwlr_layer_shell_v1");
|
||||||
setupStatusFifo();
|
setupStatusFifo();
|
||||||
std::ignore = new Bar(nullptr);
|
bar.emplace(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupStatusFifo()
|
static void setupStatusFifo()
|
||||||
|
@ -89,6 +91,9 @@ static void onStatus()
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
auto n = read(statusFifoFd, buffer, sizeof(buffer));
|
auto n = read(statusFifoFd, buffer, sizeof(buffer));
|
||||||
auto str = QString::fromUtf8(buffer, n);
|
auto str = QString::fromUtf8(buffer, n);
|
||||||
|
if (bar) {
|
||||||
|
bar->setStatus(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HandleGlobalHelper {
|
struct HandleGlobalHelper {
|
||||||
|
|
Loading…
Reference in New Issue