mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-11 13:51:01 -05:00
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.
This commit is contained in:
parent
8f88b4d4be
commit
791f79a02a
4 changed files with 27 additions and 20 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue