Skip to content

Commit

Permalink
add xcursor_theme and xcursor_size config options
Browse files Browse the repository at this point in the history
refs: #1742
  • Loading branch information
wez committed Mar 22, 2022
1 parent 409ff74 commit 9936b8a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
6 changes: 6 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,12 @@ pub struct Config {

#[serde(default)]
pub default_workspace: Option<String>,

#[serde(default)]
pub xcursor_theme: Option<String>,

#[serde(default)]
pub xcursor_size: Option<u32>,
}
impl_lua_conversion!(Config);

Expand Down
8 changes: 3 additions & 5 deletions window/src/os/wayland/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
//! in smithay_client_toolkit 0.11 which is Copyright (c) 2018 Victor Berger
//! and provided under the terms of the MIT license.
use crate::os::wayland::pointer::make_theme_manager;
use config::{ConfigHandle, RgbColor, WindowFrameConfig};
use smithay_client_toolkit::output::{add_output_listener, with_output_info, OutputListener};
use smithay_client_toolkit::seat::pointer::{ThemeManager, ThemeSpec, ThemedPointer};
use smithay_client_toolkit::seat::pointer::{ThemeManager, ThemedPointer};
use smithay_client_toolkit::shm::DoubleMemPool;
use smithay_client_toolkit::window::{ButtonState, Frame, FrameRequest, State, WindowState};
use std::cell::RefCell;
Expand Down Expand Up @@ -544,10 +545,7 @@ impl Frame for ConceptFrame {
let (themer, theme_over_surface) = if let Some(theme_manager) = theme_manager {
(theme_manager, false)
} else {
(
ThemeManager::init(ThemeSpec::System, compositor.clone(), shm.clone()),
true,
)
(make_theme_manager(compositor.clone(), shm.clone()), true)
};

let inner = Rc::new(RefCell::new(Inner {
Expand Down
27 changes: 26 additions & 1 deletion window/src/os/wayland/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,31 @@ impl PendingMouse {
}
}

pub fn make_theme_manager(
compositor: Attached<WlCompositor>,
shm: Attached<WlShm>,
) -> ThemeManager {
let config = config::configuration();
let name = config
.xcursor_theme
.as_ref()
.map(|s| s.to_string())
.or_else(|| std::env::var("XCURSOR_THEME").ok())
.unwrap_or_else(|| "default".to_string());
let size = match config.xcursor_size {
Some(size) => size,
None => match std::env::var("XCURSOR_SIZE").ok() {
Some(size_str) => size_str.parse().ok(),
None => None,
}
.unwrap_or(24),
};

let theme = ThemeSpec::Precise { name: &name, size };

ThemeManager::init(theme, compositor, shm)
}

impl PointerDispatcher {
pub fn register(
seat: &WlSeat,
Expand All @@ -240,7 +265,7 @@ impl PointerDispatcher {
}
});

let themer = ThemeManager::init(ThemeSpec::System, compositor, shm);
let themer = make_theme_manager(compositor, shm);
let auto_pointer = themer.theme_pointer(pointer.detach());

let data_device = dev_mgr.get_data_device(seat);
Expand Down
17 changes: 13 additions & 4 deletions window/src/os/x11/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::x11::XConnection;
use crate::MouseCursor;
use anyhow::{ensure, Context};
use config::ConfigHandle;
use std::collections::HashMap;
use std::convert::TryInto;
use std::ffi::OsStr;
Expand Down Expand Up @@ -84,7 +85,11 @@ fn icon_path() -> Vec<PathBuf> {
std::env::split_paths(&path).map(tilde_expand).collect()
}

fn cursor_size(map: &HashMap<String, String>) -> u32 {
fn cursor_size(xcursor_size: &Option<u32>, map: &HashMap<String, String>) -> u32 {
if let Some(size) = xcursor_size {
return *size;
}

if let Ok(size) = std::env::var("XCURSOR_SIZE") {
if let Ok(size) = size.parse::<u32>() {
return size;
Expand All @@ -108,7 +113,7 @@ fn cursor_size(map: &HashMap<String, String>) -> u32 {
}

impl CursorInfo {
pub fn new(conn: &Rc<XConnection>) -> Self {
pub fn new(config: &ConfigHandle, conn: &Rc<XConnection>) -> Self {
let mut size = None;
let mut theme = None;
let mut pict_format_id = None;
Expand All @@ -128,8 +133,12 @@ impl CursorInfo {
{
// 0.5 and later have the required support
if (vers.major_version(), vers.minor_version()) >= (0, 5) {
size.replace(cursor_size(&*conn.xrm.borrow()));
theme = conn.xrm.borrow().get("Xcursor.theme").cloned();
size.replace(cursor_size(&config.xcursor_size, &*conn.xrm.borrow()));
theme = config
.xcursor_theme
.as_ref()
.map(|s| s.to_string())
.or_else(|| conn.xrm.borrow().get("Xcursor.theme").cloned());

// Locate the Pictformat corresponding to ARGB32
if let Ok(formats) = xcb::render::query_pict_formats(conn.conn()).get_reply() {
Expand Down
2 changes: 1 addition & 1 deletion window/src/os/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ impl XWindow {
height: height.try_into()?,
dpi: conn.default_dpi(),
copy_and_paste: CopyAndPaste::default(),
cursors: CursorInfo::new(&conn),
cursors: CursorInfo::new(&config, &conn),
config: config.clone(),
has_focus: false,
last_cursor_position: Rect::default(),
Expand Down

0 comments on commit 9936b8a

Please sign in to comment.