samuelmr
samuelmr

Reputation: 617

Change awesomewm theme programmatically

I have several wallpapers and a theme/colour palette for each one, I'm trying to find a way to assign a keyboard shortcut to change the theme from one to another.

I have no problems setting each individual theme, but cannot for the life of me figure out a way to set the theme once awesomewm has started running without killing the current instance and then making a new one.

I think once the theme has been assigned and awesomewm has been instansiated the values are fixed, if that's the case I don't think it will be possible to do.

Upvotes: 6

Views: 3466

Answers (2)

TornaxO7
TornaxO7

Reputation: 1299

I wanted the same and achieved that by writing a little script which is mapped to a shortcut. If you want to do it on your own, than you can follow these steps:

  1. Create a folder which includes your themes.
  2. Write a script (or use mine) which copys the files to your ~/.config/awesome folder.
  3. Add a shortcut or something like that to execute the script. The script should copy the files inside of your theme-folder to the config folder of awesome (~/.config/awesome).
  4. After that you can see/use your theme after executing the script and restarting awesomewm (Default shortcut: modkey + shift + r
    Your rc.lua file should only read files of your awesome-config-directory. You are just "overwriting" them by copying the files of your theme-folder. I hope the explanation is fine if not just comment on this answer.

Upvotes: 0

Worron
Worron

Reputation: 181

I think one of possible ways is recreate all you widgets after theme changes. Not sure for whole code, but here is quick example how to rebuild panel by hotkey for awesome v4.0.

Some modifications for screen building functions first

local function build_panel(s)
    -- destroy old panel
    if s.mywibox then s.mywibox:remove() end

    -- create a promptbox for given screen
    s.mypromptbox = awful.widget.prompt()

    -- create a layoutbox for given screen
    s.mylayoutbox = awful.widget.layoutbox(s)
    s.mylayoutbox:buttons(awful.util.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))
    )
    -- create a taglist widget
    s.mytaglist = awful.widget.taglist(s, awful.widget.taglist.filter.all, taglist_buttons)

    -- create a tasklist widget
    s.mytasklist = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, tasklist_buttons)

    -- create panel wibox
    s.mywibox = awful.wibar({ position = "top", screen = s })

    -- add widgets to the panel wibox
    s.mywibox:setup {
        layout = wibox.layout.align.horizontal,
        { layout = wibox.layout.fixed.horizontal, mylauncher, s.mytaglist, s.mypromptbox },
        s.mytasklist,
        { layout = wibox.layout.fixed.horizontal, mykeyboardlayout, wibox.widget.systray(), mytextclock, s.mylayoutbox },
    }
end

awful.screen.connect_for_each_screen(function(s)
    -- wallpaper
    set_wallpaper(s)

    -- tags
    awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])

    -- panel setup
    build_panel(s)
end)

And add action to globalkeys

awful.key(
    { modkey }, "z",
    function()
        -- change theme settings
        beautiful.bg_normal = "#ff2020"
        beautiful.fg_normal = "#2020ff"
        -- rebuild panel widgets
        build_panel(mouse.screen)
    end,
    {description="theme colors change", group="awesome"}
),

Upvotes: 2

Related Questions