ztmux 3.7.20

A Rust port of tmux — the full terminal multiplexer, server and client
Documentation
// Copyright (c) 2012 Nicholas Marriott <nicholas.marriott@gmail.com>
// Copyright (c) 2012 George Nachman <tmux@georgester.com>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
// IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
// OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use crate::*;

macro_rules! CONTROL_SHOULD_NOTIFY_CLIENT {
    ($c:expr) => {
        !$c.is_null() && (*$c).flags.intersects(client_flag::CONTROL)
    };
}

/// C `vendor/tmux/control-notify.c:31`: `void control_notify_pane_mode_changed(int pane)`
pub unsafe fn control_notify_pane_mode_changed(pane: c_int) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    continue;
                }

                control_write!(c, "%pane-mode-changed %{}", pane);
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:44`: `void control_notify_window_layout_changed(struct window *w)`
pub unsafe fn control_notify_window_layout_changed(w: *mut window) {
    let template = c!(
        "%layout-change #{window_id} #{window_layout} #{window_visible_layout} #{window_raw_flags}"
    );

    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) || (*c).session.is_null() {
                    continue;
                }
                let s = (*c).session;

                if winlink_find_by_window_id(&raw mut (*s).windows, (*w).id).is_null() {
                    continue;
                }

                // When the last pane in a window is closed it won't have a
                // layout root and we don't need to inform the client about the
                // layout change because the whole window will go away soon.
                if (*w).layout_root.is_null() {
                    continue;
                }

                if let Some(wl) = winlink_find_by_window(&raw mut (*s).windows, w) {
                    let cp =
                        format_single(null_mut(), cstr_to_str(template), c, null_mut(), wl.as_ptr(), null_mut());
                    control_write!(c, "{}", _s(cp));
                    free_(cp);
                }
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:76`: `void control_notify_window_pane_changed(struct window *w)`
pub unsafe fn control_notify_window_pane_changed(w: *mut window) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    continue;
                }

                control_write!(
                    c,
                    "%window-pane-changed @{} %{}",
                    (*w).id,
                    (*(*w).active).id,
                );
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:92`: `void control_notify_window_unlinked(__unused struct session *s, struct window *w)`
pub unsafe fn control_notify_window_unlinked(_s: *mut session, w: *mut window) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) || (*c).session.is_null() {
                    continue;
                }
                let cs = (*c).session;

                if !winlink_find_by_window_id(&raw mut (*cs).windows, (*w).id).is_null() {
                    control_write!(c, "%window-close @{}", (*w).id);
                } else {
                    control_write!(c, "%unlinked-window-close @{}", (*w).id);
                }
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:110`: `void control_notify_window_linked(__unused struct session *s, struct window *w)`
pub unsafe fn control_notify_window_linked(_s: *mut session, w: *mut window) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) || (*c).session.is_null() {
                    continue;
                }
                let cs = (*c).session;

                if !winlink_find_by_window_id(&raw mut (*cs).windows, (*w).id).is_null() {
                    control_write!(c, "%window-add @{}", (*w).id);
                } else {
                    control_write!(c, "%unlinked-window-add @{}", (*w).id);
                }
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:128`: `void control_notify_window_renamed(struct window *w)`
pub unsafe fn control_notify_window_renamed(w: *mut window) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) || (*c).session.is_null() {
                    continue;
                }
                let cs = (*c).session;

                if !winlink_find_by_window_id(&raw mut (*cs).windows, (*w).id).is_null() {
                    control_write!(c, "%window-renamed @{} {}", (*w).id, _s((*w).name_ptr()));
                } else {
                    control_write!(c, "%unlinked-window-renamed @{} {}", (*w).id, _s((*w).name_ptr()),);
                }
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:149`: `void control_notify_client_session_changed(struct client *cc)`
pub unsafe fn control_notify_client_session_changed(cc: *mut client) {
    unsafe {
        if (*cc).session.is_null() {
            return;
        }
        let s = (*cc).session;

        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) || (*c).session.is_null() {
                    continue;
                }

                if cc == c {
                    control_write!(c, "%session-changed ${} {}", (*s).id, (*s).name);
                } else {
                    control_write!(
                        c,
                        "%client-session-changed {} ${} {}",
                        _s((*cc).name),
                        (*s).id,
                        (*s).name,
                    );
                }
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:173`: `void control_notify_client_detached(struct client *cc)`
pub unsafe fn control_notify_client_detached(cc: *mut client) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    control_write!(c, "%client-detached {}", _s((*cc).name));
                }
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:184`: `void control_notify_session_renamed(struct session *s)`
pub unsafe fn control_notify_session_renamed(s: *mut session) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    continue;
                }

                control_write!(c, "%session-renamed ${} {}", (*s).id, (*s).name);
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:197`: `void control_notify_session_created(__unused struct session *s)`
pub unsafe fn control_notify_session_created(_: *mut session) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    continue;
                }

                control_write!(c, "%sessions-changed");
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:210`: `void control_notify_session_closed(__unused struct session *s)`
pub unsafe fn control_notify_session_closed(_: *mut session) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    continue;
                }

                control_write!(c, "%sessions-changed");
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:223`: `void control_notify_session_window_changed(struct session *s)`
pub unsafe fn control_notify_session_window_changed(s: *mut session) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    continue;
                }

                control_write!(
                    c,
                    "%session-window-changed ${} @{}",
                    (*s).id,
                    (*(*(*s).curw).window).id,
                );
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:245`: `void control_notify_paste_buffer_changed(const char *name)`
pub unsafe fn control_notify_paste_buffer_changed(name: *const u8) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    continue;
                }

                control_write!(c, "%paste-buffer-changed {}", _s(name));
            }
        }
    }
}

/// C `vendor/tmux/control-notify.c:258`: `void control_notify_paste_buffer_deleted(const char *name)`
pub unsafe fn control_notify_paste_buffer_deleted(name: *const u8) {
    unsafe {
        for c in tailq_foreach(&raw mut CLIENTS).map(NonNull::as_ptr) {
            {
                if !CONTROL_SHOULD_NOTIFY_CLIENT!(c) {
                    continue;
                }

                control_write!(c, "%paste-buffer-deleted {}", _s(name));
            }
        }
    }
}