FLTK logo

Re: [fltk.coredev] Exploration: FLTK platform compatible with both Wayland and X11

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.coredev  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Exploration: FLTK platform compatible with both Wayland and X11 Albrecht Schlosser Mar 22, 2022  
 
On 3/22/22 21:57 Bill Spitzak wrote:

On Tue, Mar 22, 2022 at 1:42 PM Albrecht Schlosser <AlbrechtS...> wrote:
On 3/22/22 18:26 Bill Spitzak wrote:
I see no reason you cannot use global variables instead of function calls for these pointers.

Yes, generally you can use global variables but those used today (one name for all platforms) can't be used further because different platforms require different types. As long as you had only one platform active in the build at any time this was no problem (although it made things sometime very complicated).

I've also seen too often that global variables exposed to user ode make later changes almost impossible. The existing global variables (e.g. fl_display) are also user-writable IIRC. All these points are reasons to use accessor functions instead.

The current design that attempted to reuse the X11 symbol names for similar symbols in other systems is almost certainly a mistake.

I agree. But that mistake was done many years ago (AFAICT before I began using FLTK). At that time the Windows port was already available and I believe the old MacOS 8/9 was also available.

In particular it means you don't get a linking error if you attempt to use a different backend than fltk was compiled for.

These symbols are only defined in user code if the user code includes the platform headers. Most FLTK programs don't do that, and since code compiled for Windows can't be executed on macOS anyway I don't see this particular problem. But I agree that it was a bad decision to do that.

What I propose is renaming the symbols to be different for each platform. I don't think the fact that people can write values to them is very important, and fltk itself has to write the value for these somewhere, leaving another global variable that a user can malicioulsly write over anyway.

Only if it's exposed to the user code as a global variable (unless they use random addresses or a wild pointer). I don't meant that the variables should be write protected by the system -- inaccessible by the compilation would suffice.

The variables are there entirely so that other platform-specific code can use them. You should be able to rename them because all the users of them can change the names as well.

Yes, we can do this. But if we rename them in one step backwards compatibility is gone. We'd have to keep at least both variable names for some time. Exporting accessor functions to these variables makes sure we have full control (read-only) and we can change the function later if required.

I would very very much like to get rid of this idea that the platform is supported by virtual functions, and return to a state where it is controlled by ifdefs which can change how fltk functions are implemented, either by using completely diffferent versions of the functions, or ifdefs inside their internals, which is a very useful feature we lost with this virtual function idea. In particluar it  would allow x-only, wayland-only, and the hybrid version to use the same source code.

No, it wouldn't. In the classic style you have only one platform enabled during compilation. In the future (with a "hybrid" FLTK lib) we'd have more than one platform concurrently. #if ... #elif ... #elif ... #endif does no longer work. We would have to use #if platform-1 (code1) #endif, #if platform-2 (code2) #endif and both platform-1 and platform-2 expressions (e.g. X11 and Wayland) could be active at the same time.

That said, and as I already wrote before: we made a conscious decision to go away from the #ifdef ... style and use the current driver model. This is not going to be reverted. I'm sorry to say that to you, Bill, but that's a fact. One of the main persons in this decision process was Matthias, and the decision was mainly driven by the fact that the old style wouldn't scale to more platforms (we had three at that time).

I agree the current code structure is necessary, where the implementations each live in their own file. The old fltk scheme basically was the X11 version with ifdefs added to it to patch in alternative versions where needed. Instead this should be done like the fltk 2.0 code, where X11 would be in it's own source file, and ifdefs are almost exclusively used to switch which #include statement is compiled, and all the platform code is in that included file. However that platform code *directly* defines the public fltk function.

I'm not aware of the code structure of FLTK 2.0, but I'll take a look into the details when time permits. However, with the concept where "ifdefs are almost exclusively used to switch which #include statement is compiled" you are at the same point again: you can't have two different platforms active (compiled in) at the same time. And the maintenance nightmare that you need to edit the main files to #include another platform when such a platform is added (scalability).

Using a virtual function table has the annoying fact that it will link all the code into the program whether it is used or not.

OK, I see and I agree, point taken.

But this is only true for "driver" code (e.g. graphics output, system specific window handling, etc.), not for platform independent stuff that is compiled as separate files like image types (fltk_images library) and other optional components in their own source files.

But more importantly it puts decisions, such as how to modularize the platform-specific code, into public header files and the fltk binary api. This is not a good idea.

These header files are not "public". All driver header files (except one) are in the src/ directory or its subdirectories and can be changed at any time. Without checking the details, I believe that this wouldn't change the ABI (i.e. the /public/ application binary interface) because these details are not exported.

--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkcoredev/139a1be8-ffea-ae58-06e4-c52f1f38dd31%40online.de.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.