You are not logged in.

#1 2013-05-22 11:16:17

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Binding Caps Lock key to Control not fully working (dwm related)

Hey there!

To switch tags in dwm (and to use emacs) more easily I want to bind my caps lock key to be a control key.

I configured my caps lock key to behave like a control key by the means of xmodmap. My .Xmodmap looks like this:

remove control = Control_L
keycode  66 = Control_L NoSymbol Control_L
clear lock
add control = Control_L

This works fine for most cases. But pressing "mod4 + caps lock + w" does has not the desired effect to behave like "mod4 + control + w" -- how can this happen?
I also tried using setxkbmap with

setxkbmap -option ctrl:nocaps

but it shows the very same behaviour.

Background:
For a more convenient tag(ging) experience in dwm I named the 9 tags as 1 2 3 q w e a s d. But the problem described above hampers a pleasent usage. What follows is a quite minimal config.h for dwm -- note that I swapped the keybinding for view and toggleview and that "XK_w" doesn't appear in config.h but once (so the problem shouldn't lie in my dwm configuration, does it?)

/* config.h */

/* appearance */
static const char font[]            = "-*-profont-medium-r-*-*-12-*-*-*-*-*-*-*";
static const char normbordercolor[] = "#444444";
static const char normbgcolor[]     = "#222222";
static const char normfgcolor[]     = "#bbbbbb";
static const char selbordercolor[]  = "#005577";
static const char selbgcolor[]      = "#005577";
static const char selfgcolor[]      = "#eeeeee";
static const unsigned int borderpx  = 2;        /* border pixel of windows */
static const unsigned int snap      = 32;       /* snap pixel */
static const Bool showbar           = True;     /* False means no bar */
static const Bool topbar            = True;     /* False means bottom bar */

/* tagging */
static const char *tags[] = { "1", "2", "3", "q", "w", "e", "a", "s", "d" };

static const Rule rules[] = {
	/* class      instance    title       tags mask     isfloating   monitor */
	{ "Firefox",  NULL,       NULL,       1 << 8,       False,       -1 },
	{ "Thunderbird", NULL,    NULL,       1 << 8,       False,       -1 },
	{ "Dwb",      NULL,       NULL,       1 << 1,       False,       -1 },
	{ "Emacs",    NULL,       NULL,       1 << 2,       False,       -1 },
	{ "Zathura",  NULL,       NULL,       1 << 3,       False,       -1 },
	{ "MPlayer",  NULL,       NULL,       1 << 4,       False,       -1 },
	{ "Skype",    NULL,       NULL,       1 << 5,       True,        -1 },
	{ "Gimp",     NULL,       NULL,       1 << 6,       True,        -1 },
	{ "Exe",      NULL,       NULL,       0,            True,        -1 },
	{ "Plugin-container",NULL,NULL,       0,            True,        -1 },

};

/* layout(s) */
static const float mfact      = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster      = 1;    /* number of clients in master area */
static const Bool resizehints = True; /* True means respect size hints in tiled resizals */

static const Layout layouts[] = {
	/* symbol     arrange function */
	{ "[]=",      tile },    /* first entry is default */
	{ "><>",      NULL },    /* no layout function means floating behavior */
	{ "[M]",      monocle },
};

/* key definitions */
#define MODKEY Mod4Mask
#define TAGKEYS(KEY,TAG) \
	{ MODKEY|ControlMask,           KEY,      view,           {.ui = 1 << TAG} }, \
	{ MODKEY,                       KEY,      toggleview,     {.ui = 1 << TAG} }, \
	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },

/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }

/* commands */
static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
static const char *termcmd[]  = { "urxvt", NULL };
static const char *emacscmd[]  = { "em", NULL };
static const char *mailcmd[]  = { "urxvt", "-e", "mutt", NULL };
static const char *rangercmd[]  = { "urxvt", "-e", "ranger", NULL };
static const char *musiccmd[]  = { "urxvt", "-e", "mocp", NULL };
static const char *newscmd[]  = { "urxvt", "-e", "newsbeuter", NULL };
static const char *dwbcmd[]  =  { "dwb", NULL };

