chore(rustfmt): use nightly (#2325)
Stable rustfmt lacks a lot of features resulting in worse formatted code, thus use nightly formatter.
This commit is contained in:
parent
7006c7ceca
commit
7b0c7b6cb2
154 changed files with 3439 additions and 5891 deletions
|
|
@ -1,50 +1,40 @@
|
|||
use std::{
|
||||
cmp, env,
|
||||
ffi::CString,
|
||||
mem::replace,
|
||||
os::raw::*,
|
||||
path::Path,
|
||||
sync::{Arc, Mutex, MutexGuard},
|
||||
};
|
||||
use std::ffi::CString;
|
||||
use std::mem::replace;
|
||||
use std::os::raw::*;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
use std::{cmp, env};
|
||||
|
||||
use tracing::{debug, info, warn};
|
||||
use x11rb::{
|
||||
connection::Connection,
|
||||
properties::{WmHints, WmSizeHints, WmSizeHintsSpecification},
|
||||
protocol::{
|
||||
randr,
|
||||
shape::SK,
|
||||
xfixes::{ConnectionExt, RegionWrapper},
|
||||
xinput,
|
||||
xproto::{self, ConnectionExt as _, Rectangle},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
cursor::{Cursor, CustomCursor as RootCustomCursor},
|
||||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
||||
error::{ExternalError, NotSupportedError, OsError as RootOsError},
|
||||
event::{Event, InnerSizeWriter, WindowEvent},
|
||||
event_loop::AsyncRequestSerial,
|
||||
platform::x11::WindowType,
|
||||
platform_impl::{
|
||||
x11::{
|
||||
atoms::*, xinput_fp1616_to_float, MonitorHandle as X11MonitorHandle, WakeSender,
|
||||
X11Error,
|
||||
},
|
||||
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformCustomCursor,
|
||||
PlatformIcon, VideoModeHandle as PlatformVideoModeHandle,
|
||||
},
|
||||
window::{
|
||||
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
|
||||
WindowButtons, WindowLevel,
|
||||
},
|
||||
use x11rb::connection::Connection;
|
||||
use x11rb::properties::{WmHints, WmSizeHints, WmSizeHintsSpecification};
|
||||
use x11rb::protocol::shape::SK;
|
||||
use x11rb::protocol::xfixes::{ConnectionExt, RegionWrapper};
|
||||
use x11rb::protocol::xproto::{self, ConnectionExt as _, Rectangle};
|
||||
use x11rb::protocol::{randr, xinput};
|
||||
|
||||
use crate::cursor::{Cursor, CustomCursor as RootCustomCursor};
|
||||
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
|
||||
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError};
|
||||
use crate::event::{Event, InnerSizeWriter, WindowEvent};
|
||||
use crate::event_loop::AsyncRequestSerial;
|
||||
use crate::platform::x11::WindowType;
|
||||
use crate::platform_impl::x11::atoms::*;
|
||||
use crate::platform_impl::x11::{
|
||||
xinput_fp1616_to_float, MonitorHandle as X11MonitorHandle, WakeSender, X11Error,
|
||||
};
|
||||
use crate::platform_impl::{
|
||||
Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformCustomCursor,
|
||||
PlatformIcon, VideoModeHandle as PlatformVideoModeHandle,
|
||||
};
|
||||
use crate::window::{
|
||||
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
|
||||
WindowButtons, WindowLevel,
|
||||
};
|
||||
|
||||
use super::util::{self, SelectedCursor};
|
||||
use super::{
|
||||
ffi,
|
||||
util::{self, SelectedCursor},
|
||||
ActiveEventLoop, CookieResultExt, ImeRequest, ImeSender, VoidCookie, WindowId, XConnection,
|
||||
ffi, ActiveEventLoop, CookieResultExt, ImeRequest, ImeSender, VoidCookie, WindowId, XConnection,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -86,11 +76,8 @@ pub enum Visibility {
|
|||
|
||||
impl SharedState {
|
||||
fn new(last_monitor: X11MonitorHandle, window_attributes: &WindowAttributes) -> Mutex<Self> {
|
||||
let visibility = if window_attributes.visible {
|
||||
Visibility::YesWait
|
||||
} else {
|
||||
Visibility::No
|
||||
};
|
||||
let visibility =
|
||||
if window_attributes.visible { Visibility::YesWait } else { Visibility::No };
|
||||
|
||||
Mutex::new(SharedState {
|
||||
last_monitor,
|
||||
|
|
@ -191,16 +178,13 @@ impl UnownedWindow {
|
|||
|
||||
info!("Guessed window scale factor: {}", scale_factor);
|
||||
|
||||
let max_inner_size: Option<(u32, u32)> = window_attrs
|
||||
.max_inner_size
|
||||
.map(|size| size.to_physical::<u32>(scale_factor).into());
|
||||
let min_inner_size: Option<(u32, u32)> = window_attrs
|
||||
.min_inner_size
|
||||
.map(|size| size.to_physical::<u32>(scale_factor).into());
|
||||
let max_inner_size: Option<(u32, u32)> =
|
||||
window_attrs.max_inner_size.map(|size| size.to_physical::<u32>(scale_factor).into());
|
||||
let min_inner_size: Option<(u32, u32)> =
|
||||
window_attrs.min_inner_size.map(|size| size.to_physical::<u32>(scale_factor).into());
|
||||
|
||||
let position = window_attrs
|
||||
.position
|
||||
.map(|position| position.to_physical::<i32>(scale_factor));
|
||||
let position =
|
||||
window_attrs.position.map(|position| position.to_physical::<i32>(scale_factor));
|
||||
|
||||
let dimensions = {
|
||||
// x11 only applies constraints when the window is actively resized
|
||||
|
|
@ -219,10 +203,7 @@ impl UnownedWindow {
|
|||
dimensions.0 = cmp::max(dimensions.0, min.0);
|
||||
dimensions.1 = cmp::max(dimensions.1, min.1);
|
||||
}
|
||||
debug!(
|
||||
"Calculated physical dimensions: {}x{}",
|
||||
dimensions.0, dimensions.1
|
||||
);
|
||||
debug!("Calculated physical dimensions: {}x{}", dimensions.0, dimensions.1);
|
||||
dimensions
|
||||
};
|
||||
|
||||
|
|
@ -238,41 +219,37 @@ impl UnownedWindow {
|
|||
.roots
|
||||
.iter()
|
||||
.flat_map(|root| &root.allowed_depths)
|
||||
.flat_map(|depth| {
|
||||
depth
|
||||
.visuals
|
||||
.iter()
|
||||
.map(move |visual| (visual, depth.depth))
|
||||
});
|
||||
.flat_map(|depth| depth.visuals.iter().map(move |visual| (visual, depth.depth)));
|
||||
|
||||
// creating
|
||||
let (visualtype, depth, require_colormap) = match window_attrs
|
||||
.platform_specific
|
||||
.x11
|
||||
.visual_id
|
||||
{
|
||||
Some(vi) => {
|
||||
// Find this specific visual.
|
||||
let (visualtype, depth) = all_visuals
|
||||
.find(|(visual, _)| visual.visual_id == vi)
|
||||
.ok_or_else(|| os_error!(OsError::XError(X11Error::NoSuchVisual(vi).into())))?;
|
||||
let (visualtype, depth, require_colormap) =
|
||||
match window_attrs.platform_specific.x11.visual_id {
|
||||
Some(vi) => {
|
||||
// Find this specific visual.
|
||||
let (visualtype, depth) =
|
||||
all_visuals.find(|(visual, _)| visual.visual_id == vi).ok_or_else(
|
||||
|| os_error!(OsError::XError(X11Error::NoSuchVisual(vi).into())),
|
||||
)?;
|
||||
|
||||
(Some(visualtype), depth, true)
|
||||
}
|
||||
None if window_attrs.transparent => {
|
||||
// Find a suitable visual, true color with 32 bits of depth.
|
||||
all_visuals
|
||||
.find_map(|(visual, depth)| {
|
||||
(depth == 32 && visual.class == xproto::VisualClass::TRUE_COLOR)
|
||||
.then_some((Some(visual), depth, true))
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
debug!("Could not set transparency, because XMatchVisualInfo returned zero for the required parameters");
|
||||
(None as _, x11rb::COPY_FROM_PARENT as _, false)
|
||||
})
|
||||
}
|
||||
_ => (None, x11rb::COPY_FROM_PARENT as _, false),
|
||||
};
|
||||
(Some(visualtype), depth, true)
|
||||
},
|
||||
None if window_attrs.transparent => {
|
||||
// Find a suitable visual, true color with 32 bits of depth.
|
||||
all_visuals
|
||||
.find_map(|(visual, depth)| {
|
||||
(depth == 32 && visual.class == xproto::VisualClass::TRUE_COLOR)
|
||||
.then_some((Some(visual), depth, true))
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
debug!(
|
||||
"Could not set transparency, because XMatchVisualInfo returned \
|
||||
zero for the required parameters"
|
||||
);
|
||||
(None as _, x11rb::COPY_FROM_PARENT as _, false)
|
||||
})
|
||||
},
|
||||
_ => (None, x11rb::COPY_FROM_PARENT as _, false),
|
||||
};
|
||||
let mut visual = visualtype.map_or(x11rb::COPY_FROM_PARENT, |v| v.visual_id);
|
||||
|
||||
let window_attributes = {
|
||||
|
|
@ -320,11 +297,7 @@ impl UnownedWindow {
|
|||
};
|
||||
|
||||
// Figure out the window's parent.
|
||||
let parent = window_attrs
|
||||
.platform_specific
|
||||
.x11
|
||||
.embed_window
|
||||
.unwrap_or(root);
|
||||
let parent = window_attrs.platform_specific.x11.embed_window.unwrap_or(root);
|
||||
|
||||
// finally creating the window
|
||||
let xwindow = {
|
||||
|
|
@ -419,9 +392,7 @@ impl UnownedWindow {
|
|||
.map(|bin_name| bin_name.to_owned())
|
||||
.unwrap_or_else(|| window_attrs.title.clone());
|
||||
// This environment variable is extraordinarily unlikely to actually be used...
|
||||
let instance = env::var("RESOURCE_NAME")
|
||||
.ok()
|
||||
.unwrap_or_else(|| class.clone());
|
||||
let instance = env::var("RESOURCE_NAME").ok().unwrap_or_else(|| class.clone());
|
||||
(instance, class)
|
||||
};
|
||||
|
||||
|
|
@ -444,12 +415,10 @@ impl UnownedWindow {
|
|||
.ignore_error();
|
||||
|
||||
// Set size hints.
|
||||
let mut min_inner_size = window_attrs
|
||||
.min_inner_size
|
||||
.map(|size| size.to_physical::<u32>(scale_factor));
|
||||
let mut max_inner_size = window_attrs
|
||||
.max_inner_size
|
||||
.map(|size| size.to_physical::<u32>(scale_factor));
|
||||
let mut min_inner_size =
|
||||
window_attrs.min_inner_size.map(|size| size.to_physical::<u32>(scale_factor));
|
||||
let mut max_inner_size =
|
||||
window_attrs.max_inner_size.map(|size| size.to_physical::<u32>(scale_factor));
|
||||
|
||||
if !window_attrs.resizable {
|
||||
if util::wm_name_is_one_of(&["Xfwm4"]) {
|
||||
|
|
@ -534,9 +503,7 @@ impl UnownedWindow {
|
|||
&mut supported_ptr,
|
||||
);
|
||||
if supported_ptr == ffi::False {
|
||||
return Err(os_error!(OsError::Misc(
|
||||
"`XkbSetDetectableAutoRepeat` failed"
|
||||
)));
|
||||
return Err(os_error!(OsError::Misc("`XkbSetDetectableAutoRepeat` failed")));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -556,9 +523,7 @@ impl UnownedWindow {
|
|||
|
||||
// Try to create input context for the window.
|
||||
if let Some(ime) = event_loop.ime.as_ref() {
|
||||
let result = ime
|
||||
.borrow_mut()
|
||||
.create_context(window.xwindow as ffi::Window, false);
|
||||
let result = ime.borrow_mut().create_context(window.xwindow as ffi::Window, false);
|
||||
leap!(result);
|
||||
}
|
||||
|
||||
|
|
@ -647,10 +612,7 @@ impl UnownedWindow {
|
|||
fn set_window_types(&self, window_types: Vec<WindowType>) -> Result<VoidCookie<'_>, X11Error> {
|
||||
let atoms = self.xconn.atoms();
|
||||
let hint_atom = atoms[_NET_WM_WINDOW_TYPE];
|
||||
let atoms: Vec<_> = window_types
|
||||
.iter()
|
||||
.map(|t| t.as_atom(&self.xconn))
|
||||
.collect();
|
||||
let atoms: Vec<_> = window_types.iter().map(|t| t.as_atom(&self.xconn)).collect();
|
||||
|
||||
self.xconn.change_property(
|
||||
self.xwindow,
|
||||
|
|
@ -682,13 +644,9 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn set_theme(&self, theme: Option<Theme>) {
|
||||
self.set_theme_inner(theme)
|
||||
.expect("Failed to change window theme")
|
||||
.ignore_error();
|
||||
self.set_theme_inner(theme).expect("Failed to change window theme").ignore_error();
|
||||
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to change window theme");
|
||||
self.xconn.flush_requests().expect("Failed to change window theme");
|
||||
}
|
||||
|
||||
fn set_netwm(
|
||||
|
|
@ -703,13 +661,7 @@ impl UnownedWindow {
|
|||
self.root,
|
||||
state_atom,
|
||||
Some(xproto::EventMask::SUBSTRUCTURE_REDIRECT | xproto::EventMask::SUBSTRUCTURE_NOTIFY),
|
||||
[
|
||||
operation as u32,
|
||||
properties.0,
|
||||
properties.1,
|
||||
properties.2,
|
||||
properties.3,
|
||||
],
|
||||
[operation as u32, properties.0, properties.1, properties.2, properties.3],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -723,11 +675,7 @@ impl UnownedWindow {
|
|||
// locking up the user's display.
|
||||
self.xconn
|
||||
.xcb_connection()
|
||||
.set_input_focus(
|
||||
xproto::InputFocus::PARENT,
|
||||
self.xwindow,
|
||||
x11rb::CURRENT_TIME,
|
||||
)?
|
||||
.set_input_focus(xproto::InputFocus::PARENT, self.xwindow, x11rb::CURRENT_TIME)?
|
||||
.ignore_error();
|
||||
}
|
||||
|
||||
|
|
@ -745,7 +693,7 @@ impl UnownedWindow {
|
|||
Visibility::No | Visibility::YesWait => {
|
||||
shared_state_lock.desired_fullscreen = Some(fullscreen);
|
||||
return Ok(None);
|
||||
}
|
||||
},
|
||||
Visibility::Yes => (),
|
||||
}
|
||||
|
||||
|
|
@ -768,11 +716,9 @@ impl UnownedWindow {
|
|||
let monitor = video_mode.monitor.as_ref().unwrap();
|
||||
shared_state_lock.desktop_video_mode = Some((
|
||||
monitor.id,
|
||||
self.xconn
|
||||
.get_crtc_mode(monitor.id)
|
||||
.expect("Failed to get desktop video mode"),
|
||||
self.xconn.get_crtc_mode(monitor.id).expect("Failed to get desktop video mode"),
|
||||
));
|
||||
}
|
||||
},
|
||||
// Restore desktop video mode upon exiting exclusive fullscreen
|
||||
(&Some(Fullscreen::Exclusive(_)), &None)
|
||||
| (&Some(Fullscreen::Exclusive(_)), &Some(Fullscreen::Borderless(_))) => {
|
||||
|
|
@ -780,7 +726,7 @@ impl UnownedWindow {
|
|||
self.xconn
|
||||
.set_crtc_config(monitor_id, mode_id)
|
||||
.expect("failed to restore desktop video mode");
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
|
@ -796,18 +742,18 @@ impl UnownedWindow {
|
|||
.expect_then_ignore_error("Failed to restore window position");
|
||||
}
|
||||
flusher.map(Some)
|
||||
}
|
||||
},
|
||||
Some(fullscreen) => {
|
||||
let (video_mode, monitor) = match fullscreen {
|
||||
Fullscreen::Exclusive(PlatformVideoModeHandle::X(ref video_mode)) => {
|
||||
(Some(video_mode), video_mode.monitor.clone().unwrap())
|
||||
}
|
||||
},
|
||||
Fullscreen::Borderless(Some(PlatformMonitorHandle::X(monitor))) => {
|
||||
(None, monitor)
|
||||
}
|
||||
},
|
||||
Fullscreen::Borderless(None) => {
|
||||
(None, self.shared_state_lock().last_monitor.clone())
|
||||
}
|
||||
},
|
||||
#[cfg(wayland_platform)]
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
|
@ -854,7 +800,7 @@ impl UnownedWindow {
|
|||
self.set_position_inner(monitor_origin.0, monitor_origin.1)
|
||||
.expect_then_ignore_error("Failed to set window position");
|
||||
self.set_fullscreen_hint(true).map(Some)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -862,21 +808,15 @@ impl UnownedWindow {
|
|||
pub(crate) fn fullscreen(&self) -> Option<Fullscreen> {
|
||||
let shared_state = self.shared_state_lock();
|
||||
|
||||
shared_state
|
||||
.desired_fullscreen
|
||||
.clone()
|
||||
.unwrap_or_else(|| shared_state.fullscreen.clone())
|
||||
shared_state.desired_fullscreen.clone().unwrap_or_else(|| shared_state.fullscreen.clone())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
|
||||
if let Some(flusher) = self
|
||||
.set_fullscreen_inner(fullscreen)
|
||||
.expect("Failed to change window fullscreen state")
|
||||
if let Some(flusher) =
|
||||
self.set_fullscreen_inner(fullscreen).expect("Failed to change window fullscreen state")
|
||||
{
|
||||
flusher
|
||||
.check()
|
||||
.expect("Failed to change window fullscreen state");
|
||||
flusher.check().expect("Failed to change window fullscreen state");
|
||||
self.invalidate_cached_frame_extents();
|
||||
}
|
||||
}
|
||||
|
|
@ -899,7 +839,7 @@ impl UnownedWindow {
|
|||
drop(shared_state);
|
||||
self.set_fullscreen(fullscreen);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -908,17 +848,11 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
pub fn available_monitors(&self) -> Vec<X11MonitorHandle> {
|
||||
self.xconn
|
||||
.available_monitors()
|
||||
.expect("Failed to get available monitors")
|
||||
self.xconn.available_monitors().expect("Failed to get available monitors")
|
||||
}
|
||||
|
||||
pub fn primary_monitor(&self) -> Option<X11MonitorHandle> {
|
||||
Some(
|
||||
self.xconn
|
||||
.primary_monitor()
|
||||
.expect("Failed to get primary monitor"),
|
||||
)
|
||||
Some(self.xconn.primary_monitor().expect("Failed to get primary monitor"))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -933,9 +867,9 @@ impl UnownedWindow {
|
|||
let hidden_atom = atoms[_NET_WM_STATE_HIDDEN];
|
||||
|
||||
Some(match state {
|
||||
Ok(atoms) => atoms
|
||||
.iter()
|
||||
.any(|atom: &xproto::Atom| *atom as xproto::Atom == hidden_atom),
|
||||
Ok(atoms) => {
|
||||
atoms.iter().any(|atom: &xproto::Atom| *atom as xproto::Atom == hidden_atom)
|
||||
},
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
|
@ -1020,9 +954,7 @@ impl UnownedWindow {
|
|||
self.set_minimized_inner(minimized)
|
||||
.expect_then_ignore_error("Failed to change window minimization");
|
||||
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to change window minimization");
|
||||
self.xconn.flush_requests().expect("Failed to change window minimization");
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -1041,7 +973,7 @@ impl UnownedWindow {
|
|||
let horz_maximized = atoms.iter().any(|atom: &xproto::Atom| *atom == horz_atom);
|
||||
let vert_maximized = atoms.iter().any(|atom: &xproto::Atom| *atom == vert_atom);
|
||||
horz_maximized && vert_maximized
|
||||
}
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -1058,9 +990,7 @@ impl UnownedWindow {
|
|||
pub fn set_maximized(&self, maximized: bool) {
|
||||
self.set_maximized_inner(maximized)
|
||||
.expect_then_ignore_error("Failed to change window maximization");
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to change window maximization");
|
||||
self.xconn.flush_requests().expect("Failed to change window maximization");
|
||||
self.invalidate_cached_frame_extents();
|
||||
}
|
||||
|
||||
|
|
@ -1088,12 +1018,9 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn set_title(&self, title: &str) {
|
||||
self.set_title_inner(title)
|
||||
.expect_then_ignore_error("Failed to set window title");
|
||||
self.set_title_inner(title).expect_then_ignore_error("Failed to set window title");
|
||||
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to set window title");
|
||||
self.xconn.flush_requests().expect("Failed to set window title");
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -1115,9 +1042,7 @@ impl UnownedWindow {
|
|||
pub fn set_decorations(&self, decorations: bool) {
|
||||
self.set_decorations_inner(decorations)
|
||||
.expect_then_ignore_error("Failed to set decoration state");
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to set decoration state");
|
||||
self.xconn.flush_requests().expect("Failed to set decoration state");
|
||||
self.invalidate_cached_frame_extents();
|
||||
}
|
||||
|
||||
|
|
@ -1141,8 +1066,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
fn set_window_level_inner(&self, level: WindowLevel) -> Result<VoidCookie<'_>, X11Error> {
|
||||
self.toggle_atom(_NET_WM_STATE_ABOVE, level == WindowLevel::AlwaysOnTop)?
|
||||
.ignore_error();
|
||||
self.toggle_atom(_NET_WM_STATE_ABOVE, level == WindowLevel::AlwaysOnTop)?.ignore_error();
|
||||
self.toggle_atom(_NET_WM_STATE_BELOW, level == WindowLevel::AlwaysOnBottom)
|
||||
}
|
||||
|
||||
|
|
@ -1150,9 +1074,7 @@ impl UnownedWindow {
|
|||
pub fn set_window_level(&self, level: WindowLevel) {
|
||||
self.set_window_level_inner(level)
|
||||
.expect_then_ignore_error("Failed to set window-level state");
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to set window-level state");
|
||||
self.xconn.flush_requests().expect("Failed to set window-level state");
|
||||
}
|
||||
|
||||
fn set_icon_inner(&self, icon: PlatformIcon) -> Result<VoidCookie<'_>, X11Error> {
|
||||
|
|
@ -1199,7 +1121,7 @@ impl UnownedWindow {
|
|||
match (visible, shared_state.visibility) {
|
||||
(true, Visibility::Yes) | (true, Visibility::YesWait) | (false, Visibility::No) => {
|
||||
return
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
|
@ -1215,18 +1137,14 @@ impl UnownedWindow {
|
|||
&xproto::ConfigureWindowAux::new().stack_mode(xproto::StackMode::ABOVE),
|
||||
)
|
||||
.expect_then_ignore_error("Failed to call `xcb_configure_window`");
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to call XMapRaised");
|
||||
self.xconn.flush_requests().expect("Failed to call XMapRaised");
|
||||
shared_state.visibility = Visibility::YesWait;
|
||||
} else {
|
||||
self.xconn
|
||||
.xcb_connection()
|
||||
.unmap_window(self.xwindow)
|
||||
.expect_then_ignore_error("Failed to call `xcb_unmap_window`");
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to call XUnmapWindow");
|
||||
self.xconn.flush_requests().expect("Failed to call XUnmapWindow");
|
||||
shared_state.visibility = Visibility::No;
|
||||
}
|
||||
}
|
||||
|
|
@ -1237,9 +1155,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
fn update_cached_frame_extents(&self) {
|
||||
let extents = self
|
||||
.xconn
|
||||
.get_frame_extents_heuristic(self.xwindow, self.root);
|
||||
let extents = self.xconn.get_frame_extents_heuristic(self.xwindow, self.root);
|
||||
self.shared_state_lock().frame_extents = Some(extents);
|
||||
}
|
||||
|
||||
|
|
@ -1309,8 +1225,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
pub(crate) fn set_position_physical(&self, x: i32, y: i32) {
|
||||
self.set_position_inner(x, y)
|
||||
.expect_then_ignore_error("Failed to call `XMoveWindow`");
|
||||
self.set_position_inner(x, y).expect_then_ignore_error("Failed to call `XMoveWindow`");
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -1350,14 +1265,10 @@ impl UnownedWindow {
|
|||
.xcb_connection()
|
||||
.configure_window(
|
||||
self.xwindow,
|
||||
&xproto::ConfigureWindowAux::new()
|
||||
.width(width)
|
||||
.height(height),
|
||||
&xproto::ConfigureWindowAux::new().width(width).height(height),
|
||||
)
|
||||
.expect_then_ignore_error("Failed to call `xcb_configure_window`");
|
||||
self.xconn
|
||||
.flush_requests()
|
||||
.expect("Failed to call XResizeWindow");
|
||||
self.xconn.flush_requests().expect("Failed to call XResizeWindow");
|
||||
// cursor_hittest needs to be reapplied after each window resize.
|
||||
if self.shared_state_lock().cursor_hittest.unwrap_or(false) {
|
||||
let _ = self.set_cursor_hittest(true);
|
||||
|
|
@ -1488,19 +1399,17 @@ impl UnownedWindow {
|
|||
|
||||
pub fn set_resizable(&self, resizable: bool) {
|
||||
if util::wm_name_is_one_of(&["Xfwm4"]) {
|
||||
// Making the window unresizable on Xfwm prevents further changes to `WM_NORMAL_HINTS` from being detected.
|
||||
// This makes it impossible for resizing to be re-enabled, and also breaks DPI scaling. As such, we choose
|
||||
// the lesser of two evils and do nothing.
|
||||
// Making the window unresizable on Xfwm prevents further changes to `WM_NORMAL_HINTS`
|
||||
// from being detected. This makes it impossible for resizing to be
|
||||
// re-enabled, and also breaks DPI scaling. As such, we choose the lesser of
|
||||
// two evils and do nothing.
|
||||
warn!("To avoid a WM bug, disabling resizing has no effect on Xfwm4");
|
||||
return;
|
||||
}
|
||||
|
||||
let (min_size, max_size) = if resizable {
|
||||
let shared_state_lock = self.shared_state_lock();
|
||||
(
|
||||
shared_state_lock.min_inner_size,
|
||||
shared_state_lock.max_inner_size,
|
||||
)
|
||||
(shared_state_lock.min_inner_size, shared_state_lock.max_inner_size)
|
||||
} else {
|
||||
let window_size = Some(Size::from(self.inner_size()));
|
||||
(window_size, window_size)
|
||||
|
|
@ -1559,21 +1468,19 @@ impl UnownedWindow {
|
|||
{
|
||||
self.xconn.set_cursor_icon(self.xwindow, Some(icon));
|
||||
}
|
||||
}
|
||||
Cursor::Custom(RootCustomCursor {
|
||||
inner: PlatformCustomCursor::X(cursor),
|
||||
}) => {
|
||||
},
|
||||
Cursor::Custom(RootCustomCursor { inner: PlatformCustomCursor::X(cursor) }) => {
|
||||
#[allow(clippy::mutex_atomic)]
|
||||
if *self.cursor_visible.lock().unwrap() {
|
||||
self.xconn.set_custom_cursor(self.xwindow, &cursor);
|
||||
}
|
||||
|
||||
*self.selected_cursor.lock().unwrap() = SelectedCursor::Custom(cursor);
|
||||
}
|
||||
},
|
||||
#[cfg(wayland_platform)]
|
||||
Cursor::Custom(RootCustomCursor {
|
||||
inner: PlatformCustomCursor::Wayland(_),
|
||||
}) => tracing::error!("passed a Wayland cursor to X11 backend"),
|
||||
Cursor::Custom(RootCustomCursor { inner: PlatformCustomCursor::Wayland(_) }) => {
|
||||
tracing::error!("passed a Wayland cursor to X11 backend")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1629,23 +1536,23 @@ impl UnownedWindow {
|
|||
xproto::GrabStatus::SUCCESS => Ok(()),
|
||||
xproto::GrabStatus::ALREADY_GRABBED => {
|
||||
Err("Cursor could not be confined: already confined by another client")
|
||||
}
|
||||
},
|
||||
xproto::GrabStatus::INVALID_TIME => {
|
||||
Err("Cursor could not be confined: invalid time")
|
||||
}
|
||||
},
|
||||
xproto::GrabStatus::NOT_VIEWABLE => {
|
||||
Err("Cursor could not be confined: confine location not viewable")
|
||||
}
|
||||
},
|
||||
xproto::GrabStatus::FROZEN => {
|
||||
Err("Cursor could not be confined: frozen by another client")
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.map_err(|err| ExternalError::Os(os_error!(OsError::Misc(err))))
|
||||
}
|
||||
},
|
||||
CursorGrabMode::Locked => {
|
||||
return Err(ExternalError::NotSupported(NotSupportedError::new()));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
if result.is_ok() {
|
||||
|
|
@ -1662,23 +1569,20 @@ impl UnownedWindow {
|
|||
if visible == *visible_lock {
|
||||
return;
|
||||
}
|
||||
let cursor = if visible {
|
||||
Some((*self.selected_cursor.lock().unwrap()).clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let cursor =
|
||||
if visible { Some((*self.selected_cursor.lock().unwrap()).clone()) } else { None };
|
||||
*visible_lock = visible;
|
||||
drop(visible_lock);
|
||||
match cursor {
|
||||
Some(SelectedCursor::Custom(cursor)) => {
|
||||
self.xconn.set_custom_cursor(self.xwindow, &cursor);
|
||||
}
|
||||
},
|
||||
Some(SelectedCursor::Named(cursor)) => {
|
||||
self.xconn.set_cursor_icon(self.xwindow, Some(cursor));
|
||||
}
|
||||
},
|
||||
None => {
|
||||
self.xconn.set_cursor_icon(self.xwindow, None);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1831,8 +1735,7 @@ impl UnownedWindow {
|
|||
let state_atom = atoms[WM_STATE];
|
||||
let state_type_atom = atoms[CARD32];
|
||||
let is_minimized = if let Ok(state) =
|
||||
self.xconn
|
||||
.get_property::<u32>(self.xwindow, state_atom, state_type_atom)
|
||||
self.xconn.get_property::<u32>(self.xwindow, state_atom, state_type_atom)
|
||||
{
|
||||
state.contains(&super::ICONIC_STATE)
|
||||
} else {
|
||||
|
|
@ -1915,9 +1818,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn request_redraw(&self) {
|
||||
self.redraw_sender
|
||||
.send(WindowId(self.xwindow as _))
|
||||
.unwrap();
|
||||
self.redraw_sender.send(WindowId(self.xwindow as _)).unwrap();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -2001,10 +1902,7 @@ fn cast_dimension_to_hint(val: u32) -> i32 {
|
|||
/// Use the above strategy to cast a physical size into a hinted size.
|
||||
fn cast_physical_size_to_hint(size: PhysicalSize<u32>) -> (i32, i32) {
|
||||
let PhysicalSize { width, height } = size;
|
||||
(
|
||||
cast_dimension_to_hint(width),
|
||||
cast_dimension_to_hint(height),
|
||||
)
|
||||
(cast_dimension_to_hint(width), cast_dimension_to_hint(height))
|
||||
}
|
||||
|
||||
/// Use the above strategy to cast a size into a hinted size.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue