Skip to content

Commit a904386

Browse files
murarthOsspial
authored andcommitted
Implement DPI Usability Upgrades for X11 and Wayland (#1098)
* Fix compile errors * Use `mio` for the X11 event loop * Removes `calloop` from the X11 event loop, as the method of draining a source using a closure provided to the `calloop::EventLoop` instance conflicts with the need to deliver events directly to the callback provided to `EventLoop::run`, in order to respond to the value provided by `WindowEvent::HiDpiFactorChanged`. * Implement interactive `HiDpiFactorChanged` event for X11 * Implement interactive `HiDpiFactorChanged` event for Wayland * Run cargo fmt * Fix Wayland not processing events from EventQueue * Backport #981
1 parent 35e7cf6 commit a904386

12 files changed

Lines changed: 615 additions & 643 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ features = [
7878
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
7979
wayland-client = { version = "0.23.0", features = [ "dlopen", "egl", "cursor", "eventloop"] }
8080
calloop = "0.4.2"
81+
mio = "0.6"
82+
mio-extras = "2.0"
8183
smithay-client-toolkit = "0.6"
8284
x11-dl = "2.18.3"
8385
percent-encoding = "2.0"

src/platform_impl/linux/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use smithay_client_toolkit::reexports::client::ConnectError;
88

99
pub use self::x11::XNotSupported;
1010
use self::x11::{
11-
ffi::XVisualInfo, get_xtarget, util::WindowType as XWindowType, XConnection, XError,
11+
ffi::XVisualInfo, util::WindowType as XWindowType, XConnection, XError,
1212
};
1313
use crate::{
14-
dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize},
14+
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
1515
error::{ExternalError, NotSupportedError, OsError as RootOsError},
1616
event::Event,
1717
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootELW},
@@ -248,63 +248,63 @@ impl Window {
248248
}
249249

250250
#[inline]
251-
pub fn outer_position(&self) -> Result<LogicalPosition, NotSupportedError> {
251+
pub fn outer_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
252252
match self {
253253
&Window::X(ref w) => w.outer_position(),
254254
&Window::Wayland(ref w) => w.outer_position(),
255255
}
256256
}
257257

258258
#[inline]
259-
pub fn inner_position(&self) -> Result<LogicalPosition, NotSupportedError> {
259+
pub fn inner_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
260260
match self {
261261
&Window::X(ref m) => m.inner_position(),
262262
&Window::Wayland(ref m) => m.inner_position(),
263263
}
264264
}
265265

266266
#[inline]
267-
pub fn set_outer_position(&self, position: LogicalPosition) {
267+
pub fn set_outer_position(&self, position: Position) {
268268
match self {
269269
&Window::X(ref w) => w.set_outer_position(position),
270270
&Window::Wayland(ref w) => w.set_outer_position(position),
271271
}
272272
}
273273

274274
#[inline]
275-
pub fn inner_size(&self) -> LogicalSize {
275+
pub fn inner_size(&self) -> PhysicalSize {
276276
match self {
277277
&Window::X(ref w) => w.inner_size(),
278278
&Window::Wayland(ref w) => w.inner_size(),
279279
}
280280
}
281281

282282
#[inline]
283-
pub fn outer_size(&self) -> LogicalSize {
283+
pub fn outer_size(&self) -> PhysicalSize {
284284
match self {
285285
&Window::X(ref w) => w.outer_size(),
286286
&Window::Wayland(ref w) => w.outer_size(),
287287
}
288288
}
289289

290290
#[inline]
291-
pub fn set_inner_size(&self, size: LogicalSize) {
291+
pub fn set_inner_size(&self, size: Size) {
292292
match self {
293293
&Window::X(ref w) => w.set_inner_size(size),
294294
&Window::Wayland(ref w) => w.set_inner_size(size),
295295
}
296296
}
297297

298298
#[inline]
299-
pub fn set_min_inner_size(&self, dimensions: Option<LogicalSize>) {
299+
pub fn set_min_inner_size(&self, dimensions: Option<Size>) {
300300
match self {
301301
&Window::X(ref w) => w.set_min_inner_size(dimensions),
302302
&Window::Wayland(ref w) => w.set_min_inner_size(dimensions),
303303
}
304304
}
305305

306306
#[inline]
307-
pub fn set_max_inner_size(&self, dimensions: Option<LogicalSize>) {
307+
pub fn set_max_inner_size(&self, dimensions: Option<Size>) {
308308
match self {
309309
&Window::X(ref w) => w.set_max_inner_size(dimensions),
310310
&Window::Wayland(ref w) => w.set_max_inner_size(dimensions),
@@ -352,7 +352,7 @@ impl Window {
352352
}
353353

354354
#[inline]
355-
pub fn set_cursor_position(&self, position: LogicalPosition) -> Result<(), ExternalError> {
355+
pub fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> {
356356
match self {
357357
&Window::X(ref w) => w.set_cursor_position(position),
358358
&Window::Wayland(ref w) => w.set_cursor_position(position),
@@ -408,7 +408,7 @@ impl Window {
408408
}
409409

410410
#[inline]
411-
pub fn set_ime_position(&self, position: LogicalPosition) {
411+
pub fn set_ime_position(&self, position: Position) {
412412
match self {
413413
&Window::X(ref w) => w.set_ime_position(position),
414414
&Window::Wayland(_) => (),
@@ -595,7 +595,7 @@ impl<T: 'static> EventLoop<T> {
595595
.into_iter()
596596
.map(MonitorHandle::Wayland)
597597
.collect(),
598-
EventLoop::X(ref evlp) => get_xtarget(&evlp.target)
598+
EventLoop::X(ref evlp) => evlp
599599
.x_connection()
600600
.available_monitors()
601601
.into_iter()
@@ -609,7 +609,7 @@ impl<T: 'static> EventLoop<T> {
609609
match *self {
610610
EventLoop::Wayland(ref evlp) => MonitorHandle::Wayland(evlp.primary_monitor()),
611611
EventLoop::X(ref evlp) => {
612-
MonitorHandle::X(get_xtarget(&evlp.target).x_connection().primary_monitor())
612+
MonitorHandle::X(evlp.x_connection().primary_monitor())
613613
}
614614
}
615615
}
@@ -623,7 +623,7 @@ impl<T: 'static> EventLoop<T> {
623623

624624
pub fn run_return<F>(&mut self, callback: F)
625625
where
626-
F: FnMut(crate::event::Event<T>, &RootELW<T>, &mut ControlFlow),
626+
F: FnMut(crate::event::Event<'_, T>, &RootELW<T>, &mut ControlFlow),
627627
{
628628
match *self {
629629
EventLoop::Wayland(ref mut evlp) => evlp.run_return(callback),
@@ -633,7 +633,7 @@ impl<T: 'static> EventLoop<T> {
633633

634634
pub fn run<F>(self, callback: F) -> !
635635
where
636-
F: 'static + FnMut(crate::event::Event<T>, &RootELW<T>, &mut ControlFlow),
636+
F: 'static + FnMut(crate::event::Event<'_, T>, &RootELW<T>, &mut ControlFlow),
637637
{
638638
match self {
639639
EventLoop::Wayland(evlp) => evlp.run(callback),
@@ -674,12 +674,12 @@ impl<T> EventLoopWindowTarget<T> {
674674
}
675675

676676
fn sticky_exit_callback<T, F>(
677-
evt: Event<T>,
677+
evt: Event<'_, T>,
678678
target: &RootELW<T>,
679679
control_flow: &mut ControlFlow,
680680
callback: &mut F,
681681
) where
682-
F: FnMut(Event<T>, &RootELW<T>, &mut ControlFlow),
682+
F: FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
683683
{
684684
// make ControlFlow::Exit sticky by providing a dummy
685685
// control flow reference if it is already Exit.

0 commit comments

Comments
 (0)