Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding widgets to a theme #194

Closed
lrargerich opened this issue Jul 31, 2017 · 11 comments
Closed

Adding widgets to a theme #194

lrargerich opened this issue Jul 31, 2017 · 11 comments

Comments

@lrargerich
Copy link

I'm trying to add a few widgets to the holo theme:
File sys info
Memory Widget
Uptime
etc.

I was trying to use vicious and I have added this to rc.lua

local vicious = require("vicious")

Then in the holo theme theme.lua I tried a simple example:

datewidget = wibox.widget.textbox()
vicious.register(datewidget, vicious.widgets.date, "%b %d, %R")

But this seems to make awesome unable to start (I wonder why).
Note this makes awesome unable to start even without adding the widget to a wibox.

Can you help me with a simple guide on how to add new widgets to one of the existing themes?

Thanks!

@lcpz
Copy link
Owner

lcpz commented Jul 31, 2017

With these configs, widgets have to be put in theme.lua.

Add other widgets here and put their definition (datewidget, in your example) here.

@lcpz lcpz closed this as completed Jul 31, 2017
@lrargerich
Copy link
Author

That's exactly what I was doing but for some reason awesome refuses to start after adding the simple date widget.

@lcpz
Copy link
Owner

lcpz commented Aug 1, 2017

I forgot to say that the vicious requirement has to go in theme.lua as well, of course.

If you want to know the exact cause of your issue, you have 2 options:

  1. starting X like this:

    $ startx -- -keeptty -nolisten tcp > $HOME/.xorg.log 2>&1

    then check ~/.xorg.log when the error happens.

  2. using Xephyr for debugging.

@lrargerich
Copy link
Author

Thank you very much.
I managed to get the vicious memory widget working but I can't make it use the same fonts as my theme (holo)

Can you help me a little with this one? Then I will be able to add other vicious widgets to holo.

This is the widget: (then I just add it to the wibox)

local memwidget = wibox.widget.textbox()
vicious.cache(vicious.widgets.mem)
vicious.register(memwidget, vicious.widgets.mem, "$1% $5%", 13)

Holo is a bit different than the other themes in how widgets are handled and I couldn't find any examples of a vicious widget in holo.

@lcpz
Copy link
Owner

lcpz commented Aug 1, 2017

Not that I want to promote my library, but if you don't have a particular reason for using vicious, you could then use lain. There's plenty of examples in other themes you can just copy/paste in your custom Holo. Otherwise, check here for a vicious manual.

@lrargerich
Copy link
Author

Fair enough.
I would like a mem% swap% simple indicator, but from what I read in the lain documentation it only provides the number of MBs of memory used. Do you have a simple way to make it compute the percentages? Then I can use the lain widget and copy from some theme how to customize it.

Thanks!

@lcpz
Copy link
Owner

lcpz commented Aug 1, 2017

Try this.

local memory = lain.widget.mem {
    settings = function()
        local swap_perc = math.floor((mem_now.swap - mem_now.swapf) / mem_now.swap * 100)
        widget:set_markup(markup.fontfg(theme.font, "#e0da37", -- reset this color as you like
        mem_now.perc .. "% " .. swap_perc .. "% "))
    end
}

The markup call makes it use your theme font.

@lrargerich
Copy link
Author

Thank you very much, two questions:

  1. There is a 10% difference between the lain widget and the vicious widget for mem_now.perc, this is consistent so I wonder which one is wrong.
  2. I'm trying to add the widget you sent me in holo where I need to put it in a box, so I added the following two lines (see below)

local memory = lain.widget.mem {
settings = function()
local swap_perc = math.floor((mem_now.swap - mem_now.swapf) / mem_now.swap * 100)
widget:set_markup(lain.util.markup.fontfg(theme.font, "#FFFFFF", -- customize this
mem_now.perc .. "% " .. swap_perc .. "% "))
end
}
local membg = wibox.container.background(memory.widget, theme.bg_focus, gears.shape.rectangle)
local memwidget = wibox.containter.margin(membg, 0, 0, 5, 5)

But with these two lines awesome refuses to star so soemthing is wrong. I'm just trying to imitate what was done with the other widgets in the holo theme. Any ideas?

Thanks a lot for your help. Doing this alone would have been impossible...

@lcpz
Copy link
Owner

lcpz commented Aug 1, 2017

  1. I don't know about vicious, but lain is aligned to top and free -h: mem widget reports wrong(?) amount of memory used and it's frozen lain#271
  2. There's a typo: containter. This is correct:
local memory = lain.widget.mem {
    settings = function()
        local swap_perc = math.floor((mem_now.swap - mem_now.swapf) / (mem_now.swap > 0 and mem_now.swap or 1) * 100)
        widget:set_markup(lain.util.markup.fontfg(theme.font, "#FFFFFF",
        mem_now.perc .. "% " .. swap_perc .. "% "))
    end
}

local membg = wibox.container.background(memory.widget, theme.bg_focus, gears.shape.rectangle)
local memwidget = wibox.container.margin(membg, 0, 0, 5, 5)

@lrargerich
Copy link
Author

Thank you very much Luke. You helped me more than enough :)

@lcpz
Copy link
Owner

lcpz commented Aug 2, 2017

If you need any help in the future, remember you can always rely on the community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants