summaryrefslogtreecommitdiff
path: root/plum-tastatur/enable-plum
blob: 5ca348bcbb01baae369a5ea546087feb092566ae (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/perl -w

# Enable PLUM to work as a standard pc keyboard
# Written 2008 by Hans-Christoph Wirth <hcw@at@gmx@dot@de>
# $Revision$
# $Date$
#
# This command modifies any current X keymap (which is assumed to be
# designed for use with an ordinary 105 key PC keyboard) so that it
# can be used (almost) identically on a connected PLUM keyboard (see
# www.plum.bz for information on that matrix-like keyboard).
#
# Usage: 
#
# 1. Setup your keyboard layout for your standard keyboard using xmodmap.
# 2. Read the warning below and prepare a recovery mechanism.
# 3. Run this script without any parameters.
#
#    Run with option "-n" to print the commands without executing them.
#
# Warning:
#
# There is no reliable way (that I am aware of) to determine the type
# of the currently active keyboard.  Hence we cannot prevent that you
# call this script twice, which will instantaneously switch keyboard
# input into a completely useless state.  To recover from that, you
# should prepare your desktop to run a recovery command (like 'xmodmap
# $HOME/your-standard.modmap') on a mouse click.
#
######################################################################

$XMODMAP = "/usr/bin/xmodmap";

#
# Options
#
$opt = shift || "";
$noexec = $opt eq "-n" ? 1 : 0;
$P = $noexec ? "! " : "";

#
# Read transformation matrix
#
while (<DATA>) {
    ($plum, $pc) = split;
    $plum[$pc] = 0+ $plum;
}

#
# Read and parse existing map
#
print "${P}reading existing keymap\n";

open (IN, "$XMODMAP -pke |") or die "read keyboard mapping failed\n";
while (<IN>) {
    /^keycode\s+(\d+)\s+=\s+(.*)$/o or die "error: malformed line: $_\n";

    if ($plum[$1]) {
	push @clearkeys, "keycode $plum[$1] =\n";
	push @setkeys, "keycode $plum[$1] = $2\n";

	push @report_keys, (split( ' ', $2, 2 ))[0];
    }
}
close (IN);

#
# Read and parse existing modifiers
#
print "${P}reading existing modifiers\n";

open (IN, "$XMODMAP -pm |") or die "read modifier list failed\n";
while (<IN>) {
    unless (/^(shift|lock|control|mod\d)\s*(.*)$/) {
	next;
    }

    ($mod, $info) = ($1, $2);

    @infos = ();
    for (split( /,/, $info )) {
	s/\(\S*\)//;
	next if /^\s*$/;
	push @infos, $_;
    }

    push @clearmodifiers, "clear $mod\n";
    push @report_clearmodifiers, "$mod ";

    if (@infos) {
	push @setmodifiers, "add $mod = @infos\n";
	push @report_setmodifiers, "$mod ";
    }
}
close (IN);

#
# Now perform the changes using two external calls.
#

print "${P}clearing " . @report_keys . " keys... @report_keys\n";
print "${P}clearing " . @report_clearmodifiers . 
    " modifiers... @report_clearmodifiers\n";

if ($noexec) {
    open (OUT, "| cat") or die "clear map failed\n";
} else {
    open (OUT, "| $XMODMAP -") or die "clear map failed\n";
}

print OUT @clearkeys;
print OUT @clearmodifiers;

close (OUT) or die "clear map failed\n";

print "${P}setting all keys and modifiers @report_setmodifiers\n";

if ($noexec) {
    open (OUT, "| cat") or die "set new map failed\n";
} else {
    open (OUT, "| $XMODMAP -") or die "set new map failed\n";
}

print OUT @setkeys;
print OUT @setmodifiers;

close (OUT) or die "set new map failed\n";

# The data section lists the plum keyboard scancodes ordered from left
# to right and top to bottom.  Each line describes one key position in
# the form 'plum code' 'pc code'.  Since the keyboard is short of a
# few keys we have to move some keys in the periphery: this affects in
# particular
#
# - the key to the left of '1' moves down next to right shift
# - the key to the right of left shift moves down; there is no longer 
#   a left windows key
# - return key moves down to space key, obviously
#
# As an example, the standard German 105 key layout is mapped as
# follows:
#
#
# regular pc layout
#
#     esc     f1  f2  f3  f4    f5  f6  f7  f8    f9  f10 f11 f12
#      ^   1   2   3   4   5   6   7   8   9   0   ß   '   -bsp-
#      tab   q   w   e   r   t   z   u   i   o   p   ü   +   ret
#      lock   a   s   d   f   g   h   j   k   l   ö   ä   #
#     shf   <   y   x   c   v   b   n   m   ,   .   -   ---shf---
#     ctr   win   alt  ---------spc---------  agr   win  men  ctr
#
#
# plum mapping
#
#     esc f1  f2  f3  f4  f5  f6  f7  f8  f9  f10 f11 f12
#      1   2   3   4   5   6   7   8   9   0   ß   '  bsp
#     tab  q   w   e   r   t   z   u   i   o   p   ü   +
#     lck  a   s   d   f   g   h   j   k   l   ö   ä   #
#     shf  y   x   c   v   b   n   m   ,   .   -  shf  ^
#     ctr  <  alt  ---ret---   ---spc---  agr win ctr

__DATA__
9 9
67 67
68 68
69 69
70 70
71 71
72 72
73 73
74 74
75 75
76 76
95 95
96 96
49 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
47 23
33 24
46 25
30 26
58 27
23 28
22 29
54 30
41 31
42 32
24 33
48 34
51 35
36 36
50 66
27 38
26 39
38 40
40 41
32 42
57 43
28 44
43 45
31 46
39 47
62 48
61 51
66 50
45 52
44 53
55 54
56 55
59 56
60 57
25 58
53 59
29 60
52 61
34 62
35 49
37 37
115 94
64 64
65 65
113 113
116 116
109 109