Skip to content

tray:unix: Rework the tray structures to have an 'internal' member (Follow-up for #15364)#15368

Open
sulix wants to merge 1 commit intolibsdl-org:mainfrom
sulix:fixtray2
Open

tray:unix: Rework the tray structures to have an 'internal' member (Follow-up for #15364)#15368
sulix wants to merge 1 commit intolibsdl-org:mainfrom
sulix:fixtray2

Conversation

@sulix
Copy link
Copy Markdown
Contributor

@sulix sulix commented Apr 12, 2026

Okay, this is the follow-up to #15364 which makes the various generic structures have an internal pointer, rather than the DBus-specific ones having a class_parent structure and being cast to their generic equivalents all the time. I'm not completely convinced this is actually an improvement — or even 100% convinced it's correct, as there were a lot of subtle casts througout the original — but it passes a few tests with testtray, as well as with my own projects. Most annoyingly, it does double the number of allocations needed, as the generic and backend-specific structs are now allocated separately. (We could try to combine the allocations, but the extra ugliness is probably not worth the gain.

Thoughts?


Currently, the SDL_Tray* structs in the unix backend are subclassed for each implementation (only dbus so far). This means that the DBus-specific members are in their own structs (SDL_Tray*DBus), which all are required to have the corresponding 'parent' struct as their first member, so that they can be cast easily and used in the more generic code.

However, other SDL systems which have pluggable backends work the other way around: the 'generic' struct has an 'internal' member, which individual drivers can use to store a pointer to any internal state. This is a bit simpler to wrap one's head around -- particularly because it's consistent -- but does typically involve more memory allocations.

Change the unix/DBus tray implementations to use an 'internal' pointer to match other subsystems.

Currently, the SDL_Tray* structs in the unix backend are subclassed for each
implementation (only dbus so far). This means that the DBus-specific members
are in their own structs (SDL_Tray*DBus), which all are required to have the
corresponding 'parent' struct as their first member, so that they can be cast
easily and used in the more generic code.

However, other SDL systems which have pluggable backends work the other way
around: the 'generic' struct has an 'internal' member, which individual
drivers can use to store a pointer to any internal state. This is a bit
simpler to wrap one's head around -- particularly because it's consistent --
but does typically involve more memory allocations.

Change the unix/DBus tray implementations to use an 'internal' pointer to
match other subsystems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant