style: pointer/reference goes to type, not name
This commit is contained in:
parent
ebf06f932f
commit
30329b71f4
6 changed files with 105 additions and 103 deletions
109
src/main.cpp
109
src/main.cpp
|
|
@ -1,14 +1,13 @@
|
|||
// somebar - dwl bar
|
||||
// See LICENSE file for copyright and license details.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <list>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/signalfd.h>
|
||||
|
|
@ -38,7 +37,7 @@ struct Monitor {
|
|||
|
||||
struct SeatPointer {
|
||||
wl_unique_ptr<wl_pointer> wlPointer;
|
||||
Bar *focusedBar;
|
||||
Bar* focusedBar;
|
||||
int x, y;
|
||||
std::vector<int> btns;
|
||||
};
|
||||
|
|
@ -52,25 +51,25 @@ static void updatemon(Monitor &mon);
|
|||
static void setupStatusFifo();
|
||||
static void onStatus();
|
||||
static void cleanup();
|
||||
static void requireGlobal(const void *p, const char *name);
|
||||
static void requireGlobal(const void* p, const char* name);
|
||||
static void waylandFlush();
|
||||
[[noreturn]] static void diesys(const char *why);
|
||||
[[noreturn]] static void diesys(const char* why);
|
||||
|
||||
wl_display *display;
|
||||
wl_compositor *compositor;
|
||||
wl_shm *shm;
|
||||
zwlr_layer_shell_v1 *wlrLayerShell;
|
||||
znet_tapesoftware_dwl_wm_v1 *dwlWm;
|
||||
wl_display* display;
|
||||
wl_compositor* compositor;
|
||||
wl_shm* shm;
|
||||
zwlr_layer_shell_v1* wlrLayerShell;
|
||||
znet_tapesoftware_dwl_wm_v1* dwlWm;
|
||||
std::vector<std::string> tagNames;
|
||||
std::vector<std::string> layoutNames;
|
||||
static xdg_wm_base *xdgWmBase;
|
||||
static zxdg_output_manager_v1 *xdgOutputManager;
|
||||
static wl_surface *cursorSurface;
|
||||
static wl_cursor_image *cursorImage;
|
||||
static xdg_wm_base* xdgWmBase;
|
||||
static zxdg_output_manager_v1* xdgOutputManager;
|
||||
static wl_surface* cursorSurface;
|
||||
static wl_cursor_image* cursorImage;
|
||||
static bool ready;
|
||||
static std::list<Monitor> monitors;
|
||||
static std::list<Seat> seats;
|
||||
static Monitor *selmon;
|
||||
static Monitor* selmon;
|
||||
static std::string lastStatus;
|
||||
static std::string statusFifoName;
|
||||
static int epoll {-1};
|
||||
|
|
@ -79,27 +78,27 @@ static int statusFifoFd {-1};
|
|||
static int statusFifoWriter {-1};
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
void spawn(Monitor&, const Arg &arg)
|
||||
void spawn(Monitor&, const Arg& arg)
|
||||
{
|
||||
if (fork() == 0) {
|
||||
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 = {
|
||||
[](void*, xdg_wm_base *sender, uint32_t serial) {
|
||||
[](void*, xdg_wm_base* sender, uint32_t 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_size = [](void*, zxdg_output_v1*, int, int) { },
|
||||
.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);
|
||||
monitor.xdgName = name;
|
||||
zxdg_output_v1_destroy(xdgOutput);
|
||||
|
|
@ -131,19 +130,19 @@ static const struct zxdg_output_v1_listener xdgOutputListener = {
|
|||
|
||||
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 != end(monitors) && mon->bar ? &*mon->bar : nullptr;
|
||||
}
|
||||
static const struct wl_pointer_listener pointerListener = {
|
||||
.enter = [](void *sp, wl_pointer *pointer, uint32_t serial,
|
||||
wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
|
||||
.enter = [](void* sp, wl_pointer* pointer, uint32_t serial,
|
||||
wl_surface* surface, wl_fixed_t x, wl_fixed_t y)
|
||||
{
|
||||
auto& seat = *static_cast<Seat*>(sp);
|
||||
seat.pointer->focusedBar = barFromSurface(surface);
|
||||
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];
|
||||
cursorSurface = wl_compositor_create_surface(compositor);
|
||||
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,
|
||||
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);
|
||||
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);
|
||||
seat.pointer->x = wl_fixed_to_int(x);
|
||||
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 it = std::find(begin(seat.pointer->btns), end(seat.pointer->btns), button);
|
||||
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);
|
||||
}
|
||||
},
|
||||
.axis = [](void *sp, wl_pointer*, uint32_t, uint32_t, wl_fixed_t) { },
|
||||
.frame = [](void *sp, wl_pointer*) {
|
||||
.axis = [](void* sp, wl_pointer*, uint32_t, uint32_t, wl_fixed_t) { },
|
||||
.frame = [](void* sp, wl_pointer*) {
|
||||
auto& seat = *static_cast<Seat*>(sp);
|
||||
if (!seat.pointer->focusedBar) return;
|
||||
for (auto btn : seat.pointer->btns) {
|
||||
|
|
@ -185,7 +184,7 @@ static const struct wl_pointer_listener pointerListener = {
|
|||
};
|
||||
|
||||
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 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 = {
|
||||
.tag = [](void*, znet_tapesoftware_dwl_wm_v1*, const char *name) {
|
||||
.tag = [](void*, znet_tapesoftware_dwl_wm_v1*, const char* 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);
|
||||
},
|
||||
};
|
||||
|
||||
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);
|
||||
if (selected) {
|
||||
selmon = mon;
|
||||
|
|
@ -219,26 +218,26 @@ static const struct znet_tapesoftware_dwl_wm_monitor_v1_listener dwlWmMonitorLis
|
|||
}
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
mon->hasData = true;
|
||||
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.bar.emplace(&monitor);
|
||||
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);
|
||||
}
|
||||
|
||||
static void updatemon(Monitor &mon)
|
||||
static void updatemon(Monitor& mon)
|
||||
{
|
||||
if (!mon.hasData) return;
|
||||
if (mon.desiredVisibility) {
|
||||
|
|
@ -317,7 +316,7 @@ const std::string argAll = "all";
|
|||
const std::string argSelected = "selected";
|
||||
|
||||
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 isAll = name == argAll;
|
||||
|
|
@ -338,10 +337,10 @@ static LineBuffer<512> _statusBuffer;
|
|||
static void onStatus()
|
||||
{
|
||||
_statusBuffer.readLines(
|
||||
[](void *p, size_t size) {
|
||||
[](void* p, size_t size) {
|
||||
return read(statusFifoFd, p, size);
|
||||
},
|
||||
[](const char *buffer, size_t n) {
|
||||
[](const char* buffer, size_t n) {
|
||||
auto str = std::string {buffer, n};
|
||||
if (str.rfind(prefixStatus, 0) == 0) {
|
||||
lastStatus = str.substr(prefixStatus.size());
|
||||
|
|
@ -362,18 +361,18 @@ static void onStatus()
|
|||
}
|
||||
|
||||
struct HandleGlobalHelper {
|
||||
wl_registry *registry;
|
||||
wl_registry* registry;
|
||||
uint32_t name;
|
||||
const char *interface;
|
||||
const char* interface;
|
||||
|
||||
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;
|
||||
store = static_cast<T>(wl_registry_bind(registry, name, &iface, version));
|
||||
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 };
|
||||
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;
|
||||
}
|
||||
}
|
||||
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; });
|
||||
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,
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int opt;
|
||||
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);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void diesys(const char *why) {
|
||||
void diesys(const char* why) {
|
||||
perror(why);
|
||||
cleanup();
|
||||
exit(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue