Skip to content

Commit

Permalink
move all cleanup code into cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Dec 5, 2024
1 parent 8f92234 commit 30de839
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
33 changes: 16 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,27 +2085,27 @@ fn isuniquegeom(
}
}

fn cleanup(state: &mut State) {
fn cleanup(mut state: State) {
log::trace!("entering cleanup");

unsafe {
let a = Arg::Ui(!0);
view(state, &a);
view(&mut state, &a);
(*SELMON).lt[(*SELMON).sellt as usize] =
&Layout { symbol: c"".as_ptr(), arrange: None };

let mut m = MONS;
while !m.is_null() {
while !(*m).stack.is_null() {
unmanage(state, (*m).stack, 0);
unmanage(&mut state, (*m).stack, 0);
}
m = (*m).next;
}

xlib::XUngrabKey(state.dpy, AnyKey, AnyModifier, ROOT);

while !MONS.is_null() {
cleanupmon(state, MONS);
cleanupmon(&mut state, MONS);
}

if CONFIG.showsystray {
Expand Down Expand Up @@ -2134,6 +2134,17 @@ fn cleanup(state: &mut State) {
ROOT,
state.netatom[Net::ActiveWindow as usize],
);

let State { dpy, cursors, .. } = state;

// this needs to be dropped before DRW
drop(cursors);

drw::free(DRW);
xlib::XCloseDisplay(dpy);

#[cfg(target_os = "linux")]
drop(Box::from_raw(XCON));
}

log::trace!("finished cleanup");
Expand Down Expand Up @@ -2994,17 +3005,5 @@ fn main() {
let mut state = setup(dpy);
scan(&mut state);
run(&mut state);
cleanup(&mut state);
unsafe {
let State { dpy, cursors, .. } = state;

// this needs to be dropped before DRW
drop(cursors);

drw::free(DRW);
xlib::XCloseDisplay(dpy);

#[cfg(target_os = "linux")]
drop(Box::from_raw(XCON));
}
cleanup(state);
}
16 changes: 1 addition & 15 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,7 @@ fn main() {
.is_none());
}

cleanup(&mut state);

unsafe {
let State { dpy, cursors, .. } = state;

// this needs to be dropped before DRW
drop(cursors);

drw::free(DRW);

xlib::XCloseDisplay(dpy);

#[cfg(target_os = "linux")]
drop(Box::from_raw(XCON));
}
cleanup(state);

break 'defer true;
};
Expand Down

0 comments on commit 30de839

Please sign in to comment.