From dd9e049a8c5e04e94fa53120ae04f37bffd5e9e4 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Wed, 10 Feb 2021 23:26:23 -0500 Subject: [PATCH] menu.c, fns.h, dat.h, config.h: add omnipresent windows, add config option to enable or disable menu item; config.h, key.c: add keyboard shortcut for sticky windows --- config.h | 4 ++++ dat.h | 8 ++++++-- fns.h | 2 +- key.c | 5 +++++ menu.c | 32 +++++++++++++++++++++++++++++--- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/config.h b/config.h index be7257b..12f9b1f 100755 --- a/config.h +++ b/config.h @@ -12,6 +12,8 @@ #define SMENUFGCOL 0x000000 #define SMENUBGCOL 0x1f9b92 +// #define SHOWSTICK + #define SHORTCUTMOD Mod4Mask #define MODBITS (1<<6) @@ -21,6 +23,7 @@ #define MOVE_KEY XK_v #define RESIZE_KEY XK_r #define DESTROY_KEY XK_d +#define STICK_KEY XK_s #define SNAPLEFT_KEY XK_h #define SNAPRIGHT_KEY XK_l @@ -38,3 +41,4 @@ #define PREVVIRT_KEY XK_Left #define LAUNCH_KEY XK_slash + diff --git a/dat.h b/dat.h index 2e6c398..4702ab2 100755 --- a/dat.h +++ b/dat.h @@ -6,7 +6,11 @@ #define CORNER _corner #define INSET _inset #define MAXHIDDEN 128 -#define B3FIXED 5 +#ifdef SHOWSTICK +#define B3FIXED 6 +#else +#define B3FIXED 5 +#endif #define NUMVIRTUALS 12 #define AllButtonMask (Button1Mask|Button2Mask|Button3Mask \ @@ -188,4 +192,4 @@ extern int ignore_badwindow; /* key.c and event.c share this */ -extern int kbLaunch; \ No newline at end of file +extern int kbLaunch; diff --git a/fns.h b/fns.h index a2d3611..6da358c 100755 --- a/fns.h +++ b/fns.h @@ -81,7 +81,7 @@ void button2(); void initb2menu(); void switch_to(); void switch_to_c(); - +void stick(); /* client.c */ diff --git a/key.c b/key.c index 40c0e8b..c40e558 100755 --- a/key.c +++ b/key.c @@ -43,6 +43,7 @@ keysetup(void) int mcode = XKeysymToKeycode(dpy, MAX_KEY); int vcode = XKeysymToKeycode(dpy, MOVE_KEY); int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); + int scode = XKeysymToKeycode(dpy, STICK_KEY); int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY); int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_KEY); @@ -64,6 +65,7 @@ keysetup(void) XGrabKey(dpy, rcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(dpy, vcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(dpy, mcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); + XGrabKey(dpy, scode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(dpy, hcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(dpy, lcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(dpy, jcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); @@ -95,6 +97,7 @@ keypress(XKeyEvent *e) int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY); int mcode = XKeysymToKeycode(dpy, MAX_KEY); int vcode = XKeysymToKeycode(dpy, MOVE_KEY); + int scode = XKeysymToKeycode(dpy, STICK_KEY); int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY); int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); @@ -128,6 +131,8 @@ keypress(XKeyEvent *e) reshape(current, Button3, sweep, 0); if (e->keycode == mcode && (e->state&SHORTCUTMOD) == (MODBITS)) quickreshape(current, -BORDER, -BORDER, ra.width + 2*BORDER, ra.height + 2*BORDER); + if (e->keycode == scode && (e->state&SHORTCUTMOD) == (MODBITS)) + stick(current); /* half snap */ if (e->keycode == hcode && (e->state&SHORTCUTMOD) == (MODBITS)) diff --git a/menu.c b/menu.c index 290b8f9..f9b58be 100755 --- a/menu.c +++ b/menu.c @@ -58,6 +58,9 @@ char *b3items[B3FIXED+MAXHIDDEN+1] = "Move", "Delete", "Hide", +#ifdef SHOWSTICK + "Stick", +#endif 0 }; @@ -67,7 +70,12 @@ enum Reshape, Move, Delete, +#ifdef SHOWSTICK + Hide, + Stick +#else Hide +#endif }; Menu b3menu = @@ -119,7 +127,6 @@ button(XButtonEvent *e) } switch (e->button){ case Button1: - printf("button 1 on client"); fflush(stdout); if(c){ if (ffm) @@ -177,6 +184,11 @@ button(XButtonEvent *e) case Hide: hide(selectwin(1, 0, s)); break; +#ifdef SHOWSTICK + case Stick: + stick(selectwin(1, 0, s)); + break; +#endif default: /* unhide window */ unhide(n - B3FIXED, 1); break; @@ -347,6 +359,20 @@ unhidec(Client *c, int map) c->label, (int)c->window); } +void +stick(Client *c) +{ + printf("BEFORE STICK:\n"); + printf("virtual on client: %d\n", c->virt); + printf("virtual: %d\n", virt); + if (numvirtuals > 1 && c->virt >= 0 ) + c->virt = -1; + else c->virt = virt; + printf("AFTER STICK:\n"); + printf("virtual on client: %d\n", c->virt); + printf("virtual: %d\n", virt); +} + void renamec(Client *c, char *name) { @@ -384,7 +410,7 @@ switch_to_c(int n, Client *c) if(c->parent == DefaultRootWindow(dpy)) return; - if(c->virt != virt && c->state == NormalState){ + if(c->virt != virt && c->state == NormalState && c->virt >= 0){ XUnmapWindow(dpy, c->parent); XUnmapWindow(dpy, c->window); setstate(c, IconicState); @@ -432,7 +458,7 @@ switch_to(int n) signal(SIGTERM, SIG_DFL); signal(SIGHUP, SIG_DFL); sprintf(virtmsg, "virtual: switched to %s", b2items[virt]); - execlp("notify-send", "notify-send", "-c virtual", virtmsg, (char*)0); + execlp("notify-send", "notify-send", "-c", "virtual", virtmsg, (char*)0); } }