Configurable colors
This commit is contained in:
parent
4c0b1f31fe
commit
120af1612f
4 changed files with 26 additions and 7 deletions
19
src/bar.cpp
19
src/bar.cpp
|
@ -44,9 +44,6 @@ void Bar::layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height
|
||||||
_bufs.emplace(width, height, WL_SHM_FORMAT_XRGB8888);
|
_bufs.emplace(width, height, WL_SHM_FORMAT_XRGB8888);
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
static QBrush inactiveBg = {QColor::fromRgb(0, 0, 0)};
|
|
||||||
static QBrush activeBg = QBrush {QColor::fromRgb(0, 0, 255)};
|
|
||||||
static QPen fg = QPen {QBrush {QColor::fromRgb(255, 255, 255)}, 1};
|
|
||||||
|
|
||||||
void Bar::render()
|
void Bar::render()
|
||||||
{
|
{
|
||||||
|
@ -58,29 +55,37 @@ void Bar::render()
|
||||||
QImage::Format_ARGB32
|
QImage::Format_ARGB32
|
||||||
};
|
};
|
||||||
auto painter = QPainter {&img};
|
auto painter = QPainter {&img};
|
||||||
|
_painter = &painter;
|
||||||
auto font = painter.font();
|
auto font = painter.font();
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
font.setPixelSize(18);
|
font.setPixelSize(18);
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
painter.setPen(fg);
|
|
||||||
|
|
||||||
painter.fillRect(0, 0, img.width(), img.height(), activeBg);
|
setColorScheme(colorActive);
|
||||||
|
painter.fillRect(0, 0, img.width(), img.height(), painter.brush());
|
||||||
_fontMetrics.emplace(painter.font());
|
_fontMetrics.emplace(painter.font());
|
||||||
_textY = _fontMetrics->ascent() + paddingY;
|
_textY = _fontMetrics->ascent() + paddingY;
|
||||||
renderTags(painter);
|
renderTags(painter);
|
||||||
|
|
||||||
|
_painter = nullptr;
|
||||||
wl_surface_attach(_surface, _bufs->buffer(), 0, 0);
|
wl_surface_attach(_surface, _bufs->buffer(), 0, 0);
|
||||||
wl_surface_commit(_surface);
|
wl_surface_commit(_surface);
|
||||||
_bufs->flip();
|
_bufs->flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bar::setColorScheme(const ColorScheme &scheme)
|
||||||
|
{
|
||||||
|
_painter->setBrush(QBrush {scheme.bg});
|
||||||
|
_painter->setPen(QPen {QBrush {scheme.fg}, 1});
|
||||||
|
}
|
||||||
|
|
||||||
void Bar::renderTags(QPainter &painter)
|
void Bar::renderTags(QPainter &painter)
|
||||||
{
|
{
|
||||||
auto x = 0;
|
auto x = 0;
|
||||||
for (const auto &tag : _tags) {
|
for (const auto &tag : _tags) {
|
||||||
auto size = textWidth(tag.name) + paddingX*2;
|
auto size = textWidth(tag.name) + paddingX*2;
|
||||||
auto& bg = tag.active ? activeBg : inactiveBg;
|
setColorScheme(tag.active ? colorActive : colorInactive);
|
||||||
painter.fillRect(x, 0, size, barSize, bg);
|
painter.fillRect(x, 0, size, barSize, _painter->brush());
|
||||||
painter.drawText(paddingX+x, _textY, tag.name);
|
painter.drawText(paddingX+x, _textY, tag.name);
|
||||||
x += size;
|
x += size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
|
#include <QPainter>
|
||||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "shm_buffer.hpp"
|
#include "shm_buffer.hpp"
|
||||||
|
@ -21,6 +22,7 @@ class Bar {
|
||||||
|
|
||||||
wl_surface *_surface {nullptr};
|
wl_surface *_surface {nullptr};
|
||||||
zwlr_layer_surface_v1 *_layerSurface {nullptr};
|
zwlr_layer_surface_v1 *_layerSurface {nullptr};
|
||||||
|
QPainter *_painter {nullptr};
|
||||||
std::optional<QFontMetrics> _fontMetrics;
|
std::optional<QFontMetrics> _fontMetrics;
|
||||||
std::optional<ShmBuffer> _bufs;
|
std::optional<ShmBuffer> _bufs;
|
||||||
std::vector<Tag> _tags;
|
std::vector<Tag> _tags;
|
||||||
|
@ -30,6 +32,7 @@ class Bar {
|
||||||
void render();
|
void render();
|
||||||
void renderTags(QPainter &painter);
|
void renderTags(QPainter &painter);
|
||||||
int textWidth(const QString &text);
|
int textWidth(const QString &text);
|
||||||
|
void setColorScheme(const ColorScheme &scheme);
|
||||||
public:
|
public:
|
||||||
explicit Bar(const wl_output *output);
|
explicit Bar(const wl_output *output);
|
||||||
~Bar();
|
~Bar();
|
||||||
|
|
|
@ -3,9 +3,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
#include <QColor>
|
||||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||||
|
|
||||||
extern wl_display *display;
|
extern wl_display *display;
|
||||||
extern wl_compositor *compositor;
|
extern wl_compositor *compositor;
|
||||||
extern wl_shm *shm;
|
extern wl_shm *shm;
|
||||||
extern zwlr_layer_shell_v1 *wlrLayerShell;
|
extern zwlr_layer_shell_v1 *wlrLayerShell;
|
||||||
|
|
||||||
|
struct ColorScheme {
|
||||||
|
QColor fg, bg;
|
||||||
|
};
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
// somebar - dwl bar
|
// somebar - dwl bar
|
||||||
// See LICENSE file for copyright and license details.
|
// See LICENSE file for copyright and license details.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "common.hpp"
|
||||||
|
|
||||||
constexpr int barSize = 26;
|
constexpr int barSize = 26;
|
||||||
constexpr bool topbar = 1;
|
constexpr bool topbar = 1;
|
||||||
constexpr int paddingX = 10;
|
constexpr int paddingX = 10;
|
||||||
constexpr int paddingY = 3;
|
constexpr int paddingY = 3;
|
||||||
|
|
||||||
|
constexpr ColorScheme colorInactive = {QColor(255, 255, 255), QColor(0, 0, 0)};
|
||||||
|
constexpr ColorScheme colorActive = {QColor(255, 255, 255), QColor(0, 0, 255)};
|
||||||
|
|
Loading…
Reference in a new issue