-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename-workspace
executable file
·49 lines (35 loc) · 1.29 KB
/
rename-workspace
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
#!/usr/bin/env python3
import json
import subprocess
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk # noqa: E402
# TODO(PM): Handle multiple workspaces in focus
def get_focused_workspace_num():
"""Return the number of the first workspace that is in focus"""
workspaces = subprocess.check_output(['i3-msg', '-t', 'get_workspaces'])
workspaces = json.loads(workspaces)
for workspace in workspaces:
if workspace['focused']:
return (workspace['num'], workspace['name'])
raise RuntimeError("No workspaces are in focus")
def update_focused_workspace_name(entry):
num, old_name = get_focused_workspace_num()
cmd = f'rename workspace "{old_name}" to "{num}: {entry.get_text()}"'
subprocess.check_output(['i3-msg', cmd])
# TODO(PM): Correct way to exit here?
Gtk.main_quit()
def main():
window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
window.set_title('Rename workspace')
window.set_modal(True)
window.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
window.connect('destroy', Gtk.main_quit)
entry = Gtk.Entry()
entry.connect('activate', update_focused_workspace_name)
# TODO(PM): Exit on escape key
window.add(entry)
window.show_all()
Gtk.main()
if __name__ == '__main__':
main()