Skip to content

Commit

Permalink
Notification class. some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Junker committed Dec 20, 2019
1 parent bdf9550 commit b3206e5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 30 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_project_arguments('-DGETTEXT_PACKAGE="mictray"', language: 'c')

sources = [
'src/pulse.vala',
'src/notification.vala',
'src/config-file.vala',
'src/status-icon.vala',
'src/settings-window.vala'
Expand Down
34 changes: 5 additions & 29 deletions src/mictray.vala
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

using Gtk;
using Notify;

static MicStatusIcon status_icon;

static Pulse pulse;
static ConfigFile config;
static MicTrayApp app;
static Notify.Notification vol_notification;
static Notification notification;

extern const string GETTEXT_PACKAGE;

Expand All @@ -16,48 +15,25 @@ class MicTrayApp : Gtk.Application
protected override void activate ()
{
status_icon = new MicStatusIcon();

config = new ConfigFile();

pulse = new Pulse();

Notify.init ("MicTray");
vol_notification = new Notify.Notification ("Volume: %d%c".printf(pulse.volume, '%'), "", status_icon.icon_name);
vol_notification.set_timeout(2000);
vol_notification.set_hint("transient", new Variant.boolean(true));
notification = new Notification();

pulse.change_callback = () =>
{
status_icon.update();

if (config.show_notifications && (pulse.old_volume != pulse.volume || pulse.old_muted != pulse.muted))
if (config.show_notifications && !pulse.first_change && (pulse.old_volume != pulse.volume || pulse.old_muted != pulse.muted))
{
try
{
vol_notification.update("Volume: %d%c".printf(pulse.volume, '%'), "", status_icon.icon_name);
vol_notification.set_hint("value", new Variant.int32(pulse.volume));
vol_notification.show();
}
catch (Error e)
{
error ("Error: %s", e.message);
}
notification.update();
}
};

pulse.source_change_callback = () =>
{
if (config.show_notifications)
{
try
{
Notify.Notification notification = new Notify.Notification ("Input source changed", pulse.current_source_description, status_icon.icon_name);
notification.show();
}
catch (Error e)
{
error ("Error: %s", e.message);
}
notification.source_changed();
}
};

Expand Down
42 changes: 42 additions & 0 deletions src/notification.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Notify;

class Notification : Object
{
private Notify.Notification vol_notification;

construct
{
Notify.init ("MicTray");

vol_notification = new Notify.Notification ("Volume: %d%c".printf(pulse.volume, '%'), "", status_icon.icon_name);
vol_notification.set_timeout(2000);
vol_notification.set_hint("transient", new Variant.boolean(true));
}

public void update()
{
try
{
this.vol_notification.update("Volume: %d%c".printf(pulse.volume, '%'), "", status_icon.icon_name);
this.vol_notification.set_hint("value", new Variant.int32(pulse.volume));
this.vol_notification.show();
}
catch (Error e)
{
error ("Error: %s", e.message);
}
}

public void source_changed()
{
try
{
Notify.Notification notification = new Notify.Notification ("Input source changed", pulse.current_source_description, status_icon.icon_name);
notification.show();
}
catch (Error e)
{
error ("Error: %s", e.message);
}
}
}
2 changes: 2 additions & 0 deletions src/pulse.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Pulse : Object
public int old_volume;
public bool muted;
public bool old_muted;
public bool first_change = true;

public Callback change_callback;
public Callback source_change_callback;
Expand Down Expand Up @@ -198,6 +199,7 @@ public class Pulse : Object
this.source_change_callback();
}

this.first_change = false;
});
}
}
2 changes: 1 addition & 1 deletion src/status-icon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class MicStatusIcon : StatusIcon
{
var about = new Gtk.AboutDialog();
about.set_logo_icon_name("microphone-sensitivity-high");
about.set_version("0.2.1");
about.set_version("0.2.3");
about.set_program_name("MicTray");
about.set_comments("Microphone control application");
about.set_copyright("Dmitry Kosenkov");
Expand Down

0 comments on commit b3206e5

Please sign in to comment.