Skip to content
Jan Wielemaker edited this page Jul 30, 2025 · 31 revisions

Porting xpce to SDL

Design Issues

  • E.g., the tree images of nav should use foreground and background colour. Think about dark theme!
    • Support kind<-bitmap. This maps black pixels to the foreground and white pixels to the background.
  • How can we deal with grabbing the mouse?
    • Wayland grabs the pointer in a down/drag/up sequence.
      • Forward to initial window
    • Wayland refuses to grab the pointer except for down/drag/up sequence
    • Set this in the application and forward all mouse events to the grabbing window?
      • Add event->frame to keep track of the original frame
      • Adjust get_xy_event() to use the proper logic:
        • If receiver in ev->frame, we can do the usual logic
        • Else we cannot determine the position. Fail?
  • How to deal with monitors/displays? As is, we had multiple X11 connections, each represented by a display and on that sub-areas which represented multiple monitors. SDL only has multiple displays. Displays may have different "pixel densities"
    • Removed class monitor
    • Allow for multiple instances of display and handle dynamic adding/deleting displays
    • Update the frame-display when a frame is moved to another display.
    • How to deal with hi-res displays? SDL uses logical coordinates. By default, these are 1:1 mapped on traditional displays and typically 1:2 on hi-res displays such as 4K monitors and Mac retina displays.
      • Tell SDL we are hi-res aware. This means the SDL window is in raw pixels
      • Make our XPCE window backing pixmap match the SDL window resolution
      • Use cairo_scale() to allow us using logical coordinates
      • Make frame (SDL window) redraw aware of the scaling.
    • Use the logical/physical mapping to rescale windows using Ctrl+0-
      • Currently, several classes can change there font using these shortcuts.
    • Support multiple displays with different logical/physical mappings. It seems SDL takes care of that "by magic".
  • How to deal with frame<-confirm and frame<-confirm_centered
    • Pass window instead of point?
  • How to deal with waiting for sockets, etc.
    • Have a thread waiting for them and send a user event?
  • How to introduce transparency? At the device/graphical level? Alternatively, at the colour level.
    • Class colour now support RGBA. We probably still will introduce the alpha channel at other places.
  • Fill with images?
  • Work around SDL main thread issues. Windows can only be created in the thread that called SDL_Init(). But, right now, it seems we can no longer call SDL_Init() from a background thread. Possibly we can initialize the video subsystem in a background thread? This seems to lock the SDL notion of the main thread.
    • It is claimed that on MacOS, SDL_Init() can only be used from the main thread.
    • After the latest Fedora 42 update, calling SDL_Init() from another thread causes the Gtk window decoration to fail.
    • We need better support for using multiple threads interactively
      • Deal with Prolog flags. Introduce globally scoped flags? Is this a flag property or a set_prolog_flag/2 alternative? Cause new flags to be globally scoped?
      • Deal with command line history

TODOs for replacing X11/Win32

  • Support image<-greyed in library(imageops).
    • Added image<-grayscale
  • Draw inside images.
  • Handle failure of get_xy_event()
  • Implement tooltips
    • Not properly placed and resized when moving between adjacent objects with a tooltip. See PceDraw graphical menu.
  • Implement graphical selection using inverted colours
  • Close popup if pointer leaves the owning window and popup?
    • Allow for a delay?
  • Graphics
    • Arc
    • Arrow
      • Use cairo's subpixel scaling for better rendering of rotated arrows
    • Ellipse
    • Bezier curve
      • Now uses interpolated path. Should use Cairo native
  • Allow fill patterns to be specified as foreground or background. This makes them adjust to the current colour.
  • Modify frame drawing by (1) pre-paint window areas with the window background (removes need for r_clear_outside()) and draw nice lines for dragable borders. The advantage is that that works server-side. Basically, that is the border around all windows and lines between the sub tiles.
    • Clean windows and remove r_clear_outside()
    • Paint frame background as border and areas between tiles, indicating which can be resized.
  • Use SDL_SetAppMetadata() and friends before SDL_init()
  • Reimplement in_pce_thread() using SDLs primitives for that. See sdl.c, sdl_send()
  • Implement creating cursors from images.
  • Implement receiving drop events from other applications. Generates an SDL_DropEvent event. See https://wiki.libsdl.org/SDL3/SDL_DropEvent

