mirror of
https://github.com/AquaMorph/dotfiles.git
synced 2025-04-29 09:15:34 +00:00
86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
|
|
from i3ipc import Connection, Event
|
|
import os, time
|
|
|
|
# moveWindowToWorkspace() moves a given window to a given workspace.
|
|
def moveWindowToWorkspace(window, workspace):
|
|
window.command('move window to workspace ' + workspace)
|
|
|
|
# getWindows() returns a list of all open windows on the desktop.
|
|
def getWindows(i3):
|
|
windows = []
|
|
for con in i3.get_tree():
|
|
if con.window and con.parent.type != 'dockarea':
|
|
windows.append(con)
|
|
return windows
|
|
|
|
# getWindowByName() returns a window with the given name.
|
|
def getWindowByName(name, windows):
|
|
for win in windows:
|
|
if name in win.name:
|
|
return win
|
|
return
|
|
|
|
# filterWindowsByClass() returns a filter list of windows by class.
|
|
def filterWindowsByClass(windowClass, windows):
|
|
return [w for w in windows if w.window_class == windowClass]
|
|
|
|
# doesWindowExist() returns if a given window exists.
|
|
def doesWindowExist(window):
|
|
return window != None
|
|
|
|
# switchWorkspace() switches currently selected workspace.
|
|
def switchWorkspace(workspace):
|
|
i3.command('workspace ' + workspace)
|
|
|
|
# execI3() runs a command from i3wm.
|
|
def execI3(program):
|
|
i3.command('exec ' + program)
|
|
|
|
# launchProgram() launches a program on a given workspace.
|
|
def launchProgram(program, workspace):
|
|
switchWorkspace(workspace)
|
|
execI3(program)
|
|
|
|
# isProgramRunning() returns if a program is running and if it is
|
|
# moves it to a given workspace.
|
|
def isProgramRunning(name, windows, workspace):
|
|
for n in name:
|
|
program = getWindowByName(n, windows)
|
|
if doesWindowExist(program):
|
|
moveWindowToWorkspace(program, workspace)
|
|
return True
|
|
return False
|
|
|
|
|
|
def isPagesLoaded(windows):
|
|
for w in windows:
|
|
if 'http' not in w.name:
|
|
return True
|
|
return True
|
|
i3 = Connection()
|
|
windows = filterWindowsByClass('librewolf-default', getWindows(i3))
|
|
|
|
while(not isPagesLoaded(windows)):
|
|
time.sleep(0.1)
|
|
|
|
switchWorkspace('10')
|
|
switchWorkspace('1')
|
|
|
|
# Music
|
|
if not isProgramRunning(['music.youtube.com'], windows, '10'):
|
|
launchProgram('librewolf --new-window music.youtube.com', '10')
|
|
|
|
# Stocks
|
|
if not isProgramRunning(['Robinhood', 'Webull'], windows, '10'):
|
|
os.system('python ~/bin/launch-stocks-tracker.py')
|
|
|
|
# Videos
|
|
if not isProgramRunning(['odysee.com', 'lbry.tv', 'www.youtube.com',
|
|
' - YouTube', 'hulu.com', 'netflix.com',
|
|
'disneyplus.com', 'tv.youtube.com'],
|
|
windows, '10'):
|
|
launchProgram('librewolf --new-window youtube.com/feed/subscriptions', '10')
|
|
launchProgram('sleep 1 && librewolf -new-tab odysee.com/$/following', '10')
|