improvements
This commit is contained in:
parent
72594b51ee
commit
9f0bba0c2c
|
@ -12,6 +12,7 @@
|
|||
"items": [
|
||||
{
|
||||
"icon": "https://avatars.githubusercontent.com/u/9363150?s=60&v=4/2x/circled-down--v2.png",
|
||||
"icon_height": 40,
|
||||
"title": "Say hi!",
|
||||
"onclick": "notify-send 'hi!'"
|
||||
},
|
||||
|
@ -24,6 +25,12 @@
|
|||
"icon": "slack",
|
||||
"title": "OpenSlack",
|
||||
"onclick": "xdg-open https://slack.com"
|
||||
},
|
||||
{
|
||||
"title": "-"
|
||||
},
|
||||
{
|
||||
"title": "Menu item with no icon",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
74
init.lua
74
init.lua
|
@ -6,6 +6,8 @@ local gears = require("gears")
|
|||
local json = require("json")
|
||||
local gfs = require("gears.filesystem")
|
||||
local spawn = require("awful.spawn")
|
||||
local naughty = require("naughty")
|
||||
local row_builder = require("noobie.row_builder")
|
||||
|
||||
|
||||
local HOME_DIR = os.getenv("HOME")
|
||||
|
@ -46,6 +48,8 @@ local function worker(user_args)
|
|||
end,
|
||||
border_width = 1,
|
||||
border_color = beautiful.bg_focus,
|
||||
width = 200,
|
||||
minimum_width = 100,
|
||||
maximum_width = 400,
|
||||
offset = { y = 5 },
|
||||
widget = {}
|
||||
|
@ -98,7 +102,7 @@ local function worker(user_args)
|
|||
if new_icon:sub(1, 1) == '/' then
|
||||
self:get_children_by_id('icn')[1]:set_image(new_icon)
|
||||
|
||||
-- new_icon is a url of the icon
|
||||
-- new_icon is a url to the icon
|
||||
elseif new_icon:sub(1, 4) == 'http' then
|
||||
local icon_path = CACHE_DIR .. '/' .. new_icon:sub(-16)
|
||||
if not gfs.file_readable(icon_path) then
|
||||
|
@ -140,73 +144,7 @@ local function worker(user_args)
|
|||
for i = 0, #rows do rows[i]=nil end
|
||||
for _, item in ipairs(result.menu.items) do
|
||||
|
||||
local item_image = wibox.widget{
|
||||
resize = true,
|
||||
forced_height = 20,
|
||||
forced_width = 20,
|
||||
widget = wibox.widget.imagebox
|
||||
}
|
||||
|
||||
-- new_icon is a path to a file
|
||||
if item.icon:sub(1, 1) == '/' then
|
||||
item_image:set_image(item.icon)
|
||||
|
||||
-- new_icon is a url of the icon
|
||||
elseif item.icon:sub(1, 4) == 'http' then
|
||||
local icon_path = CACHE_DIR .. '/' .. item.icon:sub(-16)
|
||||
if not gfs.file_readable(icon_path) then
|
||||
local download_cmd = string.format([[sh -c "curl -n --create-dirs -o %s %s"]], icon_path, item.icon)
|
||||
print(download_cmd)
|
||||
spawn.easy_async(download_cmd,
|
||||
function() item_image:set_image(icon_path) end)
|
||||
else
|
||||
item_image:set_image(icon_path)
|
||||
end
|
||||
|
||||
-- new_icon is a feather icon
|
||||
else
|
||||
item_image:set_image(ICONS_DIR .. item.icon .. '.svg')
|
||||
end
|
||||
|
||||
local row = wibox.widget {
|
||||
{
|
||||
{
|
||||
item_image,
|
||||
{
|
||||
text = item.title,
|
||||
font = font,
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
spacing = 12,
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
margins = 8,
|
||||
layout = wibox.container.margin
|
||||
},
|
||||
bg = beautiful.bg_normal,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
local old_cursor, old_wibox
|
||||
row:connect_signal("mouse::enter", function(c)
|
||||
c:set_bg(beautiful.bg_focus)
|
||||
local wb = mouse.current_wibox
|
||||
old_cursor, old_wibox = wb.cursor, wb
|
||||
wb.cursor = "hand1"
|
||||
end)
|
||||
row:connect_signal("mouse::leave", function(c)
|
||||
c:set_bg(beautiful.bg_normal)
|
||||
if old_wibox then
|
||||
old_wibox.cursor = old_cursor
|
||||
old_wibox = nil
|
||||
end
|
||||
end)
|
||||
|
||||
row:buttons(gears.table.join(awful.button({}, 1, function()
|
||||
awful.spawn.with_shell(item.onclick)
|
||||
widget:set_bg(background)
|
||||
noobie_popup.visible = not noobie_popup.visible
|
||||
end)))
|
||||
local row = row_builder:build_row(item, widget, noobie_popup)
|
||||
|
||||
table.insert(rows, row)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
local awful = require("awful")
|
||||
local wibox = require("wibox")
|
||||
local beautiful = require("beautiful")
|
||||
local gears = require("gears")
|
||||
local gfs = require("gears.filesystem")
|
||||
local spawn = require("awful.spawn")
|
||||
|
||||
local HOME_DIR = os.getenv("HOME")
|
||||
local WIDGET_DIR = HOME_DIR .. '/.config/awesome/noobie'
|
||||
local ICONS_DIR = WIDGET_DIR .. '/feather_icons/'
|
||||
local CACHE_DIR = os.getenv("HOME") .. '/.cache/noobie/icons'
|
||||
|
||||
local row_builder = {}
|
||||
|
||||
local function build_header_row(item)
|
||||
return wibox.widget {
|
||||
{
|
||||
{
|
||||
markup = "<span foreground='#888888'>" .. item.title .. "</span>",
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
left = 8,
|
||||
layout = wibox.container.margin
|
||||
},
|
||||
bg = beautiful.bg_normal,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
end
|
||||
|
||||
local function build_icon_and_text_row(item, widget, noobie_popup)
|
||||
local item_image = wibox.widget{
|
||||
resize = true,
|
||||
forced_height = item.icon_size or 20,
|
||||
forced_width = item.icon_size or 20 ,
|
||||
widget = wibox.widget.imagebox
|
||||
}
|
||||
|
||||
-- new_icon is a path to a file
|
||||
if item.icon:sub(1, 1) == '/' then
|
||||
item_image:set_image(item.icon)
|
||||
|
||||
-- new_icon is a url of the icon
|
||||
elseif item.icon:sub(1, 4) == 'http' then
|
||||
local icon_path = CACHE_DIR .. '/' .. item.icon:sub(-16)
|
||||
if not gfs.file_readable(icon_path) then
|
||||
local download_cmd = string.format([[sh -c "curl -n --create-dirs -o %s %s"]], icon_path, item.icon)
|
||||
print(download_cmd)
|
||||
spawn.easy_async(download_cmd,
|
||||
function() item_image:set_image(icon_path) end)
|
||||
else
|
||||
item_image:set_image(icon_path)
|
||||
end
|
||||
|
||||
-- new_icon is a feather icon
|
||||
else
|
||||
item_image:set_image(ICONS_DIR .. item.icon .. '.svg')
|
||||
end
|
||||
|
||||
local right_part
|
||||
if item.subtitle ~=nil and #item.subtitle > 0 then
|
||||
right_part = wibox.widget {
|
||||
{
|
||||
markup = item.title,
|
||||
font = font,
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
{
|
||||
markup = item.subtitle,
|
||||
font = font,
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
spacing = 4,
|
||||
layout = wibox.layout.fixed.vertical
|
||||
}
|
||||
else
|
||||
right_part = wibox.widget {
|
||||
markup = item.title,
|
||||
font = font,
|
||||
widget = wibox.widget.textbox
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
local row = wibox.widget {
|
||||
{
|
||||
{
|
||||
{
|
||||
item_image,
|
||||
valign = 'center',
|
||||
layout = wibox.container.place,
|
||||
},
|
||||
right_part,
|
||||
spacing = 12,
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
},
|
||||
margins = 8,
|
||||
layout = wibox.container.margin
|
||||
},
|
||||
bg = beautiful.bg_normal,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
local old_cursor, old_wibox
|
||||
row:connect_signal("mouse::enter", function(c)
|
||||
c:set_bg(beautiful.bg_focus)
|
||||
local wb = mouse.current_wibox
|
||||
old_cursor, old_wibox = wb.cursor, wb
|
||||
wb.cursor = "hand1"
|
||||
end)
|
||||
row:connect_signal("mouse::leave", function(c)
|
||||
c:set_bg(beautiful.bg_normal)
|
||||
if old_wibox then
|
||||
old_wibox.cursor = old_cursor
|
||||
old_wibox = nil
|
||||
end
|
||||
end)
|
||||
|
||||
row:buttons(gears.table.join(awful.button({}, 1, function()
|
||||
awful.spawn.with_shell(item.onclick)
|
||||
widget:set_bg(background)
|
||||
noobie_popup.visible = not noobie_popup.visible
|
||||
end)))
|
||||
|
||||
return row
|
||||
end
|
||||
|
||||
|
||||
function row_builder:build_row(item, widget, noobie_popup)
|
||||
if item.header == true then
|
||||
return build_header_row(item)
|
||||
elseif item.title ~= nil and #item.title > 0 and item.icon ~= nil and #item.icon > 0 then
|
||||
return build_icon_and_text_row(item, widget, noobie_popup)
|
||||
elseif item.title ~= nil and item.title == '-' then
|
||||
return wibox.widget {
|
||||
{
|
||||
orientation = 'horizontal',
|
||||
forced_height = 1,
|
||||
span_ratio = 0.95,
|
||||
forced_width = 100,
|
||||
color = beautiful.bg_focus,
|
||||
widget = wibox.widget.separator
|
||||
},
|
||||
strategy = 'exact',
|
||||
widget = wibox.container.background
|
||||
|
||||
}
|
||||
elseif item.title ~= nil and #item.title > 0 and item.icon == nil then
|
||||
local row = wibox.widget {
|
||||
{
|
||||
{
|
||||
markup = item.title,
|
||||
font = font,
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
margins = 8,
|
||||
layout = wibox.container.margin
|
||||
},
|
||||
bg = beautiful.bg_normal,
|
||||
widget = wibox.container.background
|
||||
}
|
||||
|
||||
if item.onclick ~= nil then
|
||||
local old_cursor, old_wibox
|
||||
row:connect_signal("mouse::enter", function(c)
|
||||
c:set_bg(beautiful.bg_focus)
|
||||
local wb = mouse.current_wibox
|
||||
old_cursor, old_wibox = wb.cursor, wb
|
||||
wb.cursor = "hand1"
|
||||
end)
|
||||
row:connect_signal("mouse::leave", function(c)
|
||||
c:set_bg(beautiful.bg_normal)
|
||||
if old_wibox then
|
||||
old_wibox.cursor = old_cursor
|
||||
old_wibox = nil
|
||||
end
|
||||
end)
|
||||
|
||||
row:buttons(gears.table.join(awful.button({}, 1, function()
|
||||
awful.spawn.with_shell(item.onclick)
|
||||
widget:set_bg(background)
|
||||
noobie_popup.visible = not noobie_popup.visible
|
||||
end)))
|
||||
end
|
||||
|
||||
return row
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return row_builder
|
Loading…
Reference in New Issue