Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ldrahnik committed Oct 6, 2023
1 parent 9b10689 commit 8f3a2e5
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 20 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ $ rm /home/ldrahnik/.Xauthority
$ reboot
```

**Read environment variables for systemctl service**

```
$ systemctl status <name>.service # read PID
$ sudo strings /proc/<PID>/environ
```

## Configuration

### Keyboard layout
Expand Down
1 change: 0 additions & 1 deletion asus_touchpad.X11.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[Unit]
Description=Asus Touchpad to Numpad Handler for %i
After=display-manager.service

[Service]
User=%i
Expand Down
19 changes: 19 additions & 0 deletions asus_touchpad.X11.user.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=Asus Touchpad to Numpad Handler for %i

[Service]
User=%i
Type=idle
ExecStart=/usr/bin/env python3 /usr/share/asus_touchpad_numpad-driver/asus_touchpad.py $LAYOUT $CONFIG_FILE_DIR
StandardInput=tty-force
StandardOutput=append:/var/log/asus_touchpad_numpad-driver/error.log
StandardError=append:/var/log/asus_touchpad_numpad-driver/error.log
TimeoutSec=5
Restart=on-failure
Environment="DISPLAY=$XDISPLAY"
Environment="XAUTHORITY=$XAUTHORITY"
Environment="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS"
Environment="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR"

[Install]
WantedBy=default.target
51 changes: 46 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,42 @@ if [ "$wayland_or_x11" = "x11" ]; then

xauthority=$(/usr/bin/xauth info | grep Authority | awk '{print $3}')
xdisplay=$(echo $DISPLAY)

echo "DISPLAY: $xdisplay"
echo "AUTHORITY: $xauthority"
cat asus_touchpad.X11.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR' > /etc/systemd/system/[email protected]

if [ "$1" = "--user" ]; then

uid=$(id -u $RUN_UNDER_USER)
xdg_runtime_dir="/run/user/$uid"
dbus_session_bus_address="unix:path=$xdg_runtime_dir/bus"

echo "UID: $uid"
echo "XDG_RUNTIME_DIR: $xdg_runtime_dir"
echo "DBUS_SESSION_BUS_ADDRESS: $dbus_session_bus_address"

cat asus_touchpad.X11.user.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority XDG_RUNTIME_DIR=$xdg_runtime_dir DBUS_SESSION_BUS_ADDRESS=$dbus_session_bus_address envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS' > /usr/lib/systemd/[email protected]
cat asus_touchpad.X11.user.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority XDG_RUNTIME_DIR=$xdg_runtime_dir DBUS_SESSION_BUS_ADDRESS=$dbus_session_bus_address envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS' > /etc/systemd/system/[email protected]
cat asus_touchpad.X11.user.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority XDG_RUNTIME_DIR=$xdg_runtime_dir DBUS_SESSION_BUS_ADDRESS=$dbus_session_bus_address envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS' > /etc/systemd/user/[email protected]
else
cat asus_touchpad.X11.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model XDISPLAY=$xdisplay XAUTHORITY=$xauthority envsubst '$LAYOUT $XAUTHORITY $XDISPLAY $CONFIG_FILE_DIR' > /etc/systemd/system/[email protected]
fi
elif [ "$wayland_or_x11" = "wayland" ]; then
echo "Wayland is detected, unfortunatelly you will not be able use feature: Disabling Touchpad (e.g. Fn+special key) disables NumberPad aswell, at this moment is supported only X11"

cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/[email protected]
if [ "$1" = "--user" ]; then
cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/user/[email protected]
else
cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/[email protected]
fi
else
echo "Wayland or X11 is not detected"

cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/[email protected]
if [ "$1" = "--user" ]; then
cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/user/[email protected]
else
cat asus_touchpad.service | CONFIG_FILE_DIR="$CONFIG_FILE_DIR/" LAYOUT=$model envsubst '$LAYOUT $CONFIG_FILE_DIR' > /etc/systemd/system/[email protected]
fi
fi


Expand Down Expand Up @@ -394,7 +419,11 @@ else
echo "Automatic installing of toggling script for XF86Calculator key failed. Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)."
fi

systemctl daemon-reload
if [ "$1" = "--user" ]; then
systemctl --user daemon-reload
else
systemctl daemon-reload
fi

if [[ $? != 0 ]]; then
echo "Something went wrong when was called systemctl daemon reload"
Expand All @@ -405,7 +434,19 @@ fi

read -r -p "Do you want start the driver automatically at boot using systemd service? [y/N] (result might be black screen which will prevent login, systemd service is not designed to be started at boot with using X11, is recommended start driver on every startup by other way)" response
case "$response" in [yY][eE][sS]|[yY])
systemctl enable asus_touchpad_numpad@$RUN_UNDER_USER.service

if [ "$1" = "--user" ]; then
# --user search /etc/systemd/user/

# systemctl enable --user [email protected]
# Created symlink /home/ldrahnik/.config/systemd/user/default.target.wants/[email protected] → /etc/xdg/systemd/user/[email protected].

systemctl enable --user asus_touchpad_numpad@$RUN_UNDER_USER.service
else
# --global search /etc/systemd/system/
systemctl enable --global asus_touchpad_numpad@$RUN_UNDER_USER.service
fi

if [[ $? != 0 ]]; then
echo "Something went wrong when enabling the asus_touchpad_numpad.service"
exit 1
Expand Down
54 changes: 40 additions & 14 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,44 @@ echo $RUN_UNDER_USER

source remove_previous_implementation_of_service.sh

systemctl stop asus_touchpad_numpad@$RUN_UNDER_USER.service
if [[ $? != 0 ]]
if [ "$1" = "--user" ]
then
echo "asus_touchpad_numpad.service cannot be stopped correctly..."
fi

systemctl disable asus_touchpad_numpad@$RUN_UNDER_USER.service
if [[ $? != 0 ]]
then
echo "asus_touchpad_numpad.service cannot be disabled correctly..."
fi
systemctl --user stop asus_touchpad_numpad@$RUN_UNDER_USER.service
if [[ $? != 0 ]]
then
echo "asus_touchpad_numpad.service cannot be stopped correctly..."
fi

rm -f /etc/systemd/system/[email protected]
if [[ $? != 0 ]]
then
echo "/etc/systemd/system/asus_touchpad_numpad.service cannot be removed correctly..."
systemctl --user disable asus_touchpad_numpad@$RUN_UNDER_USER.service
if [[ $? != 0 ]]
then
echo "asus_touchpad_numpad.service cannot be disabled correctly..."
fi

rm -f /etc/systemd/user/[email protected]
if [[ $? != 0 ]]
then
echo "/etc/systemd/user/asus_touchpad_numpad.service cannot be removed correctly..."
fi
else
systemctl --global stop asus_touchpad_numpad@$RUN_UNDER_USER.service
if [[ $? != 0 ]]
then
echo "asus_touchpad_numpad.service cannot be stopped correctly..."
fi

systemctl --global disable asus_touchpad_numpad@$RUN_UNDER_USER.service
if [[ $? != 0 ]]
then
echo "asus_touchpad_numpad.service cannot be disabled correctly..."
fi

rm -f /etc/systemd/system/[email protected]
if [[ $? != 0 ]]
then
echo "/etc/systemd/system/asus_touchpad_numpad.service cannot be removed correctly..."
fi
fi


Expand Down Expand Up @@ -136,7 +158,11 @@ then
echo "/usr/lib/udev/rules.d/90-numberpad-external-keyboard.rules cannot be removed correctly..."
fi

systemctl daemon-reload
if [ "$1" = "--user" ]; then
systemctl --user daemon-reload
else
systemctl --global daemon-reload
fi

if [[ $? != 0 ]]; then
echo "Something went wrong when was called systemctl daemon reload"
Expand Down

0 comments on commit 8f3a2e5

Please sign in to comment.