awesomeWM / awesome

awesome window manager
https://awesomewm.org/
GNU General Public License v2.0
6.39k stars 597 forks source link

wibox.widget.slider: handle shape is misslocated when setting a manual height for a shape #3759

Open Crylia opened 1 year ago

Crylia commented 1 year ago

Output of awesome --version:

awesome v4.3-1581-gc8016f0c (Too long)

How to reproduce the issue:

bar_shape = function(cr, width, height)
  gshape.rounded_rect(cr, width, height, dpi(5))
end,
bar_height = dpi(5),
bar_color = Theme_config.volume_controller.border_color,
bar_active_color = Theme_config.volume_controller.volume_fg,
handle_color = Theme_config.volume_controller.volume_fg,
handle_shape = function(cr, width, height)
  gshape.partially_rounded_rect(cr, width, dpi(5), false, true, true, false)
 end,
 handle_border_color = Theme_config.volume_controller.volume_fg,
handle_width = dpi(5),
handle_cursor = 'left_ptr',
maximum = 100,
forced_height = dpi(5),
value = 50,
widget = wibox.widget.slider,

When I create a slider with the code above the handle is placed above the slider.

The problem "goes away" when I just use the provided height but then I can't limit the height.

I can see this getting fixed in two ways, maybe both would be good.

It looks like the widget uses all its *available space for the shape, even when wrapping the slider in a wibox.container.constraint or using forced_height = dpi(5)

*The space that the entire widget and its partent(a constraint with height = dpi(5) and strategy = 'exact') have in this layout

kosorin commented 1 year ago
handle_shape = function(cr, width, height)
  gshape.partially_rounded_rect(cr, width, dpi(5) --[[ here ]] , false, true, true, false)
end,

This is not how you use shape. You only clipped what is drawn and the handle is still there in its full size, you didn't magically changed its height.

You mentioned wibox.container.constraint. I'm also having trouble getting it to work, I almost think there must be some bugs or the doc is not clear and I'm missing something.

However you can use other layouts. I tried wibox.layout.align and it works:

{
    widget = wibox.layout.align.vertical,
    expand = "outside",
    nil,
    {
        bar_shape = function(cr, width, height)
            gshape.rounded_rect(cr, width, height, dpi(5))
        end,
        bar_height = dpi(5),
        bar_color = "#000044",
        bar_active_color = "#0000cc",
        handle_color = "#cc0000",
        handle_shape = function(cr, width, height)
            gshape.partially_rounded_rect(cr, width, height, false, true, true, false)
        end,
        handle_border_color = "#00cc00",
        handle_width = dpi(5),
        handle_cursor = 'left_ptr',
        maximum = 100,
        forced_height = dpi(5),
        value = 50,
        widget = wibox.widget.slider,
    },
    nil,
}

image

Edit: I just noticed this is not the best solution as it kind of hard to grab the slider.