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

This commit is contained in:
Iris Lightshard 2021-02-10 23:26:23 -05:00
parent 8ffa8d334b
commit dd9e049a8c
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
5 changed files with 45 additions and 6 deletions

View file

@ -12,6 +12,8 @@
#define SMENUFGCOL 0x000000 #define SMENUFGCOL 0x000000
#define SMENUBGCOL 0x1f9b92 #define SMENUBGCOL 0x1f9b92
// #define SHOWSTICK
#define SHORTCUTMOD Mod4Mask #define SHORTCUTMOD Mod4Mask
#define MODBITS (1<<6) #define MODBITS (1<<6)
@ -21,6 +23,7 @@
#define MOVE_KEY XK_v #define MOVE_KEY XK_v
#define RESIZE_KEY XK_r #define RESIZE_KEY XK_r
#define DESTROY_KEY XK_d #define DESTROY_KEY XK_d
#define STICK_KEY XK_s
#define SNAPLEFT_KEY XK_h #define SNAPLEFT_KEY XK_h
#define SNAPRIGHT_KEY XK_l #define SNAPRIGHT_KEY XK_l
@ -38,3 +41,4 @@
#define PREVVIRT_KEY XK_Left #define PREVVIRT_KEY XK_Left
#define LAUNCH_KEY XK_slash #define LAUNCH_KEY XK_slash

8
dat.h
View file

@ -6,7 +6,11 @@
#define CORNER _corner #define CORNER _corner
#define INSET _inset #define INSET _inset
#define MAXHIDDEN 128 #define MAXHIDDEN 128
#define B3FIXED 5 #ifdef SHOWSTICK
#define B3FIXED 6
#else
#define B3FIXED 5
#endif
#define NUMVIRTUALS 12 #define NUMVIRTUALS 12
#define AllButtonMask (Button1Mask|Button2Mask|Button3Mask \ #define AllButtonMask (Button1Mask|Button2Mask|Button3Mask \
@ -188,4 +192,4 @@ extern int ignore_badwindow;
/* key.c and event.c share this */ /* key.c and event.c share this */
extern int kbLaunch; extern int kbLaunch;

2
fns.h
View file

@ -81,7 +81,7 @@ void button2();
void initb2menu(); void initb2menu();
void switch_to(); void switch_to();
void switch_to_c(); void switch_to_c();
void stick();
/* client.c */ /* client.c */

5
key.c
View file

@ -43,6 +43,7 @@ keysetup(void)
int mcode = XKeysymToKeycode(dpy, MAX_KEY); int mcode = XKeysymToKeycode(dpy, MAX_KEY);
int vcode = XKeysymToKeycode(dpy, MOVE_KEY); int vcode = XKeysymToKeycode(dpy, MOVE_KEY);
int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); int rcode = XKeysymToKeycode(dpy, RESIZE_KEY);
int scode = XKeysymToKeycode(dpy, STICK_KEY);
int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY);
int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY); int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY);
int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_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, rcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, vcode, 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, 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, hcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, lcode, 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); XGrabKey(dpy, jcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
@ -95,6 +97,7 @@ keypress(XKeyEvent *e)
int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY); int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY);
int mcode = XKeysymToKeycode(dpy, MAX_KEY); int mcode = XKeysymToKeycode(dpy, MAX_KEY);
int vcode = XKeysymToKeycode(dpy, MOVE_KEY); int vcode = XKeysymToKeycode(dpy, MOVE_KEY);
int scode = XKeysymToKeycode(dpy, STICK_KEY);
int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); int rcode = XKeysymToKeycode(dpy, RESIZE_KEY);
int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY); int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY);
int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY);
@ -128,6 +131,8 @@ keypress(XKeyEvent *e)
reshape(current, Button3, sweep, 0); reshape(current, Button3, sweep, 0);
if (e->keycode == mcode && (e->state&SHORTCUTMOD) == (MODBITS)) if (e->keycode == mcode && (e->state&SHORTCUTMOD) == (MODBITS))
quickreshape(current, -BORDER, -BORDER, ra.width + 2*BORDER, ra.height + 2*BORDER); quickreshape(current, -BORDER, -BORDER, ra.width + 2*BORDER, ra.height + 2*BORDER);
if (e->keycode == scode && (e->state&SHORTCUTMOD) == (MODBITS))
stick(current);
/* half snap */ /* half snap */
if (e->keycode == hcode && (e->state&SHORTCUTMOD) == (MODBITS)) if (e->keycode == hcode && (e->state&SHORTCUTMOD) == (MODBITS))

32
menu.c
View file

@ -58,6 +58,9 @@ char *b3items[B3FIXED+MAXHIDDEN+1] =
"Move", "Move",
"Delete", "Delete",
"Hide", "Hide",
#ifdef SHOWSTICK
"Stick",
#endif
0 0
}; };
@ -67,7 +70,12 @@ enum
Reshape, Reshape,
Move, Move,
Delete, Delete,
#ifdef SHOWSTICK
Hide,
Stick
#else
Hide Hide
#endif
}; };
Menu b3menu = Menu b3menu =
@ -119,7 +127,6 @@ button(XButtonEvent *e)
} }
switch (e->button){ switch (e->button){
case Button1: case Button1:
printf("button 1 on client");
fflush(stdout); fflush(stdout);
if(c){ if(c){
if (ffm) if (ffm)
@ -177,6 +184,11 @@ button(XButtonEvent *e)
case Hide: case Hide:
hide(selectwin(1, 0, s)); hide(selectwin(1, 0, s));
break; break;
#ifdef SHOWSTICK
case Stick:
stick(selectwin(1, 0, s));
break;
#endif
default: /* unhide window */ default: /* unhide window */
unhide(n - B3FIXED, 1); unhide(n - B3FIXED, 1);
break; break;
@ -347,6 +359,20 @@ unhidec(Client *c, int map)
c->label, (int)c->window); 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 void
renamec(Client *c, char *name) renamec(Client *c, char *name)
{ {
@ -384,7 +410,7 @@ switch_to_c(int n, Client *c)
if(c->parent == DefaultRootWindow(dpy)) if(c->parent == DefaultRootWindow(dpy))
return; 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->parent);
XUnmapWindow(dpy, c->window); XUnmapWindow(dpy, c->window);
setstate(c, IconicState); setstate(c, IconicState);
@ -432,7 +458,7 @@ switch_to(int n)
signal(SIGTERM, SIG_DFL); signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL); signal(SIGHUP, SIG_DFL);
sprintf(virtmsg, "virtual: switched to %s", b2items[virt]); 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);
} }
} }