summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2019-02-06 00:40:43 +0100
committerChristian Duerr <contact@christianduerr.com>2019-02-06 00:40:43 +0100
commitd4785cd6795e9c06bb711247fb6eeddfafb29b5d (patch)
tree3739687c82a1e551f3375f9d9e393c4424727984
parent84a8837b22c653755128a0fd40e693a8b1737e97 (diff)
Refactor window builder
-rw-r--r--src/cli.rs4
-rw-r--r--src/window.rs68
2 files changed, 23 insertions, 49 deletions
diff --git a/src/cli.rs b/src/cli.rs
index af8346f9..46739998 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -16,7 +16,7 @@ use clap::{Arg, App, crate_name, crate_version, crate_authors, crate_description
use crate::index::{Line, Column};
use crate::config::{Dimensions, Shell};
-use crate::window::{DEFAULT_TITLE, DEFAULT_CLASS};
+use crate::window::{DEFAULT_TITLE};
use std::path::{Path, PathBuf};
use std::borrow::Cow;
@@ -91,7 +91,7 @@ impl Options {
.arg(Arg::with_name("class")
.long("class")
.takes_value(true)
- .help(&format!("Defines window class on X11 [default: {}]", DEFAULT_CLASS)))
+ .help(&format!("Defines window class on X11 [default: {}]", DEFAULT_TITLE)))
.arg(Arg::with_name("q")
.short("q")
.multiple(true)
diff --git a/src/window.rs b/src/window.rs
index 370ed83c..914f6070 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -38,18 +38,6 @@ static WINDOW_ICON: &'static [u8] = include_bytes!("../assets/windows/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
#[derive(Debug)]
pub enum Error {
@@ -150,8 +138,7 @@ impl Window {
let title = options.title.as_ref().map_or(DEFAULT_TITLE, |t| t);
let class = options.class.as_ref().map_or(DEFAULT_TITLE, |c| c);
- let window_builder = Window::get_platform_window(title, window_config);
- let window_builder = Window::platform_builder_ext(window_builder, &class);
+ let window_builder = Window::get_platform_window(title, class, window_config);
let window = create_gl_window(window_builder.clone(), &event_loop, false)
.or_else(|_| create_gl_window(window_builder, &event_loop, true))?;
window.show();
@@ -262,39 +249,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 {
+ #[cfg(not(any(target_os = "macos", windows)))]
+ pub fn get_platform_window(
+ title: &str,
+ class: &str,
+ window_config: &WindowConfig
+ ) -> WindowBuilder {
use glutin::os::unix::WindowBuilderExt;
- window_builder
- // X11
- .with_class(wm_class.to_owned(), "Alacritty".to_owned())
- // Wayland
- .with_app_id("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)))]
- pub fn get_platform_window(title: &str, window_config: &WindowConfig) -> WindowBuilder {
let decorations = match window_config.decorations() {
Decorations::None => false,
_ => true,
@@ -306,10 +268,18 @@ impl Window {
.with_transparency(true)
.with_maximized(window_config.start_maximized())
.with_decorations(decorations)
+ // X11
+ .with_class(class.into(), DEFAULT_TITLE.into())
+ // Wayland
+ .with_app_id(class.into())
}
#[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 decorations = match window_config.decorations() {
@@ -327,7 +297,11 @@ impl Window {
}
#[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;
let window = WindowBuilder::new()