Skip to content

Commit

Permalink
Merge pull request #64 from arminius-smh/set-monitor
Browse files Browse the repository at this point in the history
Adds option to specify monitor
  • Loading branch information
heyjuvi authored Jan 27, 2024
2 parents f66425c + b459e41 commit 79367b2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
7 changes: 5 additions & 2 deletions lightctl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# Options:
# -e <exponent> Change percentage curve to exponential (only for brightnessctl).
# -D <device> Specify the device name.
# -M <monitornr> Set monitor where notification will be shown.
# -d Show dark theme friendly variant of the icon
# -h Show this message and exit.
#
Expand Down Expand Up @@ -49,11 +50,13 @@ exp=
dev=
optind=1
dark=0
while getopts ':e:D:h:d' OPT; do
monitor=-1
while getopts ':e:D:h:M:d' OPT; do
case "$OPT" in
e) exp=$OPTARG;;
D) dev=$OPTARG;;
h) help; exit 0;;
M) monitor="$OPTARG";;
d) dark=1;;
\?) case "$OPTARG" in
[0-9]*) break;;
Expand Down Expand Up @@ -133,4 +136,4 @@ fi

progress=$(echo "$light" | awk '{ printf "%.2f", $1 / 100 }')

avizo-client --image-resource="$image" --progress="$progress"
avizo-client --image-resource="$image" --progress="$progress" --monitor="$monitor"
4 changes: 4 additions & 0 deletions src/avizo_client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface AvizoService : GLib.Object
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; }
public abstract int monitor { owned get; set; }

public abstract void show(double seconds) throws DBusError, IOError;
}
Expand Down Expand Up @@ -52,6 +53,7 @@ public class AvizoClient : GLib.Application
private static string _border_color = "";
private static string _bar_fg_color = "";
private static string _bar_bg_color = "";
private static int _monitor = -1;
private static double _time = 5.0;
Expand Down Expand Up @@ -80,6 +82,7 @@ public class AvizoClient : GLib.Application
{ "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" },
{ "time", 0, 0, OptionArg.DOUBLE, ref _time, "Sets the time to show the notification, default is 5", "DOUBLE" },
{ "monitor", 0, 0, OptionArg.INT, ref _monitor, "Sets the monitor to show the notification on, default is all", "INT" },
{ null }
};

Expand Down Expand Up @@ -188,6 +191,7 @@ public class AvizoClient : GLib.Application

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

if (_background != "")
{
Expand Down
33 changes: 25 additions & 8 deletions src/avizo_service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class AvizoWindow : Gtk.Window

public double progress { get; set; }

public int monitor { get; set; }

private int _width = 248;
public int width
{
Expand Down Expand Up @@ -282,7 +284,7 @@ public class AvizoWindow : Gtk.Window
public class AvizoService : GLib.Object
{
private static string[] props = {
"image_path", "image_resource", "image_opacity", "progress", "width", "height", "padding",
"image_path", "image_resource", "image_opacity", "progress", "width", "height", "padding", "monitor",
"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 @@ -306,6 +308,7 @@ public class AvizoService : GLib.Object
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); }
public int monitor { get; set; default = -1; }

private Array<AvizoWindow> _windows = new Array<AvizoWindow>();
private int _open_timeouts = 0;
Expand All @@ -320,15 +323,24 @@ public class AvizoService : GLib.Object
_windows.set_size(monitors);
}

if (monitor >= monitors)
{
stderr.printf(@"Monitor: $(monitor) does not exist\n");
return;
}

for (int i = 0; i < monitors; i++)
{
var window = _windows.index(i);
if (window == null)
if (monitor == -1 || monitor == i)
{
window = create_window(display);
_windows.insert_val(i, window);
var window = _windows.index(i);
if (window == null)
{
window = create_window(display);
_windows.insert_val(i, window);
}
show_window(window, display.get_monitor(i));
}
show_window(window, display.get_monitor(i));
}

_open_timeouts++;
Expand All @@ -338,8 +350,13 @@ public class AvizoService : GLib.Object

if (_open_timeouts == 0)
{
for (int i = 0; i < monitors; i++) {
_windows.index(i).hide_animated();
for (int i = 0; i < monitors; i++)
{
var window = _windows.index(i);
if (window != null)
{
window.hide_animated();
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions volumectl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# it will choose the first one as reported by pactl/pamixer.
# -g <gamma> Increase/decrease using gamma correction (e.g. 2.2).
# -m Control the source (mic) instead of sink (output).
# -M <monitornr> Set monitor where notification will be shown.
# -u Unmute when changing the volume (+|-|=).
# -d Show dark theme friendly variant of the icon
# -h Show this message and exit.
Expand Down Expand Up @@ -75,14 +76,16 @@ opts=
unmute_opt=
optind=1
dark=0
while getopts ':adbD:pg:muh' OPT; do
monitor=-1
while getopts ':adbD:pg:mM:uh' OPT; do
case "$OPT" in
a) all_flag=true;;
b) opts="$opts --allow-boost";;
D) dev=$OPTARG;;
p) use_playing=true;;
g) opts="$opts --gamma=$OPTARG";;
m) dev_type='source';;
M) monitor="$OPTARG";;
u) unmute_opt='--unmute';;
d) dark=1;;
h) help; exit 0;;
Expand Down Expand Up @@ -181,4 +184,4 @@ if [ "$dark" -eq 1 ]; then
fi

progress=$(echo "$volume" | awk '{ printf "%.2f", ($1 > 100 ? 1 : $1 / 100) }')
avizo-client --image-resource="$image" --progress="$progress"
avizo-client --image-resource="$image" --progress="$progress" --monitor="$monitor"

0 comments on commit 79367b2

Please sign in to comment.