Automatic placing of onscreen keyboard in linux

By Christopher, March 10, 2011

This guide is writte for my Acer 1825 but it should work on all linux devices which need a onscreen keyboard like onboard.


I got the idea of building this script from Tom/drnessie from the ubuntuforums.org (http://ubuntuforums.org/showthread.php?t=1486671&page=17), because he tried to make a improvement of my onscreen keyboard show/hide script from this post.

http://www.ceh-photo.de/blog/?p=200

He wants to place the onscreen keyboard on the bottom of the screen and shrink accordingly the active window .

He uses wmctrl but I used wmiface like in this post http://www.ceh-photo.de/blog/?p=265 (please check that post to get information about installing/downloading wmiface), because I am already comfortable with it. Maybe you could reach the same effects with wmctrl….

First two screenshots which shows you what my script does:

First screenshot show my desktop before pressing the P-Button, second screenshot shows my desktop after pressing P-Button. After another press of the P-Button I will have again screenshot one conditions. This also works for portrait-mode.

 

 

 

 

 

 

 

You could replace the old P-Button script from this post(http://www.ceh-photo.de/blog/?p=200) with my new script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#author: Christopher-Eyk Hrabia - http://www.ceh-photo.de - c.hrabia@gmail.com
#PURPOSE:
#This script places an arbitrary onscreen keyboard application at the bottom of the desktop and put the current active window above the keyboard in pseudo maximization
#if script is run again, onscreen keyboard will be killed and old window configuration will be restored


#CONFIGURATION
toppanelheight=36 #right click preferences to get height of panel
bottompanelheight=36
DEBUG="" # write DEBUG="1" for debug output
TEMPFILE=/tmp/OnScreenKeyboard.tmp
ONSCREENKEYBOARDAPP=onboard
ONSCREENKEYBOARDHEIGHTSHRINKOFFSET=50

#####################################################

#redirect stdin, stdout and stderr
[ ! "${DEBUG}" ] && exec>/dev/null 2>&1 </dev/null


running=$(pgrep $ONSCREENKEYBOARDAPP | wc -l)
if [ $running -gt 0 ] ;then #kill keyboard reset old status
     pkill $ONSCREENKEYBOARDAPP
     
     #read old configuration
     filecontent=$(cat $TEMPFILE)
     
     #check if we have old configuration
     if [ -n "$filecontent" ];then
     
     set `echo $filecontent`
     
     maximizedCur=$1
     sizeXcur=$2
     sizeYcur=$3
     xCur=$4
     yCur=$5
     winCur=$6
     
     #reset postion and size
     wmiface setFrameGeometry $winCur $xCur $yCur $sizeXcur $sizeYcur
     
     #if window was maximized bring it to former size
     case $maximizedCur in
     0)
     wmiface maximize $winCur 0 0;;
     1)
     wmiface maximize $winCur 1 0;;
     2)
     wmiface maximize $winCur 0 1;;
     3)
     wmiface maximize $winCur 1 1;;
     esac
     fi
     
     #remove old configuration
     rm $TEMPFILE
     
else # show keyboard

####################################################
#get resolution of desktop
set `xrandr -q|sed -n 's/.*current[ ]\([0-9]*\) x \([0-9]*\),.*/\1 \2/p'`
yreso=$2
echo Yreso $yreso

###################################################
#get information about active window
#get pointer of active window
winCur=$(wmiface activeWindow)
echo $winCur

#get maximized status
#0 for not maximized,
#1 for maximized horizontally,
#2 for maximized vertically or
#3 for fully maximized.
maximizedCur=$(wmiface windowMaximized $winCur)

wmiface maximize $winCur 1 0

set `wmiface frameSize $winCur | tr 'x' ' '`

sizeXcur=$1
sizeYcur=$2
echo SIZECUR $sizeXcur $sizeYcur


set `wmiface framePosition $winCur | tr '+' ' '`

xCur=$1
yCur=$2
echo PosCur $xCur $yCur

#store setting of current window in tempfile
echo $maximizedCur $sizeXcur $sizeYcur $xCur $yCur $winCur >$TEMPFILE

yCur=0

