You are not logged in.

#1 2020-04-18 08:27:13

csihshf
Member
Registered: 2020-02-18
Posts: 20

[SOLVED] DWM changing keyboard layout

Hello,

I use dwm for year now with dwmblocks as my status bar. Previously i had this line in my dwm config file for changing keyboard layouts

setxkbmap -query | grep -q 'us' && setxkbmap fr || setxkbmap us; pkill -RTMIN+1 dwmblocks

I felt like this was the wrong way of doing it. It did not configure 2 layouts it was just jumping from one to other. So i put this code in my xorg.conf.d folder and i am changing keyboard layouts with caps_lock key.

Section "InputClass"
  Identifier "system-keyboard"
  MatchIsKeyboard "on"
  Option "XkbLayout" "us,fr"
  Option "XkbModel" "pc104"
  Option "XkbVariant" "qwerty"
  Option "XkbOptions" "grp:caps_toggle,terminate:ctrl_alt_bksp"
EndSection

caps_lock is changing keyboard layout but i have one small problem. When i used first code you see last command "pkill -RTMIN+1 dwmblocks" this updated my status line and showed current layout which was set up. I could not find parameter to set in second code in xorg.conf.d folder to execute that command on cap_lock press. I tried to assign that command in dwm configuration to caps_lock key, but there is a problem. When i assign caps_lock to layout change it's no longer detected as caps_lock. I checked it in xev

Here is output of xev when assigned caps_lock. When it was not assigned to layout change shortcut it said Caps_Lock.

FocusOut event, serial 32, synthetic NO, window 0x4e00001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 32, synthetic NO, window 0x4e00001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 32, synthetic NO, window 0x0,
    keys:  114 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0

Last edited by csihshf (2020-04-21 08:18:37)

Offline

#2 2020-04-18 11:02:26

azagthoth
Member
From: Germany
Registered: 2019-03-12
Posts: 16

Re: [SOLVED] DWM changing keyboard layout

So what is the problem with the first solution? It seems to me that it works just fine.

Offline

#3 2020-04-20 16:46:52

csihshf
Member
Registered: 2020-02-18
Posts: 20

Re: [SOLVED] DWM changing keyboard layout

azagthoth wrote:

So what is the problem with the first solution? It seems to me that it works just fine.

did i ask if it's good or not? Arch wiki has second version as suggested way of setting up keyboard layouts. I also think it's better way to do it. As it really sets up 2 layouts instead of jumping from one to other.

Now i have problem with it because in first version when i set up Caps_Lock key as shortcut for that command in DWM config it messes up. Second language is in upper state. It somehow retains it's original functionality which is sticking shift key pressed. When i set it up the correct way from xorg.conf.d this does not happen. Caps_Lock just changes layout and it's losing it's original function. So in short first way does not work when i want to change layouts with Caps_Lock key from DWM.

Last edited by csihshf (2020-04-20 16:47:29)

Offline

#4 2020-04-20 17:13:43

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [SOLVED] DWM changing keyboard layout

csihshf wrote:

did i ask if it's good or not?

No.  Nor did azagthoth say it was good or bad.  He simply asked what was wrong with it.  If you want help acheiving a goal, it's useful to describe what parts of the goal are not yet met.

csihshf wrote:

Now i have problem ... sticking shift key pressed.

So if that's the only problem with the first solution, there is another alternative.  But no one could offer another alternative until you described what problem needed to be solved.  You can keep the key binding (your first solution) and just remove the lock functionality from the capslock key with setxkbmap or similar.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2020-04-20 18:12:38

csihshf
Member
Registered: 2020-02-18
Posts: 20

Re: [SOLVED] DWM changing keyboard layout

Trilby wrote:

You can keep the key binding (your first solution) and just remove the lock functionality from the capslock key with setxkbmap or similar.

Previously i had disabled caps_lock key with this command in my .xinitrc

setxkbmap -option caps:none

But this disables whole key and by xev it's detected as "VoidSymbol".

I did not find other solution to just remove that functionality from caps_lock key but still have the key enabled.

