Add xwacomcalibrate as package
This commit is contained in:
parent
fd1f22302f
commit
fa882cb478
27
packages/xwacomcalibrate/default.nix
Normal file
27
packages/xwacomcalibrate/default.nix
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
# Snowfall Lib provides a customized `lib` instance with access to your flake's library
|
||||||
|
# as well as the libraries available from your flake's inputs.
|
||||||
|
lib,
|
||||||
|
# You also have access to your flake's inputs.
|
||||||
|
inputs,
|
||||||
|
|
||||||
|
# All other arguments come from NixPkgs. You can use `pkgs` to pull packages or helpers
|
||||||
|
# programmatically or you may add the named attributes as arguments here.
|
||||||
|
pkgs,
|
||||||
|
stdenv,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
pkgs.writeShellApplication {
|
||||||
|
name = "xwacomcalibrate";
|
||||||
|
|
||||||
|
runtimeInputs = with pkgs; [
|
||||||
|
xf86_input_wacom
|
||||||
|
xorg.xwininfo
|
||||||
|
xorg.xrandr
|
||||||
|
xdotool
|
||||||
|
bc
|
||||||
|
];
|
||||||
|
|
||||||
|
text = ./xwacomcalibrate.sh;
|
||||||
|
}
|
216
packages/xwacomcalibrate/xwacomcalibrate.sh
Executable file
216
packages/xwacomcalibrate/xwacomcalibrate.sh
Executable file
@ -0,0 +1,216 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# https://aur.archlinux.org/packages/xwacomcalibrate
|
||||||
|
|
||||||
|
print_help () {
|
||||||
|
printf "\nUsage: xwacomcalibrate [-h] [-d] [-f [screen]] [-r (cw | half | ccw)]\n\n"
|
||||||
|
printf " h: prints this help\n"
|
||||||
|
printf " d: Uses xdotool to continously run the script\n"
|
||||||
|
printf " f: Uses whole X screen as window size. If xrandr screen name is given, limits itself to that monitor\n"
|
||||||
|
printf " r: Chooses the device rotation. When given, needs either \"cw\" for clockwise, \"half\" for overhead, or \"ccw\" for counterclockwise as an argument\n"
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts ":hdf:r:" opt
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
h )
|
||||||
|
print_help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
d )
|
||||||
|
DAEMON=true
|
||||||
|
;;
|
||||||
|
f ) FULLSCREEN=true
|
||||||
|
if [[ $OPTARG ]]
|
||||||
|
then
|
||||||
|
SCREEN=$OPTARG
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
r ) if [[\
|
||||||
|
$OPTARG == "cw"\
|
||||||
|
|| $OPTARG == "half"\
|
||||||
|
|| $OPTARG == "ccw"\
|
||||||
|
]]
|
||||||
|
then
|
||||||
|
ROTATION=$OPTARG
|
||||||
|
else
|
||||||
|
echo "Invalid rotation: $arg" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
: ) if [[ $OPTARG == "r" ]]
|
||||||
|
then
|
||||||
|
echo 'option requires an argument -- ' $OPTARG 1>&2
|
||||||
|
print_help
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
\? ) print_help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $(( OPTIND -1 ))
|
||||||
|
|
||||||
|
get_dev () {
|
||||||
|
DEV=$(\
|
||||||
|
xsetwacom --list devices\
|
||||||
|
| grep "STYLUS"\
|
||||||
|
| cut -d$'\t' -f 2\
|
||||||
|
| tr -cd [:digit:]
|
||||||
|
)
|
||||||
|
if [[ ! $DEV ]]
|
||||||
|
then
|
||||||
|
echo "no device found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
full_tablet_size () {
|
||||||
|
xsetwacom --set $1 ResetArea
|
||||||
|
TB_X=$( xsetwacom --get $1 Area | cut -d ' ' -f 1)
|
||||||
|
TB_Y=$( xsetwacom --get $1 Area | cut -d ' ' -f 2)
|
||||||
|
TB_WIDTH=$( xsetwacom --get $1 Area | cut -d ' ' -f 3)
|
||||||
|
TB_HEIGHT=$( xsetwacom --get $1 Area | cut -d ' ' -f 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
set_rotation () {
|
||||||
|
if [[ $2 ]]
|
||||||
|
then
|
||||||
|
xsetwacom --set $1 Rotate $2
|
||||||
|
else
|
||||||
|
xsetwacom --set $1 Rotate none
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
set_output () {
|
||||||
|
xsetwacom set $1 MapToOutput "${2}x${3}+${4}+${5}"
|
||||||
|
}
|
||||||
|
|
||||||
|
set_area () {
|
||||||
|
xsetwacom set $1 area "$2" "$3"\
|
||||||
|
$( echo "$4 + $2" | bc )\
|
||||||
|
$( echo "$5 + $3" | bc )
|
||||||
|
}
|
||||||
|
|
||||||
|
get_x_screen_size () {
|
||||||
|
W_X="0"
|
||||||
|
W_Y="0"
|
||||||
|
W_WIDTH=$( xwininfo -root | grep Width | tr -dc [:digit:])
|
||||||
|
W_HEIGHT=$( xwininfo -root | grep Height | tr -dc [:digit:])
|
||||||
|
}
|
||||||
|
|
||||||
|
get_screen_size () {
|
||||||
|
local screen=$( xrandr -q | grep "$1 connected" | cut -d ' ' -f 3 )
|
||||||
|
if [[ ! $screen ]]
|
||||||
|
then
|
||||||
|
echo "couldn't find screen: $1" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ $screen == "primary" ]]
|
||||||
|
then
|
||||||
|
local screen=$( xrandr -q | grep "$1 connected" | cut -d ' ' -f 4 )
|
||||||
|
fi
|
||||||
|
IFS='x+' read -r -a array <<< "$screen"
|
||||||
|
W_WIDTH="${array[0]}"
|
||||||
|
W_HEIGHT="${array[1]}"
|
||||||
|
W_X="${array[2]}"
|
||||||
|
W_Y="${array[3]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_active_window_size () {
|
||||||
|
W_X=$(\
|
||||||
|
xdotool getactivewindow getwindowgeometry --shell\
|
||||||
|
| grep X\
|
||||||
|
| cut -d "=" -f2\
|
||||||
|
)
|
||||||
|
W_Y=$(\
|
||||||
|
xdotool getactivewindow getwindowgeometry --shell\
|
||||||
|
| grep Y\
|
||||||
|
| cut -d "=" -f2\
|
||||||
|
)
|
||||||
|
W_WIDTH=$(\
|
||||||
|
xdotool getactivewindow getwindowgeometry --shell\
|
||||||
|
| grep WIDTH\
|
||||||
|
| cut -d "=" -f2\
|
||||||
|
)
|
||||||
|
W_HEIGHT=$(\
|
||||||
|
xdotool getactivewindow getwindowgeometry --shell\
|
||||||
|
| grep HEIGHT\
|
||||||
|
| cut -d "=" -f2\
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
calculate_new_tablet_size () {
|
||||||
|
|
||||||
|
if [[ $1 == "cw" || $1 == "ccw" ]]
|
||||||
|
then
|
||||||
|
twidth=$3
|
||||||
|
theight=$2
|
||||||
|
else
|
||||||
|
twidth=$2
|
||||||
|
theight=$3
|
||||||
|
fi
|
||||||
|
|
||||||
|
tar=$( echo "scale=16; $twidth / $theight" | bc )
|
||||||
|
war=$( echo "scale=16; $4 / $5" | bc )
|
||||||
|
|
||||||
|
if [[ $( echo "scale=16; $tar <= $war" | bc ) -eq "1" ]]
|
||||||
|
then
|
||||||
|
theight=$( echo "scale=0; $twidth / $war /1" | bc )
|
||||||
|
else
|
||||||
|
twidth=$( echo "scale=0; $theight * $war /1" | bc )
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $1 == "cw" || $1 == "ccw" ]]
|
||||||
|
then
|
||||||
|
tmp=$twidth
|
||||||
|
twidth=$theight
|
||||||
|
theight=$tmp
|
||||||
|
unset tmp
|
||||||
|
fi
|
||||||
|
|
||||||
|
TB_X=$( echo "scale=0; ($TB_WIDTH - $twidth) / 2" | bc )
|
||||||
|
TB_Y=$( echo "scale=0; ($TB_HEIGHT - $theight) / 2" | bc )
|
||||||
|
|
||||||
|
TB_WIDTH=$twidth
|
||||||
|
TB_HEIGHT=$theight
|
||||||
|
}
|
||||||
|
|
||||||
|
main () {
|
||||||
|
get_dev
|
||||||
|
set_rotation "$DEV" "$ROTATION"
|
||||||
|
full_tablet_size "$DEV"
|
||||||
|
if [[ $FULLSCREEN ]]
|
||||||
|
then
|
||||||
|
if [[ $SCREEN ]]
|
||||||
|
then
|
||||||
|
get_screen_size "$SCREEN"
|
||||||
|
else
|
||||||
|
get_x_screen_size
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
get_active_window_size
|
||||||
|
fi
|
||||||
|
calculate_new_tablet_size "$ROTATION"\
|
||||||
|
"$TB_WIDTH" "$TB_HEIGHT"\
|
||||||
|
"$W_WIDTH" "$W_HEIGHT"
|
||||||
|
set_output "$DEV" "$W_WIDTH" "$W_HEIGHT" "$W_X" "$W_Y"
|
||||||
|
set_area "$DEV" "$TB_X" "$TB_Y" "$TB_WIDTH" "$TB_HEIGHT"
|
||||||
|
echo "${W_WIDTH}x${W_HEIGHT}+${W_X}+${W_Y} \
|
||||||
|
${TB_WIDTH}x${TB_HEIGHT}+${TB_X}+${TB_Y} $ROTATIONATION"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $DAEMON ]]
|
||||||
|
then
|
||||||
|
main
|
||||||
|
xdotool search . behave %@ focus exec --sync\
|
||||||
|
$(\
|
||||||
|
echo 'xwacomcalibrate '\
|
||||||
|
$( if [[ $ROTATION ]]; then echo '-r ' $ROTATION ; fi )\
|
||||||
|
$( if [[ $FULLSCREEN ]]; then echo '-f'; fi )\
|
||||||
|
)
|
||||||
|
else
|
||||||
|
main
|
||||||
|
fi
|
@ -117,6 +117,8 @@
|
|||||||
services.xserver.windowManager.i3.enable = true;
|
services.xserver.windowManager.i3.enable = true;
|
||||||
services.xserver.windowManager.i3.package = pkgs.i3-gaps;
|
services.xserver.windowManager.i3.package = pkgs.i3-gaps;
|
||||||
|
|
||||||
|
services.xserver.wacom.enable = true;
|
||||||
|
|
||||||
services.blueman.enable = true;
|
services.blueman.enable = true;
|
||||||
services.upower.enable = true;
|
services.upower.enable = true;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user