aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2020-06-16 01:15:33 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2020-06-16 17:18:29 +0200
commit74f0423c087760873c57ce6fb02cbda94a11215d (patch)
tree8796cd8f9491219d8cd6e216a4441625f501e3b8 /contrib
parent751760287c15e511ed4a9cd4f977e27673f07cb6 (diff)
downloadriver-74f0423c087760873c57ce6fb02cbda94a11215d.tar.gz
river-74f0423c087760873c57ce6fb02cbda94a11215d.tar.xz
contrib: add tiled layout in python
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/tiled.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/contrib/tiled.py b/contrib/tiled.py
new file mode 100755
index 0000000..2bec975
--- /dev/null
+++ b/contrib/tiled.py
@@ -0,0 +1,68 @@
+#!/bin/env python
+
+from sys import argv
+
+# This is an implementation of the default "tiled" layout of dwm
+#
+# With 4 views and one master, the layout looks something like this:
+#
+# +-----------------------+------------+
+# | | |
+# | | |
+# | | |
+# | +------------+
+# | | |
+# | | |
+# | | |
+# | +------------+
+# | | |
+# | | |
+# | | |
+# +-----------------------+------------+
+
+# Assign the arguments to variables. The order and meaning of the arguments
+# is explained in the river-layouts(7) man page
+num_views = int(argv[1])
+master_count = int(argv[2])
+master_factor = float(argv[3])
+output_width = int(argv[4])
+output_height = int(argv[5])
+
+secondary_count = num_views - master_count
+
+# handle the cases where there are no master or no secondary views
+master_width = 0
+secondary_width = 0
+if master_count > 0 and secondary_count > 0:
+ master_width = int(master_factor * output_width)
+ secondary_width = output_width - master_width
+elif master_count > 0:
+ master_width = output_width
+elif secondary_count > 0:
+ secondary_width = output_width
+
+
+# for each view, output the location/dimensions separated by spaces on a new line
+for i in range(num_views):
+ if i < master_count:
+ # to make things pixel-perfect, we make the first master and first secondary
+ # view slightly larger if the height is not evenly divisible
+ master_height = output_height // master_count
+ master_height_rem = output_height % master_count
+
+ x = 0
+ y = i * master_height + (master_height_rem if i > 0 else 0)
+ width = master_width
+ height = master_height + (master_height_rem if i == 0 else 0)
+
+ print(x, y, width, height)
+ else:
+ secondary_height = output_height // secondary_count
+ secondary_height_rem = output_height % secondary_count
+
+ x = master_width
+ y = (i - master_count) * secondary_height + (secondary_height_rem if i > master_count else 0)
+ width = secondary_width
+ height = secondary_height + (secondary_height_rem if i == master_count else 0)
+
+ print(x, y, width, height)