summaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/classiclayouts.lua37
-rw-r--r--widgets/pavolctld.lua134
-rw-r--r--widgets/tasklist.lua80
-rw-r--r--widgets/volumedropdown.lua195
4 files changed, 308 insertions, 138 deletions
diff --git a/widgets/classiclayouts.lua b/widgets/classiclayouts.lua
index 515e66c..994f520 100644
--- a/widgets/classiclayouts.lua
+++ b/widgets/classiclayouts.lua
@@ -1,6 +1,8 @@
+local awful = require("awful")
local wibox = require("wibox")
local layout = require("awful.layout")
local beautiful = require("beautiful")
+local naughty = require("naughty")
local screen_widgets = {} -- need one widget per screen
@@ -32,21 +34,22 @@ function update(screen_index)
-- create widget if not existing
if w == nil then
- screen_widgets[s] = { widget = wibox.widget.textbox(), layout = l }
- if beautiful.font_mono then
- screen_widgets[s].widget.font = beautiful.font_mono
- end
+ screen_widgets[s] = {
+ widget = wibox.widget {
+ font = beautiful.layoutbox_font or beautiful.font_mono or "monospace 10",
+ widget = wibox.widget.textbox,
+ },
+ layout = l,
+ tooltip = awful.tooltip { delay_show = 1 },
+ }
w = screen_widgets[s]
- --w._layoutbox_tooltip = tooltip {objects = {w}, delay_show = 1}
-
- -- skip if no change
- elseif w.layout == l then
- return
+ w.tooltip:add_to_object(w.widget)
end
+ w.layout = l
-- set widget
local name = layout.getname(l)
- --w._layoutbox_tooltip:set_text(name)
+ w.tooltip:set_text(name)
local wtxt = layout_icons[name]
if type(wtxt) == 'function' then
wtxt = wtxt(s)
@@ -65,14 +68,18 @@ function update_screens()
end
end
-function update_current_tag(t)
+function update_tag(t)
update(t.screen)
end
-tag.connect_signal("property::selected", update_current_tag)
-tag.connect_signal("property::layout", update_current_tag)
-tag.connect_signal("tagged", update_current_tag) -- max
-tag.connect_signal("untagged", update_current_tag) -- max
+function update_client(c)
+ update(c.screen)
+end
+
+tag.connect_signal("property::selected", update_tag)
+tag.connect_signal("property::layout", update_tag)
+tag.connect_signal("tagged", update_client) -- max
+tag.connect_signal("untagged", update_client) -- max
tag.connect_signal("property::screen", update_screens)
return update
diff --git a/widgets/pavolctld.lua b/widgets/pavolctld.lua
index 3697465..6f257b5 100644
--- a/widgets/pavolctld.lua
+++ b/widgets/pavolctld.lua
@@ -1,44 +1,23 @@
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")
+local volume_dropdown = require("widgets.volumedropdown")
+
+-- ensure pavolctld loaded
+if not pavolctld then return wibox.widget.textbox("err") end
-- 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.dropdown = volume_dropdown
-- 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")
+ widget.dropdown.set_volume(pavolctld.sinks.default.vol, pavolctld.sinks.default.mute)
+ widget.dropdown.dbmeter:set_text(pavolctld.sinks.default.db .. " dB")
end)
pavolctld.set_sink_change_callback(function()
@@ -46,102 +25,11 @@ pavolctld.set_sink_change_callback(function()
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()
+ widget.dropdown.set_volume(pavolctld.sinks.default.vol, pavolctld.sinks.default.mute)
+ widget.dropdown.dbmeter:set_text(pavolctld.sinks.default.db .. " dB")
+ widget.dropdown.defsink:set_text(pavolctld.sinks.default.desc)
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
diff --git a/widgets/tasklist.lua b/widgets/tasklist.lua
new file mode 100644
index 0000000..76616bf
--- /dev/null
+++ b/widgets/tasklist.lua
@@ -0,0 +1,80 @@
+local awful = require("awful")
+local wibox = require("wibox")
+local wibox_tooltip = require("lib.wiboxtooltip")
+local beautiful = require("beautiful")
+
+local separator = { widget = wibox.widget.separator, opacity = 0 }
+
+function create_tasklist_widget(s, filter, font_focus)
+ return awful.widget.tasklist {
+ screen = s,
+ filter = filter,
+ buttons = tasklist_buttons,
+ widget_template = {
+ id = "text_role",
+ widget = wibox.widget.textbox,
+ align = "center",
+ },
+ style = {
+ font_focus = font_focus,
+ },
+ }
+end
+
+function create_tasklist(s)
+ -- allow for different styles for different layouts
+ local tasklist_focused = create_tasklist_widget(s, awful.widget.tasklist.filter.focused, beautiful.tasklist_font)
+ local tasklist_currenttags = create_tasklist_widget(s, awful.widget.tasklist.filter.currenttags, beautiful.tasklist_font_focus)
+
+ local change_layout = function(layout)
+ local max = layout == awful.layout.suit.max
+ tasklist_currenttags:set_visible(max)
+ tasklist_focused:set_visible(not max)
+ end
+ change_layout(s.selected_tag.layout)
+
+ -- setup widgets
+ local tasklist = wibox.widget {
+ layout = wibox.layout.stack,
+ tasklist_currenttags,
+ tasklist_focused,
+ }
+
+ local popup = wibox_tooltip(tasklist, awful.widget.tasklist {
+ screen = s,
+ filter = awful.widget.tasklist.filter.currenttags,
+ layout = {
+ layout = wibox.layout.fixed.vertical,
+ },
+ widget_template = {
+ id = "text_role",
+ widget = wibox.widget.textbox,
+ align = "center",
+ },
+ style = {
+ font_focus = beautiful.font_mono_bold,
+ },
+ })
+
+ -- setup signals to change tasklist filter on layout changes
+ local change_layout_from_tag = function(t)
+ if t.screen ~= s then return end
+ change_layout(t.layout)
+ end
+ tag.connect_signal("property::layout", change_layout_from_tag)
+ tag.connect_signal("property::selected", change_layout_from_tag)
+ tag.connect_signal("tagged", change_layout_from_tag)
+ tag.connect_signal("untagged", change_layout_from_tag)
+ tag.connect_signal("property::screen", change_layout_from_tag)
+
+ -- return widget
+ return wibox.widget {
+ layout = wibox.layout.align.horizontal,
+ expand = "outside",
+ separator,
+ tasklist,
+ separator,
+ }
+end
+
+return create_tasklist
diff --git a/widgets/volumedropdown.lua b/widgets/volumedropdown.lua
new file mode 100644
index 0000000..dad20eb
--- /dev/null
+++ b/widgets/volumedropdown.lua
@@ -0,0 +1,195 @@
+local awful = require("awful")
+local wibox = require("wibox")
+local beautiful = require("beautiful")
+local apply_dpi = beautiful.xresources.apply_dpi
+local pavolctld = require("lib.pavolctld")
+
+-- return table
+local widget = {}
+
+widget.dbmeter = wibox.widget.textbox("-999.99 dB") -- max width text
+local dbmeter_maxwidth, _ = widget.dbmeter:get_preferred_size_at_dpi(beautiful.xresources.get_dpi()) -- max width, TODO per screen dpi
+dbmeter_maxwidth = dbmeter_maxwidth * 1.5 -- ???
+
+local slider = wibox.widget {
+ bar_height = 0,
+ widget = wibox.widget.slider,
+ maximum = pavolctld.max_volume,
+}
+local progressbar = wibox.widget {
+ max_value = pavolctld.max_volume,
+ shape = beautiful.slider_bar_shape,
+ bg = beautiful.slider_handle_color,
+ widget = wibox.widget.progressbar,
+}
+widget.vslider = wibox.widget {
+ {
+ {
+ progressbar,
+ height = apply_dpi(3),
+ widget = wibox.container.constraint
+ },
+ halign = "center",
+ widget = wibox.container.place,
+ },
+ slider,
+ layout = wibox.layout.stack,
+}
+
+-- scrollbox for default sink select
+widget.defsink = wibox.widget.textbox()
+local default_sink_scrollbox = wibox.widget {
+ widget.defsink,
+ step_function = wibox.container.scroll.step_functions.linear_increase,
+ speed = apply_dpi(15),
+ extra_space = apply_dpi(25), -- space between repetition
+ pause = true, -- start paused
+ widget = wibox.container.scroll.horizontal,
+}
+
+local muted = wibox.widget {
+ color = "#222222",
+ check_color = beautiful.border_focus,
+ forced_width = apply_dpi(20),
+ widget = wibox.widget.checkbox,
+}
+
+-- widget dropdown
+local volume_dropdown = wibox.widget {
+ {
+ {
+ {
+ default_sink_scrollbox,
+ margins = beautiful.margin_topbottom,
+ widget = wibox.container.margin,
+ },
+ bg = "#333333",
+ widget = wibox.container.background,
+ },
+ margins = beautiful.border_width,
+ color = "#222222",
+ widget = wibox.container.margin,
+ },
+ {
+ {
+ {
+ {
+ {
+ text = "Mute:",
+ widget = wibox.widget.textbox,
+ },
+ left = apply_dpi(5),
+ right = apply_dpi(5),
+ widget = wibox.container.margin,
+ },
+ fill_vertical = true,
+ widget = wibox.container.place,
+ },
+ {
+ muted,
+ fill_vertical = true,
+ widget = wibox.container.place,
+ },
+ layout = wibox.layout.align.horizontal,
+ },
+ fill_vertical = true,
+ widget = wibox.container.place,
+ },
+ widget.vslider,
+ {
+ widget.dbmeter,
+ halign = "right",
+ forced_width = dbmeter_maxwidth,
+ widget = wibox.container.place,
+ },
+ forced_num_cols = 2,
+ forced_num_rows = 2,
+ homogeneous = false,
+ expand = true,
+ forced_width = apply_dpi(300),
+ forced_height = apply_dpi(60),
+ layout = wibox.layout.grid,
+}
+widget.dropdown = awful.popup {
+ widget = {
+ volume_dropdown,
+ left = beautiful.margin_leftright,
+ right = beautiful.margin_leftright,
+ top = beautiful.margin_topbottom,
+ bottom = beautiful.margin_topbottom,
+ widget = wibox.container.margin,
+ },
+ border_color = beautiful.border_normal,
+ border_width = beautiful.border_width,
+ ontop = true,
+ hide_on_right_click = true,
+ preferred_positions = "bottom",
+ preferred_anchors = "back",
+ visible = false,
+}
+
+function widget.set_volume(vol, mute)
+ progressbar:set_value(vol)
+ muted.checked = mute
+ if vol == slider.value then return end
+ slider.value = vol
+ if widget.dropdown.visible then
+ slider:emit_signal("widget::redraw_needed")
+ end
+end
+
+-- slider
+slider:buttons(volume_buttons)
+slider:connect_signal("property::value", function()
+ if pavolctld.sinks.default.vol == slider.value then return end
+ widget.dropdown.visible = true -- make sure widget isn't hidden
+ pavolctld.volume_set(slider.value)
+end)
+
+-- 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)
+
+-- change sink
+default_sink_scrollbox:connect_signal("button::press", function()
+ widget.dropdown.visible = true -- make sure widget isn't hidden
+
+ local g = mouse.current_widget_geometry -- relative to widget.dropdown
+ local menugeo = {
+ x = widget.dropdown.x + g.x - beautiful.margin_topbottom,
+ y = widget.dropdown.y + g.y + g.height + beautiful.margin_topbottom + (beautiful.border_width * 2),
+ width = g.width + beautiful.margin_topbottom * 2,
+ }
+ local menuopts = { items = {}, theme = menugeo }
+ for i, s in pairs(pavolctld.sinks.sinks) do
+ table.insert(menuopts.items, {
+ s.desc,
+ function() pavolctld.default_sink_set(i) end
+ })
+ end
+
+ if widget.menu then widget.menu:hide() end
+ widget.menu = awful.menu(menuopts) -- old menu dereferenced, should be cleaned up by gc
+ widget.menu:show({ coords = menugeo })
+end)
+
+widget.dropdown:connect_signal("property::visible", function()
+ if widget.menu then
+ widget.menu:hide()
+ widget.menu = nil
+ end
+end)
+
+-- mute button
+muted:connect_signal("button::press", function()
+ widget.dropdown.visible = true -- make sure widget isn't hidden
+ pavolctld.mute_toggle()
+end)
+
+return widget