pinenote-service 1.0.1

Management dervice for Pine64's PineNote device
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
//! Pixel Management
//!
//! [PixelManager] goal is to compute a set of visible rectangle for the [driver] to consume. These
//! rectangle describe what [rendering mode] a given region should use.
//!
//! # Application and Window
//!
//! [Application] are not really important. They aims to be a convenient way to find every windows
//! for a given process, and to hold a default render mode applied to every window for this
//! process. If neither the Application hint or the Window hint are set, then the global
//! default_hint will be used instead.
//!
//! A [Window] represent what's being rendered. Every Window is linked to an Application, has a
//! unique identifier and an rectangular area. A window can additionally have a hint, in which case
//! it will be used instead of the per-application one, or the global hint if both are unset.
//!
//! # Render Hint computation
//!
//! The [RectHint] the driver will received are minimized to offload the work done by the kernel in
//! userland. This minimization is achieved by putting every window area in a Z-indexed tree, and
//! reducing overlapping regions, or even removing them altogether.
//!
//! The final output aims to respect two goals:
//! 1. Minimizing the amount of [RectHint] sent
//! 2. Minimizing the size of every [RectHint] sent
//!
//! These two are somewhat incompatible, since to minimize the size you would need to split them so
//! that only their visible area is sent to the driver. To prevent proliferation of rectangles, any
//! given window will only produce one rectangle[^rec_per_win]. However the rectangle produce is
//! always the bounding box of the window's visible area.
//!
//! ## Example
//!
//! Given the following windows:
//! |Z-INDEX| Dimension |Representation|
//! |-------|-----------|--------------|
//! | 0     | {0,0,5,3} | A            |
//! | 1     | {2,0,4,2} | B            |
//! | 2     | {0,2,5,3} | C            |
//!
//! The screen would look something like this:
//! ```txt
//! AABBA
//! AABBA
//! CCCCC
//! ```
//!
//! - C doesn't overlap with B, so B will be sent as-is.
//! - C overlap with A, and fully cover the bottom region, so A rectangle can be reduced.
//! - B overlap with A, but part of A can be both on the left and right, so A cannot be reduced
//!
//! The final dimension for A is computed as {0,0,5,2}.
//!
//! [^rec_per_win]: In the future, a Window may produce more than one rectangle, if it has
//! sub-surfaces with different hints.
//!
//! # TODOs:
//! - Allow finding an Application using its pid.
//! - Allow retrieving a list of window keys for a given application
//! - Implement window sub-surfaces for more precise pixel management.
//! - Partial refresh
//!
//! [driver]: crate::drivers::rockchip_ebc::RockchipEbc
//! [rendering mode]: crate::types::rockchip_ebc::Hint

use std::collections::{HashMap, HashSet};
use thiserror::Error;

use nix::libc::pid_t;

use crate::types::{
    Rect,
    rockchip_ebc::{Hint, RectHint},
    ztree::{ZSurface, ZTree},
};

/// Application representation.
///
/// This struct represent a running process, and hold the default configuration for any of the
/// process windows for which it wasn't overridden.
#[derive(Debug)]
pub struct Application {
    app_id: String,
    pid: pid_t,
    default_hint: Option<Hint>,
    windows: HashSet<String>,
}

impl Application {
    /// Create a new [Application] using global default hint.
    pub fn new(app_id: impl Into<String>, pid: pid_t) -> Self {
        Self {
            app_id: app_id.into(),
            pid,
            default_hint: None,
            windows: Default::default(),
        }
    }

    /// Create a new Application, setting its default hint configuration
    pub fn with_hint(app_id: impl Into<String>, pid: pid_t, default_hint: Option<Hint>) -> Self {
        Self {
            app_id: app_id.into(),
            pid,
            default_hint,
            windows: Default::default(),
        }
    }

    /// Return the application unique Key.
    fn key(&self) -> String {
        format!("{}:{}", self.app_id, self.pid)
    }

    /// Add a window to the Application
    fn window_add(&mut self, win_uid: String) {
        self.windows.insert(win_uid);
    }

    /// Delete an Application window
    fn window_remove(&mut self, win_uid: &String) {
        self.windows.remove(win_uid);
    }
}

#[derive(Clone, Debug)]
pub struct WindowData {
    pub title: String,
    pub area: Rect,
    pub hint: Option<Hint>,
    pub visible: bool,
    pub fullscreen: bool,
    pub z_index: i32,
}

