aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Miller <nwg.piotr@gmail.com>2021-11-25 11:55:00 +0100
committerPiotr Miller <nwg.piotr@gmail.com>2021-11-25 11:55:00 +0100
commitea3caa81818e06ac88712443571fc79a5080e39a (patch)
treee190cefe0d12c91e706032a6235e116f96fd3530
parent2aeab6cfbd0ba86f80f824e42088d5473a9e6a58 (diff)
downloadautotiling-ea3caa81818e06ac88712443571fc79a5080e39a.tar.gz
allow specifying events; version bump
-rw-r--r--autotiling/main.py36
-rw-r--r--setup.cfg4
2 files changed, 30 insertions, 10 deletions
diff --git a/autotiling/main.py b/autotiling/main.py
index dc237a2..b7cc75e 100644
--- a/autotiling/main.py
+++ b/autotiling/main.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
"""
This script uses the i3ipc python module to switch the layout splith / splitv
for the currently focused window, depending on its dimensions.
@@ -62,8 +64,7 @@ def switch_splitting(i3, e, debug, workspaces):
is_stacked = con.parent.layout == "stacked"
is_tabbed = con.parent.layout == "tabbed"
- # Let's exclude floating containers, stacked layouts, tabbed layouts and
- # full screen mode
+ # Exclude floating containers, stacked layouts, tabbed layouts and full screen mode
if (not is_floating
and not is_stacked
and not is_tabbed
@@ -89,7 +90,7 @@ def main():
parser.add_argument("-d",
"--debug",
action="store_true",
- help="Print debug messages to stderr")
+ help="print debug messages to stderr")
parser.add_argument("-v",
"--version",
action="version",
@@ -97,24 +98,43 @@ def main():
help="display version information", )
parser.add_argument("-w",
"--workspaces",
- help="Restricts autotiling to certain workspaces. Example: autotiling --workspaces 8 9",
+ help="restricts autotiling to certain workspaces. Example: autotiling --workspaces 8 9",
+ nargs="*",
+ type=str,
+ default=[], )
+ """
+ Changing event subscription has already been the objective of several pull request. To avoid doing this again
+ and again, let's allow to specify them in the `--events` argument.
+ """
+ parser.add_argument("-e",
+ "--events",
+ help="list of events to trigger switching split orientation; Default: WINDOW MODE",
nargs="*",
type=str,
- default=[],)
+ default=["WINDOW", "MODE"])
args = parser.parse_args()
if args.debug and args.workspaces:
print("autotiling is only active on workspaces:", ','.join(args.workspaces))
-
+
# For use w/ nwg-panel
if args.workspaces:
save_string(','.join(args.workspaces), os.path.join(temp_dir(), "autotiling"))
+ if not args.events:
+ print("No events specified", file=sys.stderr)
+ sys.exit(1)
+
handler = partial(switch_splitting, debug=args.debug, workspaces=args.workspaces)
i3 = Connection()
- i3.on(Event.WINDOW, handler)
- i3.on(Event.MODE, handler)
+ for e in args.events:
+ try:
+ i3.on(Event[e], handler)
+ print("{} subscribed".format(Event[e]))
+ except KeyError:
+ print("'{}' is not a valid event".format(e), file=sys.stderr)
+
i3.main()
diff --git a/setup.cfg b/setup.cfg
index e67767f..52b9747 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,9 +1,9 @@
[metadata]
name = autotiling
-version = 1.5
+version = 1.6
author = Piotr Miller
author_email = nwg.piotr@gmail.com
-description = Automatically switch the horizontal/vertical window split orientation in i3 and sway
+description = Automatically switch the horizontal/vertical window split orientation in sway and i3
url = https://github.com/nwg-piotr/autotiling
project_urls =
Code=https://github.com/nwg-piotr/autotiling