From 42e6f73f47dc1cdcc99fc8c8887160e4952e6c32 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Mon, 22 Nov 2021 21:09:51 +0100 Subject: [PATCH] inital version of weechat scratchpad --- config.h | 6 ++-- dwm.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/config.h b/config.h index 7ae733d..3dd3e8b 100644 --- a/config.h +++ b/config.h @@ -54,7 +54,7 @@ typedef struct { } Sp; const char *spcmd1[] = {"st", "-n", "scratchpadterm", "-t", "Scratchpad", "-g", "120x34", NULL }; const char *spcmd2[] = {"st", "-n", "scratchcalc", "-t", "Calculator", "-g", "120x34", "-e", "dropdowncalc", NULL }; -const char *spcmd3[] = {"st", "-n", "matrix", "-e", "weechat", NULL }; +const char *spcmd3[] = {"st", "-n", "matrix", "-A", "0.1", "-e", "weechat", NULL }; static Sp scratchpads[] = { /* name cmd */ @@ -148,9 +148,9 @@ static Key keys[] = { /* { MODKEY|ShiftMask, XK_q, spawn, SHCMD("") }, */ { MODKEY, XK_w, spawn, SHCMD("$BROWSER") }, { MODKEY|ShiftMask, XK_w, spawn, SHCMD("chromium") }, /*using ungoogled-chromium as backup browser*/ - { MODKEY|ShiftMask|ControlMask, XK_w, togglewarp, {0} }, + { MODKEY|ShiftMask|ControlMask, XK_w, togglewarp, {0} }, { MODKEY, XK_e, spawn, SHCMD("st -e neomutt -e 'set sidebar_visible = no'; pkill -RTMIN+13 dwmblocks") }, - { MODKEY|ShiftMask, XK_e, togglescratch, {.ui = 2 } }, + { MODKEY|ShiftMask, XK_e, togglescratch, {.ui = 2 } }, //{ MODKEY|ShiftMask, XK_e, spawn, SHCMD("element-desktop") }, { MODKEY, XK_r, spawn, SHCMD("st -e $FILE") }, diff --git a/dwm.c b/dwm.c index 7e36c39..9f0c62f 100644 --- a/dwm.c +++ b/dwm.c @@ -58,6 +58,7 @@ #define SPTAG(i) ((1 << LENGTH(tags)) << (i)) #define SPTAGMASK (((1 << LENGTH(scratchpads))-1) << LENGTH(tags)) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) +#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ @@ -174,6 +175,7 @@ static void fibonacci(Monitor *mon, int s); static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); +static void focusclientmon(Monitor *msearch); static void focusstack(const Arg *arg); static Atom getatomprop(Client *c, Atom prop); static int getrootptr(int *x, int *y); @@ -203,6 +205,7 @@ static void run(void); static void scan(void); static int sendevent(Client *c, Atom proto); static void sendmon(Client *c, Monitor *m); +static void sendmontags(Client *c, Monitor *m, unsigned int tags); static void setclientstate(Client *c, long state); static void setfocus(Client *c); static void setfloating(const Arg *arg); @@ -789,8 +792,7 @@ drawbar(Monitor *m) for (i = 0; i < LENGTH(tags); i++) { /* do not draw vacant tags */ if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) - continue; - + continue; w = TEXTW(tags[i]); drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); @@ -913,6 +915,20 @@ focusmon(const Arg *arg) warp(selmon->sel); } +void +focusclientmon(Monitor *msearch) +{ + Monitor *m; + + if (!mons->next) + return; + if ((m = msearch) == selmon) + return; + unfocus(selmon->sel, 0); + selmon = m; + focus(NULL); + warp(selmon->sel); +} void focusstack(const Arg *arg) { @@ -1496,13 +1512,29 @@ scan(void) void sendmon(Client *c, Monitor *m) { + sendmontags(c, m, m->tagset[m->seltags]); + //if (c->mon == m) + // return; + //unfocus(c, 1); + //detach(c); + //detachstack(c); + //c->mon = m; + //c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ + //attach(c); + //attachstack(c); + //focus(NULL); + //arrange(NULL); +} + +void +sendmontags(Client *c, Monitor *m, unsigned int tags){ if (c->mon == m) return; unfocus(c, 1); detach(c); detachstack(c); c->mon = m; - c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ + c->tags = tags; attach(c); attachstack(c); focus(NULL); @@ -1883,23 +1915,53 @@ void togglescratch(const Arg *arg) { Client *c; + Client *cfound; + Monitor *m; unsigned int found = 0; unsigned int scratchtag = SPTAG(arg->ui); Arg sparg = {.v = scratchpads[arg->ui].cmd}; - 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); + for (m = mons; m; m = m->next){ + fprintf(stderr,"searching monitor %d\n", m->num); + for (c = m->clients; c && !(found = c->tags & scratchtag); c = c->next){ + fprintf(stderr, "client: %s\n", c->name); } - if (ISVISIBLE(c)) { - focus(c); - restack(selmon); + } + + if (found){ + cfound=c; + fprintf(stderr, "found client %s\n", cfound->name); + fprintf(stderr, "tags of scratchpad: %d\n", cfound->tags); + fprintf(stderr, "scratchtag: %d\n", scratchtag); + fprintf(stderr, "num of monitor: %d\n", cfound->mon->num); + if (cfound->mon == selmon) { + 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 { + else{ + fprintf(stderr, "we should move to selmon\n"); + //move client from cfound->mon to selmon but still in scratchtag + // remove scratchtag from tagset of cfound->mon -> + unsigned int newtagset = cfound->mon->tagset[cfound->mon->seltags] ^ scratchtag; + if (newtagset) + cfound->mon->tagset[cfound->mon->seltags] = newtagset; + //add scratchtag to monitor where client is sent to + selmon->tagset[selmon->seltags] |= scratchtag; + sendmontags(cfound, selmon, scratchtag); + fprintf(stderr, "tags of scratchpad: %d\n", cfound->tags); + fprintf(stderr, "num of monitor: %d\n", cfound->mon->num); + } + } + else { + fprintf(stderr, "Did not find client"); selmon->tagset[selmon->seltags] |= scratchtag; spawn(&sparg); }