aboutsummaryrefslogtreecommitdiffstats
path: root/ui/razer-gamewrapper
blob: 98a535ada2c75f345e2d14c117464065429edf40 (plain)
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
#!/bin/sh

[ -n "$RAZER_MOUSE_DEV" ] || RAZER_MOUSE_DEV=mouse
[ -n "$RAZER_MOUSE_GAMINGPROF" ] || RAZER_MOUSE_GAMINGPROF=5

usage()
{
	echo "Usage razer-gamewrapper GAME [GAME-OPTIONS]"
	echo
	echo "Arguments:"
	echo "  GAME is the game binary to execute"
	echo "  GAME-OPTIONS are optional options to the game"
	echo
	echo "Environment variables:"
	echo "  RAZER_MOUSE_DEV           The id-string of the mouse."
	echo "                            Defaults to the first razer mouse."
	echo "  RAZER_MOUSE_GAMINGPROF    The profile ID of the gaming profile."
	echo "                            Defaults to '5'."
}

message()
{
	echo "razer-gamewrapper: $*"
}

die()
{
	message "$*"
	cleanup
	exit 1
}

cleanup()
{
	[ -n "$oldprof" ] && {
		razercfg -d "$RAZER_MOUSE_DEV" -p "$oldprof" || die "Failed to reset mouse profile"
	}
}

terminate()
{
	cleanup
	exit 1
}

oldprof=

[ "$#" -eq 0 -o "$1" = "-h" -o "$1" = "--help" ] && { usage; terminate; }
oldprof="$(razercfg -d "$RAZER_MOUSE_DEV" -P | awk '{print $3;}')"
[ -n "$oldprof" ] || die "Failed to get current mouse profile"
trap terminate INT TERM
message "Old mouse profile: $oldprof"
message "Switching to gaming profile: $RAZER_MOUSE_GAMINGPROF"
razercfg -d "$RAZER_MOUSE_DEV" -p "$RAZER_MOUSE_GAMINGPROF" || die "Failed to set mouse gaming profile"
message "Starting game: $*"
$@ || die "Failed to start the game"
message "Switching to old profile: $oldprof"
cleanup

exit 0
bues.ch cgit interface