/// Represent an on-screen window
///
// TODO: Implement subsurfaces
// TODO: Implement per title search
#[derive(Debug)]
pub struct Window {
    uid: String,
    app_key: String,
    pub data: WindowData, //sub_surface: Vec<Surface>
}

impl Window {
    pub fn new(
        app_key: impl Into<String>,
        title: impl Into<String>,
        area: Rect,
        hint: Option<Hint>,
        visible: bool,
        fullscreen: bool,
        z_index: i32,
    ) -> Self {
        let uid = uuid::Uuid::new_v4().to_string();
        let app_key = app_key.into();
        let title = title.into();

        Self {
            uid,
            app_key,
            data: WindowData {
                title,
                area,
                hint,
                visible,
                fullscreen,
                z_index,
            },
        }
    }

    pub fn is_fullscreen(&self) -> bool {
        self.data.fullscreen
    }

    pub fn zsurface(&self, screen_area: &Rect) -> Option<ZSurface> {
        if self.data.visible {
            self.data
                .area
                .intersection(screen_area)
                .map(|rect| ZSurface::new(self.data.z_index, self.uid.clone(), rect))
        } else {
            None
        }
    }

    pub fn update(&mut self, data: WindowData) {
        self.data = data
    }
}

#[derive(Debug, PartialEq, Default)]
pub struct ComputedHints {
    pub default_hint: Option<Hint>,
    pub rect_hints: Vec<RectHint>,
}

impl ComputedHints {
    pub fn new() -> Self {
        Self {
            default_hint: None,
            rect_hints: Default::default(),
        }
    }

    pub fn with_hint(hint: Hint) -> Self {
        Self {
            default_hint: Some(hint),
            ..Default::default()
        }
    }
}

/// Manage per pixel hints
#[derive(Debug)]
pub struct PixelManager {
    /// Default Hints to use for uncovered pixels
    pub default_hint: Hint,
    /// Rectangle representing the full screen.
    screen_area: Rect,

    applications: HashMap<String, Application>,
    windows: HashMap<String, Window>,
}

#[derive(Error, Debug, PartialEq)]
pub enum PixelManagerError {
    #[error("No application with key '{0}' found.")]
    UnknownApp(String),
    #[error("No window with uid '{0}' found")]
    UnknownWindow(String),
}

impl PixelManager {
    pub fn new(default_hint: Hint, screen_area: Rect) -> Self {
        Self {
            default_hint,
            screen_area,
            applications: Default::default(),
            windows: Default::default(),
        }
    }

    pub fn app(&self, app_key: &String) -> Result<&Application, PixelManagerError> {
        self.applications
            .get(app_key)
            .ok_or(PixelManagerError::UnknownApp(app_key.to_owned()))
    }

    pub fn app_mut(&mut self, app_key: &String) -> Result<&mut Application, PixelManagerError> {
        self.applications
            .get_mut(app_key)
            .ok_or(PixelManagerError::UnknownApp(app_key.to_owned()))
    }

    /// Add a new Application to the controller
    pub fn app_add(&mut self, app: Application) -> String {
        let key = app.key();

        if !self.applications.contains_key(&key) {
            self.applications.insert(key.clone(), app);
        }

        key
    }

    /// Remove an Application and its associated Window.
    pub fn app_remove(&mut self, app_key: &String) {
        let Some(app) = self.applications.remove(app_key) else {
            return;
        };

        for win_key in app.windows {
            self.windows.remove(&win_key);
        }
    }

    /// Access default hint for a specif app
    pub fn app_hint(&self, app_key: &String) -> Result<Option<Hint>, PixelManagerError> {
        self.app(app_key).map(|a| a.default_hint)
    }

    /// Update default hint associated with the Application.
    pub fn app_set_hint(&mut self, app_key: &String, hint: Hint) -> Result<(), PixelManagerError> {
        let app = self.app_mut(app_key)?;

        app.default_hint = Some(hint);

        Ok(())
    }

    /// Remove default hint associated with the application.
    pub fn app_unset_hint(&mut self, app_key: &String) -> Result<(), PixelManagerError> {
        let app = self.app_mut(app_key)?;

        app.default_hint = None;

        Ok(())
    }

    pub fn window(&self, win_key: &String) -> Result<&Window, PixelManagerError> {
        self.windows
            .get(win_key)
            .ok_or(PixelManagerError::UnknownWindow(win_key.to_owned()))
    }

    pub fn window_mut(&mut self, win_key: &String) -> Result<&mut Window, PixelManagerError> {
        self.windows
            .get_mut(win_key)
            .ok_or(PixelManagerError::UnknownWindow(win_key.to_owned()))
    }

    /// Add a new window, and link it to an application.
    pub fn window_add(&mut self, window: Window) -> Result<String, PixelManagerError> {
        let app_key = window.app_key.clone();
        let uid = window.uid.clone();

        if !self.applications.contains_key(&app_key) {
            Err(PixelManagerError::UnknownApp(app_key.clone()))?;
        };

        if !self.windows.contains_key(&window.uid) {
            self.windows.insert(uid.clone(), window);

            self.applications
                .entry(app_key.to_owned())
                .and_modify(|a| a.window_add(uid.clone()));
        }

        Ok(uid)
    }

    /// Remove a window using its key.
    pub fn window_remove(&mut self, win_uid: String) {
        let Some(win) = self.windows.remove(&win_uid) else {
            return;
        };
        let app_key = win.app_key;

        self.applications
            .entry(app_key)
            .and_modify(|a| a.window_remove(&win_uid));
    }

    pub fn window_update(
        &mut self,
        win_key: &String,
        data: WindowData,
    ) -> Result<(), PixelManagerError> {
        let window = self.window_mut(win_key)?;

        window.update(data);

        Ok(())
    }

    /// Set a window specific hint.
    pub fn window_set_hint(
        &mut self,
        win_key: &String,
        hint: Hint,
    ) -> Result<(), PixelManagerError> {
        let win = self.window_mut(win_key)?;

        win.data.hint = Some(hint);

        Ok(())
    }

    /// Unset a window specific hint.
    pub fn window_unset_hint(&mut self, win_key: &String) -> Result<(), PixelManagerError> {
        let win = self.window_mut(win_key)?;

        win.data.hint = None;

        Ok(())
    }

    pub fn window_hint(&self, win_key: &String) -> Result<Option<Hint>, PixelManagerError> {
        self.window(win_key).map(|w| w.data.hint)
    }

    pub fn window_hint_fallback(&self, win_key: &String) -> Result<Hint, PixelManagerError> {
        let win = self.window(win_key)?;

        if let Some(hint) = win.data.hint {
            Ok(hint)
        } else {
            let app = self.app(&win.app_key)?;
            Ok(app.default_hint.unwrap_or(self.default_hint))
        }
    }

    /// Compute visible RectHint.
    pub fn compute_hints(&self) -> Result<ComputedHints, PixelManagerError> {
        let mut ret = ComputedHints::with_hint(self.default_hint);
        let mut ztree = ZTree::new();

        for win in self.windows.values() {
            if win.is_fullscreen() {
                let mut hint = ComputedHints::new();
                hint.rect_hints = vec![RectHint {
                    rect: self.screen_area.clone(),
                    hint: self.window_hint_fallback(&win.uid)?,
                }];
                return Ok(hint);
            }

            if let Some(s) = win.zsurface(&self.screen_area) {
                ztree.insert(s);
            }
        }

        let ztree = self
            .windows
            .values()
            .filter_map(|w| w.zsurface(&self.screen_area))
            .fold(ZTree::new(), |mut tree, s| {
                tree.insert(s);
                tree
            });

        ret.rect_hints = ztree
            .flatten()
            .into_iter()
            .map(
                |ZSurface {
                     area: rect,
                     reference,
                     ..
                 }| {
                    self.window_hint_fallback(&reference)
                        .map(|hint| RectHint { rect, hint })
                },
            )
            .collect::<Result<_, _>>()?;

        Ok(ret)
    }
}

#[cfg(test)]
#[allow(dead_code)]
mod tests {
    use super::*;
    use crate::types::{
        Rect,
        rockchip_ebc::{Hint, HintBitDepth as BitDepth, HintConvertMode},
    };

    const Y4DITHER_REDRAW: Hint = Hint::new(BitDepth::Y4, HintConvertMode::Dither, true);
    const Y4DITHER: Hint = Hint::new(BitDepth::Y4, HintConvertMode::Dither, false);
    const Y2DITHER_REDRAW: Hint = Hint::new(BitDepth::Y4, HintConvertMode::Dither, true);
    const Y2DITHER: Hint = Hint::new(BitDepth::Y4, HintConvertMode::Dither, false);

    const SCREEN_RECT: Rect = Rect::new(0, 0, 1872, 1404);

    fn setup_manager() -> PixelManager {
        PixelManager::new(Y4DITHER_REDRAW, SCREEN_RECT.clone())
    }

