-
Notifications
You must be signed in to change notification settings - Fork 0
/
chromium_refresh_on_workspace_change.py
73 lines (63 loc) · 2.09 KB
/
chromium_refresh_on_workspace_change.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
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
import subprocess
import keyboard
import time
from time import sleep
from chromote import Chromote
import select
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--workspace', type=int)
args = parser.parse_args()
if(getattr(args,'workspace') == None):
event_triggered_on_this_workspace = 2
else:
event_triggered_on_this_workspace = getattr(args,'workspace')
chrome = Chromote()
tab = chrome.tabs[0]
previous_workspace = 0
def get_res():
# get resolution
xr = subprocess.check_output(["xrandr"]).decode("utf-8").split()
pos = xr.index("current")
return [int(xr[pos+1]), int(xr[pos+3].replace(",", "") )]
def current_workspace():
# get the resolution (viewport size)
res = get_res()
# read wmctrl -d
vp_data = subprocess.check_output(
["wmctrl", "-d"]
).decode("utf-8").split()
# get the size of the spanning workspace (all viewports)
dt = [int(n) for n in vp_data[3].split("x")]
# calculate the number of columns
cols = int(dt[0]/res[0])
# calculate the number of rows
rows = int(dt[1]/res[1])
# get the current position in the spanning workspace
curr_vpdata = [int(n) for n in vp_data[5].split(",")]
# current column (readable format)
curr_col = int(curr_vpdata[0]/res[0])
# current row (readable format)
curr_row = int(curr_vpdata[1]/res[1])
# calculate the current viewport
return curr_col+curr_row*cols+1;
#print(current())
def refresh_browser():
#if current() == 2:
tab.reload()
f = subprocess.Popen('dbus-monitor',stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
p = select.poll()
p.register(f.stdout)
while True:
line = f.stdout.readline()
#if p.poll(1):
#print("a")
#print(line)
if b'member=ActiveWindow' in line:
workspace = current_workspace()
if previous_workspace != workspace:
if workspace == event_triggered_on_this_workspace:
refresh_browser()
previous_workspace = workspace
#chromium-browser --remote-debugging-port=9222