Compare commits
	
		
			2 commits
		
	
	
		
			main
			...
			feature_cu
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							
							
								 | 
						1d15ef6336 | ||
| 
							
							
								 | 
						ae89404de3 | 
| 
						 | 
				
			
			@ -18,4 +18,11 @@ pub mod structs {
 | 
			
		|||
        Dock,
 | 
			
		||||
        Desktop,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
 | 
			
		||||
    pub enum Cursor {
 | 
			
		||||
        Normal,
 | 
			
		||||
        Resize,
 | 
			
		||||
        Move,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,6 +21,11 @@ pub trait WindowServerBackend {
 | 
			
		|||
    fn focus_window(&self, window: Self::Window);
 | 
			
		||||
    fn unfocus_window(&self, window: Self::Window);
 | 
			
		||||
    fn raise_window(&self, window: Self::Window);
 | 
			
		||||
    fn set_window_fullscreen_state(
 | 
			
		||||
        &self,
 | 
			
		||||
        window: Self::Window,
 | 
			
		||||
        fullscreen: bool,
 | 
			
		||||
    );
 | 
			
		||||
    fn hide_window(&self, window: Self::Window);
 | 
			
		||||
    fn kill_window(&self, window: Self::Window);
 | 
			
		||||
    fn get_parent_window(&self, window: Self::Window) -> Option<Self::Window>;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,7 @@ use crate::backends::{
 | 
			
		|||
 | 
			
		||||
use self::{
 | 
			
		||||
    connection::{PropMode, XLibConnection},
 | 
			
		||||
    cursors::Cursors,
 | 
			
		||||
    ewmh::{EWMHAtom, EWMHAtoms},
 | 
			
		||||
    keysym::{
 | 
			
		||||
        keysym_to_virtual_keycode, virtual_keycode_to_keysym,
 | 
			
		||||
| 
						 | 
				
			
			@ -713,6 +714,62 @@ impl Display {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mod cursors {
 | 
			
		||||
    use std::{borrow::Borrow, ops::Index};
 | 
			
		||||
 | 
			
		||||
    use x11::xlib::{Cursor as XCursor, XCreateFontCursor, XFreeCursor};
 | 
			
		||||
 | 
			
		||||
    use crate::backends::structs::Cursor;
 | 
			
		||||
 | 
			
		||||
    use super::connection::XLibConnection;
 | 
			
		||||
 | 
			
		||||
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
 | 
			
		||||
    pub struct Cursors {
 | 
			
		||||
        normal: XCursor,
 | 
			
		||||
        resize: XCursor,
 | 
			
		||||
        grab: XCursor,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    impl Cursors {
 | 
			
		||||
        const LEFT_PTR: u32 = 68;
 | 
			
		||||
        const SIZING: u32 = 120;
 | 
			
		||||
        const FLEUR: u32 = 52;
 | 
			
		||||
 | 
			
		||||
        pub fn from_connection<C: Borrow<XLibConnection>>(con: C) -> Self {
 | 
			
		||||
            unsafe {
 | 
			
		||||
                Self {
 | 
			
		||||
                    normal: XCreateFontCursor(
 | 
			
		||||
                        con.borrow().dpy(),
 | 
			
		||||
                        Self::LEFT_PTR,
 | 
			
		||||
                    ),
 | 
			
		||||
                    resize: XCreateFontCursor(con.borrow().dpy(), Self::SIZING),
 | 
			
		||||
                    grab: XCreateFontCursor(con.borrow().dpy(), Self::FLEUR),
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        pub unsafe fn free<C: Borrow<XLibConnection>>(&self, con: C) {
 | 
			
		||||
            unsafe {
 | 
			
		||||
                XFreeCursor(con.borrow().dpy(), self.normal);
 | 
			
		||||
                XFreeCursor(con.borrow().dpy(), self.resize);
 | 
			
		||||
                XFreeCursor(con.borrow().dpy(), self.grab);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    impl Index<Cursor> for Cursors {
 | 
			
		||||
        type Output = XCursor;
 | 
			
		||||
 | 
			
		||||
        fn index(&self, index: Cursor) -> &Self::Output {
 | 
			
		||||
            match index {
 | 
			
		||||
                Cursor::Normal => &self.normal,
 | 
			
		||||
                Cursor::Resize => &self.resize,
 | 
			
		||||
                Cursor::Move => &self.grab,
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct XLib {
 | 
			
		||||
    connection: Rc<XLibConnection>,
 | 
			
		||||
    atoms: ICCCMAtoms,
 | 
			
		||||
| 
						 | 
				
			
			@ -721,6 +778,13 @@ pub struct XLib {
 | 
			
		|||
    active_border_color: Option<color::XftColor>,
 | 
			
		||||
    inactive_border_color: Option<color::XftColor>,
 | 
			
		||||
    wm_window: Window,
 | 
			
		||||
    cursors: Cursors,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Drop for XLib {
 | 
			
		||||
    fn drop(&mut self) {
 | 
			
		||||
        unsafe { self.cursors.free(self.connection.clone()) };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl XLib {
 | 
			
		||||
| 
						 | 
				
			
			@ -736,6 +800,7 @@ impl XLib {
 | 
			
		|||
            keybinds: Vec::new(),
 | 
			
		||||
            active_border_color: None,
 | 
			
		||||
            inactive_border_color: None,
 | 
			
		||||
            cursors: Cursors::from_connection(con.clone()),
 | 
			
		||||
            wm_window: unsafe {
 | 
			
		||||
                xlib::XCreateSimpleWindow(
 | 
			
		||||
                    con.dpy(),
 | 
			
		||||
| 
						 | 
				
			
			@ -753,9 +818,10 @@ impl XLib {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    unsafe fn init_as_wm(&self) {
 | 
			
		||||
        let mut window_attributes =
 | 
			
		||||
        let mut window_attributes = unsafe {
 | 
			
		||||
            std::mem::MaybeUninit::<xlib::XSetWindowAttributes>::zeroed()
 | 
			
		||||
                .assume_init();
 | 
			
		||||
                .assume_init()
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        window_attributes.event_mask = xlib::SubstructureRedirectMask
 | 
			
		||||
            | xlib::StructureNotifyMask
 | 
			
		||||
| 
						 | 
				
			
			@ -764,21 +830,23 @@ impl XLib {
 | 
			
		|||
            | xlib::PointerMotionMask
 | 
			
		||||
            | xlib::ButtonPressMask;
 | 
			
		||||
 | 
			
		||||
        xlib::XChangeWindowAttributes(
 | 
			
		||||
            self.connection.dpy(),
 | 
			
		||||
            self.connection.root(),
 | 
			
		||||
            xlib::CWEventMask,
 | 
			
		||||
            &mut window_attributes,
 | 
			
		||||
        );
 | 
			
		||||
        unsafe {
 | 
			
		||||
            xlib::XChangeWindowAttributes(
 | 
			
		||||
                self.connection.dpy(),
 | 
			
		||||
                self.connection.root(),
 | 
			
		||||
                xlib::CWEventMask,
 | 
			
		||||
                &mut window_attributes,
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
        xlib::XSelectInput(
 | 
			
		||||
            self.dpy(),
 | 
			
		||||
            self.connection.root(),
 | 
			
		||||
            window_attributes.event_mask,
 | 
			
		||||
        );
 | 
			
		||||
            xlib::XSelectInput(
 | 
			
		||||
                self.dpy(),
 | 
			
		||||
                self.connection.root(),
 | 
			
		||||
                window_attributes.event_mask,
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
        xlib::XSetErrorHandler(Some(xlib_error_handler));
 | 
			
		||||
        xlib::XSync(self.dpy(), 0);
 | 
			
		||||
            xlib::XSetErrorHandler(Some(xlib_error_handler));
 | 
			
		||||
            xlib::XSync(self.dpy(), 0);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        self.ewmh_atoms.set_supported_atoms(self.connection.clone());
 | 
			
		||||
        self.connection.delete_property(
 | 
			
		||||
| 
						 | 
				
			
			@ -1658,6 +1726,30 @@ impl WindowServerBackend for XLib {
 | 
			
		|||
            },
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn set_window_fullscreen_state(
 | 
			
		||||
        &self,
 | 
			
		||||
        window: Self::Window,
 | 
			
		||||
        fullscreen: bool,
 | 
			
		||||
    ) {
 | 
			
		||||
        if fullscreen {
 | 
			
		||||
            self.connection.change_property_long(
 | 
			
		||||
                window,
 | 
			
		||||
                self.ewmh_atoms[EWMHAtom::NetWmState],
 | 
			
		||||
                XA_WINDOW,
 | 
			
		||||
                PropMode::Replace,
 | 
			
		||||
                &[self.ewmh_atoms[EWMHAtom::NetWmStateFullscreen] as _],
 | 
			
		||||
            );
 | 
			
		||||
        } else {
 | 
			
		||||
            self.connection.change_property_long(
 | 
			
		||||
                window,
 | 
			
		||||
                self.ewmh_atoms[EWMHAtom::NetWmState],
 | 
			
		||||
                XA_WINDOW,
 | 
			
		||||
                PropMode::Replace,
 | 
			
		||||
                &[0 as _],
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl TryFrom<EWMHAtom> for WindowType {
 | 
			
		||||
| 
						 | 
				
			
			@ -1683,7 +1775,7 @@ unsafe extern "C" fn xlib_error_handler(
 | 
			
		|||
    _dpy: *mut x11::xlib::Display,
 | 
			
		||||
    ee: *mut x11::xlib::XErrorEvent,
 | 
			
		||||
) -> std::os::raw::c_int {
 | 
			
		||||
    let err_event = ee.as_ref().unwrap();
 | 
			
		||||
    let err_event = unsafe { ee.as_ref().unwrap() };
 | 
			
		||||
    let err = XlibError::from(err_event.error_code);
 | 
			
		||||
 | 
			
		||||
    match err {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,5 @@
 | 
			
		|||
#![deny(unsafe_op_in_unsafe_fn)]
 | 
			
		||||
 | 
			
		||||
pub mod backends;
 | 
			
		||||
pub mod clients;
 | 
			
		||||
pub mod state;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										15
									
								
								src/state.rs
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/state.rs
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -203,16 +203,6 @@ where
 | 
			
		|||
            },
 | 
			
		||||
        ));
 | 
			
		||||
 | 
			
		||||
        // self.add_keybind(KeyBinding::new(
 | 
			
		||||
        //     KeyBind::new(VirtualKeyCode::Print),
 | 
			
		||||
        //     |wm, _| wm.spawn("screenshot.sh", &[]),
 | 
			
		||||
        // ));
 | 
			
		||||
 | 
			
		||||
        // self.add_keybind(KeyBinding::new(
 | 
			
		||||
        //     KeyBind::new(VirtualKeyCode::Print).with_mod(ModifierKey::Shift),
 | 
			
		||||
        //     |wm, _| wm.spawn("screenshot.sh", &["-edit"]),
 | 
			
		||||
        // ));
 | 
			
		||||
 | 
			
		||||
        self.add_keybind(KeyBinding::new(
 | 
			
		||||
            KeyBind::new(VirtualKeyCode::M).with_mod(self.config.mod_key),
 | 
			
		||||
            |wm, _| wm.handle_switch_stack(),
 | 
			
		||||
| 
						 | 
				
			
			@ -488,6 +478,11 @@ where
 | 
			
		|||
                                    Some(self.clients.get_border())
 | 
			
		||||
                                },
 | 
			
		||||
                            );
 | 
			
		||||
 | 
			
		||||
                            self.backend.set_window_fullscreen_state(
 | 
			
		||||
                                client.window,
 | 
			
		||||
                                client.is_fullscreen(),
 | 
			
		||||
                            );
 | 
			
		||||
                        };
 | 
			
		||||
 | 
			
		||||
                        self.arrange_clients();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue