Merge pull request #1099 from LoipesMas/remember_pos

Add remember_window_position setting
macos-click-through
LoipesMas 3 years ago committed by GitHub
commit 36479dd45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
Cargo.lock generated

@ -2599,6 +2599,7 @@ dependencies = [
"percent-encoding",
"raw-window-handle",
"scopeguard",
"serde",
"smithay-client-toolkit",
"unicode-segmentation",
"wayland-client",

@ -39,7 +39,7 @@ dirs = "2"
rand = "0.7"
pin-project = "0.4.27"
futures = "0.3.12"
glutin = { git = "https://github.com/neovide/glutin", branch = "new-keyboard-all" }
glutin = { git = "https://github.com/neovide/glutin", branch = "new-keyboard-all", features=["serde"] }
winit = { git = "https://github.com/neovide/winit", branch = "new-keyboard-all" }
gl = "0.14.0"
swash = "0.1.4"

@ -9,7 +9,10 @@ use log::trace;
use nvim_rs::Neovim;
use parking_lot::RwLock;
pub use rmpv::Value;
pub use window_geometry::{maybe_save_window_size, parse_window_geometry, DEFAULT_WINDOW_GEOMETRY};
pub use window_geometry::{
load_last_window_position, maybe_save_window_position, maybe_save_window_size,
parse_window_geometry, DEFAULT_WINDOW_GEOMETRY,
};
use crate::bridge::TxWrapper;
use crate::error_handling::ResultPanicExplanation;

@ -1,6 +1,7 @@
use crate::settings::SETTINGS;
use crate::utils::Dimensions;
use crate::window::WindowSettings;
use glutin::dpi::PhysicalPosition;
use std::path::PathBuf;
#[cfg(unix)]
use xdg;
@ -46,6 +47,25 @@ pub fn try_to_load_last_window_size() -> Result<Dimensions, String> {
}
}
pub fn load_last_window_position() -> PhysicalPosition<i32> {
let settings_path = neovim_std_datapath();
let json = std::fs::read_to_string(&settings_path).map_err(|e| e.to_string());
if json.is_err() {
return PhysicalPosition::default();
}
let json = json.unwrap();
let loaded_position: Result<PhysicalPosition<i32>, _> =
serde_json::from_str(&json).map_err(|e| e.to_string());
if loaded_position.is_err() {
return PhysicalPosition::default();
}
let loaded_position = loaded_position.unwrap();
log::debug!("Loaded Window Position: {:?}", loaded_position);
loaded_position
}
pub fn maybe_save_window_size(grid_size: Option<Dimensions>) {
let settings = SETTINGS.get::<WindowSettings>();
let saved_window_size = if settings.remember_window_size {
@ -61,6 +81,20 @@ pub fn maybe_save_window_size(grid_size: Option<Dimensions>) {
std::fs::write(settings_path, json).unwrap();
}
pub fn maybe_save_window_position(position: Option<PhysicalPosition<i32>>) {
let settings = SETTINGS.get::<WindowSettings>();
let saved_window_position = if settings.remember_window_position {
position.unwrap_or_default()
} else {
PhysicalPosition::default()
};
let settings_path = neovim_std_datapath();
let json = serde_json::to_string(&saved_window_position).unwrap();
log::debug!("Saved Window Position: {}", json);
std::fs::write(settings_path, json).unwrap();
}
pub fn parse_window_geometry(geometry: Option<String>) -> Result<Dimensions, String> {
let saved_window_size =
try_to_load_last_window_size().or::<String>(Ok(DEFAULT_WINDOW_GEOMETRY));

@ -30,7 +30,9 @@ use crate::{
redraw_scheduler::REDRAW_SCHEDULER,
renderer::Renderer,
running_tracker::*,
settings::{maybe_save_window_size, SETTINGS},
settings::{
load_last_window_position, maybe_save_window_position, maybe_save_window_size, SETTINGS,
},
utils::Dimensions,
};
use image::{load_from_memory, GenericImageView, Pixel};
@ -270,7 +272,8 @@ pub fn create_window(
.with_window_icon(Some(icon))
.with_maximized(cmd_line_settings.maximized)
.with_transparent(true)
.with_decorations(!cmd_line_settings.frameless);
.with_decorations(!cmd_line_settings.frameless)
.with_position(load_last_window_position());
#[cfg(target_os = "linux")]
let winit_window_builder = winit_window_builder
@ -323,6 +326,13 @@ pub fn create_window(
event_loop.run(move |e, _window_target, control_flow| {
if !RUNNING_TRACKER.is_running() {
maybe_save_window_size(window_wrapper.saved_grid_size);
maybe_save_window_position(
window_wrapper
.windowed_context
.window()
.outer_position()
.ok(),
);
std::process::exit(0);
}

@ -8,6 +8,7 @@ pub struct WindowSettings {
pub fullscreen: bool,
pub iso_layout: bool,
pub remember_window_size: bool,
pub remember_window_position: bool,
pub hide_mouse_when_typing: bool,
}
@ -19,7 +20,8 @@ impl Default for WindowSettings {
iso_layout: false,
refresh_rate: 60,
no_idle: SETTINGS.get::<CmdLineSettings>().no_idle,
remember_window_size: false,
remember_window_size: true,
remember_window_position: true,
hide_mouse_when_typing: false,
}
}

Loading…
Cancel
Save