-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new cairo module #497
Conversation
b039e12
to
799a0b7
Compare
@yavko this requires luajitPackages.lgi as runtime dependency. Ideally this should be treated as an optional dep as you only need it if you use this module. Do you think you'd be able to take a look at that please on the nix side? |
i think the best way to do this would be detecting if the feature flag is enabled, so like this deps = [ "old deps" ] ++ (if (builtins.elem "cairo" features) || (features == []) then [lgi_or_whatever] else [])
|
From my (admittedly very limited) nix understanding I think that gives me what I need to do the if/else, but it's otherwise not correct. Effectively these env vars need to be set at runtime as follows: LUA_PATH = "${luajitPackages.lgi}/share/lua/5.1/?.lua;${luajitPackages.lgi}/share/lua/5.1/?/init.lua;${luajit}/share/lua/5.1/?.lua;${luajit}/share/lua/5.1/?/init.lua";
LUA_CPATH = "${luajitPackages.lgi}/lib/lua/5.1/?.so;${
luajit}/lib/lua/5.1/?.so"; Problem is that's where my knowledge ends. Are you able to pick this up please? |
Yeah sure |
aad2079
to
c49e75d
Compare
e5cc70e
to
7f6c04c
Compare
I've managed to get LGI loading in Nix, but it's behaving differently there for some reason. There's a bug with the LGI library where you cannot pass a pointer to the Cairo cairo.Context.create = nil Note that the init script is inlined as a string into the binary, so there's no IO involved. On Arch, this works fine. On Nix, it seems to do nothing, and you get hit with this:
It makes absolutely no sense to me why an inlined piece of code would behave differently when using the same lua runtime version, same library version, and same ironbar version. I'm wondering (dreading?) if patching the LGI package itself on Nix is the answer. It's literally only a single line that needs commenting out at least. |
bb64f21
to
ea9ea7f
Compare
After many hours, I have no idea why it doesn't work on Nix, but I've added a nix-specific patch that just removes the program code from LGI and it's sorted it. |
Resolves #105 Co-authored-by: A-Cloud-Ninja <[email protected]>
So: it didn't work on Nix because it didn't work anywhere. Except on my machine, where I had patched the system library without realising. Many thanks to @A-Cloud-Ninja for his help working on this with me in the background, but we've managed to work around an LGI bug and get this working reliably everywhere. |
This is an early working draft of the Cairo module, which allows you to write custom Lua scripts to draw whatever you like to a region of the bar. It's pretty rough around the edges but just about good enough to start playing with.
Currently this cannot be used in popups, however that will change fairly soon once #131 is resolved (that's been brought forward specifically because of this).
You need LuaJIT installed along with the LGI package (
lua-lgi
on Arch). This needs to be installed to theLUA_PATH
andLUA_CPATH
respectively. If installing system-wide, this should Just Werk as it's in/usr
.I have played around with the idea of vendoring but suspect I will need to write bindings to statically link
lua-lgi
and its scripts into the Ironbar binary, so unless anybody has any better ideas we'll roll with it like this for now.Example usage
In your config you can define eg:
Where:
path
- path to Lua scriptinterval
number of milliseconds between updateswidth
- canvas widthheight
- canvas heightGTK's sizing rules mean if the canvas height (or width for vertical bars) is less than the bar height, it will automatically expand to the bar height.
At the specified path, define a Lua script. The script must contain a function called
draw
, which takes the Cairo context as a parameter. Other than that, you have free reign.You can optionally create an
init.lua
file in your config directory, which is executed once on bar startup. This can house any required initialization code, as well as shared functions.The most basic example, which draws a red square, can be shown below:
A more complex example is included on the wiki page.
OLD
Currently there are some hard rules you need to keep in mind:local cr = cairo.Context(ptr)
to get a usable object.0
.cairo
global is available everywhere. This gives full access to the Cairo library, although some constructors may not work yet.I've included a proof-of-concept example script below, which results in a kinda nifty clock I wrote for Conky about 5 years ago.
OLD Lua script
I want to try and polish this up and sort most of those gotchas out before this gets merged. Any and all help/ideas welcome.
Resolves #105