Skip to content

Commit

Permalink
#104 added wayland support and rework key finding
Browse files Browse the repository at this point in the history
  • Loading branch information
ldrahnik committed May 2, 2024
1 parent 2aae615 commit 7a27265
Show file tree
Hide file tree
Showing 44 changed files with 764 additions and 849 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["up5401ea-unicode-31B9"],
"justMyCode": false,
"args": ["up5401ea"],
"env": {
"LOG": "DEBUG"
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If you find this project useful, please do not forget to give it a [![GitHub sta
## Features

- Driver during installation collects anonymous data with goal improve driver (data are publicly available [here](https://lookerstudio.google.com/reporting/2bf9a72c-c675-4ff8-a3c6-2e1e8c1167b9), you can provide used config using `$ bash install_config_send_anonymous_report.sh`)
- Driver (including backlighting if hardware supported) installed for the current user (does not run under `$ sudo`)
- Driver (including backlighting if hardware supported) installed for the current user
- Driver creates own virtual environment of currently installed version of `Python3`
- Multiple pre-created [NumberPad layouts](https://github.com/asus-linux-drivers/asus-numberpad-driver#layouts) with the possibility of [creating custom layouts or improving existing ones (keys, sizes, paddings..)](https://github.com/asus-linux-drivers/asus-numberpad-driver#keyboard-layout)
- Customization through 2-way sync [configuration file](https://github.com/asus-linux-drivers/asus-numberpad-driver#configuration-file) (when `$ bash ./install.sh` is run, changes previously made in the config file will not be overwritten without user permission, similarly when `$ bash ./uninstall.sh` is run the config file will be kept. In either case, when the config file or parts of it do not exist they will be automatically created or completed with default values)
Expand Down
2 changes: 2 additions & 0 deletions asus_numberpad_driver.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ TimeoutSec=5
Restart=on-failure
Environment="DISPLAY=$DISPLAY"
Environment="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS"
Environment="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR"
Environment="$XDG_SESSION_TYPE=$XDG_SESSION_TYPE"

[Install]
WantedBy=default.target
18 changes: 18 additions & 0 deletions asus_numberpad_driver.wayland.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Asus NumberPad Driver

[Service]
Type=simple
ExecStart=/usr/share/asus-numberpad-driver/.env/bin/python3 /usr/share/asus-numberpad-driver/numberpad.py $LAYOUT_NAME $CONFIG_FILE_DIR_PATH
StandardOutput=append:$ERROR_LOG_FILE_PATH
StandardError=append:$ERROR_LOG_FILE_PATH
TimeoutSec=5
Restart=on-failure
Environment="DISPLAY=$DISPLAY"
Environment="WAYLAND_DISPLAY=$WAYLAND_DISPLAY"
Environment="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS"
Environment="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR"
Environment="$XDG_SESSION_TYPE=$XDG_SESSION_TYPE"

[Install]
WantedBy=default.target
1 change: 1 addition & 0 deletions asus_numberpad_driver.x11.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Environment="DISPLAY=$DISPLAY"
Environment="XAUTHORITY=$XAUTHORITY"
Environment="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS"
Environment="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR"
Environment="$XDG_SESSION_TYPE=$XDG_SESSION_TYPE"

[Install]
WantedBy=default.target
11 changes: 6 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ LOGS_INSTALL_LOG_FILE_PATH="$LOGS_DIR_PATH/$LOGS_INSTALL_LOG_FILE_NAME"


{
# pip pywayland requires gcc
if [[ $(sudo apt-get install 2>/dev/null) ]]; then
PACKAGE_MANAGER="apt"
sudo apt-get -y install ibus libevdev2 curl xinput i2c-tools python3-dev python3-virtualenv libxml2-utils
sudo apt-get -y install ibus libevdev2 curl xinput i2c-tools python3-dev python3-virtualenv libxml2-utils libxkbcommon-dev gcc
elif [[ $(sudo pacman -h 2>/dev/null) ]]; then
PACKAGE_MANAGER="pacman"
# arch does not have header packages (python3-dev), headers are shipped with base? python package should contains almost latest version python3.*
sudo pacman --noconfirm --needed -S ibus libevdev curl xorg-xinput i2c-tools python python-virtualenv libxml2
sudo pacman --noconfirm --needed -S ibus libevdev curl xorg-xinput i2c-tools python python-virtualenv libxml2 libxkbcommon gcc
elif [[ $(sudo dnf help 2>/dev/null) ]]; then
PACKAGE_MANAGER="dnf"
sudo dnf -y install ibus libevdev curl xinput i2c-tools python3-devel python3-virtualenv libxml2
sudo dnf -y install ibus libevdev curl xinput i2c-tools python3-devel python3-virtualenv libxml2 libxkbcommon-devel gcc
elif [[ $(sudo yum help 2>/dev/null) ]]; then
PACKAGE_MANAGER="yum"
# yum was replaced with newer dnf above
sudo yum --y install ibus libevdev curl xinput i2c-tools python3-devel python3-virtualenv libxml2
sudo yum --y install ibus libevdev curl xinput i2c-tools python3-devel python3-virtualenv libxml2 libxkbcommon-devel gcc
elif [[ $(sudo zypper help 2>/dev/null) ]]; then
PACKAGE_MANAGER="zypper"
sudo zypper --non-interactive install ibus libevdev2 curl xinput i2c-tools python3-devel python3-virtualenv libxml2
sudo zypper --non-interactive install ibus libevdev2 curl xinput i2c-tools python3-devel python3-virtualenv libxml2 libxkbcommon-devel gcc
else
echo "Not detected package manager. Driver may not work properly because required packages have not been installed. Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)."
fi
Expand Down
7 changes: 1 addition & 6 deletions install_layout_auto_suggestion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ for OPTION in $(ls layouts); do
echo
echo "NumberPad layout"
echo
echo "3 variants of NumberPad layouts are predefined for each laptop:"
echo " - The non-unicode variant does not send any character via the unicode Ctrl+Shift+U shortcut. It uses the direct numeric keys, and key combinations (Shift + number) for the percent and hash characters. Because of this, this option is not resistant to custom overbindings nor to some keyboard language layouts (e.g. Czech)"
echo " - Standard. All keys are sent directly except the percent and hash characters (these use the unicode Ctrl+Shift+U shortcut) so that this layout should work for any keyboard language layout but still is not resistant to custom overbinding of keys, which is why the last variant exists"
echo " - The unicode variant sends all keys as unicode characters except for BACKSPACE and ENTER. This layout is the most resistant to overbinding of keys but sends multiple keys instead of just one, unnecessarily heavy if you do not need it."
echo
read -r -p "Automatically recommended numberpad layout for detected laptop $LAPTOP_NAME_FULL is $SUGGESTED_LAYOUT. Do you want to use standard variant of $SUGGESTED_LAYOUT? [y/N]" RESPONSE
read -r -p "The automatically recommended NumberPad layout for this laptop ($LAPTOP_NAME_FULL) is $SUGGESTED_LAYOUT. Do you want to use the $SUGGESTED_LAYOUT layout? (The photo of the recommended NumberPad layout can be found here https://github.com/asus-linux-drivers/asus-numberpad-driver#$SUGGESTED_LAYOUT) [y/N]" RESPONSE
case "$RESPONSE" in [yY][eE][sS]|[yY])

echo
Expand Down
7 changes: 3 additions & 4 deletions install_layout_select.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ if [ -z "$LAYOUT_NAME" ]; then
echo
echo "NumberPad layout"
echo
echo "3 variants of NumberPad layouts are predefined for each laptop:"
echo " - The non-unicode variant does not send any character via the unicode Ctrl+Shift+U shortcut. It uses the direct numeric keys, and key combinations (Shift + number) for the percent and hash characters. Because of this, this option is not resistant to custom overbindings nor to some keyboard language layouts (e.g. Czech)"
echo " - Standard. All keys are sent directly except the percent and hash characters (these use the unicode Ctrl+Shift+U shortcut) so that this layout should work for any keyboard language layout but still is not resistant to custom overbinding of keys, which is why the last variant exists"
echo " - The unicode variant sends all keys as unicode characters except for BACKSPACE and ENTER. This layout is the most resistant to overbinding of keys but sends multiple keys instead of just one, unnecessarily heavy if you do not need it."
echo "The driver will try to find the appropriate keys for each field of the layout that can be successfully sent. Key modifiers are supported. When the appropriate key cannot be found then the field will be sent using the Unicode shortcut (usually Ctrl+Shift+U+<0-F>)."
echo
echo "Photos of all layouts can be found here https://github.com/asus-linux-drivers/asus-numberpad-driver#layouts."
echo
echo "Select layout:"
echo
Expand Down
10 changes: 7 additions & 3 deletions install_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])
SERVICE=1

SERVICE_FILE_PATH=asus_numberpad_driver.service
SERVICE_WAYLAND_FILE_PATH=asus_numberpad_driver.wayland.service
SERVICE_X11_FILE_PATH=asus_numberpad_driver.x11.service
SERVICE_INSTALL_FILE_NAME="[email protected]"
SERVICE_INSTALL_DIR_PATH="/usr/lib/systemd/user"
Expand All @@ -30,6 +31,7 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])
DBUS_SESSION_BUS_ADDRESS=$(echo $DBUS_SESSION_BUS_ADDRESS)
XAUTHORITY=$(echo $XAUTHORITY)
DISPLAY=$(echo $DISPLAY)
WAYLAND_DISPLAY=$(echo $WAYLAND_DISPLAY)
XDG_SESSION_TYPE=$(echo $XDG_SESSION_TYPE)
ERROR_LOG_FILE_PATH="$LOGS_DIR_PATH/error.log"

Expand All @@ -38,6 +40,7 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])
echo "CONFIG_FILE_DIR_PATH: $CONFIG_FILE_DIR_PATH"
echo
echo "env var DISPLAY: $DISPLAY"
echo "env var WAYLAND_DISPLAY: $WAYLAND_DISPLAY"
echo "env var AUTHORITY: $XAUTHORITY"
echo "env var XDG_RUNTIME_DIR: $XDG_RUNTIME_DIR"
echo "env var DBUS_SESSION_BUS_ADDRESS: $DBUS_SESSION_BUS_ADDRESS"
Expand All @@ -47,12 +50,13 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])
echo

if [ "$XDG_SESSION_TYPE" = "x11" ]; then
cat "$SERVICE_X11_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $XAUTHORITY $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
cat "$SERVICE_X11_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_SESSION_TYPE=$XDG_SESSION_TYPE DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $XAUTHORITY $XDG_RUNTIME_DIR $XDG_SESSION_TYPE $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
elif [ "$XDG_SESSION_TYPE" = "wayland" ]; then
echo "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 "$SERVICE_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $XAUTHORITY $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
# DISPLAY=$DISPLAY for Xwayland
cat "$SERVICE_WAYLAND_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_SESSION_TYPE=$XDG_SESSION_TYPE DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $WAYLAND_DISPLAY $XDG_RUNTIME_DIR $XDG_SESSION_TYPE $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
else
cat "$SERVICE_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $XAUTHORITY $XDG_RUNTIME_DIR $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
cat "$SERVICE_FILE_PATH" | LAYOUT_NAME=$LAYOUT_NAME CONFIG_FILE_DIR_PATH="$CONFIG_FILE_DIR_PATH/" DISPLAY=$DISPLAY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR XDG_SESSION_TYPE=$XDG_SESSION_TYPE DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ERROR_LOG_FILE_PATH=$ERROR_LOG_FILE_PATH envsubst '$LAYOUT_NAME $CONFIG_FILE_DIR_PATH $DISPLAY $XDG_RUNTIME_DIR $XDG_SESSION_TYPE $DBUS_SESSION_BUS_ADDRESS $ERROR_LOG_FILE_PATH' | sudo tee "$SERVICE_INSTALL_DIR_PATH/$SERVICE_INSTALL_FILE_NAME" >/dev/null
fi

