diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pavolctld.lua | 15 | ||||
-rw-r--r-- | lib/wiboxtooltip.lua | 53 |
2 files changed, 65 insertions, 3 deletions
diff --git a/lib/pavolctld.lua b/lib/pavolctld.lua index b6b6237..42babbe 100644 --- a/lib/pavolctld.lua +++ b/lib/pavolctld.lua @@ -10,6 +10,15 @@ local Gio = lgi.Gio -- start subprocess local p = Gio.Subprocess.new({ "pavolctld" }, Gio.SubprocessFlags.STDIN_PIPE + Gio.SubprocessFlags.STDOUT_PIPE) +if p == nil then + -- TODO see if error should be handled another way + naughty.notify({ + preset = naughty.config.presets.critical, + title = "pavolctld error", + text = "pavolctld could not be loaded", + }) + return false +end local stdout = p:get_stdout_pipe() local stdin = p:get_stdin_pipe() @@ -26,7 +35,7 @@ function sinks.get(i) sinks.sinks[i] = { vol = 0, db = 0.0, - mute = 0, + mute = false, name = "", desc = "", } @@ -35,7 +44,7 @@ function sinks.get(i) end -- return table -local pavolctld = { _cb = {}, sinks = sinks } +local pavolctld = { _cb = {}, sinks = sinks, max_volume = 150 } -- callbacks function pavolctld.set_volume_change_callback(cb) pavolctld._cb['v'] = cb end @@ -57,7 +66,7 @@ awful.spawn.read_lines(stdout, function(s) local sink = sinks.get(i) sink.vol = tonumber(v()) sink.db = tonumber(v()) - sink.mute = tonumber(v()) + sink.mute = v() == "1" -- sink description change elseif cmd == 's' then local v = parse_csv(s:sub(2)) diff --git a/lib/wiboxtooltip.lua b/lib/wiboxtooltip.lua new file mode 100644 index 0000000..be56a1f --- /dev/null +++ b/lib/wiboxtooltip.lua @@ -0,0 +1,53 @@ +local awful = require("awful") +local wibox = require("wibox") +local beautiful = require("beautiful") +local gears = require("gears") + +-- TODO more args +-- TODO use tooltip theme vars +function create_wibox_tooltip(parent, widget) + local p = { + parent = parent, + popup = awful.popup { + widget = wibox.container.margin ( + widget, + beautiful.margin_leftright, beautiful.margin_leftright, + beautiful.margin_topbottom, beautiful.margin_topbottom + ), + ontop = true, + visible = false, + preferred_positions = "bottom", + preferred_anchors = "middle", + } + } + -- hover timer + p.timer = gears.timer { + timeout = 1, + single_shot = true, + callback = function() + p.popup:move_next_to(mouse.current_widget_geometry) + p.popup.visible = true + end, + } + -- signal functions + p._mouse_enter = function() + p.timer:again() + end + p._mouse_leave = function() + p.timer:stop() + p.popup.visible = false + end + p.connect_signals = function() + p.parent:connect_signal("mouse::enter", p._mouse_enter) + p.parent:connect_signal("mouse::leave", p._mouse_leave) + end + p.disconnect_signals = function() + p.parent:disconnect_signal("mouse::enter", p._mouse_enter) + p.parent:disconnect_signal("mouse::leave", p._mouse_leave) + end + + p.connect_signals() + return p +end + +return create_wibox_tooltip |