You are not logged in.

#1 2009-05-31 08:15:55

Liuuutas
Member
From: Cambridge
Registered: 2009-05-02
Posts: 71

[SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Hi guys,

I have a question here. Well at the moment I am using axkb for keyboard layout svitching as someone here in the forums has suggested, but I have recently found another way. There is a script called xkbSwitch. This way is better as it does not require many dependancies.

However it does not provide any indicator for the present keyboard layout. So, my question is - is there any software, that could create a user defined icon and changed it according to any bash script?

Thanks in advance.

Last edited by Liuuutas (2009-06-07 10:22:29)

Offline

#2 2009-05-31 08:51:41

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

You could use dzen2 to draw an icon (xpm) for the current layout. Dzen2 could be integrated in to the xkbswitch script without too much trouble.

Offline

#3 2009-05-31 09:22:38

Ashren
Member
From: Denmark
Registered: 2007-06-13
Posts: 1,229
Website

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Actually it is really easy:

 #!/bin/bash

#############
# @author: Hardik
# @purpose: Cycle through the keyboard layouts sotored in
# ~/.xkbSwitch/xkb_layouts file
# This script is called on Ctrl + Alt + k key-combination in fluxbox
################

LAYOUTS_FILE=~/.xkbSwitch/xkb_layouts
INDEX_FILE=~/.xkbSwitch/index

if [ ! -r $LAYOUTS_FILE ]; then
    echo "File $LAYOUTS_FILE does not exist"
    exit 1
fi

# if the script is running the frist time
if [ ! -r $INDEX_FILE ]; then
    echo '0' > $INDEX_FILE
fi

read line < $INDEX_FILE

let "INDEX=$line+1"
INNER_INDEX=0

while read line
do
    LAYOUTS[$INNER_INDEX]=$line
    let "INNER_INDEX +=1"
done <$LAYOUTS_FILE

if [ $INDEX -ge $INNER_INDEX ]; then
    let "INDEX -=$INNER_INDEX"
fi

setxkbmap -layout ${LAYOUTS[$INDEX]}

if [ $? = "0" ]; then
    echo $INDEX >$INDEX_FILE
    echo ${LAYOUTS[$INDEX]} | dzen2 -p -w 30 -fg 'green' &
fi

Offline

#4 2009-06-07 10:22:53

Liuuutas
Member
From: Cambridge
Registered: 2009-05-02
Posts: 71

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Thank you very much... smile

Offline

#5 2009-06-08 19:51:23

ThomasAdam
Member
From: Southampton, England
Registered: 2005-10-26
Posts: 148

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Liuuutas wrote:

Hi guys,

I have a question here. Well at the moment I am using axkb for keyboard layout svitching as someone here in the forums has suggested, but I have recently found another way. There is a script called xkbSwitch. This way is better as it does not require many dependancies.

However it does not provide any indicator for the present keyboard layout. So, my question is - is there any software, that could create a user defined icon and changed it according to any bash script?

Thanks in advance.

Since you mention FVWM, you could do this with FvwmButtons.

-- Thomas Adam

Offline

#6 2009-06-09 09:55:59

Liuuutas
Member
From: Cambridge
Registered: 2009-05-02
Posts: 71

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Thank you for this thought... I even haven't considered it... smile I guess I was mislead due to the really ugly FvwmButtons looked in the default configuration... smile

Offline

#7 2009-06-14 13:08:21

vennen
Member
From: Russian Federation
Registered: 2008-03-27
Posts: 72

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

I faced same problem in Fluxbox but even worse. I have us and ru keyboard layouts and trick wich was described hereabove doesnt work. Any letter keys doesnt work when russian layout is choosen.

I combined answers from Hardik's code, some stuff from Debian forums (dont remember link) and Ashren's dzen feature. Its useful for cyrillic layouts used with latin ones.

I put this in 'keys' file in ~/.fluxbox

 
Mod4 F5 :ExecCommand ~/.bin/kb_us
Mod4 F6 :ExecCommand ~/.bin/kb_ru

and made two executable files ( 'kb_ru' and 'kb_en') in ~/.bin direcrtory. Of course you can take any directory you want, but put the path in 'keys' file.
kb_ru contains:

 
#!/bin/bash
killall dzen2
setxkbmap -layout ru | echo ru | dzen2 -p -w 30 -x 1180 -y 768 -fg 'green' &

and kb_us:

 
#!/bin/bash
killall dzen2
setxkbmap -layout us | echo us | dzen2 -p -w 30 -x 1180 -y 768 -fg 'green' &

save it and restart Fluxbox. Enjoy!

P.S. My laptop screen is 1200x800 so set dzen's -x and -y for you desire.

Last edited by vennen (2009-06-14 13:11:43)

Offline

#8 2009-06-14 13:53:18

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Why are you piping setxkbmap output to echo ?

Last edited by moljac024 (2009-06-14 13:57:16)


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#9 2009-06-14 16:43:53

vennen
Member
From: Russian Federation
Registered: 2008-03-27
Posts: 72

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

I'm not programmer and know bash very bad. Maybe its not needed. But it works. It would be nice if you correct me.

Do I need delete pipe symbol '|' and put 'echo ....' on the next line?

Last edited by vennen (2009-06-14 16:47:25)

Offline

#10 2009-06-15 04:53:13

Liuuutas
Member
From: Cambridge
Registered: 2009-05-02
Posts: 71

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Well in Fvwm I also set up the ru layout. I just set a global shortcut key and fvwm understood it no matter the layout was smile.

Offline

#11 2009-06-15 11:13:17

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

vennen wrote:

I'm not programmer and know bash very bad. Maybe its not needed. But it works. It would be nice if you correct me.

Do I need delete pipe symbol '|' and put 'echo ....' on the next line?

It's no issue really, but since echo doesn't operate on input but only it's arguments, it's pointless to pipe stuff to it.
You can just replace the pipe symbol with "&&" <- that means execute the next command only if the last one terminated successfully.

Last edited by moljac024 (2009-06-15 11:13:52)


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#12 2009-06-16 21:34:01

vennen
Member
From: Russian Federation
Registered: 2008-03-27
Posts: 72

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

OK, thank you, moljac024

Offline

#13 2009-06-20 18:58:36

ThomasAdam
Member
From: Southampton, England
Registered: 2005-10-26
Posts: 148

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Liuuutas wrote:

Thank you for this thought... I even haven't considered it... :) I guess I was mislead due to the really ugly FvwmButtons looked in the default configuration... :)

You clearly didn't understand what it was designed for.  No surprise there -- no one reads the man page for things these days.

There's no reliable way of getting X11 to tell you what keyboard layout is in use [1] so come up with your own mechanism when you set it, perhaps:

#!/bin/bash
# Redefine/reload keyboard layout.

die()
{
    echo "$@" >&2
    exit
}

[ -z "$DISPLAY" ] && die "$0:  Can't connect to X server"

# No validation is done here...
[ -n "$1" ] && echo "$1" > ~/.xkblayyout || die "$0:  Failed to write to ~/.xkblayout"
setxkbmap -layout $(< ~/.xkblayout)

You can improve upon that -- it's just a crappy example.  Obviously if you change the layout, or have a mechanism for doing so, then you will have to reload it in the same way -- by echoing the value to the nominated file overwriting the previous contents.  For the benefit of this example, this file is:  ~/bin/setkeyboard.sh

Anyway -- assume that's how it's going to happen.  In terms of FVWM, here's an example FvwmButtons configuration:

DestroyFunc GetKBDLayout
AddToFunc   GetKBDLayout
+ I PipeRead `echo SetEnv KBDLAYOUT $(cat ~/.xkblayout)`

DestroyFunc SetKBDLayout
AddToFunc   SetKBDLayout
+ I PipeRead `~/bin/setkeyboard.sh $0`
+ I GetKBDLayout
+ I SendToModule FB ChangeButton A Icon $[KBDLAYOUT].png

DestroyModuleConfig FB:*
*FB: Columns 3
*FB: Rows 1
*FB: (1x3, Id A, Title "keyboard layout", Icon $[KBDLAYOUT].png, Action (Mouse 1) SetKBDLayout us, Action (Mouse 3) SetKBDLayout en)

AddToFunc StartFunction I Module FvwmButtons FB

You'd have to ensure that something set KBDLAYOUT at FVWM startup so it's not blank, as no icon would appear until you had pressed the button in FvwmButtons.

-- Thomas Adam

[1] No, really...

Offline

#14 2009-06-21 19:05:56

Liuuutas
Member
From: Cambridge
Registered: 2009-05-02
Posts: 71

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Thank you very much for such a detail answer, Thomas Adam. smile

About reading the man pages, I read it ocasionally, but succeeded to finish only a small fraction of them. But I must admit, that the documentation of FVWM is really well written... smile

Well my goal now is to embeed pager, stalonetray, conky and some more stuff to make a nice side bar. Off course I will do it with FvwmButtons, but need time to figure it out...:)

By the way, I noticed recently, that the fvwm.lair.be is not working... sad it is a nice place full of great examples... smile

Offline

#15 2009-06-21 19:09:49

ThomasAdam
Member
From: Southampton, England
Registered: 2005-10-26
Posts: 148

Re: [SOLVED] Stalonetray, Keyboard Layout Switching and FVWM (scripting)

Liuuutas wrote:

By the way, I noticed recently, that the fvwm.lair.be is not working... :( it is a nice place full of great examples... :)

Yes, I know.

-- Thomas Adam

Offline

Board footer

Powered by FluxBB