Future of XPCE (original) (raw)

Hi,

since some years I use SWI Prolog successfully, and all the time there was the question how to do graphics or simple visualizations. The last years I used a Web solution with Babylon.js and Websockets, but I looked at XPCE and Java integration, too. Related to XPCE, which is the base for the SWI own tools, I asking myself what the future of XPCE will be. As far as I read in some posts here, XPCE is not maintained, and in someway “dead”. But SWI uses it, so what are your thoughts about future releases of SWI (maybe for direction 10.0) ?

Just curious.

Best

Hans

jan May 1, 2025, 10:18am 2

It won’t disappear any time soon. Even some work on it has been done recently to support hi-res displays by scaling images and (with some luck) getting the default font scaling “correct”.

Don’t expect new features or bug fixes. Portability issues, in recent times mostly due to moving the C standard and C compilers dropping K&R style declarations and getting more picky on prototypes, will be applied.

The main issue is that X11 is slowly being phased out. For Linux integration we should at some point move to Wayland and for MacOS it would be much better if you would use native MacOS graphics. I don’t know whether none, one or both will ever be done. That depends on opportunities to get funding, someone willing to implement this and how fast X11 deteriorates or disappears. Moving away from X11 is certainly doable. I’d expect it to take a month or so for an experienced C programmer.

hnbeck May 1, 2025, 11:03am 3

Thank you for this answer! Just my opinion: SWI is so a great system and tool, it seems to be worth it to get a modern GUI/Graphical module (ore package). But of course, someone has to spend the work…

Anyway, some small personal remark: Since I started working on the SUN Workstations in early 90ies, I liked the X11 thing - the possibilities, and all the things on its way, PHIGS, Motif and more. Display Postscript of NeXT was a great evolution, and now we have the Web… If X11 would disappear it would be somewhat sad, even it may be logically from a technical point of view. If there is somewhere something to read about the history or technical evolution of XPCE, its roots, I would like to read it :slight_smile:

Thank you very much

Hans

jan May 1, 2025, 12:18pm 4

Yes, but it is a bit hard to make a decision. XPCE’s integration with Prolog is nice. But, the system is not very memory-safe and single threaded. The latter might be good enough. It was originally written by Anjo Anjewierden for SunView. I ported it to X11 in the early 90s. Besides porting, xpce stopped using the system widgets and only used basic window and drawing facilities from the OS/Graphics. This allowed me to abstract the OS/Graphics binding in the mid 90s and create a second implementation using the Win32 native graphics API.

The advantage of do-your-own widgets is full portability. The price is that it needs a lot of work, especially if you want to stay in sync with modern GUI development and style guides. So, it still mostly looks like old Windows or old Gnome :frowning: It doesn’t do proper scaling (everything is a pixel), doesn’t do alpha channel or transformations. Part of it is hopelessly complicated due to the support of all the complicated colour handling of old X11.

So, where to go? Some options:

This status quo exists for a long time and nothing happens as it is not a priority. It can change if some party with resources wants to see it change and invest in these changes.

For GUI you might like to try raylib. I have been working on raylib bindings for SWI prolog. It’s been a way for me to develop my C and SWI Prolog workflows and learn more about foreign function interfaces. While raylib is mainly targeted as a “games library” it’s mostly a wrapper around openGL and SDL plus some extra game freebies you can take or leave. I know at least one person who, for example, wrote a text editor in raylib. I have some prototype examples of how to connect swi prolog and raylib, I just uploaded them to github here: Github.com/ai-robert/raylib-prolog-poc

While I’ve picked up and put down building bindings for the entirety of the raylib library, you can see from my example posted that if you only need a handful of raylib functions then it’s easy to just add a few bindings for just those functions.

I took a quick look at your code … you need to check return codes from almost all PL_() functions. If you use the C++ API instead, you don’t need to check – it throws C++ exceptions and catches them in the PREDICATEs. You can mostly mix the C and C++ APIs if you wish – if you want to minimize the conversion work, the C++ API also provides Plx_*() wrappers for the PL_*() functions, that do the error checking for you.

Instead of printf(), I suggest using Sdprintf() to use the SWI-Prolog streams.

jan May 3, 2025, 8:23am 7

Interesting. I had a short read into the raylib - cheatsheet. It looks like a pretty clean match to xpce’s low level binding when we look at the level. It might actually be an interesting match. If we would rebind xpce based on raylib, we’d get

I wonder in how far LLMs can help implementing that. They might not be bad in translating stuff.

hnbeck May 3, 2025, 9:26am 8

That would be so great! I also have the impression that raylib would be a great modular and cross-platform implementation layer of XPCE - and it may be a start to evolve XPCE in direction of new concepts (camera, transformations…) and declarative ways of defining graphics (Vega…). Ok things of the future, but even a XPCE as it is with raylib as render framework would great thing.

Best

Hans

jan May 3, 2025, 4:41pm 9

Well, I spent some time with ChatGPT :slight_smile: The good news that with its help I managed to create a new binding that solely consists of stubs in just a few hours. It even documented the stubs, though the quality of the docs varies between impressive to plain wrong. Well, that is what one expects. Anyway, I pushed a branch called raylib that provides src/ray holding the empty binding. The system builds for this binding as well as the x11 binding (didn’t test Windows yet).

