refactor: standardize headers to #pragma once, add [[nodiscard]]/[[maybe_unused]] annotations

This commit is contained in:
2026-07-02 02:07:04 -04:00
parent 969a6c4ecb
commit c529815d54
10 changed files with 35 additions and 47 deletions
+13 -15
View File
@@ -1,5 +1,4 @@
#ifndef PEACHWM_CLIENT_H #pragma once
#define PEACHWM_CLIENT_H
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/util/box.h> #include <wlr/util/box.h>
@@ -77,21 +76,21 @@ typedef struct {
} LayerSurface; } LayerSurface;
/* Function declarations */ /* Function declarations */
int client_is_x11(Client *c); [[nodiscard]] int client_is_x11(Client *c);
struct wlr_surface *client_surface(Client *c); struct wlr_surface *client_surface(Client *c);
int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl); [[nodiscard]] int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl);
void client_activate_surface(struct wlr_surface *s, int activated); void client_activate_surface(struct wlr_surface *s, int activated);
uint32_t client_set_bounds(Client *c, int32_t width, int32_t height); uint32_t client_set_bounds(Client *c, int32_t width, int32_t height);
const char *client_get_appid(Client *c); [[nodiscard]] const char *client_get_appid(Client *c);
void client_get_clip(Client *c, struct wlr_box *clip); void client_get_clip(Client *c, struct wlr_box *clip);
void client_get_geometry(Client *c, struct wlr_box *geom); void client_get_geometry(Client *c, struct wlr_box *geom);
Client *client_get_parent(Client *c); [[nodiscard]] Client *client_get_parent(Client *c);
int client_has_children(Client *c); [[nodiscard]] int client_has_children(Client *c);
const char *client_get_title(Client *c); [[nodiscard]] const char *client_get_title(Client *c);
int client_is_float_type(Client *c); [[nodiscard]] int client_is_float_type(Client *c);
int client_is_rendered_on_mon(Client *c, Monitor *m); [[nodiscard]] int client_is_rendered_on_mon(Client *c, Monitor *m);
int client_is_stopped(Client *c); [[nodiscard]] int client_is_stopped(Client *c);
int client_is_unmanaged(Client *c); [[nodiscard]] int client_is_unmanaged(Client *c);
void client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb); void client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb);
void client_send_close(Client *c); void client_send_close(Client *c);
void client_set_border_color(Client *c, const float color[static 4]); void client_set_border_color(Client *c, const float color[static 4]);
@@ -100,7 +99,6 @@ void client_set_scale(struct wlr_surface *s, float scale);
uint32_t client_set_size(Client *c, uint32_t width, uint32_t height); uint32_t client_set_size(Client *c, uint32_t width, uint32_t height);
void client_set_tiled(Client *c, uint32_t edges); void client_set_tiled(Client *c, uint32_t edges);
void client_set_suspended(Client *c, int suspended); void client_set_suspended(Client *c, int suspended);
int client_wants_focus(Client *c); [[nodiscard]] int client_wants_focus(Client *c);
int client_wants_fullscreen(Client *c); [[nodiscard]] int client_wants_fullscreen(Client *c);
#endif /* PEACHWM_CLIENT_H */
+1 -3
View File
@@ -1,5 +1,4 @@
#ifndef PEACHWM_EXT_WORKSPACE_H #pragma once
#define PEACHWM_EXT_WORKSPACE_H
#include "monitor.h" #include "monitor.h"
@@ -20,4 +19,3 @@ void ext_workspace_cleanupmon(Monitor *m);
void ext_workspace_printstatus(Monitor *m); void ext_workspace_printstatus(Monitor *m);
void workspaces_init(void); void workspaces_init(void);
#endif /* PEACHWM_EXT_WORKSPACE_H */
+1 -3
View File
@@ -20,8 +20,7 @@
* 0x80000002 = mode 0x80000003 = window * 0x80000002 = mode 0x80000003 = window
*/ */
#ifndef PEACHWM_IPC_SOCKET_H #pragma once
#define PEACHWM_IPC_SOCKET_H
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@@ -88,4 +87,3 @@ void ipc_socket_send_workspace_event(const char *change);
void ipc_socket_send_window_event(const char *change); void ipc_socket_send_window_event(const char *change);
void ipc_socket_send_output_event(void); void ipc_socket_send_output_event(void);
#endif /* PEACHWM_IPC_SOCKET_H */
+1 -3
View File
@@ -1,5 +1,4 @@
#ifndef PEACHWM_MONITOR_H #pragma once
#define PEACHWM_MONITOR_H
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_scene.h> #include <wlr/types/wlr_scene.h>
@@ -55,4 +54,3 @@ struct Monitor {
struct Client *scratchpad_current; /* currently visible scratchpad client */ struct Client *scratchpad_current; /* currently visible scratchpad client */
}; };
#endif /* PEACHWM_MONITOR_H */
+1 -3
View File
@@ -1,5 +1,4 @@
#ifndef PEACHWM_PARSER_H #pragma once
#define PEACHWM_PARSER_H
#include <stdint.h> #include <stdint.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
@@ -159,4 +158,3 @@ WatchState *config_watch_start(
void config_watch_stop(WatchState *ws); void config_watch_stop(WatchState *ws);
#endif
+2 -2
View File
@@ -193,12 +193,12 @@ client_get_parent(Client *c)
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
if (c->surface.xwayland->parent) if (c->surface.xwayland->parent)
toplevel_from_wlr_surface(c->surface.xwayland->parent->surface, &p, nullptr); (void)toplevel_from_wlr_surface(c->surface.xwayland->parent->surface, &p, nullptr);
return p; return p;
} }
#endif #endif
if (c->surface.xdg->toplevel->parent) if (c->surface.xdg->toplevel->parent)
toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, &p, nullptr); (void)toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, &p, nullptr);
return p; return p;
} }
+4 -6
View File
@@ -1,5 +1,4 @@
#ifndef PEACHWM_LAYOUT_H #pragma once
#define PEACHWM_LAYOUT_H
#include "monitor.h" #include "monitor.h"
#include "client.h" #include "client.h"
@@ -25,11 +24,11 @@ void master(Monitor *m);
void monocle(Monitor *m); void monocle(Monitor *m);
/* helpers used across modules */ /* helpers used across modules */
int current_tag_idx(Monitor *m); [[nodiscard]] int current_tag_idx(Monitor *m);
const Layout *curlayout(Monitor *m); [[nodiscard]] const Layout *curlayout(Monitor *m);
/* dwindle tree helpers (exposed for swapdir) */ /* dwindle tree helpers (exposed for swapdir) */
DwindleNode *dwindle_find_leaf(DwindleNode *n, Client *c); [[nodiscard]] DwindleNode *dwindle_find_leaf(DwindleNode *n, Client *c);
void dwindle_recalc(DwindleNode *n, int gap); void dwindle_recalc(DwindleNode *n, int gap);
/* lifecycle helpers (called from peachwm.c unmap/cleanup) */ /* lifecycle helpers (called from peachwm.c unmap/cleanup) */
@@ -40,4 +39,3 @@ void master_remove_client(Client *c);
/* tile drag swap (called from buttonpress handler) */ /* tile drag swap (called from buttonpress handler) */
void swaptiled(Client *a, Client *b); void swaptiled(Client *a, Client *b);
#endif /* PEACHWM_LAYOUT_H */
+7 -7
View File
@@ -564,7 +564,7 @@ static void arrangelayers(Monitor *m) {
static void dispatch_action(const char *action, static void dispatch_action(const char *action,
const char (*args)[CFG_MAX_STRLEN], int nargs); const char (*args)[CFG_MAX_STRLEN], int nargs);
static void axisnotify(struct wl_listener *listener, void *data) { static void axisnotify(struct wl_listener *listener, [[maybe_unused]] void *data) {
/* This event is forwarded by the cursor when a pointer emits an axis event, /* This event is forwarded by the cursor when a pointer emits an axis event,
* for example when you move the scroll wheel. */ * for example when you move the scroll wheel. */
struct wlr_pointer_axis_event *event = data; struct wlr_pointer_axis_event *event = data;
@@ -591,7 +591,7 @@ static void axisnotify(struct wl_listener *listener, void *data) {
event->source, event->relative_direction); event->source, event->relative_direction);
} }
static void buttonpress(struct wl_listener *listener, void *data) { static void buttonpress(struct wl_listener *listener, [[maybe_unused]] void *data) {
struct wlr_pointer_button_event *event = data; struct wlr_pointer_button_event *event = data;
struct wlr_keyboard *keyboard; struct wlr_keyboard *keyboard;
uint32_t mods; uint32_t mods;
@@ -935,7 +935,7 @@ static void createdecoration(struct wl_listener *listener, void *data) {
requestdecorationmode(&c->set_decoration_mode, deco); requestdecorationmode(&c->set_decoration_mode, deco);
} }
static void createidleinhibitor(struct wl_listener *listener, void *data) { static void createidleinhibitor(struct wl_listener *listener, [[maybe_unused]] void *data) {
struct wlr_idle_inhibitor_v1 *idle_inhibitor = data; struct wlr_idle_inhibitor_v1 *idle_inhibitor = data;
LISTEN_STATIC(&idle_inhibitor->events.destroy, destroyidleinhibitor); LISTEN_STATIC(&idle_inhibitor->events.destroy, destroyidleinhibitor);
@@ -1285,7 +1285,7 @@ static void cursorwarptohint(void) {
double sx = active_constraint->current.cursor_hint.x; double sx = active_constraint->current.cursor_hint.x;
double sy = active_constraint->current.cursor_hint.y; double sy = active_constraint->current.cursor_hint.y;
toplevel_from_wlr_surface(active_constraint->surface, &c, nullptr); (void)toplevel_from_wlr_surface(active_constraint->surface, &c, nullptr);
if (c && active_constraint->current.cursor_hint.enabled) { if (c && active_constraint->current.cursor_hint.enabled) {
wlr_cursor_warp(cursor, nullptr, sx + c->geom.x + c->bw, wlr_cursor_warp(cursor, nullptr, sx + c->geom.x + c->bw,
sy + c->geom.y + c->bw); sy + c->geom.y + c->bw);
@@ -1348,7 +1348,7 @@ destroy:
free(lock); free(lock);
} }
static void destroylocksurface(struct wl_listener *listener, void *data) { static void destroylocksurface(struct wl_listener *listener, [[maybe_unused]] void *data) {
Monitor *m = wl_container_of(listener, m, destroy_lock_surface); Monitor *m = wl_container_of(listener, m, destroy_lock_surface);
struct wlr_session_lock_surface_v1 *surface, *lock_surface = m->lock_surface; struct wlr_session_lock_surface_v1 *surface, *lock_surface = m->lock_surface;
@@ -2217,7 +2217,7 @@ static void motionnotify(uint32_t time, struct wlr_input_device *device, double
if (active_constraint && cursor_mode != CurResize && if (active_constraint && cursor_mode != CurResize &&
cursor_mode != CurMove) { cursor_mode != CurMove) {
toplevel_from_wlr_surface(active_constraint->surface, &c, nullptr); (void)toplevel_from_wlr_surface(active_constraint->surface, &c, nullptr);
if (c && if (c &&
active_constraint->surface == seat->pointer_state.focused_surface) { active_constraint->surface == seat->pointer_state.focused_surface) {
sx = cursor->x - c->geom.x - c->bw; sx = cursor->x - c->geom.x - c->bw;
@@ -3632,7 +3632,7 @@ static void updatetitle(struct wl_listener *listener, void *data) {
static void urgent(struct wl_listener *listener, void *data) { static void urgent(struct wl_listener *listener, void *data) {
struct wlr_xdg_activation_v1_request_activate_event *event = data; struct wlr_xdg_activation_v1_request_activate_event *event = data;
Client *c = nullptr; Client *c = nullptr;
toplevel_from_wlr_surface(event->surface, &c, nullptr); (void)toplevel_from_wlr_surface(event->surface, &c, nullptr);
if (!c || c == focustop(selmon)) if (!c || c == focustop(selmon))
return; return;
+3 -2
View File
@@ -1,7 +1,8 @@
/* Copyright and license details as described in the LICENSE file. */ /* Copyright and license details as described in the LICENSE file. */
#pragma once
#include <stddef.h> #include <stddef.h>
[[noreturn]] void die(const char *fmt, ...); [[noreturn]] void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size); [[nodiscard]] void *ecalloc(size_t nmemb, size_t size);
int fd_set_nonblock(int fd); [[nodiscard]] int fd_set_nonblock(int fd);
+2 -3
View File
@@ -6,8 +6,7 @@
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" #error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif #endif
#ifndef WLR_TYPES_WLR_EXT_WORKSPACE_V1_H #pragma once
#define WLR_TYPES_WLR_EXT_WORKSPACE_V1_H
#include <wayland-protocols/ext-workspace-v1-enum.h> #include <wayland-protocols/ext-workspace-v1-enum.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
@@ -147,4 +146,4 @@ void wlr_ext_workspace_handle_v1_set_urgent(
void wlr_ext_workspace_handle_v1_set_hidden( void wlr_ext_workspace_handle_v1_set_hidden(
struct wlr_ext_workspace_handle_v1 *workspace, bool enabled); struct wlr_ext_workspace_handle_v1 *workspace, bool enabled);
#endif