Compare commits

..

No commits in common. "feature_cursor" and "main" have entirely different histories.

5 changed files with 26 additions and 127 deletions

View file

@ -18,11 +18,4 @@ pub mod structs {
Dock,
Desktop,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub enum Cursor {
Normal,
Resize,
Move,
}
}

View file

@ -21,11 +21,6 @@ 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>;

View file

@ -12,7 +12,6 @@ use crate::backends::{
use self::{
connection::{PropMode, XLibConnection},
cursors::Cursors,
ewmh::{EWMHAtom, EWMHAtoms},
keysym::{
keysym_to_virtual_keycode, virtual_keycode_to_keysym,
@ -714,62 +713,6 @@ 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,
@ -778,13 +721,6 @@ 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 {
@ -800,7 +736,6 @@ 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(),
@ -818,10 +753,9 @@ impl XLib {
}
unsafe fn init_as_wm(&self) {
let mut window_attributes = unsafe {
let mut window_attributes =
std::mem::MaybeUninit::<xlib::XSetWindowAttributes>::zeroed()
.assume_init()
};
.assume_init();
window_attributes.event_mask = xlib::SubstructureRedirectMask
| xlib::StructureNotifyMask
@ -830,7 +764,6 @@ impl XLib {
| xlib::PointerMotionMask
| xlib::ButtonPressMask;
unsafe {
xlib::XChangeWindowAttributes(
self.connection.dpy(),
self.connection.root(),
@ -846,7 +779,6 @@ impl XLib {
xlib::XSetErrorHandler(Some(xlib_error_handler));
xlib::XSync(self.dpy(), 0);
}
self.ewmh_atoms.set_supported_atoms(self.connection.clone());
self.connection.delete_property(
@ -1726,30 +1658,6 @@ 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 {
@ -1775,7 +1683,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 = unsafe { ee.as_ref().unwrap() };
let err_event = ee.as_ref().unwrap();
let err = XlibError::from(err_event.error_code);
match err {

View file

@ -1,5 +1,3 @@
#![deny(unsafe_op_in_unsafe_fn)]
pub mod backends;
pub mod clients;
pub mod state;

View file

@ -203,6 +203,16 @@ 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(),
@ -478,11 +488,6 @@ where
Some(self.clients.get_border())
},
);
self.backend.set_window_fullscreen_state(
client.window,
client.is_fullscreen(),
);
};
self.arrange_clients();