Merge branch 'master' of github.com:xsoder/oxwm
Browse files
+27 −32 flake.nix
| @@ -3,39 +3,34 @@ | ||
| 3 | 3 | |
| 4 | 4 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; |
| 5 | 5 | |
| 6 | - outputs = | |
| 7 | - { self | |
| 8 | - , nixpkgs | |
| 9 | - , | |
| 10 | - }: | |
| 11 | - let | |
| 12 | - system = "x86_64-linux"; | |
| 13 | - pkgs = import nixpkgs { inherit system; }; | |
| 14 | - in | |
| 15 | - { | |
| 16 | - devShells.${system}.default = pkgs.mkShell { | |
| 17 | - buildInputs = [ | |
| 18 | - pkgs.rustc | |
| 19 | - pkgs.cargo | |
| 20 | - pkgs.alacritty | |
| 21 | - pkgs.just | |
| 22 | - pkgs.xorg.libX11 | |
| 23 | - pkgs.xorg.libXft | |
| 24 | - pkgs.xorg.libXrender | |
| 25 | - pkgs.freetype | |
| 26 | - pkgs.fontconfig | |
| 27 | - pkgs.pkg-config | |
| 28 | - ]; | |
| 6 | + outputs = { | |
| 7 | + self, | |
| 8 | + nixpkgs, | |
| 9 | + }: let | |
| 10 | + system = "x86_64-linux"; | |
| 11 | + pkgs = import nixpkgs {inherit system;}; | |
| 12 | + in { | |
| 13 | + devShells.${system}.default = pkgs.mkShell { | |
| 14 | + buildInputs = [ | |
| 15 | + pkgs.rustc | |
| 16 | + pkgs.cargo | |
| 17 | + pkgs.alacritty | |
| 18 | + pkgs.just | |
| 19 | + pkgs.xorg.libX11 | |
| 20 | + pkgs.xorg.libXft | |
| 21 | + pkgs.xorg.libXrender | |
| 22 | + pkgs.freetype | |
| 23 | + pkgs.fontconfig | |
| 24 | + pkgs.pkg-config | |
| 25 | + ]; | |
| 29 | 26 | |
| 30 | - shellHook = '' | |
| 31 | - export PKG_CONFIG_PATH="${pkgs.xorg.libX11.dev}/lib/pkgconfig:${pkgs.xorg.libXft.dev}/lib/pkgconfig:${pkgs.xorg.libXrender.dev}/lib/pkgconfig:${pkgs.freetype.dev}/lib/pkgconfig:${pkgs.fontconfig.dev}/lib/pkgconfig:$PKG_CONFIG_PATH" | |
| 27 | + shellHook = '' | |
| 28 | + export PS1="(oxwm-dev) $PS1" | |
| 29 | + ''; | |
| 32 | 30 | |
| 33 | - export PS1="(oxwm-dev) $PS1" | |
| 34 | - ''; | |
| 35 | - | |
| 36 | - RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; | |
| 37 | - }; | |
| 38 | - | |
| 39 | - formatter.${system} = pkgs.alejandra; | |
| 31 | + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; | |
| 40 | 32 | }; |
| 33 | + | |
| 34 | + formatter.${system} = pkgs.alejandra; | |
| 35 | + }; | |
| 41 | 36 | } |
+2 −2 src/bar/bar.rs
| @@ -40,7 +40,7 @@ impl Bar { | ||
| 40 | 40 | } |
| 41 | 41 | let font = Font::new(display, screen_num as i32, FONT)?; |
| 42 | 42 | |
| 43 | - let height = (font.height() as f32 * 1.5) as u16; | |
| 43 | + let height = (font.height() as f32 * 1.4) as u16; | |
| 44 | 44 | |
| 45 | 45 | connection.create_window( |
| 46 | 46 | COPY_DEPTH_FROM_PARENT, |
| @@ -297,7 +297,7 @@ impl Bar { | ||
| 297 | 297 | } |
| 298 | 298 | current_x_position += tag_width as i16; |
| 299 | 299 | } |
| 300 | - None | |
| 300 | + return None; | |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | pub fn needs_redraw(&self) -> bool { |
+4 −0 src/bar/blocks/mod.rs
| @@ -3,10 +3,12 @@ use std::time::Duration; | ||
| 3 | 3 | |
| 4 | 4 | mod battery; |
| 5 | 5 | mod datetime; |
| 6 | +mod ram; | |
| 6 | 7 | mod shell; |
| 7 | 8 | |
| 8 | 9 | use battery::Battery; |
| 9 | 10 | use datetime::DateTime; |
| 11 | +use ram::Ram; | |
| 10 | 12 | use shell::ShellBlock; |
| 11 | 13 | |
| 12 | 14 | pub trait Block { |
| @@ -31,6 +33,7 @@ pub enum BlockCommand { | ||
| 31 | 33 | format_discharging: &'static str, |
| 32 | 34 | format_full: &'static str, |
| 33 | 35 | }, |
| 36 | + Ram, | |
| 34 | 37 | Static(&'static str), |
| 35 | 38 | } |
| 36 | 39 | |
| @@ -60,6 +63,7 @@ impl BlockConfig { | ||
| 60 | 63 | self.interval_secs, |
| 61 | 64 | self.color, |
| 62 | 65 | )), |
| 66 | + BlockCommand::Ram => Box::new(Ram::new(self.format, self.interval_secs, self.color)), | |
| 63 | 67 | BlockCommand::Static(text) => Box::new(StaticBlock::new( |
| 64 | 68 | &format!("{}{}", self.format, text), |
| 65 | 69 | self.color, |
+79 −0 src/bar/blocks/ram.rs new file mode 100644
| @@ -0,0 +1,79 @@ | ||
| 1 | +use super::Block; | |
| 2 | +use anyhow::Result; | |
| 3 | +use std::fs; | |
| 4 | +use std::time::Duration; | |
| 5 | + | |
| 6 | +pub struct Ram { | |
| 7 | + format: String, | |
| 8 | + interval: Duration, | |
| 9 | + color: u32, | |
| 10 | +} | |
| 11 | + | |
| 12 | +impl Ram { | |
| 13 | + pub fn new(format: &str, interval_secs: u64, color: u32) -> Self { | |
| 14 | + Self { | |
| 15 | + format: format.to_string(), | |
| 16 | + interval: Duration::from_secs(interval_secs), | |
| 17 | + color, | |
| 18 | + } | |
| 19 | + } | |
| 20 | + | |
| 21 | + fn get_memory_info(&self) -> Result<(u64, u64, f32)> { | |
| 22 | + let meminfo = fs::read_to_string("/proc/meminfo")?; | |
| 23 | + let mut total: u64 = 0; | |
| 24 | + let mut available: u64 = 0; | |
| 25 | + | |
| 26 | + for line in meminfo.lines() { | |
| 27 | + if line.starts_with("MemTotal:") { | |
| 28 | + total = line | |
| 29 | + .split_whitespace() | |
| 30 | + .nth(1) | |
| 31 | + .and_then(|s| s.parse().ok()) | |
| 32 | + .unwrap_or(0) | |
| 33 | + } else if line.starts_with("MemAvailable:") { | |
| 34 | + available = line | |
| 35 | + .split_whitespace() | |
| 36 | + .nth(1) | |
| 37 | + .and_then(|s| s.parse().ok()) | |
| 38 | + .unwrap_or(0) | |
| 39 | + } | |
| 40 | + } | |
| 41 | + | |
| 42 | + let used = total.saturating_sub(available); | |
| 43 | + let used_gb = used as f32 / 1024.0 / 1024.0; | |
| 44 | + let total_gb = total as f32 / 1024.0 / 1024.0; | |
| 45 | + let percentage = if total > 0 { | |
| 46 | + (used as f32 / total as f32) * 100.0 | |
| 47 | + } else { | |
| 48 | + 0.0 | |
| 49 | + }; | |
| 50 | + | |
| 51 | + Ok((used, total, percentage)) | |
| 52 | + } | |
| 53 | +} | |
| 54 | + | |
| 55 | +impl Block for Ram { | |
| 56 | + fn content(&mut self) -> Result<String> { | |
| 57 | + let (used, total, percentage) = self.get_memory_info()?; | |
| 58 | + | |
| 59 | + let used_gb = used as f32 / 1024.0 / 1024.0; | |
| 60 | + let total_gb = total as f32 / 1024.0 / 1024.0; | |
| 61 | + | |
| 62 | + let result = self | |
| 63 | + .format | |
| 64 | + .replace("{used}", &format!("{:.1}", used_gb)) | |
| 65 | + .replace("{total}", &format!("{:.1}", total_gb)) | |
| 66 | + .replace("{percent}", &format!("{:.1}", percentage)) | |
| 67 | + .replace("{}", &format!("{:.1}", used_gb)); | |
| 68 | + | |
| 69 | + Ok(result) | |
| 70 | + } | |
| 71 | + | |
| 72 | + fn interval(&self) -> Duration { | |
| 73 | + self.interval | |
| 74 | + } | |
| 75 | + | |
| 76 | + fn color(&self) -> u32 { | |
| 77 | + self.color | |
| 78 | + } | |
| 79 | +} |
+33 −5 src/config.rs
| @@ -9,17 +9,30 @@ use x11rb::protocol::xproto::KeyButMask; | ||
| 9 | 9 | pub const BORDER_WIDTH: u32 = 2; |
| 10 | 10 | pub const BORDER_FOCUSED: u32 = 0x6dade3; |
| 11 | 11 | pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb; |
| 12 | +<<<<<<< HEAD | |
| 12 | 13 | pub const FONT: &str = "IosevkaNerdFont:style=Bold:size=10"; |
| 14 | +======= | |
| 15 | +pub const FONT: &str = "JetBrainsMono Nerd Font:style=Bold:size=12"; | |
| 16 | +>>>>>>> 303f7c23b69b0d88c8acc14ec438aca4053017bf | |
| 13 | 17 | |
| 14 | 18 | // ======================================== |
| 15 | 19 | // GAPS (Vanity Gaps) |
| 16 | 20 | // ======================================== |
| 21 | +<<<<<<< HEAD | |
| 17 | 22 | pub const GAPS_ENABLED: bool = false; |
| 18 | 23 | pub const GAP_INNER_HORIZONTAL: u32 = 3; |
| 19 | 24 | pub const GAP_INNER_VERTICAL: u32 = 3; |
| 20 | 25 | pub const GAP_OUTER_HORIZONTAL: u32 = 3; |
| 21 | 26 | pub const GAP_OUTER_VERTICAL: u32 = 3; |
| 22 | 27 | // |
| 28 | +======= | |
| 29 | +pub const GAPS_ENABLED: bool = true; | |
| 30 | +pub const GAP_INNER_HORIZONTAL: u32 = 6; | |
| 31 | +pub const GAP_INNER_VERTICAL: u32 = 6; | |
| 32 | +pub const GAP_OUTER_HORIZONTAL: u32 = 6; | |
| 33 | +pub const GAP_OUTER_VERTICAL: u32 = 6; | |
| 34 | + | |
| 35 | +>>>>>>> 303f7c23b69b0d88c8acc14ec438aca4053017bf | |
| 23 | 36 | // ======================================== |
| 24 | 37 | // DEFAULTS |
| 25 | 38 | // ======================================== |
| @@ -32,7 +45,8 @@ pub const MODKEY: KeyButMask = KeyButMask::MOD4; | ||
| 32 | 45 | // ======================================== |
| 33 | 46 | |
| 34 | 47 | // Base colors |
| 35 | -const GRAY_DARK: u32 = 0x222222; | |
| 48 | +const GRAY_DARK: u32 = 0x1a1b26; | |
| 49 | +const GRAY_SEP: u32 = 0xa9b1d6; | |
| 36 | 50 | const GRAY_MID: u32 = 0x444444; |
| 37 | 51 | const GRAY_LIGHT: u32 = 0xbbbbbb; |
| 38 | 52 | const CYAN: u32 = 0x0db9d7; |
| @@ -139,14 +153,28 @@ pub const STATUS_BLOCKS: &[BlockConfig] = &[ | ||
| 139 | 153 | format_full: " Bat: {}%", |
| 140 | 154 | }, |
| 141 | 155 | interval_secs: 30, |
| 156 | + color: GREEN, | |
| 157 | + underline: true, | |
| 158 | + }, | |
| 159 | + BlockConfig { | |
| 160 | + format: " │ ", | |
| 161 | + command: BlockCommand::Static(""), | |
| 162 | + interval_secs: u64::MAX, | |
| 163 | + color: GRAY_SEP, | |
| 164 | + underline: false, | |
| 165 | + }, | |
| 166 | + BlockConfig { | |
| 167 | + format: " {used}/{total} GB", | |
| 168 | + command: BlockCommand::Ram, | |
| 169 | + interval_secs: 5, | |
| 142 | 170 | color: BLUE, |
| 143 | 171 | underline: true, |
| 144 | 172 | }, |
| 145 | 173 | BlockConfig { |
| 146 | - format: " | ", | |
| 174 | + format: " │ ", | |
| 147 | 175 | command: BlockCommand::Static(""), |
| 148 | 176 | interval_secs: u64::MAX, |
| 149 | - color: GRAY_LIGHT, | |
| 177 | + color: GRAY_SEP, | |
| 150 | 178 | underline: false, |
| 151 | 179 | }, |
| 152 | 180 | BlockConfig { |
| @@ -157,10 +185,10 @@ pub const STATUS_BLOCKS: &[BlockConfig] = &[ | ||
| 157 | 185 | underline: true, |
| 158 | 186 | }, |
| 159 | 187 | BlockConfig { |
| 160 | - format: " | ", | |
| 188 | + format: " │ ", | |
| 161 | 189 | command: BlockCommand::Static(""), |
| 162 | 190 | interval_secs: u64::MAX, |
| 163 | - color: GRAY_LIGHT, | |
| 191 | + color: GRAY_SEP, | |
| 164 | 192 | underline: false, |
| 165 | 193 | }, |
| 166 | 194 | BlockConfig { |