summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2022-08-25 08:51:19 +0300
committerGitHub <noreply@github.com>2022-08-25 05:51:19 +0000
commit791f79a02a4bbb509c257af2849e411d32f4c18b (patch)
tree509fe9e6e956dc458234348d4e2eb836a77c1774
parent8f88b4d4bed337d16e8d3d15d8e20cbe782696db (diff)
downloadalacritty-791f79a02a4bbb509c257af2849e411d32f4c18b.tar.gz
alacritty-791f79a02a4bbb509c257af2849e411d32f4c18b.zip
Rework `--class` CLI option
This commit swaps the order of `general` and `instance` arguments and also sets `instance` to `general` when only one argument was provided. This should make this option behave like in other terminals on X11, since they set either both or general by default, but not instance like Alacritty. Fixes #6279.
-rw-r--r--CHANGELOG.md2
-rw-r--r--alacritty/src/cli.rs29
-rw-r--r--alacritty/src/config/window.rs10
-rw-r--r--extra/alacritty.man6
4 files changed, 27 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff19cc77..85364b8e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Warn when either `columns` or `lines` is non-zero, but not both
- Client side decorations should have proper text rendering now on Wayland
- Config option `window.gtk_theme_variant`, you should use `window.decorations_theme_variant` instead
+- `--class` now sets both class part of WM_CLASS property and instance
+- `--class`'s `general` and `instance` options were swapped
### Fixed
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs
index 8872ec99..e9c563d4 100644
--- a/alacritty/src/cli.rs
+++ b/alacritty/src/cli.rs
@@ -11,7 +11,7 @@ use serde_yaml::Value;
use alacritty_terminal::config::{Program, PtyConfig};
-use crate::config::window::{Class, Identity, DEFAULT_NAME};
+use crate::config::window::{Class, Identity};
use crate::config::{serde_utils, UiConfig};
/// CLI options for the main Alacritty executable.
@@ -159,19 +159,16 @@ fn option_as_value(option: &str) -> Result<Value, serde_yaml::Error> {
/// Parse the class CLI parameter.
fn parse_class(input: &str) -> Result<Class, String> {
- match input.find(',') {
- Some(position) => {
- let general = input[position + 1..].to_owned();
-
- // Warn the user if they've passed too many values.
- if general.contains(',') {
- return Err(String::from("Too many parameters"));
- }
-
- Ok(Class { instance: input[..position].into(), general })
+ let (general, instance) = match input.split_once(',') {
+ // Warn the user if they've passed too many values.
+ Some((_, instance)) if instance.contains(',') => {
+ return Err(String::from("Too many parameters"))
},
- None => Ok(Class { instance: input.into(), general: DEFAULT_NAME.into() }),
- }
+ Some((general, instance)) => (general, instance),
+ None => (input, input),
+ };
+
+ Ok(Class::new(general, instance))
}
/// Convert to hex if possible, else decimal
@@ -385,15 +382,15 @@ mod tests {
#[test]
fn parse_instance_class() {
let class = parse_class("one").unwrap();
+ assert_eq!(class.general, "one");
assert_eq!(class.instance, "one");
- assert_eq!(class.general, DEFAULT_NAME);
}
#[test]
fn parse_general_class() {
let class = parse_class("one,two").unwrap();
- assert_eq!(class.instance, "one");
- assert_eq!(class.general, "two");
+ assert_eq!(class.general, "one");
+ assert_eq!(class.instance, "two");
}
#[test]
diff --git a/alacritty/src/config/window.rs b/alacritty/src/config/window.rs
index 8a59a007..80df87b7 100644
--- a/alacritty/src/config/window.rs
+++ b/alacritty/src/config/window.rs
@@ -203,13 +203,19 @@ pub struct Dimensions {
/// Window class hint.
#[derive(Serialize, Debug, Clone, PartialEq, Eq)]
pub struct Class {
- pub instance: String,
pub general: String,
+ pub instance: String,
+}
+
+impl Class {
+ pub fn new(general: impl ToString, instance: impl ToString) -> Self {
+ Self { general: general.to_string(), instance: instance.to_string() }
+ }
}
impl Default for Class {
fn default() -> Self {
- Self { instance: DEFAULT_NAME.into(), general: DEFAULT_NAME.into() }
+ Self::new(DEFAULT_NAME, DEFAULT_NAME)
}
}
diff --git a/extra/alacritty.man b/extra/alacritty.man
index eec20d60..8848938a 100644
--- a/extra/alacritty.man
+++ b/extra/alacritty.man
@@ -32,10 +32,12 @@ Increases the level of verbosity (the max level is \fB\-vvv\fR)
Prints version information
.SH "OPTIONS"
.TP
-\fB\-\-class\fR <instance> | <instance>,<general>
+\fB\-\-class\fR <general> | <general>,<instance>
Defines the window class hint on Linux [default: Alacritty,Alacritty]
-On Wayland the instance class sets the `app_id`, while the general class is ignored.
+When only the general class is passed, instance will be set to the same value.
+
+On Wayland the general class sets the `app_id`, while the instance class is ignored.
.TP
\fB\-e\fR, \fB\-\-command\fR <command>...
Command and args to execute (must be last argument)