refactor: create include/common.h with shared types/macros, deduplicate across 7 files

This commit is contained in:
2026-07-02 01:58:57 -04:00
parent 9581031dac
commit 1e09b182ee
8 changed files with 48 additions and 71 deletions
+1 -11
View File
@@ -14,17 +14,7 @@
#include "ipc.h"
#include "monitor.h"
#include "util.h"
#define LENGTH(X) (sizeof X / sizeof X[0])
#define TAGMASK ((1u << TAGCOUNT) - 1)
/* Forward declarations from peachwm.c */
typedef union {
int i;
uint32_t ui;
float f;
const void *v;
} Arg;
#include "common.h"
void view(const Arg *arg);
void toggleview(const Arg *arg);
+1 -11
View File
@@ -29,17 +29,7 @@
#include "ipc.h"
#include "ipc_socket.h"
#include "util.h"
/* ------------------------------------------------------------------ */
/* Types from peachwm.c needed by command handlers */
/* ------------------------------------------------------------------ */
typedef union {
int i;
uint32_t ui;
float f;
const void *v;
} Arg;
#include "common.h"
/* ------------------------------------------------------------------ */
/* Functions from peachwm.c called by IPC command handler */
+1 -13
View File
@@ -8,19 +8,7 @@
#include "util.h"
#include "layout.h"
#include "parser/parser.h"
/* macros (duplicated from peachwm.c) */
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define TAGMASK ((1u << TAGCOUNT) - 1)
static inline int visibleon(Client *c, Monitor *m) {
return m && c->mon == m
? (c->isscratchpad ? m->scratchpad_visible
: (int)(c->tags & m->tagset[m->seltags]))
: 0;
}
#define VISIBLEON(C, M) visibleon((C), (M))
#include "common.h"
/* globals from peachwm.c */
extern struct wl_list clients;
+1 -4
View File
@@ -82,14 +82,11 @@
#include "ext_workspace.h"
#include "ipc.h"
#include "ipc_socket.h"
#include "common.h"
/* macros */
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
#define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A))
#define TAGMASK ((1u << TAGCOUNT) - 1)
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
#define LISTEN_STATIC(E, H) \
do { \
-11
View File
@@ -14,17 +14,6 @@
#include "monitor.h"
#include "scratchpad.h"
/* ------------------------------------------------------------------ */
/* Visibility helper — duplicated from layout.c / peachwm.c */
/* ------------------------------------------------------------------ */
int visibleon(Client *c, Monitor *m) {
return m && c->mon == m
? (c->isscratchpad ? m->scratchpad_visible
: (int)(c->tags & m->tagset[m->seltags]))
: 0;
}
/* ------------------------------------------------------------------ */
/* Extern functions from peachwm.c / layout.c / ipc client */
/* ------------------------------------------------------------------ */
+1 -14
View File
@@ -3,6 +3,7 @@
#include <wlr/types/wlr_scene.h>
#include "client.h"
#include "monitor.h"
#include "common.h"
/* Forward declarations from peachwm.c */
extern struct wl_list clients;
@@ -29,20 +30,6 @@ enum {
/* NUM_LAYERS = 9 */
};
/* The argument union used by keybind functions.
* Both peachwm.c and the scratchpad module need to agree on this,
* so it sits here rather than privately in each .c file. */
typedef union {
int i;
uint32_t ui;
float f;
const void *v;
} Arg;
/* Scoped visibility helper — also defined (identically) in layout.c */
int visibleon(Client *c, Monitor *m);
#define VISIBLEON(C, M) visibleon((C), (M))
/* ----------- Extracted scratchpad functions ----------- */
/* Reparent + resize every scratchpad client of @m to a centred 80% box */