0

I'm trying to create a widget to control screens brightness.

I have a widget.interfaces table containing interfaces names (from xrandr) ans below is the widget with which I have problems:

  • when I use mouse right-click, there's no changeof sub-widget. I suspect the right-click event is propogated to each sub-widget and I turn back to the same text display
  • when I use mouse-grab to change slider value, awesome complains about mousegrabber already running. I suspect the event is, once again propagate...

Don't know how to handle these problems.

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
david
  • 1,302
  • 1
  • 10
  • 21
  • 1
    What is your widget supposed to display? Do you really want multiple sliders on top of each other or is that an attempt at having only one of them visible at the same time? If not, I would suggest not to use your stack, but instead having e.g. a `background` widget whose child widget you dynamically replace. Also: Yup, your guess is right: There is no "top-most" widget in mouse event handling. The event is sent to all the widgets that cover the position in question. – Uli Schlachter Jun 28 '20 at 13:01
  • 1
    @uli-schlachter Thanks! So I gave up stack layout and rewrote with just one widget which changes text and slider value according to screen interface. – david Jun 28 '20 at 17:41

0 Answers0