<commit_before>-- Includes {{{
-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
require("awful.autofocus")
-- Widget and layout library
local wibox = require("wibox")
-- Theme handling library
local beautiful = require("beautiful")
-- Notification library
local naughty = require("naughty")
local menubar = require("menubar")
local hotkeys_popup = require("awful.hotkeys_popup").widget
-- Enable VIM help for hotkeys widget when client with matching name is opened:
require("awful.hotkeys_popup.keys.vim")
local utils = require("utils")
local icons = require("icons")
local cal = require("cal")
local widgets = require("widgets")
local systray = require("systray")
local treetile = require("treetile")
treetile.focusnew = true
local freedesktop = require("freedesktop")

-- }}}

-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then
    naughty.notify({ preset = naughty.config.presets.critical,
                     title = "Oops, there were errors during startup!",
                     text = awesome.startup_errors })
end

-- Handle runtime errors after startup
do
    local in_error = false
    awesome.connect_signal("debug::error", function (err)
        -- Make sure we don't go into an endless error loop
        if in_error then return end
        in_error = true

        naughty.notify({ preset = naughty.config.presets.critical,
                         title = "Oops, an error happened!",
                         text = tostring(err) })
        in_error = false
    end)
end
-- }}}

-- {{{ Variable definitions
-- This is used later as the default terminal and editor to run.
shell = "bash"
-- terminal = "termite"
terminal = "alacritty"
terminal_cmd = terminal .. " -e "
-- terminal_cmd_format = terminal_cmd .. "\"%s\""
terminal_cmd_format = terminal_cmd .. "%s"
editor = os.getenv("EDITOR") or "vim"
editor_cmd = string.format(terminal_cmd_format,  editor)
filemgr = "nemo"
configdir = os.getenv("HOME") .. "/.config/awesome"

-- Config file for temporary/frequently changing layouts (untracked by git)
if utils.file_exists(configdir .. "/layoutconfig.lua") then
    layoutconfig = require("layoutconfig")
end

-- Default modkey.
modkey = "Mod4"

-- Themes define colours, icons, font and wallpapers.
beautiful.init(configdir .. "/themes/custom/theme.lua")

-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
    awful.layout.suit.floating,
    awful.layout.suit.tile,
    awful.layout.suit.tile.left,
    awful.layout.suit.tile.bottom,
    awful.layout.suit.tile.top,
    awful.layout.suit.fair,
    awful.layout.suit.fair.horizontal,
    awful.layout.suit.spiral,
    awful.layout.suit.spiral.dwindle,
    awful.layout.suit.max,
    awful.layout.suit.max.fullscreen,
    awful.layout.suit.magnifier,
    awful.layout.suit.corner.nw,
    awful.layout.suit.corner.ne,
    awful.layout.suit.corner.sw,
    awful.layout.suit.corner.se,
    treetile
}
-- }}}

-- {{{ Helper functions
local function client_menu_toggle_fn()
    local instance = nil

    return function ()
        if instance and instance.wibox.visible then
            instance:hide()
            instance = nil
        else
            instance = awful.menu.clients({ theme = { width = 250 } })
        end
    end
end
-- }}}

-- {{{ Menu
-- Create a launcher widget and a main menu
myawesomemenu = {
   { "hotkeys", function() return false, hotkeys_popup.show_help end},
   { "manual", function() utils.run_term("man awesome") end },
   { "edit config", function() utils.run_term(editor .. " " .. awesome.conffile) end },
   { "restart", awesome.restart },
   { "quit", function() awesome.quit() end}
}

systemmenu = {
   { "lock", "/home/marvin/scripts/lockscreen.sh" },
   { "poweroff", "systemctl poweroff" },
   { "reboot", "systemctl reboot" },
   { "suspend", "systemctl suspend" },
   { "hibernate", "systemctl hibernate" },
}

mymainmenu = freedesktop.menu.build({
    sub_menu = "Applications",
    before = {
        { "Awesome", myawesomemenu, beautiful.awesome_icon },
        { "System", systemmenu },
    },
    after = {
        { "Open terminal", terminal, "/usr/share/icons/gnome/16x16/apps/utilities-terminal.png" },
        { "Open file manager", filemgr, "/usr/share/icons/gnome/16x16/apps/system-file-manager.png" },
        { "Open browser", "firefox", "/usr/share/icons/hicolor/16x16/apps/firefox.png" },
        { "Open thunderbird", "thunderbird", "/usr/share/icons/hicolor/16x16/apps/thunderbird.png" },
    }
})
mymainmenu.theme.width = 150

mylauncher = awful.widget.launcher({
    image = icons.arch,
    menu = mymainmenu
})

-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
-- }}}

