1

I am trying to modify my rc.lua file the following way: when I press Mod4+R, AwesomeWM keybinding for running a command, I want Rofi to appear, blur my wallpaper and hide everything from my screen. I only want the Rofi prompt over a blurred wallpaper to be seen.

To achieve this, I have the following code in my conf file. I am using AwesomeWM v3.5.9 (Mighty Ravendark) with Lua 5.3.3:

--From PROmpt COMmand:
procom = "rofi -show run"

awful.key({ modkey }, "r", function () awful.util.spawn(procom)

    for _,c in ipairs(client.get()) do
        if c:isvisible() then
            mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible 
        else 
            mywibox[mouse.screen].visible = mywibox[mouse.screen].visible 
        end
    end

end),

Restarting AwesomeWM won't complain at all, but my wibox won't disappear. If I change the code into something trivial (i.e. if mywibox[mouse.screen],visible as the conditional statement), the widgets will go away, but an empty black bar will stay there even if I quit Rofi, only returning to its initial state when summoning Rofi again (that is caused by the statement I initially made, that's why I considered as trivial).

xvlaze
  • 837
  • 1
  • 10
  • 30
  • 1
    The title of this question is misleading and does not reflect what's asked and discussed. Google led me here for this reason and I wasted time figuring out it was irrelevant. – Arnaud Meuret Sep 04 '20 at 15:29

2 Answers2

2

For the new question:

Your code snippet doesn't work because you check if a client is visible, then toggle a random wibox (ok, not so random). The wibox will be shown and hidden many times are you do it for each client. So you end up with a ~50% change of getting back to the original state and ~50% change of having no wibox and no way to get it back.

I will expand on the last part of my previous answer as it is now the question.

What you want:

  • Hide the wibar (mywibox) when rofi starts
  • Hide All clients when rofi starts
  • Restore the wibar when rofi exists
  • Maybe display the tag again (or not, up to you).

The problems are:

  1. You don't know when rofi exits
  2. You don't know when rofi appears
  3. You don't know the names of the things you wish to hide
  4. You need to hide tags and the wibar

Problem 3:

Not your fault, the 3.5 has no documentation about this and the wiki was equally confusing.

  • An awful.wibox (now renamed wibar) is the thing at the top of the screen
  • A wibox is a random free floating widget on the screen. A wibar is a type of wibox acting like a panel.
  • A client is a window on the screen
  • A tag is similar to a virtual workspace

Problem 2:

This one is tricky. When you launch a command, there is a delay between that and when the application appears. There is ways to detect it, but they are not trivial. For now you can ignore this problem.

Problem 1:

This is the one you really have to solve. Awesome 3.5 does not have a good API to keep track of the life cycle from a command to the exit of the application. Awesome 4.0 is a little bit better, but this is an hard problem to solve. However, you should be able to know the class of rofi (using xprop). Once you know that, you can simplify the problem by only caring "do an event when rofi exits". The code for this is:

client.connect_signal("unmanage", function(c)
    if c.class == "whatever_its_class_is" then
        -- watch out of you have multiple screens, this may be too simplified.
        mywibox[mouse.screen].visible = true

        -- show the first tag, change this to what you prefer
        awful.tag.gettags(mouse.screen)[1].selected = true
    end
end)

Problem 4:

The simple way to hide the current tag (assumes you have 1 screen and 1 selected tag for the sake of simplicity)

awful.tag.selected().selected = false

Hide the main wibar (assuming you kept the default name)

mywibox[mouse.screen].visible = false

Original answer: (the question has changed)

Well, c is just a variable. In this case, you never defined it, so it's nil.

I guess you want all currently visible client. To check that, use client:isvisible().

You can loop across all clients using

for _, c in ipairs(client.get()) do
    if c:isvisible() then
        -- do something
    end
end

As shown in the client documentation (https://awesomewm.org/apidoc/classes/client.html [1])

That being said, I don't see how the description and the question/code fit. If you want to hide everything, then unselect all tags and hide the wibar. Messing with the titlebars (the thing on top of clients) seem rather unnecessary.

[1] The link is for Awesome 4.0, but in this case isn't very different from the 3.5 API.

  • I guess you're in the good way, but after some changes the problem's still there. I have updated the question. – xvlaze Jan 09 '17 at 17:10
  • I updated the answer to reflect the more specific question – Emmanuel Lepage Vallee Jan 10 '17 at 04:28
  • Seems like it's not possible to find the Rofi class name. I am attaching the result code. Thank you for your time! – xvlaze Jan 10 '17 at 13:34
  • If class isn't set (it's a bug you should report to them), then you can use the name or parse the startup_id. Anything that can identify the client will do. – Emmanuel Lepage Vallee Jan 10 '17 at 21:31
  • If I replace `"whatever_its_class_is"` with `"rofi"` nothing will happen. – xvlaze Jan 10 '17 at 22:55
  • As I said in the last comment, if it has no class, then it's their bug, but you can work around it by using something else such as the `name` or `startup_id` properties. Do some reading in the doc (https://awesomewm.org/apidoc/classes/client.html (link for 4.0, you should upgrade) ). I mean, I can answer specific questions, but you still have to dig a little and understand the concepts at play. Using Awesome without understanding how it works is never going to really work out. If you have API related questions the doc can't answer, then report a bug on Awesome issue tracker. – Emmanuel Lepage Vallee Jan 11 '17 at 07:46
  • I'll go for the name option. So if I change a bit the code, I get `mywibox[mouse.screen].visible = false` and inside the `unmanage` part, `if c.name == "rofi" then` the line which makes the wibox visible. I can make it disappear, but it won't appear again. – xvlaze Jan 11 '17 at 10:13
  • Making it appear and disappear is 2 different problem. When a client starts and when a client quit isn't the same event. See the full answer above. – Emmanuel Lepage Vallee Jan 12 '17 at 21:52
  • I have updated my code so it's easy for you to see my situation. Again, thank you for your time. – xvlaze Jan 13 '17 at 14:13
0

The whole function in my rc.lua right now. Works fine, but I'm planning to improve it in the future. Answers the question perfectly, though.

 -- Prompt
    awful.key({ modkey }, "r", 
              function ()
                  myscreen                 = awful.screen.focused()
                  commandPrompter          = "rofi -show run -normal-window"
                  blur                     = "hsetroot -fill /usr/local/share/awesome/themes/modded/back$
                  unblur                   = "hsetroot -fill /usr/local/share/awesome/themes/modded/back$
                  awful.spawn(commandPrompter)
                  myscreen.mywibox.visible = false
                  awful.spawn(blur)
              end),

enter image description here

xvlaze
  • 837
  • 1
  • 10
  • 30