added cursor types
This commit is contained in:
parent
fdf81d8d6a
commit
ae89404de3
|
@ -18,4 +18,11 @@ pub mod structs {
|
|||
Dock,
|
||||
Desktop,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
|
||||
pub enum Cursor {
|
||||
Normal,
|
||||
Resize,
|
||||
Move,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue