Redo linux state again (#10452)
With the recent Linux rewrite, I attempted to simplify the number of wrapper structs involved in the Linux code, following the macOS code as an example. Unfortunately, I missed a vital component: pointers to the platform state, held by platform data structures. As we hold all of the platform data structures on Linux, this PR reintroduces a wrapper around the internal state of both the platform and the window. This allows us to close and drop windows correctly. This PR also fixes a performance problem introduced by: https://github.com/zed-industries/zed/pull/10343, where each configure request would add a new frame callback quickly saturating the main thread and slowing everything down. Release Notes: - N/A
This commit is contained in:
parent
8d7f5eab79
commit
9d96ae6e78
3 changed files with 233 additions and 183 deletions
|
@ -45,63 +45,6 @@ pub(crate) const DOUBLE_CLICK_INTERVAL: Duration = Duration::from_millis(400);
|
||||||
pub(crate) const DOUBLE_CLICK_DISTANCE: Pixels = px(5.0);
|
pub(crate) const DOUBLE_CLICK_DISTANCE: Pixels = px(5.0);
|
||||||
pub(crate) const KEYRING_LABEL: &str = "zed-github-account";
|
pub(crate) const KEYRING_LABEL: &str = "zed-github-account";
|
||||||
|
|
||||||
pub struct RcRefCell<T>(Rc<RefCell<T>>);
|
|
||||||
|
|
||||||
impl<T> RcRefCell<T> {
|
|
||||||
pub fn new(value: T) -> Self {
|
|
||||||
RcRefCell(Rc::new(RefCell::new(value)))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[track_caller]
|
|
||||||
pub fn borrow_mut(&self) -> std::cell::RefMut<'_, T> {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
if option_env!("TRACK_BORROW_MUT").is_some() {
|
|
||||||
eprintln!(
|
|
||||||
"borrow_mut-ing {} at {}",
|
|
||||||
type_name::<T>(),
|
|
||||||
Location::caller()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.0.borrow_mut()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[track_caller]
|
|
||||||
pub fn borrow(&self) -> std::cell::Ref<'_, T> {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
if option_env!("TRACK_BORROW_MUT").is_some() {
|
|
||||||
eprintln!("borrow-ing {} at {}", type_name::<T>(), Location::caller());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.0.borrow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Deref for RcRefCell<T> {
|
|
||||||
type Target = Rc<RefCell<T>>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<T> DerefMut for RcRefCell<T> {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Clone for RcRefCell<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
RcRefCell(self.0.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait LinuxClient {
|
pub trait LinuxClient {
|
||||||
fn with_common<R>(&self, f: impl FnOnce(&mut LinuxCommon) -> R) -> R;
|
fn with_common<R>(&self, f: impl FnOnce(&mut LinuxCommon) -> R) -> R;
|
||||||
fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>;
|
fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use std::cell::RefCell;
|
use std::cell::{RefCell, RefMut};
|
||||||
use std::rc::Rc;
|
use std::rc::{Rc, Weak};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use async_task::Runnable;
|
||||||
use calloop::timer::{TimeoutAction, Timer};
|
use calloop::timer::{TimeoutAction, Timer};
|
||||||
use calloop::{EventLoop, LoopHandle};
|
use calloop::{EventLoop, LoopHandle};
|
||||||
use calloop_wayland_source::WaylandSource;
|
use calloop_wayland_source::WaylandSource;
|
||||||
|
@ -35,12 +36,13 @@ use xkbcommon::xkb::ffi::XKB_KEYMAP_FORMAT_TEXT_V1;
|
||||||
use xkbcommon::xkb::{self, Keycode, KEYMAP_COMPILE_NO_FLAGS};
|
use xkbcommon::xkb::{self, Keycode, KEYMAP_COMPILE_NO_FLAGS};
|
||||||
|
|
||||||
use super::super::DOUBLE_CLICK_INTERVAL;
|
use super::super::DOUBLE_CLICK_INTERVAL;
|
||||||
|
use super::window::{WaylandWindowState, WaylandWindowStatePtr};
|
||||||
use crate::platform::linux::is_within_click_distance;
|
use crate::platform::linux::is_within_click_distance;
|
||||||
use crate::platform::linux::wayland::cursor::Cursor;
|
use crate::platform::linux::wayland::cursor::Cursor;
|
||||||
use crate::platform::linux::wayland::window::WaylandWindow;
|
use crate::platform::linux::wayland::window::WaylandWindow;
|
||||||
use crate::platform::linux::LinuxClient;
|
use crate::platform::linux::LinuxClient;
|
||||||
use crate::platform::PlatformWindow;
|
use crate::platform::PlatformWindow;
|
||||||
use crate::{point, px, MouseExitEvent};
|
use crate::{point, px, ForegroundExecutor, MouseExitEvent};
|
||||||
use crate::{
|
use crate::{
|
||||||
AnyWindowHandle, CursorStyle, DisplayId, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers,
|
AnyWindowHandle, CursorStyle, DisplayId, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers,
|
||||||
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
|
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
|
||||||
|
@ -52,9 +54,9 @@ use crate::{LinuxCommon, WindowParams};
|
||||||
/// Used to convert evdev scancode to xkb scancode
|
/// Used to convert evdev scancode to xkb scancode
|
||||||
const MIN_KEYCODE: u32 = 8;
|
const MIN_KEYCODE: u32 = 8;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Globals {
|
pub struct Globals {
|
||||||
pub qh: QueueHandle<WaylandClient>,
|
pub qh: QueueHandle<WaylandClientStatePtr>,
|
||||||
pub compositor: wl_compositor::WlCompositor,
|
pub compositor: wl_compositor::WlCompositor,
|
||||||
pub wm_base: xdg_wm_base::XdgWmBase,
|
pub wm_base: xdg_wm_base::XdgWmBase,
|
||||||
pub shm: wl_shm::WlShm,
|
pub shm: wl_shm::WlShm,
|
||||||
|
@ -62,10 +64,15 @@ pub struct Globals {
|
||||||
pub fractional_scale_manager:
|
pub fractional_scale_manager:
|
||||||
Option<wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1>,
|
Option<wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1>,
|
||||||
pub decoration_manager: Option<zxdg_decoration_manager_v1::ZxdgDecorationManagerV1>,
|
pub decoration_manager: Option<zxdg_decoration_manager_v1::ZxdgDecorationManagerV1>,
|
||||||
|
pub executor: ForegroundExecutor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Globals {
|
impl Globals {
|
||||||
fn new(globals: GlobalList, qh: QueueHandle<WaylandClient>) -> Self {
|
fn new(
|
||||||
|
globals: GlobalList,
|
||||||
|
executor: ForegroundExecutor,
|
||||||
|
qh: QueueHandle<WaylandClientStatePtr>,
|
||||||
|
) -> Self {
|
||||||
Globals {
|
Globals {
|
||||||
compositor: globals
|
compositor: globals
|
||||||
.bind(
|
.bind(
|
||||||
|
@ -80,6 +87,7 @@ impl Globals {
|
||||||
viewporter: globals.bind(&qh, 1..=1, ()).ok(),
|
viewporter: globals.bind(&qh, 1..=1, ()).ok(),
|
||||||
fractional_scale_manager: globals.bind(&qh, 1..=1, ()).ok(),
|
fractional_scale_manager: globals.bind(&qh, 1..=1, ()).ok(),
|
||||||
decoration_manager: globals.bind(&qh, 1..=1, ()).ok(),
|
decoration_manager: globals.bind(&qh, 1..=1, ()).ok(),
|
||||||
|
executor,
|
||||||
qh,
|
qh,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +96,7 @@ impl Globals {
|
||||||
pub(crate) struct WaylandClientState {
|
pub(crate) struct WaylandClientState {
|
||||||
globals: Globals,
|
globals: Globals,
|
||||||
// Surface to Window mapping
|
// Surface to Window mapping
|
||||||
windows: HashMap<ObjectId, WaylandWindow>,
|
windows: HashMap<ObjectId, WaylandWindowStatePtr>,
|
||||||
// Output to scale mapping
|
// Output to scale mapping
|
||||||
output_scales: HashMap<ObjectId, i32>,
|
output_scales: HashMap<ObjectId, i32>,
|
||||||
keymap_state: Option<xkb::State>,
|
keymap_state: Option<xkb::State>,
|
||||||
|
@ -100,14 +108,14 @@ pub(crate) struct WaylandClientState {
|
||||||
mouse_location: Option<Point<Pixels>>,
|
mouse_location: Option<Point<Pixels>>,
|
||||||
enter_token: Option<()>,
|
enter_token: Option<()>,
|
||||||
button_pressed: Option<MouseButton>,
|
button_pressed: Option<MouseButton>,
|
||||||
mouse_focused_window: Option<WaylandWindow>,
|
mouse_focused_window: Option<WaylandWindowStatePtr>,
|
||||||
keyboard_focused_window: Option<WaylandWindow>,
|
keyboard_focused_window: Option<WaylandWindowStatePtr>,
|
||||||
loop_handle: LoopHandle<'static, WaylandClient>,
|
loop_handle: LoopHandle<'static, WaylandClientStatePtr>,
|
||||||
cursor_icon_name: String,
|
cursor_icon_name: String,
|
||||||
cursor: Cursor,
|
cursor: Cursor,
|
||||||
clipboard: Clipboard,
|
clipboard: Clipboard,
|
||||||
primary: Primary,
|
primary: Primary,
|
||||||
event_loop: Option<EventLoop<'static, WaylandClient>>,
|
event_loop: Option<EventLoop<'static, WaylandClientStatePtr>>,
|
||||||
common: LinuxCommon,
|
common: LinuxCommon,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +132,35 @@ pub(crate) struct KeyRepeat {
|
||||||
current_keysym: Option<xkb::Keysym>,
|
current_keysym: Option<xkb::Keysym>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This struct is required to conform to Rust's orphan rules, so we can dispatch on the state but hand the
|
||||||
|
/// window to GPUI.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct WaylandClientStatePtr(Weak<RefCell<WaylandClientState>>);
|
||||||
|
|
||||||
|
impl WaylandClientStatePtr {
|
||||||
|
fn get_client(&self) -> Rc<RefCell<WaylandClientState>> {
|
||||||
|
self.0
|
||||||
|
.upgrade()
|
||||||
|
.expect("The pointer should always be valid when dispatching in wayland")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn drop_window(&self, surface_id: &ObjectId) {
|
||||||
|
let mut client = self.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
|
let closed_window = state.windows.remove(surface_id).unwrap();
|
||||||
|
if let Some(window) = state.mouse_focused_window.take() {
|
||||||
|
if !window.ptr_eq(&closed_window) {
|
||||||
|
state.mouse_focused_window = Some(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(window) = state.keyboard_focused_window.take() {
|
||||||
|
if !window.ptr_eq(&closed_window) {
|
||||||
|
state.mouse_focused_window = Some(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct WaylandClient(Rc<RefCell<WaylandClientState>>);
|
pub struct WaylandClient(Rc<RefCell<WaylandClientState>>);
|
||||||
|
|
||||||
|
@ -147,7 +184,8 @@ impl WaylandClient {
|
||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
let conn = Connection::connect_to_env().unwrap();
|
let conn = Connection::connect_to_env().unwrap();
|
||||||
|
|
||||||
let (globals, mut event_queue) = registry_queue_init::<WaylandClient>(&conn).unwrap();
|
let (globals, mut event_queue) =
|
||||||
|
registry_queue_init::<WaylandClientStatePtr>(&conn).unwrap();
|
||||||
let qh = event_queue.handle();
|
let qh = event_queue.handle();
|
||||||
let mut outputs = HashMap::default();
|
let mut outputs = HashMap::default();
|
||||||
|
|
||||||
|
@ -179,19 +217,19 @@ impl WaylandClient {
|
||||||
let display = conn.backend().display_ptr() as *mut std::ffi::c_void;
|
let display = conn.backend().display_ptr() as *mut std::ffi::c_void;
|
||||||
let (primary, clipboard) = unsafe { create_clipboards_from_external(display) };
|
let (primary, clipboard) = unsafe { create_clipboards_from_external(display) };
|
||||||
|
|
||||||
let event_loop = EventLoop::try_new().unwrap();
|
let event_loop = EventLoop::<WaylandClientStatePtr>::try_new().unwrap();
|
||||||
|
|
||||||
let (common, main_receiver) = LinuxCommon::new(event_loop.get_signal());
|
let (common, main_receiver) = LinuxCommon::new(event_loop.get_signal());
|
||||||
|
|
||||||
let handle = event_loop.handle();
|
let handle = event_loop.handle();
|
||||||
|
|
||||||
handle.insert_source(main_receiver, |event, _, _: &mut WaylandClient| {
|
handle.insert_source(main_receiver, |event, _, _: &mut WaylandClientStatePtr| {
|
||||||
if let calloop::channel::Event::Msg(runnable) = event {
|
if let calloop::channel::Event::Msg(runnable) = event {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let globals = Globals::new(globals, qh);
|
let globals = Globals::new(globals, common.foreground_executor.clone(), qh);
|
||||||
|
|
||||||
let cursor = Cursor::new(&conn, &globals, 24);
|
let cursor = Cursor::new(&conn, &globals, 24);
|
||||||
|
|
||||||
|
@ -260,8 +298,12 @@ impl LinuxClient for WaylandClient {
|
||||||
) -> Box<dyn PlatformWindow> {
|
) -> Box<dyn PlatformWindow> {
|
||||||
let mut state = self.0.borrow_mut();
|
let mut state = self.0.borrow_mut();
|
||||||
|
|
||||||
let (window, surface_id) = WaylandWindow::new(state.globals.clone(), params);
|
let (window, surface_id) = WaylandWindow::new(
|
||||||
state.windows.insert(surface_id, window.clone());
|
state.globals.clone(),
|
||||||
|
WaylandClientStatePtr(Rc::downgrade(&self.0)),
|
||||||
|
params,
|
||||||
|
);
|
||||||
|
state.windows.insert(surface_id, window.0.clone());
|
||||||
|
|
||||||
Box::new(window)
|
Box::new(window)
|
||||||
}
|
}
|
||||||
|
@ -307,7 +349,13 @@ impl LinuxClient for WaylandClient {
|
||||||
.take()
|
.take()
|
||||||
.expect("App is already running");
|
.expect("App is already running");
|
||||||
|
|
||||||
event_loop.run(None, &mut self.clone(), |_| {}).log_err();
|
event_loop
|
||||||
|
.run(
|
||||||
|
None,
|
||||||
|
&mut WaylandClientStatePtr(Rc::downgrade(&self.0)),
|
||||||
|
|_| {},
|
||||||
|
)
|
||||||
|
.log_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_to_clipboard(&self, item: crate::ClipboardItem) {
|
fn write_to_clipboard(&self, item: crate::ClipboardItem) {
|
||||||
|
@ -327,16 +375,18 @@ impl LinuxClient for WaylandClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for WaylandClient {
|
impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
state: &mut Self,
|
this: &mut Self,
|
||||||
registry: &wl_registry::WlRegistry,
|
registry: &wl_registry::WlRegistry,
|
||||||
event: wl_registry::Event,
|
event: wl_registry::Event,
|
||||||
_: &GlobalListContents,
|
_: &GlobalListContents,
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
qh: &QueueHandle<Self>,
|
qh: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = state.0.borrow_mut();
|
let mut client = this.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
wl_registry::Event::Global {
|
wl_registry::Event::Global {
|
||||||
name,
|
name,
|
||||||
|
@ -360,50 +410,60 @@ impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for WaylandClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate_noop!(WaylandClient: ignore wl_compositor::WlCompositor);
|
delegate_noop!(WaylandClientStatePtr: ignore wl_compositor::WlCompositor);
|
||||||
delegate_noop!(WaylandClient: ignore wl_shm::WlShm);
|
delegate_noop!(WaylandClientStatePtr: ignore wl_shm::WlShm);
|
||||||
delegate_noop!(WaylandClient: ignore wl_shm_pool::WlShmPool);
|
delegate_noop!(WaylandClientStatePtr: ignore wl_shm_pool::WlShmPool);
|
||||||
delegate_noop!(WaylandClient: ignore wl_buffer::WlBuffer);
|
delegate_noop!(WaylandClientStatePtr: ignore wl_buffer::WlBuffer);
|
||||||
delegate_noop!(WaylandClient: ignore wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1);
|
delegate_noop!(WaylandClientStatePtr: ignore wp_fractional_scale_manager_v1::WpFractionalScaleManagerV1);
|
||||||
delegate_noop!(WaylandClient: ignore zxdg_decoration_manager_v1::ZxdgDecorationManagerV1);
|
delegate_noop!(WaylandClientStatePtr: ignore zxdg_decoration_manager_v1::ZxdgDecorationManagerV1);
|
||||||
delegate_noop!(WaylandClient: ignore wp_viewporter::WpViewporter);
|
delegate_noop!(WaylandClientStatePtr: ignore wp_viewporter::WpViewporter);
|
||||||
delegate_noop!(WaylandClient: ignore wp_viewport::WpViewport);
|
delegate_noop!(WaylandClientStatePtr: ignore wp_viewport::WpViewport);
|
||||||
|
|
||||||
impl Dispatch<WlCallback, ObjectId> for WaylandClient {
|
impl Dispatch<WlCallback, ObjectId> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
this: &mut WaylandClient,
|
state: &mut WaylandClientStatePtr,
|
||||||
_: &wl_callback::WlCallback,
|
_: &wl_callback::WlCallback,
|
||||||
event: wl_callback::Event,
|
event: wl_callback::Event,
|
||||||
surface_id: &ObjectId,
|
surface_id: &ObjectId,
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
qh: &QueueHandle<Self>,
|
qh: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let state = this.0.borrow_mut();
|
let client = state.get_client();
|
||||||
let Some(window) = state.windows.get(surface_id).cloned() else {
|
let mut state = client.borrow_mut();
|
||||||
|
let Some(window) = get_window(&mut state, surface_id) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
drop(state);
|
drop(state);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
wl_callback::Event::Done { callback_data } => {
|
wl_callback::Event::Done { callback_data } => {
|
||||||
window.frame();
|
window.frame(true);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<wl_surface::WlSurface, ()> for WaylandClient {
|
fn get_window(
|
||||||
|
mut state: &mut RefMut<WaylandClientState>,
|
||||||
|
surface_id: &ObjectId,
|
||||||
|
) -> Option<WaylandWindowStatePtr> {
|
||||||
|
state.windows.get(surface_id).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dispatch<wl_surface::WlSurface, ()> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
state: &mut Self,
|
this: &mut Self,
|
||||||
surface: &wl_surface::WlSurface,
|
surface: &wl_surface::WlSurface,
|
||||||
event: <wl_surface::WlSurface as Proxy>::Event,
|
event: <wl_surface::WlSurface as Proxy>::Event,
|
||||||
_: &(),
|
_: &(),
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = state.0.borrow_mut();
|
let mut client = this.get_client();
|
||||||
let Some(window) = state.windows.get(&surface.id()).cloned() else {
|
let mut state = client.borrow_mut();
|
||||||
|
|
||||||
|
let Some(window) = get_window(&mut state, &surface.id()) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let scales = state.output_scales.clone();
|
let scales = state.output_scales.clone();
|
||||||
|
@ -413,16 +473,18 @@ impl Dispatch<wl_surface::WlSurface, ()> for WaylandClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<wl_output::WlOutput, ()> for WaylandClient {
|
impl Dispatch<wl_output::WlOutput, ()> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
state: &mut Self,
|
this: &mut Self,
|
||||||
output: &wl_output::WlOutput,
|
output: &wl_output::WlOutput,
|
||||||
event: <wl_output::WlOutput as Proxy>::Event,
|
event: <wl_output::WlOutput as Proxy>::Event,
|
||||||
_: &(),
|
_: &(),
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = state.0.borrow_mut();
|
let mut client = this.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
|
|
||||||
let Some(mut output_scale) = state.output_scales.get_mut(&output.id()) else {
|
let Some(mut output_scale) = state.output_scales.get_mut(&output.id()) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -436,7 +498,7 @@ impl Dispatch<wl_output::WlOutput, ()> for WaylandClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<xdg_surface::XdgSurface, ObjectId> for WaylandClient {
|
impl Dispatch<xdg_surface::XdgSurface, ObjectId> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
state: &mut Self,
|
state: &mut Self,
|
||||||
xdg_surface: &xdg_surface::XdgSurface,
|
xdg_surface: &xdg_surface::XdgSurface,
|
||||||
|
@ -445,17 +507,17 @@ impl Dispatch<xdg_surface::XdgSurface, ObjectId> for WaylandClient {
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = state.0.borrow_mut();
|
let client = state.get_client();
|
||||||
let Some(window) = state.windows.get(surface_id).cloned() else {
|
let mut state = client.borrow_mut();
|
||||||
|
let Some(window) = get_window(&mut state, surface_id) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
drop(state);
|
drop(state);
|
||||||
window.handle_xdg_surface_event(event);
|
window.handle_xdg_surface_event(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<xdg_toplevel::XdgToplevel, ObjectId> for WaylandClient {
|
impl Dispatch<xdg_toplevel::XdgToplevel, ObjectId> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
this: &mut Self,
|
this: &mut Self,
|
||||||
xdg_toplevel: &xdg_toplevel::XdgToplevel,
|
xdg_toplevel: &xdg_toplevel::XdgToplevel,
|
||||||
|
@ -464,9 +526,9 @@ impl Dispatch<xdg_toplevel::XdgToplevel, ObjectId> for WaylandClient {
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = this.0.borrow_mut();
|
let client = this.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
let Some(window) = state.windows.get(surface_id).cloned() else {
|
let Some(window) = get_window(&mut state, surface_id) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -474,13 +536,12 @@ impl Dispatch<xdg_toplevel::XdgToplevel, ObjectId> for WaylandClient {
|
||||||
let should_close = window.handle_toplevel_event(event);
|
let should_close = window.handle_toplevel_event(event);
|
||||||
|
|
||||||
if should_close {
|
if should_close {
|
||||||
let mut state = this.0.borrow_mut();
|
this.drop_window(surface_id);
|
||||||
state.windows.remove(surface_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<xdg_wm_base::XdgWmBase, ()> for WaylandClient {
|
impl Dispatch<xdg_wm_base::XdgWmBase, ()> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
_: &mut Self,
|
_: &mut Self,
|
||||||
wm_base: &xdg_wm_base::XdgWmBase,
|
wm_base: &xdg_wm_base::XdgWmBase,
|
||||||
|
@ -495,7 +556,7 @@ impl Dispatch<xdg_wm_base::XdgWmBase, ()> for WaylandClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<wl_seat::WlSeat, ()> for WaylandClient {
|
impl Dispatch<wl_seat::WlSeat, ()> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
state: &mut Self,
|
state: &mut Self,
|
||||||
seat: &wl_seat::WlSeat,
|
seat: &wl_seat::WlSeat,
|
||||||
|
@ -518,7 +579,7 @@ impl Dispatch<wl_seat::WlSeat, ()> for WaylandClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClient {
|
impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
this: &mut Self,
|
this: &mut Self,
|
||||||
keyboard: &wl_keyboard::WlKeyboard,
|
keyboard: &wl_keyboard::WlKeyboard,
|
||||||
|
@ -527,7 +588,8 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClient {
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
qh: &QueueHandle<Self>,
|
qh: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = this.0.borrow_mut();
|
let mut client = this.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
match event {
|
match event {
|
||||||
wl_keyboard::Event::RepeatInfo { rate, delay } => {
|
wl_keyboard::Event::RepeatInfo { rate, delay } => {
|
||||||
state.repeat.characters_per_second = rate as u32;
|
state.repeat.characters_per_second = rate as u32;
|
||||||
|
@ -559,7 +621,7 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClient {
|
||||||
state.keymap_state = Some(xkb::State::new(&keymap));
|
state.keymap_state = Some(xkb::State::new(&keymap));
|
||||||
}
|
}
|
||||||
wl_keyboard::Event::Enter { surface, .. } => {
|
wl_keyboard::Event::Enter { surface, .. } => {
|
||||||
state.keyboard_focused_window = state.windows.get(&surface.id()).cloned();
|
state.keyboard_focused_window = get_window(&mut state, &surface.id());
|
||||||
|
|
||||||
if let Some(window) = state.keyboard_focused_window.clone() {
|
if let Some(window) = state.keyboard_focused_window.clone() {
|
||||||
drop(state);
|
drop(state);
|
||||||
|
@ -567,7 +629,7 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wl_keyboard::Event::Leave { surface, .. } => {
|
wl_keyboard::Event::Leave { surface, .. } => {
|
||||||
let keyboard_focused_window = state.windows.get(&surface.id()).cloned();
|
let keyboard_focused_window = get_window(&mut state, &surface.id());
|
||||||
state.keyboard_focused_window = None;
|
state.keyboard_focused_window = None;
|
||||||
|
|
||||||
if let Some(window) = keyboard_focused_window {
|
if let Some(window) = keyboard_focused_window {
|
||||||
|
@ -629,8 +691,9 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClient {
|
||||||
.loop_handle
|
.loop_handle
|
||||||
.insert_source(Timer::from_duration(state.repeat.delay), {
|
.insert_source(Timer::from_duration(state.repeat.delay), {
|
||||||
let input = input.clone();
|
let input = input.clone();
|
||||||
move |event, _metadata, client| {
|
move |event, _metadata, this| {
|
||||||
let state = client.0.borrow_mut();
|
let mut client = this.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
let is_repeating = id == state.repeat.current_id
|
let is_repeating = id == state.repeat.current_id
|
||||||
&& state.repeat.current_keysym.is_some()
|
&& state.repeat.current_keysym.is_some()
|
||||||
&& state.keyboard_focused_window.is_some();
|
&& state.keyboard_focused_window.is_some();
|
||||||
|
@ -691,16 +754,17 @@ fn linux_button_to_gpui(button: u32) -> Option<MouseButton> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClient {
|
impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
client: &mut Self,
|
this: &mut Self,
|
||||||
wl_pointer: &wl_pointer::WlPointer,
|
wl_pointer: &wl_pointer::WlPointer,
|
||||||
event: wl_pointer::Event,
|
event: wl_pointer::Event,
|
||||||
data: &(),
|
data: &(),
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
qh: &QueueHandle<Self>,
|
qh: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = client.0.borrow_mut();
|
let mut client = this.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
let cursor_icon_name = state.cursor_icon_name.clone();
|
let cursor_icon_name = state.cursor_icon_name.clone();
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
@ -713,7 +777,7 @@ impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClient {
|
||||||
} => {
|
} => {
|
||||||
state.mouse_location = Some(point(px(surface_x as f32), px(surface_y as f32)));
|
state.mouse_location = Some(point(px(surface_x as f32), px(surface_y as f32)));
|
||||||
|
|
||||||
if let Some(window) = state.windows.get(&surface.id()).cloned() {
|
if let Some(window) = get_window(&mut state, &surface.id()) {
|
||||||
state.enter_token = Some(());
|
state.enter_token = Some(());
|
||||||
state.mouse_focused_window = Some(window.clone());
|
state.mouse_focused_window = Some(window.clone());
|
||||||
state.cursor.set_serial_id(serial);
|
state.cursor.set_serial_id(serial);
|
||||||
|
@ -901,18 +965,19 @@ impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<wp_fractional_scale_v1::WpFractionalScaleV1, ObjectId> for WaylandClient {
|
impl Dispatch<wp_fractional_scale_v1::WpFractionalScaleV1, ObjectId> for WaylandClientStatePtr {
|
||||||
fn event(
|
fn event(
|
||||||
state: &mut Self,
|
this: &mut Self,
|
||||||
_: &wp_fractional_scale_v1::WpFractionalScaleV1,
|
_: &wp_fractional_scale_v1::WpFractionalScaleV1,
|
||||||
event: <wp_fractional_scale_v1::WpFractionalScaleV1 as Proxy>::Event,
|
event: <wp_fractional_scale_v1::WpFractionalScaleV1 as Proxy>::Event,
|
||||||
surface_id: &ObjectId,
|
surface_id: &ObjectId,
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = state.0.borrow_mut();
|
let client = this.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
|
|
||||||
let Some(window) = state.windows.get(surface_id).cloned() else {
|
let Some(window) = get_window(&mut state, surface_id) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -921,18 +986,20 @@ impl Dispatch<wp_fractional_scale_v1::WpFractionalScaleV1, ObjectId> for Wayland
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1, ObjectId> for WaylandClient {
|
impl Dispatch<zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1, ObjectId>
|
||||||
|
for WaylandClientStatePtr
|
||||||
|
{
|
||||||
fn event(
|
fn event(
|
||||||
state: &mut Self,
|
this: &mut Self,
|
||||||
_: &zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1,
|
_: &zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1,
|
||||||
event: zxdg_toplevel_decoration_v1::Event,
|
event: zxdg_toplevel_decoration_v1::Event,
|
||||||
surface_id: &ObjectId,
|
surface_id: &ObjectId,
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
let mut state = state.0.borrow_mut();
|
let client = this.get_client();
|
||||||
|
let mut state = client.borrow_mut();
|
||||||
let Some(window) = state.windows.get(surface_id).cloned() else {
|
let Some(window) = get_window(&mut state, surface_id) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cell::RefCell;
|
use std::cell::{Ref, RefCell, RefMut};
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::rc::Rc;
|
use std::rc::{Rc, Weak};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use blade_graphics as gpu;
|
use blade_graphics as gpu;
|
||||||
|
@ -27,8 +27,8 @@ use crate::platform::{PlatformAtlas, PlatformInputHandler, PlatformWindow};
|
||||||
use crate::scene::Scene;
|
use crate::scene::Scene;
|
||||||
use crate::{
|
use crate::{
|
||||||
px, size, Bounds, DevicePixels, Globals, Modifiers, Pixels, PlatformDisplay, PlatformInput,
|
px, size, Bounds, DevicePixels, Globals, Modifiers, Pixels, PlatformDisplay, PlatformInput,
|
||||||
Point, PromptLevel, RcRefCell, Size, WindowAppearance, WindowBackgroundAppearance,
|
Point, PromptLevel, Size, WaylandClientState, WaylandClientStatePtr, WindowAppearance,
|
||||||
WindowParams,
|
WindowBackgroundAppearance, WindowParams,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -79,6 +79,14 @@ pub struct WaylandWindowState {
|
||||||
decoration_state: WaylandDecorationState,
|
decoration_state: WaylandDecorationState,
|
||||||
fullscreen: bool,
|
fullscreen: bool,
|
||||||
maximized: bool,
|
maximized: bool,
|
||||||
|
client: WaylandClientStatePtr,
|
||||||
|
callbacks: Callbacks,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct WaylandWindowStatePtr {
|
||||||
|
state: Rc<RefCell<WaylandWindowState>>,
|
||||||
|
callbacks: Rc<RefCell<Callbacks>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WaylandWindowState {
|
impl WaylandWindowState {
|
||||||
|
@ -87,6 +95,7 @@ impl WaylandWindowState {
|
||||||
xdg_surface: xdg_surface::XdgSurface,
|
xdg_surface: xdg_surface::XdgSurface,
|
||||||
viewport: Option<wp_viewport::WpViewport>,
|
viewport: Option<wp_viewport::WpViewport>,
|
||||||
toplevel: xdg_toplevel::XdgToplevel,
|
toplevel: xdg_toplevel::XdgToplevel,
|
||||||
|
client: WaylandClientStatePtr,
|
||||||
globals: Globals,
|
globals: Globals,
|
||||||
options: WindowParams,
|
options: WindowParams,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -136,22 +145,47 @@ impl WaylandWindowState {
|
||||||
decoration_state: WaylandDecorationState::Client,
|
decoration_state: WaylandDecorationState::Client,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
maximized: false,
|
maximized: false,
|
||||||
|
callbacks: Callbacks::default(),
|
||||||
|
client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
pub(crate) struct WaylandWindow(pub WaylandWindowStatePtr);
|
||||||
pub(crate) struct WaylandWindow {
|
|
||||||
pub(crate) state: RcRefCell<WaylandWindowState>,
|
impl Drop for WaylandWindow {
|
||||||
pub(crate) callbacks: Rc<RefCell<Callbacks>>,
|
fn drop(&mut self) {
|
||||||
|
let mut state = self.0.state.borrow_mut();
|
||||||
|
let surface_id = state.surface.id();
|
||||||
|
let client = state.client.clone();
|
||||||
|
state.renderer.destroy();
|
||||||
|
state.toplevel.destroy();
|
||||||
|
state.xdg_surface.destroy();
|
||||||
|
state.surface.destroy();
|
||||||
|
|
||||||
|
let state_ptr = self.0.clone();
|
||||||
|
state.globals.executor.spawn(async move {
|
||||||
|
state_ptr.close();
|
||||||
|
client.drop_window(&surface_id)
|
||||||
|
});
|
||||||
|
drop(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WaylandWindow {
|
impl WaylandWindow {
|
||||||
pub fn ptr_eq(&self, other: &Self) -> bool {
|
fn borrow(&self) -> Ref<WaylandWindowState> {
|
||||||
Rc::ptr_eq(&self.state, &other.state)
|
self.0.state.borrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(globals: Globals, params: WindowParams) -> (Self, ObjectId) {
|
fn borrow_mut(&self) -> RefMut<WaylandWindowState> {
|
||||||
|
self.0.state.borrow_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(
|
||||||
|
globals: Globals,
|
||||||
|
client: WaylandClientStatePtr,
|
||||||
|
params: WindowParams,
|
||||||
|
) -> (Self, ObjectId) {
|
||||||
let surface = globals.compositor.create_surface(&globals.qh, ());
|
let surface = globals.compositor.create_surface(&globals.qh, ());
|
||||||
let xdg_surface = globals
|
let xdg_surface = globals
|
||||||
.wm_base
|
.wm_base
|
||||||
|
@ -178,31 +212,37 @@ impl WaylandWindow {
|
||||||
|
|
||||||
surface.frame(&globals.qh, surface.id());
|
surface.frame(&globals.qh, surface.id());
|
||||||
|
|
||||||
let window_state = RcRefCell::new(WaylandWindowState::new(
|
let this = Self(WaylandWindowStatePtr {
|
||||||
surface.clone(),
|
state: Rc::new(RefCell::new(WaylandWindowState::new(
|
||||||
xdg_surface,
|
surface.clone(),
|
||||||
viewport,
|
xdg_surface,
|
||||||
toplevel,
|
viewport,
|
||||||
globals,
|
toplevel,
|
||||||
params,
|
client,
|
||||||
));
|
globals,
|
||||||
|
params,
|
||||||
let this = Self {
|
))),
|
||||||
state: window_state,
|
|
||||||
callbacks: Rc::new(RefCell::new(Callbacks::default())),
|
callbacks: Rc::new(RefCell::new(Callbacks::default())),
|
||||||
};
|
});
|
||||||
|
|
||||||
// Kick things off
|
// Kick things off
|
||||||
surface.commit();
|
surface.commit();
|
||||||
|
|
||||||
(this, surface.id())
|
(this, surface.id())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn frame(&self) {
|
impl WaylandWindowStatePtr {
|
||||||
let state = self.state.borrow_mut();
|
pub fn ptr_eq(&self, other: &Self) -> bool {
|
||||||
state.surface.frame(&state.globals.qh, state.surface.id());
|
Rc::ptr_eq(&self.state, &other.state)
|
||||||
drop(state);
|
}
|
||||||
|
|
||||||
|
pub fn frame(&self, from_frame_callback: bool) {
|
||||||
|
if from_frame_callback {
|
||||||
|
let state = self.state.borrow_mut();
|
||||||
|
state.surface.frame(&state.globals.qh, state.surface.id());
|
||||||
|
drop(state);
|
||||||
|
}
|
||||||
let mut cb = self.callbacks.borrow_mut();
|
let mut cb = self.callbacks.borrow_mut();
|
||||||
if let Some(fun) = cb.request_frame.as_mut() {
|
if let Some(fun) = cb.request_frame.as_mut() {
|
||||||
fun();
|
fun();
|
||||||
|
@ -215,7 +255,7 @@ impl WaylandWindow {
|
||||||
let state = self.state.borrow();
|
let state = self.state.borrow();
|
||||||
state.xdg_surface.ack_configure(serial);
|
state.xdg_surface.ack_configure(serial);
|
||||||
drop(state);
|
drop(state);
|
||||||
self.frame();
|
self.frame(false);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -273,6 +313,10 @@ impl WaylandWindow {
|
||||||
if let Some(mut should_close) = cb.should_close.take() {
|
if let Some(mut should_close) = cb.should_close.take() {
|
||||||
let result = (should_close)();
|
let result = (should_close)();
|
||||||
cb.should_close = Some(should_close);
|
cb.should_close = Some(should_close);
|
||||||
|
if result {
|
||||||
|
drop(cb);
|
||||||
|
self.close();
|
||||||
|
}
|
||||||
result
|
result
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -428,7 +472,6 @@ impl WaylandWindow {
|
||||||
if let Some(fun) = callbacks.close.take() {
|
if let Some(fun) = callbacks.close.take() {
|
||||||
fun()
|
fun()
|
||||||
}
|
}
|
||||||
self.state.borrow_mut().toplevel.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_input(&self, input: PlatformInput) {
|
pub fn handle_input(&self, input: PlatformInput) {
|
||||||
|
@ -471,11 +514,11 @@ impl HasDisplayHandle for WaylandWindow {
|
||||||
|
|
||||||
impl PlatformWindow for WaylandWindow {
|
impl PlatformWindow for WaylandWindow {
|
||||||
fn bounds(&self) -> Bounds<DevicePixels> {
|
fn bounds(&self) -> Bounds<DevicePixels> {
|
||||||
self.state.borrow().bounds.map(|p| DevicePixels(p as i32))
|
self.borrow().bounds.map(|p| DevicePixels(p as i32))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_maximized(&self) -> bool {
|
fn is_maximized(&self) -> bool {
|
||||||
self.state.borrow().maximized
|
self.borrow().maximized
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_minimized(&self) -> bool {
|
fn is_minimized(&self) -> bool {
|
||||||
|
@ -484,7 +527,7 @@ impl PlatformWindow for WaylandWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn content_size(&self) -> Size<Pixels> {
|
fn content_size(&self) -> Size<Pixels> {
|
||||||
let state = self.state.borrow();
|
let state = self.borrow();
|
||||||
Size {
|
Size {
|
||||||
width: Pixels(state.bounds.size.width as f32),
|
width: Pixels(state.bounds.size.width as f32),
|
||||||
height: Pixels(state.bounds.size.height as f32),
|
height: Pixels(state.bounds.size.height as f32),
|
||||||
|
@ -492,7 +535,7 @@ impl PlatformWindow for WaylandWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale_factor(&self) -> f32 {
|
fn scale_factor(&self) -> f32 {
|
||||||
self.state.borrow().scale
|
self.borrow().scale
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo(linux)
|
// todo(linux)
|
||||||
|
@ -520,11 +563,11 @@ impl PlatformWindow for WaylandWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {
|
fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {
|
||||||
self.state.borrow_mut().input_handler = Some(input_handler);
|
self.borrow_mut().input_handler = Some(input_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_input_handler(&mut self) -> Option<PlatformInputHandler> {
|
fn take_input_handler(&mut self) -> Option<PlatformInputHandler> {
|
||||||
self.state.borrow_mut().input_handler.take()
|
self.borrow_mut().input_handler.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prompt(
|
fn prompt(
|
||||||
|
@ -547,10 +590,7 @@ impl PlatformWindow for WaylandWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_title(&mut self, title: &str) {
|
fn set_title(&mut self, title: &str) {
|
||||||
self.state
|
self.borrow_mut().toplevel.set_title(title.to_string());
|
||||||
.borrow_mut()
|
|
||||||
.toplevel
|
|
||||||
.set_title(title.to_string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_background_appearance(&mut self, _background_appearance: WindowBackgroundAppearance) {
|
fn set_background_appearance(&mut self, _background_appearance: WindowBackgroundAppearance) {
|
||||||
|
@ -566,7 +606,7 @@ impl PlatformWindow for WaylandWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn minimize(&self) {
|
fn minimize(&self) {
|
||||||
self.state.borrow_mut().toplevel.set_minimized();
|
self.borrow_mut().toplevel.set_minimized();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn zoom(&self) {
|
fn zoom(&self) {
|
||||||
|
@ -574,7 +614,7 @@ impl PlatformWindow for WaylandWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_fullscreen(&self) {
|
fn toggle_fullscreen(&self) {
|
||||||
let state = self.state.borrow_mut();
|
let state = self.borrow_mut();
|
||||||
if !state.fullscreen {
|
if !state.fullscreen {
|
||||||
state.toplevel.set_fullscreen(None);
|
state.toplevel.set_fullscreen(None);
|
||||||
} else {
|
} else {
|
||||||
|
@ -583,39 +623,39 @@ impl PlatformWindow for WaylandWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_fullscreen(&self) -> bool {
|
fn is_fullscreen(&self) -> bool {
|
||||||
self.state.borrow().fullscreen
|
self.borrow().fullscreen
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_request_frame(&self, callback: Box<dyn FnMut()>) {
|
fn on_request_frame(&self, callback: Box<dyn FnMut()>) {
|
||||||
self.callbacks.borrow_mut().request_frame = Some(callback);
|
self.0.callbacks.borrow_mut().request_frame = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_input(&self, callback: Box<dyn FnMut(PlatformInput) -> crate::DispatchEventResult>) {
|
fn on_input(&self, callback: Box<dyn FnMut(PlatformInput) -> crate::DispatchEventResult>) {
|
||||||
self.callbacks.borrow_mut().input = Some(callback);
|
self.0.callbacks.borrow_mut().input = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_active_status_change(&self, callback: Box<dyn FnMut(bool)>) {
|
fn on_active_status_change(&self, callback: Box<dyn FnMut(bool)>) {
|
||||||
self.callbacks.borrow_mut().active_status_change = Some(callback);
|
self.0.callbacks.borrow_mut().active_status_change = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_resize(&self, callback: Box<dyn FnMut(Size<Pixels>, f32)>) {
|
fn on_resize(&self, callback: Box<dyn FnMut(Size<Pixels>, f32)>) {
|
||||||
self.callbacks.borrow_mut().resize = Some(callback);
|
self.0.callbacks.borrow_mut().resize = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_fullscreen(&self, callback: Box<dyn FnMut(bool)>) {
|
fn on_fullscreen(&self, callback: Box<dyn FnMut(bool)>) {
|
||||||
self.callbacks.borrow_mut().fullscreen = Some(callback);
|
self.0.callbacks.borrow_mut().fullscreen = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_moved(&self, callback: Box<dyn FnMut()>) {
|
fn on_moved(&self, callback: Box<dyn FnMut()>) {
|
||||||
self.callbacks.borrow_mut().moved = Some(callback);
|
self.0.callbacks.borrow_mut().moved = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_should_close(&self, callback: Box<dyn FnMut() -> bool>) {
|
fn on_should_close(&self, callback: Box<dyn FnMut() -> bool>) {
|
||||||
self.callbacks.borrow_mut().should_close = Some(callback);
|
self.0.callbacks.borrow_mut().should_close = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_close(&self, callback: Box<dyn FnOnce()>) {
|
fn on_close(&self, callback: Box<dyn FnOnce()>) {
|
||||||
self.callbacks.borrow_mut().close = Some(callback);
|
self.0.callbacks.borrow_mut().close = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_appearance_changed(&self, callback: Box<dyn FnMut()>) {
|
fn on_appearance_changed(&self, callback: Box<dyn FnMut()>) {
|
||||||
|
@ -628,17 +668,17 @@ impl PlatformWindow for WaylandWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self, scene: &Scene) {
|
fn draw(&self, scene: &Scene) {
|
||||||
let mut state = self.state.borrow_mut();
|
let mut state = self.borrow_mut();
|
||||||
state.renderer.draw(scene);
|
state.renderer.draw(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completed_frame(&self) {
|
fn completed_frame(&self) {
|
||||||
let mut state = self.state.borrow_mut();
|
let mut state = self.borrow_mut();
|
||||||
state.surface.commit();
|
state.surface.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> {
|
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> {
|
||||||
let state = self.state.borrow();
|
let state = self.borrow();
|
||||||
state.renderer.sprite_atlas().clone()
|
state.renderer.sprite_atlas().clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue