Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
rudojaksa committed Jan 7, 2024
0 parents commit 90549f6
Show file tree
Hide file tree
Showing 16 changed files with 717 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
PACKAGE := dvorak-hhkb
VERSION := 0.1
AUTHORS := R.Jaksa 2023 GPLv3

XKB0 := $(shell find xkb -type f -o -type l | grep -v -F .bkp)
XKB := $(XKB0:%=/usr/share/X11/%)

CFG0 := $(shell find xorg.conf.d -type f | grep -v -F .bkp)
CFG := $(CFG0:%=/usr/share/X11/%)

ETC0 := $(shell find etc -type f | grep -v -F .bkp)
ETC := $(ETC0:%=/%)

all: doc/hhkbp2kp.png

# requires manual install first
doc/hhkbp2kp.png: xkb/geometry/hhkbp2kp Makefile
setxkbmap -print -rules dvorak-hhkb -geometry hhkbp2kp | xkbcomp -w 4 -xkm - - | xkbprint -ll 1 -fit -color - $@.ps
gs -r220 -q -sDEVICE=pnggray -dNOPAUSE -dBATCH -dDEVICEWIDTHPOINTS=1600 -dDEVICEHEIGHTPOINTS=600 -sOutputFile=$@.png $@.ps
convert $@.png -resize 2400 $@.2.png
pngquant -f --strip -Q 50 -o $@.3.png $@.2.png
zopflipng -y -m --lossy_8bit $@.3.png $@ 2>&1 >/dev/null
rm -f $@.*.png
rm -f $@.png $@.ps

info:
@echo $(XKB) $(CFG) $(ETC) | xargs -n 1

install: install-xkb $(CFG) $(ETC)
@echo ---------------------
@l -b -nh $(XKB0) $(CFG0) $(ETC0)
@echo ---------------------
@l -b -nh -a $(XKB) $(CFG) $(ETC)

install-xkb: $(XKB)

$(XKB) $(CFG): /usr/share/X11/%: %
install -D -m 644 $* $@

$(ETC): /%: %
install -D -m 644 $* $@

include ~/.github/Makefile.git
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Xkb setup for Dvorak HHKB + KP

