aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmacropad.pyw4
-rwxr-xr-xwin32.py3
-rw-r--r--xlib.py9
3 files changed, 12 insertions, 4 deletions
diff --git a/macropad.pyw b/macropad.pyw
index 2687065..55bb1cf 100755
--- a/macropad.pyw
+++ b/macropad.pyw
@@ -25,8 +25,10 @@ config_file = path.join(script_path, "config.ini")
config = configparser.ConfigParser(delimiters="=")
config.read(config_file)
+from collections import OrderedDict
+
init_mapping = config["mapping"]
-mapping = dict(init_mapping)
+mapping = OrderedDict(init_mapping)
from queue import Queue
q = Queue()
diff --git a/win32.py b/win32.py
index bff980b..ee146e6 100755
--- a/win32.py
+++ b/win32.py
@@ -87,10 +87,11 @@ class Listener(object):
if title.value is None:
return
title = str(title.value).lower()
- for pattern, code in self.mapping.items():
+ for pattern in reversed(self.mapping):
if pattern == "default":
continue
if pattern in title:
+ code = self.mapping[pattern]
self.queue.put ( (code, None) )
return
default = self.mapping.get("default", None)
diff --git a/xlib.py b/xlib.py
index bc2032c..4577e96 100644
--- a/xlib.py
+++ b/xlib.py
@@ -54,12 +54,17 @@ class Listener(Thread):
self.active_window = window_name
found = False
- for pattern, code in self.mapping.items():
+
+ # Create a reveverse dictionnary for getting the users added first
+ # In python, the elements in a dictionnary are sorted by insertion
+ # order, so we get the user added first here
+ for pattern in reversed(self.mapping):
# Ignore the default layout
if pattern == "default":
continue
- if not (pattern in window_name or pattern in class_name):
+ if not (pattern.lstrip() in window_name or pattern.lstrip() in class_name):
continue
+ code = self.mapping[pattern]
# We found something. At this point, even if we do not update
# the layer (because it is the same as the previous) we do not
# switch back to the default layer.