aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Lilienthal <nathan@nixpulvis.com>2018-06-18 01:26:54 -0400
committerChristian Duerr <chrisduerr@users.noreply.github.com>2018-06-18 05:26:54 +0000
commitf55252ec8537e68d0c98a1fac35728a2b596d328 (patch)
tree8a9f879ad803faec66d9a9b4385e4dcd8f358680
parent5ba34d4f9766a55a06ed5e3e44cc384af1b09f65 (diff)
downloadalacritty-f55252ec8537e68d0c98a1fac35728a2b596d328.tar.gz
alacritty-f55252ec8537e68d0c98a1fac35728a2b596d328.zip
Override dynamic_title when --title is specified
-rw-r--r--src/cli.rs24
-rw-r--r--src/config.rs30
-rw-r--r--src/main.rs4
-rw-r--r--src/window.rs23
4 files changed, 61 insertions, 20 deletions
diff --git a/src/cli.rs b/src/cli.rs
index e57caf0d..92b83f6c 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -18,17 +18,14 @@ use config::{Dimensions, Shell};
use std::path::{Path, PathBuf};
use std::borrow::Cow;
-const DEFAULT_TITLE: &str = "Alacritty";
-const DEFAULT_CLASS: &str = "Alacritty";
-
/// Options specified on the command line
pub struct Options {
pub live_config_reload: Option<bool>,
pub print_events: bool,
pub ref_test: bool,
pub dimensions: Option<Dimensions>,
- pub title: String,
- pub class: String,
+ pub title: Option<String>,
+ pub class: Option<String>,
pub log_level: log::LevelFilter,
pub command: Option<Shell<'static>>,
pub working_dir: Option<PathBuf>,
@@ -42,8 +39,8 @@ impl Default for Options {
print_events: false,
ref_test: false,
dimensions: None,
- title: DEFAULT_TITLE.to_owned(),
- class: DEFAULT_CLASS.to_owned(),
+ title: None,
+ class: None,
log_level: log::LevelFilter::Warn,
command: None,
working_dir: None,
@@ -82,11 +79,11 @@ impl Options {
.arg(Arg::with_name("title")
.long("title")
.short("t")
- .default_value(DEFAULT_TITLE)
+ .takes_value(true)
.help("Defines the window title"))
.arg(Arg::with_name("class")
.long("class")
- .default_value(DEFAULT_CLASS)
+ .takes_value(true)
.help("Defines window class on X11"))
.arg(Arg::with_name("q")
.short("q")
@@ -139,13 +136,8 @@ impl Options {
}
}
- if let Some(title) = matches.value_of("title") {
- options.title = title.to_owned();
- }
-
- if let Some(class) = matches.value_of("class") {
- options.class = class.to_owned();
- }
+ options.class = matches.value_of("class").map(|c| c.to_owned());
+ options.title = matches.value_of("title").map(|t| t.to_owned());
match matches.occurrences_of("q") {
0 => {},
diff --git a/src/config.rs b/src/config.rs
index ed69ec5d..539edb61 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -23,6 +23,7 @@ use notify::{Watcher, watcher, DebouncedEvent, RecursiveMode};
use glutin::ModifiersState;
+use cli::Options;
use input::{Action, Binding, MouseBinding, KeyBinding};
use index::{Line, Column};
use ansi::CursorStyle;
@@ -1383,6 +1384,14 @@ impl Config {
Ok(config)
}
+ /// Overrides the `dynamic_title` configuration based on `--title`.
+ pub fn update_dynamic_title(mut self, options: &Options) -> Self {
+ if options.title.is_some() {
+ self.dynamic_title = false;
+ }
+ self
+ }
+
fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
let mut f = fs::File::open(path)?;
let mut contents = String::new();
@@ -1713,6 +1722,7 @@ impl Monitor {
#[cfg(test)]
mod tests {
+ use cli::Options;
use super::Config;
#[cfg(target_os="macos")]
@@ -1733,6 +1743,26 @@ mod tests {
// Sanity check that key bindings are being parsed
assert!(!config.key_bindings.is_empty());
}
+
+ #[test]
+ fn dynamic_title_ignoring_options_by_default() {
+ let config: Config = ::serde_yaml::from_str(ALACRITTY_YML)
+ .expect("deserialize config");
+ let old_dynamic_title = config.dynamic_title;
+ let options = Options::default();
+ let config = config.update_dynamic_title(&options);
+ assert_eq!(old_dynamic_title, config.dynamic_title);
+ }
+
+ #[test]
+ fn dynamic_title_overridden_by_options() {
+ let config: Config = ::serde_yaml::from_str(ALACRITTY_YML)
+ .expect("deserialize config");
+ let mut options = Options::default();
+ options.title = Some("foo".to_owned());
+ let config = config.update_dynamic_title(&options);
+ assert!(!config.dynamic_title);
+ }
}
#[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))]
diff --git a/src/main.rs b/src/main.rs
index b0e507e4..652569be 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -44,7 +44,7 @@ use alacritty::util::fmt::Red;
fn main() {
// Load command line options and config
let options = cli::Options::load();
- let config = load_config(&options);
+ let config = load_config(&options).update_dynamic_title(&options);
// Switch to home directory
#[cfg(target_os = "macos")]
@@ -178,7 +178,7 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
.as_ref()
.and_then(|monitor| monitor.pending_config())
{
- config = new_config;
+ config = new_config.update_dynamic_title(&options);
display.update_config(&config);
processor.update_config(&config);
terminal.update_config(&config);
diff --git a/src/window.rs b/src/window.rs
index ef0d9269..1903360f 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -25,6 +25,23 @@ use MouseCursor;
use cli::Options;
use config::WindowConfig;
+/// Default text for the window's title bar, if not overriden.
+///
+/// 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
#[derive(Debug)]
pub enum Error {
@@ -205,12 +222,14 @@ impl Window {
) -> Result<Window> {
let event_loop = EventsLoop::new();
+ let title = options.title.as_ref().map_or(DEFAULT_TITLE, |t| t);
+ let class = options.class.as_ref().map_or(DEFAULT_CLASS, |c| c);
let window_builder = WindowBuilder::new()
- .with_title(&*options.title)
+ .with_title(title)
.with_visibility(false)
.with_transparency(true)
.with_decorations(window_config.decorations());
- let window_builder = Window::platform_builder_ext(window_builder, &options.class);
+ let window_builder = Window::platform_builder_ext(window_builder, &class);
let window = create_gl_window(window_builder.clone(), &event_loop, false)
.or_else(|_| create_gl_window(window_builder, &event_loop, true))?;
window.show();