1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 05:42:03 +03:00

add xcursor_theme and xcursor_size config options

refs: #1742
This commit is contained in:
Wez Furlong 2022-03-22 08:23:17 -07:00
parent 409ff74b84
commit 9936b8a5ab
5 changed files with 49 additions and 11 deletions

View File

@ -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);

View File

@ -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;
@ -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 {

View File

@ -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,
@ -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);

View File

@ -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;
@ -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;
@ -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;
@ -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() {

View File

@ -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(),