Skip to content

Commit

Permalink
Implement dragging and resizing of borderless window
Browse files Browse the repository at this point in the history
  • Loading branch information
hborchardt committed May 6, 2024
1 parent 48c088a commit 0967b05
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Notable changes to the `alacritty_terminal` crate are documented in its

## 0.14.0-dev

### Added

- Moving and resizing of windows without decorations by dragging the padding at the top or bottom-right

### Changed

- Pressing `Alt` with unicode input will now add `ESC` like for ASCII input
Expand Down
15 changes: 15 additions & 0 deletions alacritty/src/display/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use {
png::Decoder,
};

use log::debug;
use std::fmt::{self, Display, Formatter};

#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -363,6 +364,20 @@ impl Window {
self.window.set_resize_increments(Some(increments));
}

pub fn drag_window(&self) {
match self.window.drag_window() {
Err(err) => debug!("Unable to initiate dragging the window: {}", err),
Ok(_) => (),
}
}

pub fn drag_resize_window(&self) {
match self.window.drag_resize_window(winit::window::ResizeDirection::SouthEast) {
Err(err) => debug!("Unable to initiate resizing the window: {}", err),
Ok(_) => (),
}
}

/// Toggle the window's fullscreen state.
pub fn toggle_fullscreen(&self) {
self.set_fullscreen(self.window.fullscreen().is_none());
Expand Down
35 changes: 33 additions & 2 deletions alacritty/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use alacritty_terminal::vi_mode::ViMotion;
use alacritty_terminal::vte::ansi::{ClearMode, Handler};

use crate::clipboard::Clipboard;
#[cfg(target_os = "macos")]
use crate::config::window::Decorations;
use crate::config::{Action, BindingMode, MouseAction, SearchAction, UiConfig, ViAction};
use crate::display::hint::HintMatch;
Expand Down Expand Up @@ -450,6 +449,21 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
let inside_text_area = size_info.contains_point(x, y);
let cell_side = self.cell_side(x);

if !inside_text_area && self.ctx.config().window.decorations == Decorations::None {
// North padding of borderless window allows to move the window.
if y < size_info.padding_y() as usize {
self.ctx.window().set_mouse_cursor(CursorIcon::Move);
return;
}
// South-east corner of padding of borderless window allows to resize the window.
else if y > size_info.height() as usize - size_info.padding_y() as usize
&& x > size_info.width() as usize - size_info.padding_x() as usize
{
self.ctx.window().set_mouse_cursor(CursorIcon::SeResize);
return;
}
}

let point = self.ctx.mouse().point(&size_info, display_offset);
let cell_changed = old_point != point;

Expand Down Expand Up @@ -625,7 +639,24 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {

// Load mouse point, treating message bar and padding as the closest cell.
let display_offset = self.ctx.terminal().grid().display_offset();
let point = self.ctx.mouse().point(&self.ctx.size_info(), display_offset);
let size_info = self.ctx.size_info();
let point = self.ctx.mouse().point(&size_info, display_offset);

if self.ctx.config().window.decorations == Decorations::None {
// When clicking the north padding, drag window.
if self.ctx.mouse().y < size_info.padding_y() as usize {
self.ctx.window().drag_window();
return;
}
// When clicking the south-east padding corner, resize window.
if self.ctx.mouse().y > size_info.height() as usize - size_info.padding_y() as usize
&& self.ctx.mouse().x
> size_info.width() as usize - size_info.padding_x() as usize
{
self.ctx.window().drag_resize_window();
return;
}
}

if let MouseButton::Left = button {
self.on_left_click(point)
Expand Down

0 comments on commit 0967b05

Please sign in to comment.