Skip to content

Commit

Permalink
Merge master into fig and new lints (#32)
Browse files Browse the repository at this point in the history
* Implement the pertag patch for dwm (#23)

* add Pertag and allocate one when creating a Monitor

* update focusstack and setlayout

* update togglebar, setmfact, and toggleview

* update view

* actually capture the chained assignment semantics

* realize that I had two separate view functions, clippy for mem::swap

* fix off-by-one

this was clear in the patch, but I just didn't include the +1. symptom was a
crash when trying to access tag 9

* make isfullscreen bool

* Implement window swallowing (#24)

* update Rule struct, add st example

* update Client

* make isfloating bool

* impl swallow, add XCON

* impl unswallow

* progress on swallowing with horrifying process management

* finish swallowing?

* delete unused xcon

* Add scratchpad patch (#25)

* work on scratchpad

* finish scratchpad

* fix width -> height

* try another found approach

currently it always spawns a new scratchpad instead of toggling

* fix duplicate pertag

* fix duplicate scratchtag code

* move fig to git dep for CI

* handle newly-denied references to static mut

https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html
  • Loading branch information
ntBre authored Nov 23, 2024
1 parent 124d549 commit af31373
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 50 deletions.
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

0 comments on commit af31373

Please sign in to comment.