summaryrefslogtreecommitdiff
path: root/widgets/pavolctld.lua
blob: 369746593729e570e9a227561bcf5ae0680ef20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful")
local menubar = require("menubar")
local pavolctld = require("lib.pavolctld")

-- return table
local widget = {}
widget.textbox = wibox.widget.textbox()
widget.dbmeter = wibox.widget.textbox()
widget.vslider = wibox.widget {
	{
		{
			{
				value = 50,
				max_value = 150,
				shape = beautiful.slider_bar_shape,
				bg = beautiful.slider_handle_color,
				widget = wibox.widget.progressbar,
			},
			height = 5,
			widget = wibox.container.constraint
		},
		halign = "center",
		widget = wibox.container.place,
	},
	{
		bar_height = 0,
		widget = wibox.widget.slider,
	},
	layout = wibox.layout.stack,
}
widget.defsink = wibox.widget.textbox()
widget.tooltip = awful.tooltip { objects = {widget.textbox}, delay_show = 1 }

-- widget callbacks
pavolctld.set_volume_change_callback(function()
	widget.vslider.value =  pavolctld.sinks.default.vol
	widget.textbox:set_text(pavolctld.sinks.default.vol)
	widget.dbmeter:set_text(pavolctld.sinks.default.db .. " dB")
end)

pavolctld.set_sink_change_callback(function()
	widget.tooltip:set_text(pavolctld.sinks.default.desc)
end)

pavolctld.set_default_sink_change_callback(function()
	widget.vslider.value =  pavolctld.sinks.default.vol
	widget.textbox:set_text(pavolctld.sinks.default.vol)
	widget.dbmeter:set_text(pavolctld.sinks.default.db .. " dB")
	widget.tooltip:set_text(pavolctld.sinks.default.desc)
	widget.defsink:set_text(pavolctld.sinks.default.desc)
end)

-- slider
widget.vslider.maximum = 150 -- max in pavolctld
widget.vslider:buttons(volume_buttons)
widget.vslider:connect_signal("property::value", function()
	if pavolctld.sinks.default.vol == widget.vslider.value then return end -- help prevent overloading daemon
	pavolctld.volume_set(widget.vslider.value)
end)

-- scrollbox for default sink select
local default_sink_scrollbox = wibox.widget {
	widget.defsink,
	step_function = wibox.container.scroll.step_functions.linear_increase,
	speed = 25,
	extra_space = 25, -- space between repetition
	pause = true, -- start paused
	widget = wibox.container.scroll.horizontal,
}

-- scroll when hovering
default_sink_scrollbox:connect_signal("mouse::enter", function()
	default_sink_scrollbox:continue()
end)

default_sink_scrollbox:connect_signal("mouse::leave", function()
	default_sink_scrollbox:pause()
	default_sink_scrollbox:reset_scrolling()
end)

-- widget dropdown
local volume_dropdown = wibox.widget {
	{
		{
			{
				default_sink_scrollbox,
				margins = 5,
				widget = wibox.container.margin,
			},
			bg = "#333333",
			widget = wibox.container.background,
		},
		margins = beautiful.border_width,
		color = "#222222",
		widget = wibox.container.margin,
	},
	{
		{
			text = "M",
			widget = wibox.widget.textbox,
		},
		{
			widget.vslider,
			left = 10,
			right = 10,
			widget = wibox.container.margin,
			layout = wibox.layout.stack,
		},
		{
			widget.dbmeter,
			forced_width = 125,
			halign = "right",
			widget = wibox.container.place,
		},
		layout = wibox.layout.align.horizontal,
	},
	forced_num_cols = 1,
	forced_num_rows = 2,
	expand          = true,
	forced_width = 500,
	forced_height = 100,
	layout = wibox.layout.grid,
}
widget.dropdown = awful.popup {
	widget = {
		volume_dropdown,
		margins = 15,
		widget = wibox.container.margin,
	},
	border_color = beautiful.border_focus,
	border_width = beautiful.border_width,
	shape        = gears.shape.rounded_rect,
	ontop        = true,
	hide_on_right_click = true,
	preferred_positions = "bottom",
	preferred_anchors   = 'back',
	visible = false,
	offset = { y = 5 },
}

widget.dropdown:bind_to_widget(widget.textbox)


return widget