perf(wm): use bounded channels

This commit is contained in:
LGUG2Z
2024-06-08 14:54:16 -07:00
parent edc87d9940
commit 9a58c1ee42
4 changed files with 13 additions and 9 deletions

View File

@@ -59,7 +59,7 @@ pub struct Notification;
static CHANNEL: OnceLock<(Sender<Notification>, Receiver<Notification>)> = OnceLock::new();
pub fn channel() -> &'static (Sender<Notification>, Receiver<Notification>) {
CHANNEL.get_or_init(crossbeam_channel::unbounded)
CHANNEL.get_or_init(|| crossbeam_channel::bounded(5))
}
pub fn event_tx() -> Sender<Notification> {
@@ -129,11 +129,16 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
// Check the wm state every time we receive a notification
let state = wm.lock();
let is_paused = state.is_paused;
let focused_monitor_idx = state.focused_monitor_idx();
let monitors = state.monitors.elements().clone();
let pending_move_op = state.pending_move_op.clone();
drop(state);
// If borders are disabled
if !BORDER_ENABLED.load_consume()
// Or if the wm is paused
|| state.is_paused
|| is_paused
// Or if we are handling an alt-tab across workspaces
|| ALT_TAB_HWND.load().is_some()
{
@@ -146,9 +151,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
continue 'receiver;
}
let focused_monitor_idx = state.focused_monitor_idx();
'monitors: for (monitor_idx, m) in state.monitors.elements().iter().enumerate() {
'monitors: for (monitor_idx, m) in monitors.iter().enumerate() {
// Only operate on the focused workspace of each monitor
if let Some(ws) = m.focused_workspace() {
// Workspaces with tiling disabled don't have borders
@@ -215,6 +218,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
for id in &to_remove {
borders.remove(id);
}
continue 'monitors;
}
@@ -261,7 +265,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
for (idx, c) in ws.containers().iter().enumerate() {
// Update border when moving or resizing with mouse
if state.pending_move_op.is_some() && idx == ws.focused_container_idx() {
if pending_move_op.is_some() && idx == ws.focused_container_idx() {
let restore_z_order = *Z_ORDER.lock();
*Z_ORDER.lock() = ZOrder::TopMost;

View File

@@ -40,7 +40,7 @@ pub struct Notification;
static CHANNEL: OnceLock<(Sender<Notification>, Receiver<Notification>)> = OnceLock::new();
pub fn channel() -> &'static (Sender<Notification>, Receiver<Notification>) {
CHANNEL.get_or_init(crossbeam_channel::unbounded)
CHANNEL.get_or_init(|| crossbeam_channel::bounded(5))
}
pub fn event_tx() -> Sender<Notification> {

View File

@@ -29,7 +29,7 @@ pub fn known_hwnds() -> Vec<isize> {
}
pub fn channel() -> &'static (Sender<Notification>, Receiver<Notification>) {
CHANNEL.get_or_init(crossbeam_channel::unbounded)
CHANNEL.get_or_init(|| crossbeam_channel::bounded(5))
}
pub fn event_tx() -> Sender<Notification> {

View File

@@ -50,7 +50,7 @@ pub fn start() {
}
fn channel() -> &'static (Sender<WindowManagerEvent>, Receiver<WindowManagerEvent>) {
CHANNEL.get_or_init(crossbeam_channel::unbounded)
CHANNEL.get_or_init(|| crossbeam_channel::bounded(5))
}
pub fn event_tx() -> Sender<WindowManagerEvent> {