somebar/src/common.hpp

75 lines
2.1 KiB
C++
Raw Normal View History

2021-10-20 18:20:27 +00:00
// somebar - dwl bar
// See LICENSE file for copyright and license details.
#pragma once
2021-10-25 17:02:35 +00:00
#include <memory>
2021-10-27 15:24:47 +00:00
#include <string>
2021-10-24 17:04:29 +00:00
#include <vector>
2021-10-26 09:40:46 +00:00
#include <wayland-client.h>
#include <linux/input-event-codes.h>
2021-10-27 15:24:47 +00:00
#include <cairo/cairo.h>
#include <pango/pango.h>
2021-10-20 18:20:27 +00:00
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
2021-10-25 17:02:35 +00:00
#include "net-tapesoftware-dwl-wm-unstable-v1-client-protocol.h"
2021-10-20 18:20:27 +00:00
2021-10-27 15:24:47 +00:00
struct Color {
2021-10-29 18:33:27 +00:00
Color() {}
constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255) : r(r), g(g), b(b), a(a) { }
uint8_t r, g, b, a {255};
2021-10-27 15:24:47 +00:00
};
2021-10-26 09:40:46 +00:00
struct ColorScheme {
2021-10-29 18:33:27 +00:00
Color fg, bg;
2021-10-26 09:40:46 +00:00
};
union Arg {
unsigned int ui;
const void* v;
2021-10-26 09:40:46 +00:00
};
struct Monitor;
enum { ClkNone, ClkTagBar, ClkLayoutSymbol, ClkWinTitle, ClkStatusText };
struct Button {
int control;
int btn; // <linux/input-event-codes.h>
void (*func)(Monitor& mon, const Arg& arg);
const Arg arg;
};
extern wl_display* display;
extern wl_compositor* compositor;
extern wl_shm* shm;
extern zwlr_layer_shell_v1* wlrLayerShell;
2021-10-27 15:24:47 +00:00
extern std::vector<std::string> tagNames;
extern std::vector<std::string> layoutNames;
2021-10-22 13:42:42 +00:00
void view(Monitor& m, const Arg& arg);
void toggleview(Monitor& m, const Arg& arg);
void setlayout(Monitor& m, const Arg& arg);
void tag(Monitor& m, const Arg& arg);
void toggletag(Monitor& m, const Arg& arg);
void spawn(Monitor&, const Arg& arg);
[[noreturn]] void die(const char* why);
2021-10-26 09:40:46 +00:00
2021-10-25 17:02:35 +00:00
// wayland smart pointers
template<typename T>
struct wl_deleter;
#define WL_DELETER(type, fn) template<> struct wl_deleter<type> { \
2021-10-29 18:33:27 +00:00
void operator()(type* v) { if(v) fn(v); } \
}
2021-10-25 17:02:35 +00:00
template<typename T>
using wl_unique_ptr = std::unique_ptr<T, wl_deleter<T>>;
WL_DELETER(wl_buffer, wl_buffer_destroy);
WL_DELETER(wl_output, wl_output_release);
2021-10-26 10:59:41 +00:00
WL_DELETER(wl_pointer, wl_pointer_release);
WL_DELETER(wl_seat, wl_seat_release);
WL_DELETER(wl_surface, wl_surface_destroy);
2021-10-25 17:02:35 +00:00
WL_DELETER(znet_tapesoftware_dwl_wm_monitor_v1, znet_tapesoftware_dwl_wm_monitor_v1_release);
2021-10-26 10:59:41 +00:00
WL_DELETER(zwlr_layer_surface_v1, zwlr_layer_surface_v1_destroy);
2021-10-27 15:24:47 +00:00
WL_DELETER(cairo_t, cairo_destroy);
WL_DELETER(cairo_surface_t, cairo_surface_destroy);
WL_DELETER(PangoContext, g_object_unref);
WL_DELETER(PangoLayout, g_object_unref);