0

I'm on Debian 9.11 with the MATE desktop (pinebook pro)

I've an Init script /etc/init.d/customMapping that remaps some of my keys using both setxkbmap and xmodmap. Here it is

#! /bin/sh

### BEGIN INIT INFO
# Provides:          customMapping
# Required-Start:    $local_fs x11-common xserver display
# Required-Stop:     $local_fs x11-common xserver display
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Custom keyboard mapping
# Description:       This is a simple Init script
#                    Custom keyboard mapping
### END INIT INFO
#

# Some things that run always
echo "customMapping script"

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script customMapping "
    echo "start" >> /opt/test.txt

    # Make Caps Lock a Control key
    setxkbmap -option ctrl:nocaps > /opt/logs 2>&1

    # Swap Left Control with Left Alt
    setxkbmap -option ctrl:swap_lalt_lctl > /opt/logs 2>&1

    # Make Pause/Break an End key
    xmodmap -e "keycode 127 = End" > /opt/logs 2>&1

    # Make Screen Lock a Home key
    xmodmap -e "keycode 78 = Home" > /opt/logs 2>&1

    ;;
  stop)
    echo "Stopping custom Mapping"
    ;;
  *)
    echo "Usage: /etc/init.d/customMapping {start|stop}"
    exit 1
    ;;
esac

exit 0

As you can see I've tried several kind of keywords in the Required-Start section but this doesn't work and when I check in the /opt/logs file I see the following error messages

Cannot open display "default display"

Cannot open display "default display"

xmodmap: unable to open display ''

xmodmap: unable to open display ''

What value should I set in Required-Start in order for my script to access display (X server)? Also is the Default-Start values correct?

Thank you

1 Answers1

1

You really don’t want to run these commands as a startup service, but rather something that is executed as part of your X session when it starts.

If they run in an init script, they run as root in the context of startup, not as part of your X session.

You’d be better off putting those commands in your xinitrc or xsessionrc (depending on how you launch X).

jsbillings
  • 24,006
  • 6
  • 56
  • 58
  • There are even more problems than that. systemd's translation of rc scripts is of necessity imperfect. And the _right_ way to configure this stuff is _not with a script of commands at all_. https://unix.stackexchange.com/a/479720/5132 – JdeBP Jan 26 '20 at 01:44
  • I'll read about `xinitrc` and `xsessionrc` I'm new to Linux and I didn't know about that. But @JdeBP's comment seems to be leading to a better way. Very useful information – Jérôme MEVEL Jan 27 '20 at 08:05