somebar/src/bar.hpp

52 lines
1.3 KiB
C++
Raw Normal View History

2021-10-20 20:20:27 +02:00
// somebar - dwl bar
// See LICENSE file for copyright and license details.
#pragma once
2021-10-20 20:45:23 +02:00
#include <optional>
2021-10-22 15:34:19 +02:00
#include <vector>
2021-10-20 20:20:27 +02:00
#include <wayland-client.h>
2021-10-22 15:34:19 +02:00
#include <QString>
#include <QFontMetrics>
2021-10-22 15:42:42 +02:00
#include <QPainter>
2021-10-20 20:20:27 +02:00
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "common.hpp"
#include "shm_buffer.hpp"
2021-10-22 15:34:19 +02:00
struct Tag {
QString name;
bool active;
2021-10-22 17:26:05 +02:00
int x;
2021-10-22 15:34:19 +02:00
};
2021-10-20 20:20:27 +02:00
class Bar {
2021-10-20 20:45:23 +02:00
static const zwlr_layer_surface_v1_listener _layerSurfaceListener;
2021-10-22 16:52:04 +02:00
static const wl_callback_listener _frameListener;
2021-10-20 20:45:23 +02:00
2021-10-20 20:20:27 +02:00
wl_surface *_surface {nullptr};
zwlr_layer_surface_v1 *_layerSurface {nullptr};
2021-10-22 15:42:42 +02:00
QPainter *_painter {nullptr};
2021-10-22 15:49:09 +02:00
QFont _font;
QFontMetrics _fontMetrics;
2021-10-20 20:45:23 +02:00
std::optional<ShmBuffer> _bufs;
2021-10-22 15:55:29 +02:00
int _textY, _x;
2021-10-22 16:52:04 +02:00
bool _invalid {false};
2021-10-22 15:55:29 +02:00
2021-10-22 15:34:19 +02:00
std::vector<Tag> _tags;
2021-10-22 15:55:29 +02:00
QString _windowTitle;
QString _status;
2021-10-20 20:45:23 +02:00
void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height);
2021-10-20 21:09:19 +02:00
void render();
2021-10-22 15:55:29 +02:00
void renderTags();
void renderStatus();
void renderText(const QString &text);
2021-10-22 15:34:19 +02:00
int textWidth(const QString &text);
2021-10-22 15:42:42 +02:00
void setColorScheme(const ColorScheme &scheme);
2021-10-22 16:52:04 +02:00
void invalidate();
2021-10-20 20:20:27 +02:00
public:
2021-10-20 20:45:23 +02:00
explicit Bar(const wl_output *output);
2021-10-22 16:52:04 +02:00
void setStatus(const QString &status);
2021-10-22 17:26:05 +02:00
void click(int x, int y);
2021-10-20 20:45:23 +02:00
~Bar();
2021-10-20 20:20:27 +02:00
};