Skip to content

Commit

Permalink
Merge branch 'SoumyaRanjanPatnaik:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SoumyaRanjanPatnaik authored Aug 23, 2023
2 parents 8480e05 + 9cd5319 commit 7530b6b
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 13 deletions.
12 changes: 12 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# The border radius of the notification in px.
;border-radius = 16

# Sets the border width of the notification in px.
;border-width = 1

# The block height of the progress indicator.
;block-height = 10

Expand All @@ -33,9 +36,18 @@
# Sets the amount of blocks in the progress indicator.
;block-count = 20

# Sets the fade in animation duration in seconds.
;fade-in = 0.2

# Sets the fade out animation duration in seconds.
;fade-out = 0.5

# The color of the notification background in format: rgba([0, 255], [0, 255], [0, 255], [0, 1]).
;background = rgba(160, 160, 160, 0.8)

# Sets the color of the notification border in format rgba([0, 255], [0, 255], [0, 255], [0, 1]).
;border-color = rgba(90, 90, 90, 0.8)

# The color of the filled bar blocks in format: rgba([0, 255], [0, 255], [0, 255], [0, 1]).
;bar-fg-color = rgba(0, 0, 0, 0.8)

Expand Down
21 changes: 21 additions & 0 deletions src/avizo_client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ interface AvizoService : GLib.Object
public abstract int width { owned get; set; }
public abstract int height { owned get; set; }
public abstract int border_radius { owned get; set; }
public abstract int border_width { owned get; set; }
public abstract int padding { owned get; set; }
public abstract double y_offset { owned get; set; }
public abstract int block_height { owned get; set; }
public abstract int block_spacing { owned get; set; }
public abstract int block_count { owned get; set; }
public abstract double fade_in { owned get; set; }
public abstract double fade_out { owned get; set; }
public abstract Gdk.RGBA background { owned get; set; }
public abstract Gdk.RGBA border_color { owned get; set; }
public abstract Gdk.RGBA bar_fg_color { owned get; set; }
public abstract Gdk.RGBA bar_bg_color { owned get; set; }

Expand All @@ -38,10 +42,14 @@ public class AvizoClient : GLib.Application
private static double _y_offset = 0.75;
private static int _padding = 24;
private static int _border_radius = 16;
private static int _border_width = 1;
private static int _block_height = 10;
private static int _block_spacing = 2;
private static int _block_count = 20;
private static double _fade_in = 0.2;
private static double _fade_out = 0.5;
private static string _background = "";
private static string _border_color = "";
private static string _bar_fg_color = "";
private static string _bar_bg_color = "";
Expand All @@ -60,10 +68,14 @@ public class AvizoClient : GLib.Application
{ "y-offset", 0, 0, OptionArg.DOUBLE, ref _y_offset, "Sets relative offset of the notification to the top of the screen, allowed values range from 0 (top) to 1.0 (bottom)", "DOUBLE" },
{ "padding", 0, 0, OptionArg.INT, ref _padding, "Sets the inner padding of the notification", "INT" },
{ "border-radius", 0, 0, OptionArg.INT, ref _border_radius, "Sets the border radius of the notification in px", "INT" },
{ "border-width", 0, 0, OptionArg.INT, ref _border_width, "Sets the border width of the notification in px", "INT" },
{ "block-height", 0, 0, OptionArg.INT, ref _block_height, "Sets the block height of the progress indicator", "INT" },
{ "block-spacing", 0, 0, OptionArg.INT, ref _block_spacing, "Sets the spacing between blocks in the progress indicator", "INT" },
{ "block-count", 0, 0, OptionArg.INT, ref _block_count, "Sets the amount of blocks in the progress indicator", "INT" },
{ "fade-in", 0, 0, OptionArg.DOUBLE, ref _fade_in, "Sets the fade in animation duration in seconds", "DOUBLE" },
{ "fade-out", 0, 0, OptionArg.DOUBLE, ref _fade_out, "Sets the fade out animation duration in seconds", "DOUBLE" },
{ "background", 0, 0, OptionArg.STRING, ref _background, "Sets the color of the notification background in format rgba([0, 255], [0, 255], [0, 255], [0, 1])", "STRING" },
{ "border-color", 0, 0, OptionArg.STRING, ref _border_color, "Sets the color of the notification border in format rgba([0, 255], [0, 255], [0, 255], [0, 1])", "STRING" },
{ "foreground", 0, 0, OptionArg.STRING, ref _bar_fg_color, "Deprecated alias for --bar-fg-color", "STRING" },
{ "bar-fg-color", 0, 0, OptionArg.STRING, ref _bar_fg_color, "Sets the color of the filled bar blocks in format rgba([0, 255], [0, 255], [0, 255], [0, 1])", "STRING" },
{ "bar-bg-color", 0, 0, OptionArg.STRING, ref _bar_bg_color, "Sets the color of the unfilled bar blocks in format rgba([0, 255], [0, 255], [0, 255], [0, 1])", "STRING" },
Expand Down Expand Up @@ -159,10 +171,14 @@ public class AvizoClient : GLib.Application
_service.padding = _padding;
_service.y_offset = _y_offset;
_service.border_radius = _border_radius;
_service.border_width = _border_width;
_service.block_height = _block_height;
_service.block_spacing = _block_spacing;
_service.block_count = _block_count;

_service.fade_in = _fade_in;
_service.fade_out = _fade_out;

if (_background != "")
{
var color = parse_rgba(_background);
Expand All @@ -178,6 +194,11 @@ public class AvizoClient : GLib.Application
}
}

if (_border_color != "")
{
_service.border_color = parse_rgba(_border_color);
}

if (_bar_bg_color != "")
{
_service.bar_bg_color = parse_rgba(_bar_bg_color);
Expand Down
117 changes: 104 additions & 13 deletions src/avizo_service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,25 @@ public class AvizoWindow : Gtk.Window

public int padding { get; set; }
public int border_radius { get; set; }
public new int border_width { get; set; }

public int block_height { get; set; }
public int block_spacing { get; set; }
public int block_count { get; set; }

public double fade_in { get; set; }
public double fade_out { get; set; }

public Gdk.RGBA background { get; set; default = Gdk.RGBA(); }
public Gdk.RGBA border_color { get; set; default = Gdk.RGBA(); }
public Gdk.RGBA bar_fg_color { get; set; default = Gdk.RGBA(); }
public Gdk.RGBA bar_bg_color { get; set; default = Gdk.RGBA(); }

private new double opacity = 0;
private bool is_fade_in = true;
private int64 prev_frame_time = 0;
private uint prev_callback_id = 0;

[GtkChild]
private unowned Gtk.Image image;

Expand All @@ -100,13 +110,76 @@ public class AvizoWindow : Gtk.Window
draw.connect(on_draw);
}

public void show_animated()
{
remove_tick_callback(prev_callback_id);
is_fade_in = true;
prev_callback_id = add_tick_callback(animation_tick);
show();
}

public void hide_animated()
{
remove_tick_callback(prev_callback_id);
is_fade_in = false;
prev_callback_id = add_tick_callback(animation_tick);
}

private bool animation_tick(Gtk.Widget widget, Gdk.FrameClock frame_clock)
{
frame_clock.begin_updating();
int64 animation_us_elapsed;
if (prev_frame_time == 0)
{
animation_us_elapsed = 0;
}
else {

animation_us_elapsed = (frame_clock.get_frame_time() - prev_frame_time);
}
prev_frame_time = frame_clock.get_frame_time();
var animation_sec_elapsed = (double)animation_us_elapsed / 1000000;
//var animation_sec_elapsed = (double)us_elapsed(frame_clock) / 1000000;
//print("ms elapsed: %lld, sec elapsed: %f, fade in : %f, fade out: %f\n", animation_us_elapsed / 1000, animation_sec_elapsed, fade_in, fade_out);
if (is_fade_in)
{
if (opacity >= 1)
{
prev_frame_time = 0;
frame_clock.end_updating();
return false;
}
opacity += animation_sec_elapsed/fade_in;
if (opacity > 1) opacity = 1;
print("Fade in: %f\n", opacity);
widget.set_opacity(opacity);
}
else
{
if (opacity <= 0)
{
hide();
prev_frame_time = 0;
frame_clock.end_updating();
return false;
}
opacity -= animation_sec_elapsed/fade_out;
if (opacity < 0) opacity = 0;
print("Fade out: %f\n", opacity);
widget.set_opacity(opacity);
}

frame_clock.end_updating();
return true; // Keep going
}

