Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix window positioning issue on macOS #7839

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Build failure when compiling with x11 feature on NetBSD
- Hint `Select` action selecting the entire line for URL escapes
- Kitty encoding used for regular keys when they don't carry text
- Configuration window position dependency on macOS window size
- Limitation on the width of configuration windows on macOS

### Changed

Expand Down
14 changes: 14 additions & 0 deletions alacritty/src/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use log::{debug, info};
use parking_lot::MutexGuard;
use raw_window_handle::RawWindowHandle;
use serde::{Deserialize, Serialize};
#[cfg(target_os = "macos")]
use winit::dpi::PhysicalPosition;
use winit::dpi::PhysicalSize;
use winit::keyboard::ModifiersState;
use winit::window::CursorIcon;
Expand Down Expand Up @@ -411,12 +413,23 @@ impl Display {
let metrics = glyph_cache.font_metrics();
let (cell_width, cell_height) = compute_cell_size(config, &metrics);

// In macOS, for keeping the window position after resizing
// at the top left window corner, it must be visible.
#[cfg(target_os = "macos")]
window.set_visible(true);

// Resize the window to account for the user configured size.
if let Some(dimensions) = config.window.dimensions() {
let size = window_size(config, dimensions, cell_width, cell_height, scale_factor);
window.request_inner_size(size);
}

// Set the window position to account for the user configured position.
#[cfg(target_os = "macos")]
if let Some(position) = config.window.position {
window.set_outer_position(PhysicalPosition::new(position.x as u32, position.y as u32));
}
Comment on lines +428 to +431
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you just add this using trial and error? We're already setting the position on startup, why are you setting it again?

This does not seem like the proper solution, it just looks like we're moving it a bunch hoping that one of the operations will stick.


// Create the GL surface to draw into.
let surface = renderer::platform::create_gl_surface(
&gl_context,
Expand Down Expand Up @@ -479,6 +492,7 @@ impl Display {
window.set_resize_increments(PhysicalSize::new(cell_width, cell_height));
}

#[cfg(not(target_os = "macos"))]
window.set_visible(true);

#[allow(clippy::single_match)]
Expand Down
6 changes: 6 additions & 0 deletions alacritty/src/display/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ impl Window {
let _ = self.window.request_inner_size(size);
}

#[inline]
#[cfg(target_os = "macos")]
pub fn set_outer_position(&self, position: PhysicalPosition<u32>) {
self.window.set_outer_position(position);
}

#[inline]
pub fn inner_size(&self) -> PhysicalSize<u32> {
self.window.inner_size()
Expand Down