From a5ab50defbbb88f5d5b257437d7d4c4cadfe24a7 Mon Sep 17 00:00:00 2001 From: streetturtle Date: Mon, 9 Nov 2020 15:54:33 -0500 Subject: [experiments-volume] add icon widget --- experiments/volume/arc-widget.lua | 37 ----------------- experiments/volume/icon-and-text-widget.lua | 46 ---------------------- experiments/volume/utils.lua | 1 - experiments/volume/volume.lua | 19 +++++++-- experiments/volume/widgets/arc-widget.lua | 39 ++++++++++++++++++ .../volume/widgets/icon-and-text-widget.lua | 45 +++++++++++++++++++++ experiments/volume/widgets/icon-widget.lua | 35 ++++++++++++++++ 7 files changed, 134 insertions(+), 88 deletions(-) delete mode 100644 experiments/volume/arc-widget.lua delete mode 100644 experiments/volume/icon-and-text-widget.lua create mode 100644 experiments/volume/widgets/arc-widget.lua create mode 100644 experiments/volume/widgets/icon-and-text-widget.lua create mode 100644 experiments/volume/widgets/icon-widget.lua diff --git a/experiments/volume/arc-widget.lua b/experiments/volume/arc-widget.lua deleted file mode 100644 index 85cc20a..0000000 --- a/experiments/volume/arc-widget.lua +++ /dev/null @@ -1,37 +0,0 @@ -local wibox = require("wibox") -local beautiful = require('beautiful') - -local widget = {} - -function widget.get_widget() - - return wibox.widget { - { - id = "icon", - image = '/usr/share/icons/Arc/status/symbolic/audio-volume-muted-symbolic.svg', - resize = true, - widget = wibox.widget.imagebox, - }, - max_value = 100, - thickness = 2, - start_angle = 4.71238898, -- 2pi*3/4 - forced_height = 18, - forced_width = 18, - bg = '#ffffff11', - paddings = 2, - widget = wibox.container.arcchart, - set_volume_level = function(self, new_value) - self.value = new_value - end, - mute = function(self) - self.colors = {'#BF616A'} - end, - unmute = function(self) - self.colors = {beautiful.fg_color} - end - } - -end - - -return widget \ No newline at end of file diff --git a/experiments/volume/icon-and-text-widget.lua b/experiments/volume/icon-and-text-widget.lua deleted file mode 100644 index 929d32d..0000000 --- a/experiments/volume/icon-and-text-widget.lua +++ /dev/null @@ -1,46 +0,0 @@ -local wibox = require("wibox") - -local widget = {} - -local WIDGET_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/experiments/volume/icons/' - -function widget.get_widget() - - return wibox.widget { - { - { - id = "icon", - image = '/usr/share/icons/Arc/status/symbolic/audio-volume-muted-symbolic.svg', - resize = false, - widget = wibox.widget.imagebox, - }, - valign = 'center', - layout = wibox.container.place - }, - { - id = 'txt', - widget = wibox.widget.textbox - }, - layout = wibox.layout.fixed.horizontal, - set_volume_level = function(self, new_value) - self:get_children_by_id('txt')[1]:set_text(new_value) - local new_value_num = tonumber(new_value) - local volume_icon_name = '' - if (new_value_num >= 0 and new_value_num < 33) then - volume_icon_name="audio-volume-low-symbolic" - elseif (new_value_num < 66) then - volume_icon_name="audio-volume-medium-symbolic" - else - volume_icon_name="audio-volume-high-symbolic" - end - self:get_children_by_id('icon')[1]:set_image(WIDGET_DIR .. volume_icon_name .. '.svg') - end, - mute = function(self) self:get_children_by_id('icon')[1]:set_image(WIDGET_DIR .. 'audio-volume-muted-symbolic.svg') end, - unmute = function() end, - - } - -end - - -return widget \ No newline at end of file diff --git a/experiments/volume/utils.lua b/experiments/volume/utils.lua index 02742ec..dcaeb84 100644 --- a/experiments/volume/utils.lua +++ b/experiments/volume/utils.lua @@ -99,7 +99,6 @@ function utils.extract_sinks_and_sources(pacmd_output) ports[key] = t[2] end end - print(json.encode(sources)) return sinks, sources end diff --git a/experiments/volume/volume.lua b/experiments/volume/volume.lua index 2e9bc18..9110a45 100644 --- a/experiments/volume/volume.lua +++ b/experiments/volume/volume.lua @@ -14,8 +14,6 @@ local gears = require("gears") local beautiful = require("beautiful") local watch = require("awful.widget.watch") local utils = require("awesome-wm-widgets.experiments.volume.utils") -local arc_widget = require("awesome-wm-widgets.experiments.volume.arc-widget") -local icon_and_text_widget = require("awesome-wm-widgets.experiments.volume.icon-and-text-widget") local LIST_DEVICES_CMD = [[sh -c "pacmd list-sinks; pacmd list-sources"]] @@ -25,6 +23,12 @@ local DEC_VOLUME_CMD = 'amixer -q -D pulse sset Master 5%-' local TOG_VOLUME_CMD = 'amixer -q -D pulse sset Master toggle' +local widget_types = { + icon_and_text = require("awesome-wm-widgets.experiments.volume.widgets.icon-and-text-widget"), + icon = require("awesome-wm-widgets.experiments.volume.widgets.icon-widget"), + arc = require("awesome-wm-widgets.experiments.volume.widgets.arc-widget") +} + local volume_widget = wibox.widget{} local rows = { layout = wibox.layout.fixed.vertical } @@ -156,8 +160,15 @@ end local function worker(args) - volume_widget = arc_widget.get_widget() - -- volume_widget = icon_and_text_widget.get_widget() + local args = args or {} + + local widget_type = args.widget_type + + if widget_types[widget_type] == nil then + volume_widget = widget_types['icon_and_text'].get_widget() + else + volume_widget = widget_types[widget_type].get_widget() + end volume_widget:buttons( awful.util.table.join( diff --git a/experiments/volume/widgets/arc-widget.lua b/experiments/volume/widgets/arc-widget.lua new file mode 100644 index 0000000..d7a3b1f --- /dev/null +++ b/experiments/volume/widgets/arc-widget.lua @@ -0,0 +1,39 @@ +local wibox = require("wibox") +local beautiful = require('beautiful') + +local ICON_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/experiments/volume/icons/' + +local widget = {} + +function widget.get_widget() + + return wibox.widget { + { + id = "icon", + image = ICON_DIR .. 'audio-volume-high-symbolic.svg', + resize = true, + widget = wibox.widget.imagebox, + }, + max_value = 100, + thickness = 2, + start_angle = 4.71238898, -- 2pi*3/4 + forced_height = 18, + forced_width = 18, + bg = '#ffffff11', + paddings = 2, + widget = wibox.container.arcchart, + set_volume_level = function(self, new_value) + self.value = new_value + end, + mute = function(self) + self.colors = {'#BF616A'} + end, + unmute = function(self) + self.colors = {beautiful.fg_color} + end + } + +end + + +return widget \ No newline at end of file diff --git a/experiments/volume/widgets/icon-and-text-widget.lua b/experiments/volume/widgets/icon-and-text-widget.lua new file mode 100644 index 0000000..5ea626b --- /dev/null +++ b/experiments/volume/widgets/icon-and-text-widget.lua @@ -0,0 +1,45 @@ +local wibox = require("wibox") + +local widget = {} + +local WIDGET_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/experiments/volume/icons/' + +function widget.get_widget() + + return wibox.widget { + { + { + id = "icon", + resize = false, + widget = wibox.widget.imagebox, + }, + valign = 'center', + layout = wibox.container.place + }, + { + id = 'txt', + widget = wibox.widget.textbox + }, + layout = wibox.layout.fixed.horizontal, + set_volume_level = function(self, new_value) + self:get_children_by_id('txt')[1]:set_text(new_value) + local new_value_num = tonumber(new_value) + local volume_icon_name = '' + if (new_value_num >= 0 and new_value_num < 33) then + volume_icon_name="audio-volume-low-symbolic" + elseif (new_value_num < 66) then + volume_icon_name="audio-volume-medium-symbolic" + else + volume_icon_name="audio-volume-high-symbolic" + end + self:get_children_by_id('icon')[1]:set_image(WIDGET_DIR .. volume_icon_name .. '.svg') + end, + mute = function(self) self:get_children_by_id('icon')[1]:set_image(WIDGET_DIR .. 'audio-volume-muted-symbolic.svg') end, + unmute = function() end, + + } + +end + + +return widget \ No newline at end of file diff --git a/experiments/volume/widgets/icon-widget.lua b/experiments/volume/widgets/icon-widget.lua new file mode 100644 index 0000000..6725e6d --- /dev/null +++ b/experiments/volume/widgets/icon-widget.lua @@ -0,0 +1,35 @@ +local wibox = require("wibox") + +local widget = {} + +local WIDGET_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/experiments/volume/icons/' + +function widget.get_widget() + + return wibox.widget { + { + id = "icon", + resize = false, + widget = wibox.widget.imagebox, + }, + valign = 'center', + layout = wibox.container.place, + set_volume_level = function(self, new_value) + local new_value_num = tonumber(new_value) + local volume_icon_name = '' + if (new_value_num >= 0 and new_value_num < 33) then + volume_icon_name="audio-volume-low-symbolic" + elseif (new_value_num < 66) then + volume_icon_name="audio-volume-medium-symbolic" + else + volume_icon_name="audio-volume-high-symbolic" + end + self:get_children_by_id('icon')[1]:set_image(WIDGET_DIR .. volume_icon_name .. '.svg') + end, + mute = function(self) self:get_children_by_id('icon')[1]:set_image(WIDGET_DIR .. 'audio-volume-muted-symbolic.svg') end, + unmute = function() end, + } + +end + +return widget \ No newline at end of file -- cgit v1.2.3