mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Add option for window position at startup
This commit is contained in:
parent
0ec4bd28da
commit
e240da9ab3
10 changed files with 76 additions and 13 deletions
|
@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- MSI installer for Windows is now available
|
||||
- New default key bindings Alt+Home, Alt+End, Alt+PageUp and Alt+PageDown
|
||||
- Dynamic title support on Windows
|
||||
- Ability to specify starting position with the `--position` flag
|
||||
- New configuration field `window.position` allows specifying the starting position
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ _alacritty()
|
|||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
prevprev="${COMP_WORDS[COMP_CWORD-2]}"
|
||||
opts="-h --help -V --version --live-config-reload --no-live-config-reload --persistent-logging --print-events -q -qq -v -vv -vvv --ref-test -e --command --config-file -d --dimensions -t --title --working-directory"
|
||||
opts="-h --help -V --version --live-config-reload --no-live-config-reload --persistent-logging --print-events -q -qq -v -vv -vvv --ref-test -e --command --config-file -d --dimensions --position -t --title --working-directory"
|
||||
|
||||
# If `--command` or `-e` is used, stop completing
|
||||
for i in "${!COMP_WORDS[@]}"; do
|
||||
|
|
|
@ -68,6 +68,11 @@ complete \
|
|||
-l "dimensions" \
|
||||
-d "Window dimensions <columns> <lines>"
|
||||
|
||||
complete \
|
||||
-c alacritty \
|
||||
-l "position" \
|
||||
-d "Window position <x-pos> <y-pos>"
|
||||
|
||||
complete \
|
||||
-c alacritty \
|
||||
-s "e" \
|
||||
|
|
|
@ -16,6 +16,7 @@ _alacritty() {
|
|||
"--ref-test[Generates ref test]" \
|
||||
"--config-file[Specify an alternative config file]:file:_files" \
|
||||
"(-d --dimensions)"{-d,--dimensions}"[Window dimensions]:dimensions:_guard '<->' width: :_guard '<->' length" \
|
||||
"--position[Window position]:position:_guard '<->' x-pos: :_guard '<->' y-pos" \
|
||||
"--title[Defines the window title]:title:" \
|
||||
"--working-directory[Start shell in specified directory]:directory:_dir_list" \
|
||||
"(-e --command)"{-e,--command}"[Execute command (must be last arg)]:program: _command_names -e:*::program arguments: _normal"
|
||||
|
|
|
@ -22,8 +22,9 @@ Disable automatic config reloading
|
|||
.TP
|
||||
\fB\-\-persistent\-logging\fR
|
||||
Keep the log file after quitting Alacritty
|
||||
.HP
|
||||
.TP
|
||||
\fB\-\-print\-events\fR
|
||||
Print all events to stdout
|
||||
.TP
|
||||
\fB\-q\fR
|
||||
Reduces the level of verbosity (the min level is \fB\-qq\fR)
|
||||
|
@ -43,15 +44,16 @@ Defines the window class on X11 [default: Alacritty]
|
|||
.TP
|
||||
\fB\-e\fR, \fB\-\-command\fR <command>...
|
||||
Command and args to execute (must be last argument)
|
||||
.HP
|
||||
.TP
|
||||
\fB\-\-config\-file\fR <config\-file>
|
||||
.IP
|
||||
Specify alternative configuration file [default: $XDG_CONFIG_HOME/alacritty/alacritty.yml]
|
||||
.HP
|
||||
.TP
|
||||
\fB\-d\fR, \fB\-\-dimensions\fR <columns> <lines>
|
||||
.IP
|
||||
Defines the window dimensions. Falls back to size specified by window manager if set to 0x0 [default: 0x0]
|
||||
.TP
|
||||
\fB\-\-position\fR <x-pos> <y-pos>
|
||||
Defines the window position. Falls back to position specified by window manager if unset [default: unset]
|
||||
.TP
|
||||
\fB\-t\fR, \fB\-\-title\fR <title>
|
||||
Defines the window title [default: Alacritty]
|
||||
.TP
|
||||
|
|
|
@ -21,6 +21,14 @@ window:
|
|||
columns: 0
|
||||
lines: 0
|
||||
|
||||
# Window position (changes require restart)
|
||||
#
|
||||
# Specified in number of pixels.
|
||||
# If the position is not set, the window manager will handle the placement.
|
||||
#position:
|
||||
# x: 0
|
||||
# y: 0
|
||||
|
||||
# Window padding (changes require restart)
|
||||
#
|
||||
# Blank space added around the window in pixels. This padding is scaled
|
||||
|
|
25
src/cli.rs
25
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()
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue