mirror of
https://github.com/AquaMorph/dotfiles.git
synced 2025-04-29 17:25:34 +00:00
Move Firefox windows to proper workspaces
This commit is contained in:
parent
650d747791
commit
1f44801edb
61
scripts/start-firefox.py
Normal file
61
scripts/start-firefox.py
Normal file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from i3ipc import Connection, Event
|
||||
import os
|
||||
|
||||
# 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
|
||||
|
||||
# launchProgram() launches a program on a given workspace.
|
||||
def launchProgram(program, workspace):
|
||||
i3.command('workspace ' + workspace + '; exec ' + program)
|
||||
|
||||
# isProgramRunning() returns if a program is running and if it is
|
||||
# moves it to a given workspace.
|
||||
def isProgramRunning(name, windows, workspace):
|
||||
program = getWindowByName(name, windows)
|
||||
if doesWindowExist(program):
|
||||
moveWindowToWorkspace(program, workspace)
|
||||
return True
|
||||
return False
|
||||
|
||||
i3 = Connection()
|
||||
firefoxWindows = filterWindowsByClass('Firefox', getWindows(i3))
|
||||
|
||||
# Music
|
||||
if not isProgramRunning('YouTube Music', firefoxWindows, '10'):
|
||||
launchProgram('exec firefox --new-window music.youtube.com', '10')
|
||||
|
||||
# Stocks
|
||||
if not isProgramRunning('Robinhood', firefoxWindows, '10'):
|
||||
os.system('python ~/.config/scripts/launch-stocks-tracker.py')
|
||||
|
||||
|
||||
# YouTube
|
||||
if not isProgramRunning('Subscriptions - YouTube', firefoxWindows, '10'):
|
||||
launchProgram('firefox --new-window youtube.com/feed/subscriptions', '10')
|
||||
|
@ -27,9 +27,7 @@ function launchi3() {
|
||||
if [ -z "$skipi3" ]; then
|
||||
echo Opening i3wm sound workspaces
|
||||
sleep .1 && i3-msg 'workspace 5; exec firefox'
|
||||
sleep .1 && i3-msg 'workspace 10; exec firefox --new-window music.youtube.com'
|
||||
sleep .1 && python python ~/.config/scripts/launch-stocks-tracker.py
|
||||
sleep .1 && i3-msg 'workspace 10; exec firefox --new-window youtube.com/feed/subscriptions'
|
||||
sleep .1 && python ~/.config/scripts/start-firefox.py
|
||||
fi
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user