1

I'm extremely confused about how to do this. The documentation of Awesome is not clear to me at all, nor following stuff from the rc.lua helps. All I wanna do is to pop up the calendar upon clicking the textclock widget (with LMB), though I don't know how to start with it because the documentation has no examples (or at least I could not find it after spending 1 hour of googling), and the rc.lua has many different lines and arguments in each of them, making me unable to do anything.

My idea was

awful.button({}, 1, function() wibox.widget.calendar.year(os.date('*t')) end)

, but I have no clue how to attach this to the textclock widget. Also, I'm not quite sure if that is going to work anyway (that is, after I manage to attach it to the textclock). I'd wanna avoid adding too many widgets that I can interact with, and keep it simple, with as few as possible.

Thank you in advance, and I hope I didn't make anyone pull their hair out...

Balthasar
  • 21
  • 1

1 Answers1

3

AwesomeWM concept of "buttons" can be split into 2 APIs. First of all, there is the button widget, which actually doesn't do much and is just a glorified wibox.widget.imagebox. This is the part not super relevant to your question.

The other part, which is relevant, is the event model. There are 2 ways to get something to happen when you click on a widget. The first one are the signals. Each widget has a button::press, button::release, mouse::enter and mouse::leave signals. You can attach a function to a signal this way:

mytextclock:connect_signal("button::press", function(self, lx, ly, button, mods, metadata)
   wibox.widget.calendar.year(os.date('*t'))
end)

That API is more rich than a simple button. You get a lot of geometry and layout information you don't get from awful.button. However, it is overkill for simple buttons, thus awful.button.

Each widget has a :buttons() method in AwesomeWM < v4.4 or a .buttons object property in AwesomeWM >= v4.4. There are several examples in rc.lua of how to add some awful.buttons to these widget. Here are the snippets for the mylayoutbox widget:

For < v4.4:

    s.mylayoutbox:buttons(gears.table.join(
                           awful.button({ }, 1, function () awful.layout.inc( 1) end),
                           awful.button({ }, 3, function () awful.layout.inc(-1) end),
                           awful.button({ }, 4, function () awful.layout.inc( 1) end),
                           awful.button({ }, 5, function () awful.layout.inc(-1) end)))

for >= v4.4:

    s.mylayoutbox = awful.widget.layoutbox {
        screen  = s
    }

    s.mylayoutbox.buttons = {
        awful.button({ }, 1, function () awful.layout.inc( 1) end),
        awful.button({ }, 3, function () awful.layout.inc(-1) end),
        awful.button({ }, 4, function () awful.layout.inc(-1) end),
        awful.button({ }, 5, function () awful.layout.inc( 1) end),
    }

    -- That works too.
    s.mylayoutbox:add_button(awful.button({ }, 1, function () awful.layout.inc( 1) end))

As for the lack of examples in the documentation. That's a fair point. I will add some.

Ôrel
  • 7,044
  • 3
  • 27
  • 46
  • Unfortunately, I'm still clueless on how to make a calendar appear upon pressing the textclock. I'll probably just leave it for now and don't bother. Guess I'm just trying something too fancy for now, because I'm totally new to Awesome (and Lua as well). Also still haven't figured out how to make my volume to change upon pressing "Volume up/Volume down" buttons, so I guess that says a lot about my knowledge, lol. – Balthasar Dec 29 '21 at 15:55
  • You might want to join the Discord chat server at https://discord.gg/BPat4F87dg . The SackOverflow format probably isn't the best to handle that part of the learning curve. I think I answered the original question as it was written. I guess the issue here is "how to I get access the the clock object? In that case, it's called `mytextclock` in the default `rc.lua`. Adding buttons to the clock is identical to adding buttons to the layoutbox a few lines away in the default `rc.lua`. – Emmanuel Lepage Vallee Dec 30 '21 at 03:38