-
Notifications
You must be signed in to change notification settings - Fork 133
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
io,layout: switch Source from struct to interface #134
Conversation
This patch make possible to customise the Source, which is equivalent of the older version of Queue. Signed-off-by: inkeliz <inkeliz@inkeliz.com>
I'm kindly pinging @eliasnaur since that issue is a significant for gio-plugins and other libraries. |
If I understand this you're encoding a custom op into the internal How about calling |
That was how it used to work, before Gio 0.6. I know that it wasn't stable, and Gio, in general, isn't stable too. However, the goal was to make it similar to other kinds of Ops (like I want to replace it with
But how I can send If EDIT: That is how things used to work on Gio 0.1~0.4:
That implements the old |
67c77c9
to
46cc311
Compare
Benchmarks using gio-example kitchen: Current Patch (New = This Patch):
|
What about a memory benchmark? As mentioned in #136 (comment), changing At a higher level, I'm not convinced allowing external packages to use the Gio event routing is a good idea. As I wrote above, users of the various plugins can add an extra |
I will check it, and the heap-escape.
That was already previously discussed, https://lists.sr.ht/~eliasnaur/gio/%3Cfe3835f7-b4d4-4db9-81fb-dfd8ab06f2ed%40www.fastmail.com%3E. That is why I made Until Gio 0.6 was possible to get/insert events and works fine. Even if it's not promised to work, it does work due to Queue-interface and the Op that accepts anything as So, most of my code was already written with just a single
I think it's more than just
The
That was a quick port, from previous Op (where Gio doesn't have TransferEvent). It's important to mention that Other types of plugins, like "Auth" (which is Sign In With Apple/Goole), needs Note that is already possible to use all plugins without messing with Events or anything. However, you also need to provide all information (from many types of events) manually, and call So, usually you need to have some kind of global variable or passing it across multiple components. The current Haptic and Explorer from gio-x have such problem. Consider the most basic one, Haptic, you need to use https://pkg.go.dev/gioui.org/x/haptic#NewBuzzer store it somewhere and then call |
Using
However, that is illegal in unsafe.Pointer rules. So, the last option is to use some |
This code works with Gio 0.6, right? In particular, If so, why can't you do the same for
Why not
Same
Why not
All this is handled by
I see. This is yet another reason to introduce
Again, it seems to me a set of wrapping |
I did that week ago, so it's possible to use |
I'm migrating from version 0.1 to 0.6, and I'm also migrating
gio-plugins
and other packages. However, the lack of interfaces makes it harder to intercept and add custom events into thelayout.Context
.Background: In previous versions,
Queue
was an interface. This allowed for custom implementations, a feature thatgio-plugins
relies on. It was possible (even if not explicitly intended) to use:That Op was captured by a custom implementation of Queue. The same implementation was responsible for injecting another custom event, such as gioexplorer.OpenFileEvent.
Currently, in version 0.6, it's not possible to achieve the same results. It is impossible to gtx.Execute(gioexplorer.OpenFile{}) and then catch a transfer.DataEvent{}.
Alternatives and Failed Attempts:
go:linkname: Using go:linkname is impossible due to the inlining of Source.Execute and Source.Event. The only option would be using //go:noinline in the Gio source code, which requires changes anyway.
go -overlay: This command allows replacing files and supposedly changing the current router.go. However, it is harder to use (requires generator + compilation arguments) and is currently incompatible with gogio.
External events: The point of gio-plugins was to be similar to Gio, allowing for similar usage across components. While calling gioexplorer.Open() and gtx.Execute(gioexplorer.Open{}) is not much different, we need to get the result. Using the current gtx.Event helps to streamline everything. Otherwise, you need to keep some callback function, channel, or spawn goroutines.
Switching from Struct to Interface fixes this issue, and it's the cleaner solution. It may have some performance impact, due to dynamic-dispatch. The current code also caches the
source
asSource
to prevent mitigate allocations. Furthermore, thedisabled
use the same Source, instead of creating new ones.