From e8f047f0ec83bad30e3500e10a6461bed2417849 Mon Sep 17 00:00:00 2001 From: mar77i Date: Tue, 19 Mar 2024 13:02:03 +0000 Subject: [PATCH 1/1] initial commit --- .gitignore | 1 + generate-desktop-files.sh | 43 ++++++++++++ laptop-double.svg | 7 ++ laptop-single.svg | 7 ++ laptop-vertical.svg | 10 +++ setup_screens.sh | 136 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 204 insertions(+) create mode 100644 .gitignore create mode 100755 generate-desktop-files.sh create mode 100644 laptop-double.svg create mode 100644 laptop-single.svg create mode 100644 laptop-vertical.svg create mode 100755 setup_screens.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0f6562 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.desktop diff --git a/generate-desktop-files.sh b/generate-desktop-files.sh new file mode 100755 index 0000000..29e97b2 --- /dev/null +++ b/generate-desktop-files.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +cd "$(dirname "$(realpath -Pe "${0}")")" +find . -name '*.desktop' -delete + +setup_screens= + +while (( ${#} )); do + if [[ -x "${1}" ]]; then + if [[ "${setup_screens}" ]]; then + echo "Error: script path set twice" >&2 + exit 1 + fi + setup_screens="$(realpath -Pe "${1}")" + fi + shift +done + +if [[ -z "${setup_screens}" || ! -x "${setup_screens}" ]]; then + echo "Error: script path not set or does not exist" >&2 + exit 1 +fi + +get_icon_config() { + local svg_file="$(dirname "${setup_screens}")/laptop-${REPLY,,}.svg" + if [[ -e "${svg_file}" ]]; then + echo "Icon=${svg_file}" + else + echo "#Icon=${svg_file}" + fi +} + +while read -r -d $'\n'; do + cat >"${REPLY}.desktop" </dev/null) diff --git a/laptop-double.svg b/laptop-double.svg new file mode 100644 index 0000000..a78a6dc --- /dev/null +++ b/laptop-double.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/laptop-single.svg b/laptop-single.svg new file mode 100644 index 0000000..687d56f --- /dev/null +++ b/laptop-single.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/laptop-vertical.svg b/laptop-vertical.svg new file mode 100644 index 0000000..edb6b4c --- /dev/null +++ b/laptop-vertical.svg @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/setup_screens.sh b/setup_screens.sh new file mode 100755 index 0000000..ffe7de8 --- /dev/null +++ b/setup_screens.sh @@ -0,0 +1,136 @@ +#!/bin/bash + +kernel_pkg_ver() { + pacman -Qi linux | sed -rn 's/^Version\s*:\s*(.*)$/\1/p' +} + +kernel_running_ver() { + uname -r | sed -r 's/-/./' +} + +try_finding_stylus() { + local found=0 + if [[ "$(kernel_pkg_ver)" != "$(kernel_running_ver)" ]]; then + echo "Warning: Kernel was updated: You need a reboot!" >&2 + fi + echo "Tip with the stylus on monitor ${1}" + for (( i = 0; i < 16; i++ )); do + sleep 1 + if grep -Fq "${2}" < <(xinput list --name-only); then + found=1 + break + fi + done + if (( !found )); then + echo "Error: Stylus was not found: ${2}" >&2 + return 1 + fi + +} + +setup_styluses() { + local -A styluses=( + [eDP-1]="ELAN9008:00 04F3:425B Stylus Pen (0)" + [eDP-2]="ELAN9009:00 04F3:425A Stylus Pen (0)" + ) + local mon stylus + for mon in "${!styluses[@]}"; do + stylus="${styluses[${mon}]}" + xinput disable "${stylus}" + if grep -q "${mon}" < <(xrandr --listactivemonitors); then + if ! grep -Fq "${stylus}" < <(xinput list --name-only); then + try_finding_stylus "${mon}" "${stylus}" || return 1 + fi + xinput enable "${stylus}" + xinput --map-to-output "${stylus}" "${mon}" + echo "$(date) mapped stylus pen ${stylus%% *} to ${mon}" >&2 + else + echo "$(date) disabled stylus pen ${stylus%% *}" >&2 + fi + done +} + +setup_touchpads() { + local touchpads=( + "ELAN9008:00 04F3:425B" + "ELAN9008:00 04F3:425B Touchpad" + "ELAN9009:00 04F3:425A" + "ELAN9009:00 04F3:425A Touchpad" + ) + local touchpad + for touchpad in "${touchpads[@]}"; do + xinput disable "${touchpad}" + done +} + +check_config () { + local config + for config in "${configs[@]}"; do + if [[ "${1}" == "${config}" ]]; then + return 0 + fi + done + return 1 +} + +exit_script() { + local ret="${?}" + if (( wait_for_keypress )); then + echo "Press a key!" + read -n1 + fi + echo exit "${1:-${ret}}" +} + +help() { + echo "TODO: help text" + exit 0 +} + +wait_for_keypress=0 +load_saved= +configs=() + +if ! output="$(lxqt-config-monitor --list-saved 2>/dev/null)"; then + lxqt-config-monitor --list-saved + exit_script +elif [[ "${output}" ]]; then + mapfile -d $'\n' -t configs < <(printf '%s\n' "${output}") +fi +unset output +list_saved_failed="${?}" +while (( ${#} )); do + case "${1}" in + --wait-for-keypress) + wait_for_keypress=1 + ;; + --load-saved) + load_saved="${2}" + shift + ;; + --help) + help + ;; + *) + echo "Error: unknown argument: ${1}" >&2 + exit_script 1 + ;; + esac + shift +done + +if [[ "${load_saved}" ]]; then + (( list_saved_failed )) && exit "${list_saved_failed}" + if check_config "${load_saved}"; then + lxqt-config-monitor --load-saved "${load_saved}" || exit 1 + sleep .4 + else + echo "Error: no such saved config: ${load_saved}" >&2 + exit_script 1 + fi +fi + +setup_touchpads +setup_styluses + +exit_script -- 2.44.0