From 333b3163d3e66407cf75a61ec8e2ce9149b0e422 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 9 Sep 2022 18:32:58 +0400 Subject: [PATCH] Remove Xbase in Rust --- rust-polytreewm/src/lib.rs | 2 - rust-polytreewm/src/xbase.rs | 80 ------------------------------------ 2 files changed, 82 deletions(-) delete mode 100644 rust-polytreewm/src/xbase.rs diff --git a/rust-polytreewm/src/lib.rs b/rust-polytreewm/src/lib.rs index 6994c5d..62f0b75 100644 --- a/rust-polytreewm/src/lib.rs +++ b/rust-polytreewm/src/lib.rs @@ -1,10 +1,8 @@ mod api; mod constraints; -mod xbase; pub mod geom; pub mod settings; pub mod unit; pub use settings::Settings; -pub use xbase::Xbase; diff --git a/rust-polytreewm/src/xbase.rs b/rust-polytreewm/src/xbase.rs deleted file mode 100644 index eca95f3..0000000 --- a/rust-polytreewm/src/xbase.rs +++ /dev/null @@ -1,80 +0,0 @@ -use crate::geom; - -use std::os::raw::*; -use std::ptr::null; - -use x11::xlib::{self, Display}; - -pub type ErrorHandler = - unsafe extern "C" fn(*mut Display, *mut xlib::XErrorEvent) -> c_int; - -pub struct Xbase { - program_title: String, - x_display: *mut Display, - x_screen: c_int, - x_root: c_ulong, - screen_sizes: geom::Sizes, - x_error: Option, -} - -impl Xbase { - pub fn new( - program_title: String, - x_error_handler: ErrorHandler, - ) -> Result> { - unsafe { - if xlib::XSupportsLocale() == 0 { - return Err("no locale support in X".into()); - } - - let x_display = xlib::XOpenDisplay(null()); - if x_display.is_null() { - return Err("cannot open X display".into()); - } - - let x_screen = xlib::XDefaultScreen(x_display); - let x_root = xlib::XRootWindow(x_display, x_screen); - - let screen_sizes = geom::Sizes::new( - xlib::XDisplayWidth(x_display, x_screen), - xlib::XDisplayHeight(x_display, x_screen), - ); - - let x_error = xlib::XSetErrorHandler(Some(x_error_wm_check)); - - // TODO: XSetErrorHandler - - xlib::XSelectInput( - x_display, - xlib::XDefaultRootWindow(x_display), - xlib::SubstructureRedirectMask, - ); - xlib::XSync(x_display, xlib::False); - xlib::XSetErrorHandler(Some(x_error_handler)); - // TODO: XSetErrorHandler - xlib::XSync(x_display, xlib::False); - - Ok(Self { - program_title, - x_display, - x_screen, - x_root, - screen_sizes, - x_error, - }) - } - } -} - -impl Drop for Xbase { - fn drop(&mut self) { - unsafe { xlib::XCloseDisplay(self.x_display) }; - } -} - -unsafe extern "C" fn x_error_wm_check( - _display: *mut Display, - _x_error_event: *mut xlib::XErrorEvent, -) -> c_int { - panic!("another window manager is already running"); -}