gardesk/garchomp / db230c1

Browse files

subscribe to RandR events for screen rotation/resize handling

Authored by espadonne
SHA
db230c12f3438d8c3e0de722ec589926ac192aa4
Parents
cf796ee
Tree
3e9d06d

1 changed file

StatusFile+-
M garchomp/src/compositor/mod.rs 17 0
garchomp/src/compositor/mod.rsmodified
@@ -25,6 +25,7 @@ use x11rb::protocol::xproto::{
2525
     DestroyNotifyEvent, EventMask, MapNotifyEvent, PropertyNotifyEvent,
2626
     UnmapNotifyEvent, Window,
2727
 };
28
+use x11rb::protocol::randr::{ConnectionExt as RandrConnectionExt, NotifyMask as RandrNotifyMask};
2829
 use x11rb::protocol::Event;
2930
 
3031
 #[derive(Error, Debug)]
@@ -102,6 +103,14 @@ impl Compositor {
102103
             &ChangeWindowAttributesAux::new().event_mask(event_mask),
103104
         )?;
104105
 
106
+        // Subscribe to RandR screen change events (for rotation/resolution changes)
107
+        if let Err(e) = conn.conn.randr_select_input(
108
+            conn.root(),
109
+            RandrNotifyMask::SCREEN_CHANGE,
110
+        ) {
111
+            tracing::warn!("Failed to subscribe to RandR events: {}", e);
112
+        }
113
+
105114
         conn.flush()?;
106115
 
107116
         // Try to connect to gar
@@ -475,6 +484,14 @@ impl Compositor {
475484
             Event::ConfigureNotify(e) => self.handle_configure(e)?,
476485
             Event::PropertyNotify(e) => self.handle_property(e)?,
477486
             Event::DamageNotify(e) => self.handle_damage(e),
487
+            Event::RandrScreenChangeNotify(e) => {
488
+                tracing::info!(
489
+                    "RandR screen change: {}x{} -> resizing compositor",
490
+                    e.width, e.height
491
+                );
492
+                self.renderer.resize(e.width as u32, e.height as u32);
493
+                self.needs_redraw = true;
494
+            }
478495
             Event::Error(e) => {
479496
                 tracing::warn!("X11 error: {:?}", e);
480497
             }