gardesk/gar / 772a119

Browse files

fix screen size caching to handle rotation properly

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
772a119ff4412ac1cb68814ea8ffe99c16cddca6
Parents
6c9c79b
Tree
dd6b136

3 changed files

StatusFile+-
M gar/src/core/mod.rs 3 0
M gar/src/x11/connection.rs 32 0
M gar/src/x11/events.rs 9 2
gar/src/core/mod.rsmodified
@@ -292,6 +292,9 @@ impl WindowManager {
292292
     pub fn refresh_monitors(&mut self) -> Result<()> {
293293
         tracing::info!("Refreshing monitor configuration");
294294
 
295
+        // Update cached screen dimensions (may have changed due to rotation)
296
+        self.conn.update_screen_size();
297
+
295298
         let mut new_monitors = self.conn.detect_monitors().unwrap_or_else(|e| {
296299
             tracing::warn!("Failed to detect monitors: {}, keeping current", e);
297300
             return self.monitors.clone();
gar/src/x11/connection.rsmodified
@@ -1336,6 +1336,38 @@ impl Connection {
13361336
         )?;
13371337
         Ok(())
13381338
     }
1339
+
1340
+    /// Update cached screen dimensions using RandR query.
1341
+    /// Called after RandR events when we don't have the new size from the event.
1342
+    pub fn update_screen_size(&mut self) {
1343
+        use x11rb::protocol::randr::ConnectionExt as RandrExt;
1344
+
1345
+        // Query current screen size from RandR
1346
+        if let Ok(reply) = self.conn.randr_get_screen_info(self.root) {
1347
+            if let Ok(info) = reply.reply() {
1348
+                // Get the size from the current rotation/size index
1349
+                if let Some(size) = info.sizes.get(info.size_id as usize) {
1350
+                    let (new_w, new_h) = if info.rotation.contains(x11rb::protocol::randr::Rotation::ROTATE90)
1351
+                        || info.rotation.contains(x11rb::protocol::randr::Rotation::ROTATE270)
1352
+                    {
1353
+                        // Rotated 90 or 270 - swap dimensions
1354
+                        (size.height, size.width)
1355
+                    } else {
1356
+                        (size.width, size.height)
1357
+                    };
1358
+
1359
+                    if new_w != self.screen_width || new_h != self.screen_height {
1360
+                        tracing::info!(
1361
+                            "Screen size updated: {}x{} -> {}x{}",
1362
+                            self.screen_width, self.screen_height, new_w, new_h
1363
+                        );
1364
+                        self.screen_width = new_w;
1365
+                        self.screen_height = new_h;
1366
+                    }
1367
+                }
1368
+            }
1369
+        }
1370
+    }
13391371
 }
13401372
 
13411373
 impl std::ops::Deref for Connection {
gar/src/x11/events.rsmodified
@@ -574,8 +574,15 @@ impl WindowManager {
574574
             Event::EnterNotify(e) => {
575575
                 self.handle_enter_notify(e)?;
576576
             }
577
-            Event::RandrScreenChangeNotify(_) => {
578
-                tracing::info!("RandR screen change detected, refreshing monitors");
577
+            Event::RandrScreenChangeNotify(e) => {
578
+                tracing::info!(
579
+                    "RandR screen change: {}x{} -> {}x{}",
580
+                    self.conn.screen_width, self.conn.screen_height,
581
+                    e.width, e.height
582
+                );
583
+                // Update cached screen dimensions from the event
584
+                self.conn.screen_width = e.width;
585
+                self.conn.screen_height = e.height;
579586
                 self.refresh_monitors()?;
580587
                 self.broadcast_i3_output_event();
581588
             }