我正在尝试创建一个控件来控制屏幕亮度。
我有一个widget.interfaces
表,其中包含接口名称(来自xrandr)
以下是我遇到问题的小部件:
mousegrabber already running
。我怀疑该事件正在再次传播... 不知道如何处理这些问题。
function widget.sliderBrightnessWidget()
--
local MAX = 100
local maxi = 2
local MIN = 0
local mini = .5
--
local leswidgets = wibox.widget({
forced_width = 150,
layout = wibox.layout.stack
})
--
for i, iface in ipairs(widget.interfaces) do
-- la barre
local slider = wibox.widget {
bar_shape = gears.shape.rounded_rect,
bar_height = 1,
bar_color = beautiful.border_color,
handle_shape = gears.shape.circle,
handle_color = fu.couleurBarre(beautiful.widget_sliderBrightness_handle_color_type, 100, MIN, MAX),
minimum = MIN,
maximum = MAX,
widget = wibox.widget.slider,
}
-- le texte
local sliderTexte = wibox.widget(
{
markup = "<span foreground='white'>" .. iface .. "</span>",
align = "center",
widget = wibox.widget.textbox
}
)
-- le widget complet
local unWidgetComplet = wibox.widget(
{
{
sliderTexte,
slider,
vertical_offset = 0,
layout = wibox.layout.stack
},
bg = beautiful.noir,
widget = wibox.container.background
}
)
-- callback changement de la barre
unWidgetComplet:connect_signal("property::value", function()
local v = tostring(mini + (slider.value * (maxi - mini) / MAX))
v = v:gsub(",",".")
local command="xrandr --output " .. iface .." --brightness " .. v
fu.commandeExecute(command)
slider.handle_color = fu.couleurBarre(beautiful.widget_sliderBrightness_handle_color_type, v, mini, maxi)
end)
-- callbak changement de widget
unWidgetComplet:buttons(
gears.table.join(
awful.button({}, 3,
function()
widget.activeIndex = 1 + widget.activeIndex%#widget.interfaces
leswidgets:raise(widget.activeIndex)
end
)
)
)
leswidgets:add(unWidgetComplet)
end
--
return leswidgets
end