shithub: rio

Download patch

ref: a9e909fe0e23030d2d682e084b14df34bb52f55d
parent: c9695eec3720c70a1df638b9614a38b7dd60e837
author: glenda <glenda@cirno>
date: Fri Mar 21 23:38:49 EDT 2025

simplify snapping for windows

--- a/rio.c
+++ b/rio.c
@@ -1185,9 +1185,6 @@
     return edges ? edges : -1;
 }
 
-/*
- * Get snapped rectangle based on screen edges
- */
 static Rectangle
 snaprect(Rectangle screenr, int edges)
 {
@@ -1196,37 +1193,15 @@
     int midy = (screenr.min.y + screenr.max.y)/2;
     
     r = screenr;
-    
-    /* Handle corners first (two edges) */
-    if((edges & 5) == 5){  /* Top-left */
+
+    if(edges & 1)  // Left edge
         r.max.x = midx;
-        r.max.y = midy;
-    }
-    else if((edges & 6) == 6){  /* Top-right */
+    if(edges & 2)  // Right edge
         r.min.x = midx;
+    if(edges & 4)  // Top edge
         r.max.y = midy;
-    }
-    else if((edges & 9) == 9){  /* Bottom-left */
-        r.max.x = midx;
+    if(edges & 8)  // Bottom edge
         r.min.y = midy;
-    }
-    else if((edges & 10) == 10){  /* Bottom-right */
-        r.min.x = midx;
-        r.min.y = midy;
-    }
-    /* Handle edges (one edge) */
-    else if(edges & 4){  /* Top */
-        r.max.y = midy;
-    }
-    else if(edges & 8){  /* Bottom */
-        r.min.y = midy;
-    }
-    else if(edges & 1){  /* Left */
-        r.max.x = midx;
-    }
-    else if(edges & 2){  /* Right */
-        r.min.x = midx;
-    }
     
     return r;
 }