gardesk/gardisplay / 08a81ff

Browse files

add --demo flag for multi-monitor UI testing

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
08a81ff4224a29748cd043d70582bfe5a7b77ffd
Parents
9cc7867
Tree
4795c38

2 changed files

StatusFile+-
M gardisplay/src/app.rs 36 4
M gardisplay/src/main.rs 5 1
gardisplay/src/app.rsmodified
@@ -28,7 +28,7 @@ pub struct App {
2828
 
2929
 impl App {
3030
     /// Create a new application instance.
31
-    pub fn new(config: Config) -> Result<Self> {
31
+    pub fn new(config: Config, demo: bool) -> Result<Self> {
3232
         // Connect to X11
3333
         let conn = Connection::connect(None)?;
3434
         tracing::info!("connected to X11 display");
@@ -80,9 +80,14 @@ impl App {
8080
         let view_rect = Rect::new(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT - 100); // Leave room for controls
8181
         let mut monitor_view = MonitorView::new(view_rect);
8282
 
83
-        // Detect monitors
84
-        let monitors = detect_monitors(&conn)?;
85
-        tracing::info!("detected {} monitors", monitors.len());
83
+        // Detect or create demo monitors
84
+        let monitors = if demo {
85
+            tracing::info!("demo mode: using fake monitors");
86
+            Self::demo_monitors()
87
+        } else {
88
+            detect_monitors(&conn)?
89
+        };
90
+        tracing::info!("using {} monitors", monitors.len());
8691
         for m in &monitors {
8792
             tracing::debug!(
8893
                 "  {} {}x{} at ({}, {}) {}",
@@ -107,6 +112,33 @@ impl App {
107112
         })
108113
     }
109114
 
115
+    /// Create demo monitors for UI testing.
116
+    fn demo_monitors() -> Vec<gartk_x11::Monitor> {
117
+        vec![
118
+            gartk_x11::Monitor {
119
+                name: "eDP-1".to_string(),
120
+                rect: Rect::new(0, 0, 2560, 1600),
121
+                primary: true,
122
+                width_mm: 290,
123
+                height_mm: 180,
124
+            },
125
+            gartk_x11::Monitor {
126
+                name: "HDMI-1".to_string(),
127
+                rect: Rect::new(2560, 0, 1920, 1080),
128
+                primary: false,
129
+                width_mm: 530,
130
+                height_mm: 300,
131
+            },
132
+            gartk_x11::Monitor {
133
+                name: "DP-1".to_string(),
134
+                rect: Rect::new(2560, 1080, 1920, 1080),
135
+                primary: false,
136
+                width_mm: 530,
137
+                height_mm: 300,
138
+            },
139
+        ]
140
+    }
141
+
110142
     /// Run the application event loop.
111143
     pub fn run(&mut self) -> Result<()> {
112144
         // Initial render
gardisplay/src/main.rsmodified
@@ -14,6 +14,10 @@ struct Args {
1414
     /// Configuration file path
1515
     #[arg(short, long)]
1616
     config: Option<String>,
17
+
18
+    /// Demo mode with fake monitors for UI testing
19
+    #[arg(long)]
20
+    demo: bool,
1721
 }
1822
 
1923
 fn main() -> anyhow::Result<()> {
@@ -30,6 +34,6 @@ fn main() -> anyhow::Result<()> {
3034
     tracing::info!("starting gardisplay");
3135
 
3236
     let config = config::load_config(args.config.as_deref())?;
33
-    let mut app = app::App::new(config)?;
37
+    let mut app = app::App::new(config, args.demo)?;
3438
     app.run()
3539
 }