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!