update readme
This commit is contained in:
parent
f652e2eec0
commit
06d339c68d
82
README.md
82
README.md
|
@ -1 +1,83 @@
|
|||
# noobie
|
||||
|
||||
Create a wibar widget for Awesome WM with no lua code!
|
||||
|
||||
This is widget-maker tool - it creates a widget based on a definition described in JSON format and returned by a script.
|
||||
|
||||
For example, if your script returns a following JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"widget": {
|
||||
"icon_path": "smile",
|
||||
"text": "noobie",
|
||||
"mouse_actions": {
|
||||
"on_scroll_up": "echo 'scroll up'",
|
||||
"on_scroll_down": "echo 'scroll down'",
|
||||
"on_right_click": "echo 'right click'"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
noobie will convert it to following widget:
|
||||
|
||||
![screenshot](./screenshots/screenshot.png).
|
||||
|
||||
You can also create widgets with menu:
|
||||
|
||||
```json
|
||||
{
|
||||
"widget": {
|
||||
"icon_path": "smile",
|
||||
"text": "noobie",
|
||||
"mouse_actions": {
|
||||
"on_scroll_up": "echo 'scroll up'",
|
||||
"on_scroll_down": "echo 'scroll down'",
|
||||
"on_right_click": "echo 'right click'"
|
||||
}
|
||||
},
|
||||
"menu": {
|
||||
"items": [
|
||||
{
|
||||
"icon": "bell",
|
||||
"title": "Say hi!",
|
||||
"onclick": "notify-send 'hi!'"
|
||||
},
|
||||
{
|
||||
"icon": "terminal",
|
||||
"title": "Execute some script",
|
||||
"onclick": "/tmp/somescript.sh"
|
||||
},
|
||||
{
|
||||
"icon": "slack",
|
||||
"title": "OpenSlack",
|
||||
"onclick": "xdg-open https://slack.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
gives:
|
||||
|
||||
![](./screenshots/screenshot2.png)
|
||||
|
||||
## Plugins
|
||||
|
||||
You can create your own scripts in any language, the only rule is - it should return a proper JSON.
|
||||
Or you can check existing plugins in this repo: https://github.com/streetturtle/noobie-plugins.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Download the latest release under ~/.config/awesome/ folder
|
||||
1. At the top of rc.lua add an import:
|
||||
|
||||
```lua
|
||||
local noobie_exmaple = require("noobie")
|
||||
```
|
||||
1. Add a widget to wibox and provide a path to your script:
|
||||
|
||||
```lua
|
||||
noobie{ path = os.getenv("HOME") .. '/.config/awesome/noobie/test.sh' },
|
||||
```
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"widget": {
|
||||
"icon_path": "smile",
|
||||
"text": "noobie",
|
||||
"mouse_actions": {
|
||||
"on_scroll_up": "echo 'scroll up'",
|
||||
"on_scroll_down": "echo 'scroll down'",
|
||||
"on_right_click": "echo 'right click'"
|
||||
}
|
||||
},
|
||||
"menu": {
|
||||
"items": [
|
||||
{
|
||||
"icon": "bell",
|
||||
"title": "Say hi!",
|
||||
"onclick": "notify-send 'hi!'"
|
||||
},
|
||||
{
|
||||
"icon": "terminal",
|
||||
"title": "Execute some script",
|
||||
"onclick": "/tmp/somescript.sh"
|
||||
},
|
||||
{
|
||||
"icon": "slack",
|
||||
"title": "OpenSlack",
|
||||
"onclick": "xdg-open https://slack.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
67
init.lua
67
init.lua
|
@ -5,7 +5,6 @@ local beautiful = require("beautiful")
|
|||
local gears = require("gears")
|
||||
local json = require("json")
|
||||
|
||||
|
||||
local HOME_DIR = os.getenv("HOME")
|
||||
local WIDGET_DIR = HOME_DIR .. '/.config/awesome/noobie'
|
||||
local ICONS_DIR = WIDGET_DIR .. '/feather_icons/'
|
||||
|
@ -13,19 +12,6 @@ local ICONS_DIR = WIDGET_DIR .. '/feather_icons/'
|
|||
local cur_stdout
|
||||
local noobie_widget = {}
|
||||
|
||||
local noobie_popup = awful.popup{
|
||||
ontop = true,
|
||||
visible = false,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end,
|
||||
border_width = 1,
|
||||
border_color = beautiful.bg_focus,
|
||||
maximum_width = 400,
|
||||
offset = { y = 5 },
|
||||
widget = {}
|
||||
}
|
||||
|
||||
local function show_warning(message)
|
||||
naughty.notify{
|
||||
preset = naughty.config.presets.critical,
|
||||
|
@ -37,14 +23,28 @@ local function worker(user_args)
|
|||
local args = user_args or {}
|
||||
local refresh_rate = args.refresh_rate or 600
|
||||
local path = args.path
|
||||
local background = args.background or '#00000000'
|
||||
|
||||
if path == nil then
|
||||
show_warning("Cannot create a widget, required parameter 'path' is not provided")
|
||||
return
|
||||
end
|
||||
|
||||
local noobie_popup = awful.popup{
|
||||
ontop = true,
|
||||
visible = false,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end,
|
||||
border_width = 1,
|
||||
border_color = beautiful.bg_focus,
|
||||
maximum_width = 400,
|
||||
offset = { y = 5 },
|
||||
widget = {}
|
||||
}
|
||||
local has_menu = false
|
||||
local has_mouse_actions = false
|
||||
local menu_buttons = {}
|
||||
local mouse_actions_buttons = {}
|
||||
|
||||
noobie_widget = wibox.widget {
|
||||
{
|
||||
|
@ -74,6 +74,7 @@ local function worker(user_args)
|
|||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, 4)
|
||||
end,
|
||||
bg = background,
|
||||
widget = wibox.container.background,
|
||||
set_text = function(self, new_text)
|
||||
if new_text == nil or new_text == '' then
|
||||
|
@ -89,7 +90,12 @@ local function worker(user_args)
|
|||
}
|
||||
|
||||
local update_widget = function(widget, stdout, stderr)
|
||||
if stderr ~= '' then
|
||||
show_warning(stderr)
|
||||
return
|
||||
end
|
||||
|
||||
--- do nothing if the output hasn't changed
|
||||
if (cur_stdout == stdout) then return
|
||||
else cur_stdout = stdout
|
||||
end
|
||||
|
@ -101,10 +107,7 @@ local function worker(user_args)
|
|||
has_menu = result.menu ~= nil and result.menu.items ~= nil and #result.menu.items > 0
|
||||
|
||||
if has_menu then
|
||||
local rows = {
|
||||
{ widget = wibox.widget.textbox },
|
||||
layout = wibox.layout.fixed.vertical,
|
||||
}
|
||||
local rows = { layout = wibox.layout.fixed.vertical }
|
||||
|
||||
for i = 0, #rows do rows[i]=nil end
|
||||
for _, item in ipairs(result.menu.items) do
|
||||
|
@ -148,9 +151,9 @@ local function worker(user_args)
|
|||
end
|
||||
end)
|
||||
|
||||
row:buttons(awful.util.table.join(awful.button({}, 1, function()
|
||||
row:buttons(gears.table.join(awful.button({}, 1, function()
|
||||
awful.spawn.with_shell(item.onclick)
|
||||
noobie_widget:set_bg('#00000000')
|
||||
widget:set_bg(background)
|
||||
noobie_popup.visible = not noobie_popup.visible
|
||||
end)))
|
||||
|
||||
|
@ -159,19 +162,17 @@ local function worker(user_args)
|
|||
|
||||
noobie_popup:setup(rows)
|
||||
|
||||
noobie_widget:buttons(
|
||||
awful.util.table.join(
|
||||
menu_buttons = gears.table.join(
|
||||
awful.button({}, 1, function()
|
||||
if noobie_popup.visible then
|
||||
noobie_widget:set_bg('#00000000')
|
||||
widget:set_bg(background)
|
||||
noobie_popup.visible = not noobie_popup.visible
|
||||
else
|
||||
noobie_widget:set_bg(beautiful.bg_focus)
|
||||
widget:set_bg(beautiful.bg_focus)
|
||||
noobie_popup:move_next_to(mouse.current_widget_geometry)
|
||||
end
|
||||
end)
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
local actions = result.widget.mouse_actions
|
||||
|
@ -179,13 +180,15 @@ local function worker(user_args)
|
|||
|
||||
if has_mouse_actions then
|
||||
|
||||
widget:buttons(awful.util.table.join(
|
||||
awful.button({}, 1, function() if actions.on_left_click ~= nill then awful.spawn.with_shell(actions.on_left_click) end end),
|
||||
awful.button({}, 2, function() if actions.on_right_click ~= nill then awful.spawn.with_shell(actions.on_right_click) end end),
|
||||
awful.button({}, 4, function() if actions.on_scroll_up ~= nill then awful.spawn.with_shell(actions.on_scroll_up) end end),
|
||||
awful.button({}, 5, function() if actions.on_scroll_down ~= nill then awful.spawn.with_shell(actions.on_scroll_down) end end)
|
||||
))
|
||||
mouse_actions_buttons = gears.table.join(
|
||||
awful.button({}, 1, function() if actions.on_left_click ~= nil then awful.spawn.with_shell(actions.on_left_click) end end),
|
||||
awful.button({}, 2, function() if actions.on_right_click ~= nil then awful.spawn.with_shell(actions.on_right_click) end end),
|
||||
awful.button({}, 4, function() if actions.on_scroll_up ~= nil then awful.spawn.with_shell(actions.on_scroll_up) end end),
|
||||
awful.button({}, 5, function() if actions.on_scroll_down ~= nil then awful.spawn.with_shell(actions.on_scroll_down) end end)
|
||||
)
|
||||
end
|
||||
|
||||
widget:buttons(gears.table.join(mouse_actions_buttons, menu_buttons))
|
||||
end
|
||||
|
||||
watch(string.format([[sh -c "%s"]], path), refresh_rate, update_widget, noobie_widget)
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
{
|
||||
"widget": {
|
||||
"icon_path": "activity",
|
||||
"text": "hello",
|
||||
"mouse_actions": {
|
||||
"on_scroll_up": "asd",
|
||||
"on_scroll_down": "",
|
||||
"on_left_click": "",
|
||||
"on_right_click": ""
|
||||
}
|
||||
},
|
||||
"menu": {
|
||||
"items": [
|
||||
{
|
||||
"icon": "bell",
|
||||
"title": "Some title"
|
||||
},
|
||||
{
|
||||
"icon": "check",
|
||||
"title": "Some title"
|
||||
},
|
||||
{
|
||||
"icon": "box",
|
||||
"title": "Some title"
|
||||
},
|
||||
{
|
||||
"icon": "slack",
|
||||
"title": "Some title"
|
||||
},
|
||||
{
|
||||
"icon": "cloud",
|
||||
"title": "Some title"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue