2

Since it is impossible to make udev rules that affect Xorg settings run on startup, I'd like to replace these with other alternatives. At the moment, I have two primary udev scripts that I've written. The first changes keyboard layout when the keyboard is plugged in or removed, as well as starting xcape. The second slows down the pointer when a specific mouse is plugged in, and also allow input from the mouse to wake the computer up.

I'm using (K)ubuntu 13.04. The udev rules and scripts follow, as do the xmodmaps.

/etc/udev/rules.d/00-teck.rules:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0e6a", ATTR{idProduct}=="030c", RUN+="/usr/local/bin/TECK_connect"
ACTION=="remove", SUBSYSTEM=="usb", RUN+="/usr/local/bin/TECK_disconnect"

/usr/local/bin/TECK_connect:

#!/usr/bin/env bash

export DISPLAY=:0.0
cp -f /home/sparhawk/HDD/Computer/Xmodmaps/Xmodmap_for_TECK /home/sparhawk/.Xmodmap
sudo -u sparhawk setxkbmap -layout us -variant altgr-intl
sudo -u sparhawk xmodmap /home/sparhawk/.Xmodmap
sudo -u sparhawk pkill xcape
sudo -u sparhawk xcape -e 'Alt_L=Return' && sudo -u sparhawk notify-send "xmodmap" "TECK connected." -i /usr/share/icons/oxygen/48x48/devices/input-keyboard.png --hint=int:transient:1

/usr/local/bin/TECK_disconnect:

#!/usr/bin/env bash
if [[ `lsusb | egrep -c 'Apple, Inc\. Aluminum Keyboard'` == 0 ]] && [[ `lsusb | egrep -c 'Megawin Technology Co\., Ltd'` == 0 ]]; then
  export DISPLAY=:0.0
  cp -f /home/sparhawk/HDD/Computer/Xmodmaps/Xmodmap_for_internal_Dell_keyboard /home/sparhawk/.Xmodmap
  sudo -u sparhawk setxkbmap -layout us -variant altgr-intl
  sudo -u sparhawk xmodmap /home/sparhawk/.Xmodmap
  sudo -u sparhawk pkill xcape
fi

/etc/udev/rules.d/90-razerwakeup-slowdown.rules:

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1532", ATTRS{idProduct}=="0016" RUN+="/bin/sh -c 'echo $env{DEVPATH} | grep -q usb./[^/]*/[^/]*/[^/]*$ && echo enabled > /sys$env{DEVPATH}/../power/wakeup; razer_slowdown'"

/usr/local/bin/razer_slowdown:

#!/usr/bin/env bash
# slow down the tracking speed of a razer mouse.
# to check, $ xinput --list-props "Razer Razer DeathAdder"| grep 'Constant Deceleration'
# which was originally 1

scriptproper () {
        sleep 0.5 # perhaps not necessary, but putting it in background is.
        export DISPLAY=:0.0
        sudo -u sparhawk xinput --set-prop "Razer Razer DeathAdder" "Device Accel Constant Deceleration" 3
}

scriptproper &

~/HDD/Computer/Xmodmaps/Xmodmap_for_TECK:

! map right blank key to "menu" for KDE.
keycode 97 = Menu Menu
! Swap left ctrl and shift
keycode 50 = Control_L Control_L
keycode 37 = Shift_L Shift_L
! Replace right ctrl with shift
keycode 105 = Shift_R Shift_R
! Replace right shift, '
keycode 62 = apostrophe quotedbl
keycode 48 = slash question
! Enter to alt
keycode 36 = Alt_L Meta_L
! AltGr to Compose
!keycode 108 = Multi_key
! AltGr+key
keycode 20 = minus underscore minus underscore endash emdash
keycode 60 = period greater period greater ellipsis
! Left blank key to AltGr
keycode 101 = ISO_Level3_Shift Multi_key ISO_Level3_Shift
! key to the left of `
keycode 94 = Return NoSymbol Return
! Fn+F5 and Fn+F6 control brightness
keycode 148 = XF86MonBrightnessDown NoSymbol XF86MonBrightnessDown
keycode 179 = XF86MonBrightnessUp NoSymbol XF86MonBrightnessUp

clear Shift
clear Lock
clear Control
clear Mod1
clear Mod2
clear Mod3
clear Mod4
clear Mod5
add    Shift   = Shift_L Shift_R
add    Lock    = Caps_Lock
add    Control = Control_L Control_R
add    Mod1    = Alt_L
add    Mod2    = Num_Lock
add    Mod4    = Super_L Super_R
add    Mod5    = Mode_switch ISO_Level3_Shift ISO_Level3_Shift ISO_Level3_Shift

~/HDD/Computer/Xmodmaps/Xmodmap_for_internal_Dell_keyboard:

! map right alt to ISO_Level3_Shift (e.g. for compose)
keycode 108 =   ISO_Level3_Shift Multi_key
! Swap left ctrl and caps lock
keycode 66 =    Control_L
keycode 37 =    Caps_Lock

! AltGr+key
keycode 20 = minus underscore minus underscore endash emdash
keycode 60 = period greater period greater ellipsis

keycode 105 =   Control_R       Multi_key
clear Shift
clear Lock
clear Control
clear Mod1
clear Mod2
clear Mod3
clear Mod4
clear Mod5
add    Shift   = Shift_L Shift_R
add    Lock    = Caps_Lock
add    Control = Control_L Control_R
add    Mod1    = Alt_L
add    Mod2    = Num_Lock
add    Mod4    = Super_L Super_R
add    Mod5    = Mode_switch ISO_Level3_Shift ISO_Level3_Shift ISO_Level3_Shift
Sparhawk
  • 19,941
  • N.B. this is partially answered in the comments in the first link, and has been split from there. @don_crissti will (probably) post his answer here. – Sparhawk May 24 '13 at 11:43
  • Also, let me know if I've included too much text in the question, and I'll move some of it to pastebin. I couldn't work out if it were better to have everything on the one site or not. – Sparhawk May 24 '13 at 11:45
  • And note that it is quite possible to run udev rules on start up. It is however impossible to modify Xorg settings before Xorg has started. – phemmer May 24 '13 at 12:30
  • @Sparhawk yeah I think you might have taken the wrong message from the last answer. The problem in the last post is that the udev rules are firing before there's even an Xorg instance running, which is why it's not doing anything. If udev didn't fire at start up you'd have some serious issue (and would be largely back to the mknod nightmare that inspired devfs/udev). – Bratchley May 24 '13 at 12:55
  • @Patrick and Joel Davis : right. Sorry. I've only ever used udev rules for modifying Xorg settings after usb devices connect, so in my head they are the same thing. I'll edit to correct this. – Sparhawk May 24 '13 at 13:04

1 Answers1

0

To replace xcape, I instead installed at-home-modifier, which does a similar thing, but at a root level. It has the added advantage of being configured by xorg rules, allowing it to only operate on particular keyboards.

Hence, /etc/X11/xorg.conf.d/11-TECK-keymap.conf contains

Section "InputClass"
  Identifier "TECK"
  Driver "evdev"
  Option "XKBOptions" "terminate:ctrl_alt_bksp" # and so on

  # If you save this file under xorg.conf.d/ :
  Option "AutoServerLayout" "on"

  MatchIsKeyboard "on"
  MatchProduct "TrulyErgonomic.com Truly Ergonomic Computer Keyboard"

  ### at-home-modifier options begin here.
  # The basic option.
  Option "XkbLayout" "us"
  Option "XkbVariant" "altgr-intl"
  Option "XKbOptions" "lv3:ralt_switch_multikey,numpad:pc"
  Option "TransMod" "36:64" # Defines key/modifier pairs. Use xev. e.g. Enter (real key):Alt (virtual key).
EndSection

For the keymaps, I instead used TECK's newly-released software to reconfigure the firmware (although I could've modified /usr/share/X11/xkb/keycodes/evdev). For the AltGr keys, I directly modified /usr/share/X11/xkb/symbols/us, replacing entries in the xkb_symbols "intl" { section

I replaced

key <AE11> { [ minus, underscore, yen, dead_belowdot ] };

with

key <AE11> { [ minus, underscore, endash, emdash ] };

and

key <AB09> { [ period, greater, dead_abovedot, dead_caron ] };

with

key <AB09> { [ period, greater, ellipsis, dead_caron ] };

I then deleted the cached xkb configurations at /var/lib/xkb/*.xkm as per this answer, and restarted.

I'm still not sure how to make Fn+F5 and Fn+F6 control brightness (XF86MonBrightnessDown and XF86MonBrightnessUp)

Sparhawk
  • 19,941