Weechat scratchpad #1

Merged
AlexBocken merged 3 commits from weechat_scratch into master 2021-11-22 21:50:30 +01:00
2 changed files with 64 additions and 17 deletions

View File

@ -54,7 +54,7 @@ typedef struct {
} Sp; } Sp;
const char *spcmd1[] = {"st", "-n", "scratchpadterm", "-t", "Scratchpad", "-g", "120x34", NULL }; 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 *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[] = { static Sp scratchpads[] = {
/* name cmd */ /* name cmd */

57
dwm.c
View File

@ -58,6 +58,7 @@
#define SPTAG(i) ((1 << LENGTH(tags)) << (i)) #define SPTAG(i) ((1 << LENGTH(tags)) << (i))
#define SPTAGMASK (((1 << LENGTH(scratchpads))-1) << LENGTH(tags)) #define SPTAGMASK (((1 << LENGTH(scratchpads))-1) << LENGTH(tags))
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* enums */ /* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
@ -174,6 +175,7 @@ static void fibonacci(Monitor *mon, int s);
static void focus(Client *c); static void focus(Client *c);
static void focusin(XEvent *e); static void focusin(XEvent *e);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusclientmon(Monitor *msearch);
static void focusstack(const Arg *arg); static void focusstack(const Arg *arg);
static Atom getatomprop(Client *c, Atom prop); static Atom getatomprop(Client *c, Atom prop);
static int getrootptr(int *x, int *y); static int getrootptr(int *x, int *y);
@ -203,6 +205,7 @@ static void run(void);
static void scan(void); static void scan(void);
static int sendevent(Client *c, Atom proto); static int sendevent(Client *c, Atom proto);
static void sendmon(Client *c, Monitor *m); 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 setclientstate(Client *c, long state);
static void setfocus(Client *c); static void setfocus(Client *c);
static void setfloating(const Arg *arg); static void setfloating(const Arg *arg);
@ -790,7 +793,6 @@ drawbar(Monitor *m)
/* do not draw vacant tags */ /* do not draw vacant tags */
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
continue; continue;
w = TEXTW(tags[i]); w = TEXTW(tags[i]);
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); 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); 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); 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 void
focusstack(const Arg *arg) focusstack(const Arg *arg)
{ {
@ -1496,13 +1512,29 @@ scan(void)
void void
sendmon(Client *c, Monitor *m) 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) if (c->mon == m)
return; return;
unfocus(c, 1); unfocus(c, 1);
detach(c); detach(c);
detachstack(c); detachstack(c);
c->mon = m; c->mon = m;
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ c->tags = tags;
attach(c); attach(c);
attachstack(c); attachstack(c);
focus(NULL); focus(NULL);
@ -1883,12 +1915,16 @@ void
togglescratch(const Arg *arg) togglescratch(const Arg *arg)
{ {
Client *c; Client *c;
Monitor *m;
unsigned int found = 0; unsigned int found = 0;
unsigned int scratchtag = SPTAG(arg->ui); unsigned int scratchtag = SPTAG(arg->ui);
Arg sparg = {.v = scratchpads[arg->ui].cmd}; Arg sparg = {.v = scratchpads[arg->ui].cmd};
for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); for (m = mons; m && !found; m = m->next)
if (found) { for (c = m->clients; c && !(found = c->tags & scratchtag); c = c->next);
if (found){
if (c->mon == selmon) {
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag;
if (newtagset) { if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset; selmon->tagset[selmon->seltags] = newtagset;
@ -1899,7 +1935,18 @@ togglescratch(const Arg *arg)
focus(c); focus(c);
restack(selmon); restack(selmon);
} }
} else { }
else{
unsigned int newtagset = c->mon->tagset[c->mon->seltags] ^ scratchtag;
if (newtagset)
c->mon->tagset[c->mon->seltags] = newtagset;
//add scratchtag to monitor where client is sent to
selmon->tagset[selmon->seltags] |= scratchtag;
sendmontags(c, selmon, scratchtag);
}
}
else {
selmon->tagset[selmon->seltags] |= scratchtag; selmon->tagset[selmon->seltags] |= scratchtag;
spawn(&sparg); spawn(&sparg);
} }