summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--secrets.lua16
-rw-r--r--volume-widget/README.md25
-rw-r--r--volume-widget/volume.lua20
-rw-r--r--weather-widget/weather.lua41
4 files changed, 90 insertions, 12 deletions
diff --git a/secrets.lua b/secrets.lua
index 19f35b8..f387a20 100644
--- a/secrets.lua
+++ b/secrets.lua
@@ -5,14 +5,28 @@
-- @copyright 2019 Pavel Makhov
--------------------------------------------
+local function getenv_bool(var_name, default_val)
+ val = os.getenv(var_name)
+ if val ~= nil then
+ return val:lower() == 'true'
+ else
+ return default_val
+ end
+end
+
local secrets = {
+ -- See volume-widget/README.md
+ volume_audio_controller = os.getenv('AWW_VOLUME_CONTROLLER') or 'pulse', -- 'pulse' or 'alsa_only'
+
-- Yandex.Translate API key - https://tech.yandex.com/translate/
translate_widget_api_key = os.getenv('AWW_TRANSLATE_API_KEY') or 'API_KEY',
-- OpenWeatherMap API key - https://openweathermap.org/appid
weather_widget_api_key = os.getenv('AWW_WEATHER_API_KEY') or 'API_KEY',
weather_widget_city = os.getenv('AWW_WEATHER_CITY') or 'Montreal,ca',
- weather_widget_units = os.getenv('AWW_WEATHER_UNITS') or 'metric' -- for celsius, or 'imperial' for fahrenheit
+ weather_widget_units = os.getenv('AWW_WEATHER_UNITS') or 'metric', -- for celsius, or 'imperial' for fahrenheit
+ weather_both_temp_units_widget = getenv_bool('AWW_WEATHER_BOTH_UNITS_WIDGET', false), -- on widget, if true shows "22 C (72 F)", instead of only "22 C"
+ weather_both_temp_units_popup = getenv_bool('AWW_WEATHER_BOTH_UNITS_POPUP', true) -- in the popup, if true shows "22.3 C (72.2 F)" instead of only "22.3 C"
}
return secrets
diff --git a/volume-widget/README.md b/volume-widget/README.md
index 118abc6..494be24 100644
--- a/volume-widget/README.md
+++ b/volume-widget/README.md
@@ -31,6 +31,31 @@ s.mytasklist, -- Middle widget
sudo sed -i 's/bebebe/ed4737/g' ./audio-volume-muted-symbolic_red.svg
```
+### Pulse or ALSA only
+
+Try running this command:
+
+```amixer -D pulse sget Master```
+
+If that prints something like this, then the default setting of 'pulse' is probably fine:
+```
+Simple mixer control 'Master',0
+ Capabilities: pvolume pvolume-joined pswitch pswitch-joined
+ Playback channels: Mono
+ Limits: Playback 0 - 64
+ Mono: Playback 64 [100%] [0.00dB] [on]
+
+```
+
+If it prints something like this:
+```
+$ amixer -D pulse sget Master
+ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
+
+amixer: Mixer attach pulse error: Connection refused
+```
+then try setting the environment variable `AWW_VOLUME_CONTROLLER` to `alsa_only`.
+
## Control volume
To mute/unmute click on the widget. To increase/decrease volume scroll up or down when mouse cursor is over the widget.
diff --git a/volume-widget/volume.lua b/volume-widget/volume.lua
index 8124bcf..fe7ff2c 100644
--- a/volume-widget/volume.lua
+++ b/volume-widget/volume.lua
@@ -13,12 +13,22 @@ local wibox = require("wibox")
local watch = require("awful.widget.watch")
local spawn = require("awful.spawn")
+local secrets = require("awesome-wm-widgets.secrets")
+
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
-local GET_VOLUME_CMD = 'amixer -D pulse sget Master'
-local INC_VOLUME_CMD = 'amixer -D pulse sset Master 5%+'
-local DEC_VOLUME_CMD = 'amixer -D pulse sset Master 5%-'
-local TOG_VOLUME_CMD = 'amixer -D pulse sset Master toggle'
+local device_arg
+if secrets.volume_audio_controller == 'pulse' then
+ device_arg = '-D pulse'
+else
+ device_arg = ''
+end
+
+local GET_VOLUME_CMD = 'amixer ' .. device_arg .. ' sget Master'
+local INC_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master 5%+'
+local DEC_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master 5%-'
+local TOG_VOLUME_CMD = 'amixer ' .. device_arg .. ' sset Master toggle'
+
local volume_widget = wibox.widget {
{
@@ -64,4 +74,4 @@ end)
watch(GET_VOLUME_CMD, 1, update_graphic, volume_widget)
-return volume_widget \ No newline at end of file
+return volume_widget
diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua
index 2d80947..d6693cf 100644
--- a/weather-widget/weather.lua
+++ b/weather-widget/weather.lua
@@ -98,9 +98,39 @@ local function to_direction(degrees)
return directions[math.floor((degrees % 360) / 22.5) + 1]
end
+-- Convert degrees Celsius to Fahrenheit
+local function celsius_to_fahrenheit(c)
+ return c*9/5+32
+end
+
+-- Convert degrees Fahrenheit to Celsius
+local function fahrenheit_to_celsius(f)
+ return (f-32)*5/9
+end
+
local weather_timer = gears.timer({ timeout = 60 })
local resp
+local function gen_temperature_str(temp, fmt_str, show_other_units)
+ local temp_str = string.format(fmt_str, temp)
+ local s = temp_str .. '°' .. (secrets.weather_widget_units == 'metric' and 'C' or 'F')
+
+ if (show_other_units) then
+ local temp_conv, units_conv
+ if (secrets.weather_widget_units == 'metric') then
+ temp_conv = celsius_to_fahrenheit(temp)
+ units_conv = 'F'
+ else
+ temp_conv = fahrenheit_to_celsius(temp)
+ units_conv = 'C'
+ end
+
+ local temp_conv_str = string.format(fmt_str, temp_conv)
+ s = s .. ' ' .. '('.. temp_conv_str .. '°' .. units_conv .. ')'
+ end
+ return s
+end
+
weather_timer:connect_signal("timeout", function ()
local resp_json = {}
local res, status = http.request{
@@ -132,9 +162,8 @@ weather_timer:connect_signal("timeout", function ()
elseif (resp_json ~= nil and resp_json ~= '') then
resp = json.decode(resp_json)
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]
- temp_widget:set_text(string.gsub(resp.main.temp, "%.%d+", "")
- .. '°'
- .. (secrets.weather_widget_units == 'metric' and 'C' or 'F'))
+ temp_widget:set_text(gen_temperature_str(resp.main.temp, '%.0f',
+ secrets.weather_both_temp_units_widget))
end
end)
weather_timer:start()
@@ -149,13 +178,13 @@ weather_widget:connect_signal("mouse::enter", function()
text =
'<big>' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')</big><br>' ..
'<b>Humidity:</b> ' .. resp.main.humidity .. '%<br>' ..
- '<b>Temperature:</b> ' .. resp.main.temp .. '°'
- .. (secrets.weather_widget_units == 'metric' and 'C' or 'F') .. '<br>' ..
+ '<b>Temperature:</b> ' .. gen_temperature_str(resp.main.temp, '%.1f',
+ secrets.weather_both_temp_units_popup) .. '<br>' ..
'<b>Pressure:</b> ' .. resp.main.pressure .. 'hPa<br>' ..
'<b>Clouds:</b> ' .. resp.clouds.all .. '%<br>' ..
'<b>Wind:</b> ' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')',
timeout = 5, hover_timeout = 10,
- width = 200
+ width = (secrets.weather_both_temp_units_popup == true and 210 or 200)
}
end)