feat(dwm): 添加 scratchpad

This commit is contained in:
augety 2024-07-20 21:44:44 +08:00
parent de9e120cdf
commit b9f5d2f2a0
3 changed files with 143 additions and 0 deletions

View File

@ -64,6 +64,8 @@ static const Layout layouts[] = {
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL }; static const char *termcmd[] = { "st", NULL };
static const char scratchpadname[] = "scratchpad";
static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "130x34", NULL };
static const Key keys[] = { static const Key keys[] = {
/* modifier key function argument */ /* modifier key function argument */
@ -71,6 +73,8 @@ static const Key keys[] = {
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY, XK_p, spawn, {.v = dmenucmd } },
// 终端 // 终端
{ MODKEY, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_Return, spawn, {.v = termcmd } },
// 浮动终端
{ MODKEY, XK_apostrophe, togglescratch, {.v = scratchpadcmd } },
// 设置主窗口 // 设置主窗口
{ MODKEY|ShiftMask, XK_Return, zoom, {0} }, { MODKEY|ShiftMask, XK_Return, zoom, {0} },
// 关闭 | 打开 状态栏 // 关闭 | 打开 状态栏

View File

@ -230,6 +230,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m); static void tile(Monitor *m);
static void togglebar(const Arg *arg); static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg); static void togglefloating(const Arg *arg);
static void togglescratch(const Arg *arg);
static void toggletag(const Arg *arg); static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg); static void toggleview(const Arg *arg);
static void togglewin(const Arg *arg); static void togglewin(const Arg *arg);
@ -304,6 +305,8 @@ struct Pertag {
int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */ int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
}; };
static unsigned int scratchtag = 1 << LENGTH(tags);
/* compile-time check if all tags fit into an unsigned int bit array. */ /* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
@ -1233,6 +1236,14 @@ manage(Window w, XWindowAttributes *wa)
c->y = MAX(c->y, c->mon->wy); c->y = MAX(c->y, c->mon->wy);
c->bw = borderpx; c->bw = borderpx;
selmon->tagset[selmon->seltags] &= ~scratchtag;
if (!strcmp(c->name, scratchpadname)) {
c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag;
c->isfloating = True;
c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
}
wc.border_width = c->bw; wc.border_width = c->bw;
XConfigureWindow(dpy, w, CWBorderWidth, &wc); XConfigureWindow(dpy, w, CWBorderWidth, &wc);
XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
@ -1993,6 +2004,7 @@ spawn(const Arg *arg)
if (arg->v == dmenucmd) if (arg->v == dmenucmd)
dmenumon[0] = '0' + selmon->num; dmenumon[0] = '0' + selmon->num;
selmon->tagset[selmon->seltags] &= ~scratchtag;
if (fork() == 0) { if (fork() == 0) {
if (dpy) if (dpy)
close(ConnectionNumber(dpy)); close(ConnectionNumber(dpy));
@ -2079,6 +2091,28 @@ togglefloating(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
void
togglescratch(const Arg *arg)
{
Client *c;
unsigned int found = 0;
for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next);
if (found) {
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag;
if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset;
focus(NULL);
arrange(selmon);
}
if (ISVISIBLE(c)) {
focus(c);
restack(selmon);
}
} else
spawn(arg);
}
void void
toggletag(const Arg *arg) toggletag(const Arg *arg)
{ {

View File

@ -0,0 +1,105 @@
From b9f3c11c3150f0b5d5b297a4eeeb2012764c98f5 Mon Sep 17 00:00:00 2001
From: visil <workregor@mail.ru>
Date: Thu, 21 Mar 2024 15:16:39 +0300
Subject: [PATCH] Patch updated to 6.5
---
config.def.h | 3 +++
dwm.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/config.def.h b/config.def.h
index 9efa774..0b8b310 100644
--- a/config.def.h
+++ b/config.def.h
@@ -59,11 +59,14 @@ static const Layout layouts[] = {
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
+static const char scratchpadname[] = "scratchpad";
+static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL };
static const Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
+ { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
diff --git a/dwm.c b/dwm.c
index f1d86b2..a8db21a 100644
--- a/dwm.c
+++ b/dwm.c
@@ -211,6 +211,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
+static void togglescratch(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus);
@@ -271,6 +272,8 @@ static Window root, wmcheckwin;
/* configuration, allows nested code to access above variables */
#include "config.h"
+static unsigned int scratchtag = 1 << LENGTH(tags);
+
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
@@ -1061,6 +1064,14 @@ manage(Window w, XWindowAttributes *wa)
c->y = MAX(c->y, c->mon->wy);
c->bw = borderpx;
+ selmon->tagset[selmon->seltags] &= ~scratchtag;
+ if (!strcmp(c->name, scratchpadname)) {
+ c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag;
+ c->isfloating = True;
+ c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
+ c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
+ }
+
wc.border_width = c->bw;
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
@@ -1651,6 +1662,7 @@ spawn(const Arg *arg)
if (arg->v == dmenucmd)
dmenumon[0] = '0' + selmon->num;
+ selmon->tagset[selmon->seltags] &= ~scratchtag;
if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
@@ -1735,6 +1747,28 @@ togglefloating(const Arg *arg)
arrange(selmon);
}
+void
+togglescratch(const Arg *arg)
+{
+ Client *c;
+ unsigned int found = 0;
+
+ for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next);
+ if (found) {
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag;
+ if (newtagset) {
+ selmon->tagset[selmon->seltags] = newtagset;
+ focus(NULL);
+ arrange(selmon);
+ }
+ if (ISVISIBLE(c)) {
+ focus(c);
+ restack(selmon);
+ }
+ } else
+ spawn(arg);
+}
+
void
toggletag(const Arg *arg)
{
--
2.44.0