1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 13:21:38 +03:00

macos: support disabling the titlebar

This isn't fully baked yet, so I'm not documenting it yet.
This commit is contained in:
Wez Furlong 2021-03-03 22:47:31 -08:00
parent 783f445c57
commit 4834a29791
5 changed files with 87 additions and 12 deletions

View File

@ -636,6 +636,9 @@ pub struct Config {
#[serde(default)]
pub allow_square_glyphs_to_overflow_width: AllowSquareGlyphOverflow,
#[serde(default)]
pub window_decorations: WindowDecorations,
/// When using FontKitXXX font systems, a set of directories to
/// search ahead of the standard font locations for fonts.
/// Relative paths are taken to be relative to the directory
@ -1157,6 +1160,18 @@ pub struct LoadedConfig {
lua: Option<mlua::Lua>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum WindowDecorations {
Full,
None,
}
impl Default for WindowDecorations {
fn default() -> Self {
Self::Full
}
}
struct PathPossibility {
path: PathBuf,
is_required: bool,

View File

@ -48,4 +48,13 @@ impl WindowConfiguration for ConfigBridge {
fn window_background_opacity(&self) -> f32 {
configuration().window_background_opacity
}
fn decorations(&self) -> ::window::WindowDecorations {
use ::config::WindowDecorations as CWD;
use ::window::WindowDecorations as WD;
match configuration().window_decorations {
CWD::Full => WD::Full,
CWD::None => WD::None,
}
}
}

View File

@ -1,3 +1,4 @@
use crate::WindowDecorations;
use std::sync::{Arc, Mutex};
pub trait WindowConfiguration {
@ -44,6 +45,10 @@ pub trait WindowConfiguration {
fn window_background_opacity(&self) -> f32 {
1.0
}
fn decorations(&self) -> WindowDecorations {
WindowDecorations::default()
}
}
lazy_static::lazy_static! {

View File

@ -78,6 +78,18 @@ pub enum MouseCursor {
SizeLeftRight,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum WindowDecorations {
Full,
None,
}
impl Default for WindowDecorations {
fn default() -> Self {
Self::Full
}
}
#[allow(unused_variables)]
pub trait WindowCallbacks: Any {
/// Called when the window close button is clicked.

View File

@ -6,7 +6,7 @@ use crate::connection::ConnectionOps;
use crate::{
config, Clipboard, Connection, Dimensions, KeyCode, KeyEvent, Modifiers, MouseButtons,
MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, Rect, ScreenPoint, Size,
WindowCallbacks, WindowOps, WindowOpsMut,
WindowCallbacks, WindowDecorations, WindowOps, WindowOpsMut,
};
use anyhow::{anyhow, bail, ensure};
use cocoa::appkit::{
@ -358,10 +358,7 @@ impl Window {
callbacks: Box<dyn WindowCallbacks>,
) -> anyhow::Result<Window> {
unsafe {
let style_mask = NSWindowStyleMask::NSTitledWindowMask
| NSWindowStyleMask::NSClosableWindowMask
| NSWindowStyleMask::NSMiniaturizableWindowMask
| NSWindowStyleMask::NSResizableWindowMask;
let style_mask = decoration_to_mask(config().decorations());
let rect = NSRect::new(
NSPoint::new(0., 0.),
NSSize::new(width as f64, height as f64),
@ -618,6 +615,35 @@ fn screen_point_to_cartesian(point: ScreenPoint) -> NSPoint {
}
impl WindowInner {
fn is_fullscreen(&mut self) -> bool {
if self.is_native_fullscreen() {
true
} else if let Some(window_view) = WindowView::get_this(unsafe { &**self.view }) {
window_view.inner.borrow().fullscreen.is_some()
} else {
false
}
}
fn apply_decorations(&mut self) {
if !self.is_fullscreen() {
let mask = decoration_to_mask(config().decorations());
unsafe {
self.window.setStyleMask_(mask);
/*
NSWindow::setMovableByWindowBackground_(
*self.window,
if mask == NSWindowStyleMask::NSResizableWindowMask {
YES
} else {
NO
},
);
*/
}
}
}
fn toggle_native_fullscreen(&mut self) {
unsafe {
NSWindow::toggleFullScreen_(*self.window, nil);
@ -663,13 +689,8 @@ impl WindowInner {
Some(saved_rect) => unsafe {
// Restore prior dimensions
self.window.orderOut_(nil);
self.window.setStyleMask_(
NSWindowStyleMask::NSTitledWindowMask
| NSWindowStyleMask::NSClosableWindowMask
| NSWindowStyleMask::NSMiniaturizableWindowMask
| NSWindowStyleMask::NSResizableWindowMask,
);
self.window
.setStyleMask_(decoration_to_mask(config().decorations()));
self.window.setFrame_display_(saved_rect, YES);
self.window.makeKeyAndOrderFront_(nil);
self.window.setOpaque_(NO);
@ -833,6 +854,19 @@ impl WindowOpsMut for WindowInner {
fn config_did_change(&mut self) {
self.update_window_shadow();
self.apply_decorations();
}
}
fn decoration_to_mask(decorations: WindowDecorations) -> NSWindowStyleMask {
match decorations {
WindowDecorations::Full => {
NSWindowStyleMask::NSTitledWindowMask
| NSWindowStyleMask::NSClosableWindowMask
| NSWindowStyleMask::NSMiniaturizableWindowMask
| NSWindowStyleMask::NSResizableWindowMask
}
WindowDecorations::None => NSWindowStyleMask::NSResizableWindowMask,
}
}