if [[ $? != 0 ]]; then
Expand Down
19 changes: 0 additions & 19 deletions layouts/b7402-non-unicode.py

This file was deleted.

19 changes: 0 additions & 19 deletions layouts/b7402-unicode.py

This file was deleted.

8 changes: 4 additions & 4 deletions layouts/b7402.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
bottom_offset = 80

keys = [
[EV_KEY.KEY_KP7, EV_KEY.KEY_KP8, EV_KEY.KEY_KP9, EV_KEY.KEY_KPSLASH, EV_KEY.KEY_BACKSPACE],
[EV_KEY.KEY_KP4, EV_KEY.KEY_KP5, EV_KEY.KEY_KP6, EV_KEY.KEY_KPASTERISK, EV_KEY.KEY_BACKSPACE],
[EV_KEY.KEY_KP1, EV_KEY.KEY_KP2, EV_KEY.KEY_KP3, EV_KEY.KEY_KPMINUS, "%"],
[EV_KEY.KEY_KP0, EV_KEY.KEY_KPDOT, EV_KEY.KEY_KPENTER, EV_KEY.KEY_KPPLUS, EV_KEY.KEY_KPEQUAL]
["7", "8", "9", "slash", "BackSpace"],
["4", "5", "6", "asterisk", "BackSpace"],
["1", "2", "3", "minus", "percent"],
["0", "period", "Return", "plus", "equal"]
]
19 changes: 0 additions & 19 deletions layouts/e210ma-non-unicode.py

