-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmodmap-toggle
executable file
·146 lines (127 loc) · 4.02 KB
/
xmodmap-toggle
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
#!/bin/bash
# Brief:
# This is a shell script file for switching keymap via xmodmap quickly
#
# Tips:
# 1. keycode can be found via command 'xev'
# 2. xmodmap -pm #print modifier map
# 3. xmodmap -pk #print keymap table
# 4. disable key for nothing: keycode 50 = 0x0000
#
# Notice:
# dconf key 'alt-tab-next-window' and 'alt-tab-prev-window' will not work but the value is
# still be there when logout or reboot, therefore these keys must be reset then overwrite again.
#
# Params:
# 1. option $1, value: "xmode" "dconf" etc.
# when $1 is "xmod" it will overwirte the xmodmap keys
# when $1 is "dconf" it will overwirte the dconf keys
# 2. option $2, value: "swap" "default" etc.
# when $2 is "swap" it will overwrite keys or reset default
########################################################################
#=> common libs
########################################################################
source "${HOME}/CodeHub/SHELL/libs/bootstrap.sh"
# My notebook keymap
# 37 0xffe3 (Control_L) 0x0000 (NoSymbol) 0xffe3 (Control_L)
# 50 0xffe1 (Shift_L) 0x0000 (NoSymbol) 0xffe1 (Shift_L)
# 64 0xffe9 (Alt_L) 0xffe7 (Meta_L) 0xffe9 (Alt_L) 0xffe7 (Meta_L)
# 66 0xffe5 (Caps_Lock) 0x0000 (NoSymbol) 0xffe5 (Caps_Lock)
# 105 0xffe4 (Control_R) 0x0000 (NoSymbol) 0xffe4 (Control_R)
# 108 0xffea (Alt_R) 0xffe8 (Meta_R) 0xffea (Alt_R) 0xffe8 (Meta_R)
# 133 0xffeb (Super_L) 0x0000 (NoSymbol) 0xffeb (Super_L)
#
# shift Shift_L (0x32), Shift_R (0x3e)
# lock Caps_Lock (0x42)
# control Control_L (0x25), Control_R (0x69)
# mod1 Alt_L (0x40), Alt_R (0x6c), Meta_L (0xcd)
# mod2 Num_Lock (0x4d)
# mod3
# mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
# mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
# function getxmodmapcmd start ================
function getxmodmapcmd() {
DEFAULTMAPS="
!default keymap
keycode 9 = Escape
keycode 37 = Control_L
keycode 64 = Alt_L Meta_L
keycode 66 = Caps_Lock
keycode 76 = F10
keycode 108 = Alt_R Meta_R
keycode 133 = Super_L
keycode 135 = Menu
"
SWAPMAPS="
!swap keymap
keycode 9 = Caps_Lock
keycode 37 = Super_L
keycode 64 = Control_L
keycode 66 = Escape
keycode 76 = Menu
keycode 108 = F10
keycode 133 = Alt_L Meta_L
keycode 135 = Alt_R Meta_R
"
TEMP=
case $1 in
swap)
TEMP="$SWAPMAPS"
;;
default)
TEMP="$DEFAULTMAPS"
;;
*)
echo
exit 1
;;
esac
TEMPLATE="!customkeymap
clear control
clear mod1
clear mod4
clear lock
clear shift
"$TEMP"
add control = Control_L Control_R
add mod1 = Alt_L Meta_L Alt_R
add mod4 = Super_L
add lock = Caps_Lock
add shift = Shift_L Shift_R
"
echo "${TEMPLATE}"
}
# function getxmodmapcmd end ================
########################################################################
#=> main code here
########################################################################
# 1.xmodmap keymap handle
FILENAME="${HOME}/.Xmodmap"
TAG=
[[ -n $(sed -n '/default keymap/p' $FILENAME) ]] && TAG="swap" || TAG="default"
if [[ -n $2 ]]; then
TAG=$2
fi
if [[ -z $1 || $1 == "xmod" ]]; then
CMDSTR=$(getxmodmapcmd $TAG)
if [[ -n "$CMDSTR" ]]; then
sed -i '/customkeymap/,$d' "$FILENAME"
echo "$CMDSTR" >> "$FILENAME"
xmodmap "$FILENAME"
fi
fi
# 2.dconf keyamp change about unity switcher
if [[ -z $1 || $1 == "dconf" ]]; then
PROFILE_KEYMAP="
/org/compiz/profiles/unity/plugins/unityshell/alt-tab-forward,<Alt>Tab,<Control>Tab
/org/compiz/profiles/unity/plugins/unityshell/alt-tab-prev,<Alt><Shift>Tab,<Control><Shift>Tab
/org/compiz/profiles/unity/plugins/unityshell/alt-tab-next-window,<Alt>grave,<Control>grave
/org/compiz/profiles/unity/plugins/unityshell/alt-tab-prev-window,<Shift><Alt>asciitilde,<Control><Shift>grave
"
for LINE in $(echo "$PROFILE_KEYMAP"); do
declare -a ARR=($(explode $LINE ","))
KEY=${ARR[0]}
[[ $TAG == "swap" ]] && VAL=${ARR[2]} || VAL=${ARR[1]}
dconf write "$KEY" "'$VAL'"
done
fi