-- {{{ Widgets
separator = wibox.widget.textbox()
separator:set_text("  ")

systraywidget = systray()
systraywidget:toggle() -- Hide the systray
cpuwidget = widgets.cpu({ timeout = 3 })
memwidget = widgets.mem({ timeout = 3 })
volwidget = widgets.volume({ timeout = 5 })
batwidget = widgets.bat({ timeout = 61, battery = "BAT1", ac = "ACAD" })
tempwidget = widgets.temp({ timeout = 59, })
mpdwidget = widgets.mpd({ timeout = 3, notify = "off" })
brightwidget = widgets.brightness()
wiredwidget = widgets.wired({ autohide = true })
wifiwidget = widgets.wifi({ autohide = true })
fswidget = widgets.fs()

mytextclock = wibox.widget.textclock()
cal.register(mytextclock)

-- Keyboard map indicator and switcher
-- mykeyboardlayout = awful.widget.keyboardlayout()
-- }}}

-- {{{ Screen, Tag, Wibar Setup
-- Create a wibox for each screen and add it
local taglist_buttons = awful.util.table.join(
    awful.button({ }, 1, function(t) t:view_only() end),
    awful.button({ }, 3, awful.tag.viewtoggle),
    awful.button({ modkey }, 1, function(t)
        if client.focus then
            client.focus:move_to_tag(t)
        end
    end),
    awful.button({ modkey }, 3, function(t)
        if client.focus then
            client.focus:toggle_tag(t)
        end
    end),
    awful.button({ }, 4, function(t) awful.tag.viewprev(t.screen) end),
    awful.button({ }, 5, function(t) awful.tag.viewnext(t.screen) end)
)

local tasklist_buttons = awful.util.table.join(
     awful.button({ }, 1, function(c)
         if c == client.focus then
             c.minimized = true
         else
             -- Without this, the following
             -- :isvisible() makes no sense
             c.minimized = false
             if not c:isvisible() and c.first_tag then
                 c.first_tag:view_only()
             end
             -- This will also un-minimize
             -- the client, if needed
             client.focus = c
             c:raise()
         end
     end),
     awful.button({ }, 2, function(c) c:kill() end),
     awful.button({ }, 3, client_menu_toggle_fn()),
     awful.button({ }, 4, function() awful.client.focus.byidx(1) end),
     awful.button({ }, 5, function() awful.client.focus.byidx(-1) end)
)

-- Setup screens {{{
local function set_wallpaper(s)
    -- Wallpaper
    if beautiful.wallpaper then
        local wallpaper = beautiful.wallpaper
        -- If wallpaper is a function, call it with the screen
        if type(wallpaper) == "function" then
            wallpaper = wallpaper(s)
        end
        gears.wallpaper.centered(wallpaper, s)
    end
end

-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
screen.connect_signal("property::geometry", set_wallpaper)

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

    -- Each screen has its own tag table.
    awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[2])

    -- s.tags[2].layout = treetile

    -- Create a promptbox for each screen
    s.mypromptbox = awful.widget.prompt()
    -- Create an imagebox widget which will contains an icon indicating which layout we're using.
    -- We need one layoutbox per 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 the wibox
    s.mywibox = awful.wibar({ position = "top", screen = s })

    -- Add widgets to the wibox
    s.mywibox:setup {
        layout = wibox.layout.align.horizontal,
        { -- Left widgets
            layout = wibox.layout.fixed.horizontal,
            mylauncher,
            s.mytaglist,
            s.mypromptbox,
        },
        s.mytasklist, -- Middle widget
        { -- Right widgets
            layout = wibox.layout.fixed.horizontal,
            -- mykeyboardlayout,
            systraywidget.widget,
            separator,
            mpdwidget:get_container(),
            separator,
            wifiwidget:get_container(),
            wiredwidget:get_container(),
            -- separator,
            fswidget:get_container(),
            separator,
            brightwidget:get_container(),
            separator,
            tempwidget:get_container(),
            separator,
            volwidget:get_container(),
            separator,
            batwidget:get_container(),
            separator,
            memwidget:get_container(),
            separator,
            cpuwidget:get_container(),
            separator,
            mytextclock,
            s.mylayoutbox,
        },
    }

    -- Apply custom config
    if layoutconfig then
        layoutconfig(s)
    end
end)
-- }}}
-- }}}

