旋转堆栈布局中的小部件

时间:2020-06-27 16:54:46

标签: lua widget awesome-wm

我正在尝试创建一个控件来控制屏幕亮度。

我有一个widget.interfaces表,其中包含接口名称(来自xrandr) 以下是我遇到问题的小部件:

  • 当我用鼠标右键单击时,子小部件没有变化。我怀疑右键单击事件传播到每个子小部件,并且我又回到了相同的文本显示
  • 当我使用mouse-grab更改滑块值时,真棒抱怨 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

0 个答案:

没有答案