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.
223 lines
7.4 KiB
223 lines
7.4 KiB
local awful = require("awful")
|
|
local gears = require("gears")
|
|
local awmtk2 = require("awmtk2")
|
|
local wibox = require("wibox")
|
|
local beautiful = require("beautiful")
|
|
|
|
local icon = beautiful["applications-tab-symbolic"]
|
|
|
|
local xdg_search = function(name,rlimit,sorting_method)
|
|
local ranked_results = {}
|
|
if sorting_method == "usage" then
|
|
local filter = {}
|
|
local keys = {}
|
|
for k,v in pairs(xdg.apps) do
|
|
if not v.count then
|
|
v.count = 0
|
|
end
|
|
if v.name:lower():find(name,nil,true) then
|
|
if not filter[v.count] then
|
|
table.insert(keys, v.count)
|
|
filter[v.count] = {}
|
|
end
|
|
table.insert(filter[v.count],{k,v})
|
|
end
|
|
end
|
|
table.sort(keys,function(a,b) return a > b end)
|
|
local count = 0
|
|
local exit = false
|
|
for k = 1,rlimit do
|
|
local i = keys[k]
|
|
if not filter[i] then
|
|
break
|
|
end
|
|
for _,v in pairs(filter[i]) do
|
|
table.insert(ranked_results, v)
|
|
count = count + 1
|
|
if count >= rlimit then
|
|
exit = true
|
|
break
|
|
end
|
|
end
|
|
if exit == true then
|
|
break
|
|
end
|
|
end
|
|
elseif sorting_method == "recent" then
|
|
local most_recent = 0
|
|
for k,v in pairs(xdg.apps) do
|
|
if v.name:lower():find(name,nil,true) and v.atime and v.atime >= most_recent then
|
|
most_recent = v.atime
|
|
table.insert(ranked_results,1,{k,v})
|
|
end
|
|
if #ranked_results > rlimit then
|
|
table.remove(ranked_results,rlimit+1)
|
|
end
|
|
end
|
|
end
|
|
return ranked_results
|
|
end
|
|
|
|
|
|
return function(args)
|
|
local style = awmtk2.create_style("applications_tab",
|
|
awmtk2.generic.menu, args.style, args.vertical)
|
|
local templates = awmtk2.create_template_lib("applications_tab",
|
|
awmtk2.templates,args.templates)
|
|
local t = awmtk2.build_templates(templates,style,args.vertical)
|
|
args.rows = args.rows or 8
|
|
args.columns = args.columns or 6
|
|
local widget = wibox.widget({
|
|
{
|
|
{
|
|
t.center(t.container(
|
|
t.container({
|
|
widget = wibox.widget.textbox,
|
|
markup = "Search",
|
|
id = "searchtext"
|
|
},{
|
|
id = "searchbox",
|
|
bg = style.container.bg_highlight,
|
|
forced_width = 240
|
|
})
|
|
)),
|
|
t.center(
|
|
t.container({
|
|
t.button(
|
|
t.textbox({
|
|
markup = "Most used"
|
|
}),{
|
|
id = "usage"
|
|
}
|
|
),
|
|
t.button(
|
|
t.textbox({
|
|
markup = "Recent"
|
|
}),{
|
|
id = "recent"
|
|
}
|
|
),
|
|
layout = wibox.layout.flex.horizontal,
|
|
spacing = style.base.spacing,
|
|
forced_width = 240
|
|
},{
|
|
bg = "#00000000"
|
|
})
|
|
),
|
|
layout = wibox.layout.fixed.vertical,
|
|
spacing = style.base.spacing,
|
|
},
|
|
{
|
|
{
|
|
layout = wibox.layout.grid,
|
|
forced_num_cols = args.columns,
|
|
homogenous = true,
|
|
expand = true,
|
|
vertical_expand = true,
|
|
orientation = "veritcal",
|
|
spacing = style.base.spacing,
|
|
id = "appgrid"
|
|
},
|
|
margins = 20,
|
|
widget = wibox.container.margin
|
|
},
|
|
{
|
|
widget = wibox.container.background
|
|
},
|
|
layout = wibox.layout.align.vertical,
|
|
spacing = style.base.spacing,
|
|
expand = "inside",
|
|
id = "root_ratio"
|
|
},
|
|
widget = wibox.container.margin,
|
|
margins = 20
|
|
})
|
|
local sorting_method = "usage"
|
|
local recent_sort = widget:get_children_by_id("recent")[1]
|
|
local usage_sort = widget:get_children_by_id("usage")[1]
|
|
local searchbox = widget:get_children_by_id("searchbox")[1]
|
|
local searchtext = widget:get_children_by_id("searchtext")[1]
|
|
usage_sort:connect_signal("button::press",function()
|
|
recent_sort:set_bg(style.bg_normal)
|
|
if style.button.onrelease then
|
|
style.button.onrelease(recent_sort)
|
|
end
|
|
usage_sort:set_bg(style.bg_focus)
|
|
if style.button.onpress then
|
|
style.button.onpress(usage_sort)
|
|
end
|
|
sorting_method = "usage"
|
|
end)
|
|
recent_sort:connect_signal("button::press",function()
|
|
usage_sort:set_bg(style.bg_normal)
|
|
if style.button.onrelease then
|
|
style.button.onrelease(usage_sort)
|
|
end
|
|
recent_sort:set_bg(style.bg_focus)
|
|
if style.button.onpress then
|
|
style.button.onpress(recent_sort)
|
|
end
|
|
sorting_method = "recent"
|
|
end)
|
|
local appgrid = widget:get_children_by_id("appgrid")[1]
|
|
local icon_cache = gears.cache(function(icon,title,exec)
|
|
local appicon = wibox.widget({
|
|
t.icon({
|
|
image = icon or beautiful.icon_default,
|
|
}),
|
|
{
|
|
markup = title,
|
|
widget = wibox.widget.textbox,
|
|
align = "center"
|
|
},
|
|
spacing = style.base.spacing,
|
|
layout = wibox.layout.fixed.vertical
|
|
})
|
|
appicon:connect_signal("button::press",function(_,_,_,button)
|
|
if button == 1 then
|
|
supermenu.visible = false
|
|
awful.spawn(exec)
|
|
end
|
|
end)
|
|
return appicon
|
|
end)
|
|
local prompt_open = false
|
|
supermenu:connect_signal("property::visible",function()
|
|
if prompt_open then
|
|
awful.keygrabber.stop()
|
|
prompt_open = false
|
|
end
|
|
end)
|
|
searchbox:connect_signal("button::press",function()
|
|
prompt_open = true
|
|
awful.prompt.run {
|
|
textbox = searchtext,
|
|
exe_callback = function(command)
|
|
local results = xdg_search(command, args.rows*args.columns, sorting_method)
|
|
appgrid:reset()
|
|
for _,v in pairs(results) do
|
|
appgrid:add(icon_cache:get(
|
|
v[2].icon or beautiful.icon_default,
|
|
v[2].name,
|
|
v[2].exec
|
|
))
|
|
end
|
|
end,
|
|
done_callback = function()
|
|
prompt_open = false
|
|
searchtext:set_markup("Search")
|
|
end
|
|
}
|
|
end)
|
|
awesome.connect_signal("xdg::all_finished",function()
|
|
local count = 0
|
|
for _,v in pairs(xdg.apps) do
|
|
count = count + 1
|
|
appgrid:add(icon_cache:get(v.icon or beautiful.icon_default,v.name,v.exec))
|
|
if count >= args.columns*args.rows then
|
|
break
|
|
end
|
|
end
|
|
end)
|
|
return widget,icon
|
|
end
|