Skip to content

Commit c3bb3ba

Browse files
committed
wip
1 parent ff2423b commit c3bb3ba

11 files changed

Lines changed: 44 additions & 35 deletions

File tree

examples/render_femtovg/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl WindowHandler for FemtovgExample {
104104
) => {
105105
self.current_mouse_position.set(position);
106106
if position.y > 400. && !self.window_context.has_focus() {
107-
self.window_context.focus()
107+
let _ = self.window_context.focus();
108108
}
109109
self.damaged.set(true);
110110
}

src/context.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::*;
12
use crate::{platform, MouseCursor, WindowSize};
23
use dpi::Size;
34
use raw_window_handle::{
@@ -18,8 +19,9 @@ impl WindowContext {
1819
}
1920

2021
/// Sets the [`MouseCursor`] icon to be displayed when the mouse cursor hovers this window.
21-
pub fn set_mouse_cursor(&self, mouse_cursor: MouseCursor) {
22-
self.inner.set_mouse_cursor(mouse_cursor);
22+
pub fn set_mouse_cursor(&self, mouse_cursor: MouseCursor) -> Result<()> {
23+
self.inner.set_mouse_cursor(mouse_cursor)?;
24+
Ok(())
2325
}
2426

2527
/// Requests the window to be closed.
@@ -38,16 +40,18 @@ impl WindowContext {
3840
}
3941

4042
/// Focuses this window.
41-
pub fn focus(&self) {
42-
self.inner.focus();
43+
pub fn focus(&self) -> Result<()> {
44+
self.inner.focus()?;
45+
Ok(())
4346
}
4447

4548
/// Resizes this window to the given `size`.
4649
///
4750
/// The given `size` can either be in [physical](dpi::PhysicalSize) or
4851
/// [logical](dpi::LogicalSize) pixels.
49-
pub fn resize(&self, size: impl Into<Size>) {
50-
self.inner.resize(size.into());
52+
pub fn resize(&self, size: impl Into<Size>) -> Result<()> {
53+
self.inner.resize(size.into())?;
54+
Ok(())
5155
}
5256

5357
/// Returns the current scale factor of this window.
@@ -78,13 +82,13 @@ impl WindowContext {
7882
}
7983

8084
impl HasWindowHandle for WindowContext {
81-
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
85+
fn window_handle(&self) -> core::result::Result<WindowHandle<'_>, HandleError> {
8286
self.inner.window_handle().ok_or(HandleError::Unavailable)
8387
}
8488
}
8589

8690
impl HasDisplayHandle for WindowContext {
87-
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
91+
fn display_handle(&self) -> core::result::Result<DisplayHandle<'_>, HandleError> {
8892
Ok(self.inner.display_handle())
8993
}
9094
}
@@ -124,13 +128,13 @@ const _: () = {
124128
};
125129

126130
impl HasWindowHandle for PlatformHandle {
127-
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
131+
fn window_handle(&self) -> core::result::Result<WindowHandle<'_>, HandleError> {
128132
self.inner.window_handle().ok_or(HandleError::Unavailable)
129133
}
130134
}
131135

132136
impl HasDisplayHandle for PlatformHandle {
133-
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
137+
fn display_handle(&self) -> core::result::Result<DisplayHandle<'_>, HandleError> {
134138
Ok(self.inner.display_handle())
135139
}
136140
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ pub use mouse_cursor::MouseCursor;
2424
pub use window::*;
2525
pub use window_open_options::*;
2626

27-
pub(crate) use tracing::*;
27+
pub(crate) use tracing::warn;
2828

2929
pub(crate) mod wrappers;

src/platform/macos/gl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use crate::gl::{GlConfig, Profile};
44
use crate::platform::*;
5-
use crate::tracing::*;
5+
use crate::warn;
66
use objc2::rc::Retained;
77
use objc2::AllocAnyThread;
88
use objc2::{MainThreadMarker, MainThreadOnly};

src/platform/win/gl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use windows_core::{s, PCSTR};
55
use windows_sys::Win32::Graphics::OpenGL::wglGetProcAddress;
66

77
use crate::gl::*;
8-
use crate::tracing::warn;
8+
use crate::warn;
99
use crate::wrappers::win32::window::{
1010
with_dummy_window, HWnd, OwnDeviceContext, PixelFormat, PixelFormatAttribs, WglContext,
1111
WglExtra,

src/platform/x11/drag_n_drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::xcb_connection::{Atoms, GetPropertyError};
22
use super::*;
33
use crate::handler::WindowHandler;
44
use crate::platform::x11::error::ReplyExt;
5-
use crate::tracing::warn;
5+
use crate::warn;
66
use crate::{DropData, Event, MouseEvent};
77
use core::result::Result;
88
use dpi::PhysicalPosition;

src/platform/x11/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::platform::x11::drag_n_drop::ParseError;
22
use crate::platform::x11::xcb_connection::GetPropertyError;
3-
use crate::tracing::warn;
3+
use crate::warn;
44
use crate::wrappers::xlib::{DisplayOpenFailedError, InitThreadsFailedError};
55
use crate::HandlerError;
66
use std::sync::mpsc::RecvError;

src/platform/x11/event_loop.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::drag_n_drop::DragNDropState;
22
use super::keyboard::{convert_key_press_event, convert_key_release_event, key_mods};
33
use super::*;
44

5+
use crate::warn;
56
use crate::wrappers::connection_poller::{ConnectionPoller, PollStatus};
67
use crate::wrappers::xkbcommon::XkbcommonState;
78
use crate::{Event, MouseButton, MouseEvent, ScrollDelta, WindowEvent, WindowHandler, WindowSize};
@@ -59,11 +60,16 @@ impl EventLoop {
5960
}
6061

6162
if let Some(size) = self.new_physical_size.take() {
62-
self.window.window_size.set(size);
63+
let previous = self.window.window_size.replace(size);
6364

6465
let scale_factor = self.window.scaling_factor.get();
65-
66-
self.handler.resized(WindowSize::from_physical(size.cast(), scale_factor));
66+
if let Err(e) =
67+
self.handler.resized(WindowSize::from_physical(size.cast(), scale_factor))
68+
{
69+
warn!("Window Handler failed to resize: {}", e);
70+
self.window.window_size.set(previous);
71+
self.window.xcb_window.resize(previous.cast())?.check_warn();
72+
}
6773
}
6874

6975
Ok(())

src/platform/x11/window_shared.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use raw_window_handle::{DisplayHandle, XlibWindowHandle};
66
use std::cell::Cell;
77
use std::rc::Rc;
88
use std::sync::Arc;
9-
use x11rb::protocol::xproto::{
10-
ChangeWindowAttributesAux, ConfigureWindowAux, ConnectionExt, InputFocus, Visualid,
11-
};
9+
use x11rb::protocol::xproto::{ChangeWindowAttributesAux, ConnectionExt, InputFocus, Visualid};
1210
use x11rb::CURRENT_TIME;
1311

1412
pub(crate) struct WindowInner {
@@ -90,16 +88,7 @@ impl WindowInner {
9088

9189
pub fn resize(&self, size: Size) -> Result<()> {
9290
let new_physical_size = size.to_physical::<u32>(self.scaling_factor.get());
93-
94-
self.connection
95-
.conn
96-
.configure_window(
97-
self.xcb_window.id().get(),
98-
&ConfigureWindowAux::new()
99-
.width(new_physical_size.width)
100-
.height(new_physical_size.height),
101-
)?
102-
.check()?;
91+
self.xcb_window.resize(new_physical_size)?;
10392

10493
// This will trigger a `ConfigureNotify` event which will in turn change `self.window_info`
10594
// and notify the window handler about it

src/platform/x11/xcb_window.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use std::num::{NonZero, NonZeroU32};
55
use std::rc::Rc;
66
use x11rb::connection::Connection;
77
use x11rb::cookie::VoidCookie;
8-
use x11rb::errors::ReplyOrIdError;
8+
use x11rb::errors::{ConnectionError, ReplyOrIdError};
99
use x11rb::protocol::xproto::{
10-
AtomEnum, ConnectionExt as _, CreateWindowAux, EventMask, PropMode, WindowClass,
10+
AtomEnum, ConfigureWindowAux, ConnectionExt as _, CreateWindowAux, EventMask, PropMode,
11+
WindowClass,
1112
};
1213
use x11rb::wrapper::ConnectionExt as _;
1314
use x11rb::xcb_ffi::XCBConnection;
@@ -63,6 +64,15 @@ impl XcbWindow {
6364
Ok(self.connection.conn.map_window(self.window_id.get())?)
6465
}
6566

67+
pub fn resize(
68+
&self, size: PhysicalSize<u32>,
69+
) -> Result<VoidCookie<'_, XCBConnection>, ConnectionError> {
70+
Ok(self.connection.conn.configure_window(
71+
self.id().get(),
72+
&ConfigureWindowAux::new().width(size.width).height(size.height),
73+
)?)
74+
}
75+
6676
pub fn set_title(&self, title: &str) -> Result<VoidCookie<'_, XCBConnection>, ReplyOrIdError> {
6777
Ok(self.connection.conn.change_property8(
6878
PropMode::REPLACE,

0 commit comments

Comments
 (0)