git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit93bf9f0f919a5624d42f6536323d11334a2168e7
parentba213d4e12
authorMichal Siedlaczek <[email protected]>
date2021-08-10 18:43
contrib: make layout.py more pythonic

 contrib/layout.py | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/contrib/layout.py b/contrib/layout.py
index fd60fcf..7940988 100755
--- a/contrib/layout.py
+++ b/contrib/layout.py
@@ -33,25 +33,22 @@ def layout_handle_layout_demand(layout, view_count, usable_w, usable_h, tags, se
     y = 0
     w = usable_w
     h = usable_h
-    i = 0
-    while i < view_count:
-        if i == view_count - 1:
-            layout.push_view_dimensions(x, y, w, h, serial)
+    for i in range(0, view_count - 1):
+        if i % 2 == 0:
+            w //= 2
+            if i % 4 == 2:
+                layout.push_view_dimensions(x + w, y, w, h, serial)
+            else:
+                layout.push_view_dimensions(x, y, w, h, serial)
+                x += w
         else:
-            if i % 2 == 0:
-                w = int(w/2)
-                if i % 4 == 2:
-                    layout.push_view_dimensions(x + w, y, w, h, serial)
-                else:
-                    layout.push_view_dimensions(x, y, w, h, serial)
-                    x += w
+            h //= 2
+            if i % 4 == 3:
+                layout.push_view_dimensions(x, y + h, w, h, serial)
             else:
-                h = int(h/2)
-                if i % 4 == 3:
-                    layout.push_view_dimensions(x, y + h, w, h, serial)
-                else:
-                    layout.push_view_dimensions(x, y, w, h, serial)
-                    y += h
+                layout.push_view_dimensions(x, y, w, h, serial)
+                y += h
+    layout.push_view_dimensions(x, y, w, h, serial)
 
     # Committing the layout means telling the server that your code is done
     # laying out windows. Make sure you have pushed exactly the right amount of
@@ -61,7 +58,7 @@ def layout_handle_layout_demand(layout, view_count, usable_w, usable_h, tags, se
     # the server can forward to status bars. You can use it to tell the user
     # which layout is currently in use. You could also add some status
     # information status information about your layout, which is what we do here.
-    layout.commit(str(view_count) + " windows layout out by python", serial)
+    layout.commit(f"{view_count} windows layed out by python", serial)
 
 def layout_handle_namespace_in_use(layout):
     # Oh no, the namespace we choose is already used by another client! All we
@@ -81,14 +78,14 @@ class Output(object):
         self.id = None
 
     def destroy(self):
-        if self.layout != None:
+        if self.layout is not None:
             self.layout.destroy()
-        if self.output != None:
+        if self.output is not None:
             self.output.destroy()
 
     def configure(self):
         global layout_manager
-        if self.layout == None and layout_manager != None:
+        if self.layout is None and layout_manager is not None:
             # We need to set a namespace, which is used to identify our layout.
             self.layout = layout_manager.get_layout(self.output, "layout.py")
             self.layout.user_data = self
@@ -123,7 +120,7 @@ registry.dispatcher["global_remove"] = registry_handle_global_remove
 display.dispatch(block=True)
 display.roundtrip()
 
-if layout_manager == None:
+if layout_manager is None:
     print("No layout_manager, aborting")
     quit()