TODOs for XPCE next generation

  • Implement class epilog and allow running a Prolog thread with I/O attached to it, replacing swipl-win. Nicknamed Epilog See Replacing swipl‐win
  • Introduce floats for dimensions. This is required for sub-pixel rendering using logical coordinates. SDL uses floats, Cairo doubles and Pango fixed points (1/1024pt).
    • Replace xpce Int type to represent a tagged float, loosing 1 bit mantisse.
    • Support this in the Prolog interface
    • Introduce C Num type as synonym for Int
    • Introduce type num for the new non-object numeric type.
    • Re-introduce type int for values that need to be integer.
    • Modify class number to be the class equivalent of `num'.
    • Make class real and deprecated subclass of class number.
    • Replace most use of the real type with num.
    • Gradually change the sdldraw.c functions to use doubles and arithmetic inside graphical classes to use doubles. Start with classes where it matters most
      • arrow (avoid skewed arrows under non-90-degrees angles)
      • class text_cursor to make triangle neat on even-pitched fonts.
  • Add automatic theme selection. See SDL_GetSystemTheme()
    • Added display<-system_theme.
  • Use Pango font metrics to replace UNDERLINE_PEN and UNDERLINE_SEP.
  • Replace Postscript generation by Cairo.
  • Add PDF generation based on Cairo
  • Add transparency for graphicals
  • Add (matrix) transform to graphics. Should this be at the level of class device or graphical?

Bugs

  • ws_load_image() should properly cleanup the SDL surface or create the ciaro surface as a copy.
  • According to nvdia-smi, there is a video memory leak while scrolling around in a big file.
  • Scrolling a long file (library(clpfd)) lags while dragging the scrollbar. Can we early skip the redraw? Maybe poll for messages until we get none? Yes, see SDL_HasEvents()
  • Popup window is a little too big
  • When displayed on a sub-window, popup is misplaced.
  • Opening a popup on a tab label raises an error (wrong @arg1 context)
  • Moving and resizing objects "sprays"
    • In part solved using FloatArea(). See r_box() and r_ellipse()
  • GUI debugger shows background below binding window
  • GUI debugger variable window toggle of pin bitmap does not clear.
  • PceDraw menus are white. Somehow the converted .png does not draw transparent.
  • Select tool of visual hierarchy does not handle cursor well.
  • Visual hierarchy finding sub-graphicals seems buggy.
  • Gui tracer on test_chat/0: jump over sentence/5 messes up the stack view.
  • Handle double-width characters in Epilog. One option might be to fill two cells. First with the real char and the one after with a special char value, e.g., -1. That would keep wrapping work as it should.
  • xpce colour demo does not work properly
  • gxref/0 does not work properly.
    • Popups do now show
    • Drag and drop does not work. Does SDL support that?

Windows port bugs

  • Repaint in Epilog windows is sometimes incomplete, requires some interaction with the window to complete painting.
  • Epilog window does not go to start of line after entering a query.
  • Unicode > 0xffff support
    • Displaying text objects to respect UTF-16.
    • Class text_image (editor). Probably use uint32_t for character array
    • Class terminal_image (Epilog) uses own defined uchar_t.
    • Use uchar_t for wide PceString?

MacOS issues

  • Set TERM to xterm in bundle. Possibly on all platforms for Epilog.
  • For the bundle
    • Set initial working directory to ~/Documents/Prolog
    • Save and restore working directory in an XDG file

Testing

  • Test X11: SDL_VIDEODRIVER=x11 src/swipl gr.pl. Seems to work nicely.
  • Headless testing: SDL_VIDEODRIVER=dummy src/swipl gr.pl

Clone this wiki locally