gardesk/gar / 88f32a7

Browse files

floating: respect window geometry instead of hardcoded 640x480

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
88f32a747ddedf10dfdd1dee116c12ada8ed7171
Parents
0b3a00d
Tree
e0574a5

1 changed file

StatusFile+-
M gar/src/core/mod.rs 52 10
gar/src/core/mod.rsmodified
@@ -313,12 +313,33 @@ impl WindowManager {
313313
 
314314
         tracing::info!("Managing window {} on workspace {} (floating)", window, workspace_idx + 1);
315315
 
316
-        // Calculate floating geometry
316
+        // Get window's requested geometry - respect the window's size/position
317317
         let screen = self.screen_rect();
318
-        let float_width = (screen.width * 4 / 5).max(400);
319
-        let float_height = (screen.height * 4 / 5).max(300);
320
-        let float_x = screen.x + (screen.width as i16 - float_width as i16) / 2;
321
-        let float_y = screen.y + (screen.height as i16 - float_height as i16) / 2;
318
+        let (float_x, float_y, float_width, float_height) =
319
+            if let Ok(Ok(geom)) = self.conn.conn.get_geometry(window).map(|c| c.reply()) {
320
+                // Use window's actual geometry, but ensure it fits on screen
321
+                let w = geom.width.min(screen.width).max(100);
322
+                let h = geom.height.min(screen.height).max(100);
323
+                // Use window's position if valid, otherwise center
324
+                let x = if geom.x >= 0 && (geom.x as u16) < screen.width {
325
+                    geom.x
326
+                } else {
327
+                    screen.x + (screen.width as i16 - w as i16) / 2
328
+                };
329
+                let y = if geom.y >= 0 && (geom.y as u16) < screen.height {
330
+                    geom.y
331
+                } else {
332
+                    screen.y + (screen.height as i16 - h as i16) / 2
333
+                };
334
+                (x, y, w, h)
335
+            } else {
336
+                // Fallback to default centered geometry (80% of screen)
337
+                let w = (screen.width * 4 / 5).max(400);
338
+                let h = (screen.height * 4 / 5).max(300);
339
+                let x = screen.x + (screen.width as i16 - w as i16) / 2;
340
+                let y = screen.y + (screen.height as i16 - h as i16) / 2;
341
+                (x, y, w, h)
342
+            };
322343
 
323344
         // Track the window with floating state
324345
         let mut win = Window::new(window, workspace_idx);
@@ -344,12 +365,33 @@ impl WindowManager {
344365
 
345366
         tracing::info!("Managing window {} (floating)", window);
346367
 
347
-        // Calculate centered floating geometry
368
+        // Get window's requested geometry - respect the window's size/position
348369
         let screen = self.screen_rect();
349
-        let float_width = 640.min(screen.width.saturating_sub(40));
350
-        let float_height = 480.min(screen.height.saturating_sub(40));
351
-        let float_x = screen.x + (screen.width as i16 - float_width as i16) / 2;
352
-        let float_y = screen.y + (screen.height as i16 - float_height as i16) / 2;
370
+        let (float_x, float_y, float_width, float_height) =
371
+            if let Ok(Ok(geom)) = self.conn.conn.get_geometry(window).map(|c| c.reply()) {
372
+                // Use window's actual geometry, but ensure it fits on screen
373
+                let w = geom.width.min(screen.width).max(100);
374
+                let h = geom.height.min(screen.height).max(100);
375
+                // Use window's position if valid, otherwise center
376
+                let x = if geom.x >= 0 && (geom.x as u16) < screen.width {
377
+                    geom.x
378
+                } else {
379
+                    screen.x + (screen.width as i16 - w as i16) / 2
380
+                };
381
+                let y = if geom.y >= 0 && (geom.y as u16) < screen.height {
382
+                    geom.y
383
+                } else {
384
+                    screen.y + (screen.height as i16 - h as i16) / 2
385
+                };
386
+                (x, y, w, h)
387
+            } else {
388
+                // Fallback to default centered geometry
389
+                let w = 640u16.min(screen.width.saturating_sub(40));
390
+                let h = 480u16.min(screen.height.saturating_sub(40));
391
+                let x = screen.x + (screen.width as i16 - w as i16) / 2;
392
+                let y = screen.y + (screen.height as i16 - h as i16) / 2;
393
+                (x, y, w, h)
394
+            };
353395
 
354396
         // Track the window with floating state
355397
         let mut win = Window::new(window, self.focused_workspace);