[X keyboard extension](https://en.wikipedia.org/wiki/X_keyboard_extension "Xkb") /
[Happy Hacking KeyBoard](https://en.wikipedia.org/wiki/Happy_Hacking_Keyboard "HHKB") /
[Dvorak keyboard layout](https://en.wikipedia.org/wiki/Dvorak_keyboard_layout "Dvorak") /
[numeric KeyPad](https://en.wikipedia.org/wiki/Numeric_keypad "KP")

<p>
<a href=doc/hhkbp2kp.png>
<img src=doc/hhkbp2kp.png>
</a>
</p>

Similar to: `setxkbmap -rules evdev -layout dvorak -option altwin:meta_win -model hhk`

* with a custom Alt/Meta setup
* with a custom Central-Europe ISO-Level3 extensions (or optionaly without)
* minimal setup, without any code for other keyboards or layouts

This setup is for 001001 DIP switch setup (HHKB Professional 2) - default with just the backspace activated.

Contains:

* Xkb setup `/usr/share/X11/xkb/{keycodes,symbols,geometry,rules,...}/{hhkbkp,hhkbp2kp,...}`
* Xorg config `/usr/share/X11/xorg.conf.d/90-xkbrj.conf`
* corresponding console keyboard config `/etc/default/keyboard`

### Reasoning

* Xkb intsead of xmodmap: xmodmap is limited to the current running session, so it requires re-run after every keyboard reconnection, like after every [KVM switch](https://en.wikipedia.org/wiki/KVM_switch) event.
* Dvorak instead of qwerty: another layout is like a foreign language for fingers.
* HHKB <!--(Apple M0110)--> instead of big keyboard, with arrow keys under the hand.

### Installation

Xkb keyboard setup requires access to system-wide places `/usr/share/X11` and
`/etc/default/keyboard`, thus the real user-only configuration (homedir based)
is not possible.

1. Run the `sudo make install` to copy supplied configuration files to required directories:
`/usr/share/X11/xkb`
`/usr/share/X11/xorg.conf.d`
`/etc/default/keyboard`
2. Manually add `setxkbmap -rules hhkb-dvorak` to your `.xinitrc` or session startup script, if needed.
3. Call `setxkbmap -rules dvorak-hhkb` or reboot the computer to activate the setup.

### Hacking

Changes to the configuration can make your keyboard not working, you will need
a remote acces to fix it back!
Some debug commands:

```
xkbcomp $DISPLAY -
setxkbmap -print -verbose 10
cat /usr/share/X11/xkb/keycodes/evdev | grep = # keycodes numbers
xev -event keyboard
```

```
setxkbmap -print | xkbcomp -w 4 -xkm - - | xkbprint -ll 1 -fit -color - /tmp/kbd.ps; gv -swap -scale=2 /tmp/kbd.ps &
setxkbmap -print -rules dvorak-hhkb | xkbcomp -xkm - - | xkbprint -color - /tmp/kbd.ps; gv -swap -scale=3 /tmp/kbd.ps &
```

### Links

Documentation:
&nbsp;&nbsp; https://www.x.org/releases/X11R7.7/doc/kbproto/xkbproto.html
&nbsp;&nbsp; https://github.com/xkbcommon/libxkbcommon/blob/master/doc/keymap-format-text-v1.md
&nbsp;&nbsp; https://wiki.archlinux.org/title/X_keyboard_extension
&nbsp;&nbsp; https://github.com/barsv/ivan-pascal-xkb
&nbsp;&nbsp; https://hhkb.io/layout
Code:
&nbsp;&nbsp; https://github.com/xkbcommon/libxkbcommon
&nbsp;&nbsp; https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config
&nbsp;&nbsp; https://gitlab.freedesktop.org/xorg/app/xkbcomp
&nbsp;&nbsp; https://gitlab.freedesktop.org/xorg/app/xkbprint
&nbsp;&nbsp; https://gitlab.freedesktop.org/xorg/app/xkbutils

<br><div align=right><i>R.Jaksa 2023</i></div>
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* rewrite xkbprint to produce svg
- add all-levels output
- also write txt visualization to terminal
* include geometry for Fn keys
Binary file added doc/hhkbp2kp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions etc/default/keyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# man keyboard(5)
XKBMODEL="hhkbkp"
XKBLAYOUT="dvorak"
30 changes: 30 additions & 0 deletions xkb/compat/minimal
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// happy hacking + kp -*-c-*-

xkb_compatibility "minimal" {

virtual_modifiers NumLock,LevelThree;


interpret ISO_Level3_Shift {
action= SetMods(modifiers=LevelThree);
};

interpret ISO_Level3_Shift+Any {
useModMapMods= level1;
virtualModifier= LevelThree;
action= SetMods(modifiers=LevelThree);
};


interpret Num_Lock+Any {
virtualModifier = NumLock;
action = LockMods(modifiers=NumLock); };

interpret Any+Any {
action = SetMods(modifiers=modMapMods); };

indicator "Num Lock" {
whichModState = locked;
modifiers = NumLock; };};

// R.Jaksa 2023
73 changes: 73 additions & 0 deletions xkb/geometry/hhkbp2kp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Happy Hacking + KP -*-c-*-

default xkb_geometry "hhkbp2kp" {

description = "HHKB Professional 2 + KP";
width = 417;
height = 110;
section.left = 1;
row.left = 3;
key.gap = 1;
key.shape = "NORM";
color = "gray6";
key.color = "grey2";
text.color = "grey40";
shape.cornerRadius = 1;

// keys: outer_rectangle,shift,inner_rectangle
shape "NORM" {{[18,18]},{[2,1],[15,15]}};
shape "BKSP" {{[27,18]},{[2,1],[24,15]}};
shape "TAB" {{[28,18]},{[2,1],[25,15]}};
shape "CTRL" {{[32,18]},{[2,1],[29,15]}};
shape "RTRN" {{[42,18]},{[2,1],[39,15]}};
shape "SPCE" {{[114,18]},{[2,1],[111,15]}};
shape "KPAD" {{[18,37]},{[2,1],[15,34]}};
shape "KP0" {{[37,18]},{[2,1],[34,15]}};

// outlines
shape "KB" { cornerRadius=2, {[294,110]}};
shape "KP" { cornerRadius=2, {[85,110]}};
solid "edges" { top=0; left=0; shape="KB"; color="grey6"; };
solid "edges2" { top=-4; left=326; angle=1; shape="KP"; color="grey6"; };

text "label" { left=253; top=91; fontSize=15; text=" HHKB\nProfessional 2"; };

section "HHKB" { top=10;
row { top=1; keys {
{ <ESC>,color="grey12" },
<AE01>,<AE02>,<AE03>,<AE04>,<AE05>,<AE06>,<AE07>,<AE08>,<AE09>,<AE10>,<AE11>,<AE12>,
<BKSL>,<TLDE> };};
row { top=20; keys {
{ <TAB>,"TAB",color="grey12" },
<AD01>,<AD02>,<AD03>,<AD04>,<AD05>,<AD06>,<AD07>,<AD08>,<AD09>,<AD10>,<AD11>,<AD12>,
{ <BKSP>,"BKSP",color="grey12" }};};
row { top=39; keys {
{ <LCTL>,"CTRL",color="grey12" },
<AC01>,<AC02>,<AC03>,<AC04>,<AC05>,<AC06>,<AC07>,<AC08>,<AC09>,<AC10>,<AC11>,
{ <RTRN>,"RTRN",color="grey12" }};};
row { top=58; keys {
{ <LFSH>,"RTRN",color="grey12" },
<AB01>,<AB02>,<AB03>,<AB04>,<AB05>,<AB06>,<AB07>,<AB08>,<AB09>,<AB10>,
{ <RTSH>,"CTRL",color="grey12" },
{ <FN>,color="grey12" }};};
row { top=77; left=30; keys {
{ <LALT>,color="grey12" },
{ <MUHE>,"TAB",color="grey12" },
{ <SPCE>,"SPCE" },
{ <HENK>,"TAB",color="grey12" },
{ <RALT>,color="grey12" }};};};

section "KP" { top=6; left=325; angle=10;
row { top=1; keys { <NMLK>, <KPDV>, <KPMU>, <KPSU> };};
row { top=20; keys { <KP7>, <KP8>, <KP9>, { <KPAD>,"KPAD" }};};
row { top=39; keys { <KP4>, <KP5>, <KP6> };};
row { top=58; keys { <KP1>, <KP2>, <KP3>, { <KPEN>,"KPAD" }};};
row { top=77; keys {{ <KP0>, "KP0" }, <KPDL> };};};

shape "LED" { cornerRadius=1, {[2,2]}};
indicator.shape = "LED";
indicator.offColor = "grey2";
indicator.onColor = "green60";
indicator "Num Lock" { top=3; left=337; };};

// R.Jaksa 2023
1 change: 1 addition & 0 deletions xkb/keycodes/hhkbkp
129 changes: 129 additions & 0 deletions xkb/keycodes/hhkbp2kp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// happy hacking professional 2 + kp -*-c-*-

default xkb_keycodes "hhkbp2kp" {

minimum = 8; maximum = 255;

<ESC> = 9; // Esc
<AE01> = 10; // 1!
<AE02> = 11; // 2@
<AE03> = 12; // 3#
<AE04> = 13; // 4$
<AE05> = 14; // 5%
<AE06> = 15; // 6^
<AE07> = 16; // 7&
<AE08> = 17; // 8*
<AE09> = 18; // 9(
<AE10> = 19; // 0)
<AE11> = 20; // [{
<AE12> = 21; // ]}
<BKSL> = 51; // \|
<TLDE> = 49; // ~`

<TAB> = 23; // Tab
<AD01> = 24; // '"
<AD02> = 25; // ,<
<AD03> = 26; // .>
<AD04> = 27; // pP
<AD05> = 28; // yY
<AD06> = 29; // fF
<AD07> = 30; // gG
<AD08> = 31; // cC
<AD09> = 32; // rR
<AD10> = 33; // lL
<AD11> = 34; // /?
<AD12> = 35; // =+
<BKSP> = 22; // Bs

<LCTL> = 37; // Ctrl
<AC01> = 38; // aA
<AC02> = 39; // oO
<AC03> = 40; // eE
<AC04> = 41; // uU
<AC05> = 42; // iI
<AC06> = 43; // dD
<AC07> = 44; // hH
<AC08> = 45; // tT
<AC09> = 46; // nN
<AC10> = 47; // sS
<AC11> = 48; // -_
<RTRN> = 36; // Ret

<LFSH> = 50; // Shift
<AB01> = 52; // ;:
<AB02> = 53; // qQ
<AB03> = 54; // jJ
<AB04> = 55; // kK
<AB05> = 56; // xX
<AB06> = 57; // bB
<AB07> = 58; // mM
<AB08> = 59; // wW
<AB09> = 60; // vV
<AB10> = 61; // zZ
<RTSH> = 62; // Shift
// Fn

<LALT> = 64; // Alt
<MUHE> = 102; // Meta
<SPCE> = 65; // Space
<HENK> = 100; // Alt
<RALT> = 108; // Meta

// Fn
<FK01> = 67; // 1
<FK02> = 68; // 2
<FK03> = 69; // 3
<FK04> = 70; // 4
<FK05> = 71; // 5
<FK06> = 72; // 6
<FK07> = 73; // 7
<FK08> = 74; // 8
<FK09> = 75; // 9
<FK10> = 76; // 0
<FK11> = 95; // [
<FK12> = 96; // ]
<INS> = 118; // \
<DELE> = 119; // `

<PRSC> = 107; // c
<SCLK> = 78; // r
<PAUS> = 127; // l
<UP> = 111; // /

<HOME> = 110; // t
<PGUP> = 112; // n -> Prior
<LEFT> = 113; // s
<RGHT> = 114; // -

<END> = 115; // w
<PGDN> = 117; // v -> Next
<DOWN> = 116; // z

<STOP> = 136; // MetaR -> Cancel

// keypad
<NMLK> = 77; // NumLock
<KPDV> = 106; // /
<KPMU> = 63; // *
<KPSU> = 82; // -

<KP7> = 79; // Home
<KP8> = 80; // Up
<KP9> = 81; // PgUp
<KPAD> = 86; // +

<KP4> = 83; // Left
<KP5> = 84; // Begin
<KP6> = 85; // Right

<KP1> = 87; // End
<KP2> = 88; // Down
<KP3> = 89; // Next
<KPEN> = 104; // Ret

<KP0> = 90; // Insert
<KPDL> = 91; // Del

indicator 2 = "Num Lock"; };

// R.Jaksa 2023
11 changes: 11 additions & 0 deletions xkb/rules/dvorak-hhkb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Dvorak HHK -*-c-*-

! model = keycodes geometry
hhkbkp = hhkbkp hhkbp2kp
* = hhkbkp hhkbp2kp

! layout = symbols compat types
dvorak = dvorak minimal minimal
* = dvorak minimal minimal

// R.Jaksa 2023
5 changes: 5 additions & 0 deletions xkb/rules/dvorak-hhkb.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
! model
hhkbkp HHKB + KP

! layout
dvorak HHKB Dvorak
1 change: 1 addition & 0 deletions xkb/symbols/dvorak
Loading

0 comments on commit 90549f6

Please sign in to comment.