Skip to content

Commit

Permalink
fix: исправить некорректное изменение громкости через кнопки увеличен…
Browse files Browse the repository at this point in the history
…ия, уменьшения громкости и скролл по кнопке через тач
  • Loading branch information
Rirusha committed Jun 2, 2024
1 parent dd05d4b commit 1eb72d0
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/widgets/buttons/menu/volume-button.vala
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ public class Cassette.VolumeButton : CustomMenuButton {

var se = new Gtk.EventControllerScroll (Gtk.EventControllerScrollFlags.VERTICAL);
se.scroll.connect ((dx, dy) => {
if (dy < 0) {
increase_volume ();

} else {
decrease_volume ();
}
change_volume (dy * MUL);
});
add_controller (se);

Expand All @@ -98,18 +93,29 @@ public class Cassette.VolumeButton : CustomMenuButton {
}

void increase_volume () {
if (volume + volume_step > volume_upper) {
volume = volume_upper;
} else {
volume += volume_step;
}
change_volume (volume_step);
}

void decrease_volume () {
if (volume - volume_step < volume_lower) {
change_volume (-volume_step);
}

/*
* @param dvol delta volume, 0.0-1.0
*/
void change_volume (double dvol) {
double svol = Math.pow (volume, 1.0 / 3.0);

svol += dvol;

if (svol > volume_upper) {
volume = volume_upper;

} else if (svol < volume_lower) {
volume = volume_lower;

} else {
volume -= volume_step;
volume = Math.pow (svol, 3.0);
}
}

Expand Down Expand Up @@ -195,19 +201,11 @@ public class Cassette.VolumeButton : CustomMenuButton {
val = adjustment_actual_upper;
}

val *= MUL;

mute = false;

volume = Math.pow (val, 3.0);
volume = Math.pow (val * MUL, 3.0);

return true;

// if (val < volume_lower || val > volume_upper) {
// return false;
// }

// return true;
});

var volume_second_button = new Gtk.Button () {
Expand Down

0 comments on commit 1eb72d0

Please sign in to comment.