Skip to content

Commit 9cd5319

Browse files
authored
Merge pull request heyjuvi#52 from edgararaj/master
Added background border customization & fade-in-out animations
2 parents 4c001f7 + 0e725f1 commit 9cd5319

File tree

3 files changed

+136
-12
lines changed

3 files changed

+136
-12
lines changed

Diff for: config.ini

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
# The border radius of the notification in px.
2525
;border-radius = 16
2626

27+
# Sets the border width of the notification in px.
28+
;border-width = 1
29+
2730
# The block height of the progress indicator.
2831
;block-height = 10
2932

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

39+
# Sets the fade in animation duration in seconds.
40+
;fade-in = 0.2
41+
42+
# Sets the fade out animation duration in seconds.
43+
;fade-out = 0.5
44+
3645
# The color of the notification background in format: rgba([0, 255], [0, 255], [0, 255], [0, 1]).
3746
;background = rgba(160, 160, 160, 0.8)
3847

48+
# Sets the color of the notification border in format rgba([0, 255], [0, 255], [0, 255], [0, 1]).
49+
;border-color = rgba(90, 90, 90, 0.8)
50+
3951
# The color of the filled bar blocks in format: rgba([0, 255], [0, 255], [0, 255], [0, 1]).
4052
;bar-fg-color = rgba(0, 0, 0, 0.8)
4153

Diff for: src/avizo_client.vala

+21
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ interface AvizoService : GLib.Object
1010
public abstract int width { owned get; set; }
1111
public abstract int height { owned get; set; }
1212
public abstract int border_radius { owned get; set; }
13+
public abstract int border_width { owned get; set; }
1314
public abstract int padding { owned get; set; }
1415
public abstract double y_offset { owned get; set; }
1516
public abstract int block_height { owned get; set; }
1617
public abstract int block_spacing { owned get; set; }
1718
public abstract int block_count { owned get; set; }
19+
public abstract double fade_in { owned get; set; }
20+
public abstract double fade_out { owned get; set; }
1821
public abstract Gdk.RGBA background { owned get; set; }
22+
public abstract Gdk.RGBA border_color { owned get; set; }
1923
public abstract Gdk.RGBA bar_fg_color { owned get; set; }
2024
public abstract Gdk.RGBA bar_bg_color { owned get; set; }
2125

@@ -38,10 +42,14 @@ public class AvizoClient : GLib.Application
3842
private static double _y_offset = 0.75;
3943
private static int _padding = 24;
4044
private static int _border_radius = 16;
45+
private static int _border_width = 1;
4146
private static int _block_height = 10;
4247
private static int _block_spacing = 2;
4348
private static int _block_count = 20;
49+
private static double _fade_in = 0.2;
50+
private static double _fade_out = 0.5;
4451
private static string _background = "";
52+
private static string _border_color = "";
4553
private static string _bar_fg_color = "";
4654
private static string _bar_bg_color = "";
4755
@@ -60,10 +68,14 @@ public class AvizoClient : GLib.Application
6068
{ "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" },
6169
{ "padding", 0, 0, OptionArg.INT, ref _padding, "Sets the inner padding of the notification", "INT" },
6270
{ "border-radius", 0, 0, OptionArg.INT, ref _border_radius, "Sets the border radius of the notification in px", "INT" },
71+
{ "border-width", 0, 0, OptionArg.INT, ref _border_width, "Sets the border width of the notification in px", "INT" },
6372
{ "block-height", 0, 0, OptionArg.INT, ref _block_height, "Sets the block height of the progress indicator", "INT" },
6473
{ "block-spacing", 0, 0, OptionArg.INT, ref _block_spacing, "Sets the spacing between blocks in the progress indicator", "INT" },
6574
{ "block-count", 0, 0, OptionArg.INT, ref _block_count, "Sets the amount of blocks in the progress indicator", "INT" },
75+
{ "fade-in", 0, 0, OptionArg.DOUBLE, ref _fade_in, "Sets the fade in animation duration in seconds", "DOUBLE" },
76+
{ "fade-out", 0, 0, OptionArg.DOUBLE, ref _fade_out, "Sets the fade out animation duration in seconds", "DOUBLE" },
6677
{ "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" },
78+
{ "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" },
6779
{ "foreground", 0, 0, OptionArg.STRING, ref _bar_fg_color, "Deprecated alias for --bar-fg-color", "STRING" },
6880
{ "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" },
6981
{ "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" },
@@ -159,10 +171,14 @@ public class AvizoClient : GLib.Application
159171
_service.padding = _padding;
160172
_service.y_offset = _y_offset;
161173
_service.border_radius = _border_radius;
174+
_service.border_width = _border_width;
162175
_service.block_height = _block_height;
163176
_service.block_spacing = _block_spacing;
164177
_service.block_count = _block_count;
165178

