~smlavine/scripts

ref: 5baff32f611b2013046beab575d024dee6a3f0a2 scripts/src/touch-menu -rwxr-xr-x 1.7 KiB
5baff32fSebastian LaVine Remove 'extract' 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# Copyright (c) 2021 Sebastian LaVine <mail@smlavine.com>
# Licensed under the GPLv3. See GPLv3.txt for details.
#
# File:        touch-menu
# Description: Provide a menu to perform common activites without needing to
#              input commands with a keyboard. This is useful in mouse-only
#              environments, such as when the keyboard is unavailable in a
#              laptop with tablet capabilities like the Thinkpad X220 Tablet.

quit_a_program()
{
	ps --sort +etime o pid,tty,etime,comm |
		dmenu -i -c -l 30 -sb 'dark blue' -p 'Which one?' |
		awk '{ print $1 }' |
		xargs kill
}

rotate_screen()
{
	way="$(dmenu -c -i -l 5 -fn 'monospace:size=50' -p 'Which way?' |
		tr '[:upper:]' '[:lower:]')"
	case "$way" in
		left)     matrix="0 -1 1 1 0 0 0 0 1"  ;;
		right)    matrix="0 1 0 -1 0 1 0 0 1"  ;;
		inverted) matrix="-1 0 1 0 -1 1 0 0 1" ;;
		normal)   matrix="1 0 0 0 1 0 0 0 1"   ;;
		*)   exit 0 ;;
	esac

	xrandr -o "$way" || exit $?

	# Without this command, the touch screen inputs do not match up with
	# the new orientation of the screen.
	xinput --set-prop 'Wacom ISDv4 E6 Pen Pen (0)' \
		'Coordinate Transformation Matrix' $matrix
}

main()
{
	item="$(dmenu -c -i -l 20 -fn 'monospace:size=50' \
		-p 'What to do?')"
	[ "$item" = "*Cancel*" ] && exit 0
	case "$item" in
		'Rotate Screen')
			rotate_screen <<- EOF
			Left
			Right
			Inverted
			Normal
			*Cancel*
			EOF
			;;
		'Quit a Program')
			quit_a_program
			;;
		*)
			# Execute the item as a shell command. There are
			# deliberately no quotes here to parse options and
			# arguments properly.
			$item
			;;
	esac
}

main << EOF
Rotate Screen
xournalpp
svkbd-en -d
pithos
pavucontrol
Quit a Program
*Cancel*
EOF