-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
76 lines (65 loc) · 1.76 KB
/
common.py
File metadata and controls
76 lines (65 loc) · 1.76 KB
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
74
75
76
from platform import system
from threading import Event, Lock, Thread
import json
import re
toggleActions = {}
regexToAppName = {}
keyReleaseEvents = {}
titleMatchToConfigFile = {}
prefixToFunc = {}
toggle = False
layer = 0
toggleThread = Lock()
showGUI = Event()
winTitleSplitter = re.compile(u'[\u2014\-\*]')
layerApp = ""
kill = False
isEditing = False
toggleKey = None
toRemap = []
disabledApps = []
WIDGET_HEIGHT = 0
WIDGET_WIDTH = 0
doRemapping = True
redrawGui = False
disableGUI = False
updateBGInterval = 0
layout = None
drawGUI = True
windowTitle = ""
if system() == 'Windows':
import win32gui
def getWindowName() -> str:
if showGUI.isSet():
return windowTitle
return win32gui.GetWindowText(win32gui.GetForegroundWindow())
elif system() == 'Linux':
def getWindowName() -> str:
print("TODO IMPLEMENT LINUX")
def getAppName():
winName = getWindowName()
win32gui.GetDesktopWindow
return re.split(winTitleSplitter, winName).pop().strip()
def getTitleMatch():
winName = getWindowName()
titleMatch = None
appName = re.split(winTitleSplitter, winName).pop().strip()
if not appName in titleMatchToConfigFile:
maxPriority = None
for ptrn, (title, priority) in regexToAppName.items():
if re.search(ptrn, winName) and (maxPriority is None or maxPriority < priority):
titleMatch = title
maxPriority = priority
else:
titleMatch = appName
if titleMatch is None:
titleMatch = "Default"
return titleMatch
def getLayer(titleMatch = None):
global layer, layerApp
if titleMatch is None:
titleMatch = getTitleMatch()
if titleMatch != layerApp:
layer = 0
layerApp = titleMatch
return layer