1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Set window title on Wayland

Fixes #1582.
Fixes #1875.
This commit is contained in:
Christian Duerr 2019-02-06 21:10:45 +00:00 committed by GitHub
parent 7eb0ea82ef
commit a7a6bf53d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 53 deletions

View file

@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added
- Window class on Wayland is set to `Alacritty` by default
### Changed ### Changed
- Improve scrolling accuracy with devices sending fractional updates (like touchpads) - Improve scrolling accuracy with devices sending fractional updates (like touchpads)

View file

@ -16,7 +16,7 @@ use clap::{Arg, App, crate_name, crate_version, crate_authors, crate_description
use crate::index::{Line, Column}; use crate::index::{Line, Column};
use crate::config::{Dimensions, Shell}; use crate::config::{Dimensions, Shell};
use crate::window::{DEFAULT_TITLE, DEFAULT_CLASS}; use crate::window::{DEFAULT_NAME};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::borrow::Cow; use std::borrow::Cow;
@ -87,11 +87,11 @@ impl Options {
.long("title") .long("title")
.short("t") .short("t")
.takes_value(true) .takes_value(true)
.help(&format!("Defines the window title [default: {}]", DEFAULT_TITLE))) .help(&format!("Defines the window title [default: {}]", DEFAULT_NAME)))
.arg(Arg::with_name("class") .arg(Arg::with_name("class")
.long("class") .long("class")
.takes_value(true) .takes_value(true)
.help(&format!("Defines window class on X11 [default: {}]", DEFAULT_CLASS))) .help(&format!("Defines window class on X11 [default: {}]", DEFAULT_NAME)))
.arg(Arg::with_name("q") .arg(Arg::with_name("q")
.short("q") .short("q")
.multiple(true) .multiple(true)

View file

@ -33,22 +33,8 @@ use crate::MouseCursor;
#[cfg(windows)] #[cfg(windows)]
static WINDOW_ICON: &'static [u8] = include_bytes!("../assets/windows/alacritty.ico"); static WINDOW_ICON: &'static [u8] = include_bytes!("../assets/windows/alacritty.ico");
/// Default text for the window's title bar, if not overriden. /// Default Alacritty name, used for window title and class.
/// pub const DEFAULT_NAME: &str = "Alacritty";
/// In X11, this the default value for the `WM_NAME` property.
pub const DEFAULT_TITLE: &str = "Alacritty";
/// Default text for general window class, X11 specific.
///
/// In X11, this is the default value for the `WM_CLASS` property. The
/// second value of `WM_CLASS` is **never** changed to anything but
/// the default value.
///
/// ```ignore
/// $ xprop | grep WM_CLASS
/// WM_CLASS(STRING) = "Alacritty", "Alacritty"
/// ```
pub const DEFAULT_CLASS: &str = "Alacritty";
/// Window errors /// Window errors
#[derive(Debug)] #[derive(Debug)]
@ -148,10 +134,9 @@ impl Window {
pub fn new(options: &Options, window_config: &WindowConfig) -> Result<Window> { pub fn new(options: &Options, window_config: &WindowConfig) -> Result<Window> {
let event_loop = EventsLoop::new(); let event_loop = EventsLoop::new();
let title = options.title.as_ref().map_or(DEFAULT_TITLE, |t| t); let title = options.title.as_ref().map_or(DEFAULT_NAME, |t| t);
let class = options.class.as_ref().map_or(DEFAULT_TITLE, |c| c); let class = options.class.as_ref().map_or(DEFAULT_NAME, |c| c);
let window_builder = Window::get_platform_window(title, window_config); let window_builder = Window::get_platform_window(title, class, window_config);
let window_builder = Window::platform_builder_ext(window_builder, &class);
let window = create_gl_window(window_builder.clone(), &event_loop, false) let window = create_gl_window(window_builder.clone(), &event_loop, false)
.or_else(|_| create_gl_window(window_builder, &event_loop, true))?; .or_else(|_| create_gl_window(window_builder, &event_loop, true))?;
window.show(); window.show();
@ -262,35 +247,14 @@ impl Window {
} }
} }
#[cfg(
any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
)
)]
fn platform_builder_ext(window_builder: WindowBuilder, wm_class: &str) -> WindowBuilder {
use glutin::os::unix::WindowBuilderExt;
window_builder.with_class(wm_class.to_owned(), "Alacritty".to_owned())
}
#[cfg(
not(
any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
)
)
)]
fn platform_builder_ext(window_builder: WindowBuilder, _: &str) -> WindowBuilder {
window_builder
}
#[cfg(not(any(target_os = "macos", windows)))] #[cfg(not(any(target_os = "macos", windows)))]
pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder { pub fn get_platform_window(
title: &str,
class: &str,
window_config: &WindowConfig
) -> WindowBuilder {
use glutin::os::unix::WindowBuilderExt;
let decorations = match window_config.decorations() { let decorations = match window_config.decorations() {
Decorations::None => false, Decorations::None => false,
_ => true, _ => true,
@ -302,10 +266,18 @@ impl Window {
.with_transparency(true) .with_transparency(true)
.with_maximized(window_config.start_maximized()) .with_maximized(window_config.start_maximized())
.with_decorations(decorations) .with_decorations(decorations)
// X11
.with_class(class.into(), DEFAULT_NAME.into())
// Wayland
.with_app_id(class.into())
} }
#[cfg(windows)] #[cfg(windows)]
pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder { pub fn get_platform_window(
title: &str,
_class: &str,
window_config: &WindowConfig
) -> WindowBuilder {
let icon = Icon::from_bytes_with_format(WINDOW_ICON, ImageFormat::ICO).unwrap(); let icon = Icon::from_bytes_with_format(WINDOW_ICON, ImageFormat::ICO).unwrap();
let decorations = match window_config.decorations() { let decorations = match window_config.decorations() {
@ -323,7 +295,11 @@ impl Window {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder { pub fn get_platform_window(
title: &str,
_class: &str,
window_config: &WindowConfig
) -> WindowBuilder {
use glutin::os::macos::WindowBuilderExt; use glutin::os::macos::WindowBuilderExt;
let window = WindowBuilder::new() let window = WindowBuilder::new()