local awibar = require 'awful.wibar' local awful = require 'awful' local beautiful = require 'beautiful' local wibox = require 'wibox' local mymainmenu = require 'rc.ui.menu.mymainmenu' local capi = { client = _G.client, screen = _G.screen } local modkey = 'Mod4' local bar = { _private = { instances = {} }, mt = {} } local function get_screen_id(screen) local s = capi.screen[screen] or screen return s.index end -- Get the bar instance for a given screen function bar:instance(screen) local screen_id = get_screen_id(screen) local instance = self._private.instances[screen_id] if not instance then instance = bar.new(screen) self._private.instances[screen_id] = instance end return instance end function bar.new (screen) local my_bar = {} my_bar.wibar = awibar { screen = screen, position = 'top' } my_bar.launcher = awful.widget.launcher { image = beautiful.awesome_icon, menu = mymainmenu() } my_bar.keyboardlayout = awful.widget.keyboardlayout() my_bar.textclock = wibox.widget.textclock() my_bar.promptbox = awful.widget.prompt() my_bar.layoutbox = awful.widget.layoutbox { screen = screen, buttons = { 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), } } my_bar.taglist = awful.widget.taglist { screen = screen, filter = awful.widget.taglist.filter.all, buttons = { awful.button({}, 1, function(tag) tag:view_only() end), awful.button({ modkey }, 1, function(tag) if capi.client.focus then capi.client.focus:move_to_tag(tag) end end), awful.button({}, 3, awful.tag.viewtoggle), awful.button({ modkey }, 3, function(tag) if capi.client.focus then capi.client.focus:toggle_tag(tag) end end), awful.button({ }, 4, function(tag) awful.tag.viewprev(tag.screen) end), awful.button({ }, 5, function(tag) awful.tag.viewnext(tag.screen) end) } } my_bar.tasklist = awful.widget.tasklist { screen = screen, filter = awful.widget.tasklist.filter.currenttags, buttons = { awful.button({ }, 1, function (c) c:activate { context = "tasklist", action = "toggle_minimization" } end), awful.button({ }, 3, function() awful.menu.client_list { theme = { width = 250 } } end), awful.button({ }, 4, function() awful.client.focus.byidx(-1) end), awful.button({ }, 5, function() awful.client.focus.byidx( 1) end), } } my_bar.wibar:setup { layout = wibox.layout.align.horizontal, { -- Left widgets layout = wibox.layout.fixed.horizontal, my_bar.launcher, my_bar.taglist, my_bar.promptbox, }, screen.mytasklist, -- Middle widget { -- Right widgets layout = wibox.layout.fixed.horizontal, my_bar.keyboardlayout, wibox.widget.systray(), my_bar.textclock, my_bar.layoutbox, } } return my_bar end function bar.mt:__call(...) return self:instance(...) end return setmetatable(bar, bar.mt)