local awful = require("awful") local wibox = require("wibox") local gears = require("gears") local beautiful = require("beautiful") local switcherpopup = { iconSize = 128, systraySize = 64, buttonSize = 96, spacing = 5, defaultLayout = awful.layout.suit.max, iconPath = gears.filesystem.get_configuration_dir() .. "/switcherpopup/" } function switcherpopup.nextTagName(s) print(#s.tags, #s.tags+1) return tostring(#s.tags+1) end local systray = wibox.widget.systray() systray:set_base_size(switcherpopup.systraySize) function switcherpopup.new(s) local popup = false local tasklistWidget = wibox.widget{ screen = s, layout = wibox.layout.grid.vertical(math.floor(s.geometry.width / (switcherpopup.iconSize + switcherpopup.spacing))) } local clock = wibox.container.place(wibox.widget.textclock("%H:%M %Y-%m-%d"), "center", "center") local tagindex = wibox.widget({widget = wibox.widget.textbox, align = "center"}) local function updateSwitcherpopup() tagindex.text = "Tag: "..tostring(awful.screen.focused().selected_tag.name) local fp, fs = io.open("/sys/class/power_supply/axp20x-battery/capacity","rb"), io.open("/sys/class/power_supply/axp20x-battery/status","rb") if fp and fs then local status = fs:read() tagindex.text = string.format("Battery: %s%%%s\n%s", fp:read(), status == "Charging" and "+" or "-", tagindex.text) fp:close() fs:close() end tasklistWidget:reset() for k,v in pairs(awful.screen.focused().selected_tag:clients()) do local clientIcon = awful.widget.clienticon(v) clientIcon:set_forced_width(switcherpopup.iconSize) clientIcon:set_forced_height(switcherpopup.iconSize) clientIcon:buttons(gears.table.join( awful.button({ }, 1, function (c) v:raise() popup.visible = false end))) if v == client.focus then tasklistWidget:add(wibox.widget{clientIcon,bg=beautiful.get().tasklist_bg_focus or beautiful.get().bg_focus,widget=wibox.container.background}) else tasklistWidget:add(clientIcon) end end end screen.connect_signal("arrange",updateSwitcherpopup) local close_button = wibox.container.place(awful.widget.button({image = switcherpopup.iconPath .. "/window-close.png"}), "center", "center") close_button:buttons(gears.table.join( close_button:buttons(), awful.button({}, 1, nil, function() if s.clients[1] then s.clients[1]:kill() popup.visible = false end end) )) local create_tag_button = wibox.container.place(awful.widget.button({image = switcherpopup.iconPath .. "/tag-new.png"}), "center", "center") create_tag_button:buttons(gears.table.join( create_tag_button:buttons(), awful.button({}, 1, nil, function() awful.tag.add(switcherpopup.nextTagName(s), { screen = s, layout = switcherpopup.defaultLayout }):view_only() popup.visible = false end) )) local destroy_tag_button = wibox.container.place(awful.widget.button({image = switcherpopup.iconPath .. "remove.png"}), "center", "center") destroy_tag_button:buttons(gears.table.join( destroy_tag_button:buttons(), awful.button({}, 1, nil, function() if #s.tags > 1 then s.selected_tag:delete() popup.visible = false end end) )) local prev_tag_button = wibox.container.place(awful.widget.button({image = switcherpopup.iconPath .. "/go-previous.png"}), "center", "center") prev_tag_button:buttons(gears.table.join( prev_tag_button:buttons(), awful.button({}, 1, nil, function() awful.tag.viewprev(s) popup.visible = false end) )) local next_tag_button = wibox.container.place(awful.widget.button({image = switcherpopup.iconPath .. "/go-next.png"}), "center", "center") next_tag_button:buttons(gears.table.join( next_tag_button:buttons(), awful.button({}, 1, nil, function() awful.tag.viewnext(s) popup.visible = false end) )) local tagbuttons = wibox.widget({layout = wibox.layout.fixed.horizontal, spacing = (switcherpopup.iconSize + switcherpopup.spacing) - switcherpopup.buttonSize, prev_tag_button, create_tag_button, destroy_tag_button, next_tag_button, close_button}) systray:set_screen(s) systray:set_horizontal(true) popup = awful.popup { widget = {layout = wibox.layout.fixed.vertical, clock, tagindex, systray, tasklistWidget, wibox.container.constraint(tagbuttons, min, switcherpopup.buttonSize*5, switcherpopup.buttonSize)}, border_color = beautiful.border_focus, border_width = 2, ontop = true, placement = awful.placement.centered, visible = false, } function popup.show(self) updateSwitcherpopup() self.visible = true end function popup.hide(self) self.visible = false end function popup.toggle(self) updateSwitcherpopup() self.visible = not self.visible end return popup end return switcherpopup