From cb5fbb5a4874655a6e6d36d86fefa20c89bc3541 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Tue, 22 Mar 2022 01:00:39 +0400 Subject: [PATCH] Added debug info to windows --- core/titlebar.lua | 7 + themes/carbon/icons/warning.svg | 120 ++++++++++++++++++ themes/icons.lua | 2 + widgets/client-volume.lua | 110 ++++++++++++++++ .../{window_debug.lua => window-debug.lua} | 12 +- 5 files changed, 245 insertions(+), 6 deletions(-) create mode 100644 themes/carbon/icons/warning.svg create mode 100644 widgets/client-volume.lua rename widgets/{window_debug.lua => window-debug.lua} (89%) diff --git a/core/titlebar.lua b/core/titlebar.lua index e8bc1b9..ed185f2 100644 --- a/core/titlebar.lua +++ b/core/titlebar.lua @@ -69,6 +69,13 @@ local menu_widget = menu({ function() awful.spawn("kill -s KILL "..tostring(c.pid)) end + }, + { "Debug info", + { + before = { + require("widgets.window-debug")() + } + } } }, vertical = true diff --git a/themes/carbon/icons/warning.svg b/themes/carbon/icons/warning.svg new file mode 100644 index 0000000..85ed7e4 --- /dev/null +++ b/themes/carbon/icons/warning.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + ! + + + + + + + + + + diff --git a/themes/icons.lua b/themes/icons.lua index 260b077..be002a3 100644 --- a/themes/icons.lua +++ b/themes/icons.lua @@ -49,4 +49,6 @@ beautiful.mailbox_icon = gears.color.recolor_image(beautiful.icon_dir.."mail.svg beautiful.username_logout_icon = gears.color.recolor_image(beautiful.icon_dir.."system-log-out-symbolic.svg",beautiful.fg_normal) beautiful.drawer_open_icon = gears.color.recolor_image(beautiful.icon_dir.."drawer-open.svg",beautiful.fg_normal) beautiful.drawer_closed_icon = gears.color.recolor_image(beautiful.icon_dir.."drawer-closed.svg",beautiful.fg_normal) +-- Generic icons +beautiful.warning_icon = gears.color.recolor_image(beautiful.icon_dir.."warning.svg",beautiful.fg_normal) diff --git a/widgets/client-volume.lua b/widgets/client-volume.lua new file mode 100644 index 0000000..12e8669 --- /dev/null +++ b/widgets/client-volume.lua @@ -0,0 +1,110 @@ +local awful = require("awful") +local gears = require("gears") +local wibox = require("wibox") +local awmtk = require("awmtk") + +return function(args) + local style = awmtk.style(awmtk.defaults, args.style or {},"client_volume_") + local device = args.device or "default" + local icons = args.icons or { + high = style.client_volume_icon_high, + medium = style.client_volume_icon_medium, + low = style.client_volume_icon_low, + muted = style.client_volume_icon_muted, + warn = style.client_volume_warning_icon + } + local function get_icon(percent) + if percent >= 66 then + return icons.high + elseif percent >= 33 then + return icons.medium + elseif percent > 0 then + return icons.low + else + return icons.muted + end + end + local commands = args.commands or { + get_master = "amixer -D "..device.." sget Master", + set = "amixer -q -D "..device.." sset ", + get = "amixer -D "..device.." sget " + } + local list = { + layout = wibox.layout.fixed.horizontal + } + for k,v in pairs(controls) do + local widget = wibox.widget({ + { + widget = wibox.widget.textbox, + markup = v, + ellipsize = "end", + font = style.volume_font + }, + { + { + widget = wibox.widget.slider, + id = "widget_slider", + handle_width = style.volume_handle_width or 6, + bar_height = style.volumer_bar_width or 5, + bar_color = style.volume_bar_color or "#55CC60", + bar_shape = style.bar_shape, + handler_shape = style.handle_shape, + value = 100, + }, + widget = wibox.container.rotate, + direction = "east" + }, + layout = wibox.layout.fixed.vertical, + spacing = style.volume_container_spacing_horizontal, + forced_width = style.volume_slider_width or 40, + forced_height = style.volume_slider_height or 120 + }) + local slider = widget:get_children_by_id("widget_slider")[1] + awful.spawn.easy_async_with_shell(commands.get..v,function(out) + local volume_percent = out:match("%[(%d+)%%%]") or "" + volume_percent = tonumber(volume_percent) + if not volume_percent then + return + end + slider.value = volume_percent + end) + slider:connect_signal("widget::redraw_needed",function() + awful.spawn(commands.set..v.." "..slider.value.."%") + end) + table.insert(list,widget) + end + local tweaker_popup = awful.popup(style.container(list,{ + visible = false, + ontop = true + })) + local icon = style.icon({ + widget = wibox.widget.imagebox, + image = icons.muted, + id = "widget_icon" + },{},{ + function() + if mouse.current_widget_geometry and (not tweaker_popup.visible) then + tweaker_popup:move_next_to(mouse.current_widget_geometry) + tweaker_popup.visible = true + else + tweaker_popup.visible = false + end + end + }) + gears.timer { + autostart = true, + timeout = 0.5, + call_now = true, + callback = function() + awful.spawn.easy_async_with_shell(commands.get_master, function(out) + local volume_percent = out:match("%[(%d+)%%%]") or "" + volume_percent = tonumber(volume_percent) + if not volume_percent then + return + end + icon:get_children_by_id("widget_icon")[1].image = get_icon(volume_percent) + end) + end + } + return icon +end diff --git a/widgets/window_debug.lua b/widgets/window-debug.lua similarity index 89% rename from widgets/window_debug.lua rename to widgets/window-debug.lua index 3d7eb81..759477e 100644 --- a/widgets/window_debug.lua +++ b/widgets/window-debug.lua @@ -14,8 +14,8 @@ local function generate_text(c) end return markup end -return function(c) - local widget = { +return function() + local widget = wibox.widget { { widget = wibox.widget.textbox, markup = "", @@ -27,12 +27,9 @@ return function(c) max_size = 300, speed = 100 } - widget[1].markup = generate_text(c) - widget = wibox.widget(widget) - widget:pause() widget:connect_signal("button::press",function(self,lx,ly,button) if button == 1 then - widget:get_children_by_id("text")[1].markup = generate_text(c) + widget:get_children_by_id("text")[1].markup = generate_text(client.focus) end end) widget:connect_signal("mouse::enter",function() @@ -41,6 +38,9 @@ return function(c) widget:connect_signal("mouse::leave",function() widget:continue() end) + client.connect_signal("focus",function() + widget:get_children_by_id("text")[1].markup = generate_text(client.focus) + end) return widget end