mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +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>,
|
device_pixels_per_px: Option<f32>,
|
||||||
user_agent: Option<String>,
|
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.
|
// Implements window methods, used by compositor.
|
||||||
let window = if opts::get().headless {
|
let window = if opts::get().headless {
|
||||||
|
|
|
@ -8,6 +8,8 @@ use servo::embedder_traits::EventLoopWaker;
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
use std::time;
|
use std::time;
|
||||||
use winit;
|
use winit;
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ServoEvent {
|
pub enum ServoEvent {
|
||||||
|
@ -30,17 +32,31 @@ impl EventsLoop {
|
||||||
// Ideally, we could use the winit event loop in both modes,
|
// Ideally, we could use the winit event loop in both modes,
|
||||||
// but on Linux, the event loop requires a X11 server.
|
// but on Linux, the event loop requires a X11 server.
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
#[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())))
|
EventsLoop(EventLoop::Winit(Some(winit::event_loop::EventLoopBuilder::with_user_event().build())))
|
||||||
}
|
}
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[cfg(target_os = "linux")]
|
||||||
pub fn new(headless: bool) -> EventsLoop {
|
pub fn new(headless: bool, _has_output_file: bool) -> EventsLoop {
|
||||||
EventsLoop(if headless {
|
EventsLoop(if headless {
|
||||||
EventLoop::Headless(Arc::new((Mutex::new(false), Condvar::new())))
|
EventLoop::Headless(Arc::new((Mutex::new(false), Condvar::new())))
|
||||||
} else {
|
} else {
|
||||||
EventLoop::Winit(Some(winit::event_loop::EventLoopBuilder::with_user_event().build()))
|
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 {
|
impl EventsLoop {
|
||||||
|
|
|
@ -11,8 +11,6 @@ use euclid::{
|
||||||
Angle, Point2D, Rotation3D, Scale, Size2D, UnknownUnit,
|
Angle, Point2D, Rotation3D, Scale, Size2D, UnknownUnit,
|
||||||
Vector2D, Vector3D,
|
Vector2D, Vector3D,
|
||||||
};
|
};
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
use winit::platform::macos::{ActivationPolicy, WindowBuilderExtMacOS};
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
use winit::window::Icon;
|
use winit::window::Icon;
|
||||||
use winit::event::{ElementState, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
|
use winit::event::{ElementState, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
|
||||||
|
@ -50,21 +48,6 @@ use winapi;
|
||||||
use winit::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
|
use winit::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
|
||||||
use winit::event::ModifiersState;
|
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 {
|
pub struct Window {
|
||||||
winit_window: winit::window::Window,
|
winit_window: winit::window::Window,
|
||||||
webrender_surfman: WebrenderSurfman,
|
webrender_surfman: WebrenderSurfman,
|
||||||
|
@ -117,15 +100,13 @@ impl Window {
|
||||||
let width = win_size.to_untyped().width;
|
let width = win_size.to_untyped().width;
|
||||||
let height = win_size.to_untyped().height;
|
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_title("Servo".to_string())
|
||||||
.with_decorations(!no_native_titlebar)
|
.with_decorations(!no_native_titlebar)
|
||||||
.with_transparent(no_native_titlebar)
|
.with_transparent(no_native_titlebar)
|
||||||
.with_inner_size(PhysicalSize::new(width as f64, height as f64))
|
.with_inner_size(PhysicalSize::new(width as f64, height as f64))
|
||||||
.with_visible(visible);
|
.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.");
|
let winit_window = window_builder.build(events_loop.as_winit()).expect("Failed to create window.");
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
|
@ -508,13 +489,11 @@ impl WindowPortsMethods for Window {
|
||||||
) -> Box<dyn webxr::glwindow::GlWindow> {
|
) -> Box<dyn webxr::glwindow::GlWindow> {
|
||||||
let size = self.winit_window.outer_size();
|
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_title("Servo XR".to_string())
|
||||||
.with_inner_size(size)
|
.with_inner_size(size)
|
||||||
.with_visible(true);
|
.with_visible(true);
|
||||||
|
|
||||||
window_builder = builder_with_platform_options(window_builder);
|
|
||||||
|
|
||||||
let winit_window = window_builder.build(event_loop)
|
let winit_window = window_builder.build(event_loop)
|
||||||
.expect("Failed to create window.");
|
.expect("Failed to create window.");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue