From 8856b6ecb7f9633a47ae51d8b8fd8dd0899ad4d9 Mon Sep 17 00:00:00 2001 From: Freya Gentz Date: Thu, 23 Jan 2020 12:42:15 -0700 Subject: [PATCH] Remove unused code in X11 backend. (#1416) Signed-off-by: Freya Gentz --- src/platform_impl/linux/x11/mod.rs | 12 ---- .../linux/x11/util/client_msg.rs | 58 ------------------- src/platform_impl/linux/x11/util/format.rs | 13 ----- src/platform_impl/linux/x11/util/geometry.rs | 36 ------------ src/platform_impl/linux/x11/util/hint.rs | 49 +--------------- src/platform_impl/linux/x11/util/mod.rs | 13 ----- .../linux/x11/util/window_property.rs | 1 + 7 files changed, 2 insertions(+), 180 deletions(-) diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 7aea3b5e..35c1987e 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -489,21 +489,9 @@ impl<'a> Deref for DeviceInfo<'a> { #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct WindowId(ffi::Window); -impl WindowId { - pub unsafe fn dummy() -> Self { - WindowId(0) - } -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DeviceId(c_int); -impl DeviceId { - pub unsafe fn dummy() -> Self { - DeviceId(0) - } -} - pub struct Window(Arc); impl Deref for Window { diff --git a/src/platform_impl/linux/x11/util/client_msg.rs b/src/platform_impl/linux/x11/util/client_msg.rs index 3fafcdf9..2f2b7edf 100644 --- a/src/platform_impl/linux/x11/util/client_msg.rs +++ b/src/platform_impl/linux/x11/util/client_msg.rs @@ -43,62 +43,4 @@ impl XConnection { }; self.send_event(target_window, event_mask, event) } - - // Prepare yourself for the ultimate in unsafety! - // You should favor `send_client_msg` whenever possible, but some protocols (i.e. startup notification) require you - // to send more than one message worth of data. - pub fn send_client_msg_multi( - &self, - window: c_ulong, // The window this is "about"; not necessarily this window - target_window: c_ulong, // The window we're sending to - message_type: ffi::Atom, - event_mask: Option, - data: &[T], - ) -> Flusher<'_> { - let format = T::FORMAT; - let size_of_t = mem::size_of::(); - debug_assert_eq!(size_of_t, format.get_actual_size()); - let mut event = ffi::XClientMessageEvent { - type_: ffi::ClientMessage, - display: self.display, - window, - message_type, - format: format as c_int, - data: ffi::ClientMessageData::new(), - // These fields are ignored by `XSendEvent` - serial: 0, - send_event: 0, - }; - - let t_per_payload = format.get_payload_size() / size_of_t; - assert!(t_per_payload > 0); - let payload_count = data.len() / t_per_payload; - let payload_remainder = data.len() % t_per_payload; - let payload_ptr = data.as_ptr() as *const ClientMsgPayload; - - let mut payload_index = 0; - while payload_index < payload_count { - let payload = unsafe { payload_ptr.offset(payload_index as isize) }; - payload_index += 1; - event.data = unsafe { mem::transmute(*payload) }; - self.send_event(target_window, event_mask, &event).queue(); - } - - if payload_remainder > 0 { - let mut payload: ClientMsgPayload = [0; 5]; - let t_payload = payload.as_mut_ptr() as *mut T; - let invalid_payload = unsafe { payload_ptr.offset(payload_index as isize) }; - let invalid_t_payload = invalid_payload as *const T; - let mut t_index = 0; - while t_index < payload_remainder { - let valid_t = unsafe { invalid_t_payload.offset(t_index as isize) }; - unsafe { (*t_payload.offset(t_index as isize)) = (*valid_t).clone() }; - t_index += 1; - } - event.data = unsafe { mem::transmute(payload) }; - self.send_event(target_window, event_mask, &event).queue(); - } - - Flusher::new(self) - } } diff --git a/src/platform_impl/linux/x11/util/format.rs b/src/platform_impl/linux/x11/util/format.rs index 6090c65d..1ab5e01f 100644 --- a/src/platform_impl/linux/x11/util/format.rs +++ b/src/platform_impl/linux/x11/util/format.rs @@ -21,10 +21,6 @@ impl Format { } } - pub fn is_same_size_as(&self) -> bool { - mem::size_of::() == self.get_actual_size() - } - pub fn get_actual_size(&self) -> usize { match self { &Format::Char => mem::size_of::(), @@ -32,15 +28,6 @@ impl Format { &Format::Long => mem::size_of::(), } } - - pub fn get_payload_size(&self) -> usize { - match self { - // Due to the wonders of X11, half the space goes unused if you're not using longs (on 64-bit). - &Format::Char => mem::size_of::() * 20, - &Format::Short => mem::size_of::() * 10, - &Format::Long => mem::size_of::() * 5, - } - } } pub trait Formattable: Debug + Clone + Copy + PartialEq + PartialOrd { diff --git a/src/platform_impl/linux/x11/util/geometry.rs b/src/platform_impl/linux/x11/util/geometry.rs index 149418e3..d8f466fc 100644 --- a/src/platform_impl/linux/x11/util/geometry.rs +++ b/src/platform_impl/linux/x11/util/geometry.rs @@ -1,7 +1,6 @@ use std::cmp; use super::*; -use crate::dpi::{LogicalPosition, LogicalSize}; // Friendly neighborhood axis-aligned rectangle #[derive(Debug, Clone, PartialEq, Eq)] @@ -89,16 +88,6 @@ impl FrameExtents { pub fn from_border(border: c_ulong) -> Self { Self::new(border, border, border, border) } - - pub fn as_logical(&self, factor: f64) -> LogicalFrameExtents { - let logicalize = |value: c_ulong| value as f64 / factor; - LogicalFrameExtents { - left: logicalize(self.left), - right: logicalize(self.right), - top: logicalize(self.top), - bottom: logicalize(self.bottom), - } - } } #[derive(Debug, Clone)] @@ -135,20 +124,6 @@ impl FrameExtentsHeuristic { } } - pub fn inner_pos_to_outer_logical( - &self, - mut logical: LogicalPosition, - factor: f64, - ) -> LogicalPosition { - use self::FrameExtentsHeuristicPath::*; - if self.heuristic_path != UnsupportedBordered { - let frame_extents = self.frame_extents.as_logical(factor); - logical.x -= frame_extents.left; - logical.y -= frame_extents.top; - } - logical - } - pub fn inner_size_to_outer(&self, width: u32, height: u32) -> (u32, u32) { ( width.saturating_add( @@ -163,17 +138,6 @@ impl FrameExtentsHeuristic { ), ) } - - pub fn inner_size_to_outer_logical( - &self, - mut logical: LogicalSize, - factor: f64, - ) -> LogicalSize { - let frame_extents = self.frame_extents.as_logical(factor); - logical.width += frame_extents.left + frame_extents.right; - logical.height += frame_extents.top + frame_extents.bottom; - logical - } } impl XConnection { diff --git a/src/platform_impl/linux/x11/util/hint.rs b/src/platform_impl/linux/x11/util/hint.rs index 94c7e33a..809f3063 100644 --- a/src/platform_impl/linux/x11/util/hint.rs +++ b/src/platform_impl/linux/x11/util/hint.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use super::*; #[derive(Debug)] +#[allow(dead_code)] pub enum StateOperation { Remove = 0, // _NET_WM_STATE_REMOVE Add = 1, // _NET_WM_STATE_ADD @@ -189,22 +190,6 @@ impl<'a> NormalHints<'a> { } } - pub fn has_flag(&self, flag: c_long) -> bool { - has_flag(self.size_hints.flags, flag) - } - - fn getter(&self, flag: c_long, field1: &c_int, field2: &c_int) -> Option<(u32, u32)> { - if self.has_flag(flag) { - Some((*field1 as _, *field2 as _)) - } else { - None - } - } - - pub fn get_size(&self) -> Option<(u32, u32)> { - self.getter(ffi::PSize, &self.size_hints.width, &self.size_hints.height) - } - // WARNING: This hint is obsolete pub fn set_size(&mut self, size: Option<(u32, u32)>) { if let Some((width, height)) = size { @@ -216,14 +201,6 @@ impl<'a> NormalHints<'a> { } } - pub fn get_max_size(&self) -> Option<(u32, u32)> { - self.getter( - ffi::PMaxSize, - &self.size_hints.max_width, - &self.size_hints.max_height, - ) - } - pub fn set_max_size(&mut self, max_size: Option<(u32, u32)>) { if let Some((max_width, max_height)) = max_size { self.size_hints.flags |= ffi::PMaxSize; @@ -234,14 +211,6 @@ impl<'a> NormalHints<'a> { } } - pub fn get_min_size(&self) -> Option<(u32, u32)> { - self.getter( - ffi::PMinSize, - &self.size_hints.min_width, - &self.size_hints.min_height, - ) - } - pub fn set_min_size(&mut self, min_size: Option<(u32, u32)>) { if let Some((min_width, min_height)) = min_size { self.size_hints.flags |= ffi::PMinSize; @@ -252,14 +221,6 @@ impl<'a> NormalHints<'a> { } } - pub fn get_resize_increments(&self) -> Option<(u32, u32)> { - self.getter( - ffi::PResizeInc, - &self.size_hints.width_inc, - &self.size_hints.height_inc, - ) - } - pub fn set_resize_increments(&mut self, resize_increments: Option<(u32, u32)>) { if let Some((width_inc, height_inc)) = resize_increments { self.size_hints.flags |= ffi::PResizeInc; @@ -270,14 +231,6 @@ impl<'a> NormalHints<'a> { } } - pub fn get_base_size(&self) -> Option<(u32, u32)> { - self.getter( - ffi::PBaseSize, - &self.size_hints.base_width, - &self.size_hints.base_height, - ) - } - pub fn set_base_size(&mut self, base_size: Option<(u32, u32)>) { if let Some((base_width, base_height)) = base_size { self.size_hints.flags |= ffi::PBaseSize; diff --git a/src/platform_impl/linux/x11/util/mod.rs b/src/platform_impl/linux/x11/util/mod.rs index 4e854236..4bd14206 100644 --- a/src/platform_impl/linux/x11/util/mod.rs +++ b/src/platform_impl/linux/x11/util/mod.rs @@ -23,18 +23,12 @@ pub use self::{ use std::{ mem::{self, MaybeUninit}, - ops::BitAnd, os::raw::*, ptr, }; use super::{ffi, XConnection, XError}; -pub fn reinterpret<'a, A, B>(a: &'a A) -> &'a B { - let b_ptr = a as *const _ as *const B; - unsafe { &*b_ptr } -} - pub fn maybe_change(field: &mut Option, value: T) -> bool { let wrapped = Some(value); if *field != wrapped { @@ -45,13 +39,6 @@ pub fn maybe_change(field: &mut Option, value: T) -> bool { } } -pub fn has_flag(bitset: T, flag: T) -> bool -where - T: Copy + PartialEq + BitAnd, -{ - bitset & flag == flag -} - #[must_use = "This request was made asynchronously, and is still in the output buffer. You must explicitly choose to either `.flush()` (empty the output buffer, sending the request now) or `.queue()` (wait to send the request, allowing you to continue to add more requests without additional round-trips). For more information, see the documentation for `util::flush_requests`."] pub struct Flusher<'a> { xconn: &'a XConnection, diff --git a/src/platform_impl/linux/x11/util/window_property.rs b/src/platform_impl/linux/x11/util/window_property.rs index 0b9e7a71..34977f36 100644 --- a/src/platform_impl/linux/x11/util/window_property.rs +++ b/src/platform_impl/linux/x11/util/window_property.rs @@ -26,6 +26,7 @@ impl GetPropertyError { const PROPERTY_BUFFER_SIZE: c_long = 1024; // 4k of RAM ought to be enough for anyone! #[derive(Debug)] +#[allow(dead_code)] pub enum PropMode { Replace = ffi::PropModeReplace as isize, Prepend = ffi::PropModePrepend as isize,