Skip to content

Commit

Permalink
handle new clippy with addr_of macros
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Jan 14, 2024
1 parent 0b6ec4b commit 199ea0c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
41 changes: 24 additions & 17 deletions src/drw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,15 @@ impl Drw {
self.scheme = scm.as_mut_ptr();
}

pub(crate) fn textw(&self, stext: &str) -> usize {
pub(crate) fn textw(&self, stext: *const String) -> usize {
unsafe { self.fontset_getwidth(stext) + LRPAD }
}

fn fontset_getwidth(&self, text: &str) -> usize {
if self.fonts.is_null() || text.is_empty() {
return 0;
fn fontset_getwidth(&self, text: *const String) -> usize {
unsafe {
if self.fonts.is_null() || (*text).is_empty() {
return 0;
}
}
self.text(0, 0, 0, 0, 0, text, 0)
}
Expand All @@ -223,7 +225,7 @@ impl Drw {
mut w: usize,
h: usize,
lpad: usize,
text: &str,
text: *const String,
invert: c_int,
) -> usize {
let mut ty;
Expand All @@ -248,14 +250,16 @@ impl Drw {
let mut charexists = false;
let mut overflow = false;

if (render && (self.scheme.is_null() || w == 0))
|| text.is_empty()
|| self.fonts.is_null()
{
return 0;
}
let ellipsis = String::from("...");

unsafe {
if (render && (self.scheme.is_null() || w == 0))
|| (*text).is_empty()
|| self.fonts.is_null()
{
return 0;
}

if !render {
w = if invert != 0 { invert } else { !invert } as usize;
} else {
Expand Down Expand Up @@ -290,7 +294,7 @@ impl Drw {

usedfont = self.fonts;
if ELLIPSIS_WIDTH == 0 && render {
ELLIPSIS_WIDTH = self.fontset_getwidth("...");
ELLIPSIS_WIDTH = self.fontset_getwidth(&ellipsis);
}

let mut text_idx = 0;
Expand All @@ -300,7 +304,7 @@ impl Drw {
utf8strlen = 0;
utf8str = text;
nextfont = std::ptr::null_mut();
for ch in text.chars() {
for ch in (*text).chars() {
utf8charlen = ch.len_utf8();
utf8codepoint = ch as usize;
curfont = self.fonts;
Expand All @@ -312,9 +316,10 @@ impl Drw {
utf8codepoint as u32,
) != 0;
if charexists {
let text = String::from((*text).clone());

Check failure on line 319 in src/drw.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `std::string::String`

error: useless conversion to the same type: `std::string::String` --> src/drw.rs:319:40 | 319 | ... let text = String::from((*text).clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `(*text).clone()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `-D clippy::useless-conversion` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::useless_conversion)]`

Check failure on line 319 in src/drw.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `std::string::String`

error: useless conversion to the same type: `std::string::String` --> src/drw.rs:319:40 | 319 | ... let text = String::from((*text).clone()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `(*text).clone()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `-D clippy::useless-conversion` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::useless_conversion)]`
self.font_getexts(
curfont,
text,
&text,
utf8charlen,
&mut tmpw,
std::ptr::null_mut(),
Expand Down Expand Up @@ -359,7 +364,7 @@ impl Drw {
ty = y as usize
+ (h - (*usedfont).h) / 2
+ (*(*usedfont).xfont).ascent as usize;
let s = CString::new(utf8str).unwrap();
let s = CString::new((*utf8str).clone()).unwrap();
XftDrawStringUtf8(
d,
self.scheme.offset(if invert != 0 {
Expand All @@ -380,10 +385,12 @@ impl Drw {
}

if render && overflow {
self.text(ellipsis_x, y, ellipsis_w, h, 0, "...", invert);
self.text(
ellipsis_x, y, ellipsis_w, h, 0, &ellipsis, invert,
);
}

if text_idx >= text.len() || overflow {
if text_idx >= (*text).len() || overflow {
break;
} else if !nextfont.is_null() {
charexists = false;
Expand Down
32 changes: 18 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::mem::{size_of, MaybeUninit};
use std::os::fd::AsRawFd;
use std::path::Path;
use std::process::Command;
use std::ptr::null_mut;
use std::ptr::{addr_of, addr_of_mut, null_mut};

use config::{
COLORS, DMENUMON, FONTS, KEYS, LAYOUTS, MFACT, NMASTER, SHOWBAR, TOPBAR,
Expand Down Expand Up @@ -1259,7 +1259,7 @@ pub fn spawn(_dpy: &Display, arg: Arg) {
let r: &'static str = format!("{}", (*SELMON).num).leak();
let r: Box<&'static str> = Box::new(r);
let mut r: &'static &'static str = Box::leak(r);
std::mem::swap(&mut DMENUMON, &mut r);
std::ptr::swap(addr_of_mut!(DMENUMON), &mut r);
}
Command::new(s[0])
.args(&s[1..])
Expand Down Expand Up @@ -1840,7 +1840,7 @@ fn unfocus(dpy: &Display, c: *mut Client, setfocus: bool) {

fn updatestatus(dpy: &Display) {
unsafe {
let c = gettextprop(dpy, ROOT, XA_WM_NAME, &mut STEXT);
let c = gettextprop(dpy, ROOT, XA_WM_NAME, addr_of_mut!(STEXT));
if !c {
STEXT = "rwm-0.0.1".to_owned();
}
Expand Down Expand Up @@ -1868,14 +1868,14 @@ fn drawbar(m: *mut Monitor) {
if m == SELMON {
// status is only drawn on selected monitor
drw.setscheme(&mut SCHEME[Scheme::Norm as usize]);
tw = drw.textw(&STEXT) - LRPAD + 2; // 2px right padding
tw = drw.textw(addr_of!(STEXT)) - LRPAD + 2; // 2px right padding
drw.text(
((*m).ww - tw as i16) as i32,
0,
tw,
BH as usize,
0,
&STEXT,
addr_of!(STEXT),
0,
);
}
Expand All @@ -1890,7 +1890,8 @@ fn drawbar(m: *mut Monitor) {
}

for i in 0..TAGS.len() {
w = drw.textw(TAGS[i]);
let text = TAGS[i].to_owned();
w = drw.textw(&text);
drw.setscheme(
&mut SCHEME[if ((*m).tagset[(*m).seltags] & 1 << i) != 0 {
Scheme::Sel as usize
Expand All @@ -1904,7 +1905,7 @@ fn drawbar(m: *mut Monitor) {
w,
BH as usize,
LRPAD / 2,
TAGS[i],
&text,
(urg as i32) & 1 << i,
);

Expand Down Expand Up @@ -1961,12 +1962,12 @@ fn gettextprop(
dpy: &Display,
w: Window,
atom: Atom,
text: &mut String,
text: *mut String,
) -> bool {
if text.is_empty() {
return false;
}
unsafe {
if (*text).is_empty() {
return false;
}
let mut name = MaybeUninit::uninit();
let c = XGetTextProperty(dpy.inner, w, name.as_mut_ptr(), atom);
let name = name.assume_init();
Expand Down Expand Up @@ -2867,18 +2868,21 @@ fn buttonpress(dpy: &Display, e: *mut XEvent) {
let mut i = 0;
// do while with ++i in condition
let drw = &DRW.as_ref().unwrap();
x += drw.textw(TAGS[i]);
let text = TAGS[i].to_owned();
x += drw.textw(&text);
i += 1;
while ev.x >= x as i32 && i < TAGS.len() {
x += drw.textw(TAGS[i]);
let text = TAGS[i].to_owned();
x += drw.textw(&text);
i += 1;
}
if i < TAGS.len() {
click = Clk::TagBar;
arg = Arg::Uint(1 << i);
} else if ev.x < (x + drw.textw(&(*SELMON).ltsymbol)) as i32 {
click = Clk::LtSymbol;
} else if ev.x > ((*SELMON).ww as usize - drw.textw(&STEXT)) as i32
} else if ev.x
> ((*SELMON).ww as usize - drw.textw(addr_of!(STEXT))) as i32
{
click = Clk::StatusText;
} else {
Expand Down

0 comments on commit 199ea0c

Please sign in to comment.