git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

src/scale.rs (1.8K)

 1 use std::sync::{OnceLock, RwLock};
 2 
 3 static SCALE_FACTOR: RwLock<f32> = RwLock::new(1.0);
 4 static FORCED_SCALE: OnceLock<Option<f32>> = OnceLock::new();
 5 
 6 /// `CCE_FORCE_SCALE`: HiDPI override for foreign compositors that report a
 7 /// scale-1 output (the display-manager greeter under cage). In forced mode the
 8 /// compositor's logical coordinate space is treated as physical: configure
 9 /// sizes and pointer positions are divided by this factor, layout/rendering
10 /// scale up by it, and the surface keeps `buffer_scale` 1 so the buffer still
11 /// matches the size the compositor configured. Unset (the normal case, under
12 /// cce-fx) this is `None` and nothing changes.
13 pub fn forced_scale() -> Option<f32> {
14     *FORCED_SCALE.get_or_init(|| {
15         std::env::var("CCE_FORCE_SCALE")
16             .ok()
17             .and_then(|v| v.parse::<f32>().ok())
18             .filter(|s| *s > 0.0 && (*s - 1.0).abs() > 0.001)
19     })
20 }
21 static APP_ID: RwLock<String> = RwLock::new(String::new());
22 static FULLSCREEN: RwLock<bool> = RwLock::new(false);
23 static MAXIMIZED: RwLock<bool> = RwLock::new(false);
24 
25 pub fn scale_factor() -> f32 {
26     *SCALE_FACTOR.read().unwrap()
27 }
28 
29 pub fn set_scale_factor(scale: f32) {
30     if let Ok(mut lock) = SCALE_FACTOR.write() {
31         *lock = scale;
32     }
33 }
34 
35 pub fn app_id() -> String {
36     APP_ID.read().unwrap().clone()
37 }
38 
39 pub fn set_app_id(id: String) {
40     if let Ok(mut lock) = APP_ID.write() {
41         *lock = id;
42     }
43 }
44 
45 pub fn is_fullscreen() -> bool {
46     *FULLSCREEN.read().unwrap()
47 }
48 
49 pub fn set_fullscreen(fs: bool) {
50     if let Ok(mut lock) = FULLSCREEN.write() {
51         *lock = fs;
52     }
53 }
54 
55 pub fn is_maximized() -> bool {
56     *MAXIMIZED.read().unwrap()
57 }
58 
59 pub fn set_maximized(m: bool) {
60     if let Ok(mut lock) = MAXIMIZED.write() {
61         *lock = m;
62     }
63 }