Compare commits

...

3 Commits

4 changed files with 262 additions and 19 deletions

View File

@ -7,7 +7,6 @@ with pkgs;
# Further tools
lazygit
languagetool
# makemkv
audacity
@ -23,12 +22,12 @@ with pkgs;
hexedit
# rfid reader tests
openct
opensc
pcsclite
pcsctools
ccid
libnfc
# openct
# opensc
# pcsclite
# pcsctools
# ccid
# libnfc
xournalpp
@ -42,7 +41,7 @@ with pkgs;
libqalculate
# schildichat-desktop # not updated regularly
element-desktop
# element-desktop
tdesktop # telegram
tealdeer
@ -53,10 +52,10 @@ with pkgs;
git
dotter
mc
broot
# broot
rnr # renaming tool in rust
doublecmd
mucommander
# doublecmd
# mucommander
tree
wezterm
kitty
@ -67,10 +66,9 @@ with pkgs;
topgrade
arandr
# wireguard-tools
htop
texlive.combined.scheme-full
texlab
# texlive.combined.scheme-full
# texlab
usbutils # lsusb
pciutils # lspci
@ -104,7 +102,7 @@ with pkgs;
ffmpeg
links2
julia-bin
xdg-desktop-portal-gtk
# xdg-desktop-portal-gtk
discord
lnav # log analyzing tool
fdupes # find and delete duplicate files
@ -114,10 +112,7 @@ with pkgs;
nomacs
rocketchat-desktop
# zotero
inkscape
pulseaudio
gcolor3
geogebra
languagetool
@ -128,7 +123,7 @@ with pkgs;
poppler_utils # Pdf utils including pdfimages
matlab # Using nix-matlab overlay defined in flake
# sage
sage
gimp
@ -156,6 +151,7 @@ with pkgs;
## My scripts
frajul.edit-config
frajul.xwacomcalibrate
nheko
conda

View 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;
}

View 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

View File

@ -55,6 +55,8 @@
"cifs"
];
boot.blacklistedKernelModules = [ "pcspkr" ]; # Disables "beep"
networking.hostName = "aspi";
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
networking.networkmanager.enable = true;
@ -117,6 +119,8 @@
services.xserver.windowManager.i3.enable = true;
services.xserver.windowManager.i3.package = pkgs.i3-gaps;
services.xserver.wacom.enable = true;
services.blueman.enable = true;
services.upower.enable = true;