#
# Keyboard source for the CH 'qwertz' layout. This is a fairly generic
# keyboard that should work at any screen resolution. It draws the keyboard
# with vector graphics, using gropnode coordinate mapping to have the server
# scale the keyboard to fit the screen
#
# This keyboard works nicely at 320x240 and 240x320. It is a little tight
# but still fully usable at 160x240. At 160x160 is is quite mushed and probably
# not very fun to use.
#
# Keyboard source is in the form of a perl script that uses functions
# built into kbcompile.pl to generate the keyboard data.
#
# This code is released into the public domain. Feel free to use it in whole
# or in part for your own keyboard layouts.
#
# -- Christian Grigis <christian.grigis@smartdata.ch>
#    highly based on US 'qwerty' keyboard by 
#    Micah Dowty <micahjd@users.sourceforge.net>
#

$option{'side'} = PG_S_BOTTOM;
$option{'size'} = 19;
$option{'sizemode'} = PG_SZMODE_PERCENT;
$option{'path'} = './img/';

####################################### Subroutines

sub initpattern {
    newpattern;
    clear;
    setmapping(0,0,$width = 58,4,PG_MAP_SCALE);
    setcolor(0xFFFFFF);
    rect(0,0,$width,4);
    setcolor(0);
    font("Helvetica", 12, 0);
    frame(0,0,$width,4);
    
    $defaultpat = $defaultmods = 0;
}

sub keyrow {
    ($num,$start,$end) = @_;

    slab(0,$num,$width);
    drawkey(0,$num,$start,$grid[$j++]);
    for ($i=$start;$i<=$end;$i+=4) {
	bar($i,$num,1);
	drawkey($i,$num,4,$grid[$j++]);
    }
    bar($i,$num,1);
    drawkey($i,$num,$width-$end,$grid[$j++]);
}

sub drawgrid {
    $j = 0;
    @grid = @_;
    
    keyrow(0,6,46);
    keyrow(1,7,47);
    keyrow(2,9,45);

    # Spacebar messes up the last row
    slab(0,3,$width);
    drawkey(0,3,8,$grid[$j++]);
    bar(8,3,1);
    drawkey(8,3,4,$grid[$j++]);
    bar(12,3,1);
    drawkey(12,3,5,$grid[$j++]);
    bar(17,3,1);
    drawkey(17,3,20,$grid[$j++]);
    bar(37,3,1);
    drawkey(37,3,6,$grid[$j++]);
    bar(43,3,1);
    drawkey(43,3,5,$grid[$j++]);
    bar(48,3,1);
    drawkey(48,3,5,$grid[$j++]);
    bar(53,3,1);
    drawkey(53,3,5,$grid[$j++]);
}

