somebar/src/bar.hpp

75 lines
1.9 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-27 17:24:47 +02:00
#include <string>
2021-10-22 15:34:19 +02:00
#include <vector>
2021-10-20 20:20:27 +02:00
#include <wayland-client.h>
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "common.hpp"
#include "shm_buffer.hpp"
2021-10-22 15:34:19 +02:00
2021-10-27 17:24:47 +02:00
class BarComponent {
2021-10-29 20:33:27 +02:00
std::unique_ptr<std::string> _text;
2021-10-27 17:24:47 +02:00
public:
2021-10-29 20:33:27 +02:00
BarComponent();
explicit BarComponent(wl_unique_ptr<PangoLayout> layout);
int width() const;
void setText(const std::string& text);
wl_unique_ptr<PangoLayout> pangoLayout;
int x {0};
2021-10-27 17:24:47 +02:00
};
2021-10-22 15:34:19 +02:00
struct Tag {
2021-10-29 22:22:58 +02:00
int state;
2021-10-29 20:33:27 +02:00
int numClients;
int focusedClient;
BarComponent component;
2021-10-22 15:34:19 +02:00
};
2021-10-20 20:20:27 +02:00
2021-10-26 11:40:46 +02:00
struct Monitor;
2021-10-20 20:20:27 +02:00
class Bar {
2021-10-29 20:33:27 +02:00
static const zwlr_layer_surface_v1_listener _layerSurfaceListener;
static const wl_callback_listener _frameListener;
2021-10-20 20:45:23 +02:00
2021-10-29 20:33:27 +02:00
wl_unique_ptr<wl_surface> _surface;
wl_unique_ptr<zwlr_layer_surface_v1> _layerSurface;
wl_unique_ptr<PangoContext> _pangoContext;
std::optional<ShmBuffer> _bufs;
std::vector<Tag> _tags;
BarComponent _layoutCmp, _titleCmp, _statusCmp;
bool _selected;
bool _invalid {false};
2021-10-27 17:24:47 +02:00
2021-10-29 20:33:27 +02:00
// only vaild during render()
cairo_t* _painter {nullptr};
int _x;
ColorScheme _colorScheme;
2021-10-20 20:45:23 +02:00
2021-10-29 20:33:27 +02:00
void layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height);
void render();
void renderTags();
void renderStatus();
2021-10-27 17:24:47 +02:00
2021-10-29 20:33:27 +02:00
// low-level rendering
void setColorScheme(const ColorScheme& scheme, bool invert = false);
void beginFg();
void beginBg();
void renderComponent(BarComponent& component);
BarComponent createComponent(const std::string& initial = {});
2021-10-20 20:20:27 +02:00
public:
Bar();
2021-10-29 20:33:27 +02:00
const wl_surface* surface() const;
bool visible() const;
void show(wl_output* output);
void hide();
2021-10-29 22:22:58 +02:00
void setTag(int tag, int state, int numClients, int focusedClient);
2021-10-29 20:33:27 +02:00
void setSelected(bool selected);
2021-10-29 22:22:58 +02:00
void setLayout(const std::string& layout);
2021-10-29 20:33:27 +02:00
void setTitle(const std::string& title);
void setStatus(const std::string& status);
void invalidate();
void click(Monitor* mon, int x, int y, int btn);
2021-10-20 20:20:27 +02:00
};