static Key keys[] = {
	/* modifier                     key        function        argument */
	{ MODKEY|ShiftMask,             XK_x,      spawn,          {.v = emacscmd } },
	{ MODKEY|ShiftMask,             XK_r,      spawn,          {.v = rangercmd } },
	{ MODKEY|ShiftMask,             XK_y,      spawn,          {.v = mailcmd } },
	{ MODKEY|ShiftMask,             XK_m,      spawn,          {.v = musiccmd } },
	{ MODKEY|ShiftMask,             XK_n,      spawn,          {.v = newscmd } },
	{ MODKEY|ShiftMask,             XK_b,      spawn,          {.v = dwbcmd } },
	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
	{ MODKEY,                       XK_b,      togglebar,      {0} },
	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
	{ MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
	{ MODKEY|ShiftMask,             XK_i,      incnmaster,     {.i = -1 } },
	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
	{ MODKEY,                       XK_Return, zoom,           {0} },
	{ MODKEY,                       XK_Tab,    view,           {0} },
	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
	{ MODKEY,                       XK_space,  setlayout,      {0} },
	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
	{ MODKEY,                       XK_period, focusmon,       {.i = +1 } },
	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
	TAGKEYS(                        XK_1,                      0)
	TAGKEYS(                        XK_2,                      1)
	TAGKEYS(                        XK_3,                      2)
	TAGKEYS(                        XK_q,                      3)
	TAGKEYS(                        XK_w,                      4)
	TAGKEYS(                        XK_e,                      5)
	TAGKEYS(                        XK_a,                      6)
	TAGKEYS(                        XK_s,                      7)
	TAGKEYS(                        XK_d,                      8)
	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
};

/* button definitions */
/* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
	/* click                event mask      button          function        argument */
	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
	{ ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
	{ ClkTagBar,            0,              Button1,        view,           {0} },
	{ ClkTagBar,            0,              Button3,        toggleview,     {0} },
	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
};

I am stuck here. Any hints?

Offline

#2 2013-05-22 11:59:01

chpln
Member
From: Australia
Registered: 2009-09-17
Posts: 361

Re: Binding Caps Lock key to Control not fully working (dwm related)

I've an almost identical configuration under XMonad (ctrl-mod4 for some WM bindings) and it behaved correctly when using your xmodmap.

If you issue a key sequence not bound under dwm while Emacs is in focus, does emacs show the right key sequence in the modeline?

Last edited by chpln (2013-05-22 12:00:41)

Offline

#3 2013-05-22 12:18:14

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Re: Binding Caps Lock key to Control not fully working (dwm related)

chpln wrote:

If you issue a key sequence not bound under dwm while Emacs is in focus, does emacs show the right key sequence in the modeline?

Yes! Pressing "Mod4 + caps lock + w" in emacs has no effect on the emacs modeline at all -- this means that the key stroke is catched somewhere, because pressing another combination like "Mod4 + caps lock + l" makes emacs complaining "C-s-l is undefined".

But other than a .xbindkeysrc, which doesn't involve the "w" key at all, I have no additional key mapping configuration on my system. This is strange.

Last edited by ball (2013-05-22 12:34:00)

Offline

#4 2013-05-22 12:29:03

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,042

Re: Binding Caps Lock key to Control not fully working (dwm related)

I use dwm and I make caps lock another ctrl via the setxkbmap method and Emacs catches mod4-caps-w as "C-s-w is undefined". So something's going on in your setup for sure.

Offline

#5 2013-05-22 13:56:46

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Re: Binding Caps Lock key to Control not fully working (dwm related)

I Just unbound "XK_w" in dwm but still emacs can't catch "mod4 + caps lock + w". Every other combination  "mod4 + caps lock + <key>" gets catched by emacs correctly. This is so odd.

jakobcreutzfeldt wrote:

So something's going on in your setup for sure.

I know that this could be anything, nevertheless I'm asking what the problem could be. I just checked all the files which come into consideration (.xbindkeysrc, .Xmodmap, .xinitrc, dwm config.h) but I couldn't find anything.

Offline

#6 2013-05-22 14:05:12

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,042

Re: Binding Caps Lock key to Control not fully working (dwm related)

Yeah, sorry that wasn't super helpful.

Try installing xorg-twm and running it instead of dwm, then run emacs within it and try again if the keycombo is not being caught. That can at least rule out whether it's the window manager. Alternatively, try running dwm with a bare .xinitrc and no .xbindkeysrc or .Xmodmap. Hopefully one of those will help narrow down the source of the problem.

Offline

#7 2013-05-22 14:54:33

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Re: Binding Caps Lock key to Control not fully working (dwm related)

Thanks. I renamed my .xinitrc and did startx, launching twm. Turns out that even then emacs is not able to catch this very key combo. I searched for modified files with

sudo pacman -Qii | awk '/^MODIFIED/ {print $2}'

but the only one having to do with X was /etc/X11/xorg.conf.d/10-evdev.conf, where I configured only my keyboard layout.

I'm beginning to suspect that it's my keyboard (Lenovo Thinkpad T400). Maybe I should use the next opportunity to stick in an USB keyboard in order check this...

Offline

Board footer

Powered by FluxBB