-
Notifications
You must be signed in to change notification settings - Fork 2
/
swap_alt_win
executable file
·69 lines (52 loc) · 1.93 KB
/
swap_alt_win
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
#!/usr/bin/env python3
import subprocess
import sys
import json
import argparse
ALTWIN_OPTION = "altwin:swap_alt_win"
def xgb_options_cmd(option, args):
return f"gsettings {option} org.gnome.desktop.input-sources xkb-options {args}"
def xgb_options_get():
return xgb_options_cmd("get", "")
def xgb_options_set(args):
return xgb_options_cmd("set", f"\"{args}\"")
def toggle(existing_values):
if ALTWIN_OPTION in existing_values:
existing_values.remove(ALTWIN_OPTION)
else:
existing_values.append(ALTWIN_OPTION)
return existing_values
def on(existing_values):
if ALTWIN_OPTION not in existing_values:
existing_values.append(ALTWIN_OPTION)
return existing_values
def off(existing_values):
if ALTWIN_OPTION in existing_values:
existing_values.remove(ALTWIN_OPTION)
return existing_values
def status(existing_values):
if ALTWIN_OPTION in existing_values:
print("swap_alt_win: on")
else:
print("swap_alt_win: off")
def run(args):
output = subprocess.run(xgb_options_get(), shell=True, capture_output=True)
existing_values = json.loads(output.stdout.decode().replace('\'', '"'))
if args.altwin == "status":
status(existing_values)
return
if args.altwin == "toggle":
updated_values = toggle(existing_values)
elif args.altwin == "on":
updated_values = on(existing_values)
elif args.altwin == "off":
updated_values = off(existing_values)
else:
raise ValueError(f"Unsupported argument {sys.argv}")
subprocess.run(xgb_options_set(updated_values), shell=True)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--altwin', type=str, default="toggle", help="Argument for altwin setting")
parser.add_argument('--verbose', action='store_true', help="Show verbose results")
args = parser.parse_args()
run(args)