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

make alpha work on macos

This commit is contained in:
Wez Furlong 2021-05-06 19:15:14 -07:00
parent 0503abc63a
commit e81fb6e721
2 changed files with 24 additions and 13 deletions

View File

@ -1,6 +1,7 @@
use ::window::*;
use anyhow::Context;
use promise::spawn::spawn;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
pub struct GpuContext {
pub swap_chain: wgpu::SwapChain,
@ -227,6 +228,18 @@ async fn spawn_window() -> anyhow::Result<()> {
is_full_screen: _,
} => {
state.resize(dimensions);
#[cfg(target_os = "macos")]
if let RawWindowHandle::MacOS(h) = win.raw_window_handle() {
use cocoa::base::{id, NO};
use objc::*;
unsafe {
// Allow transparency, as the default for Metal is opaque
let layer: id = msg_send![h.ns_view as id, layer];
let () = msg_send![layer, setOpaque: NO];
}
state.paint()?;
}
}
WindowEvent::MouseEvent(event) => {
state.cursor_pos = event.coords;

View File

@ -17,8 +17,9 @@ use cocoa::appkit::{
NSWindowStyleMask,
};
use cocoa::base::*;
use cocoa::foundation::NSAutoreleasePool;
use cocoa::foundation::{NSArray, NSNotFound, NSPoint, NSRect, NSSize, NSUInteger};
use cocoa::foundation::{
NSArray, NSAutoreleasePool, NSInteger, NSNotFound, NSPoint, NSRect, NSSize, NSUInteger,
};
use config::ConfigHandle;
use core_foundation::base::{CFTypeID, TCFType};
use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName};
@ -39,6 +40,9 @@ use std::rc::Rc;
use std::str::FromStr;
use std::time::Instant;
#[allow(non_upper_case_globals)]
const NSViewLayerContentsPlacementTopLeft: NSInteger = 11;
fn round_away_from_zerof(value: f64) -> f64 {
if value > 0. {
value.max(1.).round()
@ -189,17 +193,6 @@ impl GlContextPair {
}
};
#[allow(non_upper_case_globals)]
unsafe {
use cocoa::foundation::NSInteger;
const NSViewLayerContentsPlacementTopLeft: NSInteger = 11;
let () = msg_send![
view,
setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft
];
}
Ok(Self { context, backend })
}
}
@ -455,6 +448,11 @@ impl Window {
view.initWithFrame_(rect);
view.setAutoresizingMask_(NSViewHeightSizable | NSViewWidthSizable);
let () = msg_send![
*view,
setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft
];
window.setContentView_(*view);
window.setDelegate_(*view);