awesome-switcherpopup/init.lua

191 lines
6.5 KiB
Lua

local awful = require("awful")
local wibox = require("wibox")
local gears = require("gears")
local beautiful = require("beautiful")
local longpress = require("awesome-longpress")
local batterystat = require("awesome-batterystat")
local memstat = require("awesome-memwidget")
local fswidget = require("awesome-fswidget")
local switcherpopup = {
iconSize = 128,
systraySize = 64,
buttonSize = 96,
spacing = 5,
defaultLayout = awful.layout.suit.max,
iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-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{
layout = wibox.layout.fixed.vertical,
wibox.widget{
widget = wibox.widget.textbox,
align = "center",
text = "time"
},
wibox.widget{
widget = wibox.widget.textbox,
align = "center",
text = "date"
}
})
function clock.update(self)
self.widget.children[1].markup = string.format('<span size="xx-large">%s</span>',os.date("%H:%M"))
self.widget.children[2].markup = os.date("%Y-%m-%d")
end
local tagindex = wibox.widget({widget = wibox.widget.textbox, align = "center", valign = "center"})
local indicators = wibox.widget({layout=wibox.layout.grid.horizontal, spacing=5, mem, battery})
local unpack = unpack or table.unpack -- in Lua 5.1, table.unpack was just called 'unpack'
for k,v in ipairs({memstat, batterystat, fswidget}) do
indicators:add(unpack(v.all()))
end
local function updateSwitcherpopup()
clock:update()
tagindex.markup = '<span size="xx-large" color="'..tostring(beautiful.bg_normal)..'">'..tostring(awful.screen.focused().selected_tag.name)..'</span>'
for k,v in ipairs(indicators.children) do
pcall(v.update, v)
end
tasklistWidget:reset()
tasklistWidget.forced_num_cols = math.min(math.floor(s.geometry.width / (switcherpopup.iconSize + switcherpopup.spacing)), #awful.screen.focused().selected_tag:clients())
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 updateTimer = gears.timer{
timeout = 60,
callback = updateSwitcherpopup
}
local function pictureButton(icon,fn,lfn)
local rc = 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)
longpress.add(rc,fn,lfn)
return wibox.container.place(rc)
end
local close_button = pictureButton("window-close.svg",
function()
if s.clients[1] then
s.clients[1]:kill()
popup.visible = false
end
end
)
local create_tag_button = pictureButton("tag-create.svg",
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",
function()
if #s.tags > 1 then
s.selected_tag:delete()
popup.visible = false
end
end
)
local prev_tag_button = pictureButton("go-previous.svg",
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",
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
end
end
)
local tagbuttons = wibox.widget({layout = wibox.layout.grid.horizontal, prev_tag_button,create_tag_button,wibox.widget{layout=wibox.layout.stack, destroy_tag_button, tagindex},next_tag_button,close_button})
systray:set_screen(s)
systray:set_horizontal(true)
popup = awful.popup {
widget = {layout = wibox.layout.fixed.vertical, clock, wibox.container.place(indicators), wibox.container.place(systray), wibox.container.place(tasklistWidget), wibox.container.place(tagbuttons)},
border_color = beautiful.border_focus,
border_width = 2,
ontop = true,
placement = awful.placement.centered,
visible = false,
}
function popup.show(self)
updateSwitcherpopup()
self.visible = true
updateTimer:again()
end
function popup.hide(self)
self.visible = false
updateTimer:stop()
end
function popup.toggle(self)
updateSwitcherpopup()
self.visible = not self.visible
if self.visible then
updateTimer:again()
else
updateTimer:stop()
end
end
return popup
end
return switcherpopup