summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormac <ra@afu.re>2025-08-26 22:46:29 -0400
committermac <ra@afu.re>2025-08-26 22:46:29 -0400
commit5c3e67b987ead6efb6201850012c5bad7120d26c (patch)
treeac4c60acc94b9ab43c3f502ca2c9af94ac7d7c8a
parent9a23ae35025698adca57db2e28abcdc7a721a988 (diff)
add simple_scratchpad-v0.7.patch
-rw-r--r--config.def.h.rej12
-rw-r--r--dwl.c34
-rw-r--r--simple_scratchpad.c68
3 files changed, 112 insertions, 2 deletions
diff --git a/config.def.h.rej b/config.def.h.rej
new file mode 100644
index 0000000..9d830f1
--- /dev/null
+++ b/config.def.h.rej
@@ -0,0 +1,12 @@
+--- config.def.h
++++ config.def.h
+@@ -136,6 +136,9 @@ static const Key keys[] = {
+ { MODKEY, XKB_KEY_Return, zoom, {0} },
+ { MODKEY, XKB_KEY_Tab, view, {0} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C, killclient, {0} },
++ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Z, addscratchpad, {0} },
++ { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_z, togglescratchpad, {0} },
++ { MODKEY, XKB_KEY_z, removescratchpad, {0} },
+ { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
diff --git a/dwl.c b/dwl.c
index a662911..72810e0 100644
--- a/dwl.c
+++ b/dwl.c
@@ -144,6 +144,7 @@ struct Client {
int isfloating, isurgent, isfullscreen;
int isterm, noswallow;
uint32_t resize; /* configure serial of a pending resize */
+ struct wl_list link_temp;
pid_t pid;
Client *swallowing; /* client being hidden */
Client *swallowedby;
@@ -261,6 +262,7 @@ typedef struct {
} SessionLock;
/* function declarations */
+static void addscratchpad(const Arg *arg);
static void applybounds(Client *c, struct wlr_box *bbox);
static void applyrules(Client *c);
static void arrange(Monitor *m);
@@ -357,6 +359,7 @@ static void printstatus(void);
static void powermgrsetmode(struct wl_listener *listener, void *data);
static void quit(const Arg *arg);
static void rendermon(struct wl_listener *listener, void *data);
+static void removescratchpad(const Arg *arg);
static void requestdecorationmode(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
static void requestmonstate(struct wl_listener *listener, void *data);
@@ -386,6 +389,7 @@ static void togglefullscreen(const Arg *arg);
static void togglegaps(const Arg *arg);
static void toggleswallow(const Arg *arg);
static void toggleautoswallow(const Arg *arg);
+static void togglescratchpad(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
@@ -499,6 +503,9 @@ static struct wl_listener new_session_lock = {.notify = locksession};
static struct zdwl_ipc_manager_v2_interface dwl_manager_implementation = {.release = dwl_ipc_manager_release, .get_output = dwl_ipc_manager_get_output};
static struct zdwl_ipc_output_v2_interface dwl_output_implementation = {.release = dwl_ipc_output_release, .set_tags = dwl_ipc_output_set_tags, .set_layout = dwl_ipc_output_set_layout, .set_client_tags = dwl_ipc_output_set_client_tags};
+static struct wl_list scratchpad_clients;
+static int scratchpad_visible = 1;
+
#ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data);
@@ -518,6 +525,8 @@ static struct wlr_xwayland *xwayland;
/* attempt to encapsulate suck into one file */
#include "client.h"
+#include "simple_scratchpad.c"
+
/* function implementations */
void
applybounds(Client *c, struct wlr_box *bbox)
@@ -1424,10 +1433,20 @@ void
destroynotify(struct wl_listener *listener, void *data)
{
/* Called when the xdg_toplevel is destroyed. */
- Client *c = wl_container_of(listener, c, destroy);
+ Client *sc, *c = wl_container_of(listener, c, destroy);
wl_list_remove(&c->destroy.link);
wl_list_remove(&c->set_title.link);
wl_list_remove(&c->fullscreen.link);
+ /* Check if destroyed client was part of scratchpad_clients
+ * and clean it from the list if so. */
+ if (c && wl_list_length(&scratchpad_clients) > 0) {
+ wl_list_for_each(sc, &scratchpad_clients, link_temp) {
+ if (sc == c) {
+ wl_list_remove(&c->link_temp);
+ break;
+ }
+ }
+ }
#ifdef XWAYLAND
if (c->type != XDGShell) {
wl_list_remove(&c->activate.link);
@@ -2724,11 +2743,21 @@ setcursorshape(struct wl_listener *listener, void *data)
void
setfloating(Client *c, int floating)
{
- Client *p = client_get_parent(c);
+ Client *sc, *p = client_get_parent(c);
c->isfloating = floating;
/* If in floating layout do not change the client's layer */
if (!c->mon || !client_surface(c)->mapped || !c->mon->lt[c->mon->sellt]->arrange)
return;
+ /* Check if unfloated client was part of scratchpad_clients
+ * and remove it from scratchpad_clients list if so */
+ if (!floating && wl_list_length(&scratchpad_clients) > 0) {
+ wl_list_for_each(sc, &scratchpad_clients, link_temp) {
+ if (sc == c) {
+ wl_list_remove(&c->link_temp);
+ break;
+ }
+ }
+ }
wlr_scene_node_reparent(&c->scene->node, layers[c->isfullscreen ||
(p && p->isfullscreen) ? LyrFS
: c->isfloating ? LyrFloat : LyrTile]);
@@ -2958,6 +2987,7 @@ setup(void)
*/
wl_list_init(&clients);
wl_list_init(&fstack);
+ wl_list_init(&scratchpad_clients);
xdg_shell = wlr_xdg_shell_create(dpy, 6);
wl_signal_add(&xdg_shell->events.new_toplevel, &new_xdg_toplevel);
diff --git a/simple_scratchpad.c b/simple_scratchpad.c
new file mode 100644
index 0000000..26d6b66
--- /dev/null
+++ b/simple_scratchpad.c
@@ -0,0 +1,68 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* simple_scratchpad.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: jmakkone <jmakkone@student.hive.fi> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/12/19 19:35:02 by jmakkone #+# #+# */
+/* Updated: 2025/01/04 13:35:50 by jmakkone ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+void
+addscratchpad(const Arg *arg)
+{
+ Client *cc, *c = focustop(selmon);
+
+ if (!c)
+ return;
+ /* Check if the added client is already a scratchpad client */
+ wl_list_for_each(cc, &scratchpad_clients, link_temp) {
+ if (cc == c)
+ return;
+ }
+ if (!c->isfloating) {
+ setfloating(c, 1);
+ }
+ wl_list_insert(&scratchpad_clients, &c->link_temp);
+}
+
+void
+togglescratchpad(const Arg *arg)
+{
+ Client *c;
+ Monitor *m = selmon;
+
+ scratchpad_visible = !scratchpad_visible;
+ if (scratchpad_visible) {
+ wl_list_for_each(c, &scratchpad_clients, link_temp) {
+ c->mon = m;
+ c->tags = m->tagset[m->seltags];
+ arrange(m);
+ focusclient(c, 1);
+ }
+ } else {
+ wl_list_for_each(c, &scratchpad_clients, link_temp) {
+ c->tags = 0;
+ focusclient(focustop(m), 1);
+ arrange(m);
+ }
+ }
+}
+
+void
+removescratchpad(const Arg *arg)
+{
+ Client *sc, *c = focustop(selmon);
+
+ if (c && wl_list_length(&scratchpad_clients) > 0) {
+ /* Check if c is in scratchpad_clients */
+ wl_list_for_each(sc, &scratchpad_clients, link_temp) {
+ if (sc == c) {
+ wl_list_remove(&c->link_temp);
+ break;
+ }
+ }
+ }
+}