Skip to content

Commit

Permalink
add notification_handling option to control suppression
Browse files Browse the repository at this point in the history
refs: #3727
  • Loading branch information
wez committed Sep 29, 2023
1 parent c75f20f commit 845fa5d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 8 deletions.
13 changes: 13 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ pub struct Config {
#[dynamic(default)]
pub ime_preedit_rendering: ImePreeditRendering,

#[dynamic(default)]
pub notification_handling: NotificationHandling,

#[dynamic(default = "default_true")]
pub use_dead_keys: bool,

Expand Down Expand Up @@ -2008,6 +2011,16 @@ pub enum ImePreeditRendering {
System,
}

#[derive(Debug, FromDynamic, ToDynamic, Clone, Copy, PartialEq, Eq, Default)]
pub enum NotificationHandling {
#[default]
AlwaysShow,
NeverShow,
SuppressFromFocusedPane,
SuppressFromFocusedTab,
SuppressFromFocusedWindow,
}

fn validate_row_or_col(value: &u16) -> Result<(), String> {
if *value < 1 {
Err("initial_cols and initial_rows must be non-zero".to_string())
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ As features stabilize some brief notes about them will accumulate here.
enhanced to allow setting an alphabet for quickly launching items beyond
the first 10 items, as well as customizing the description/label text.
Thanks to @Danielkonge! #4226 #4227
* [notification_handling](config/lua/config/notification_handling.md) to
control whether notifications are suppressed based on focus. #3727

#### Fixed
* Command Palette was using now-invalid Nerd Font 2.0 symbols for macOS
Expand Down
30 changes: 30 additions & 0 deletions docs/config/lua/config/notification_handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
tags:
- notifications
---

# `notification_handling = "AlwaysShow"`

{{since('nightly')}}

This option controls how wezterm behaves when a toast notification escape
sequence is received.

The following escape sequences will generate a toast notification:

```console
$ printf "\e]777;notify;%s;%s\e\\" "title" "body"
```

```console
$ printf "\e]9;%s\e\\" "hello there"
```

This configuration option can have one of the following values,
which have the following effects:

* `AlwaysShow` - Show the notification regardless of the current focus
* `NeverShow` - Never show the notification
* `SuppressFromFocusedPane` - Show the notification unless it was generated from the currently focused pane
* `SuppressFromFocusedTab` - Show the notification unless it was generated from the currently focused tab
* `SuppressFromFocusedWindow` - Show the notification unless it was generated from the currently focused window
9 changes: 9 additions & 0 deletions mux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,15 @@ impl Mux {
}
}

pub fn resolve_focused_pane(
&self,
client_id: &ClientId,
) -> Option<(DomainId, WindowId, TabId, PaneId)> {
let pane_id = self.clients.read().get(client_id)?.focused_pane_id?;
let (domain, window, tab) = self.resolve_pane_id(pane_id)?;
Some((domain, window, tab, pane_id))
}

pub fn record_focus_for_client(&self, client_id: &ClientId, pane_id: PaneId) {
let mut prior = None;
if let Some(info) = self.clients.write().get_mut(client_id) {
Expand Down
38 changes: 30 additions & 8 deletions wezterm-gui/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::TermWindow;
use ::window::*;
use anyhow::{Context, Error};
use config::keyassignment::{KeyAssignment, SpawnCommand};
use config::ConfigSubscription;
pub use config::FrontEndSelection;
use config::{ConfigSubscription, NotificationHandling};
use mux::client::ClientId;
use mux::window::WindowId as MuxWindowId;
use mux::{Mux, MuxNotification};
Expand Down Expand Up @@ -96,20 +96,42 @@ impl GuiFrontEnd {
MuxNotification::PaneOutput(_) => {}
MuxNotification::PaneAdded(_) => {}
MuxNotification::Alert {
pane_id: _,
pane_id,
alert:
Alert::ToastNotification {
title,
body,
focus: _,
},
} => {
let message = if title.is_none() { "" } else { &body };
let title = title.as_ref().unwrap_or(&body);
// FIXME: if notification.focus is true, we should do
// something here to arrange to focus pane_id when the
// notification is clicked
persistent_toast_notification(title, message);
let mux = Mux::get();

if let Some((_domain, window_id, tab_id)) = mux.resolve_pane_id(pane_id) {
let config = config::configuration();

if let Some((_fdomain, f_window, f_tab, f_pane)) =
mux.resolve_focused_pane(&client_id)
{
let show = match config.notification_handling {
NotificationHandling::NeverShow => false,
NotificationHandling::AlwaysShow => true,
NotificationHandling::SuppressFromFocusedPane => f_pane != pane_id,
NotificationHandling::SuppressFromFocusedTab => f_tab != tab_id,
NotificationHandling::SuppressFromFocusedWindow => {
f_window != window_id
}
};

if show {
let message = if title.is_none() { "" } else { &body };
let title = title.as_ref().unwrap_or(&body);
// FIXME: if notification.focus is true, we should do
// something here to arrange to focus pane_id when the
// notification is clicked
persistent_toast_notification(title, message);
}
}
}
}
MuxNotification::Alert {
pane_id: _,
Expand Down

0 comments on commit 845fa5d

Please sign in to comment.