Pi66

pino-rs
Rust notification daemon.
git clone https://git.pi66.xyz/pino-rs

← back to log

remove the bloated screen placement file

author: pixel
date: 2025-05-03 13:09
hash: 893371c151cb8f6379f2c9a98a8154063a4760af

Diffstat:

M

src/config.rs
6 +++-

M

src/main.rs
22 ++++++++++----

D

src/screen.rs
47 ------------------------------
  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
diff --git a/src/config.rs b/src/config.rs
index 8f26304..34b2cdd 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -21,9 +21,11 @@ pub fn generate_config(config_path: PathBuf) {
             b"[screen]
 monitor = 0 # Set the monitor using index

+# Placment: 
+#   top_left  |   top_center  |  top_right
+# bottom_left | bottom_center | bottom_right

-horizontal = \"left\"   #[right] |  [left]
-vertical = \"top\"      # [top]  | [bottom]
+placement = \"top_left\"
 x = 25                  # X access palcement
 y = 55                  # Y access palcement

diff --git a/src/main.rs b/src/main.rs
index 0a3198f..756adb7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,11 @@
 use argh::FromArgs;
+use fltk::app::screen_xywh;
 use serde::Deserialize;
 use std::{fs, io::Write, os::unix::net::UnixStream, path::Path};
 use utils::is_running;

 mod colors;
 mod config;
-mod screen;
 mod ui;
 mod utils;

@@ -62,9 +62,8 @@ struct Config {

 #[derive(Debug, Deserialize)]
 struct Screen {
-    monitor: usize,
-    horizontal: String,
-    vertical: String,
+    monitor: i32,
+    placement: String,
     x: i32,
     y: i32,
     width: i32,
@@ -166,6 +165,7 @@ fn main() {
             ),
         };

+        /*
         let screen = screen::get_size(
             config.screen.monitor,
             config.screen.vertical.as_str(),
@@ -175,9 +175,19 @@ fn main() {
             config.screen.width,
             config.screen.height,
         );
-
+*/
+        let (sx, sy, sw, sh) = screen_xywh(config.screen.monitor);
+        let screen = match config.screen.placement.as_str() {
+            "top_left"       => (sx + config.screen.x, sy + config.screen.y),
+            "top_center"     => (sx + (sw - config.screen.width) / 2, sy + config.screen.y),
+            "top_right"      => (sx + sw - config.screen.width - config.screen.x, sy + config.screen.y),
+            "bottom_left"    => (sx + config.screen.x, sy + sh - config.screen.height - config.screen.y),
+            "bottom_center"  => (sx + (sw - config.screen.width) / 2, sy + sh - config.screen.height - config.screen.y),
+            "bottom_right"   => (sx + sw - config.screen.width - config.screen.x, sy + sh - config.screen.height - config.screen.y),
+            _                => (20, 30),
+        };
         ui::ui(
-            screen,
+            (screen.0,screen.1,config.screen.width,config.screen.height),
             config.frame.font_family,
             (config.border.weight, config.border.radius),
             (config.title.x, config.title.y, config.title.font_size),
diff --git a/src/screen.rs b/src/screen.rs
deleted file mode 100644
index c47efcb..0000000
--- a/src/screen.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-use fltk::app;
-
-pub fn get_size(
-    monitor: usize,
-    v: &str,
-    h: &str,
-    ax: i32,
-    ay: i32,
-    aw: i32,
-    ah: i32,
-) -> (i32, i32, i32, i32) {
-    let mut screens = vec![];
-
-    for screen in 0..app::screen_count() {
-        screens.push(app::screen_xywh(screen));
-    }
-
-    if h.to_lowercase() == "left" {
-        if v.to_lowercase() == "top" {
-            return (screens[monitor].0 + ax, ay + screens[monitor].1, aw, ah);
-        } else if v.to_lowercase() == "bottom" {
-            return (
-                screens[monitor].0 + ax,
-                screens[monitor].1 + screens[monitor].3 - ah - ay,
-                aw,
-                ah,
-            );
-        }
-    } else if h.to_lowercase() == "right" {
-        if v.to_lowercase() == "top" {
-            return (
-                screens[monitor].0 + screens[monitor].2 - aw - ax,
-                screens[monitor].1 + ay,
-                aw,
-                ah,
-            );
-        } else if v.to_lowercase() == "bottom" {
-            return (
-                screens[monitor].0 + screens[monitor].2 - aw - ax,
-                screens[monitor].1 + screens[monitor].3 - ah - ay,
-                aw,
-                ah,
-            );
-        }
-    }
-    (0, 0, 100, 100)
-}