The bad news is that raylib supports only a single window. That is not a match for xpce :frowning: So, I think this route has failed before it started. Well, the empty binding with documentation is quite valuable :slight_smile: A simple sed script should be enough to rename the binding to something else.

ChatGPT recommends SDL, GLFW or RGFW (considered less mature). Opinions?

I’m surely not going to turn this into a concrete project. I am interested in the options though and I’m particularly interested how far LLMs can help doing a lot of the work. For the first step I’m fairly happy. It took about an hour to get ChatGPT to understand what I wanted, an hour to go through the various files and another hour to adjust the build process and resolve some issues to make the thing compile and link. Without, this certainly would have taken several frustrating days of typing :slight_smile:

I like SDL, it’s popular for games programming too. I like that it supports windows, macOS, Linux, android, and iOS.

hnbeck May 3, 2025, 6:52pm 11

I got introduced to GLFW via Ada and others. It seems to be very portable and useful, but I my knowledge is too limited to compare it to SDL or others. It’s interesting to read that LLM is such a big helper already.

jan May 16, 2025, 9:32am 12

I’ve been doing some experiments with quite a bit of help from ChatGPT :slight_smile: Current state:

Rudimentary means that most of the IDE tools run, though not very stable, with some graphics glitches and some missing graphics.

It seems worthwhile to continue this. There is still quite some work to do though. I’m asking for your support to make this possible. Think about

Phase A

That would make it a viable replacement for the current state. From there, we can continue

Phase B

Again, opinions, but notably help is welcome. Financial help is great. Help in (C) coding, generating tests (Prolog), testing, icon design, etc. are all very welcome. Depending on feedback I’ll organise the project to facilitate cooperation.

CapelliC May 16, 2025, 11:13am 13

I fully agree. By myself, I did some small experiments using Dear ImGui, but nothing worth further deepening.
Just in case, maybe I could help to port swipl-win.exe to the new architecture.

jan May 16, 2025, 11:39am 14

Good to know. Funny that ChatGPT also suggested Dear ImGui if native menu support was a requirement.

SDL3, nor Cairo support widgets. That is fine, as xpce has its own based on its graphics primitives. ChatGPT suggests implementing swipl-win based on the xpce low-level binding and using xpce for the menu. This is fully portable. Next, it suggests Dear ImGui or platform specific support for selected platforms. For Windows, we already have that code as part of swipl-win.exe.

That all makes sense to me :slight_smile: ChatGPT is quite useful in evaluating design choices. Of course, it remains an unreliable tool in the sense that its answers vary from nonsense to brilliant.

hnbeck May 16, 2025, 1:00pm 15

Great news! I’ll considering GitHub sponsor. Testing (Mac and Win) is something I could support, for coding my knowledge is too limited :slight_smile:

jan May 16, 2025, 1:06pm 16

Thanks and thanks. For now, the target is Linux. Mac will be next once the Linux version is usable. Of course, unless someone wants to do the porting earlier :slight_smile:

jan May 28, 2025, 8:14pm 17

Quite a bit of work has been done :slight_smile: The project looks promising. The current state, issues and building instructions are at the xpce wiki at github. Executive summary:

There are still several serious bugs

Future

Assuming the above issues can be fixed, this looks promising. Main remaining issues:

Support, be it help or sponsoring, is very welcome.

Hello,
I have just managed to compile the sdl branch on fedora 42 and it works quite well !
The only weird thing I have noticed is a input lag in the terminal prolog top level after loading xpce.
Is that a known issue ?

Although I don’t have much time, I would like to help with testing or maybe even coding.
Last time I tried to use xpce, I was trying to draw shapes with bezier curves.
I have noticed this bullet point in your TODO list:

    - [ ] Now uses interpolated path. Should use Cairo native

Could this be an appropriate task for a novice like me ?

jan May 30, 2025, 8:32pm 19

Yes. At some point it was fine, but this got back. Should be fixable. But, the idea is that people will prefer the xpce terminal now called epilog.

That is up to you :). I’ll surely welcome a PR. Overall, the plan is to move as much as possible to cairo and use that for PostScript and PDF generation, removing all stuff there is now.

You’ll still find quite a few stubs in the sdl directory. Some are probably worth filling in. Bigger questions are how to deal with multiple monitors, cleanup images, color handling, move coordinates to floats, etc. Any small step is welcome though.

P.s. The MacOS version appears usable as well now. The fonts are very “fat”. Better font handling is also on the agenda. One issue is whether or not to include the “pango” library. I had some hope we could do without, but we might really need it.

Finally, there is Windows. I’m not yet sure how hard that will be. I have some hope it will be fairly simple … MacOS only took a couple of hours :slight_smile:

Disclaimer: No offence intended, just some brainwriting.

Mostlikely you could ditch, XPCE , you have the
keys already in your hands. Just replace this:

image

With what you did for SWI Tinker with CodeMirror:

image

Maybe distribute it with some Skunk browser like
Ladybird, which has a LibJS, LibWeb, LibWasm etc..

Residual problem porting gtrace to a browser…

Edit 05.06.2025
BTW: Currently toying around with another interesting
project QuickJS, from Fabrice Ballard, you might remember

him from your LibBF binding.