###########################
#handle onscreen keyboard
eval $ONSCREENKEYBOARDAPP &
#wait for process start and  get windowid
window=$(wmiface findNormalWindows "" $ONSCREENKEYBOARDAPP "" "" 0 false)
while [[ $window -eq "" ]]
do
window=$(wmiface findNormalWindows "" $ONSCREENKEYBOARDAPP "" "" 0 false)
done


echo WindowID $window

wmiface maximize $window 1 0

set `wmiface frameSize $window | tr 'x' ' '`

sizeX=$1
sizeY=$2
sizeY=$((sizeY-ONSCREENKEYBOARDHEIGHTSHRINKOFFSET))

echo SIZE $sizeX $sizeY

set `wmiface framePosition $window | tr '+' ' '`

x=$1
y=$2

echo Pos $x $y

y=$(( yreso-sizeY ))

#####################################
#place windows

#KEYBOARD
wmiface setFrameGeometry $window $x $y $sizeX $sizeY

#set current window to wanted position
sizeYcur=$(( yreso-sizeY-toppanelheight - bottompanelheight ))

wmiface setFrameGeometry $winCur $xCur $yCur $sizeXcur $sizeYcur

fi

To get a well looking result you need to change the configuration at the top of the script. It is important that you set the correct height of your bottom and top panel of you desktop. You could get this information by right click on panel and choosing properties. more over you could define how many pixels are subtracted from the start height of your onscreen keyboard application (ONSCREENKEYBOARDHEIGHTSHRINKOFFSET). Moreover you could choose another onscreen keyboard application by replacing onboard in ONSCREENKEYBOARDAPP.

This script stores the current appearance settings of the current visible application and after the closing of the onscreen keyboard it recovers the old settings.

In general this script should work on all screens ,  linux desktops and distributions  which are supported by wmiface (At least GNOME, KDE).

I hope somebody like that script! Give it a try!

7 Comments

  1. Arobase40 says:

    Hi, Toffer,

    It’s nice that you have the feeling to discover “new features” by yourself with Tom and drnessie, but ain’t you reinventing the wheel ?

    I followed your different adventures, trials about this function, but sounds like this was already documented by Irohr on october 2nd 2010, even if it was binded to a specifique key…

    http://ubuntuforums.org/showthread.php?t=1486671&page=2

    😉 😀

  2. arobase40 says:

    Ohh I meant : “even if it was NOT binded to a specific key…”

    • Christopher says:

      I replyed in ubuntuforums.org, because I was a bit confused. But in general my script does more than your mentioned script. It is complete dynamic, works for all resolutions,monitors,keyboard-apps… moreover it resizes your current application and also reverts it if you have finished typing. try it..

  3. sadcruel says:

    Have you try Florence? (http://florence.sourceforge.net/)

    Easy to install for GNOME (I use it in Ubuntu 10.10) and has a nicer keyboard. When you touch over a textfield or textarea in any program, a small box appears inviting you to display the keyboard.

    • Christopher says:

      hey sadcruel,
      no I do not know florence. I will try it, sounds nice.

      • Christopher says:

        hey sadcruel,
        I tried Florence, but I have some difficulties:
        How did you use Florence as applet or standalone app?
        In applet mode I think its a bit strange to have such a huge panel?I do not understand, whats the advantage of this?
        If I run florence as standalone app I does not autohide although this feature is activated.
        Could you tell me more about your usage and configuration of florence?

        • sadcruel says:

          I’ve installed Florence without options (that also means no stand alone applet). Then you can chooose to start it manually, at startup, or when you rotate the screen, etc. It’s only invoking the command in the moment / script you want. It will always add the applet in the gnome bar.

          The result is that when a textarea or textfield has the focus, then the square icon (the keys) will apear next to it. If there are no textarea neither textfield (desktop, for example), the icon don’t appear.

          And if you touch the icon the keyboard appear, and when you push outside it dissapear.

          In any case, I will install soon the 11.04, with Unity, and I will try configurations again (I will tell you). I really think that Florence is much more nicer, and about the ugly big icon, I think it colud be easy to change looking the code a bit.

          ——

          My Florence config (! means not marqued):

          * Windows: !Decorated, Transparent(70%), Resizable, !Task bar, Always on top

          * Behaviour: Auto hide, !move to near selected widget, intermediate icon.

          Note that if you want keyboard to be transparent you need to use the compiz (the Ubuntu default is ok)

What do you think?

You must be logged in to post a comment.