This repository has been archived by the owner on May 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwm.py
62 lines (34 loc) · 1.65 KB
/
wm.py
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
import os
import subprocess as sp
tmp_dir = os.path.join(os.environ.get('XDG_RUNTIME_DIR', '/tmp'), 'qoverview')
def get_window_ids(workspace):
out = sp.check_output("wmctrl -l | awk '($2 != \"-1\") && ($2 == \"%s\") { print $1 }'" % workspace, shell=True)
out = out.decode('utf-8')
return [x.strip() for x in out.split('\n')][:-1] # :-1 removes last element (which will be empty) from list
def get_window_name(win_id):
out = sp.check_output("wmctrl -l | grep %s | awk '{$1=\"\"; $2=\"\";$3=\"\"; print $0}' | sed 's/^ //g'" % win_id, shell=True)
return out.decode('utf-8').rstrip()
def close(win_id):
sp.Popen(['xdotool', 'windowclose', win_id]).wait()
def activate(win_id):
sp.Popen(['xdotool', 'windowactivate', win_id])
def get_num_workspaces():
out = sp.check_output(['xdotool', 'get_num_desktops'])
return int(out.decode('utf-8').rstrip())
def switch_workspace(workspace_num):
sp.Popen(['xdotool', 'set_desktop', str(workspace_num)])
def get_current_workspace():
try:
res = int(sp.check_output(['xdotool', 'get_desktop']).decode('utf-8').rstrip())
except sp.CalledProcessError:
res = 0
return res
def get_window_screenshot(win_id, filename):
sp.Popen(['import', '-quiet', '-window', win_id, os.path.join(tmp_dir, filename + '.png')]).wait()
return os.path.join(tmp_dir, filename + '.png')
def move_to_workspace(workspace, w_id):
sp.Popen(['xdotool', 'set_desktop_for_window', w_id, str(workspace)]).wait()
def get_focused_window():
return hex(int(sp.check_output(['xdotool', 'getactivewindow']).decode('utf-8').strip()))
def set_window_title(window, title):
sp.Popen(['xdotool', 'set_window', '--name', title, window]).wait()