179+
_service.fade_in = _fade_in;
180+
_service.fade_out = _fade_out;
181+
166182
if (_background != "")
167183
{
168184
var color = parse_rgba(_background);
@@ -178,6 +194,11 @@ public class AvizoClient : GLib.Application
178194
}
179195
}
180196

197+
if (_border_color != "")
198+
{
199+
_service.border_color = parse_rgba(_border_color);
200+
}
201+
181202
if (_bar_bg_color != "")
182203
{
183204
_service.bar_bg_color = parse_rgba(_bar_bg_color);

Diff for: src/avizo_service.vala

+103-12
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,25 @@ public class AvizoWindow : Gtk.Window
7676

7777
public int padding { get; set; }
7878
public int border_radius { get; set; }
79+
public new int border_width { get; set; }
7980

8081
public int block_height { get; set; }
8182
public int block_spacing { get; set; }
8283
public int block_count { get; set; }
8384

85+
public double fade_in { get; set; }
86+
public double fade_out { get; set; }
87+
8488
public Gdk.RGBA background { get; set; default = Gdk.RGBA(); }
89+
public Gdk.RGBA border_color { get; set; default = Gdk.RGBA(); }
8590
public Gdk.RGBA bar_fg_color { get; set; default = Gdk.RGBA(); }
8691
public Gdk.RGBA bar_bg_color { get; set; default = Gdk.RGBA(); }
8792

93+
private new double opacity = 0;
94+
private bool is_fade_in = true;
95+
private int64 prev_frame_time = 0;
96+
private uint prev_callback_id = 0;
97+
8898
[GtkChild]
8999
private unowned Gtk.Image image;
90100

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

113+
public void show_animated()
114+
{
115+
remove_tick_callback(prev_callback_id);
116+
is_fade_in = true;
117+
prev_callback_id = add_tick_callback(animation_tick);
118+
show();
119+
}
120+
121+
public void hide_animated()
122+
{
123+
remove_tick_callback(prev_callback_id);
124+
is_fade_in = false;
125+
prev_callback_id = add_tick_callback(animation_tick);
126+
}
127+
128+
private bool animation_tick(Gtk.Widget widget, Gdk.FrameClock frame_clock)
129+
{
130+
frame_clock.begin_updating();
131+
int64 animation_us_elapsed;
132+
if (prev_frame_time == 0)
133+
{
134+
animation_us_elapsed = 0;
135+
}
136+
else {
137+
138+
animation_us_elapsed = (frame_clock.get_frame_time() - prev_frame_time);
139+
}
140+
prev_frame_time = frame_clock.get_frame_time();
141+
var animation_sec_elapsed = (double)animation_us_elapsed / 1000000;
142+
//var animation_sec_elapsed = (double)us_elapsed(frame_clock) / 1000000;
143+
//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);
144+
if (is_fade_in)
145+
{
146+
if (opacity >= 1)
147+
{
148+
prev_frame_time = 0;
149+
frame_clock.end_updating();
150+
return false;
151+
}
152+
opacity += animation_sec_elapsed/fade_in;
153+
if (opacity > 1) opacity = 1;
154+
print("Fade in: %f\n", opacity);
155+
widget.set_opacity(opacity);
156+
}
157+
else
158+
{
159+
if (opacity <= 0)
160+
{
161+
hide();
162+
prev_frame_time = 0;
163+
frame_clock.end_updating();
164+
return false;
165+
}
166+
opacity -= animation_sec_elapsed/fade_out;
167+
if (opacity < 0) opacity = 0;
168+
print("Fade out: %f\n", opacity);
169+
widget.set_opacity(opacity);
170+
}
171+
172+
frame_clock.end_updating();
173+
return true; // Keep going
174+
}
175+
103176
private bool on_draw(Gtk.Widget widget, Cairo.Context ctx)
104177
{
105-
double block_width = (_width - 2 * padding -
178+
double block_width = (_width - 2 * padding - 2 * border_width -
106179
(double) ((block_count - 1) * block_spacing)) / block_count;
107180

108-
double blocks_x = padding;
109-
double blocks_y = _height - padding - block_height;
181+
double blocks_x = padding + border_width;
182+
double blocks_y = _height - padding - border_width - block_height;
110183

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

117190
ctx.set_operator(Cairo.Operator.SOURCE);
118-
Gdk.cairo_set_source_rgba(ctx, background);
191+
Gdk.cairo_set_source_rgba(ctx, border_color);
119192
draw_round_rect(ctx, 0, 0, _width, _height, border_radius);
120193

194+
Gdk.cairo_set_source_rgba(ctx, background);
195+
draw_round_rect(ctx, border_width, border_width, _width - 2 * border_width, _height - 2 * border_width, border_radius - border_width);
196+
121197
Gdk.cairo_set_source_rgba(ctx, bar_bg_color);
122198

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

131207
Gdk.cairo_set_source_rgba(ctx, bar_fg_color);
132208

133-
for (int i = 0; i < (int) (block_count * progress); i++)
209+
if (block_spacing > 0)
134210
{
135-
draw_rect(ctx, blocks_x + (block_width + block_spacing) * i,
136-
blocks_y,
137-
block_width,
138-
block_height);
211+
for (int i = 0; i < (int) (block_count * progress); i++)
212+
{
213+
draw_rect(ctx, blocks_x + (block_width + block_spacing) * i,
214+
blocks_y,
215+
block_width,
216+
block_height);
217+
}
218+
}
219+
else {
220+
var width = block_width * block_count * progress;
221+
var height = block_height;
222+
draw_rect(ctx, blocks_x,
223+
blocks_y,
224+
width,
225+
height);
139226
}
140227

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

@@ -196,10 +283,14 @@ public class AvizoService : GLib.Object
196283
public int padding { get; set; default = 24; }
197284
public double y_offset { get; set; default = 0.75; }
198285
public int border_radius { get; set; default = 16; }
286+
public int border_width { get; set; default = 1; }
199287
public int block_height { get; set; default = 10; }
200288
public int block_spacing { get; set; default = 2; }
201289
public int block_count { get; set; default = 20; }
290+
public double fade_in { get; set; default = 0.2; }
291+
public double fade_out { get; set; default = 0.5; }
202292
public Gdk.RGBA background { get; set; default = rgba(160, 160, 160, 0.8); }
293+
public Gdk.RGBA border_color { get; set; default = rgba(90, 90, 90, 0.8); }
203294
public Gdk.RGBA bar_fg_color { get; set; default = rgba(0, 0, 0, 0.8); }
204295
public Gdk.RGBA bar_bg_color { get; set; default = rgba(106, 106, 106, 0.8); }
205296

@@ -235,7 +326,7 @@ public class AvizoService : GLib.Object
235326
if (_open_timeouts == 0)
236327
{
237328
for (int i = 0; i < monitors; i++) {
238-
_windows.index(i).hide();
329+
_windows.index(i).hide_animated();
239330
}
240331
}
241332

@@ -287,7 +378,7 @@ public class AvizoService : GLib.Object
287378
window.set_accept_focus(false);
288379
}
289380

290-
window.show();
381+
window.show_animated();
291382
window.queue_draw();
292383
}
293384
}

0 commit comments

Comments
 (0)