sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-keycodes-6.4.diff (7098B)


      1 From 081fc7fb9aa2f45df786561bbcbc99adf8509a90 Mon Sep 17 00:00:00 2001
      2 From: Quentin Rameau <quinq@fifth.space>
      3 Date: Tue, 10 Apr 2018 13:26:33 +0200
      4 Subject: [PATCH] Use keycode for keyboard input instead of keysyms
      5 
      6 ---
      7  config.def.h | 68 ++++++++++++++++++++++++++--------------------------
      8  dwm.c        | 16 +++++--------
      9  2 files changed, 40 insertions(+), 44 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 061ad66..bba31ed 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -60,40 +60,40 @@ static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray
     16  static const char *termcmd[]  = { "st", NULL };
     17  
     18  static const Key keys[] = {
     19 -	/* modifier                     key        function        argument */
     20 -	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
     21 -	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
     22 -	{ MODKEY,                       XK_b,      togglebar,      {0} },
     23 -	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
     24 -	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
     25 -	{ MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
     26 -	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
     27 -	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
     28 -	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
     29 -	{ MODKEY,                       XK_Return, zoom,           {0} },
     30 -	{ MODKEY,                       XK_Tab,    view,           {0} },
     31 -	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
     32 -	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
     33 -	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
     34 -	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
     35 -	{ MODKEY,                       XK_space,  setlayout,      {0} },
     36 -	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
     37 -	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
     38 -	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
     39 -	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
     40 -	{ MODKEY,                       XK_period, focusmon,       {.i = +1 } },
     41 -	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
     42 -	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
     43 -	TAGKEYS(                        XK_1,                      0)
     44 -	TAGKEYS(                        XK_2,                      1)
     45 -	TAGKEYS(                        XK_3,                      2)
     46 -	TAGKEYS(                        XK_4,                      3)
     47 -	TAGKEYS(                        XK_5,                      4)
     48 -	TAGKEYS(                        XK_6,                      5)
     49 -	TAGKEYS(                        XK_7,                      6)
     50 -	TAGKEYS(                        XK_8,                      7)
     51 -	TAGKEYS(                        XK_9,                      8)
     52 -	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
     53 +	/* modifier             key     function        argument */
     54 +	{ MODKEY,               33,     spawn,          {.v = dmenucmd } }, // p
     55 +	{ MODKEY|ShiftMask,     36,     spawn,          {.v = termcmd } }, // Return
     56 +	{ MODKEY,               56,     togglebar,      {0} },          // b
     57 +	{ MODKEY,               44,     focusstack,     {.i = +1 } },   // j
     58 +	{ MODKEY,               45,     focusstack,     {.i = -1 } },   // k
     59 +	{ MODKEY,               31,     incnmaster,     {.i = +1 } },   // i
     60 +	{ MODKEY,               40,     incnmaster,     {.i = -1 } },   // d
     61 +	{ MODKEY,               43,     setmfact,       {.f = -0.05} }, // h
     62 +	{ MODKEY,               46,     setmfact,       {.f = +0.05} }, // l
     63 +	{ MODKEY,               36,     zoom,           {0} },          // Return
     64 +	{ MODKEY,               23,     view,           {0} },          // Tab
     65 +	{ MODKEY|ShiftMask,     54,     killclient,     {0} },          // c
     66 +	{ MODKEY,               28,     setlayout,      {.v = &layouts[0]} }, // t
     67 +	{ MODKEY,               41,     setlayout,      {.v = &layouts[1]} }, // f
     68 +	{ MODKEY,               58,     setlayout,      {.v = &layouts[2]} }, // m
     69 +	{ MODKEY,               65,     setlayout,      {0} },          // space
     70 +	{ MODKEY|ShiftMask,     65,     togglefloating, {0} },          // space
     71 +	{ MODKEY,               19,     view,           {.ui = ~0 } },  // 0
     72 +	{ MODKEY|ShiftMask,     19,     tag,            {.ui = ~0 } },  // 0
     73 +	{ MODKEY,               59,     focusmon,       {.i = -1 } },   // comma
     74 +	{ MODKEY,               60,     focusmon,       {.i = +1 } },   // period
     75 +	{ MODKEY|ShiftMask,     59,     tagmon,         {.i = -1 } },   // comma
     76 +	{ MODKEY|ShiftMask,     60,     tagmon,         {.i = +1 } },   // period
     77 +	TAGKEYS(                10,                     0)              // 1
     78 +	TAGKEYS(                11,                     1)              // 2
     79 +	TAGKEYS(                12,                     2)              // 3
     80 +	TAGKEYS(                13,                     3)              // 4
     81 +	TAGKEYS(                14,                     4)              // 5
     82 +	TAGKEYS(                15,                     5)              // 6
     83 +	TAGKEYS(                16,                     6)              // 7
     84 +	TAGKEYS(                17,                     7)              // 8
     85 +	TAGKEYS(                18,                     8)              // 9
     86 +	{ MODKEY|ShiftMask,     24,     quit,           {0} },          // q
     87  };
     88  
     89  /* button definitions */
     90 diff --git a/dwm.c b/dwm.c
     91 index e5efb6a..65b4562 100644
     92 --- a/dwm.c
     93 +++ b/dwm.c
     94 @@ -31,7 +31,6 @@
     95  #include <sys/types.h>
     96  #include <sys/wait.h>
     97  #include <X11/cursorfont.h>
     98 -#include <X11/keysym.h>
     99  #include <X11/Xatom.h>
    100  #include <X11/Xlib.h>
    101  #include <X11/Xproto.h>
    102 @@ -101,7 +100,7 @@ struct Client {
    103  
    104  typedef struct {
    105  	unsigned int mod;
    106 -	KeySym keysym;
    107 +	KeyCode keycode;
    108  	void (*func)(const Arg *);
    109  	const Arg arg;
    110  } Key;
    111 @@ -957,14 +956,13 @@ grabkeys(void)
    112  	{
    113  		unsigned int i, j;
    114  		unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
    115 -		KeyCode code;
    116  
    117  		XUngrabKey(dpy, AnyKey, AnyModifier, root);
    118  		for (i = 0; i < LENGTH(keys); i++)
    119 -			if ((code = XKeysymToKeycode(dpy, keys[i].keysym)))
    120 -				for (j = 0; j < LENGTH(modifiers); j++)
    121 -					XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
    122 -						True, GrabModeAsync, GrabModeAsync);
    123 +			for (j = 0; j < LENGTH(modifiers); j++)
    124 +				XGrabKey(dpy, keys[i].keycode,
    125 +				         keys[i].mod | modifiers[j], root,
    126 +				         True, GrabModeAsync, GrabModeAsync);
    127  	}
    128  }
    129  
    130 @@ -991,13 +989,11 @@ void
    131  keypress(XEvent *e)
    132  {
    133  	unsigned int i;
    134 -	KeySym keysym;
    135  	XKeyEvent *ev;
    136  
    137  	ev = &e->xkey;
    138 -	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
    139  	for (i = 0; i < LENGTH(keys); i++)
    140 -		if (keysym == keys[i].keysym
    141 +		if (ev->keycode == keys[i].keycode
    142  		&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
    143  		&& keys[i].func)
    144  			keys[i].func(&(keys[i].arg));
    145 -- 
    146 2.40.0
    147