2023-08-20 11:21:03 +05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-08-20 11:32:38 +05:00
|
|
|
if [[ $XDG_SESSION_TYPE != "x11" ]]; then
|
2023-08-20 12:01:56 +05:00
|
|
|
echo "Unsupported session type: $XDG_SESSION_TYPE"
|
|
|
|
exit 1
|
2023-08-20 11:32:38 +05:00
|
|
|
fi
|
|
|
|
|
2023-08-20 11:21:03 +05:00
|
|
|
get_tg_window_id(){
|
2023-08-20 12:00:53 +05:00
|
|
|
tg_window_id=$(wmctrl -lx | grep telegram-desktop | awk '{print $1}')
|
2023-08-20 11:21:03 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
get_mouse_location(){
|
2023-08-20 12:00:53 +05:00
|
|
|
mouse_xy=$(xdotool getmouselocation --shell)
|
|
|
|
mouse_x=$(printf "%s\n" "$mouse_xy" | grep X= | cut -d= -f2)
|
|
|
|
mouse_y=$(printf "%s\n" "$mouse_xy" | grep Y= | cut -d= -f2)
|
2023-08-20 11:21:03 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
return_mouse(){
|
2023-08-20 12:00:53 +05:00
|
|
|
xdotool mousemove $mouse_x $mouse_y
|
|
|
|
}
|
|
|
|
|
|
|
|
lock_tg(){
|
|
|
|
xdotool windowactivate --sync $tg_window_id key ctrl+l
|
|
|
|
}
|
|
|
|
|
|
|
|
readpin(){
|
2023-08-20 12:15:35 +05:00
|
|
|
if [[ ! -f ~/.local/.tgpin.txt ]]; then
|
|
|
|
echo "Error: PIN file not found!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-08-20 12:00:53 +05:00
|
|
|
tgpin=$(cat ~/.local/.tgpin.txt)
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock_tg(){
|
|
|
|
xdotool windowactivate --sync $tg_window_id key $tgpin Return
|
2023-08-20 11:21:03 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$1" == "lock" ]; then
|
2023-08-20 12:00:53 +05:00
|
|
|
get_tg_window_id
|
|
|
|
get_mouse_location
|
|
|
|
lock_tg
|
|
|
|
return_mouse
|
2023-08-20 11:21:03 +05:00
|
|
|
elif [ "$1" == "unlock" ]; then
|
2023-08-20 12:15:35 +05:00
|
|
|
readpin
|
2023-08-20 12:00:53 +05:00
|
|
|
get_tg_window_id
|
|
|
|
get_mouse_location
|
|
|
|
unlock_tg
|
|
|
|
return_mouse
|
2023-08-20 11:21:03 +05:00
|
|
|
else
|
2023-08-20 12:01:56 +05:00
|
|
|
echo "Invalid argument. Please use 'lock' or 'unlock'."
|
|
|
|
exit 1
|
2023-08-20 11:21:03 +05:00
|
|
|
fi
|