commit 473940f034d26db0ef0448925b5cb0c6b3fb9e70
parent 6c85883fdcc4ef9eed0b48bc488b5afdcb4df319
Author: Lucas de Sena <lucas@seninha.org>
Date: Fri, 20 Jan 2023 19:01:57 -0300
deprecate -m; add -A and -W
The -m was problematic.
Shod needs both a key symbol and a modifier to work; and also needs that
such modifier be generated by such key symbol. Both things were set by
the -m command-line option. Two things could happen:
- The user provides an invalid key symbol with -m. Shod just failed on
such case.
- The user provides a valid key symbol which produces no modifier key
(say, "space", or "F8"). Shod initiates successfully, but acts
erradically.
There are only a few modifiers on X:
- Control (should not be used by shod; applications depend on it).
- Shift (should not be used by shod; uppercase letters depend on it).
- Mod1Mask/Alt (shod can use it).
- Mod2Mask/NumLock (should not be used by shod; the keypad depends on it).
- Mod3Mask/ScrllLock (nobody knows what it is or does).
- Mod4Mask/Super/Win (shod can use it).
- Mod5Mask/AltGR (should not be used by shod; typing extra characters on
some keyboard layouts depends on it).
As you can see, the only modifier keys one can freely use on a window
manager are Mod1Mask/Alt and Mod4Mask/Super. Therefore, it is not a
problem to limit the options to only allow the user to use one of those
two keys.
The option -m, which was too powerful and only useful when invoked as
`-m Alt_L` or `-m Super_L`, has been then replaced by -A and -W.
Diffstat:
5 files changed, 45 insertions(+), 46 deletions(-)
diff --git a/config.c b/config.c
@@ -16,10 +16,9 @@ struct Config config = {
.disablehidden = 0, /* set to 1 to disable notification of hidden window as minimized */
/* general configuration */
- .altkeysym = XK_Alt_L,
- .tabkeysym = XK_Tab,
- .modifier = Mod1Mask,
- .shift = ShiftMask,
+ .altkeysym = XK_Alt_L, /* XK_Alt_L for Alt, XK_Super_L for Super (aka WinKey) */
+ .tabkeysym = XK_Tab, /* tab key; you should probably not change this */
+ .modifier = Mod1Mask, /* Mod1Mask for Alt, Mod4Mask for Super */
.snap = 8, /* proximity of container edges to perform snap attraction */
.font = "monospace:pixelsize=11", /* font for titles in titlebars */
.ndesktops = 10, /* number of desktops per monitor */
diff --git a/shod.1 b/shod.1
@@ -7,8 +7,7 @@
.Nd mouse-focused window manager
.Sh SYNOPSIS
.Nm shod
-.Op Fl cdhst
-.Op Fl m Ar keysym
+.Op Fl AcdhstW
.Op Ar file
.Pp
.Nm shodc
@@ -76,6 +75,17 @@ to run commands read from the standard input instead.
.Pp
The options are as follows:
.Bl -tag -width Ds
+.It Fl A
+Use
+.Qq "Alt"
+as modifier key.
+More technically, use
+.Qq "Alt_L"
+as the key to perform container cycling (alt-tab); and use
+.Qq "Mod1Mask"
+as the modifier for mouse operations.
+This option is incompatible with
+.Fl W .
.It Fl c
Honor configure requests.
By default,
@@ -104,27 +114,24 @@ By default, windows whose containers are obscured by other containers are set as
hidden (aka minimized).
This default behavior emulates the way Plan9's rio lists obscured windows as hidden.
With this option set, only manually minimized containers are set as hidden.
-.It Fl m Ar keysym
-Specifies the key symbol that is used for the container cycling,
-and that provides the modifier to move and resize windows with the mouse pointer.
-By default,
-.Nm
-uses
-.Cm Alt_L
-(Left Alt) as modifier.
-See the
-.Pa keysymdef.h
-header file for a list of key symbols
-(it is usually at
-.Pa /usr/X11R6/include/X11/keysymdef.h
-or
-.Pa /usr/include/X11/keysymdef.h
-on most systems).
.It Fl s
Use sloppy focus rather than click-to-focus.
.It Fl t
Disable container cycling (aka
-.Dq "alt-tab" No ).
+.Dq "alt-tab" ) .
+.It Fl W
+Use
+.Qq "Super"
+(also known as
+.Qq "Window Key" ) .
+as modifier key.
+More technically, use
+.Qq "Super_L"
+as the key to perform container cycling (alt-tab); and use
+.Qq "Mod4Mask"
+as the modifier for mouse operations.
+This option is incompatible with
+.Fl A .
.El
.Pp
.Nm shodc
@@ -504,9 +511,11 @@ Each title bar has a right button.
Clicking on the right title-bar button with the first mouse button
closes the focused client or its top dialog.
.Pp
-Containers can be cycled using the key provided by the
-.Fl m
-option
+Containers can be cycled using the modifier key set with either the
+.Fl A
+or
+.Fl W
+command-line option
.No ( Cm Alt_L
by default) followed by the
.Cm Tab
diff --git a/shod.c b/shod.c
@@ -35,7 +35,7 @@ struct Dock dock;
static void
usage(void)
{
- (void)fprintf(stderr, "usage: shod [-cdhst] [-m modifier] [file]\n");
+ (void)fprintf(stderr, "usage: shod [-AcdhstW] [file]\n");
exit(1);
}
@@ -119,8 +119,12 @@ getoptions(int argc, char *argv[])
{
int c;
- while ((c = getopt(argc, argv, "cdhm:st")) != -1) {
+ while ((c = getopt(argc, argv, "AcdhstW")) != -1) {
switch (c) {
+ case 'A' :
+ config.altkeysym = XK_Alt_L;
+ config.modifier = Mod1Mask;
+ break;
case 'c':
config.honorconfig = 1;
break;
@@ -130,16 +134,16 @@ getoptions(int argc, char *argv[])
case 'h':
config.disablehidden = 1;
break;
- case 'm':
- if ((config.altkeysym = XStringToKeysym(optarg)) == NoSymbol)
- errx(1, "supplied key does not match any key symbol: %s", optarg);
- break;
case 's':
config.sloppyfocus = 1;
break;
case 't':
config.disablealttab = 1;
break;
+ case 'W' :
+ config.altkeysym = XK_Super_L;
+ config.modifier = Mod4Mask;
+ break;
default:
usage();
break;
diff --git a/shod.h b/shod.h
@@ -654,7 +654,6 @@ struct Config {
KeyCode altkeycode; /* keycode of the altkeysym */
KeyCode tabkeycode; /* keycode of the tabkeysym */
unsigned int modifier; /* modifier of the altkeycode */
- unsigned int shift; /* shift modifier */
int corner; /* = .borderwidth + .titlewidth */
int divwidth; /* = .borderwidth */
};
diff --git a/xevents.c b/xevents.c
@@ -200,13 +200,6 @@ isvalidstate(unsigned int state)
return config.modifier != 0 && (state & config.modifier) == config.modifier;
}
-/* check whether given state matches shift */
-static int
-isshiftstate(unsigned int state)
-{
- return config.shift != 0 && (state & config.shift) == config.shift;
-}
-
/* get tab given window is a dialog for */
static struct Tab *
getdialogfor(Window win)
@@ -722,7 +715,7 @@ alttab(int shift)
case KeyPress:
if (ev.xkey.keycode == config.tabkeycode && isvalidstate(ev.xkey.state)) {
containerbacktoplace(c, 1);
- c = containerraisetemp(c, isshiftstate(ev.xkey.state));
+ c = containerraisetemp(c, (ev.xkey.state & ShiftMask));
}
break;
case KeyRelease:
@@ -1823,7 +1816,6 @@ void
setmod(void)
{
config.altkeycode = 0;
- config.modifier = 0;
if ((config.altkeycode = XKeysymToKeycode(dpy, config.altkeysym)) == 0) {
warnx("could not get keycode from keysym");
return;
@@ -1832,10 +1824,6 @@ setmod(void)
warnx("could not get keycode from keysym");
return;
}
- if ((config.modifier = XkbKeysymToModifiers(dpy, config.altkeysym)) == 0) {
- warnx("could not get modifier from keysym");
- return;
- }
if (config.disablealttab)
return;
XUngrabKey(dpy, config.tabkeycode, config.modifier, root);