You are not logged in.

#1 2010-05-04 22:23:32

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Display keyboard layout in xsetroot

Hello guys,

I'm using dwm in combination with a tiny xsetroot statusbar. This are the responsible lines in .xinitrc:

#statusbar
while true
do
    if acpi -a | grep off-line > /dev/null; then
        xsetroot -name "Bat. $( acpi -b | awk '{ print $4 $5 }' | tr -d ',' ) | $(date +"%a, %b %d %R")"
    else
        xsetroot -name "$(date +"%a, %b %d %R")"
    fi
    sleep 1s   
done &

I'm toggling between two layouts in X which I set in my 10-keymap.fdi.

   <merge key="input.xkb.layout" type="string">de,pl</merge>
   <merge key="input.xkb.options" type="string">grp:alt_shift_toggle</merge>

Now I'm thinking of how to display the currently used layout in this xsetroot statusbar? I thought of any If-statement.

Any ideas? I'm not as that familiar with bash programming but perhaps you could help me out. smile

Thank you.

Regards

Last edited by orschiro (2010-05-04 22:23:56)

Offline

#2 2010-05-07 07:36:47

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Display keyboard layout in xsetroot

Any ideas?

Offline

#3 2010-05-27 13:00:38

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Display keyboard layout in xsetroot

I'm a step further now. xset -q gives me indirectly what I want.

Using that command in combination with grep and awk I have this:

$ xset -q | grep "LED mask:" | awk '{ print $10 }'
00000000 
00010000

This either outputs 00000000 for german layout or 00010000 for polish layout.

Now the point where I failed - constructing my xsetroot command.

I first want to query which of the two layouts is used currently and then print it in the xsetroot command.

Here my adapted version that isn't working so far. It doesn't display the layout in the bar.

#set statusbar
while true
do

   #define keyboard layout
   if [ "$(xset -q | grep "LED mask:" | awk '{ print $10 }')" == "00000000" ] ; then
           kb = "de"
   else
           kb = "pl"
   fi
   #print statusbar depending on ac_status
   if acpi -a | grep off-line > /dev/null; then
       xsetroot -name "Bat. $( acpi -b | awk '{ print $4 " " $5 }' | tr -d ',' ) | Vol. $(amixer get Master | tail -1 | awk '{ print $5 }' | tr -d '[]') | $kb | $(date +"%a, %b %d %R")"
   else
       xsetroot -name "Vol. $(amixer get Master | tail -1 | awk '{ print $5 }' | tr -d '[]') | $kb | $(date +"%a, %b %d %R")"
   fi
   sleep 1s
done &

It would be great if someone could assist me as I'm not really familiar with bash scripting.

Thank you

Last edited by orschiro (2010-05-27 13:01:25)

Offline

#4 2010-05-27 13:36:58

skualito
Member
Registered: 2008-11-19
Posts: 203

Re: Display keyboard layout in xsetroot

I can see your question's been answered on the ml at suckless, but here is just another way to get the current keyboard layout displayed, without having to sed the code of the layout.

setxkbmap -print | grep xkb_symbols | awk '{print $4}' | awk -F"+" '{print $2}'

from this thread

Offline

#5 2010-05-27 13:45:16

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: Display keyboard layout in xsetroot

For me the trouble is xset because when I change my layout with 'setxkbmap pl' it doesn't change the output of xset.

I think that you should use 'setxkbmap -print' instead

Last edited by lymphatik (2010-05-27 13:47:03)

Offline

#6 2010-05-27 13:49:36

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Display keyboard layout in xsetroot

Hello skualito,

as I wrote already at the mailing list this line always prints me just 'de' even when I toggle between the layouts.

Regards

EDIT:

Obviously changing the layout via evdev doesn't change the line of xkb_symbols.

When I manually do setxkbmap pl or de then everything is fine.

Last edited by orschiro (2010-05-27 13:54:43)

Offline

#7 2010-05-27 13:55:16

skualito
Member
Registered: 2008-11-19
Posts: 203

Re: Display keyboard layout in xsetroot

hmm, it's working on my computer, changing between layouts displays instantly the layout on the statusbar. Maybe a line wrapping problem or indentation.

while xsetroot -name "$(setxkbmap -print | grep xkb_symbols | awk '{print $4}' | awk -F"+" '{print $2}') | $(date +"%a, %b %d %Y | %H:%M")"
do sleep 2s
done &

Offline

#8 2010-05-27 13:56:26

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: Display keyboard layout in xsetroot

Could you try to set your layout with setxkbmap pl and run this

setxkbmap -print | grep xkb_symbols | awk -F"+" '{print $2}'

Because it works perfectly for me. However I don't use dbus or hal to switch keyboard layout

Offline

#9 2010-05-27 14:04:57

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Display keyboard layout in xsetroot

See my post above. It's working fine then. But why not in combination with evdev?

And how do you toggle between the layouts? With a shortcut in config.h of dwm?

Offline

#10 2010-05-27 17:51:57

Ogion
Member
From: Germany
Registered: 2007-12-11
Posts: 367

Re: Display keyboard layout in xsetroot

Without having studied the specifics here, but one idea: Is there a way to include writing the current layout to a file in the same command/script that you use to switch layout? Then you'd just have to read that file. Shouldn't be too hard i imagine.

Ogion


(my-dotfiles)
"People willing to trade their freedom for temporary security deserve neither and will lose both." - Benjamin Franklin
"Enlightenment is man's leaving his self-caused immaturity." - Immanuel Kant

Offline

#11 2011-08-30 22:06:56

zx201
Member
Registered: 2011-08-28
Posts: 3

Re: Display keyboard layout in xsetroot

orschiro wrote:

   if [ "$(xset -q | grep "LED mask:" | awk '{ print $10 }')" == "00000000" ] ; then
           kb = "de"
   else
           kb = "pl"
   fi

You are doing it wrong.
Should be like this:

if [ "$(xset -q | grep "LED mask:" | awk '{ print $10 }')" == "00000000" ] ; then
  xsetroot -name "de :: $(date '+%d-%m-%Y %R')"
else
  xsetroot -name "pl :: $(date '+%d-%m-%Y %R')"
fi

Offline

Board footer

Powered by FluxBB