buffet / kiwmi

A fully programmable Wayland Compositor
Mozilla Public License 2.0
585 stars 22 forks source link

Implement rendering from lua with the new scene-graph API #75

Open kuruczgy opened 1 year ago

kuruczgy commented 1 year ago

I think the main question here is the shape of the API we want to expose to lua.

As a conversation starter, here is my PoC implementation that mostly just maps the scene-graph API one-to-one to lua: https://github.com/kuruczgy/kiwmi/commit/e83bc5bdf2274ebe0f59d5a44fc64eb1715ea431

The API exposed to lua looks like this:

---@meta

---Represents a view (a window in kiwmi terms).
---@class kiwmi_view
local view = {}

---@return scene_tree The scene tree for this view.
function view:scene_tree() end

---A scene node.
---@class scene_node
local node = {}

---Set the position of this node.
---@param x number
---@param y number
function node:set_position(x, y) end

---Only valid if created through tree:add_rect.
---@param width number
---@param height number
function node:set_size(width, height) end

---Only valid if created through tree:add_rect.
---@param color string
function node:set_color(color) end

---@class scene_tree
local tree = {}

---Add a new rectangle node to this tree.
---@param color string The color in the format #rrggbb.
---@return scene_node node The created node.
function tree:add_rect(width, height, color) end

---Add a new text node to this tree.
---@return scene_node node The created node.
function tree:add_text(text, color) end

This API should already be quite powerful. Most decorations we want to draw (window borders, title bars, highlighting the active view) can be done with just rectangles, and window titles (with any other kind of information we want) can be added with text nodes.