Skip to content

lablink_client_service.monitoring.samplers.active_window

Active-window sampler.

Polls xdotool getactivewindow getwindowname and buckets the title (which we never store) into one of four buckets. Returns "other" when xdotool is absent, the call fails, or no subject pattern is configured — degraded behaviour, not a crash.

Return the bucket name for the currently focused window.

Parameters:

Name Type Description Default
subject_patterns Iterable[str]

lower-cased substrings that, when contained in the title, mark it as the tutorial app (e.g. ["sleap"], ["deeplabcut"]). An empty iterable disables subject matching entirely.

required

Returns:

Type Description
str

One of "subject" / "terminal" / "browser" / "other".

Source code in packages/client/src/lablink_client_service/monitoring/samplers/active_window.py
def sample(subject_patterns: Iterable[str]) -> str:
    """Return the bucket name for the currently focused window.

    Args:
        subject_patterns: lower-cased substrings that, when contained in the
            title, mark it as the tutorial app (e.g. ["sleap"], ["deeplabcut"]).
            An empty iterable disables subject matching entirely.

    Returns:
        One of "subject" / "terminal" / "browser" / "other".
    """
    title = _get_title()
    if not title:
        return "other"
    title_l = title.lower()
    subj = [p.lower() for p in subject_patterns]
    if subj and any(p in title_l for p in subj):
        return "subject"
    if any(p in title_l for p in TERMINAL_PATS):
        return "terminal"
    if any(p in title_l for p in BROWSER_PATS):
        return "browser"
    return "other"