Skip to content

Commit 6e72a9c

Browse files
committed
Add "Open Buffer" as a secondary action when the default is to activate Halloy, and remove it as a secondary when it is the default (it will be displayed twice in that case, on macOS).
1 parent fa324c7 commit 6e72a9c

6 files changed

Lines changed: 58 additions & 58 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Added:
88
- Support displaying a larger version of the card images in-app
99
- IRCv3 `no-implicit-names` support
1010
- Keyboard shortcuts validation (e.g no duplicate key binds)
11-
- `actions.buffer.notification` setting to control how interacting with notifications is handled
11+
- `actions.buffer.notifications` settings to control how interacting with notifications is handled
1212
- `actions.buffer.click_nickname` and `actions.nicklist.click_nickname` can be used to specify whether a nickname will: open query and how the query is opened, insert nickname in the input box, or no action (`"no-action"` or `"noop"`); takes over functionality from `buffer.nickname.click` and `buffer.channel.nicklist.click` and adds the ability to perform no action
1313
- `actions.buffer.click_channel_name` and `actions.buffer.click_highlight` can be set to no action (`"no-action"` or `"noop"`) to not open the channel when clicking on the channel name
1414
- Explicit portable mode

data/src/config/actions.rs

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct Actions {
88
pub sidebar: Sidebar,
99
pub buffer: Buffer,
1010
pub nicklist: Nicklist,
11-
pub notification: NotificationAction,
11+
pub notification: Notification,
1212
}
1313

1414
#[derive(Debug, Default, Clone, Deserialize)]
@@ -138,43 +138,16 @@ impl<'de> Deserialize<'de> for ChannelClickAction {
138138
}
139139
}
140140

141-
#[derive(Debug, Copy, Clone, Default)]
142-
pub enum NotificationAction {
143-
OpenBuffer(BufferAction),
144-
#[default]
145-
Noop,
141+
#[derive(Debug, Copy, Clone, Default, Deserialize)]
142+
#[serde(default)]
143+
pub struct Notification {
144+
pub default: NotificationAction,
145+
pub open_buffer: BufferAction,
146146
}
147147

148-
impl<'de> Deserialize<'de> for NotificationAction {
149-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
150-
where
151-
D: Deserializer<'de>,
152-
{
153-
#[derive(Deserialize)]
154-
#[serde(rename_all = "kebab-case")]
155-
enum ClickAction {
156-
OpenBuffer(BufferAction),
157-
#[serde(alias = "no-action")]
158-
Noop,
159-
}
160-
161-
#[derive(Deserialize)]
162-
#[serde(untagged)]
163-
enum Action {
164-
ClickAction(ClickAction),
165-
BufferAction(BufferAction),
166-
}
167-
168-
match Action::deserialize(deserializer)? {
169-
Action::ClickAction(click_action) => match click_action {
170-
ClickAction::OpenBuffer(buffer_action) => {
171-
Ok(NotificationAction::OpenBuffer(buffer_action))
172-
}
173-
ClickAction::Noop => Ok(NotificationAction::Noop),
174-
},
175-
Action::BufferAction(buffer_action) => {
176-
Ok(NotificationAction::OpenBuffer(buffer_action))
177-
}
178-
}
179-
}
148+
#[derive(Debug, Copy, Clone, Default, Deserialize)]
149+
pub enum NotificationAction {
150+
OpenBuffer,
151+
#[default]
152+
ActivateApplication,
180153
}

docs/configuration/actions.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Application-wide actions; how user actions should be enacted.
44

55
## `buffer`
66

7-
How buffer actions should be enacted
7+
How buffer actions should be enacted.
88

99
```toml
1010
# Replace pane when clicking on channel/user names in a pane
@@ -111,7 +111,7 @@ join_channel = "replace-pane"
111111

112112
## `nicklist`
113113

114-
How nicklist actions should be enacted
114+
How nicklist actions should be enacted.
115115

116116
```toml
117117
# Replace pane when clicking on a nickname in the nicklist
@@ -139,15 +139,40 @@ click_nickname = { "open-query" = "replace-pane" }
139139

140140
## `notification`
141141

142-
Action when clicking on a notification with a buffer context (e.g. when clicking a notification for a highlight in a channel, the context is the channel buffer). `"new-pane"` opens a new pane each time. `"replace-pane"` replaces the focused pane with the buffer context. `"new-window"` opens a new window each time. `"no-action"` or `"noop"` will perform no action on clicks aside from the default application activation behavior.
142+
How notification actions should be enacted.
143+
144+
```toml
145+
# Open buffer in a new window when clicking on a notification
146+
147+
[actions.notification]
148+
default = "open-buffer"
149+
open_buffer = "new-window"
150+
```
151+
152+
### `default`
153+
154+
Default action when clicking on a notification. When set to `"activate-application"` or when there is no buffer context for the notification (e.g. when clicking a notification for a monitored user going offline), then the default application activation behavior for notification will be enacted. When there is a buffer context (e.g. when clicking a notification for a highlight in a channel, the context is the channel buffer) and set to `"open-buffer"`, then the buffer context will be opened. If there is a buffer context and `"activate-application"` is set, then `"open-buffer"` will be provided as a secondary action (if supported by the notification system). When opening a buffer, [`actions.notification.open_buffer`](#open_buffer) determines how it will be opened.
143155

144156
```toml
145157
# Type: string
146-
# Values: "new-pane", "replace-pane", "new-window", "no-action", "noop"
147-
# Default: "noop"
158+
# Values: "activate-application", "open-buffer"
159+
# Default: "activate-application"
160+
161+
[actions.notification]
162+
default = "open-buffer"
163+
```
164+
165+
### `open_buffer`
166+
167+
When opening a buffer from a notification, how it will be opened. `"new-pane"` opens a new pane each time. `"replace-pane"` replaces the focused pane with the buffer. `"new-window"` opens a new window each time.
168+
169+
```toml
170+
# Type: string
171+
# Values: "new-pane", "replace-pane", "new-window"
172+
# Default: "new-pane"
148173

149-
[actions]
150-
notification = "new-pane"
174+
[actions.notification]
175+
open_buffer = "replace-pane"
151176
```
152177

153178
## `sidebar`

src/notification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ impl Notifications {
516516

517517
self.execute(
518518
notification_config,
519-
config.actions.notification,
519+
config.actions.notification.default,
520520
notification,
521521
&title,
522522
subtitle.as_deref(),

src/notification/toast.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,17 @@ impl Toast {
7575
notification.app_id(data::environment::APPLICATION_ID);
7676
}
7777

78-
if has_buffer_context
79-
&& !matches!(notification_action, NotificationAction::Noop)
80-
{
81-
notification.action("default", "Open Buffer");
82-
notification.action("open_or_focus_buffer", "Open Buffer");
78+
match notification_action {
79+
NotificationAction::ActivateApplication => {
80+
if has_buffer_context {
81+
notification.action("open_or_focus_buffer", "Open Buffer");
82+
}
83+
}
84+
NotificationAction::OpenBuffer => {
85+
if has_buffer_context {
86+
notification.action("default", "Open Buffer");
87+
}
88+
}
8389
}
8490

8591
Self(notification.finalize())

src/screen/dashboard.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use chrono::{DateTime, Utc};
99
use data::capabilities::{
1010
LabeledResponseContext, MultilineBatchKind, multiline_concat_lines,
1111
};
12-
use data::config::actions::NotificationAction;
1312
use data::config::buffer::{ScrollPosition, UsernameFormat};
1413
use data::dashboard::{self, BufferAction};
1514
use data::environment::{RELEASE_WEBSITE, WIKI_WEBSITE};
@@ -4637,10 +4636,7 @@ impl Dashboard {
46374636
match action {
46384637
toast::Action::Dismiss => Task::none(),
46394638
toast::Action::OpenOrFocusBuffer => {
4640-
if let Some(buffer) = buffer
4641-
&& let NotificationAction::OpenBuffer(buffer_action) =
4642-
config.actions.notification
4643-
{
4639+
if let Some(buffer) = buffer {
46444640
// When an notification action is performed in Wayland
46454641
// the application is not automatically brought forward.
46464642
// Request attention in order to do so.
@@ -4661,7 +4657,7 @@ impl Dashboard {
46614657
.chain(
46624658
self.open_or_focus_buffer(
46634659
buffer,
4664-
buffer_action,
4660+
config.actions.notification.open_buffer,
46654661
clients,
46664662
config,
46674663
),

0 commit comments

Comments
 (0)