First Widget¶
This guide walks through the smallest useful Lua widget and explains each piece.
What we are building¶
We will create one clock widget that:
- appears on the right side of the bar
- shows the current time
- refreshes once per minute
Minimal example¶
local clock
clock = easybar.add(easybar.kind.item, "clock", {
position = "right",
order = 10,
label = os.date("%H:%M"),
interval = 60,
on_interval = function()
clock:set({
label = os.date("%H:%M"),
})
end,
})
How it works¶
easybar.add(...) creates one node and returns its handle.
The arguments are:
- the node kind, here
easybar.kind.item - a stable node id, here
"clock" - a property table describing placement, content, and behavior
Important fields¶
position = "right"places the node on the right side of the barorder = 10controls render ordering among other root nodeslabel = ...sets the displayed textinterval = 60asks EasyBar to callon_intervalevery 60 secondson_interval = function() ... endupdates the node in place
The clock variable stores the handle returned by EasyBar, which lets the callback call clock:set(...) later.
Where this widget goes¶
EasyBar loads every *.lua file in your widgets directory.
That directory is configured with [app].widgets_dir in config.toml.
See App Settings.
Expanding the widget¶
Once the basic widget works, you can add:
- an icon through
icon = { string = "..." } - colors through
label.colororcolor - click behavior through
node:subscribe(...) - a popup through the
popupproperty
Next steps¶
- Read Subscribe To Events to make the widget interactive.
- Read Style Popups And Groups to shape more complex widgets.
- Keep API Summary open as a quick reference.