aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs25
-rw-r--r--src/config/mod.rs17
-rw-r--r--src/display.rs8
-rw-r--r--src/window.rs9
4 files changed, 52 insertions, 7 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 63faa5b5..12d3ade0 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -15,7 +15,7 @@ use ::log;
use clap::{Arg, App, crate_name, crate_version, crate_authors, crate_description};
use crate::index::{Line, Column};
-use crate::config::{Dimensions, Shell};
+use crate::config::{Dimensions, Delta, Shell};
use crate::window::{DEFAULT_NAME};
use std::path::{Path, PathBuf};
use std::borrow::Cow;
@@ -26,6 +26,7 @@ pub struct Options {
pub print_events: bool,
pub ref_test: bool,
pub dimensions: Option<Dimensions>,
+ pub position: Option<Delta<i32>>,
pub title: Option<String>,
pub class: Option<String>,
pub log_level: log::LevelFilter,
@@ -42,6 +43,7 @@ impl Default for Options {
print_events: false,
ref_test: false,
dimensions: None,
+ position: None,
title: None,
class: None,
log_level: log::LevelFilter::Warn,
@@ -73,7 +75,8 @@ impl Options {
.help("Disable automatic config reloading")
.conflicts_with("live-config-reload"))
.arg(Arg::with_name("print-events")
- .long("print-events"))
+ .long("print-events")
+ .help("Print all events to stdout"))
.arg(Arg::with_name("persistent-logging")
.long("persistent-logging")
.help("Keep the log file after quitting Alacritty"))
@@ -83,6 +86,12 @@ impl Options {
.value_names(&["columns", "lines"])
.help("Defines the window dimensions. Falls back to size specified by \
window manager if set to 0x0 [default: 0x0]"))
+ .arg(Arg::with_name("position")
+ .long("position")
+ .allow_hyphen_values(true)
+ .value_names(&["x-pos", "y-pos"])
+ .help("Defines the window position. Falls back to position specified by \
+ window manager if unset [default: unset]"))
.arg(Arg::with_name("title")
.long("title")
.short("t")
@@ -147,6 +156,14 @@ impl Options {
}
}
+ if let Some(mut position) = matches.values_of("position") {
+ let x = position.next().map(|x| x.parse::<i32>());
+ let y = position.next().map(|y| y.parse::<i32>());
+ if let (Some(Ok(x)), Some(Ok(y))) = (x, y) {
+ options.position = Some(Delta { x, y });
+ }
+ }
+
options.class = matches.value_of("class").map(|c| c.to_owned());
options.title = matches.value_of("title").map(|t| t.to_owned());
@@ -187,6 +204,10 @@ impl Options {
self.dimensions
}
+ pub fn position(&self) -> Option<Delta<i32>> {
+ self.position
+ }
+
pub fn command(&self) -> Option<&Shell<'_>> {
self.command.as_ref()
}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 3f0cd0bb..4b9e1f8e 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -414,6 +414,10 @@ pub struct WindowConfig {
#[serde(default, deserialize_with = "failure_default")]
dimensions: Dimensions,
+ /// Initial position
+ #[serde(default, deserialize_with = "failure_default")]
+ position: Option<Delta<i32>>,
+
/// Pixel padding
#[serde(deserialize_with = "deserialize_padding")]
padding: Delta<u8>,
@@ -435,6 +439,7 @@ impl Default for WindowConfig {
fn default() -> Self {
WindowConfig{
dimensions: Default::default(),
+ position: Default::default(),
padding: default_padding(),
decorations: Default::default(),
dynamic_padding: Default::default(),
@@ -476,10 +481,6 @@ impl WindowConfig {
/// Top-level config type
#[derive(Debug, PartialEq, Deserialize)]
pub struct Config {
- /// Initial dimensions
- #[serde(default, deserialize_with = "failure_default")]
- dimensions: Option<Dimensions>,
-
/// Pixel padding
#[serde(default, deserialize_with = "failure_default")]
padding: Option<Delta<u8>>,
@@ -582,6 +583,9 @@ pub struct Config {
// TODO: DEPRECATED
unfocused_hollow_cursor: Option<bool>,
+
+ // TODO: DEPRECATED
+ dimensions: Option<Dimensions>,
}
impl Default for Config {
@@ -1756,6 +1760,11 @@ impl Config {
self.dimensions.unwrap_or(self.window.dimensions)
}
+ #[inline]
+ pub fn position(&self) -> Option<Delta<i32>> {
+ self.window.position
+ }
+
/// Get window config
#[inline]
pub fn window(&self) -> &WindowConfig {
diff --git a/src/display.rs b/src/display.rs
index 4873e02a..8266e655 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -140,6 +140,14 @@ impl Display {
// Create the window where Alacritty will be displayed
let mut window = Window::new(&options, config.window())?;
+ // TODO: replace `set_position` with `with_position` once available
+ // Upstream issue: https://github.com/tomaka/winit/issues/806
+ // Set window position early so it doesn't "teleport"
+ let position = options.position().or_else(|| config.position());
+ if let Some(position) = position {
+ window.set_position(position.x, position.y);
+ }
+
let dpr = window.hidpi_factor();
info!("Device pixel ratio: {}", dpr);
diff --git a/src/window.rs b/src/window.rs
index cceffcab..54f0b887 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -24,7 +24,7 @@ use glutin::{
self, ContextBuilder, ControlFlow, Event, EventsLoop,
MouseCursor as GlutinMouseCursor, WindowBuilder,
};
-use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
+use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
use crate::cli::Options;
use crate::config::{Decorations, WindowConfig};
@@ -182,6 +182,13 @@ impl Window {
self.window.set_inner_size(size);
}
+ // TODO: use `with_position` once available
+ // Upstream issue: https://github.com/tomaka/winit/issues/806
+ pub fn set_position(&mut self, x: i32, y: i32) {
+ let logical = PhysicalPosition::from((x, y)).to_logical(self.window.get_hidpi_factor());
+ self.window.set_position(logical);
+ }
+
#[inline]
pub fn hidpi_factor(&self) -> f64 {
self.window.get_hidpi_factor()