You are not logged in.
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.
Thank you.
Regards
Last edited by orschiro (2010-05-04 22:23:56)
Offline
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
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
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
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
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
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
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
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