Skip to content

Commit

Permalink
fix(macOS): Window layers (#220)
Browse files Browse the repository at this point in the history
* Fix macOS layers (fix cursor on first draw and other minor glitches)

* Fix typo and add change file

* Fix fmt
  • Loading branch information
lemarier authored Apr 29, 2021
1 parent 39d6f59 commit d550b2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/macos-layers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fix `macOS` cursors and other minors UI glitch.
15 changes: 8 additions & 7 deletions src/webview/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{

use cocoa::{
appkit::{NSView, NSViewHeightSizable, NSViewWidthSizable},
base::id,
base::{id, YES},
};
use core_graphics::geometry::{CGPoint, CGRect, CGSize};
use objc::{
Expand Down Expand Up @@ -191,9 +191,8 @@ impl InnerWebView {
}

// Resize
let size = window.inner_size().to_logical(window.scale_factor());
let rect = CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(size.width, size.height));
let _: () = msg_send![webview, initWithFrame:rect configuration:config];
let zero = CGRect::new(&CGPoint::new(0., 0.), &CGSize::new(0., 0.));
let _: () = msg_send![webview, initWithFrame:zero configuration:config];
webview.setAutoresizingMask_(NSViewHeightSizable | NSViewWidthSizable);

// Message handler
Expand Down Expand Up @@ -288,9 +287,11 @@ impl InnerWebView {
w.navigate(url.as_str());
}
}

let view = window.ns_view() as id;
view.addSubview_(webview);
// Tell the webview we use layers
let _: () = msg_send![webview, setWantsLayer: YES];
// Inject the web view into the window as main content
let ns_window = window.ns_window() as id;
let _: () = msg_send![ns_window, setContentView: webview];

Ok(w)
}
Expand Down

0 comments on commit d550b2f

Please sign in to comment.