Compare commits
	
		
			2 commits
		
	
	
		
			main
			...
			feature_cu
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							
							
								 | 
						1d15ef6336 | ||
| 
							
							
								 | 
						ae89404de3 | 
| 
						 | 
					@ -18,4 +18,11 @@ pub mod structs {
 | 
				
			||||||
        Dock,
 | 
					        Dock,
 | 
				
			||||||
        Desktop,
 | 
					        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 focus_window(&self, window: Self::Window);
 | 
				
			||||||
    fn unfocus_window(&self, window: Self::Window);
 | 
					    fn unfocus_window(&self, window: Self::Window);
 | 
				
			||||||
    fn raise_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 hide_window(&self, window: Self::Window);
 | 
				
			||||||
    fn kill_window(&self, window: Self::Window);
 | 
					    fn kill_window(&self, window: Self::Window);
 | 
				
			||||||
    fn get_parent_window(&self, window: Self::Window) -> Option<Self::Window>;
 | 
					    fn get_parent_window(&self, window: Self::Window) -> Option<Self::Window>;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,7 @@ use crate::backends::{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use self::{
 | 
					use self::{
 | 
				
			||||||
    connection::{PropMode, XLibConnection},
 | 
					    connection::{PropMode, XLibConnection},
 | 
				
			||||||
 | 
					    cursors::Cursors,
 | 
				
			||||||
    ewmh::{EWMHAtom, EWMHAtoms},
 | 
					    ewmh::{EWMHAtom, EWMHAtoms},
 | 
				
			||||||
    keysym::{
 | 
					    keysym::{
 | 
				
			||||||
        keysym_to_virtual_keycode, virtual_keycode_to_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 {
 | 
					pub struct XLib {
 | 
				
			||||||
    connection: Rc<XLibConnection>,
 | 
					    connection: Rc<XLibConnection>,
 | 
				
			||||||
    atoms: ICCCMAtoms,
 | 
					    atoms: ICCCMAtoms,
 | 
				
			||||||
| 
						 | 
					@ -721,6 +778,13 @@ pub struct XLib {
 | 
				
			||||||
    active_border_color: Option<color::XftColor>,
 | 
					    active_border_color: Option<color::XftColor>,
 | 
				
			||||||
    inactive_border_color: Option<color::XftColor>,
 | 
					    inactive_border_color: Option<color::XftColor>,
 | 
				
			||||||
    wm_window: Window,
 | 
					    wm_window: Window,
 | 
				
			||||||
 | 
					    cursors: Cursors,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Drop for XLib {
 | 
				
			||||||
 | 
					    fn drop(&mut self) {
 | 
				
			||||||
 | 
					        unsafe { self.cursors.free(self.connection.clone()) };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl XLib {
 | 
					impl XLib {
 | 
				
			||||||
| 
						 | 
					@ -736,6 +800,7 @@ impl XLib {
 | 
				
			||||||
            keybinds: Vec::new(),
 | 
					            keybinds: Vec::new(),
 | 
				
			||||||
            active_border_color: None,
 | 
					            active_border_color: None,
 | 
				
			||||||
            inactive_border_color: None,
 | 
					            inactive_border_color: None,
 | 
				
			||||||
 | 
					            cursors: Cursors::from_connection(con.clone()),
 | 
				
			||||||
            wm_window: unsafe {
 | 
					            wm_window: unsafe {
 | 
				
			||||||
                xlib::XCreateSimpleWindow(
 | 
					                xlib::XCreateSimpleWindow(
 | 
				
			||||||
                    con.dpy(),
 | 
					                    con.dpy(),
 | 
				
			||||||
| 
						 | 
					@ -753,9 +818,10 @@ impl XLib {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unsafe fn init_as_wm(&self) {
 | 
					    unsafe fn init_as_wm(&self) {
 | 
				
			||||||
        let mut window_attributes =
 | 
					        let mut window_attributes = unsafe {
 | 
				
			||||||
            std::mem::MaybeUninit::<xlib::XSetWindowAttributes>::zeroed()
 | 
					            std::mem::MaybeUninit::<xlib::XSetWindowAttributes>::zeroed()
 | 
				
			||||||
                .assume_init();
 | 
					                .assume_init()
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        window_attributes.event_mask = xlib::SubstructureRedirectMask
 | 
					        window_attributes.event_mask = xlib::SubstructureRedirectMask
 | 
				
			||||||
            | xlib::StructureNotifyMask
 | 
					            | xlib::StructureNotifyMask
 | 
				
			||||||
| 
						 | 
					@ -764,6 +830,7 @@ impl XLib {
 | 
				
			||||||
            | xlib::PointerMotionMask
 | 
					            | xlib::PointerMotionMask
 | 
				
			||||||
            | xlib::ButtonPressMask;
 | 
					            | xlib::ButtonPressMask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        unsafe {
 | 
				
			||||||
            xlib::XChangeWindowAttributes(
 | 
					            xlib::XChangeWindowAttributes(
 | 
				
			||||||
                self.connection.dpy(),
 | 
					                self.connection.dpy(),
 | 
				
			||||||
                self.connection.root(),
 | 
					                self.connection.root(),
 | 
				
			||||||
| 
						 | 
					@ -779,6 +846,7 @@ impl XLib {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            xlib::XSetErrorHandler(Some(xlib_error_handler));
 | 
					            xlib::XSetErrorHandler(Some(xlib_error_handler));
 | 
				
			||||||
            xlib::XSync(self.dpy(), 0);
 | 
					            xlib::XSync(self.dpy(), 0);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.ewmh_atoms.set_supported_atoms(self.connection.clone());
 | 
					        self.ewmh_atoms.set_supported_atoms(self.connection.clone());
 | 
				
			||||||
        self.connection.delete_property(
 | 
					        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 {
 | 
					impl TryFrom<EWMHAtom> for WindowType {
 | 
				
			||||||
| 
						 | 
					@ -1683,7 +1775,7 @@ unsafe extern "C" fn xlib_error_handler(
 | 
				
			||||||
    _dpy: *mut x11::xlib::Display,
 | 
					    _dpy: *mut x11::xlib::Display,
 | 
				
			||||||
    ee: *mut x11::xlib::XErrorEvent,
 | 
					    ee: *mut x11::xlib::XErrorEvent,
 | 
				
			||||||
) -> std::os::raw::c_int {
 | 
					) -> 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);
 | 
					    let err = XlibError::from(err_event.error_code);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    match err {
 | 
					    match err {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,5 @@
 | 
				
			||||||
 | 
					#![deny(unsafe_op_in_unsafe_fn)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub mod backends;
 | 
					pub mod backends;
 | 
				
			||||||
pub mod clients;
 | 
					pub mod clients;
 | 
				
			||||||
pub mod state;
 | 
					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(
 | 
					        self.add_keybind(KeyBinding::new(
 | 
				
			||||||
            KeyBind::new(VirtualKeyCode::M).with_mod(self.config.mod_key),
 | 
					            KeyBind::new(VirtualKeyCode::M).with_mod(self.config.mod_key),
 | 
				
			||||||
            |wm, _| wm.handle_switch_stack(),
 | 
					            |wm, _| wm.handle_switch_stack(),
 | 
				
			||||||
| 
						 | 
					@ -488,6 +478,11 @@ where
 | 
				
			||||||
                                    Some(self.clients.get_border())
 | 
					                                    Some(self.clients.get_border())
 | 
				
			||||||
                                },
 | 
					                                },
 | 
				
			||||||
                            );
 | 
					                            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            self.backend.set_window_fullscreen_state(
 | 
				
			||||||
 | 
					                                client.window,
 | 
				
			||||||
 | 
					                                client.is_fullscreen(),
 | 
				
			||||||
 | 
					                            );
 | 
				
			||||||
                        };
 | 
					                        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        self.arrange_clients();
 | 
					                        self.arrange_clients();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue