Skip to content

Commit

Permalink
Merge pull request #416 from Luka5W/master
Browse files Browse the repository at this point in the history
volume-widget: added arguments, fixed colors for light themes
  • Loading branch information
streetturtle authored Nov 19, 2023
2 parents d98fb49 + 7ebd572 commit c0abbbf
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 26 deletions.
42 changes: 28 additions & 14 deletions volume-widget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ s.mytasklist, -- Middle widget
},
```

Note that widget uses following command the get the current volume: `amixer -D pulse sget Master`, so please make sure that it works for you, otherwise you need to set parameter `device = 'default'`.
Note that the widget uses following command to get the current volume: `amixer -c 1 -D pulse sget Master`, so please make sure that it works for you, otherwise you need to set some parameters by entering this command in the terminal:

Command output:
- Some data of a mixer: Override all parameters you've changed
- Error `Invalid card number`: Change parameter `-c`/ `card`
- Error `Mixer attach pulse error: No such file or directory`: Change parameter `-D`/ `device`
- Error `Unable to find simple control 'Master',0`: Change parameter `mixctrl`

Note: `amixer[ -c ...][ -D ...]` returns a list of Mixers for the selected card/ device. omitting `-D` falls back to `default`.

### Shortcuts

Expand All @@ -54,20 +62,26 @@ It is possible to customize the widget by providing a table with all or some of

### Generic parameter

| Name | Default | Description |
|---|---|---|
| `mixer_cmd` | `pavucontrol` | command to run on middle click (e.g. a mixer program) |
| `step` | 5 | How much the volume is raised or lowered at once (in %) |
| `widget_type`| `icon_and_text`| Widget type, one of `horizontal_bar`, `vertical_bar`, `icon`, `icon_and_text`, `arc` |
| `device` | `pulse` | Select the device name to control |
| Name | Default | Description |
|---------------|-----------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `mixer_cmd` | `pavucontrol` | command to run on middle click (e.g. a mixer program) |
| `toggle_cmd` | *nil* | Use custom command instead of `amixer ... toggle` because [amixer's unmute option seems to be broken](https://superuser.com/a/822085) |
| `step` | 5 | How much the volume is raised or lowered at once (in %) |
| `widget_type` | `icon_and_text` | Widget type, one of `horizontal_bar`, `vertical_bar`, `icon`, `icon_and_text`, `arc` |
| `card` | 1 | Select the card name to control |
| `device` | `pulse` | Select the device name to control |
| `mixctrl` | `Master` | Select the mixer name to control |
| `value_type` | `-M` | Select how the volume is increased/ decreased (intended for `-M`/ `-R` parameters). See `man amixer` for additional info |

Note: If unmuting or toggling using the default amixer command does not work, this command may work: `pactl set-sink-mute [card] toggle`

Depends on the chosen widget type add parameters from the corresponding section below:

#### `icon` parameters

| Name | Default | Description |
|---|---|---|
| `icon_dir`| `./icons`| Path to the folder with icons |
| Name | Default | Description |
|------------|----------------------|-----------------------------------------------|
| `icon_dir` | `[widget_dir]/icons` | Path to the folder with icons (absolute path) |

_Note:_ if you are changing icons, the folder should contain following .svg images:
- audio-volume-high-symbolic
Expand All @@ -77,10 +91,10 @@ _Note:_ if you are changing icons, the folder should contain following .svg imag

#### `icon_and_text` parameters

| Name | Default | Description |
|---|---|---|
| `icon_dir`| `./icons`| Path to the folder with icons |
| `font` | `beautiful.font` | Font name and size, like `Play 12` |
| Name | Default | Description |
|------------|----------------------|-----------------------------------------------|
| `icon_dir` | `[widget_dir]/icons` | Path to the folder with icons (absolute path) |
| `font` | `beautiful.font` | Font name and size, like `Play 12` |

#### `arc` parameters

Expand Down
45 changes: 33 additions & 12 deletions volume-widget/volume.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ local utils = require("awesome-wm-widgets.volume-widget.utils")


local LIST_DEVICES_CMD = [[sh -c "pacmd list-sinks; pacmd list-sources"]]
local function GET_VOLUME_CMD(device) return 'amixer -D ' .. device .. ' sget Master' end
local function INC_VOLUME_CMD(device, step) return 'amixer -D ' .. device .. ' sset Master ' .. step .. '%+' end
local function DEC_VOLUME_CMD(device, step) return 'amixer -D ' .. device .. ' sset Master ' .. step .. '%-' end
local function TOG_VOLUME_CMD(device) return 'amixer -D ' .. device .. ' sset Master toggle' end
local function GET_VOLUME_CMD(card, device, mixctrl, value_type) return 'amixer -c '..card..' -D '..device..' sget '..mixctrl..' '..value_type end
local function INC_VOLUME_CMD(card, device, mixctrl, value_type, step) return 'amixer -c '..card..' -D '..device..' sset '..mixctrl..' '..value_type..' '..step..'%+' end
local function DEC_VOLUME_CMD(card, device, mixctrl, value_type, step) return 'amixer -c '..card..' -D '..device..' sset '..mixctrl..' '..value_type..' '..step..'%-' end
local function TOG_VOLUME_CMD(card, device, mixctrl) return 'amixer -c '..card..' -D '..device..' sset '..mixctrl..' toggle' end


local widget_types = {
Expand All @@ -36,6 +36,7 @@ local rows = { layout = wibox.layout.fixed.vertical }

local popup = awful.popup{
bg = beautiful.bg_normal,
fg = beautiful.fg_normal,
ontop = true,
visible = false,
shape = gears.shape.rounded_rect,
Expand All @@ -60,12 +61,12 @@ local function build_rows(devices, on_checkbox_click, device_type)

local checkbox = wibox.widget {
checked = device.is_default,
color = beautiful.bg_normal,
color = beautiful.fg_normal,
paddings = 2,
shape = gears.shape.circle,
forced_width = 20,
forced_height = 20,
check_color = beautiful.fg_urgent,
check_color = beautiful.fg_normal,
widget = wibox.widget.checkbox
}

Expand Down Expand Up @@ -99,11 +100,22 @@ local function build_rows(devices, on_checkbox_click, device_type)
layout = wibox.container.margin
},
bg = beautiful.bg_normal,
fg = beautiful.fg_normal,
widget = wibox.container.background
}

row:connect_signal("mouse::enter", function(c) c:set_bg(beautiful.bg_focus) end)
row:connect_signal("mouse::leave", function(c) c:set_bg(beautiful.bg_normal) end)
row:connect_signal("mouse::enter", function(c)
checkbox:set_color(beautiful.fg_focus)
checkbox:set_check_color(beautiful.fg_focus)
c:set_fg(beautiful.fg_focus)
c:set_bg(beautiful.bg_focus)
end)
row:connect_signal("mouse::leave", function(c)
checkbox:set_color(beautiful.fg_normal)
checkbox:set_check_color(beautiful.fg_normal)
c:set_fg(beautiful.fg_normal)
c:set_bg(beautiful.bg_normal)
end)

local old_cursor, old_wibox
row:connect_signal("mouse::enter", function()
Expand Down Expand Up @@ -138,6 +150,7 @@ local function build_header_row(text)
widget = wibox.widget.textbox
},
bg = beautiful.bg_normal,
fg = beautiful.fg_normal,
widget = wibox.container.background
}
end
Expand Down Expand Up @@ -167,7 +180,11 @@ local function worker(user_args)
local widget_type = args.widget_type
local refresh_rate = args.refresh_rate or 1
local step = args.step or 5
local card = args.card or 1
local device = args.device or 'pulse'
local mixctrl = args.mixctrl or 'Master'
local value_type = args.value_type or '-M'
local toggle_cmd = args.toggle_cmd or nil

if widget_types[widget_type] == nil then
volume.widget = widget_types['icon_and_text'].get_widget(args.icon_and_text_args)
Expand All @@ -186,15 +203,19 @@ local function worker(user_args)
end

function volume:inc(s)
spawn.easy_async(INC_VOLUME_CMD(device, s or step), function(stdout) update_graphic(volume.widget, stdout) end)
spawn.easy_async(INC_VOLUME_CMD(card, device, mixctrl, value_type, s or step), function(stdout) update_graphic(volume.widget, stdout) end)
end

function volume:dec(s)
spawn.easy_async(DEC_VOLUME_CMD(device, s or step), function(stdout) update_graphic(volume.widget, stdout) end)
spawn.easy_async(DEC_VOLUME_CMD(card, device, mixctrl, value_type, s or step), function(stdout) update_graphic(volume.widget, stdout) end)
end

function volume:toggle()
spawn.easy_async(TOG_VOLUME_CMD(device), function(stdout) update_graphic(volume.widget, stdout) end)
if toggle_cmd == nil then
spawn.easy_async(TOG_VOLUME_CMD(card, device, mixctrl), function(stdout) update_graphic(volume.widget, stdout) end)
else
spawn.easy_async(toggle_cmd, function(_stdout) spawn.easy_async(GET_VOLUME_CMD(card, device, mixctrl, value_type), function(stdout) update_graphic(volume.widget, stdout) end) end)
end
end

function volume:mixer()
Expand All @@ -220,7 +241,7 @@ local function worker(user_args)
)
)

watch(GET_VOLUME_CMD(device), refresh_rate, update_graphic, volume.widget)
watch(GET_VOLUME_CMD(card, device, mixctrl, value_type), refresh_rate, update_graphic, volume.widget)

return volume.widget
end
Expand Down

0 comments on commit c0abbbf

Please sign in to comment.