You are not logged in.

#1 2012-05-10 20:54:39

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Awesome: Center Widget in Panel

Howdy-ha, folks.  I'm wondering if there's any way to center a widget in the wibox; I'd like to stick my clock in the center of the top panel, since that's where my eyes often drift while I work.  A textbox spacer can suffice for now, but when other widgets update or display long strings, the clock moves off-center. I've tried using "awful.widget.layout.margins[clock.widget] = {left = [integer] }," as well as widget.layout.horizontal, without any luck.  My next guess would be "awful.widget.layout.horizontal.flex," but there's no documentation on it in the Awesome wiki (except for a note on converting from 3.3 to 3.4, which just says that the "flex" widget layout has changed; there's nothing about the original usage), so I don't know how to use it.

If anyone's confused about what I'm looking for, here's a screenshot to give you an idea.  When new tags are added or the battery status changes, the clock shifts.  I'd like it to stay fixed in the center.

Offline

#2 2012-05-11 16:00:36

mt22
Member
Registered: 2012-03-31
Posts: 20

Re: Awesome: Center Widget in Panel

Actually the centred clock looks good in your screenshot.
For only numbers you could fill with zeros (3 -> 03)... but that's not a pretty solution and it doesn't solve the variable string problem... hoping someone has a true solution.

Offline

#3 2012-05-11 16:27:32

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Awesome: Center Widget in Panel

The problem is that the strings I listed above either don't have an effect or break my config, and besides, it moves off-center when the info in the wibox changes or when it's displayed on a second monitor of a different resolution.  I've been putting off learning Lua for too long (I'm not really a coder), but I've got a couple weeks to play around.  It's probably about time I sat down with a tutorial and tried to sort it out.  Based on others' experience, is it sensible for someone with no coding experience to try and learn enough Lua to just work with Awesome?  Or am I selling myself short with that?

Last edited by ANOKNUSA (2012-05-11 16:29:07)

Offline

#4 2012-05-11 22:51:24

Wey
Member
Registered: 2011-04-22
Posts: 217

Re: Awesome: Center Widget in Panel

Based on wibox.layout.align from awesome-git I hacked up a custom layout center.lua: http://pastebin.com/ARMsQjPQ. Which is then used similar to this:

local left_layout = wibox.layout.fixed.horizontal()
left_layout:add(mytaglist)
left_layout:add(mypromptbox)
left_layout:add(mytasklist)

local layout = center.horizontal()

layout:set_first(left_layout)
layout:set_second(mytextclock)
layout:set_third(wibox.widget.systray())

mywibox:set_widget(layout)

bildschirmfotovom20120euzh.png

I only modified the draw function, and it doesn't cope with vertical layouts. From what I can gather, it works surprisingly well. The function receives the width and height of the total bar,
then acquires the width of the second, centered widget, and declares the variables left=width/2-(width of center widget/2), respectively right=width/2+(width of center widget/2).
The first widget is than drawn from 0 to left and the third from right to width.

Overflowing widgets seem to get wrapped:
bildschirmfotovom20123julg.pngbildschirmfotovom2012you4c.png

Though I haven't yet figured out where the actual layout code is located in the stable version, so I don't know if it could be transferred.

I've been putting off learning Lua for too long (I'm not really a coder), but I've got a couple weeks to play around.  It's probably about time I sat down with a tutorial and tried to sort it out.  Based on others' experience, is it sensible for someone with no coding experience to try and learn enough Lua to just work with Awesome?  Or am I selling myself short with that?

I'm not particularly experienced in lua myself, but I guess the most work would be learning awesome's API, since the basic control flow stuff is pretty straight-forward, and as far as I learned lua all data structures are build up on the idea of key-value tables. The interactive lua console might be a good way to get started.

Offline

#5 2012-05-12 16:40:22

Wey
Member
Registered: 2011-04-22
Posts: 217

Re: Awesome: Center Widget in Panel

So I tried to port this to the stable version. I copied awful.widget.layout.horizontal and added a center function. It seems to work, but the code is rather awkward and I didn't remove any debugging output: https://gist.github.com/2667398 Neither did I test it very extensively, so I do not know how robust it is regarding exotic configurations. Usage would be something like:

    mywibox[s].widgets = {
      {
        mytaglist[s],
        mytasklist[s],
        layout=horizontal.leftright
      },
      mytextclock,
      mysystray,
      layout=horizontal.center,
    }

Which would result in:
bildschirmfotovom2012vhz7r.png bildschirmfotovom2012p1z4y.png

Regarding the flex layout you mentioned in your initial post, it should simply sum up the number of elements in the bar and divide the available horizontal space so each element will receive an equal amount of space.

Edit: In case anybody cares, i uploaded an updated version here: https://bitbucket.org/Wey/aw-center/src

Last edited by Wey (2012-05-27 15:02:32)

Offline

#6 2012-05-13 21:01:15

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Awesome: Center Widget in Panel

Thanks for getting back to me, Wey.  I was planning on migrating to the git master in the next couple days; once I've done that, I'll give your new center layout a shot.

As for learning Lua: I actually have no knowledge of programming at all, and a lot of the concepts and terminology ("command flow," "object," etc.) are just lost on me.  Seeing a string of code and then visualizing what effect it will have on-screen is pretty foreign, and nearly every "beginner's guide" I've found for any given language assumes the reader already has some coding experience.  Is there an absolute-beginner resource you can recommend for me to look at online?  I get the feeling I'm gonna have to start at the very basics instead of just jumping into Lua, and while I'm grateful for your contribution, I always feel like a bit of a leech when I could be learning to this myself. tongue

Offline

#7 2012-05-13 21:23:02

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,804

Re: Awesome: Center Widget in Panel

@ANOKNUSA:  I've seen your posts, so I am comfortable making this suggestion.  You might not believe it, but I think you should pick up a copy of the canonical reference on 'C':

The C Programming Language, Brian Kerninghan and Dennis Ritchie.

It is the most concise, elegant book on the subject I have ever seen.  It starts at the beginning and takes you through the whole language.  No hand holding, no fluff.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#8 2012-05-18 00:53:41

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Awesome: Center Widget in Panel

@Wey: I migrated to the Git branch of Awesome a few days ago without much trouble.  Now, about center.lua: where did you place the file?  Do I need to place it in ~/.config/awesome and "require" it in rc.lua?

@ewaller: Thanks for the recommendation.  Payday just passed by, so I sprung the cash for it--should be here in a few days.  We'll see how this little experiment goes. wink

Offline

#9 2012-05-18 09:26:09

Wey
Member
Registered: 2011-04-22
Posts: 217

Re: Awesome: Center Widget in Panel

Now, about center.lua: where did you place the file?  Do I need to place it in ~/.config/awesome and "require" it in rc.lua?

Yes, I created .config/awesome/center.lua, and then added require("center") in rc.lua.

Offline

Board footer

Powered by FluxBB