diff --git a/Cargo.lock b/Cargo.lock index 274ed38..8b1cee0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,6 +107,7 @@ dependencies = [ [[package]] name = "fig" version = "0.1.0" +source = "git+https://github.com/ntBre/fig#37dcfda168ddbf8d1b5b83838de8d3982e8791fe" dependencies = [ "nom", ] diff --git a/Cargo.toml b/Cargo.toml index 0031350..baf56c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ libc = "0.2.158" yeslogic-fontconfig-sys = "6.0.0" env_logger = "0.11.3" log = "0.4.21" -fig = { path = "../fig" } +fig = { git = "https://github.com/ntBre/fig" } diff --git a/blocks/src/main.rs b/blocks/src/main.rs index a22c03a..01edaf4 100644 --- a/blocks/src/main.rs +++ b/blocks/src/main.rs @@ -21,6 +21,53 @@ struct Globals { statusstr: [String; 2], } +fn getsigcmds(g: *mut Globals, signal: c_int) { + for (i, current) in BLOCKS.iter().enumerate() { + if current.signal == signal { + unsafe { + (*g).statusbar[i] = current.getcmd(); + } + } + } +} + +fn getstatus(g: *mut Globals) -> bool { + unsafe { + (*g).statusstr[1] = std::mem::take(&mut (*g).statusstr[0]); + (*g).statusstr[0] = (*g).statusbar.join("").replace('\n', ""); + (*g).statusstr[0] != (*g).statusstr[1] + } +} + +/// NOTE: inlined from setroot, can also be pstdout with -p flag, presumably +/// for debugging +fn writestatus(g: *mut Globals) { + // only set root if text has changed + if !getstatus(g) { + return; + } + unsafe { + let dpy = XOpenDisplay(null()); + let screen = XDefaultScreen(dpy); + let root = XRootWindow(dpy, screen); + let s = CString::new((*g).statusstr[0].clone()).unwrap(); + XStoreName(dpy, root, s.as_ptr()); + XCloseDisplay(dpy); + } +} + +fn statusloop(g: *mut Globals) { + setupsignals(); + unsafe { + (*g).getcmds(-1); + for i in 0.. { + (*g).getcmds(i); + writestatus(g); + sleep(Duration::from_secs(1)); + } + } +} + impl Globals { const fn new() -> Self { const S: String = String::new(); @@ -36,47 +83,6 @@ impl Globals { } } } - - fn getsigcmds(&mut self, signal: c_int) { - for (i, current) in BLOCKS.iter().enumerate() { - if current.signal == signal { - self.statusbar[i] = current.getcmd(); - } - } - } - - fn getstatus(&mut self) -> bool { - self.statusstr[1] = std::mem::take(&mut self.statusstr[0]); - self.statusstr[0] = self.statusbar.join("").replace('\n', ""); - self.statusstr[0] != self.statusstr[1] - } - - /// NOTE: inlined from setroot, can also be pstdout with -p flag, presumably - /// for debugging - fn writestatus(&mut self) { - // only set root if text has changed - if !self.getstatus() { - return; - } - unsafe { - let dpy = XOpenDisplay(null()); - let screen = XDefaultScreen(dpy); - let root = XRootWindow(dpy, screen); - let s = CString::new(self.statusstr[0].clone()).unwrap(); - XStoreName(dpy, root, s.as_ptr()); - XCloseDisplay(dpy); - } - } - - fn statusloop(&mut self) { - setupsignals(); - self.getcmds(-1); - for i in 0.. { - self.getcmds(i); - self.writestatus(); - sleep(Duration::from_secs(1)); - } - } } /// adapted from @@ -90,10 +96,8 @@ extern "C" fn termhandler(_: c_int) { } extern "C" fn sighandler(signum: c_int) { - unsafe { - GLOB.getsigcmds(signum - SIGRTMIN()); - GLOB.writestatus(); - } + getsigcmds(&raw mut GLOB, signum - SIGRTMIN()); + writestatus(&raw mut GLOB); } struct Block { @@ -139,6 +143,6 @@ fn main() { unsafe { signal(SIGTERM, get_handler(termhandler)); signal(SIGINT, get_handler(termhandler)); - GLOB.statusloop(); + statusloop(&raw mut GLOB); } } diff --git a/src/main.rs b/src/main.rs index 731c2cb..825451b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -386,7 +386,7 @@ fn setup() { XA_ATOM, 32, PropModeReplace, - NETATOM.as_ptr() as *mut c_uchar, + &raw mut NETATOM as *mut c_uchar, Net::Last as i32, ); xlib::XDeleteProperty(DPY, ROOT, NETATOM[Net::ClientList as usize]); @@ -2442,9 +2442,10 @@ fn manage(w: Window, wa: *mut xlib::XWindowAttributes) { log::trace!("manage: XConfigureWindow"); xlib::XConfigureWindow(DPY, w, CWBorderWidth as u32, &mut wc); log::trace!( - "manage: XSetWindowBorder with DPY = {DPY:?} and w = {w:?}" + "manage: XSetWindowBorder with DPY = {:?} and w = {w:?}", + &raw const DPY ); - log::trace!("scheme: {:?}", SCHEME); + log::trace!("scheme: {:?}", &raw const SCHEME); let scheme_norm: *mut Clr = *SCHEME.offset(Scheme::Norm as isize); log::trace!("scheme[SchemeNorm]: {scheme_norm:?}"); let border: Clr = *scheme_norm.offset(Col::Border as isize);