varingst / awesome-conky

Make AwesomeWM 4.0 widgets displaying system information from conky
29 stars 1 forks source link

What do `show_key` and `toggle_key` functions do? #2

Closed doronbehar closed 7 years ago

doronbehar commented 7 years ago

Hello, I'm very interested in using this plugin for my awesome configuration, but I couldn't easily figure out how can I use the keybindings which awesome-conky provides me? I think the example given there isn't enough descriptive for noobs in lua like myself. Could you provide some more info please?

varingst commented 7 years ago

What does your configuration with awesome-conky look like?

The show-key and toggle-key functions are just convenience functions wrapping awful.key, they return keys for the globalkeys table in rc.lua

In order for them to work, awesome-conky must be able to find the conky client, if your own_window_class in your conky configuration ~/.conkyrc is set to something other than default, you need to set the conky.class = <window_class> in rc.lua

doronbehar commented 7 years ago

Sorry for not answering in a long time. I tried to add the following to my rc.lua:

    -- {{{ Conky
    awful.key({modkey               }, "c",         conky.show_key("F12"),
        {description="Show conkey Key F12", group="Conky"}),
    -- }}}

I understand that's not how you meant users will use conky.show_key().

I'll be happy if you'll spear more details about the usage of this function and conky.toggle_key() as well.

varingst commented 7 years ago

What you want is this: conky.show_key("c", {modkey})

What you are doing here:

    -- {{{ Conky
    awful.key({modkey               }, "c",         conky.show_key("F12"),
        {description="Show conkey Key F12", group="Conky"}),
    -- }}}

Is creating a key binding bound to the result of show_key. The result of show_key is a key object, not a function.

awful.key takes a table of modifier keys, a key, a function to call, and a description, and returns a key object to add to the globalkeys table in rc.lua

conky.show_key and conky.toggle_key returns the exact same key object as awful.key, they call awful.key in their body and return the result:

function public.show_key(key, mod) -- {{{2
    -- sets the key to hold for the conky window to be visible
    return awful.key(mod or {}, key, window.raise, window.lower_delayed,
           { description = "conky window on top while held", group = "conky" })
end

function public.toggle_key(key, mod)  -- {{{2
    -- sets the key to press to toggle the conky window visibility
    return awful.key(mod or {}, key, window.toggle,
           { description = "toggle conky window on top", group = "conky" })
end

How show_key and toggle_key are meant to be used, is to create keys for the globalkeys table in rc.lua, just how awful.key is used:

globalkeys = awful.util.table.join(
    -- other keys using awful.key() here
    conky.show_key("F12")
)

The result is that pressing the key F12 shows the window while held.

doronbehar commented 7 years ago

Got it, Thanks :)