aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-01 07:59:28 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-01 08:03:12 +0400
commit8d443c2e841505dd9a09d50dbb24a2a5956ecbd7 (patch)
tree09d98ab7566dc72a34842c5f1083355e62e2eca3 /src/utils.rs
parentd39da3f46112395e5e359efd756e9c510c03e243 (diff)
downloadniri-8d443c2e841505dd9a09d50dbb24a2a5956ecbd7.tar.gz
niri-8d443c2e841505dd9a09d50dbb24a2a5956ecbd7.tar.bz2
niri-8d443c2e841505dd9a09d50dbb24a2a5956ecbd7.zip
Make default cursor respect output scale
First part of https://github.com/YaLTeR/niri/issues/16
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs74
1 files changed, 3 insertions, 71 deletions
diff --git a/src/utils.rs b/src/utils.rs
index f1aca8b2..7113bc92 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,24 +1,15 @@
use std::ffi::OsStr;
-use std::fs::File;
-use std::io::{self, Read};
+use std::io;
use std::os::unix::process::CommandExt;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::time::Duration;
-use anyhow::{anyhow, Context};
+use anyhow::Context;
use directories::UserDirs;
use nix::time::{clock_gettime, ClockId};
-use smithay::backend::allocator::Fourcc;
-use smithay::backend::renderer::element::texture::TextureBuffer;
-use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
-use smithay::utils::{Logical, Physical, Point, Rectangle, Transform};
+use smithay::utils::{Logical, Point, Rectangle};
use time::OffsetDateTime;
-use xcursor::parser::parse_xcursor;
-use xcursor::CursorTheme;
-
-const CURSOR_SIZE: u32 = 24;
-static FALLBACK_CURSOR_DATA: &[u8] = include_bytes!("../resources/cursor.rgba");
pub fn get_monotonic_time() -> Duration {
Duration::from(clock_gettime(ClockId::CLOCK_MONOTONIC).unwrap())
@@ -28,65 +19,6 @@ pub fn center(rect: Rectangle<i32, Logical>) -> Point<i32, Logical> {
rect.loc + rect.size.downscale(2).to_point()
}
-fn load_xcursor() -> anyhow::Result<xcursor::parser::Image> {
- let theme = CursorTheme::load("default");
- let path = theme
- .load_icon("default")
- .ok_or_else(|| anyhow!("no default icon"))?;
- let mut file = File::open(path).context("error opening cursor icon file")?;
- let mut buf = vec![];
- file.read_to_end(&mut buf)
- .context("error reading cursor icon file")?;
- let images = parse_xcursor(&buf).context("error parsing cursor icon file")?;
-
- let nearest_image = images
- .iter()
- .min_by_key(|image| (CURSOR_SIZE as i32 - image.size as i32).abs())
- .unwrap();
- let frame = images
- .iter()
- .find(move |image| {
- image.width == nearest_image.width && image.height == nearest_image.height
- })
- .unwrap();
- Ok(frame.clone())
-}
-
-pub fn load_default_cursor(
- renderer: &mut GlesRenderer,
-) -> (TextureBuffer<GlesTexture>, Point<i32, Physical>) {
- let frame = match load_xcursor() {
- Ok(frame) => frame,
- Err(err) => {
- warn!("error loading xcursor default cursor: {err:?}");
-
- xcursor::parser::Image {
- size: 32,
- width: 64,
- height: 64,
- xhot: 1,
- yhot: 1,
- delay: 1,
- pixels_rgba: Vec::from(FALLBACK_CURSOR_DATA),
- pixels_argb: vec![],
- }
- }
- };
-
- let texture = TextureBuffer::from_memory(
- renderer,
- &frame.pixels_rgba,
- Fourcc::Abgr8888,
- (frame.width as i32, frame.height as i32),
- false,
- 1,
- Transform::Normal,
- None,
- )
- .unwrap();
- (texture, (frame.xhot as i32, frame.yhot as i32).into())
-}
-
pub fn make_screenshot_path() -> anyhow::Result<PathBuf> {
let dirs = UserDirs::new().context("error retrieving home directory")?;
let mut path = dirs.picture_dir().map(|p| p.to_owned()).unwrap_or_else(|| {