diff --git a/src/drw.rs b/src/drw.rs index 8964cc6..e19826f 100644 --- a/src/drw.rs +++ b/src/drw.rs @@ -1,3 +1,5 @@ +#![allow(clippy::missing_safety_doc)] + use std::ffi::{c_char, c_int, c_long, c_uchar, c_uint, CStr, CString}; use std::mem::MaybeUninit; use std::ptr::null_mut; @@ -113,6 +115,7 @@ fn utf8decode(c: *const i8, u: *mut c_long, clen: usize) -> usize { } } +/// # Safety pub unsafe fn create( dpy: *mut Display, screen: c_int, @@ -147,6 +150,7 @@ pub unsafe fn create( } } +/// # Safety pub unsafe fn free(drw: *mut Drw) { unsafe { xlib::XFreePixmap((*drw).dpy, (*drw).drawable); @@ -156,7 +160,8 @@ pub unsafe fn free(drw: *mut Drw) { } } -pub fn rect( +/// # Safety +pub unsafe fn rect( drw: *mut Drw, x: c_int, y: c_int, @@ -202,7 +207,8 @@ pub fn rect( } } -pub fn cur_create(drw: *mut Drw, shape: c_int) -> Cur { +/// # Safety +pub unsafe fn cur_create(drw: *mut Drw, shape: c_int) -> Cur { assert!(!drw.is_null()); unsafe { Cur { @@ -221,7 +227,8 @@ impl Drop for Cur { } } -pub fn setscheme(drw: *mut Drw, scm: *mut Clr) { +/// # Safety +pub unsafe fn setscheme(drw: *mut Drw, scm: *mut Clr) { if !drw.is_null() { unsafe { (*drw).scheme = scm; @@ -229,6 +236,7 @@ pub fn setscheme(drw: *mut Drw, scm: *mut Clr) { } } +/// # Safety pub unsafe fn fontset_create(drw: *mut Drw, fonts: &[CString]) -> *mut Fnt { log::trace!("fontset_create"); unsafe { @@ -379,7 +387,8 @@ pub fn scm_create( ret } -pub fn fontset_getwidth(drw: *mut Drw, text: *const c_char) -> c_uint { +/// # Safety +pub unsafe fn fontset_getwidth(drw: *mut Drw, text: *const c_char) -> c_uint { unsafe { if drw.is_null() || (*drw).fonts.is_null() || text.is_null() { return 0; @@ -389,7 +398,7 @@ pub fn fontset_getwidth(drw: *mut Drw, text: *const c_char) -> c_uint { } #[allow(clippy::too_many_arguments)] -pub fn text( +pub unsafe fn text( drw: *mut Drw, mut x: c_int, y: c_int, @@ -727,7 +736,7 @@ fn font_getexts( } } -pub fn map( +pub unsafe fn map( drw: *mut Drw, win: Window, x: c_int, @@ -755,7 +764,7 @@ pub fn map( } } -pub fn resize(drw: *mut Drw, w: c_uint, h: c_uint) { +pub unsafe fn resize(drw: *mut Drw, w: c_uint, h: c_uint) { unsafe { if drw.is_null() { return; diff --git a/src/main.rs b/src/main.rs index e7cf264..4c5e3b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2293,29 +2293,30 @@ fn setclientstate(c: *mut Client, state: usize) { } } -static HANDLER: LazyLock< - [fn(&State, *mut xlib::XEvent); x11::xlib::LASTEvent as usize], -> = LazyLock::new(|| { - fn dh(_state: &State, _ev: *mut xlib::XEvent) {} - let mut ret = [dh as fn(state: &State, *mut xlib::XEvent); - x11::xlib::LASTEvent as usize]; - ret[x11::xlib::ButtonPress as usize] = handlers::buttonpress; - ret[x11::xlib::ClientMessage as usize] = handlers::clientmessage; - ret[x11::xlib::ConfigureRequest as usize] = handlers::configurerequest; - ret[x11::xlib::ConfigureNotify as usize] = handlers::configurenotify; - ret[x11::xlib::DestroyNotify as usize] = handlers::destroynotify; - ret[x11::xlib::EnterNotify as usize] = handlers::enternotify; - ret[x11::xlib::Expose as usize] = handlers::expose; - ret[x11::xlib::FocusIn as usize] = handlers::focusin; - ret[x11::xlib::KeyPress as usize] = handlers::keypress; - ret[x11::xlib::MappingNotify as usize] = handlers::mappingnotify; - ret[x11::xlib::MapRequest as usize] = handlers::maprequest; - ret[x11::xlib::MotionNotify as usize] = handlers::motionnotify; - ret[x11::xlib::PropertyNotify as usize] = handlers::propertynotify; - ret[x11::xlib::ResizeRequest as usize] = handlers::resizerequest; - ret[x11::xlib::UnmapNotify as usize] = handlers::unmapnotify; - ret -}); +type HandlerFn = fn(&State, *mut xlib::XEvent); + +static HANDLER: LazyLock<[HandlerFn; x11::xlib::LASTEvent as usize]> = + LazyLock::new(|| { + fn dh(_state: &State, _ev: *mut xlib::XEvent) {} + let mut ret = [dh as fn(state: &State, *mut xlib::XEvent); + x11::xlib::LASTEvent as usize]; + ret[x11::xlib::ButtonPress as usize] = handlers::buttonpress; + ret[x11::xlib::ClientMessage as usize] = handlers::clientmessage; + ret[x11::xlib::ConfigureRequest as usize] = handlers::configurerequest; + ret[x11::xlib::ConfigureNotify as usize] = handlers::configurenotify; + ret[x11::xlib::DestroyNotify as usize] = handlers::destroynotify; + ret[x11::xlib::EnterNotify as usize] = handlers::enternotify; + ret[x11::xlib::Expose as usize] = handlers::expose; + ret[x11::xlib::FocusIn as usize] = handlers::focusin; + ret[x11::xlib::KeyPress as usize] = handlers::keypress; + ret[x11::xlib::MappingNotify as usize] = handlers::mappingnotify; + ret[x11::xlib::MapRequest as usize] = handlers::maprequest; + ret[x11::xlib::MotionNotify as usize] = handlers::motionnotify; + ret[x11::xlib::PropertyNotify as usize] = handlers::propertynotify; + ret[x11::xlib::ResizeRequest as usize] = handlers::resizerequest; + ret[x11::xlib::UnmapNotify as usize] = handlers::unmapnotify; + ret + }); /// main event loop fn run(state: &State) {