Skip to content

Commit

Permalink
Prevent notifs and scrshot from locking up when sink is locked (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Jul 10, 2023
1 parent daec799 commit 2696249
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
42 changes: 25 additions & 17 deletions src/daemon/notifications/dbus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -471,28 +471,13 @@
sound_name = notification.hints.get("sound-name").get_string();
}

play_sound(notification, sound_name);
}

/**
* Play a sound for a notification.
*/
private void play_sound(Notification notification, string? sound_name = "dialog-information") {
// Try to map the notification's category to a sound name to use
if (sound_name == "dialog-information" && notification.category != null) {
sound_name = get_sound_for_category(notification.category);
}

// Play the sound
if (sound_name != null) {
Canberra.Proplist props;
Canberra.Proplist.create(out props);

props.sets(Canberra.PROP_CANBERRA_CACHE_CONTROL, "volatile");
props.sets(Canberra.PROP_EVENT_ID, sound_name);

CanberraGtk.context_get().play_full(0, props);
}
var player = new SoundPlayer(notification, sound_name);
new Thread<void>(null, player.play);
}

/**
Expand Down Expand Up @@ -618,4 +603,27 @@
}
}
}

class SoundPlayer {
private Notification notification;
private string? sound_name;

public SoundPlayer(Notification notification, string? sound_name = "dialog-information") {
this.notification = notification;
this.sound_name = sound_name;
}

public void play() {
// Play the sound
if (sound_name != null) {
Canberra.Proplist props;
Canberra.Proplist.create(out props);

props.sets(Canberra.PROP_CANBERRA_CACHE_CONTROL, "volatile");
props.sets(Canberra.PROP_EVENT_ID, sound_name);

CanberraGtk.context_get().play_full(0, props);
}
}
}
}
3 changes: 2 additions & 1 deletion src/daemon/screenshot.vala
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ namespace BudgieScr {
// fake thread to make sure flash and shutter are in sync
pipeline.set_state(State.PLAYING);
Gst.Bus bus = pipeline.get_bus();
bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS);
// time out after 2 seconds, in case the output is locked
bus.timed_pop_filtered(2000000000, Gst.MessageType.ERROR | Gst.MessageType.EOS);
pipeline.set_state(Gst.State.NULL);

return false;
Expand Down

0 comments on commit 2696249

Please sign in to comment.