private bool on_draw(Gtk.Widget widget, Cairo.Context ctx)
{
double block_width = (_width - 2 * padding -
double block_width = (_width - 2 * padding - 2 * border_width -
(double) ((block_count - 1) * block_spacing)) / block_count;

double blocks_x = padding;
double blocks_y = _height - padding - block_height;
double blocks_x = padding + border_width;
double blocks_y = _height - padding - border_width - block_height;

ctx.set_operator(Cairo.Operator.SOURCE);
ctx.paint();
Expand All @@ -115,9 +188,12 @@ public class AvizoWindow : Gtk.Window
draw_rect(ctx, 0, 0, _width, _height);

ctx.set_operator(Cairo.Operator.SOURCE);
Gdk.cairo_set_source_rgba(ctx, background);
Gdk.cairo_set_source_rgba(ctx, border_color);
draw_round_rect(ctx, 0, 0, _width, _height, border_radius);

Gdk.cairo_set_source_rgba(ctx, background);
draw_round_rect(ctx, border_width, border_width, _width - 2 * border_width, _height - 2 * border_width, border_radius - border_width);

Gdk.cairo_set_source_rgba(ctx, bar_bg_color);

for (int i = 0; i < block_count; i++)
Expand All @@ -130,12 +206,23 @@ public class AvizoWindow : Gtk.Window

Gdk.cairo_set_source_rgba(ctx, bar_fg_color);

for (int i = 0; i < (int) (block_count * progress); i++)
if (block_spacing > 0)
{
draw_rect(ctx, blocks_x + (block_width + block_spacing) * i,
blocks_y,
block_width,
block_height);
for (int i = 0; i < (int) (block_count * progress); i++)
{
draw_rect(ctx, blocks_x + (block_width + block_spacing) * i,
blocks_y,
block_width,
block_height);
}
}
else {
var width = block_width * block_count * progress;
var height = block_height;
draw_rect(ctx, blocks_x,
blocks_y,
width,
height);
}

ctx.set_operator(Cairo.Operator.OVER);
Expand Down Expand Up @@ -183,7 +270,7 @@ public class AvizoService : GLib.Object
{
private static string[] props = {
"image_path", "image_resource", "image_opacity", "progress", "width", "height", "padding",
"border_radius", "block_height", "block_spacing", "block_count", "background",
"border_radius", "border_width", "block_height", "block_spacing", "block_count", "fade_in", "fade_out", "background", "border_color",
"bar_fg_color", "bar_bg_color",
};

Expand All @@ -196,10 +283,14 @@ public class AvizoService : GLib.Object
public int padding { get; set; default = 24; }
public double y_offset { get; set; default = 0.75; }
public int border_radius { get; set; default = 16; }
public int border_width { get; set; default = 1; }
public int block_height { get; set; default = 10; }
public int block_spacing { get; set; default = 2; }
public int block_count { get; set; default = 20; }
public double fade_in { get; set; default = 0.2; }
public double fade_out { get; set; default = 0.5; }
public Gdk.RGBA background { get; set; default = rgba(160, 160, 160, 0.8); }
public Gdk.RGBA border_color { get; set; default = rgba(90, 90, 90, 0.8); }
public Gdk.RGBA bar_fg_color { get; set; default = rgba(0, 0, 0, 0.8); }
public Gdk.RGBA bar_bg_color { get; set; default = rgba(106, 106, 106, 0.8); }

Expand Down Expand Up @@ -235,7 +326,7 @@ public class AvizoService : GLib.Object
if (_open_timeouts == 0)
{
for (int i = 0; i < monitors; i++) {
_windows.index(i).hide();
_windows.index(i).hide_animated();
}
}

Expand Down Expand Up @@ -287,7 +378,7 @@ public class AvizoService : GLib.Object
window.set_accept_focus(false);
}

window.show();
window.show_animated();
window.queue_draw();
}
}
Expand Down Expand Up @@ -326,7 +417,7 @@ public void main(string[] args)
Bus.own_name(BusType.SESSION, "org.danb.avizo.service", BusNameOwnerFlags.NONE,
on_bus_aquired,
() => {},
() => stderr.printf("Could not aquire name\n"));
() => stderr.printf("Could not acquire name\n"));

new AvizoService();

Expand Down

0 comments on commit 7530b6b

Please sign in to comment.