Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/panel/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ deps = [
if libpulse.found()
widget_sources += [
'widgets/volume.cpp',
'widgets/volume-level.cpp',
]
deps += [libpulse, libgvc]
else
Expand All @@ -50,7 +49,6 @@ if wireplumber.found()
'widgets/wp-mixer/wp-mixer.cpp',
'widgets/wp-mixer/wf-wp-control.cpp',
'widgets/wp-mixer/wp-common.cpp',
'widgets/volume-level.cpp',
]
deps += [pipewire, wireplumber]
else
Expand Down
42 changes: 0 additions & 42 deletions src/panel/widgets/volume-level.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions src/panel/widgets/volume-level.hpp

This file was deleted.

8 changes: 5 additions & 3 deletions src/panel/widgets/volume.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#include <gtkmm.h>
#include <glibmm.h>

#include "volume.hpp"
#include "icon-select.hpp"

#include "volume-level.hpp"
#define ICON(volume) icon_from_range(volume_icons, volume)

void WayfireVolume::update_icon()
{
if (gvc_stream && gvc_mixer_stream_get_is_muted(gvc_stream))
{
main_image.set_from_icon_name(volume_icon_for(0)); // mute
main_image.set_from_icon_name(ICON(0)); // mute
return;
}

main_image.set_from_icon_name(volume_icon_for(volume_scale.get_target_value() / (double)max_norm));
main_image.set_from_icon_name(ICON(volume_scale.get_target_value() / (double)max_norm));
}

bool WayfireVolume::on_popover_timeout(int timer)
Expand Down
8 changes: 5 additions & 3 deletions src/panel/widgets/wp-mixer/wf-wp-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <gtkmm.h>

#include "wf-wp-control.hpp"
#include "../volume-level.hpp"
#include "icon-select.hpp"

#define ICON(volume) icon_from_range(volume_icons, volume)

WfWpControl::WfWpControl(WpPipewireObject *obj, WayfireWpMixer *parent_widget)
{
Expand Down Expand Up @@ -143,12 +145,12 @@ void WfWpControl::update_icon()
if (button.get_active())
{
add_css_class("muted");
volume_icon.set_from_icon_name(volume_icon_for(0)); // mute
volume_icon.set_from_icon_name(ICON(0)); // mute
return;
}

remove_css_class("muted");
volume_icon.set_from_icon_name(volume_icon_for(get_scale_target_value()));
volume_icon.set_from_icon_name(ICON(get_scale_target_value()));
}

double WfWpControl::get_scale_target_value()
Expand Down
10 changes: 6 additions & 4 deletions src/panel/widgets/wp-mixer/wp-mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "wp-mixer.hpp"
#include "wf-wp-control.hpp"
#include "../volume-level.hpp"
#include "icon-select.hpp"

#define ICON(volume) icon_from_range(volume_icons, volume)

bool WayfireWpMixer::on_popover_timeout(int timer)
{
Expand Down Expand Up @@ -332,17 +334,17 @@ void WayfireWpMixer::update_icon()
// depends on quick_target widget
if (!quick_target)
{
main_image.set_from_icon_name(volume_icon_for(-1)); // OOR
main_image.set_from_icon_name(ICON(-1)); // OOR
return;
}

if (quick_target->button.get_active())
{
main_image.set_from_icon_name(volume_icon_for(0)); // mute
main_image.set_from_icon_name(ICON(0)); // mute
return;
}

main_image.set_from_icon_name(volume_icon_for(quick_target->get_scale_target_value()));
main_image.set_from_icon_name(ICON(quick_target->get_scale_target_value()));
}

void WayfireWpMixer::set_quick_target_from(WfWpControl *from)
Expand Down
14 changes: 14 additions & 0 deletions src/util/icon-select.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "icon-select.hpp"

std::string icon_from_range(std::map<double, std::string> icons, double value)
{
for (auto pair : icons)
{
if (value <= pair.first)
{
return pair.second;
}
}

return "";
}
17 changes: 17 additions & 0 deletions src/util/icon-select.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <map>
#include <string>
#include <limits>

std::string icon_from_range(std::map<double, std::string> icons, double value);

// the number in the first term is the maximal value at which this icon will be shown
// selection values of the tables are expected to be ordered from least to greatest

const std::map<double, std::string> volume_icons = {
{std::numeric_limits<double>::min(), "emblem-unreadable"},
{0.0, "audio-volume-muted"},
{1.0 / 3, "audio-volume-low"},
{(1.0 / 3) * 2, "audio-volume-medium"},
{1.0, "audio-volume-high"},
{std::numeric_limits<double>::max(), "audio-volume-high-danger-symbolic"}
};
2 changes: 2 additions & 0 deletions src/util/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ util = static_library(
'util',
[
'gtk-utils.cpp',
'icon-select.cpp',
'wf-shell-app.cpp',
'wf-autohide-window.cpp',
'wf-popover.cpp',
'css-config.cpp',
'wf-ipc.cpp',
'animated-scale.cpp',
'background-gl.cpp',
'icon-select.cpp'
],
dependencies: [wf_protos, gtklayershell, wayland_client, gtkmm, wfconfig, libinotify, json],
)
Expand Down