Skip to content

Commit

Permalink
Merge pull request #10 from f0s3/latest
Browse files Browse the repository at this point in the history
Add switching to layout from config when program is launched.
  • Loading branch information
f0s3 authored Oct 31, 2018
2 parents 9d30c99 + b87231c commit 8b85454
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions keymap.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os, time, json
import os, time, json, psutil
import subprocess as sp

previousWorkspace = 1
currentWorkspace = 1
appLaunched = False
layoutOrder = {}

def shell(cmd):
Expand All @@ -15,11 +16,24 @@ def shell(cmd):
with open("./config/config.json", "r+") as f:
config = eval(f.read())

def programIsRunning(programName):
for process in psutil.process_iter():
if process.name() == programName:
return True
return False

while True:
currentWorkspace = [i["num"] for i in json.loads(shell("i3-msg -t get_workspaces")) if i["focused"]][0]
for program in config["programs"]:
if programIsRunning(list(program.keys())[0]):
os.system("xkblayout-state set {}".format(layoutOrder[list(filter(lambda x: list(program.keys())[0] in x, config["programs"]))[0][list(program.keys())[0]]]))
appLaunched = True
elif appLaunched:
appLaunched = False
currentWorkspace = currentWorkspace + 1
if currentWorkspace == previousWorkspace:
currentLayout = shell("xkblayout-state print %s")
if currentLayout != config["workspaces"][currentWorkspace]: config["workspaces"][currentWorkspace][currentWorkspace] = currentLayout
if currentLayout != config["workspaces"][currentWorkspace][currentWorkspace]: config["workspaces"][currentWorkspace][currentWorkspace] = currentLayout
else:
if shell("xkblayout-state print %s") != config["workspaces"][currentWorkspace][currentWorkspace]:
os.system("xkblayout-state set {}".format(layoutOrder[config["workspaces"][currentWorkspace][currentWorkspace]]))
Expand Down

0 comments on commit 8b85454

Please sign in to comment.