Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into fig #32

Merged
merged 9 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
96 changes: 50 additions & 46 deletions blocks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,53 @@ struct Globals<const N: usize> {
statusstr: [String; 2],
}

fn getsigcmds<const N: usize>(g: *mut Globals<N>, signal: c_int) {
for (i, current) in BLOCKS.iter().enumerate() {
if current.signal == signal {
unsafe {
(*g).statusbar[i] = current.getcmd();
}
}
}
}

fn getstatus<const N: usize>(g: *mut Globals<N>) -> 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<const N: usize>(g: *mut Globals<N>) {
// 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<const N: usize>(g: *mut Globals<N>) {
setupsignals();
unsafe {
(*g).getcmds(-1);
for i in 0.. {
(*g).getcmds(i);
writestatus(g);
sleep(Duration::from_secs(1));
}
}
}

impl<const N: usize> Globals<N> {
const fn new() -> Self {
const S: String = String::new();
Expand All @@ -36,47 +83,6 @@ impl<const N: usize> Globals<N> {
}
}
}

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
Expand All @@ -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 {
Expand Down Expand Up @@ -139,6 +143,6 @@ fn main() {
unsafe {
signal(SIGTERM, get_handler(termhandler));
signal(SIGINT, get_handler(termhandler));
GLOB.statusloop();
statusloop(&raw mut GLOB);
}
}
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down
Loading