Skip to content

Commit

Permalink
restore my Arg enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Aug 16, 2024
1 parent 2d129fd commit 551f3b9
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use x11::xlib::{
use bindgen::{
bh, buttons, colors, cursor, dpy, drw, fonts, keys, layouts, lrpad, mons,
netatom, resizehints, root, scheme, screen, selmon, sh, stext, sw, tags,
wmatom, wmcheckwin, Arg, Atom, Client, Clr, ColBorder, Layout, Monitor,
wmatom, wmcheckwin, Atom, Client, Clr, ColBorder, Layout, Monitor,
WMProtocols, XInternAtom,
};
use enums::{Clk, Col, Cur, Net, Scheme, WM};
Expand Down Expand Up @@ -162,15 +162,26 @@ const BROKEN: &CStr = c"broken";
// const TAGMASK: usize = (1 << TAGS.len()) - 1;
// const MOUSEMASK: i64 = BUTTONMASK | PointerMotionMask;

// #[derive(Clone)]
// pub enum Arg {
// Uint(usize),
// Int(isize),
// Float(f64),
// Str(&'static [&'static str]),
// Layout(&'static Layout),
// None,
// }
#[derive(Clone, Default)]
pub enum Arg {
Uint(c_uint),
Int(isize),
Float(f64),
Str(&'static [&'static str]),
Layout(&'static Layout),
#[default]
None,
}

impl Arg {
pub fn as_uint(&self) -> Option<&c_uint> {
if let Self::Uint(v) = self {
Some(v)
} else {
None
}
}
}

// pub struct Button {
// pub click: Clk,
Expand Down Expand Up @@ -1336,12 +1347,15 @@ fn detach(c: *mut Client) {

fn view(arg: *const Arg) {
unsafe {
if (*arg).ui & TAGMASK == (*selmon).tagset[(*selmon).seltags as usize] {
if (*arg).as_uint().unwrap() & TAGMASK
== (*selmon).tagset[(*selmon).seltags as usize]
{
return;
}
(*selmon).seltags ^= 1; // toggle sel tagset
if ((*arg).ui & TAGMASK) != 0 {
(*selmon).tagset[(*selmon).seltags as usize] = (*arg).ui & TAGMASK;
if ((*arg).as_uint().unwrap() & TAGMASK) != 0 {
(*selmon).tagset[(*selmon).seltags as usize] =
(*arg).as_uint().unwrap() & TAGMASK;
}
focus(null_mut());
arrange(selmon);
Expand Down Expand Up @@ -2265,7 +2279,7 @@ fn cleanup() {
log::trace!("entering cleanup");

unsafe {
let a = Arg { ui: !0 };
let a = Arg::Uint(!0);
view(&a);
(*selmon).lt[(*selmon).sellt as usize] =
&Layout { symbol: c"".as_ptr(), arrange: None };
Expand Down

0 comments on commit 551f3b9

Please sign in to comment.