awesome-switcherpopup/init.lua

162 lines
5.9 KiB
Lua

local awful = require("awful")
local wibox = require("wibox")
local gears = require("gears")
local beautiful = require("beautiful")
local longpress = require("awesome-longpress")
local switcherpopup = {
iconSize = 128,
systraySize = 64,
buttonSize = 96,
spacing = 5,
defaultLayout = awful.layout.suit.max,
iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-switcherpopup/",
batteryPath = "/sys/class/power_supply/pad-battery/"
}
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(switcherpopup.batteryPath .. "/capacity","rb"), io.open(switcherpopup.batteryPath .. "/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)
clientName = wibox.container.constraint(wibox.widget{
widget = wibox.widget.textbox,
valign = center,
halign = center,
text = v.name
},nil,switcherpopup.iconSize,switcherpopup.iconSize * 0.5)
clientWidget = wibox.widget{
layout = wibox.layout.fixed.vertical
}
clientWidget:add(clientIcon,clientName)
clientWidget:buttons(gears.table.join(
awful.button({ }, 1, function (c)
v:raise()
popup.visible = false
end)))
if v == client.focus then
tasklistWidget:add(wibox.widget{wibox.container.constraint(clientWidget,nil,switcherpopup.iconSize,switcherpopup.iconSize * 1.5),bg=beautiful.get().tasklist_bg_focus or beautiful.get().bg_focus,widget=wibox.container.background})
else
tasklistWidget:add(wibox.container.constraint(clientWidget,nil,switcherpopup.iconSize,switcherpopup.iconSize * 1.5))
end
end
end
screen.connect_signal("arrange",updateSwitcherpopup)
local function pictureButton(icon)
local rc = wibox.container.place(wibox.container.constraint(wibox.widget({
widget=wibox.widget.imagebox,
forced_width = switcherpopup.buttonSize,
forced_height = switcherpopup.buttonSize,
image = switcherpopup.iconPath .. "/" .. icon
}),nil,switcherpopup.buttonSize,switcherpopup.buttonSize), "center", "top")
rc.content_fill_vertical = true
rc.content_fill_horizontal = true
return rc
end
local close_button = pictureButton("window-close.svg")
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 = pictureButton("tag-create.svg")
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 = pictureButton("tag-destroy.svg")
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 = pictureButton("go-previous.svg")
longpress.add(prev_tag_button, function()
awful.tag.viewprev(s)
popup.visible = false
end, function()
if s.clients[1] and s.selected_tag then
local nextTag = s.selected_tag.index-1
if nextTag < 1 then nextTag = #s.tags end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
error("move attempted")
end
error("move failed?")
end)
local next_tag_button = pictureButton("go-next.svg")
longpress.add(next_tag_button, function()
awful.tag.viewnext(s)
popup.visible = false
end, function()
if s.clients[1] and s.selected_tag then
local nextTag = s.selected_tag.index+1
if nextTag > #s.tags then nextTag = 1 end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
error("move attempted")
end
error("move failed?")
end)
local tagbuttons = wibox.widget({layout = wibox.layout.ratio.horizontal, spacing=0, 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