This file was deleted.

19 changes: 0 additions & 19 deletions layouts/e210ma-unicode.py

This file was deleted.

8 changes: 4 additions & 4 deletions layouts/e210ma.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
bottom_offset = 40

keys = [
[EV_KEY.KEY_KP7, EV_KEY.KEY_KP8, EV_KEY.KEY_KP9, EV_KEY.KEY_KPSLASH, EV_KEY.KEY_BACKSPACE],
[EV_KEY.KEY_KP4, EV_KEY.KEY_KP5, EV_KEY.KEY_KP6, EV_KEY.KEY_KPASTERISK, EV_KEY.KEY_BACKSPACE],
[EV_KEY.KEY_KP1, EV_KEY.KEY_KP2, EV_KEY.KEY_KP3, EV_KEY.KEY_KPMINUS, "%"],
[EV_KEY.KEY_KP0, EV_KEY.KEY_KPDOT, EV_KEY.KEY_KPENTER, EV_KEY.KEY_KPPLUS, EV_KEY.KEY_KPEQUAL]
["7", "8", "9", "slash", "BackSpace"],
["4", "5", "6", "asterisk", "BackSpace"],
["1", "2", "3", "minus", "percent"],
["0", "period", "Return", "plus", "equal"]
]
31 changes: 0 additions & 31 deletions layouts/g513-non-unicode.py

This file was deleted.

31 changes: 0 additions & 31 deletions layouts/g513-unicode.py

This file was deleted.

10 changes: 5 additions & 5 deletions layouts/g513.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
left_offset = 80
bottom_offset = 80

# please create an issue in case values does not work
# please create an issue in case values do not work
backlight_levels = [
"0x41",
"0x42",
Expand All @@ -24,8 +24,8 @@
]

keys = [
[EV_KEY.KEY_KP7, EV_KEY.KEY_KP8, EV_KEY.KEY_KP9, EV_KEY.KEY_KPSLASH],
[EV_KEY.KEY_KP4, EV_KEY.KEY_KP5, EV_KEY.KEY_KP6, EV_KEY.KEY_KPASTERISK, EV_KEY.KEY_BACKSPACE],
[EV_KEY.KEY_KP1, EV_KEY.KEY_KP2, EV_KEY.KEY_KP3, EV_KEY.KEY_KPMINUS, EV_KEY.KEY_KPENTER],
[EV_KEY.KEY_KP0, EV_KEY.KEY_KP0, EV_KEY.KEY_KPDOT, EV_KEY.KEY_KPPLUS, EV_KEY.KEY_KPENTER]
["7", "8", "9", "slash"],
["4", "5", "6", "asterisk", "BackSpace"],
["1", "2", "3", "minus", "Return"],
["0", "0", "period", "plus", "Return"]
]
19 changes: 0 additions & 19 deletions layouts/g533-non-unicode.py

This file was deleted.

Loading

0 comments on commit 7a27265

Please sign in to comment.