    #[test]
    fn empty_sets_default() {
        let mut mgr = setup_manager();

        let expected = ComputedHints::with_hint(Y4DITHER_REDRAW);

        assert_eq!(expected, mgr.compute_hints().unwrap());

        let expected = ComputedHints::with_hint(Y2DITHER_REDRAW);

        mgr.default_hint = Y2DITHER_REDRAW;

        assert_eq!(expected, mgr.compute_hints().unwrap());
    }

    #[test]
    fn clip_window_to_screen() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let app = Application::new("testapp", 1234);
        let app_key = mgr.app_add(app);

        let win_rect = Rect::new(1000, 1000, 2000, 1600);
        let win_hint = Y2DITHER;

        let win = Window::new(
            app_key,
            "TestWindow",
            win_rect.clone(),
            Some(win_hint),
            true,
            false,
            0,
        );

        mgr.window_add(win)?;

        let expected = ComputedHints {
            default_hint: Some(mgr.default_hint),
            rect_hints: vec![RectHint {
                hint: win_hint,
                rect: Rect::new(1000, 1000, SCREEN_RECT.x2, SCREEN_RECT.y2),
            }],
        };

        assert_eq!(expected, mgr.compute_hints()?);

        Ok(())
    }

    #[test]
    fn window_add_noapp_fails() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let win = Window::new(
            "test_app:1234",
            "test_win",
            Rect::new(100, 100, 200, 200),
            Some(Y2DITHER),
            true,
            false,
            0,
        );

        assert_eq!(
            Err(PixelManagerError::UnknownApp("test_app:1234".to_string())),
            mgr.window_add(win)
        );

        Ok(())
    }

    #[test]
    fn one_window() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let win_rect = Rect::new(100, 100, 500, 600);
        let win_hint = Y2DITHER;

        let expected = ComputedHints {
            default_hint: Some(mgr.default_hint),
            rect_hints: vec![RectHint {
                rect: win_rect.clone(),
                hint: win_hint,
            }],
        };

        let app = Application::new("testapp", 1234);
        let app_key = mgr.app_add(app);

        let win = Window::new(
            app_key,
            "TestWindow",
            win_rect.clone(),
            Some(win_hint),
            true,
            false,
            0,
        );

        mgr.window_add(win)?;

        assert_eq!(expected, mgr.compute_hints()?);

        Ok(())
    }

    #[test]
    fn hidden_window() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let win_rect = Rect::new(100, 100, 500, 600);
        let win_hint = Y2DITHER;

        let expected = ComputedHints {
            default_hint: Some(mgr.default_hint),
            rect_hints: vec![],
        };

        let app = Application::new("testapp", 1234);
        let app_key = mgr.app_add(app);

        let win = Window::new(
            app_key,
            "TestWindow",
            win_rect.clone(),
            Some(win_hint),
            false,
            false,
            0,
        );

        mgr.window_add(win)?;

        assert_eq!(expected, mgr.compute_hints()?);

        Ok(())
    }

    #[test]
    fn app_hint_fallback() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let win_rect = Rect::new(100, 100, 500, 500);

        let app_hint = Y2DITHER;

        let expected = ComputedHints {
            default_hint: Some(mgr.default_hint),
            rect_hints: vec![RectHint {
                rect: win_rect.clone(),
                hint: app_hint,
            }],
        };

        let app_key = mgr.app_add(Application::with_hint("testapp", 1234, Some(app_hint)));

        mgr.window_add(Window::new(
            app_key,
            "TestWindow",
            win_rect.clone(),
            None,
            true,
            false,
            0,
        ))?;

        assert_eq!(expected, mgr.compute_hints()?);

        Ok(())
    }

    #[test]
    fn global_hint_fallback() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let win_rect = Rect::new(100, 100, 500, 500);

        let expected = ComputedHints {
            default_hint: Some(Y4DITHER_REDRAW),
            rect_hints: vec![RectHint {
                rect: win_rect.clone(),
                hint: Y4DITHER_REDRAW,
            }],
        };

        let app_key = mgr.app_add(Application::new("testapp", 1234));

        mgr.window_add(Window::new(
            app_key,
            "TestWindow",
            win_rect.clone(),
            None,
            true,
            false,
            0,
        ))?;

        assert_eq!(expected, mgr.compute_hints()?);

        Ok(())
    }

    #[test]
    fn respect_z_indexing() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let app_key = mgr.app_add(Application::new("testapp", 1234));
        let rect_hint1 = RectHint {
            rect: Rect::new(100, 100, 500, 500),
            hint: Y2DITHER,
        };
        let window1 = Window::new(
            app_key,
            "TestWindow1",
            rect_hint1.rect.clone(),
            Some(rect_hint1.hint),
            true,
            false,
            5,
        );
        mgr.window_add(window1)?;

        let rect_hint2 = RectHint {
            rect: Rect::new(100, 100, 600, 600),
            hint: Y2DITHER_REDRAW,
        };
        let app_key = mgr.app_add(Application::new("testapp", 1235));
        let window2 = Window::new(
            app_key,
            "TestWindow2",
            rect_hint2.rect.clone(),
            Some(rect_hint2.hint),
            true,
            false,
            3,
        );
        mgr.window_add(window2)?;

        let rect_hint3 = RectHint {
            rect: Rect::new(0, 0, 400, 400),
            hint: Y4DITHER,
        };
        let app_key = mgr.app_add(Application::new("testapp", 1236));
        let window3 = Window::new(
            app_key,
            "TestWindow3",
            rect_hint3.rect.clone(),
            Some(rect_hint3.hint),
            true,
            false,
            4,
        );
        mgr.window_add(window3)?;

        let expected = ComputedHints {
            default_hint: Some(mgr.default_hint),
            rect_hints: vec![rect_hint2, rect_hint3, rect_hint1],
        };

        assert_eq!(expected, mgr.compute_hints()?);

        Ok(())
    }

    #[test]
    fn fullscreen_window_support() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let app_key = mgr.app_add(Application::new("testapp", 1234));
        let rect_hint1 = RectHint {
            rect: Rect::new(100, 100, 500, 500),
            hint: Y2DITHER,
        };
        let window1 = Window::new(
            app_key,
            "TestWindow1",
            rect_hint1.rect.clone(),
            Some(rect_hint1.hint),
            true,
            false,
            5,
        );
        mgr.window_add(window1)?;

        let rect_hint2 = RectHint {
            rect: Rect::new(100, 100, 600, 600),
            hint: Y2DITHER_REDRAW,
        };
        let app_key = mgr.app_add(Application::new("testapp", 1235));
        let window2 = Window::new(
            app_key,
            "TestWindow2",
            rect_hint2.rect.clone(),
            Some(rect_hint2.hint),
            true,
            true,
            3,
        );
        mgr.window_add(window2)?;

        let rect_hint3 = RectHint {
            rect: Rect::new(0, 0, 400, 400),
            hint: Y4DITHER,
        };
        let app_key = mgr.app_add(Application::new("testapp", 1236));
        let window3 = Window::new(
            app_key,
            "TestWindow3",
            rect_hint3.rect.clone(),
            Some(rect_hint3.hint),
            true,
            false,
            4,
        );
        mgr.window_add(window3)?;

        let full_screen_rect = RectHint {
            rect: SCREEN_RECT.clone(),
            hint: Y2DITHER_REDRAW,
        };
        let expected = ComputedHints {
            default_hint: None,
            rect_hints: vec![full_screen_rect],
        };

        assert_eq!(expected, mgr.compute_hints()?);

        Ok(())
    }

    #[test]
    fn remove_hidden_window() -> Result<(), PixelManagerError> {
        let mut mgr = setup_manager();

        let app_key = mgr.app_add(Application::new("testapp", 1234));
        let rect_hint1 = RectHint {
            rect: Rect::new(100, 100, 500, 500),
            hint: Y2DITHER,
        };
        let window1 = Window::new(
            app_key,
            "TestWindow1",
            rect_hint1.rect.clone(),
            Some(rect_hint1.hint),
            true,
            false,
            0,
        );
        mgr.window_add(window1)?;

        let rect_hint2 = RectHint {
            rect: Rect::new(100, 100, 600, 600),
            hint: Y2DITHER_REDRAW,
        };
        let app_key = mgr.app_add(Application::new("testapp", 1235));
        let window2 = Window::new(
            app_key,
            "TestWindow2",
            rect_hint2.rect.clone(),
            Some(rect_hint2.hint),
            true,
            false,
            1,
        );
        mgr.window_add(window2)?;

        let expected = ComputedHints {
            default_hint: Some(mgr.default_hint),
            rect_hints: vec![rect_hint2],
        };

        assert_eq!(expected, mgr.compute_hints()?);

        Ok(())
    }
}