mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Fix macOS extensions in winit.
This commit is contained in:
parent
f89602948e
commit
f64814f249
3 changed files with 22 additions and 27 deletions
|
@ -40,7 +40,7 @@ impl App {
|
|||
device_pixels_per_px: Option<f32>,
|
||||
user_agent: Option<String>,
|
||||
) {
|
||||
let events_loop = EventsLoop::new(opts::get().headless);
|
||||
let events_loop = EventsLoop::new(opts::get().headless, opts::get().output_file.is_some());
|
||||
|
||||
// Implements window methods, used by compositor.
|
||||
let window = if opts::get().headless {
|
||||
|
|
|
@ -8,6 +8,8 @@ use servo::embedder_traits::EventLoopWaker;
|
|||
use std::sync::{Arc, Condvar, Mutex};
|
||||
use std::time;
|
||||
use winit;
|
||||
#[cfg(target_os = "macos")]
|
||||
use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ServoEvent {
|
||||
|
@ -30,17 +32,31 @@ impl EventsLoop {
|
|||
// Ideally, we could use the winit event loop in both modes,
|
||||
// but on Linux, the event loop requires a X11 server.
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
pub fn new(_headless: bool) -> EventsLoop {
|
||||
pub fn new(_headless: bool, _has_output_file: bool) -> EventsLoop {
|
||||
EventsLoop(EventLoop::Winit(Some(winit::event_loop::EventLoopBuilder::with_user_event().build())))
|
||||
}
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
pub fn new(headless: bool) -> EventsLoop {
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn new(headless: bool, _has_output_file: bool) -> EventsLoop {
|
||||
EventsLoop(if headless {
|
||||
EventLoop::Headless(Arc::new((Mutex::new(false), Condvar::new())))
|
||||
} else {
|
||||
EventLoop::Winit(Some(winit::event_loop::EventLoopBuilder::with_user_event().build()))
|
||||
})
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn new(headless: bool, _has_output_file: bool) -> EventsLoop {
|
||||
EventsLoop(if headless {
|
||||
EventLoop::Headless(Arc::new((Mutex::new(false), Condvar::new())))
|
||||
} else {
|
||||
let mut event_loop_builder = winit::event_loop::EventLoopBuilder::with_user_event();
|
||||
if _has_output_file {
|
||||
// Prevent the window from showing in Dock.app, stealing focus,
|
||||
// when generating an output file.
|
||||
event_loop_builder.with_activation_policy(ActivationPolicy::Prohibited);
|
||||
}
|
||||
EventLoop::Winit(Some(event_loop_builder.build()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl EventsLoop {
|
||||
|
|
|
@ -11,8 +11,6 @@ use euclid::{
|
|||
Angle, Point2D, Rotation3D, Scale, Size2D, UnknownUnit,
|
||||
Vector2D, Vector3D,
|
||||
};
|
||||
#[cfg(target_os = "macos")]
|
||||
use winit::platform::macos::{ActivationPolicy, WindowBuilderExtMacOS};
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
use winit::window::Icon;
|
||||
use winit::event::{ElementState, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
|
||||
|
@ -50,21 +48,6 @@ use winapi;
|
|||
use winit::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
|
||||
use winit::event::ModifiersState;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn builder_with_platform_options(mut builder: winit::window::WindowBuilder) -> winit::window::WindowBuilder {
|
||||
if opts::get().output_file.is_some() {
|
||||
// Prevent the window from showing in Dock.app, stealing focus,
|
||||
// when generating an output file.
|
||||
builder = builder.with_activation_policy(ActivationPolicy::Prohibited)
|
||||
}
|
||||
builder
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
fn builder_with_platform_options(builder: winit::window::WindowBuilder) -> winit::window::WindowBuilder {
|
||||
builder
|
||||
}
|
||||
|
||||
pub struct Window {
|
||||
winit_window: winit::window::Window,
|
||||
webrender_surfman: WebrenderSurfman,
|
||||
|
@ -117,15 +100,13 @@ impl Window {
|
|||
let width = win_size.to_untyped().width;
|
||||
let height = win_size.to_untyped().height;
|
||||
|
||||
let mut window_builder = winit::window::WindowBuilder::new()
|
||||
let window_builder = winit::window::WindowBuilder::new()
|
||||
.with_title("Servo".to_string())
|
||||
.with_decorations(!no_native_titlebar)
|
||||
.with_transparent(no_native_titlebar)
|
||||
.with_inner_size(PhysicalSize::new(width as f64, height as f64))
|
||||
.with_visible(visible);
|
||||
|
||||
window_builder = builder_with_platform_options(window_builder);
|
||||
|
||||
let winit_window = window_builder.build(events_loop.as_winit()).expect("Failed to create window.");
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
|
@ -508,13 +489,11 @@ impl WindowPortsMethods for Window {
|
|||
) -> Box<dyn webxr::glwindow::GlWindow> {
|
||||
let size = self.winit_window.outer_size();
|
||||
|
||||
let mut window_builder = winit::window::WindowBuilder::new()
|
||||
let window_builder = winit::window::WindowBuilder::new()
|
||||
.with_title("Servo XR".to_string())
|
||||
.with_inner_size(size)
|
||||
.with_visible(true);
|
||||
|
||||
window_builder = builder_with_platform_options(window_builder);
|
||||
|
||||
let winit_window = window_builder.build(event_loop)
|
||||
.expect("Failed to create window.");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue