You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
5.7 KiB
154 lines
5.7 KiB
-- This file is part of Reno desktop.
|
|
--
|
|
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
--
|
|
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
--
|
|
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
|
|
local awful = require("awful")
|
|
local gears = require("gears")
|
|
local awmtk2 = require("awmtk2")
|
|
local beautiful = require("beautiful")
|
|
local wibox = require("wibox")
|
|
local json = require("dkjson")
|
|
local try_blur = require("imagemagick_blur")
|
|
local ask = require("asckey")
|
|
|
|
local bgimagegen = function(path)
|
|
return function(cont,cr,width,height)
|
|
local s = gears.surface.load_uncached_silently(
|
|
path
|
|
)
|
|
local bg_width,bg_height = gears.surface.get_size(s)
|
|
local scale = height/bg_height
|
|
if width/bg_width > scale then
|
|
scale = width/bg_width
|
|
end
|
|
cr:translate((width - (bg_width*scale))/2,(height - (bg_height*scale))/2)
|
|
cr:rectangle(0,0, (bg_width*scale), (bg_height*scale))
|
|
cr:clip()
|
|
cr:scale(scale,scale)
|
|
cr:set_source_surface(s)
|
|
cr:paint()
|
|
end
|
|
end
|
|
local function _preload(args)
|
|
local style = awmtk2.create_style("supermenu",
|
|
awmtk2.generic.composite_widget,{})
|
|
local templates = awmtk2.create_template_lib("supermenu",awmtk2.templates,{})
|
|
local t = awmtk2.build_templates(templates,style,args.vertical)
|
|
local wallpaper
|
|
if gears.filesystem.file_readable(root_path.."/wallpaper.txt") then
|
|
local wallpaper_f = io.open(root_path.."/wallpaper.txt","r")
|
|
wallpaper = wallpaper_f:read("*a")
|
|
wallpaper_f:close()
|
|
end
|
|
supermenu = awful.popup(t.popup({
|
|
{
|
|
{
|
|
widget = wibox.container.background
|
|
},
|
|
{
|
|
layout = wibox.layout.flex.vertical,
|
|
id = "contents"
|
|
},
|
|
{
|
|
t.container({
|
|
id = "buttonlist",
|
|
layout = wibox.layout.fixed.vertical
|
|
},{
|
|
bg = style.container.bg_highlight
|
|
}),
|
|
valign = "center",
|
|
halign = "right",
|
|
fill_vertical = true,
|
|
fill_horizontal = false,
|
|
widget = wibox.container.place
|
|
},
|
|
layout = wibox.layout.align.horizontal
|
|
},
|
|
widget = wibox.container.background,
|
|
forced_width = args.screen.workarea.width-style.popup.margins,
|
|
forced_height = args.screen.workarea.height-style.popup.margins,
|
|
id = "supermenu_root"
|
|
},{
|
|
x = args.screen.workarea.x,
|
|
y = args.screen.workarea.y,
|
|
visible = false
|
|
}))
|
|
local supermenu_root = supermenu.widget:get_children_by_id("supermenu_root")[1]
|
|
if style.popup.transparent then
|
|
if not awesome.composite_manager_running then
|
|
-- Really slow but the effect is ok
|
|
supermenu_root.bgimage = bgimagegen(try_blur(wallpaper or beautiful.wallpaper,
|
|
function(path)
|
|
supermenu_root.bgimage = bgimagegen(path)
|
|
end))
|
|
else
|
|
-- Let the compositor handle transparency
|
|
supermenu_root.bg = style.popup.bg_normal.."66"
|
|
supermenu.widget.bg = "#00000000"
|
|
end
|
|
end
|
|
args.screen:connect_signal("property::workarea",function()
|
|
supermenu.x = args.screen.workarea.x
|
|
supermenu.y = args.screen.workarea.y
|
|
supermenu_root.forced_width = args.screen.workarea.width-style.popup.margins*2
|
|
supermenu_root.forced_height = args.screen.workarea.height-style.popup.margins*2
|
|
end)
|
|
supermenu:connect_signal("button::press",function(self,x,y,button)
|
|
if button == 3 then
|
|
supermenu.visible = false
|
|
end
|
|
end)
|
|
local tabsfile = io.open(root_path.."/themes/"..global.theme..'/config/supermenu.json',"r")
|
|
local contents = supermenu.widget:get_children_by_id("contents")[1]
|
|
local buttonlist = supermenu.widget:get_children_by_id("buttonlist")[1]
|
|
local tabs = {}
|
|
local tab_icons = {}
|
|
local function gen_buttons(tab_id,icon)
|
|
local button = wibox.widget({
|
|
image = icon,
|
|
resize = true,
|
|
widget = wibox.widget.imagebox,
|
|
forced_width = style.icon.width,
|
|
forced_height = style.icon.height
|
|
})
|
|
button:connect_signal("button::press",function()
|
|
contents:set(1,tabs[tab_id])
|
|
end)
|
|
return button
|
|
end
|
|
if tabsfile then
|
|
for k,v in pairs(json.decode(tabsfile:read("*a"))) do
|
|
local widget,icon = require(k)(v)
|
|
print(widget,icon)
|
|
table.insert(tab_icons,icon or beautiful.icon_default)
|
|
table.insert(tabs,widget)
|
|
end
|
|
end
|
|
if tabs[1] then
|
|
contents:add(tabs[1])
|
|
end
|
|
for k,_ in pairs(tabs) do
|
|
buttonlist:add(gen_buttons(k,tab_icons[k]))
|
|
end
|
|
root.keys(gears.table.join(
|
|
root.keys(),
|
|
ask.k(":supermenu.open",function()
|
|
supermenu.visible = not supermenu.visible
|
|
end,{
|
|
description = "open supermenu",
|
|
group = "widgets"
|
|
})
|
|
))
|
|
return supermenu
|
|
end
|
|
return function(args)
|
|
for s in screen do
|
|
s.lock = _preload(gears.table.join(args,{
|
|
screen = s
|
|
}))
|
|
end
|
|
end
|
|
|