1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 06:12:16 +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)] #[serde(default)]
pub default_workspace: Option<String>, pub default_workspace: Option<String>,
#[serde(default)]
pub xcursor_theme: Option<String>,
#[serde(default)]
pub xcursor_size: Option<u32>,
} }
impl_lua_conversion!(Config); impl_lua_conversion!(Config);

View File

@ -2,9 +2,10 @@
//! in smithay_client_toolkit 0.11 which is Copyright (c) 2018 Victor Berger //! in smithay_client_toolkit 0.11 which is Copyright (c) 2018 Victor Berger
//! and provided under the terms of the MIT license. //! and provided under the terms of the MIT license.
use crate::os::wayland::pointer::make_theme_manager;
use config::{ConfigHandle, RgbColor, WindowFrameConfig}; use config::{ConfigHandle, RgbColor, WindowFrameConfig};
use smithay_client_toolkit::output::{add_output_listener, with_output_info, OutputListener}; 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::shm::DoubleMemPool;
use smithay_client_toolkit::window::{ButtonState, Frame, FrameRequest, State, WindowState}; use smithay_client_toolkit::window::{ButtonState, Frame, FrameRequest, State, WindowState};
use std::cell::RefCell; use std::cell::RefCell;
@ -544,10 +545,7 @@ impl Frame for ConceptFrame {
let (themer, theme_over_surface) = if let Some(theme_manager) = theme_manager { let (themer, theme_over_surface) = if let Some(theme_manager) = theme_manager {
(theme_manager, false) (theme_manager, false)
} else { } else {
( (make_theme_manager(compositor.clone(), shm.clone()), true)
ThemeManager::init(ThemeSpec::System, compositor.clone(), shm.clone()),
true,
)
}; };
let inner = Rc::new(RefCell::new(Inner { 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 { impl PointerDispatcher {
pub fn register( pub fn register(
seat: &WlSeat, 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 auto_pointer = themer.theme_pointer(pointer.detach());
let data_device = dev_mgr.get_data_device(seat); let data_device = dev_mgr.get_data_device(seat);

View File

@ -1,6 +1,7 @@
use crate::x11::XConnection; use crate::x11::XConnection;
use crate::MouseCursor; use crate::MouseCursor;
use anyhow::{ensure, Context}; use anyhow::{ensure, Context};
use config::ConfigHandle;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryInto; use std::convert::TryInto;
use std::ffi::OsStr; use std::ffi::OsStr;
@ -84,7 +85,11 @@ fn icon_path() -> Vec<PathBuf> {
std::env::split_paths(&path).map(tilde_expand).collect() 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) = std::env::var("XCURSOR_SIZE") {
if let Ok(size) = size.parse::<u32>() { if let Ok(size) = size.parse::<u32>() {
return size; return size;
@ -108,7 +113,7 @@ fn cursor_size(map: &HashMap<String, String>) -> u32 {
} }
impl CursorInfo { impl CursorInfo {
pub fn new(conn: &Rc<XConnection>) -> Self { pub fn new(config: &ConfigHandle, conn: &Rc<XConnection>) -> Self {
let mut size = None; let mut size = None;
let mut theme = None; let mut theme = None;
let mut pict_format_id = None; let mut pict_format_id = None;
@ -128,8 +133,12 @@ impl CursorInfo {
{ {
// 0.5 and later have the required support // 0.5 and later have the required support
if (vers.major_version(), vers.minor_version()) >= (0, 5) { if (vers.major_version(), vers.minor_version()) >= (0, 5) {
size.replace(cursor_size(&*conn.xrm.borrow())); size.replace(cursor_size(&config.xcursor_size, &*conn.xrm.borrow()));
theme = conn.xrm.borrow().get("Xcursor.theme").cloned(); 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 // Locate the Pictformat corresponding to ARGB32
if let Ok(formats) = xcb::render::query_pict_formats(conn.conn()).get_reply() { 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()?, height: height.try_into()?,
dpi: conn.default_dpi(), dpi: conn.default_dpi(),
copy_and_paste: CopyAndPaste::default(), copy_and_paste: CopyAndPaste::default(),
cursors: CursorInfo::new(&conn), cursors: CursorInfo::new(&config, &conn),
config: config.clone(), config: config.clone(),
has_focus: false, has_focus: false,
last_cursor_position: Rect::default(), last_cursor_position: Rect::default(),