Skip to content

Commit

Permalink
handle clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Dec 5, 2024
1 parent 43b3b03 commit 95a38bf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
23 changes: 16 additions & 7 deletions src/drw.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -147,6 +150,7 @@ pub unsafe fn create(
}
}

/// # Safety
pub unsafe fn free(drw: *mut Drw) {
unsafe {
xlib::XFreePixmap((*drw).dpy, (*drw).drawable);
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -221,14 +227,16 @@ 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;
}
}
}

/// # Safety
pub unsafe fn fontset_create(drw: *mut Drw, fonts: &[CString]) -> *mut Fnt {
log::trace!("fontset_create");
unsafe {
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -727,7 +736,7 @@ fn font_getexts(
}
}

pub fn map(
pub unsafe fn map(
drw: *mut Drw,
win: Window,
x: c_int,
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 24 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 95a38bf

Please sign in to comment.