mirror of
https://github.com/JakeStanger/ironbar.git
synced 2026-07-11 07:15:19 +01:00
[GH-ISSUE #105] Cairo module/widget #7086
Labels
No labels
A:Build
A:CI
A:Client
A:Config
A:Core
A:Documentation
A:Documentation
A:IPC
A:Testing
A:UX/UI
blocked
BREAKING CHANGE
duplicate
good first issue
GTK4
help wanted
invalid
M:Battery
M:Battery
M:Bindmode
M:Bluetooth
M:Brightness
M:Cairo
M:Clipboard
M:Clock
M:Clock
M:Custom
M:Focused
M:Keyboard
M:Launcher
M:Menu
M:Music
M:Music
M:Music
M:Network Manager
M:Notifications
M:SysInfo
M:Tray
M:Volume
M:Workspaces
partially resolved
P:Critical
P:High
P:Low
P:Medium
pull-request
T:Bug
T:Bug
T:Core Enhancement
T:Module Enhancement
T:New Module
T:Question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
JakeStanger/ironbar#7086
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @JakeStanger on GitHub (Apr 10, 2023).
Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/105
Is your feature request related to a problem? Please describe.
You are currently limited to the available widgets, which imposes some restriction on the possible shapes and content that can be displayed.
Describe the solution you'd like
GTK allows you to draw to widgets directly using Cairo. Some form of wrapper around this (perhaps via Lua) would allow full scripting of custom content.
Describe alternatives you've considered
None yet.
Additional context
Originally discussed in https://github.com/JakeStanger/ironbar/issues/68#issuecomment-1493427388
Example implementation in eww: https://github.com/elkowar/eww/pull/328/files
@yavko commented on GitHub (Apr 12, 2023):
WASM could also work. I also wrote up this insanity below, that could keep everything declarative, but honestly, maybe it's too much, and would be difficult to create an embedded DSL as I came up with below.
@JakeStanger commented on GitHub (Apr 12, 2023):
WASM is a fantastic idea! If I can figure out a way to do that without requiring too much work for the user (ie I'd rather not force people to require a whole build chain just to configure a module), I absolutely will.
The DSL I think I'd rather avoid. In part, because I think writing/maintaining a whole parser just for this would be wayyy to much work, but also in part because it adds the requirement of learning it just to be able to use it here and nowhere else, vs re-using an existing lang like Lua (or even JavaScript...) which can also be used elsewhere.
@yavko commented on GitHub (Apr 22, 2023):
I actually found something perfect for this https://lib.rs/crates/evalexpr, since it uses syntax that every language uses it could work, I could write up a quick POC of a DSL like this in a bit
@yavko commented on GitHub (Apr 22, 2023):
Also, will this be a custom module widget, or a just a module? Or maybe both?
@JakeStanger commented on GitHub (Apr 22, 2023):
Lua is still my number 1 choice at the moment, but go for it, I'd be interested to see what you're thinking of and how it would work.
TBC, but hopefully both. The long term goal is that at least some of the simpler modules will be shared between both without duplication.
@yavko commented on GitHub (Apr 24, 2023):
I have made something, tho incomplete, It's able to almost recreate the eww circular progress, (except for child widgets, since I didn't make it in GTK), here is the code in case you want to see how it's done https://gist.github.com/yavko/2f5a74020ccbeadd08c5a0d6b63136b3
The types could maybe also be used to support Lua, or other runtimes
@A-Cloud-Ninja commented on GitHub (Apr 24, 2023):
Fwiw to throw this idea out there if lua is the current champ as far as existing ideas goes, a specific lua library, LGI, could be very powerful here. Here's a small sample of coercing objects in and out of C (should be plausible to work this with rust) from lua with bindings on both ends
Note that the "release" builds of LGI are outdated and will crash on some newer libraries, but building the latest version will properly work, including gtk4{-layer-shell}, so for the forseeable future this should be future proof too.
@yavko commented on GitHub (Apr 24, 2023):
I personally think mlua would be better as there is no need to use a C library & ffi
@A-Cloud-Ninja commented on GitHub (Apr 24, 2023):
The benefit of LGI here would be the flexibility to we'll say, end users in creating essentially arbitrary widgets. All up to what the true goals here are, though.
Also, regardless of LGI or not, mlua (or another VM library impl) would have to be used anyway if lua is to be used. LGI just facilitates creation and passing of GObjects to and from both sides easier.
@yavko commented on GitHub (Apr 24, 2023):
That's cool and all but it doesn't have rust bindings and making rust bindings for a C library isn't fun as it requires unsafe code and idk if it's possible or easy to pass a gtk-rs struct as a raw GObject
@A-Cloud-Ninja commented on GitHub (Apr 24, 2023):
This shouldn't require anything extra rust-side, unless I'm mistaken. If you use Mlua targeting we'll say PUC Lua 5.1, and LGI is shipped/depended on and built for 5.1, "rust" doesn't have to know anything about LGI, as the Lua-side passes
GtkWidget._nativewhich will return a native pointer to the actual object. See Interoperability with native code.@JakeStanger commented on GitHub (Apr 24, 2023):
I've had a quick look at this and it looks very promising. I'll have a proper read through/review as soon as I can, but I reckon we can do something with it.
This is the make or break situation for having a scripting interface with GTK inside the bar. I can't see that it wouldn't be possible, but it depends on what rust will let me pass to lua. I'm not afraid of getting my hands dirty and playing with some unsafe code if necessary, but by the sounds of it there shouldn't be much need anyway. It's something that'll be a good few months off anyway (assuming nobody else gets there before I do :p)
@yavko commented on GitHub (Apr 24, 2023):
I'm like 94.87% sure you are, I've had to do FFI in rust before, and if you didn't wrap C libraries you'd be introducing unsafe and UB which is not the rust way
@yavko commented on GitHub (Apr 24, 2023):
I think having Lua and json would be better as sometimes you need more power, but the way I was thinking of adding child widgets to my json impl was just by using the ironbar syntax like in custom modules
@yavko commented on GitHub (Mar 8, 2024):
I just saw u changed the milestone, and remembered this issue, and I was thinking, that maybe instead of lua, rhai could be used, since it's more rusty https://lib.rs/crates/rhai
@JakeStanger commented on GitHub (Mar 8, 2024):
I've been playing around with this in the background over the past few days funnily enough, and Rhai is one of the things I've looked at.
The issue with Rhai is that it needs to generate its own methods and typings rather than using the Rust ones, and although it does have methods of automatically doing that I've not been able to make them play nice with GTK/Cairo. It seems everything would have to be manually implemented (or I'd have to write a macro to generate everything and I don't know where I'd begin with that for this). GTK especially poses difficultly because of its prelude based implementation.
Lua meanwhile has the advantage of being very low level and very lightweight, and fairly popular. Using mlua + lgi seems like the combo here, as I can just pass a glib pointer for any gobject into the runtime and have it fully exist in Lua. I'm testing this one currently.
@JakeStanger commented on GitHub (Mar 8, 2024):
A lot to work out still, but it WORKS! We can do a lot with this potentially
mlua + lgi, currently requires both to be installed as system packages but playing with the possibility of vendoring.
@yavko commented on GitHub (Mar 8, 2024):
Sick, generating an image is cool, though integrating it must be harder. Maybe lua could also be integrated with other parts, like instead of a script.
@yavko commented on GitHub (Mar 8, 2024):
If I figure out how to add rhai, would you merge a PR?
@JakeStanger commented on GitHub (Mar 9, 2024):
Yeah this unlocks an enormous amount of potential. I'm still not 100% on the direction I want to take it yet but this does possibly give a much more powerful alternative to calling out to shell scripts for custom stuff.
I'm certainly open to it, no harm in more choice at this level I don't think. I'd want it to closely mirror whatever lua impl I come up with is the main consideration, so that ideally the choice is "pick your lang, they do the same thing"
@JakeStanger commented on GitHub (Mar 14, 2024):
Far from done, but I've got a working module at the PR above which is in a useable state with some fiddling about. Full details in there.