diff options
| author | Kirill Chibisov <contact@kchibisov.com> | 2023-10-01 17:42:56 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-10-01 17:50:42 +0300 |
| commit | d8a511bbac8d487c537dc325d105c1b07ff9c0cf (patch) | |
| tree | 562c4f77d1ab98f704a6a03f13ca5046b8ad9dd5 /src/cursor.rs | |
| parent | 8d443c2e841505dd9a09d50dbb24a2a5956ecbd7 (diff) | |
| download | niri-d8a511bbac8d487c537dc325d105c1b07ff9c0cf.tar.gz niri-d8a511bbac8d487c537dc325d105c1b07ff9c0cf.tar.bz2 niri-d8a511bbac8d487c537dc325d105c1b07ff9c0cf.zip | |
config/input: add cursor section
This should allow users to configure theme and size for the cursor,
as well as automatically set `XCURSOR_THEME` and `XCURSOR_SIZE` env
variables.
Diffstat (limited to 'src/cursor.rs')
| -rw-r--r-- | src/cursor.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/cursor.rs b/src/cursor.rs index 454cd99b..bfc6e818 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::env; use std::fs::File; use std::io::Read; @@ -10,17 +11,22 @@ use smithay::utils::{Physical, Point, Transform}; use xcursor::parser::{parse_xcursor, Image}; use xcursor::CursorTheme; -const CURSOR_SIZE: i32 = 24; static FALLBACK_CURSOR_DATA: &[u8] = include_bytes!("../resources/cursor.rgba"); pub struct Cursor { images: Vec<Image>, + size: i32, cache: HashMap<i32, (TextureBuffer<GlesTexture>, Point<i32, Physical>)>, } impl Cursor { - pub fn load() -> Self { - let images = match load_xcursor() { + /// Load the said theme as well as set the `XCURSOR_THEME` and `XCURSOR_SIZE` + /// env variables. + pub fn load(theme: &str, size: u8) -> Self { + env::set_var("XCURSOR_THEME", theme); + env::set_var("XCURSOR_SIZE", size.to_string()); + + let images = match load_xcursor(theme) { Ok(images) => images, Err(err) => { warn!("error loading xcursor default cursor: {err:?}"); @@ -40,6 +46,7 @@ impl Cursor { Self { images, + size: size as i32, cache: HashMap::new(), } } @@ -54,7 +61,7 @@ impl Cursor { .or_insert_with_key(|scale| { let _span = tracy_client::span!("create cursor texture"); - let size = CURSOR_SIZE * scale; + let size = self.size * scale; let nearest_image = self .images @@ -86,10 +93,10 @@ impl Cursor { } } -fn load_xcursor() -> anyhow::Result<Vec<Image>> { +fn load_xcursor(theme: &str) -> anyhow::Result<Vec<Image>> { let _span = tracy_client::span!(); - let theme = CursorTheme::load("default"); + let theme = CursorTheme::load(theme); let path = theme .load_icon("default") .ok_or_else(|| anyhow!("no default icon"))?; |