Last edited by csihshf (2020-04-20 21:08:19)

Offline

#6 2020-04-20 18:16:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,578
Website

Re: [SOLVED] DWM changing keyboard layout

Ah, right.  I suppose xmodmap would be better if you just want to clear the locking but keep the key.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2020-04-20 21:21:20

csihshf
Member
Registered: 2020-02-18
Posts: 20

Re: [SOLVED] DWM changing keyboard layout

Yeah

xmodmap -e 'clear Lock'

tried this but still it does not work.

How i test.

When pressing on Caps_Lock dwm runs this command

setxkbmap -query | grep -q 'us' && setxkbmap fr || setxkbmap us; pkill -RTMIN+1 dwmblocks

and when i try to type something in browser it show squars.

But when i swith layout from terminal command directly by running

setxkbmap fr

it works in terminal and in browser too.

If i change shortcut key in DWM config to say ctrl + space for that command, it works in terminal and browser too just like when i change layouts directly from terminal. This is why i think Caps_Lock is the issue here.

Last edited by csihshf (2020-04-20 21:33:18)

Offline

#8 2020-04-21 05:54:56

seth
Member
Registered: 2012-09-03
Posts: 51,945

Re: [SOLVED] DWM changing keyboard layout

when i try to type something in browser it show squars

Squares? Caps? You presumingly did not remove the caps functionality from the key, so you activate the shortcut and at the same time enter the caps lock?

xset q | grep -i caps

https://dwm.suckless.org/patches/xkb/

Offline

#9 2020-04-21 06:26:52

csihshf
Member
Registered: 2020-02-18
Posts: 20

Re: [SOLVED] DWM changing keyboard layout

seth wrote:

when i try to type something in browser it show squars

Squares? Caps? You presumingly did not remove the caps functionality from the key, so you activate the shortcut and at the same time enter the caps lock?

xset q | grep -i caps

https://dwm.suckless.org/patches/xkb/

That is exactly what i am trying to solve.

That command says

00: Caps Lock:   on

when i press caps lock to change layout. It changes layout but also activates lock. That is the source of this problem. As suggested in previous posts i tried to remove lock functionality from caps lock button, but

xmodmap -e 'clear Lock'

does not work, although man page says it should. I would prefer to resolve this issue without patching dwm. I would like to have dwm modified as minimally as possible. It's the last thing i would do to fix this problem.

Offline

#10 2020-04-21 06:39:14

seth
Member
Registered: 2012-09-03
Posts: 51,945

Re: [SOLVED] DWM changing keyboard layout

"xmodmap -pm" before and after the attempted clearance?
The state is though likely reset w/ the next layout change.

You could perhaps map caps_lock to something entirely different (eg. the "hyper" key through xkb or really anything like F13-F20 using xmodmap, again: lost with the next layout change)

Other than that you'd either have to constantly poll the layout or write a daemon that listens to layout changes (as the dwm patch provides)

I would like to have dwm modified as minimally as possible

The patches are a normal thing for the suckless tools. You want the feature, so patch it in. Anything else is a rather cumbersome crutch.

Offline

#11 2020-04-21 08:08:34

csihshf
Member
Registered: 2020-02-18
Posts: 20

Re: [SOLVED] DWM changing keyboard layout

I reverted this configuration

Section "InputClass"
  Identifier "system-keyboard"
  MatchIsKeyboard "on"
  Option "XkbLayout" "us,fr"
  Option "XkbModel" "pc104"
  Option "XkbVariant" "qwerty"
  Option "XkbOptions" "grp:caps_toggle,terminate:ctrl_alt_bksp"
EndSection

I just realized when this disables caps_lock it actually assigns new keysym ISO_Next_Group, so i put XK_ISO_Next_Group as shortcut to run

pkill -RTMIN+1 dwmblocks

which updates layout on dwm bar.

So the issue is solved. Thanks for helping me.

Last edited by csihshf (2020-04-21 08:18:04)

Offline

Board footer

Powered by FluxBB