Skip to content

Commit

Permalink
update to support uinput
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCMcDonough committed Oct 4, 2023
1 parent 528644f commit 9656a8c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 26 deletions.
4 changes: 3 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fi

. /scripts/setup_default_envs.sh
. /scripts/setup_directories.sh
. /scripts/hardware_accel.sh
. /scripts/hardware_setup.sh
. /scripts/setup_dbus.sh
. /scripts/setup_sway_config.sh
. /scripts/setup_novnc.sh
Expand All @@ -14,6 +14,8 @@ setup_directories

handle_hardware_accel

handle_uinput_setup

setup_dbus

get_sway_config "$@" >/etc/sway/config
Expand Down
25 changes: 0 additions & 25 deletions scripts/hardware_accel.sh

This file was deleted.

11 changes: 11 additions & 0 deletions scripts/hardware_group_operations.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/sh

add_uinput_to_group_if_exists() {
device="$DEV_UINPUT_PATH"
if [ -e "$device" ]; then
gid=$(stat -c '%g' "$device")
groupadd --gid $gid temp_group_$gid
usermod -a -G temp_group_$gid ubuntu
else
echo "Warning: $device does not exist. Skipping uinput ADD_GROUP operations."
fi
}

add_to_group_if_exists() {
if [ -e "$1" ]; then
gid=$(stat -c '%g' "$1")
Expand Down
19 changes: 19 additions & 0 deletions scripts/hardware_node_operations.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
#!/bin/sh

recreate_uinput_dev_node_if_exists() {
target_path="${HOSTDEV_UINPUT_PATH}"
node_path="${DEV_UINPUT_PATH}"

if [ -e "$target_path" ]; then
major=$(stat -c '%t' "$target_path")
minor=$(stat -c '%T' "$target_path")
major_dec=$(printf "%d" "0x$major")
minor_dec=$(printf "%d" "0x$minor")
rm -f "$node_path"
mknod "$node_path" c $major_dec $minor_dec
chmod 777 "$node_path"
else
echo "Warning: $target_path does not exist. Skipping uinput MKNOD operations."
fi
}

recreate_dev_node_if_exists() {
target_path="${HOSTDEV_DRI_PATH}$1"
node_path="${DEV_DRI_PATH}$1"
Expand All @@ -12,6 +29,8 @@ recreate_dev_node_if_exists() {
rm -f "$node_path"
mknod "$node_path" c $major_dec $minor_dec
chmod 777 "$node_path"
else
echo "Warning: $HOSTDEV_DRI_PATH does not exist. Skipping uinput MKNOD operations."
fi
}

Expand Down
42 changes: 42 additions & 0 deletions scripts/hardware_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

. /scripts/hardware_group_operations.sh
. /scripts/hardware_node_operations.sh

handle_hardware_accel() {
if [ "$DISABLE_HW_ACCEL" != "true" ]; then
case "$DRI_DEVICE_MODE" in
"ADD_GROUP")
perform_group_operations
;;
"MKNOD")
perform_node_operations
;;
"NONE")
echo "Warning: DRI_DEVICE_MODE=NONE and DISABLE_HW_ACCEL!=true . Hardware acceleration may not function correctly."
;;
*)
echo "Invalid DRI_DEVICE_MODE. Use either 'ADD_GROUP', 'MKNOD', or 'NONE'."
;;
esac
else
echo "Hardware acceleration is disabled."
fi
}

handle_uinput_setup() {
case "$UINPUT_DEVICE_MODE" in
"ADD_GROUP")
add_uinput_to_group_if_exists
;;
"MKNOD")
recreate_uinput_dev_node_if_exists
;;
"NONE")
echo "Warning: UINPUT_DEVICE_MODE=NONE. Gamepads may not functino correctly."
;;
*)
echo "Invalid UINPUT_DEVICE_MODE. Use either 'ADD_GROUP', 'MKNOD', or 'NONE'."
;;
esac
}
4 changes: 4 additions & 0 deletions scripts/setup_default_envs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# NODE — automatically regenerates device nodes using mknod
# GROUP — Adds user 1000 to the existing group mounted in.
export DRI_DEVICE_MODE="${DRI_DEVICE_MODE:-"NONE"}"
export UINPUT_DEVICE_MODE="${UINPUT_DEVICE_MODE:-"NONE"}"

# Enable or disable hardware acceleration
export DISABLE_HW_ACCEL="${DISABLE_HW_ACCEL:-"true"}"
Expand All @@ -13,6 +14,9 @@ export FFMPEG_HARDWARE="${FFMPEG_HARDWARE:-"1"}"
export DEV_DRI_PATH="${DEV_DRI_PATH:-"/dev/dri/"}"
export HOSTDEV_DRI_PATH="${HOSTDEV_DRI_PATH:-"/dev/host-dri/"}"

export DEV_UINPUT_PATH="${DEV_UINPUT_PATH:-"/dev/uinput"}"
export HOSTDEV_UINPUT_PATH="${HOSTDEV_UINPUT_PATH:-"/dev/host-uinput"}"

# Configure Displays and Audio for guest applications
export WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-"wayland-1"}"
export DISPLAY="${DISPLAY:-":0"}"
Expand Down

0 comments on commit 9656a8c

Please sign in to comment.