MAJOR REFACTOR (2)

This commit is contained in:
Emile Clark-Boman 2025-08-27 17:59:12 +10:00
parent 1e69ae1e21
commit f4fa50d4bf
13 changed files with 133 additions and 98 deletions

View file

@ -1,3 +1,5 @@
#include "lib/client.h"
void applybounds(Client *c, struct wlr_box *bbox) { void applybounds(Client *c, struct wlr_box *bbox) {
/* set minimum possible */ /* set minimum possible */
c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width); c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width);

View file

@ -9,6 +9,8 @@
enum { XDGShell, LayerShell, X11 }; /* client types */ enum { XDGShell, LayerShell, X11 }; /* client types */
typedef struct Monitor Monitor; // forward declare
typedef struct { typedef struct {
/* Must keep this field first */ /* Must keep this field first */
unsigned int type; /* XDGShell or X11* */ unsigned int type; /* XDGShell or X11* */

View file

@ -1,3 +1,12 @@
#include "sys/types.h"
#include "crywl.h"
/* Static Variables */
static pid_t child_pid = -1;
void chvt(const Arg *arg) { wlr_session_change_vt(session, arg->ui); } void chvt(const Arg *arg) { wlr_session_change_vt(session, arg->ui); }
void cleanup(void) { void cleanup(void) {
@ -295,6 +304,42 @@ void handlesig(int signo) {
quit(NULL); quit(NULL);
} }
void printstatus(void) {
Monitor *m = NULL;
Client *c;
uint32_t occ, urg, sel;
wl_list_for_each(m, &mons, link) {
occ = urg = 0;
wl_list_for_each(c, &clients, link) {
if (c->mon != m)
continue;
occ |= c->tags;
if (c->isurgent)
urg |= c->tags;
}
if ((c = focustop(m))) {
printf("%s title %s\n", m->wlr_output->name, client_get_title(c));
printf("%s appid %s\n", m->wlr_output->name, client_get_appid(c));
printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
sel = c->tags;
} else {
printf("%s title \n", m->wlr_output->name);
printf("%s appid \n", m->wlr_output->name);
printf("%s fullscreen \n", m->wlr_output->name);
printf("%s floating \n", m->wlr_output->name);
sel = 0;
}
printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
printf("%s tags %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 "\n",
m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
}
fflush(stdout);
}
void run(char *startup_cmd) { void run(char *startup_cmd) {
/* Add a Unix socket to the Wayland display. */ /* Add a Unix socket to the Wayland display. */
const char *socket = wl_display_add_socket_auto(dpy); const char *socket = wl_display_add_socket_auto(dpy);
@ -315,7 +360,7 @@ void run(char *startup_cmd) {
die("startup: pipe:"); die("startup: pipe:");
if ((child_pid = fork()) < 0) if ((child_pid = fork()) < 0)
die("startup: fork:"); die("startup: fork:");
if (child_pid == 0) { if (child_pid == 0) {
setsid(); setsid();
dup2(piperw[0], STDIN_FILENO); dup2(piperw[0], STDIN_FILENO);
close(piperw[0]); close(piperw[0]);
@ -365,3 +410,4 @@ void spawn(const Arg *arg) {
} }
void quit(const Arg *arg) { wl_display_terminate(dpy); } void quit(const Arg *arg) { wl_display_terminate(dpy); }

View file

@ -7,6 +7,7 @@ static void chvt(const Arg *arg);
static void cleanup(void); static void cleanup(void);
static void cleanuplisteners(void); static void cleanuplisteners(void);
static void handlesig(int signo); static void handlesig(int signo);
static void printstatus(void);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static void run(char *startup_cmd); static void run(char *startup_cmd);
static void setup(void); static void setup(void);

View file

@ -1,3 +1,5 @@
#include "lib/layers.h"
void createlayersurface(struct wl_listener *listener, void *data) { void createlayersurface(struct wl_listener *listener, void *data) {
struct wlr_layer_surface_v1 *layer_surface = data; struct wlr_layer_surface_v1 *layer_surface = data;
LayerSurface *l; LayerSurface *l;

View file

@ -1,5 +1,7 @@
#ifndef CRYWL_LAYER_H #ifndef CRYWL_LAYERS_H
#define CRYWL_LAYER_H #define CRYWL_LAYERS_H
#include "lib/monitor.h"
enum { enum {
LyrBg, LyrBg,
@ -33,4 +35,4 @@ typedef struct {
/* ===== Function Declarations ===== */ /* ===== Function Declarations ===== */
static void createlayersurface(struct wl_listener *listener, void *data); static void createlayersurface(struct wl_listener *listener, void *data);
#endif /* CRYWL_LAYER_H */ #endif /* CRYWL_LAYERS_H */

14
src/lib/macros.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef CRYWL_MACROS_H
#define CRYWL_MACROS_H
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
#define VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#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 { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
#endif /* CRYWL_MACROS_H */

View file

@ -1,3 +1,5 @@
#include "lib/monitor.h"
void arrange(Monitor *m) { void arrange(Monitor *m) {
Client *c; Client *c;
@ -292,6 +294,29 @@ Client *focustop(Monitor *m) {
return NULL; return NULL;
} }
void gpureset(struct wl_listener *listener, void *data) {
struct wlr_renderer *old_drw = drw;
struct wlr_allocator *old_alloc = alloc;
struct Monitor *m;
if (!(drw = wlr_renderer_autocreate(backend)))
die("couldn't recreate renderer");
if (!(alloc = wlr_allocator_autocreate(backend, drw)))
die("couldn't recreate allocator");
wl_list_remove(&gpu_reset.link);
wl_signal_add(&drw->events.lost, &gpu_reset);
wlr_compositor_set_renderer(compositor, drw);
wl_list_for_each(m, &mons, link) {
wlr_output_init_render(m->wlr_output, alloc, drw);
}
wlr_allocator_destroy(old_alloc);
wlr_renderer_destroy(old_drw);
}
void incnmaster(const Arg *arg) { void incnmaster(const Arg *arg) {
if (!arg || !selmon) if (!arg || !selmon)
return; return;

View file

@ -1,7 +1,13 @@
#ifndef CRYWL_MONITOR_H #ifndef CRYWL_MONITOR_H
#define CRYWL_MONITOR_H #define CRYWL_MONITOR_H
typedef struct Monitor Monitor; #include "lib/client.h"
// client.h contains a forward declaration of Monitor
typedef struct {
const char *symbol;
void (*arrange)(Monitor *);
} Layout;
struct Monitor { struct Monitor {
struct wl_list link; struct wl_list link;
@ -27,11 +33,6 @@ struct Monitor {
int asleep; int asleep;
}; };
typedef struct {
const char *symbol;
void (*arrange)(Monitor *);
} Layout;
typedef struct { typedef struct {
const char *name; const char *name;
float mfact; float mfact;
@ -63,6 +64,7 @@ static Monitor *dirtomon(enum wlr_direction dir);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg); static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m); static Client *focustop(Monitor *m);
static void gpureset(struct wl_listener *listener, void *data);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
static void monocle(Monitor *m); static void monocle(Monitor *m);
static void rendermon(struct wl_listener *listener, void *data); static void rendermon(struct wl_listener *listener, void *data);

View file

@ -1,58 +0,0 @@
void gpureset(struct wl_listener *listener, void *data) {
struct wlr_renderer *old_drw = drw;
struct wlr_allocator *old_alloc = alloc;
struct Monitor *m;
if (!(drw = wlr_renderer_autocreate(backend)))
die("couldn't recreate renderer");
if (!(alloc = wlr_allocator_autocreate(backend, drw)))
die("couldn't recreate allocator");
wl_list_remove(&gpu_reset.link);
wl_signal_add(&drw->events.lost, &gpu_reset);
wlr_compositor_set_renderer(compositor, drw);
wl_list_for_each(m, &mons, link) {
wlr_output_init_render(m->wlr_output, alloc, drw);
}
wlr_allocator_destroy(old_alloc);
wlr_renderer_destroy(old_drw);
}
void printstatus(void) {
Monitor *m = NULL;
Client *c;
uint32_t occ, urg, sel;
wl_list_for_each(m, &mons, link) {
occ = urg = 0;
wl_list_for_each(c, &clients, link) {
if (c->mon != m)
continue;
occ |= c->tags;
if (c->isurgent)
urg |= c->tags;
}
if ((c = focustop(m))) {
printf("%s title %s\n", m->wlr_output->name, client_get_title(c));
printf("%s appid %s\n", m->wlr_output->name, client_get_appid(c));
printf("%s fullscreen %d\n", m->wlr_output->name, c->isfullscreen);
printf("%s floating %d\n", m->wlr_output->name, c->isfloating);
sel = c->tags;
} else {
printf("%s title \n", m->wlr_output->name);
printf("%s appid \n", m->wlr_output->name);
printf("%s fullscreen \n", m->wlr_output->name);
printf("%s floating \n", m->wlr_output->name);
sel = 0;
}
printf("%s selmon %u\n", m->wlr_output->name, m == selmon);
printf("%s tags %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 "\n",
m->wlr_output->name, occ, m->tagset[m->seltags], sel, urg);
printf("%s layout %s\n", m->wlr_output->name, m->ltsymbol);
}
fflush(stdout);
}

View file

@ -1,9 +0,0 @@
/* TODO: rename other.(c|h) to some better word */
#ifndef CRYWL_OTHER_H
#define CRYWL_OTHER_H
/* ===== Function Declarations ===== */
static void gpureset(struct wl_listener *listener, void *data);
static void printstatus(void);
#endif /* CRYWL_OTHER_H */

View file

@ -69,28 +69,9 @@
#endif #endif
#include "util.h" #include "util.h"
#include "lib/layers.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 VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#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 { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
/* enums */
typedef union {
int i;
uint32_t ui;
float f;
const void *v;
} Arg;
/* variables */ /* variables */
static pid_t child_pid = -1;
static int locked; static int locked;
static void *exclusive_focus; static void *exclusive_focus;
static struct wl_display *dpy; static struct wl_display *dpy;

View file

@ -1,5 +1,30 @@
/* See LICENSE.dwm file for copyright and license details. */ #ifndef CRYWL_UTIL_H
#define CRYWL_UTIL_H
#include <stddef.h>
#include <stdint.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 VISIBLEON(C, M) ((M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#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 { struct wl_listener *_l = ecalloc(1, sizeof(*_l)); _l->notify = (H); wl_signal_add((E), _l); } while (0)
typedef union {
int i;
uint32_t ui;
float f;
const void *v;
} Arg;
/* ===== Function Declaration ===== */
void die(const char *fmt, ...); void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size); void *ecalloc(size_t nmemb, size_t size);
int fd_set_nonblock(int fd); int fd_set_nonblock(int fd);
#endif /* CRYWL_UTIL_H */