dont deadlock while receiving events
This commit is contained in:
parent
0b5710da3e
commit
7298730969
7 changed files with 134 additions and 80 deletions
46
src/bar.cpp
46
src/bar.cpp
|
|
@ -27,25 +27,25 @@ static QFont getFont()
|
|||
font.setBold(fontBold);
|
||||
return font;
|
||||
}
|
||||
static QFont font = getFont();
|
||||
static QFontMetrics fontMetrics = QFontMetrics {font};
|
||||
|
||||
Bar::Bar(const wl_output *output)
|
||||
: _font {getFont()}
|
||||
, _fontMetrics {_font}
|
||||
{
|
||||
_surface = wl_compositor_create_surface(compositor);
|
||||
_layerSurface = zwlr_layer_shell_v1_get_layer_surface(wlrLayerShell,
|
||||
_surface, nullptr, ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "net.tapesoftware.Somebar");
|
||||
zwlr_layer_surface_v1_add_listener(_layerSurface, &_layerSurfaceListener, this);
|
||||
_surface.reset(wl_compositor_create_surface(compositor));
|
||||
_layerSurface.reset(zwlr_layer_shell_v1_get_layer_surface(wlrLayerShell,
|
||||
_surface.get(), nullptr, ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "net.tapesoftware.Somebar"));
|
||||
zwlr_layer_surface_v1_add_listener(_layerSurface.get(), &_layerSurfaceListener, this);
|
||||
auto anchor = topbar ? ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP : ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
||||
zwlr_layer_surface_v1_set_anchor(_layerSurface,
|
||||
zwlr_layer_surface_v1_set_anchor(_layerSurface.get(),
|
||||
anchor | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
|
||||
|
||||
auto barSize = _fontMetrics.ascent() + _fontMetrics.descent() + paddingY * 2;
|
||||
_textY = _fontMetrics.ascent() + paddingY;
|
||||
auto barSize = fontMetrics.ascent() + fontMetrics.descent() + paddingY * 2;
|
||||
_textY = fontMetrics.ascent() + paddingY;
|
||||
|
||||
zwlr_layer_surface_v1_set_size(_layerSurface, 0, barSize);
|
||||
zwlr_layer_surface_v1_set_exclusive_zone(_layerSurface, barSize);
|
||||
wl_surface_commit(_surface);
|
||||
zwlr_layer_surface_v1_set_size(_layerSurface.get(), 0, barSize);
|
||||
zwlr_layer_surface_v1_set_exclusive_zone(_layerSurface.get(), barSize);
|
||||
wl_surface_commit(_surface.get());
|
||||
|
||||
for (auto tag : tagNames) {
|
||||
_tags.push_back({ tag, false });
|
||||
|
|
@ -54,11 +54,7 @@ Bar::Bar(const wl_output *output)
|
|||
_status = "Status";
|
||||
}
|
||||
|
||||
Bar::~Bar()
|
||||
{
|
||||
wl_surface_destroy(_surface);
|
||||
zwlr_layer_surface_v1_destroy(_layerSurface);
|
||||
}
|
||||
const wl_surface* Bar::surface() const { return _surface.get(); }
|
||||
|
||||
void Bar::click(int x, int)
|
||||
{
|
||||
|
|
@ -75,9 +71,9 @@ void Bar::invalidate()
|
|||
{
|
||||
if (_invalid) return;
|
||||
_invalid = true;
|
||||
auto frame = wl_surface_frame(_surface);
|
||||
auto frame = wl_surface_frame(_surface.get());
|
||||
wl_callback_add_listener(frame, &_frameListener, this);
|
||||
wl_surface_commit(_surface);
|
||||
wl_surface_commit(_surface.get());
|
||||
}
|
||||
|
||||
void Bar::setStatus(const QString &status)
|
||||
|
|
@ -88,7 +84,7 @@ void Bar::setStatus(const QString &status)
|
|||
|
||||
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.get(), serial);
|
||||
_bufs.emplace(width, height, WL_SHM_FORMAT_XRGB8888);
|
||||
render();
|
||||
}
|
||||
|
|
@ -105,7 +101,7 @@ void Bar::render()
|
|||
auto painter = QPainter {&img};
|
||||
_painter = &painter;
|
||||
_x = 0;
|
||||
painter.setFont(_font);
|
||||
painter.setFont(font);
|
||||
|
||||
setColorScheme(colorActive);
|
||||
painter.fillRect(0, 0, img.width(), img.height(), painter.brush());
|
||||
|
|
@ -115,9 +111,9 @@ void Bar::render()
|
|||
renderStatus();
|
||||
|
||||
_painter = nullptr;
|
||||
wl_surface_attach(_surface, _bufs->buffer(), 0, 0);
|
||||
wl_surface_damage(_surface, 0, 0, INT_MAX, INT_MAX);
|
||||
wl_surface_commit(_surface);
|
||||
wl_surface_attach(_surface.get(), _bufs->buffer(), 0, 0);
|
||||
wl_surface_damage(_surface.get(), 0, 0, INT_MAX, INT_MAX);
|
||||
wl_surface_commit(_surface.get());
|
||||
_bufs->flip();
|
||||
_invalid = false;
|
||||
}
|
||||
|
|
@ -156,5 +152,5 @@ void Bar::renderStatus()
|
|||
|
||||
int Bar::textWidth(const QString &text)
|
||||
{
|
||||
return _fontMetrics.size(Qt::TextSingleLine, text).width();
|
||||
return fontMetrics.size(Qt::TextSingleLine, text).width();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue