Skip to content

Commit

Permalink
Only send notification if VTE doesn't have global focus
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunn1 committed Jan 11, 2016
1 parent de1cea1 commit 8554bbd
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
6 changes: 6 additions & 0 deletions data/gsettings/com.gexperts.Terminix.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
<default>'system'</default>
<summary>Which theme variant to use</summary>
</key>
<!-- Notification Options -->
<key name="notify-on-process-complete" type="b">
<default>true</default>
<summary>Whether to notify when a process is completed</summary>
<description>If true, notifications will be sent when non-visible processes complete in terminals.</description>
</key>
<!-- Search Options -->
<key name="search-default-match-case" type="b">
<default>false</default>
Expand Down
12 changes: 8 additions & 4 deletions source/gx/terminix/appwindow.d
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ private:
SessionNotificationPopover poSessionNotifications;

SessionNotification[string] sessionNotifications;

GSettings gsSettings;

/**
* Create the user interface
Expand Down Expand Up @@ -386,14 +388,16 @@ private:

void onSessionProcessNotification(string summary, string _body, string terminalUUID, string sessionUUID) {
trace(format("Notification Received\n\tSummary=%s\n\tBody=%s", summary, _body));
//If window not active, send notification to shell
if (!isActive()) {
// If window not active, send notification to shell
if (!isActive() && gsSettings.getBoolean(SETTINGS_NOTIFY_ON_PROCESS_COMPLETE_KEY)) {
Notification n = new Notification(_(summary));
n.setBody(_body);
n.setDefaultAction("app.activate-session::" ~ sessionUUID);
getApplication().sendNotification("command-completed", n);
//if session not visible send to local handler
} else if (sessionUUID != getCurrentSession().sessionUUID) {
}
// If session not active, keep copy locally
if (sessionUUID != getCurrentSession().sessionUUID) {
trace(format("SessionUUID: %s versus Notification UUID: %s", sessionUUID, getCurrentSession().sessionUUID));
//handle session level notifications here
ProcessNotificationMessage msg = ProcessNotificationMessage(terminalUUID, summary, _body);
Expand Down Expand Up @@ -555,8 +559,8 @@ public:

this(Application application) {
super(application);
trace("Adding window to terminix");
terminix.addAppWindow(this);
gsSettings = new GSettings(SETTINGS_ID);
setTitle(_("Terminix"));
setIconName("terminal");

Expand Down
1 change: 1 addition & 0 deletions source/gx/terminix/preferences.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum SETTINGS_THEME_VARIANT_LIGHT_VALUE = "light";
enum SETTINGS_THEME_VARIANT_DARK_VALUE = "dark";

enum SETTINGS_PROMPT_ON_NEW_SESSION_KEY = "prompt-on-new-session";
enum SETTINGS_NOTIFY_ON_PROCESS_COMPLETE_KEY = "notify-on-process-complete";

enum SETTINGS_SEARCH_DEFAULT_MATCH_CASE = "search-default-match-case";
enum SETTINGS_SEARCH_DEFAULT_MATCH_ENTIRE_WORD = "search-default-match-entire-word";
Expand Down
11 changes: 11 additions & 0 deletions source/gx/terminix/prefwindow.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import gdk.Event;

import gio.Settings;

import gobject.Signals;
import gobject.Value;

import gtk.AccelGroup;
Expand All @@ -40,6 +41,8 @@ import gtk.TreeView;
import gtk.TreeViewColumn;
import gtk.Widget;

import vte.Terminal;

import gx.gtk.actions;
import gx.gtk.util;

Expand Down Expand Up @@ -372,6 +375,14 @@ private:
settings.bind(SETTINGS_PROMPT_ON_NEW_SESSION_KEY, cbPrompt, "active", GSettingsBindFlags.DEFAULT);
attach(cbPrompt, 0, row, 2, 1);
row++;

//Show Notifications, only show option if notifications are supported
if (Signals.lookup("notification-received", Terminal.getType()) != 0) {
CheckButton cbNotify = new CheckButton(_("Send desktop notification on process complete"));
settings.bind(SETTINGS_NOTIFY_ON_PROCESS_COMPLETE_KEY, cbNotify, "active", GSettingsBindFlags.DEFAULT);
attach(cbNotify, 0, row, 2, 1);
row++;
}

Label lblAppearance = new Label("");
lblAppearance.setUseMarkup(true);
Expand Down
4 changes: 3 additions & 1 deletion source/gx/terminix/session.d
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ private:
}
}

//De/Serialization code in this private block
/************************************************
* De/Serialization code in this private block
************************************************/
private:

string _filename;
Expand Down
2 changes: 1 addition & 1 deletion source/gx/terminix/terminal/terminal.d
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private:
vte.addOnFocusIn(&onTerminalFocusIn);
vte.addOnFocusOut(&onTerminalFocusOut);
vte.addOnNotificationReceived(delegate(string summary, string _body, VTE terminal) {
if (titleInitialized) {
if (titleInitialized && !terminal.hasFocus()) {
notifyProcessNotification(summary, _body, terminalUUID);
}
});
Expand Down

0 comments on commit 8554bbd

Please sign in to comment.