sub drawkey {
    my ($x,$y,$w,$keycode,$h) = @_;
    
    ($name,$key,$pgkey,$mods,$pat) = split /:/,$keycode;

    $name =~ s/colon/:/;
    $key =~ s/colon/:/;
    $key = chr(substr($key,1)) if (length($key) > 1 && $key=~/^#/);

    $mods = $defaultmods if (!defined $mods);
    $pat = $defaultpat if (!defined $pat);
    $h = 1 if (!defined $h);

    if (defined $name && $name ne "") {
	text($x,$y,$name);
    }

    hotspot($x,$y,$w,$h,0,ord($key),$pgkey,$mods,$pat);
}
    

####################################### Main pattern (1)

initpattern;
drawgrid("tab:\t:PGKEY_TAB",
	 "q:q:PGKEY_q",
	 "w:w:PGKEY_w",
	 "e:e:PGKEY_e",
	 "r:r:PGKEY_r",
	 "t:t:PGKEY_t",
	 "z:z:PGKEY_z",
	 "u:u:PGKEY_u",
	 "i:i:PGKEY_i",
	 "o:o:PGKEY_o",
	 "p:p:PGKEY_p",
#	 "-:-:PGKEY_MINUS",
         "`e:#232:PGKEY_WORLD_72",
	 "del:\b:PGKEY_BACKSPACE",
	 "cap::::3",
	 "a:a:PGKEY_a",
	 "s:s:PGKEY_s",
	 "d:d:PGKEY_d",
	 "f:f:PGKEY_f",
	 "g:g:PGKEY_g",
	 "h:h:PGKEY_h",
	 "j:j:PGKEY_j",
	 "k:k:PGKEY_k",
	 "l:l:PGKEY_l",
#	 ";:;:PGKEY_SEMICOLON",
         "'e:#233:PGKEY_WORLD_73",
#	 "':':PGKEY_QUOTE",
         "`a:#224:PGKEY_WORLD_64",
	 "ret:\r:PGKEY_RETURN",
	 "shf::::2",
	 "y:y:PGKEY_y",
	 "x:x:PGKEY_x",
	 "c:c:PGKEY_c",
	 "v:v:PGKEY_v",
	 "b:b:PGKEY_b",
	 "n:n:PGKEY_n",
	 "m:m:PGKEY_m",
	 ",:,:PGKEY_COMMA",
	 ".:.:PGKEY_PERIOD",
#	 "/:/:PGKEY_SLASH",
	 "-:-:PGKEY_MINUS",
	 "shf::::2",
	 "ctl::::4",
	 "#::::5",
	 "\@::::6",
	 ": :PGKEY_SPACE",
	 "/\\::PGKEY_UP",
	 "\\/::PGKEY_DOWN",
	 "<-::PGKEY_LEFT",
	 "->::PGKEY_RIGHT");

####################################### Shift pattern (2)

initpattern;

# Jump back to the normal pattern after a keypress
$defaultpat = 1;

# Shift modifier, of course
$defaultmods = PGMOD_SHIFT;

drawgrid("tab:\t:PGKEY_TAB",
	 "Q:Q:PGKEY_q",
	 "W:W:PGKEY_w",
	 "E:E:PGKEY_e",
	 "R:R:PGKEY_r",
	 "T:T:PGKEY_t",
	 "Z:Z:PGKEY_z",
	 "U:U:PGKEY_u",
	 "I:I:PGKEY_i",
	 "O:O:PGKEY_o",
	 "P:P:PGKEY_p",
#	 "_:_:PGKEY_UNDERSCORE",
         "\"u:#252:PGKEY_WORLD_92",
	 "del:\b:PGKEY_BACKSPACE",
	 "cap::::3",
	 "A:A:PGKEY_a",
	 "S:S:PGKEY_s",
	 "D:D:PGKEY_d",
	 "F:F:PGKEY_f",
	 "G:G:PGKEY_g",
	 "H:H:PGKEY_h",
	 "J:J:PGKEY_j",
	 "K:K:PGKEY_k",
	 "L:L:PGKEY_l",
#	 "colon:colon:PGKEY_COLON",
         "\"o:#246:PGKEY_WORLD_86",
#	 "\":\":PGKEY_QUOTEDBL",
         "\"a:#228:PGKEY_WORLD_68",
	 "ret:\r:PGKEY_RETURN",
	 "shf",
	 "Y:Y:PGKEY_y",
	 "X:X:PGKEY_x",
	 "C:C:PGKEY_c",
	 "V:V:PGKEY_v",
	 "B:B:PGKEY_b",
	 "N:N:PGKEY_n",
	 "M:M:PGKEY_m",
#	 "<:<:PGKEY_LESS",
	 "colon:colon:PGKEY_COLON",
#	 ">:>:PGKEY_GREATER",
	 ";:;:PGKEY_SEMICOLON",
#	 "?:?:PGKEY_QUESTION",
	 "_:_:PGKEY_UNDERSCORE",
	 "shf",
	 "ctl::::4",
	 "#::::5",
	 "\@::::6",
	 ": :PGKEY_SPACE",
	 "/\\::PGKEY_UP",
	 "\\/::PGKEY_DOWN",
	 "<-::PGKEY_LEFT",
	 "->::PGKEY_RIGHT");

# Show the shift keys as inverted
setlgop(PG_LGOP_XOR);
setcolor(0xFFFFFF);
rect(0,2,9,1);
rect($width-9,2,9,1);

####################################### Capslock pattern (3)

initpattern;

# Shift modifier, of course
$defaultmods = PGMOD_SHIFT;

drawgrid("tab:\t:PGKEY_TAB",
	 "Q:Q:PGKEY_q",
	 "W:W:PGKEY_w",
	 "E:E:PGKEY_e",
	 "R:R:PGKEY_r",
	 "T:T:PGKEY_t",
	 "Z:Z:PGKEY_z",
	 "U:U:PGKEY_u",
	 "I:I:PGKEY_i",
	 "O:O:PGKEY_o",
	 "P:P:PGKEY_p",
#	 "-:-:PGKEY_MINUS",
         "`e:#232:PGKEY_WORLD_72",
	 "del:\b:PGKEY_BACKSPACE",
	 "cap::::1",
	 "A:A:PGKEY_a",
	 "S:S:PGKEY_s",
	 "D:D:PGKEY_d",
	 "F:F:PGKEY_f",
	 "G:G:PGKEY_g",
	 "H:H:PGKEY_h",
	 "J:J:PGKEY_j",
	 "K:K:PGKEY_k",
	 "L:L:PGKEY_l",
#	 ";:;:PGKEY_SEMICOLON",
         "'e:#233:PGKEY_WORLD_73",
#	 "':':PGKEY_QUOTE",
         "`a:#224:PGKEY_WORLD_64",
	 "ret:\r:PGKEY_RETURN",
	 "shf::::1",
	 "Y:Y:PGKEY_y",
	 "X:X:PGKEY_x",
	 "C:C:PGKEY_c",
	 "V:V:PGKEY_v",
	 "B:B:PGKEY_b",
	 "N:N:PGKEY_n",
	 "M:M:PGKEY_m",
	 ",:,:PGKEY_COMMA",
	 ".:.:PGKEY_PERIOD",
#	 "/:/:PGKEY_SLASH",
	 "-:-:PGKEY_MINUS",
	 "shf::::1",
	 "ctl::::4",
	 "#::::5",
	 "\@::::6",
	 ": :PGKEY_SPACE",
	 "/\\::PGKEY_UP",
	 "\\/::PGKEY_DOWN",
	 "<-::PGKEY_LEFT",
	 "->::PGKEY_RIGHT");

# Show the caps lock as inverted
setlgop(PG_LGOP_XOR);
setcolor(0xFFFFFF);
rect(0,1,7,1);

####################################### Control pattern (4)

initpattern;
$defaultpat = 1;
$defaultmods = PGMOD_CTRL;

drawgrid("tab:\t:PGKEY_TAB",
	 "^Q:#17:PGKEY_q",
	 "^W:#23:PGKEY_w",
	 "^E:#5:PGKEY_e",
	 "^R:#18:PGKEY_r",
	 "^T:#20:PGKEY_t",
	 "^Z:#26:PGKEY_z",
	 "^U:#21:PGKEY_u",
	 "^I:#9:PGKEY_i",
	 "^O:#15:PGKEY_o",
	 "^P:#16:PGKEY_p",
#	 "-:-:PGKEY_MINUS",
         "`e:#232:PGKEY_WORLD_72",
	 "del:\b:PGKEY_BACKSPACE",
	 "cap::::3",
	 "^A:#1:PGKEY_a",
	 "^S:#19:PGKEY_s",
	 "^D:#4:PGKEY_d",
	 "^F:#6:PGKEY_f",
	 "^G:#7:PGKEY_g",
	 "^H:#8:PGKEY_h",
	 "^J:#10:PGKEY_j",
	 "^K:#11:PGKEY_k",
	 "^L:#12:PGKEY_l",
#	 ";:;:PGKEY_SEMICOLON",
         "'e:#233:PGKEY_WORLD_73",
#	 "':':PGKEY_QUOTE",
         "`a:#224:PGKEY_WORLD_64",
	 "ret:\r:PGKEY_RETURN",
	 "shf::::2",
	 "^Y:#25:PGKEY_y",
	 "^X:#24:PGKEY_x",
	 "^C:#3:PGKEY_c",
	 "^V:#22:PGKEY_v",
	 "^B:#2:PGKEY_b",
	 "^N:#14:PGKEY_n",
	 "^M:#13:PGKEY_m",
	 ",:,:PGKEY_COMMA",
	 ".:.:PGKEY_PERIOD",
#	 "/:/:PGKEY_SLASH",
	 "-:-:PGKEY_MINUS",
	 "shf::::2",
	 "ctl",
	 "#::::5",
	 "\@::::6",
	 ": :PGKEY_SPACE",
	 "/\\::PGKEY_UP",
	 "\\/::PGKEY_DOWN",
	 "<-::PGKEY_LEFT",
	 "->::PGKEY_RIGHT");

# Show the ctrl as inverted
setlgop(PG_LGOP_XOR);
setcolor(0xFFFFFF);
rect(0,3,8,1);

####################################### Numbers pattern (5)

initpattern;

# Control keys
bar(6,0,4);
slab(0,1,6);
slab(0,2,6);
slab(0,3,6);
drawkey(0,0,6,"abc::::1");
drawkey(0,1,6,"tab:\t:PGKEY_TAB");
drawkey(0,2,6,"del:\b:PGKEY_BACKSPACE");
drawkey(0,3,6,"ret:\r:PGKEY_KP_ENTER");

# Number grid
bar(8,0,4);
bar(13,0,3);
bar(18,0,4);
bar(23,0,4);
slab(8,1,15);
slab(8,2,15);
slab(8,3,15);
drawkey(8,0,5,"7:7:PGKEY_KP7");
drawkey(13,0,5,"8:8:PGKEY_KP8");
drawkey(18,0,5,"9:9:PGKEY_KP9");
drawkey(8,1,5,"4:4:PGKEY_KP4");
drawkey(13,1,5,"5:5:PGKEY_KP5");
drawkey(18,1,5,"6:6:PGKEY_KP6");
drawkey(8,2,5,"1:1:PGKEY_KP1");
drawkey(13,2,5,"2:2:PGKEY_KP2");
drawkey(18,2,5,"3:3:PGKEY_KP3");
drawkey(8,3,10,"0:0:PGKEY_KP0");
drawkey(18,3,5,".:.:PGKEY_KP_PERIOD");

# Arithmetic keys
bar(25,0,4);
bar(29,0,4);
bar(33,0,4);
slab(29,1,4);
slab(25,2,8);
slab(25,3,8);
drawkey(25,0,4,"+:+:PGKEY_KP_PLUS",2);
drawkey(25,2,4,"-:-:PGKEY_KP_MINUS");
drawkey(25,3,4,"=:=:PGKEY_KP_EQUALS");
drawkey(29,0,4,"*:*:PGKEY_KP_MULTIPLY");
drawkey(29,1,4,"/:/:PGKEY_KP_DIVIDE");
drawkey(29,2,4,"^:^:PGKEY_6:PGMOD_SHIFT");
drawkey(29,3,4,"%:%:PGKEY_5:PGMOD_SHIFT");

# Hex keys
bar(35,0,4);
bar(38,0,4);
bar(41,0,4);
slab(35,1,6);
slab(35,2,6);
slab(35,3,6);
drawkey(35,0,3,"A:A:PGKEY_a:PGMOD_SHIFT");
drawkey(35,1,3,"B:B:PGKEY_b:PGMOD_SHIFT");
drawkey(35,2,3,"C:C:PGKEY_c:PGMOD_SHIFT");
drawkey(35,3,3,"D:D:PGKEY_d:PGMOD_SHIFT");
drawkey(38,0,3,"E:E:PGKEY_e:PGMOD_SHIFT");
drawkey(38,1,3,"F:F:PGKEY_f:PGMOD_SHIFT");
drawkey(38,2,3,"x:x:PGKEY_x");
drawkey(38,3,3,"b:b:PGKEY_b");

# Navigation grid
bar(43,0,4);
bar(48,0,3);
bar(53,0,4);
slab(43,1,15);
slab(43,2,15);
slab(43,3,15);
drawkey(43,0,5,"hom::PGKEY_HOME");
drawkey(48,0,5,"/\\::PGKEY_UP");
drawkey(53,0,5,"pgu::PGKEY_PAGEUP");
drawkey(43,1,5,"<-::PGKEY_LEFT");
drawkey(48,1,5,"ret:\r:PGKEY_KP_ENTER");
drawkey(53,1,5,"->::PGKEY_RIGHT");
drawkey(43,2,5,"end::PGKEY_END");
drawkey(48,2,5,"\\/::PGKEY_DOWN");
drawkey(53,2,5,"pgd::PGKEY_PAGEDOWN");
drawkey(43,3,10,"ins::PGKEY_INSERT");
drawkey(53,3,5,"del::PGKEY_DELETE");

####################################### Symbols pattern (6)

initpattern;
$defaultpat = 1;
drawgrid("esc:\e:PGKEY_ESCAPE",
	 "1:1:PGKEY_1",
	 "2:2:PGKEY_2",
	 "3:3:PGKEY_3",
	 "4:4:PGKEY_4",
	 "5:5:PGKEY_5",
	 "6:6:PGKEY_6",
	 "7:7:PGKEY_7",
	 "8:8:PGKEY_8",
	 "9:9:PGKEY_9",
	 "0:0:PGKEY_0",
	 "|:|:124",
	 "\\:\\:PGKEY_BACKSLASH",
	 "~:~:126",
#	 "!:!:PGKEY_1:PGMOD_SHIFT",
	 "+:+:PGKEY_1:PGMOD_SHIFT",
#	 "\@:\@:PGKEY_2:PGMOD_SHIFT",
	 "\":\":PGKEY_2:PGMOD_SHIFT",
#	 "#:#:PGKEY_3:PGMOD_SHIFT",
         "*:*:PGKEY_3:PGMOD_SHIFT",
#	 "\$:\$:PGKEY_4:PGMOD_SHIFT",
	 ",c:#231:PGKEY_4:PGMOD_SHIFT",
	 "%:%:PGKEY_5:PGMOD_SHIFT",
#	 "^:^:PGKEY_6:PGMOD_SHIFT",
	 "&:&:PGKEY_6:PGMOD_SHIFT",
#	 "&:&:PGKEY_7:PGMOD_SHIFT",
	 "/:/:PGKEY_7:PGMOD_SHIFT",
#	 "*:*:PGKEY_8:PGMOD_SHIFT",
	 "(:(:PGKEY_8:PGMOD_SHIFT",
#	 "(:(:PGKEY_9:PGMOD_SHIFT",
	 "):):PGKEY_9:PGMOD_SHIFT",
#	 "):):PGKEY_0:PGMOD_SHIFT",
	 "=:=:PGKEY_0:PGMOD_SHIFT",
	 "`:`:PGKEY_BACKQUOTE",
	 "ret:\r:PGKEY_RETURN",
	 "shf::::2",
	 "{:{:123",
	 "}:}:125",
	 "[:[:PGKEY_LEFTBRACKET",
	 "]:]:PGKEY_RIGHTBRACKET",
#	 "+:+:PGKEY_PLUS",
	 "\@:\@:PGKEY_AT",
#	 "=:=:PGKEY_EQUALS",
	 "#:#:PGKEY_HASH",
	 "?:?:PGKEY_QUESTION",
#	 ",:,:PGKEY_COMMA",
	 "':':PGKEY_QUOTE",
#	 ".:.:PGKEY_PERIOD",
	 "^:^:PGKEY_CARET",
#	 "/:/:PGKEY_SLASH",
	 "!:!:PGKEY_EXCLAIM",
	 "shf::::2",
	 "ctl::::4",
	 "#::::5",
	 "\@",
	 ": :PGKEY_SPACE",
	 "/\\::PGKEY_UP",
	 "\\/::PGKEY_DOWN",
	 "<-::PGKEY_LEFT",
	 "->::PGKEY_RIGHT");

# Show the symbol button as inverted
setlgop(PG_LGOP_XOR);
setcolor(0xFFFFFF);
rect(12,3,5,1);

### The End ###




