Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikReider committed Feb 21, 2023
1 parent 450ad37 commit d748f01
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Post your setup here: [Config flex 💪](https://github.com/ErikReider/SwayNotif

- Keyboard shortcuts
- Notification body markup with image support
- Inline replies
- A panel to view previous notifications
- Show album art for notifications like Spotify
- Do not disturb
Expand Down
11 changes: 10 additions & 1 deletion src/controlCenter/controlCenter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ namespace SwayNotificationCenter {
// sometimes being passed through to unfucused application
// Ex: Firefox in a fullscreen YouTube video
this.key_release_event.connect ((w, event_key) => {
if (this.get_focus () is Gtk.Entry) {
switch (Gdk.keyval_name (event_key.keyval)) {
case "Escape":
this.set_focus (null);
return true;
}
return false;
}
if (event_key.type == Gdk.EventType.KEY_RELEASE) {
switch (Gdk.keyval_name (event_key.keyval)) {
case "Escape":
Expand All @@ -85,6 +93,7 @@ namespace SwayNotificationCenter {
});

this.key_press_event.connect ((w, event_key) => {
if (this.get_focus () is Gtk.Entry) return false;
if (event_key.type == Gdk.EventType.KEY_PRESS) {
var children = list_box.get_children ();
Notification noti = (Notification)
Expand Down Expand Up @@ -145,7 +154,7 @@ namespace SwayNotificationCenter {
}
navigate_list (list_position);
}
return true;
return false;
});

// Switches the stack page depending on the
Expand Down
4 changes: 4 additions & 0 deletions src/notiDaemon/notiDaemon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace SwayNotificationCenter {
"synchronous",
"private-synchronous",
"x-canonical-private-synchronous",
"inline-reply",
};
}

Expand Down Expand Up @@ -324,5 +325,8 @@ namespace SwayNotificationCenter {
* support the concept of being able to "invoke" a notification.
*/
public signal void ActionInvoked (uint32 id, string action_key);

/** To be used by the non-standard "inline-reply" capability */
public signal void NotificationReplied (uint32 id, string text);
}
}
62 changes: 41 additions & 21 deletions src/notiModel/notiModel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ namespace SwayNotificationCenter {
private int priv_value { private get; private set; }
public bool has_synch { public get; private set; }

/** Inline-replies */
public Action ? inline_reply { get; set; }
public string ? inline_reply_placeholder { get; set; }

// Custom hints
/** Disables scripting for notification */
public bool swaync_no_script { get; set; }
Expand Down Expand Up @@ -133,30 +137,12 @@ namespace SwayNotificationCenter {
this.replaces = false;
this.has_synch = false;

s_hints ();

Array<Action> ac_array = new Array<Action> ();
if (actions.length > 1 && actions.length % 2 == 0) {
for (int i = 0; i < actions.length; i++) {
var action = new Action ();
action.identifier = actions[i];
action.name = actions[i + 1];
if (action.name != null && action.identifier != null
&& action.name != "" && action.identifier != "") {
parse_hints ();

if (action.identifier.down () == "default") {
default_action = action;
} else {
ac_array.append_val (action);
}
}
i++;
}
}
this.actions = ac_array;
parse_actions (actions);
}

private void s_hints () {
private void parse_hints () {
foreach (var hint in hints.get_keys ()) {
Variant hint_value = hints[hint];
switch (hint) {
Expand Down Expand Up @@ -239,8 +225,42 @@ namespace SwayNotificationCenter {
urgency = UrgencyLevels.from_value (hint_value.get_byte ());
}
break;
case "x-kde-reply-placeholder-text":
if (hint_value.is_of_type (VariantType.STRING)) {
inline_reply_placeholder = hint_value.get_string ();
}
break;
}
}
}

private void parse_actions (string[] actions) {
Array<Action> parsed_actions = new Array<Action> ();
if (actions.length > 1 && actions.length % 2 == 0) {
for (int i = 0; i < actions.length; i++) {
var action = new Action ();
action.identifier = actions[i];
action.name = actions[i + 1];
if (action.name != null && action.identifier != null
&& action.name != "" && action.identifier != "") {

string id = action.identifier.down ();
switch (id) {
case "default":
default_action = action;
break;
case "inline-reply":
inline_reply = action;
break;
default:
parsed_actions.append_val (action);
break;
}
}
i++;
}
}
this.actions = parsed_actions;
}

public string to_string () {
Expand Down
49 changes: 46 additions & 3 deletions src/notification/notification.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<requires lib="libhandy" version="1.2"/>
Expand Down Expand Up @@ -45,10 +45,10 @@
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="default_button">
<object class="GtkEventBox" id="default_action">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="receives-default">False</property>
<property name="events">GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
Expand Down Expand Up @@ -192,6 +192,49 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="inline_reply_box">
<property name="can-focus">False</property>
<child>
<object class="GtkEntry" id="inline_reply_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="input-hints">GTK_INPUT_HINT_SPELLCHECK | GTK_INPUT_HINT_EMOJI | GTK_INPUT_HINT_NONE</property>
<style>
<class name="inline-reply-entry"/>
</style>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="inline_reply_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<style>
<class name="inline-reply-button"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<style>
<class name="inline-reply"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<style>
<class name="notification-content"/>
</style>
Expand Down
Loading

0 comments on commit d748f01

Please sign in to comment.