style: pointer/reference goes to type, not name

This commit is contained in:
Raphael Robatsch 2021-10-29 20:19:09 +02:00
parent ebf06f932f
commit 30329b71f4
6 changed files with 105 additions and 103 deletions

View File

@ -11,13 +11,13 @@
#include "pango/pango-layout.h" #include "pango/pango-layout.h"
const zwlr_layer_surface_v1_listener Bar::_layerSurfaceListener = { const zwlr_layer_surface_v1_listener Bar::_layerSurfaceListener = {
[](void *owner, zwlr_layer_surface_v1*, uint32_t serial, uint32_t width, uint32_t height) [](void* owner, zwlr_layer_surface_v1*, uint32_t serial, uint32_t width, uint32_t height)
{ {
static_cast<Bar*>(owner)->layerSurfaceConfigure(serial, width, height); static_cast<Bar*>(owner)->layerSurfaceConfigure(serial, width, height);
} }
}; };
const wl_callback_listener Bar::_frameListener = { const wl_callback_listener Bar::_frameListener = {
[](void *owner, wl_callback *cb, uint32_t) [](void* owner, wl_callback* cb, uint32_t)
{ {
static_cast<Bar*>(owner)->render(); static_cast<Bar*>(owner)->render();
wl_callback_destroy(cb); wl_callback_destroy(cb);
@ -25,7 +25,7 @@ const wl_callback_listener Bar::_frameListener = {
}; };
struct Font { struct Font {
PangoFontDescription *description; PangoFontDescription* description;
int height {0}; int height {0};
}; };
static Font getFont() static Font getFont()
@ -60,15 +60,13 @@ int BarComponent::width() const
pango_layout_get_size(pangoLayout.get(), &w, &h); pango_layout_get_size(pangoLayout.get(), &w, &h);
return PANGO_PIXELS(w); return PANGO_PIXELS(w);
} }
void BarComponent::setText(const std::string &text) void BarComponent::setText(const std::string& text)
{ {
auto chars = new char[text.size()]; _text = std::make_unique<std::string>(text);
text.copy(chars, text.size()); pango_layout_set_text(pangoLayout.get(), _text->c_str(), _text->size());
_text.reset(chars);
pango_layout_set_text(pangoLayout.get(), chars, text.size());
} }
Bar::Bar(Monitor *mon) Bar::Bar(Monitor* mon)
{ {
_mon = mon; _mon = mon;
_pangoContext.reset(pango_font_map_create_context(pango_cairo_font_map_get_default())); _pangoContext.reset(pango_font_map_create_context(pango_cairo_font_map_get_default()));
@ -84,7 +82,7 @@ Bar::Bar(Monitor *mon)
const wl_surface* Bar::surface() const { return _surface.get(); } const wl_surface* Bar::surface() const { return _surface.get(); }
bool Bar::visible() const { return _surface.get(); } bool Bar::visible() const { return _surface.get(); }
void Bar::show(wl_output *output) void Bar::show(wl_output* output)
{ {
if (visible()) return; if (visible()) return;
_surface.reset(wl_compositor_create_surface(compositor)); _surface.reset(wl_compositor_create_surface(compositor));
@ -118,8 +116,8 @@ void Bar::setTag(int tag, znet_tapesoftware_dwl_wm_monitor_v1_tag_state state, i
} }
void Bar::setSelected(bool selected) { _selected = selected; } void Bar::setSelected(bool selected) { _selected = selected; }
void Bar::setLayout(int layout) { _layoutCmp.setText(layoutNames[layout]); } void Bar::setLayout(int layout) { _layoutCmp.setText(layoutNames[layout]); }
void Bar::setTitle(const std::string &title) { _titleCmp.setText(title); } void Bar::setTitle(const std::string& title) { _titleCmp.setText(title); }
void Bar::setStatus(const std::string &status) { _statusCmp.setText(status); } void Bar::setStatus(const std::string& status) { _statusCmp.setText(status); }
void Bar::invalidate() void Bar::invalidate()
{ {
@ -133,7 +131,7 @@ void Bar::invalidate()
void Bar::click(int x, int, int btn) void Bar::click(int x, int, int btn)
{ {
Arg arg = {0}; Arg arg = {0};
Arg *argp = nullptr; Arg* argp = nullptr;
int control = ClkNone; int control = ClkNone;
if (x > _statusCmp.x) { if (x > _statusCmp.x) {
control = ClkStatusText; control = ClkStatusText;
@ -225,17 +223,20 @@ void Bar::renderStatus()
renderComponent(_statusCmp); renderComponent(_statusCmp);
} }
void Bar::setColorScheme(const ColorScheme &scheme, bool invert) void Bar::setColorScheme(const ColorScheme& scheme, bool invert)
{ {
_colorScheme = invert _colorScheme = invert
? ColorScheme {scheme.bg, scheme.fg} ? ColorScheme {scheme.bg, scheme.fg}
: ColorScheme {scheme.fg, scheme.bg}; : ColorScheme {scheme.fg, scheme.bg};
} }
static void setColor(cairo_t *painter, const Color &color) { cairo_set_source_rgba(painter, color.r/255.0, color.g/255.0, color.b/255.0, color.a/255.0); } static void setColor(cairo_t* painter, const Color& color)
{
cairo_set_source_rgba(painter, color.r/255.0, color.g/255.0, color.b/255.0, color.a/255.0);
}
void Bar::beginFg() { setColor(_painter, _colorScheme.fg); } void Bar::beginFg() { setColor(_painter, _colorScheme.fg); }
void Bar::beginBg() { setColor(_painter, _colorScheme.bg); } void Bar::beginBg() { setColor(_painter, _colorScheme.bg); }
void Bar::renderComponent(BarComponent &component) void Bar::renderComponent(BarComponent& component)
{ {
pango_cairo_update_layout(_painter, component.pangoLayout.get()); pango_cairo_update_layout(_painter, component.pangoLayout.get());
auto size = component.width() + paddingX*2; auto size = component.width() + paddingX*2;

View File

@ -11,12 +11,12 @@
#include "shm_buffer.hpp" #include "shm_buffer.hpp"
class BarComponent { class BarComponent {
std::unique_ptr<char[]> _text; std::unique_ptr<std::string> _text;
public: public:
BarComponent(); BarComponent();
explicit BarComponent(wl_unique_ptr<PangoLayout> layout); explicit BarComponent(wl_unique_ptr<PangoLayout> layout);
int width() const; int width() const;
void setText(const std::string &text); void setText(const std::string& text);
wl_unique_ptr<PangoLayout> pangoLayout; wl_unique_ptr<PangoLayout> pangoLayout;
int x {0}; int x {0};
}; };
@ -36,7 +36,7 @@ class Bar {
wl_unique_ptr<wl_surface> _surface; wl_unique_ptr<wl_surface> _surface;
wl_unique_ptr<zwlr_layer_surface_v1> _layerSurface; wl_unique_ptr<zwlr_layer_surface_v1> _layerSurface;
wl_unique_ptr<PangoContext> _pangoContext; wl_unique_ptr<PangoContext> _pangoContext;
Monitor *_mon; Monitor* _mon;
std::optional<ShmBuffer> _bufs; std::optional<ShmBuffer> _bufs;
std::vector<Tag> _tags; std::vector<Tag> _tags;
BarComponent _layoutCmp, _titleCmp, _statusCmp; BarComponent _layoutCmp, _titleCmp, _statusCmp;
@ -44,7 +44,7 @@ class Bar {
bool _invalid {false}; bool _invalid {false};
// only vaild during render() // only vaild during render()
cairo_t *_painter {nullptr}; cairo_t* _painter {nullptr};
int _x; int _x;
ColorScheme _colorScheme; ColorScheme _colorScheme;
@ -54,22 +54,22 @@ class Bar {
void renderStatus(); void renderStatus();
// low-level rendering // low-level rendering
void setColorScheme(const ColorScheme &scheme, bool invert=false); void setColorScheme(const ColorScheme& scheme, bool invert = false);
void beginFg(); void beginFg();
void beginBg(); void beginBg();
void renderComponent(BarComponent &component); void renderComponent(BarComponent& component);
BarComponent createComponent(const std::string &initial = {}); BarComponent createComponent(const std::string& initial = {});
public: public:
Bar(Monitor *mon); Bar(Monitor *mon);
const wl_surface* surface() const; const wl_surface* surface() const;
bool visible() const; bool visible() const;
void show(wl_output *output); void show(wl_output* output);
void hide(); void hide();
void setTag(int tag, znet_tapesoftware_dwl_wm_monitor_v1_tag_state state, int numClients, int focusedClient); void setTag(int tag, znet_tapesoftware_dwl_wm_monitor_v1_tag_state state, int numClients, int focusedClient);
void setSelected(bool selected); void setSelected(bool selected);
void setLayout(int layout); void setLayout(int layout);
void setTitle(const std::string &title); void setTitle(const std::string& title);
void setStatus(const std::string &status); void setStatus(const std::string& status);
void invalidate(); void invalidate();
void click(int x, int y, int btn); void click(int x, int y, int btn);
}; };

View File

@ -22,7 +22,7 @@ struct ColorScheme {
}; };
union Arg { union Arg {
unsigned int ui; unsigned int ui;
const void *v; const void* v;
}; };
struct Monitor; struct Monitor;
@ -30,29 +30,31 @@ enum { ClkNone, ClkTagBar, ClkLayoutSymbol, ClkWinTitle, ClkStatusText };
struct Button { struct Button {
int control; int control;
int btn; // <linux/input-event-codes.h> int btn; // <linux/input-event-codes.h>
void (*func)(Monitor &mon, const Arg &arg); void (*func)(Monitor& mon, const Arg& arg);
const Arg arg; const Arg arg;
}; };
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;
extern std::vector<std::string> tagNames; extern std::vector<std::string> tagNames;
extern std::vector<std::string> layoutNames; extern std::vector<std::string> layoutNames;
void view(Monitor &m, const Arg &arg); void view(Monitor& m, const Arg& arg);
void toggleview(Monitor &m, const Arg &arg); void toggleview(Monitor& m, const Arg& arg);
void setlayout(Monitor &m, const Arg &arg); void setlayout(Monitor& m, const Arg& arg);
void tag(Monitor &m, const Arg &arg); void tag(Monitor& m, const Arg& arg);
void toggletag(Monitor &m, const Arg &arg); void toggletag(Monitor& m, const Arg& arg);
void spawn(Monitor&, const Arg &arg); void spawn(Monitor&, const Arg& arg);
[[noreturn]] void die(const char *why); [[noreturn]] void die(const char* why);
// wayland smart pointers // wayland smart pointers
template<typename T> template<typename T>
struct wl_deleter; struct wl_deleter;
#define WL_DELETER(type, fn) template<> struct wl_deleter<type> { void operator()(type *v) { if(v) fn(v); } } #define WL_DELETER(type, fn) template<> struct wl_deleter<type> { \
void operator()(type* v) { if(v) fn(v); } \
}
template<typename T> template<typename T>
using wl_unique_ptr = std::unique_ptr<T, wl_deleter<T>>; using wl_unique_ptr = std::unique_ptr<T, wl_deleter<T>>;

View File

@ -10,11 +10,11 @@ constexpr int paddingX = 10;
constexpr int paddingY = 3; constexpr int paddingY = 3;
// See https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html // See https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html
constexpr const char *font = "Sans 12"; constexpr const char* font = "Sans 12";
constexpr ColorScheme colorInactive = {Color(0xbb, 0xbb, 0xbb), Color(0x22, 0x22, 0x22)}; constexpr ColorScheme colorInactive = {Color(0xbb, 0xbb, 0xbb), Color(0x22, 0x22, 0x22)};
constexpr ColorScheme colorActive = {Color(0xee, 0xee, 0xee), Color(0x00, 0x55, 0x77)}; constexpr ColorScheme colorActive = {Color(0xee, 0xee, 0xee), Color(0x00, 0x55, 0x77)};
constexpr const char *termcmd[] = {"foot", nullptr}; constexpr const char* termcmd[] = {"foot", nullptr};
constexpr Button buttons[] = { constexpr Button buttons[] = {
{ ClkTagBar, BTN_LEFT, view, {0} }, { ClkTagBar, BTN_LEFT, view, {0} },

View File

@ -1,14 +1,13 @@
// somebar - dwl bar // somebar - dwl bar
// See LICENSE file for copyright and license details. // See LICENSE file for copyright and license details.
#include <stdio.h>
#include <fcntl.h>
#include <math.h>
#include <signal.h>
#include <algorithm> #include <algorithm>
#include <cstdio>
#include <list> #include <list>
#include <optional> #include <optional>
#include <vector> #include <vector>
#include <fcntl.h>
#include <signal.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/signalfd.h> #include <sys/signalfd.h>
@ -38,7 +37,7 @@ struct Monitor {
struct SeatPointer { struct SeatPointer {
wl_unique_ptr<wl_pointer> wlPointer; wl_unique_ptr<wl_pointer> wlPointer;
Bar *focusedBar; Bar* focusedBar;
int x, y; int x, y;
std::vector<int> btns; std::vector<int> btns;
}; };
@ -52,25 +51,25 @@ static void updatemon(Monitor &mon);
static void setupStatusFifo(); static void setupStatusFifo();
static void onStatus(); static void onStatus();
static void cleanup(); static void cleanup();
static void requireGlobal(const void *p, const char *name); static void requireGlobal(const void* p, const char* name);
static void waylandFlush(); static void waylandFlush();
[[noreturn]] static void diesys(const char *why); [[noreturn]] static void diesys(const char* why);
wl_display *display; wl_display* display;
wl_compositor *compositor; wl_compositor* compositor;
wl_shm *shm; wl_shm* shm;
zwlr_layer_shell_v1 *wlrLayerShell; zwlr_layer_shell_v1* wlrLayerShell;
znet_tapesoftware_dwl_wm_v1 *dwlWm; znet_tapesoftware_dwl_wm_v1* dwlWm;
std::vector<std::string> tagNames; std::vector<std::string> tagNames;
std::vector<std::string> layoutNames; std::vector<std::string> layoutNames;
static xdg_wm_base *xdgWmBase; static xdg_wm_base* xdgWmBase;
static zxdg_output_manager_v1 *xdgOutputManager; static zxdg_output_manager_v1* xdgOutputManager;
static wl_surface *cursorSurface; static wl_surface* cursorSurface;
static wl_cursor_image *cursorImage; static wl_cursor_image* cursorImage;
static bool ready; static bool ready;
static std::list<Monitor> monitors; static std::list<Monitor> monitors;
static std::list<Seat> seats; static std::list<Seat> seats;
static Monitor *selmon; static Monitor* selmon;
static std::string lastStatus; static std::string lastStatus;
static std::string statusFifoName; static std::string statusFifoName;
static int epoll {-1}; static int epoll {-1};
@ -79,27 +78,27 @@ static int statusFifoFd {-1};
static int statusFifoWriter {-1}; static int statusFifoWriter {-1};
static bool quitting {false}; static bool quitting {false};
void view(Monitor &m, const Arg &arg) void view(Monitor& m, const Arg& arg)
{ {
znet_tapesoftware_dwl_wm_monitor_v1_set_tags(m.dwlMonitor.get(), arg.ui, 1); znet_tapesoftware_dwl_wm_monitor_v1_set_tags(m.dwlMonitor.get(), arg.ui, 1);
} }
void toggleview(Monitor &m, const Arg &arg) void toggleview(Monitor& m, const Arg& arg)
{ {
znet_tapesoftware_dwl_wm_monitor_v1_set_tags(m.dwlMonitor.get(), arg.ui, 0); znet_tapesoftware_dwl_wm_monitor_v1_set_tags(m.dwlMonitor.get(), arg.ui, 0);
} }
void setlayout(Monitor &m, const Arg &arg) void setlayout(Monitor& m, const Arg& arg)
{ {
znet_tapesoftware_dwl_wm_monitor_v1_set_layout(m.dwlMonitor.get(), arg.ui); znet_tapesoftware_dwl_wm_monitor_v1_set_layout(m.dwlMonitor.get(), arg.ui);
} }
void tag(Monitor &m, const Arg &arg) void tag(Monitor& m, const Arg& arg)
{ {
znet_tapesoftware_dwl_wm_monitor_v1_set_client_tags(m.dwlMonitor.get(), 0, arg.ui); znet_tapesoftware_dwl_wm_monitor_v1_set_client_tags(m.dwlMonitor.get(), 0, arg.ui);
} }
void toggletag(Monitor &m, const Arg &arg) void toggletag(Monitor& m, const Arg& arg)
{ {
znet_tapesoftware_dwl_wm_monitor_v1_set_client_tags(m.dwlMonitor.get(), 0xffffff, arg.ui); znet_tapesoftware_dwl_wm_monitor_v1_set_client_tags(m.dwlMonitor.get(), 0xffffff, arg.ui);
} }
void spawn(Monitor&, const Arg &arg) void spawn(Monitor&, const Arg& arg)
{ {
if (fork() == 0) { if (fork() == 0) {
auto argv = static_cast<char* const*>(arg.v); auto argv = static_cast<char* const*>(arg.v);
@ -112,7 +111,7 @@ void spawn(Monitor&, const Arg &arg)
} }
static const struct xdg_wm_base_listener xdgWmBaseListener = { static const struct xdg_wm_base_listener xdgWmBaseListener = {
[](void*, xdg_wm_base *sender, uint32_t serial) { [](void*, xdg_wm_base* sender, uint32_t serial) {
xdg_wm_base_pong(sender, serial); xdg_wm_base_pong(sender, serial);
} }
}; };
@ -121,7 +120,7 @@ static const struct zxdg_output_v1_listener xdgOutputListener = {
.logical_position = [](void*, zxdg_output_v1*, int, int) { }, .logical_position = [](void*, zxdg_output_v1*, int, int) { },
.logical_size = [](void*, zxdg_output_v1*, int, int) { }, .logical_size = [](void*, zxdg_output_v1*, int, int) { },
.done = [](void*, zxdg_output_v1*) { }, .done = [](void*, zxdg_output_v1*) { },
.name = [](void *mp, zxdg_output_v1 *xdgOutput, const char *name) { .name = [](void* mp, zxdg_output_v1* xdgOutput, const char* name) {
auto& monitor = *static_cast<Monitor*>(mp); auto& monitor = *static_cast<Monitor*>(mp);
monitor.xdgName = name; monitor.xdgName = name;
zxdg_output_v1_destroy(xdgOutput); zxdg_output_v1_destroy(xdgOutput);
@ -131,19 +130,19 @@ static const struct zxdg_output_v1_listener xdgOutputListener = {
static Bar* barFromSurface(const wl_surface *surface) static Bar* barFromSurface(const wl_surface *surface)
{ {
auto mon = std::find_if(begin(monitors), end(monitors), [surface](const Monitor &mon) { auto mon = std::find_if(begin(monitors), end(monitors), [surface](const Monitor& mon) {
return mon.bar && mon.bar->surface() == surface; return mon.bar && mon.bar->surface() == surface;
}); });
return mon != end(monitors) && mon->bar ? &*mon->bar : nullptr; return mon != end(monitors) && mon->bar ? &*mon->bar : nullptr;
} }
static const struct wl_pointer_listener pointerListener = { static const struct wl_pointer_listener pointerListener = {
.enter = [](void *sp, wl_pointer *pointer, uint32_t serial, .enter = [](void* sp, wl_pointer* pointer, uint32_t serial,
wl_surface *surface, wl_fixed_t x, wl_fixed_t y) wl_surface* surface, wl_fixed_t x, wl_fixed_t y)
{ {
auto& seat = *static_cast<Seat*>(sp); auto& seat = *static_cast<Seat*>(sp);
seat.pointer->focusedBar = barFromSurface(surface); seat.pointer->focusedBar = barFromSurface(surface);
if (!cursorImage) { if (!cursorImage) {
auto cursorTheme = wl_cursor_theme_load(NULL, 24, shm); auto cursorTheme = wl_cursor_theme_load(nullptr, 24, shm);
cursorImage = wl_cursor_theme_get_cursor(cursorTheme, "left_ptr")->images[0]; cursorImage = wl_cursor_theme_get_cursor(cursorTheme, "left_ptr")->images[0];
cursorSurface = wl_compositor_create_surface(compositor); cursorSurface = wl_compositor_create_surface(compositor);
wl_surface_attach(cursorSurface, wl_cursor_image_get_buffer(cursorImage), 0, 0); wl_surface_attach(cursorSurface, wl_cursor_image_get_buffer(cursorImage), 0, 0);
@ -152,16 +151,16 @@ static const struct wl_pointer_listener pointerListener = {
wl_pointer_set_cursor(pointer, serial, cursorSurface, wl_pointer_set_cursor(pointer, serial, cursorSurface,
cursorImage->hotspot_x, cursorImage->hotspot_y); cursorImage->hotspot_x, cursorImage->hotspot_y);
}, },
.leave = [](void *sp, wl_pointer*, uint32_t serial, wl_surface*) { .leave = [](void* sp, wl_pointer*, uint32_t serial, wl_surface*) {
auto& seat = *static_cast<Seat*>(sp); auto& seat = *static_cast<Seat*>(sp);
seat.pointer->focusedBar = nullptr; seat.pointer->focusedBar = nullptr;
}, },
.motion = [](void *sp, wl_pointer*, uint32_t, wl_fixed_t x, wl_fixed_t y) { .motion = [](void* sp, wl_pointer*, uint32_t, wl_fixed_t x, wl_fixed_t y) {
auto& seat = *static_cast<Seat*>(sp); auto& seat = *static_cast<Seat*>(sp);
seat.pointer->x = wl_fixed_to_int(x); seat.pointer->x = wl_fixed_to_int(x);
seat.pointer->y = wl_fixed_to_int(y); seat.pointer->y = wl_fixed_to_int(y);
}, },
.button = [](void *sp, wl_pointer*, uint32_t, uint32_t, uint32_t button, uint32_t pressed) { .button = [](void* sp, wl_pointer*, uint32_t, uint32_t, uint32_t button, uint32_t pressed) {
auto& seat = *static_cast<Seat*>(sp); auto& seat = *static_cast<Seat*>(sp);
auto it = std::find(begin(seat.pointer->btns), end(seat.pointer->btns), button); auto it = std::find(begin(seat.pointer->btns), end(seat.pointer->btns), button);
if (pressed == WL_POINTER_BUTTON_STATE_PRESSED && it == end(seat.pointer->btns)) { if (pressed == WL_POINTER_BUTTON_STATE_PRESSED && it == end(seat.pointer->btns)) {
@ -170,8 +169,8 @@ static const struct wl_pointer_listener pointerListener = {
seat.pointer->btns.erase(it); seat.pointer->btns.erase(it);
} }
}, },
.axis = [](void *sp, wl_pointer*, uint32_t, uint32_t, wl_fixed_t) { }, .axis = [](void* sp, wl_pointer*, uint32_t, uint32_t, wl_fixed_t) { },
.frame = [](void *sp, wl_pointer*) { .frame = [](void* sp, wl_pointer*) {
auto& seat = *static_cast<Seat*>(sp); auto& seat = *static_cast<Seat*>(sp);
if (!seat.pointer->focusedBar) return; if (!seat.pointer->focusedBar) return;
for (auto btn : seat.pointer->btns) { for (auto btn : seat.pointer->btns) {
@ -185,7 +184,7 @@ static const struct wl_pointer_listener pointerListener = {
}; };
static const struct wl_seat_listener seatListener = { static const struct wl_seat_listener seatListener = {
.capabilities = [](void *sp, wl_seat*, uint32_t cap) .capabilities = [](void* sp, wl_seat*, uint32_t cap)
{ {
auto& seat = *static_cast<Seat*>(sp); auto& seat = *static_cast<Seat*>(sp);
auto hasPointer = cap & WL_SEAT_CAPABILITY_POINTER; auto hasPointer = cap & WL_SEAT_CAPABILITY_POINTER;
@ -201,16 +200,16 @@ static const struct wl_seat_listener seatListener = {
}; };
static const struct znet_tapesoftware_dwl_wm_v1_listener dwlWmListener = { static const struct znet_tapesoftware_dwl_wm_v1_listener dwlWmListener = {
.tag = [](void*, znet_tapesoftware_dwl_wm_v1*, const char *name) { .tag = [](void*, znet_tapesoftware_dwl_wm_v1*, const char* name) {
tagNames.push_back(name); tagNames.push_back(name);
}, },
.layout = [](void*, znet_tapesoftware_dwl_wm_v1*, const char *name) { .layout = [](void*, znet_tapesoftware_dwl_wm_v1*, const char* name) {
layoutNames.push_back(name); layoutNames.push_back(name);
}, },
}; };
static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorListener { static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorListener {
.selected = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t selected) { .selected = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t selected) {
auto mon = static_cast<Monitor*>(mv); auto mon = static_cast<Monitor*>(mv);
if (selected) { if (selected) {
selmon = mon; selmon = mon;
@ -219,26 +218,26 @@ static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorLis
} }
mon->bar->setSelected(selected); mon->bar->setSelected(selected);
}, },
.tag = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t tag, uint32_t state, uint32_t numClients, int32_t focusedClient) { .tag = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t tag, uint32_t state, uint32_t numClients, int32_t focusedClient) {
auto mon = static_cast<Monitor*>(mv); auto mon = static_cast<Monitor*>(mv);
mon->bar->setTag(tag, static_cast<znet_tapesoftware_dwl_wm_monitor_v1_tag_state>(state), numClients, focusedClient); mon->bar->setTag(tag, static_cast<znet_tapesoftware_dwl_wm_monitor_v1_tag_state>(state), numClients, focusedClient);
}, },
.layout = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t layout) { .layout = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, uint32_t layout) {
auto mon = static_cast<Monitor*>(mv); auto mon = static_cast<Monitor*>(mv);
mon->bar->setLayout(layout); mon->bar->setLayout(layout);
}, },
.title = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*, const char *title) { .title = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*, const char* title) {
auto mon = static_cast<Monitor*>(mv); auto mon = static_cast<Monitor*>(mv);
mon->bar->setTitle(title); mon->bar->setTitle(title);
}, },
.frame = [](void *mv, znet_tapesoftware_dwl_wm_monitor_v1*) { .frame = [](void* mv, znet_tapesoftware_dwl_wm_monitor_v1*) {
auto mon = static_cast<Monitor*>(mv); auto mon = static_cast<Monitor*>(mv);
mon->hasData = true; mon->hasData = true;
updatemon(*mon); updatemon(*mon);
} }
}; };
static void setupMonitor(Monitor &monitor) { static void setupMonitor(Monitor& monitor) {
monitor.dwlMonitor.reset(znet_tapesoftware_dwl_wm_v1_get_monitor(dwlWm, monitor.wlOutput.get())); monitor.dwlMonitor.reset(znet_tapesoftware_dwl_wm_v1_get_monitor(dwlWm, monitor.wlOutput.get()));
monitor.bar.emplace(&monitor); monitor.bar.emplace(&monitor);
monitor.bar->setStatus(lastStatus); monitor.bar->setStatus(lastStatus);
@ -247,7 +246,7 @@ static void setupMonitor(Monitor &monitor) {
znet_tapesoftware_dwl_wm_monitor_v1_add_listener(monitor.dwlMonitor.get(), &dwlWmMonitorListener, &monitor); znet_tapesoftware_dwl_wm_monitor_v1_add_listener(monitor.dwlMonitor.get(), &dwlWmMonitorListener, &monitor);
} }
static void updatemon(Monitor &mon) static void updatemon(Monitor& mon)
{ {
if (!mon.hasData) return; if (!mon.hasData) return;
if (mon.desiredVisibility) { if (mon.desiredVisibility) {
@ -317,7 +316,7 @@ const std::string argAll = "all";
const std::string argSelected = "selected"; const std::string argSelected = "selected";
template<typename T> template<typename T>
static void updateVisibility(const std::string &name, T updater) static void updateVisibility(const std::string& name, T updater)
{ {
auto isCurrent = name == argSelected; auto isCurrent = name == argSelected;
auto isAll = name == argAll; auto isAll = name == argAll;
@ -338,10 +337,10 @@ static LineBuffer<512> _statusBuffer;
static void onStatus() static void onStatus()
{ {
_statusBuffer.readLines( _statusBuffer.readLines(
[](void *p, size_t size) { [](void* p, size_t size) {
return read(statusFifoFd, p, size); return read(statusFifoFd, p, size);
}, },
[](const char *buffer, size_t n) { [](const char* buffer, size_t n) {
auto str = std::string {buffer, n}; auto str = std::string {buffer, n};
if (str.rfind(prefixStatus, 0) == 0) { if (str.rfind(prefixStatus, 0) == 0) {
lastStatus = str.substr(prefixStatus.size()); lastStatus = str.substr(prefixStatus.size());
@ -362,18 +361,18 @@ static void onStatus()
} }
struct HandleGlobalHelper { struct HandleGlobalHelper {
wl_registry *registry; wl_registry* registry;
uint32_t name; uint32_t name;
const char *interface; const char* interface;
template<typename T> template<typename T>
bool handle(T &store, const wl_interface &iface, int version) { bool handle(T& store, const wl_interface& iface, int version) {
if (strcmp(interface, iface.name)) return false; if (strcmp(interface, iface.name)) return false;
store = static_cast<T>(wl_registry_bind(registry, name, &iface, version)); store = static_cast<T>(wl_registry_bind(registry, name, &iface, version));
return true; return true;
} }
}; };
static void registryHandleGlobal(void*, wl_registry *registry, uint32_t name, const char *interface, uint32_t version) static void registryHandleGlobal(void*, wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
{ {
auto reg = HandleGlobalHelper { registry, name, interface }; auto reg = HandleGlobalHelper { registry, name, interface };
if (reg.handle(compositor, wl_compositor_interface, 4)) return; if (reg.handle(compositor, wl_compositor_interface, 4)) return;
@ -401,7 +400,7 @@ static void registryHandleGlobal(void*, wl_registry *registry, uint32_t name, co
return; return;
} }
} }
static void registryHandleRemove(void*, wl_registry *registry, uint32_t name) static void registryHandleRemove(void*, wl_registry* registry, uint32_t name)
{ {
monitors.remove_if([name](const Monitor &mon) { return mon.registryName == name; }); monitors.remove_if([name](const Monitor &mon) { return mon.registryName == name; });
seats.remove_if([name](const Seat &seat) { return seat.name == name; }); seats.remove_if([name](const Seat &seat) { return seat.name == name; });
@ -411,7 +410,7 @@ static const struct wl_registry_listener registry_listener = {
.global_remove = registryHandleRemove, .global_remove = registryHandleRemove,
}; };
int main(int argc, char **argv) int main(int argc, char* argv[])
{ {
int opt; int opt;
while ((opt = getopt(argc, argv, "chv")) != -1) { while ((opt = getopt(argc, argv, "chv")) != -1) {
@ -542,13 +541,13 @@ void waylandFlush()
} }
} }
void die(const char *why) { void die(const char* why) {
fprintf(stderr, "%s\n", why); fprintf(stderr, "%s\n", why);
cleanup(); cleanup();
exit(1); exit(1);
} }
void diesys(const char *why) { void diesys(const char* why) {
perror(why); perror(why);
cleanup(); cleanup();
exit(1); exit(1);

View File

@ -12,11 +12,11 @@ class MemoryMapping {
size_t _size {0}; size_t _size {0};
public: public:
MemoryMapping() { } MemoryMapping() { }
explicit MemoryMapping(void *ptr, size_t size) : _ptr(ptr), _size(size) { } explicit MemoryMapping(void* ptr, size_t size) : _ptr(ptr), _size(size) { }
MemoryMapping(const MemoryMapping&) = delete; MemoryMapping(const MemoryMapping&) = delete;
MemoryMapping(MemoryMapping &&other) { swap(other); } MemoryMapping(MemoryMapping&& other) { swap(other); }
MemoryMapping& operator=(const MemoryMapping &other) = delete; MemoryMapping& operator=(const MemoryMapping& other) = delete;
MemoryMapping& operator=(MemoryMapping &&other) { swap(other); return *this; } MemoryMapping& operator=(MemoryMapping&& other) { swap(other); return *this; }
~MemoryMapping() { if (_ptr) munmap(_ptr, _size); } ~MemoryMapping() { if (_ptr) munmap(_ptr, _size); }
void swap(MemoryMapping &other) { void swap(MemoryMapping &other) {
using std::swap; using std::swap;
@ -29,7 +29,7 @@ public:
// format is must be 32-bit // format is must be 32-bit
class ShmBuffer { class ShmBuffer {
struct Buf { struct Buf {
uint8_t *data {nullptr}; uint8_t* data {nullptr};
wl_unique_ptr<wl_buffer> buffer; wl_unique_ptr<wl_buffer> buffer;
}; };
std::array<Buf, 2> _buffers; std::array<Buf, 2> _buffers;