-- {{{ Mouse bindings
root.buttons(awful.util.table.join(
    awful.button({ }, 3, function () mymainmenu:toggle() end)
    -- awful.button({ }, 4, awful.tag.viewnext),
    -- awful.button({ }, 5, awful.tag.viewprev)
))
-- }}}

-- {{{ Key bindings
local function switch_focus(dir)
    awful.client.focus.global_bydirection(dir)
    if client.focus then client.focus:raise() end
end

-- Global keys {{{
globalkeys = awful.util.table.join(
    -- awful.key({ modkey }, "s",      hotkeys_popup.show_help, {description="show help", group="awesome"}),

    awful.key({ "Mod1"          }, "Tab",
        function()
            local filter = function(c)
                return not c.minimized
            end

            local f = client.focus
            if f then
                for c in awful.client.iterate(filter, f.index, f.screen) do
                    client.focus = c
                    c:raise()
                end
            end
        end,
        { description = "cycle through clients", group = "client" }),

    -- Media keys {{{
    awful.key({ }, "XF86MonBrightnessDown", function() brightwidget:incBrightness(-5) end,
              { description = "decrease brightness", group = "media" }),

    awful.key({ }, "XF86MonBrightnessUp", function() brightwidget:incBrightness(5) end,
              { description = "increase brightness", group = "media" }),

    awful.key({}, "XF86AudioRaiseVolume", function() volwidget:changeVolume("1dB+") end,
              { description = "raise volume", group = "media" }),

    awful.key({}, "XF86AudioLowerVolume", function() volwidget:changeVolume("1dB-") end,
              { description = "lower volume", group = "media" }),

    awful.key({}, "XF86AudioMute", function() volwidget:toggleMute() end,
              { description = "mute", group = "media" }),

    awful.key({}, "XF86AudioStop", function()
            utils.async("mpc --wait stop", function(out) mpdwidget:update() end)
        end,
        { description = "stop", group = "media" }),

    awful.key({}, "XF86AudioNext", function()
            utils.async("mpc --wait next", function(out) mpdwidget:update() end)
        end,
        { description = "next", group = "media" }),

    awful.key({}, "XF86AudioPrev", function()
            utils.async("mpc --wait prev", function(out) mpdwidget:update() end)
        end,
        { description = "previous", group = "media" }),

    awful.key({}, "XF86AudioPlay", function() awful.spawn("mpc toggle") end,
        { description = "toggle play/pause", group = "media" }),
    -- }}}

    -- Screenshot
    awful.key({ },         "Print", function() utils.screenshot(mouse.screen.index) end,
              { description = "current screen", group = "screenshot" }),
    awful.key({ "Shift" }, "Print", function() utils.screenshot(-1) end,
              { description = "all screens", group = "screenshot" }),
    awful.key({ modkey },  "Print", function() utils.screenshot(0) end,
              { description = "selection", group = "screenshot" }),

    -- Open file explorer
    awful.key({ modkey }, "e", function() awful.spawn(filemgr) end,
              { description = "open file explorer", group = "launcher" }),
    awful.key({ modkey , "Shift" }, "e", function() awful.spawn.with_shell("urxvt -e python3 $(which ranger)") end,
              { description = "open ranger in urxvt", group = "launcher" }),

    -- Focus {{{
    awful.key({ modkey }, "Left",   awful.tag.viewprev, { description = "view previous", group = "tag" }),
    awful.key({ modkey }, "Right",  awful.tag.viewnext, { description = "view next", group = "tag" }),
    awful.key({ modkey }, "Escape", awful.tag.history.restore, { description = "go back", group = "tag" }),

    awful.key({ modkey }, "j", function() switch_focus("down") end,
        { description = "focus below", group = "client" }),
    awful.key({ modkey }, "k", function() switch_focus("up") end,
        { description = "focus above", group = "client" }),
    awful.key({ modkey }, "h", function() switch_focus("left") end,
        { description = "focus left", group = "client" }),
    awful.key({ modkey }, "l", function() switch_focus("right") end,
        { description = "focus right", group = "client" }),

    awful.key({ modkey, "Mod5" }, "j", function() awful.screen.focus_relative( 1) end,
        { description = "focus the next screen", group = "screen" }),
    awful.key({ modkey, "Mod5" }, "k", function() awful.screen.focus_relative(-1) end,
        { description = "focus the previous screen", group = "screen" }),
    awful.key({ modkey }, "u", awful.client.urgent.jumpto,
        { description = "jump to urgent client", group = "client" }),

    awful.key({ modkey }, "Tab",
        function()
            awful.client.focus.history.previous()
            if client.focus then
                client.focus:raise()
            end
        end,
        { description = "go back", group = "client" }),
    -- }}}

    -- Layout manipulation
    -- In-/Decrease num master/column {{{
    awful.key({ modkey, "Control" }, "k",
        function()
            awful.tag.incnmaster(1, nil, true)
            utils.notify(tostring(awful.tag.getnmaster()), "Master")
        end,
        { description = "increase the number of master clients", group = "layout" }),

    awful.key({ modkey, "Control" }, "j",
        function()
            awful.tag.incnmaster(-1, nil, true)
            utils.notify({ title = 'Master', text = tostring(awful.tag.getnmaster()), timeout = 1  })
        end,
        { description = "decrease the number of master clients", group = "layout" }),

    awful.key({ modkey, "Control" }, "h",
        function()
            awful.tag.incncol(1, nil, true)
            utils.notify({ title = 'Columns', text = tostring(awful.tag.getncol()), timeout = 1  })
        end,
        { description = "increase the number of columns", group = "layout" }),

    awful.key({ modkey, "Control" }, "l",
        function()
            awful.tag.incncol(-1, nil, true)
            utils.notify({ title = 'Columns', text = tostring(awful.tag.getncol()), timeout = 1  })
        end,
        { description = "decrease the number of columns", group = "layout" }),
    -- }}}

    awful.key({ modkey,           }, "space", function() awful.layout.inc( 1) end,
              {description = "select next", group = "layout"}),
    awful.key({ modkey, "Shift"   }, "space", function() awful.layout.inc(-1) end,
              {description = "select previous", group = "layout"}),

    -- Standard program
    awful.key({ modkey            }, "w", function() mymainmenu:show() end, { description = "show main menu", group = "awesome" }),
    awful.key({ modkey            }, "Return", function() awful.spawn(terminal) end, { description = "open a terminal", group = "launcher" }),
    awful.key({ modkey, "Control" }, "r", awesome.restart, { description = "reload awesome", group = "awesome" }),
    awful.key({ modkey, "Shift"   }, "q", awesome.quit, { description = "quit awesome", group = "awesome" }),

    awful.key({ modkey, "Shift" }, "j", function() awful.client.swap.global_bydirection("down") end,
        { description = "swap with client below", group = "client" }),
    awful.key({ modkey, "Shift" }, "k", function() awful.client.swap.global_bydirection("up") end,
        { description = "swap with client above", group = "client" }),
    awful.key({ modkey, "Shift" }, "h", function() awful.client.swap.global_bydirection("left") end,
        { description = "swap with client left", group = "client" }),
    awful.key({ modkey, "Shift" }, "l", function() awful.client.swap.global_bydirection("right") end,
        { description = "swap with client right", group = "client" }),

    awful.key({ modkey, "Control" }, "n",
        function()
            local c = awful.client.restore()
            -- Focus restored client
            if c then
                client.focus = c
                c:raise()
            end
        end,
        { description = "restore minimized", group = "client" }),

    -- Prompt
    awful.key({ modkey }, "r", function() awful.screen.focused().mypromptbox:run() end,
        { description = "run prompt", group = "launcher" }),

    awful.key({ modkey }, "x",
        function ()
            awful.prompt.run {
                prompt       = "Run Lua code: ",
                textbox      = awful.screen.focused().mypromptbox.widget,
                exe_callback = awful.util.eval,
                history_path = awful.util.get_cache_dir() .. "/history_eval"
            }
        end,
        { description = "lua execute prompt", group = "awesome" }),

    -- Menubar
    awful.key({ modkey }, "p", function() menubar.show() end,
        { description = "show the menubar", group = "launcher" }),

    -- Toggle systray visibility
    awful.key({ modkey, "Control" }, "s", function() systraywidget:toggle() end,
              { description = "toggle systray visibility", group = "media" })
)
-- }}}

-- Client keys {{{
clientkeys = awful.util.table.join(<commit_msg>Use albert as application launcher<commit_after>-- Includes {{{
-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
require("awful.autofocus")
-- Widget and layout library
local wibox = require("wibox")
-- Theme handling library
local beautiful = require("beautiful")
-- Notification library
local naughty = require("naughty")
local menubar = require("menubar")
local hotkeys_popup = require("awful.hotkeys_popup").widget
-- Enable VIM help for hotkeys widget when client with matching name is opened:
require("awful.hotkeys_popup.keys.vim")
local utils = require("utils")
local icons = require("icons")
local cal = require("cal")
local widgets = require("widgets")
local systray = require("systray")
local treetile = require("treetile")
treetile.focusnew = true
local freedesktop = require("freedesktop")

-- }}}

-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then
    naughty.notify({ preset = naughty.config.presets.critical,
                     title = "Oops, there were errors during startup!",
                     text = awesome.startup_errors })
end

-- Handle runtime errors after startup
do
    local in_error = false
    awesome.connect_signal("debug::error", function (err)
        -- Make sure we don't go into an endless error loop
        if in_error then return end
        in_error = true

        naughty.notify({ preset = naughty.config.presets.critical,
                         title = "Oops, an error happened!",
                         text = tostring(err) })
        in_error = false
    end)
end
-- }}}

-- {{{ Variable definitions
-- This is used later as the default terminal and editor to run.
shell = "bash"
-- terminal = "termite"
terminal = "alacritty"
terminal_cmd = terminal .. " -e "
-- terminal_cmd_format = terminal_cmd .. "\"%s\""
terminal_cmd_format = terminal_cmd .. "%s"
editor = os.getenv("EDITOR") or "vim"
editor_cmd = string.format(terminal_cmd_format,  editor)
filemgr = "nemo"
configdir = os.getenv("HOME") .. "/.config/awesome"

-- Config file for temporary/frequently changing layouts (untracked by git)
if utils.file_exists(configdir .. "/layoutconfig.lua") then
    layoutconfig = require("layoutconfig")
end

-- Default modkey.
modkey = "Mod4"

-- Themes define colours, icons, font and wallpapers.
beautiful.init(configdir .. "/themes/custom/theme.lua")

-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
    awful.layout.suit.floating,
    awful.layout.suit.tile,
    awful.layout.suit.tile.left,
    awful.layout.suit.tile.bottom,
    awful.layout.suit.tile.top,
    awful.layout.suit.fair,
    awful.layout.suit.fair.horizontal,
    awful.layout.suit.spiral,
    awful.layout.suit.spiral.dwindle,
    awful.layout.suit.max,
    awful.layout.suit.max.fullscreen,
    awful.layout.suit.magnifier,
    awful.layout.suit.corner.nw,
    awful.layout.suit.corner.ne,
    awful.layout.suit.corner.sw,
    awful.layout.suit.corner.se,
    treetile
}
-- }}}

-- {{{ Helper functions
local function client_menu_toggle_fn()
    local instance = nil

    return function ()
        if instance and instance.wibox.visible then
            instance:hide()
            instance = nil
        else
            instance = awful.menu.clients({ theme = { width = 250 } })
        end
    end
end
-- }}}

-- {{{ Menu
-- Create a launcher widget and a main menu
myawesomemenu = {
   { "hotkeys", function() return false, hotkeys_popup.show_help end},
   { "manual", function() utils.run_term("man awesome") end },
   { "edit config", function() utils.run_term(editor .. " " .. awesome.conffile) end },
   { "restart", awesome.restart },
   { "quit", function() awesome.quit() end}
}

systemmenu = {
   { "lock", "/home/marvin/scripts/lockscreen.sh" },
   { "poweroff", "systemctl poweroff" },
   { "reboot", "systemctl reboot" },
   { "suspend", "systemctl suspend" },
   { "hibernate", "systemctl hibernate" },
}

mymainmenu = freedesktop.menu.build({
    sub_menu = "Applications",
    before = {
        { "Awesome", myawesomemenu, beautiful.awesome_icon },
        { "System", systemmenu },
    },
    after = {
        { "Open terminal", terminal, "/usr/share/icons/gnome/16x16/apps/utilities-terminal.png" },
        { "Open file manager", filemgr, "/usr/share/icons/gnome/16x16/apps/system-file-manager.png" },
        { "Open browser", "firefox", "/usr/share/icons/hicolor/16x16/apps/firefox.png" },
        { "Open thunderbird", "thunderbird", "/usr/share/icons/hicolor/16x16/apps/thunderbird.png" },
    }
})
mymainmenu.theme.width = 150

mylauncher = awful.widget.launcher({
    image = icons.arch,
    menu = mymainmenu
})

-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
-- }}}

-- {{{ Widgets
separator = wibox.widget.textbox()
separator:set_text("  ")

systraywidget = systray()
systraywidget:toggle() -- Hide the systray
cpuwidget = widgets.cpu({ timeout = 3 })
memwidget = widgets.mem({ timeout = 3 })
volwidget = widgets.volume({ timeout = 5 })
batwidget = widgets.bat({ timeout = 61, battery = "BAT1", ac = "ACAD" })
tempwidget = widgets.temp({ timeout = 59, })
mpdwidget = widgets.mpd({ timeout = 3, notify = "off" })
brightwidget = widgets.brightness()
wiredwidget = widgets.wired({ autohide = true })
wifiwidget = widgets.wifi({ autohide = true })
fswidget = widgets.fs()

mytextclock = wibox.widget.textclock()
cal.register(mytextclock)

-- Keyboard map indicator and switcher
-- mykeyboardlayout = awful.widget.keyboardlayout()
-- }}}

-- {{{ Screen, Tag, Wibar Setup
-- Create a wibox for each screen and add it
local taglist_buttons = awful.util.table.join(
    awful.button({ }, 1, function(t) t:view_only() end),
    awful.button({ }, 3, awful.tag.viewtoggle),
    awful.button({ modkey }, 1, function(t)
        if client.focus then
            client.focus:move_to_tag(t)
        end
    end),
    awful.button({ modkey }, 3, function(t)
        if client.focus then
            client.focus:toggle_tag(t)
        end
    end),
    awful.button({ }, 4, function(t) awful.tag.viewprev(t.screen) end),
    awful.button({ }, 5, function(t) awful.tag.viewnext(t.screen) end)
)

local tasklist_buttons = awful.util.table.join(
     awful.button({ }, 1, function(c)
         if c == client.focus then
             c.minimized = true
         else
             -- Without this, the following
             -- :isvisible() makes no sense
             c.minimized = false
             if not c:isvisible() and c.first_tag then
                 c.first_tag:view_only()
             end
             -- This will also un-minimize
             -- the client, if needed
             client.focus = c
             c:raise()
         end
     end),
     awful.button({ }, 2, function(c) c:kill() end),
     awful.button({ }, 3, client_menu_toggle_fn()),
     awful.button({ }, 4, function() awful.client.focus.byidx(1) end),
     awful.button({ }, 5, function() awful.client.focus.byidx(-1) end)
)

-- Setup screens {{{
local function set_wallpaper(s)
    -- Wallpaper
    if beautiful.wallpaper then
        local wallpaper = beautiful.wallpaper
        -- If wallpaper is a function, call it with the screen
        if type(wallpaper) == "function" then
            wallpaper = wallpaper(s)
        end
        gears.wallpaper.centered(wallpaper, s)
    end
end

-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
screen.connect_signal("property::geometry", set_wallpaper)

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

    -- Each screen has its own tag table.
    awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[2])

    -- s.tags[2].layout = treetile

    -- Create a promptbox for each screen
    s.mypromptbox = awful.widget.prompt()
    -- Create an imagebox widget which will contains an icon indicating which layout we're using.
    -- We need one layoutbox per 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 the wibox
    s.mywibox = awful.wibar({ position = "top", screen = s })

    -- Add widgets to the wibox
    s.mywibox:setup {
        layout = wibox.layout.align.horizontal,
        { -- Left widgets
            layout = wibox.layout.fixed.horizontal,
            mylauncher,
            s.mytaglist,
            s.mypromptbox,
        },
        s.mytasklist, -- Middle widget
        { -- Right widgets
            layout = wibox.layout.fixed.horizontal,
            -- mykeyboardlayout,
            systraywidget.widget,
            separator,
            mpdwidget:get_container(),
            separator,
            wifiwidget:get_container(),
            wiredwidget:get_container(),
            -- separator,
            fswidget:get_container(),
            separator,
            brightwidget:get_container(),
            separator,
            tempwidget:get_container(),
            separator,
            volwidget:get_container(),
            separator,
            batwidget:get_container(),
            separator,
            memwidget:get_container(),
            separator,
            cpuwidget:get_container(),
            separator,
            mytextclock,
            s.mylayoutbox,
        },
    }

    -- Apply custom config
    if layoutconfig then
        layoutconfig(s)
    end
end)
-- }}}
-- }}}

-- {{{ Mouse bindings
root.buttons(awful.util.table.join(
    awful.button({ }, 3, function () mymainmenu:toggle() end)
    -- awful.button({ }, 4, awful.tag.viewnext),
    -- awful.button({ }, 5, awful.tag.viewprev)
))
-- }}}

-- {{{ Key bindings
local function switch_focus(dir)
    awful.client.focus.global_bydirection(dir)
    if client.focus then client.focus:raise() end
end

-- Global keys {{{
globalkeys = awful.util.table.join(
    -- awful.key({ modkey }, "s",      hotkeys_popup.show_help, {description="show help", group="awesome"}),

    awful.key({ "Mod1"          }, "Tab",
        function()
            local filter = function(c)
                return not c.minimized
            end

            local f = client.focus
            if f then
                for c in awful.client.iterate(filter, f.index, f.screen) do
                    client.focus = c
                    c:raise()
                end
            end
        end,
        { description = "cycle through clients", group = "client" }),

    -- Media keys {{{
    awful.key({ }, "XF86MonBrightnessDown", function() brightwidget:incBrightness(-5) end,
              { description = "decrease brightness", group = "media" }),

    awful.key({ }, "XF86MonBrightnessUp", function() brightwidget:incBrightness(5) end,
              { description = "increase brightness", group = "media" }),

    awful.key({}, "XF86AudioRaiseVolume", function() volwidget:changeVolume("1dB+") end,
              { description = "raise volume", group = "media" }),

    awful.key({}, "XF86AudioLowerVolume", function() volwidget:changeVolume("1dB-") end,
              { description = "lower volume", group = "media" }),

    awful.key({}, "XF86AudioMute", function() volwidget:toggleMute() end,
              { description = "mute", group = "media" }),

    awful.key({}, "XF86AudioStop", function()
            utils.async("mpc --wait stop", function(out) mpdwidget:update() end)
        end,
        { description = "stop", group = "media" }),

    awful.key({}, "XF86AudioNext", function()
            utils.async("mpc --wait next", function(out) mpdwidget:update() end)
        end,
        { description = "next", group = "media" }),

    awful.key({}, "XF86AudioPrev", function()
            utils.async("mpc --wait prev", function(out) mpdwidget:update() end)
        end,
        { description = "previous", group = "media" }),

    awful.key({}, "XF86AudioPlay", function() awful.spawn("mpc toggle") end,
        { description = "toggle play/pause", group = "media" }),
    -- }}}

    -- Screenshot
    awful.key({ },         "Print", function() utils.screenshot(mouse.screen.index) end,
              { description = "current screen", group = "screenshot" }),
    awful.key({ "Shift" }, "Print", function() utils.screenshot(-1) end,
              { description = "all screens", group = "screenshot" }),
    awful.key({ modkey },  "Print", function() utils.screenshot(0) end,
              { description = "selection", group = "screenshot" }),

    -- Open file explorer
    awful.key({ modkey }, "e", function() awful.spawn(filemgr) end,
              { description = "open file explorer", group = "launcher" }),
    awful.key({ modkey , "Shift" }, "e", function() awful.spawn.with_shell("urxvt -e python3 $(which ranger)") end,
              { description = "open ranger in urxvt", group = "launcher" }),

    -- Focus {{{
    awful.key({ modkey }, "Left",   awful.tag.viewprev, { description = "view previous", group = "tag" }),
    awful.key({ modkey }, "Right",  awful.tag.viewnext, { description = "view next", group = "tag" }),
    awful.key({ modkey }, "Escape", awful.tag.history.restore, { description = "go back", group = "tag" }),

    awful.key({ modkey }, "j", function() switch_focus("down") end,
        { description = "focus below", group = "client" }),
    awful.key({ modkey }, "k", function() switch_focus("up") end,
        { description = "focus above", group = "client" }),
    awful.key({ modkey }, "h", function() switch_focus("left") end,
        { description = "focus left", group = "client" }),
    awful.key({ modkey }, "l", function() switch_focus("right") end,
        { description = "focus right", group = "client" }),

    awful.key({ modkey, "Mod5" }, "j", function() awful.screen.focus_relative( 1) end,
        { description = "focus the next screen", group = "screen" }),
    awful.key({ modkey, "Mod5" }, "k", function() awful.screen.focus_relative(-1) end,
        { description = "focus the previous screen", group = "screen" }),
    awful.key({ modkey }, "u", awful.client.urgent.jumpto,
        { description = "jump to urgent client", group = "client" }),

    awful.key({ modkey }, "Tab",
        function()
            awful.client.focus.history.previous()
            if client.focus then
                client.focus:raise()
            end
        end,
        { description = "go back", group = "client" }),
    -- }}}

    -- Layout manipulation
    -- In-/Decrease num master/column {{{
    awful.key({ modkey, "Control" }, "k",
        function()
            awful.tag.incnmaster(1, nil, true)
            utils.notify(tostring(awful.tag.getnmaster()), "Master")
        end,
        { description = "increase the number of master clients", group = "layout" }),

    awful.key({ modkey, "Control" }, "j",
        function()
            awful.tag.incnmaster(-1, nil, true)
            utils.notify({ title = 'Master', text = tostring(awful.tag.getnmaster()), timeout = 1  })
        end,
        { description = "decrease the number of master clients", group = "layout" }),

    awful.key({ modkey, "Control" }, "h",
        function()
            awful.tag.incncol(1, nil, true)
            utils.notify({ title = 'Columns', text = tostring(awful.tag.getncol()), timeout = 1  })
        end,
        { description = "increase the number of columns", group = "layout" }),

    awful.key({ modkey, "Control" }, "l",
        function()
            awful.tag.incncol(-1, nil, true)
            utils.notify({ title = 'Columns', text = tostring(awful.tag.getncol()), timeout = 1  })
        end,
        { description = "decrease the number of columns", group = "layout" }),
    -- }}}

    awful.key({ modkey,           }, "space", function() awful.layout.inc( 1) end,
              {description = "select next", group = "layout"}),
    awful.key({ modkey, "Shift"   }, "space", function() awful.layout.inc(-1) end,
              {description = "select previous", group = "layout"}),

    -- Standard program
    awful.key({ modkey            }, "w", function() mymainmenu:show() end, { description = "show main menu", group = "awesome" }),
    awful.key({ modkey            }, "Return", function() awful.spawn(terminal) end, { description = "open a terminal", group = "launcher" }),
    awful.key({ modkey, "Control" }, "r", awesome.restart, { description = "reload awesome", group = "awesome" }),
    awful.key({ modkey, "Shift"   }, "q", awesome.quit, { description = "quit awesome", group = "awesome" }),

    awful.key({ modkey, "Shift" }, "j", function() awful.client.swap.global_bydirection("down") end,
        { description = "swap with client below", group = "client" }),
    awful.key({ modkey, "Shift" }, "k", function() awful.client.swap.global_bydirection("up") end,
        { description = "swap with client above", group = "client" }),
    awful.key({ modkey, "Shift" }, "h", function() awful.client.swap.global_bydirection("left") end,
        { description = "swap with client left", group = "client" }),
    awful.key({ modkey, "Shift" }, "l", function() awful.client.swap.global_bydirection("right") end,
        { description = "swap with client right", group = "client" }),

    awful.key({ modkey, "Control" }, "n",
        function()
            local c = awful.client.restore()
            -- Focus restored client
            if c then
                client.focus = c
                c:raise()
            end
        end,
        { description = "restore minimized", group = "client" }),

    -- Prompt
    awful.key({ modkey }, "r", function() awful.screen.focused().mypromptbox:run() end,
        { description = "run prompt", group = "launcher" }),

    awful.key({ modkey }, "x",
        function ()
            awful.prompt.run {
                prompt       = "Run Lua code: ",
                textbox      = awful.screen.focused().mypromptbox.widget,
                exe_callback = awful.util.eval,
                history_path = awful.util.get_cache_dir() .. "/history_eval"
            }
        end,
        { description = "lua execute prompt", group = "awesome" }),

    -- Menubar
    -- awful.key({ modkey }, "p", function() menubar.show() end,
    --     { description = "show the menubar", group = "launcher" }),

    awful.key({ modkey }, "p", function() awful.spawn("albert show") end,
        { description = "open application launcher", group = "launcher" }),

    -- Toggle systray visibility
    awful.key({ modkey, "Control" }, "s", function() systraywidget:toggle() end,
              { description = "toggle systray visibility", group = "media" })
)
-- }}}

-- Client keys {{{
clientkeys = awful.util.table.join(
{'fraction_non_alphanumeric': 0.15075232987973136, 'fraction_numerical': 0.005518821263081168, 'mean_word_length': 2.5529966703662597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7186571', 'n_tokens_mistral': 11873, 'n_tokens_neox': 11730, 'n_words': 2904}