From 6763a95610c80334b7bf0ddfd3a2da2c9ba37a04 Mon Sep 17 00:00:00 2001
From: Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz>
Date: Sun, 14 Aug 2022 21:31:07 +0200
Subject: [PATCH] Wrappers: Exec: Set button and modifiers

---
 Wrappers.cs | 29 +++++++++++++++++++++++++++--
 sample.conf |  5 +++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/Wrappers.cs b/Wrappers.cs
index 443994a..e24681f 100644
--- a/Wrappers.cs
+++ b/Wrappers.cs
@@ -40,8 +40,33 @@ abstract partial class StatusBar
 		if(section.Contains("_color"))
 			module  = new WrapperColor(module, section.Mandatory("_color").AsColor());
 
-		if(section.Contains("_exec"))
-			module  = new WrapperExec(module, section.Mandatory("_exec").AsString(), MouseButton.Left, 0);
+		foreach(var opt in section)
+		{
+			MouseButton? button = null;
+			Modifiers modifiers = 0;
+			if(opt.KeyAsValue().Tokens()[0] == "_exec")
+			{
+				opt.Use();
+				foreach(var t in opt.KeyAsValue().Tokens()[1..])
+				{
+					void setButton(MouseButton _button)
+					{
+						if(button != null)
+							throw new ConfigMistake(t, "Duplicit button definition.");
+						button = _button;
+					}
+					if(t=="left") setButton(MouseButton.Left); else
+					if(t=="right") setButton(MouseButton.Right); else
+					if(t=="middle") setButton(MouseButton.Middle); else
+					if(t=="ctrl" || t=="control") modifiers |= Modifiers.Control; else
+					if(t=="shift") modifiers |= Modifiers.Shift; else
+					if(t=="alt") modifiers |= Modifiers.Alt; else
+					if(t=="super" || t=="win" || t=="windows") modifiers |= Modifiers.Super; else
+						throw new ConfigMistake(t, $"No such modifiers or mouse key \"{t.AsString()}\".");
+				}
+				module  = new WrapperExec(module, opt.AsString(), button ?? MouseButton.Left, modifiers);
+			}
+		}
 
 		module.Init(parrent, section);
 		return module;
diff --git a/sample.conf b/sample.conf
index 5549686..4e9906b 100644
--- a/sample.conf
+++ b/sample.conf
@@ -306,6 +306,11 @@ _default_color = red
 # <color>
 # Set color if module don't set any
 
+#exec [KEY (left (default)/right/middle)] [MODIFIERS (shift/ctlr/alt/super) ...]
+_exec right super shift = osdc "Super+Shift+Right pressed"
+# <string>
+# Command to run
+
 
 # Parsers:
 # ========
-- 
GitLab