Specifying Gargoyle's Glk extensions

I’ve finally come back to this after implementing the Garglk extensions in RemGlk-rs.

Here’s the final algorithm I implemented (a little different from what I suggested above):

  1. There are two methods for setting the window margin, stylehints and the Garglk extensions. Each store their own margin colour; which will be used is decided when glk_select is called.
  2. A call to glk_stylehint_set for a all/buffer window background colour immediately updates the stylehints margin colour, likewise a call to glk_stylehint_clear immediately clears it. Note that a setting the background colour stylehint for grid windows has no effect on the window margin.
  3. When setting via the Garglk extension functions, the stored colour is only actually updated when glk_window_clear is called (or when a zero height grid window is expanded, which is treated as clearing the window). Clearing any buffer window will update the stored colour, or clearing a grid window if there are no open buffer windows.
  4. The two stored colours could be active or inactive. If only one is active, then it’s simple, that colour is used for the window margin when glk_select is called. But if both are active, then it depends on which function was most recently called: glk_stylehint_set/glk_stylehint_clear or glk_window_clear. A more recent call to garglk_set_zcolors doesn’t matter, only the call to glk_window_clear.

This doesn’t match any existing implementation, but it’s what I think makes most sense.

It also means that my Test 2 is wrong as it’s not the timing of garglk_set_zcolors vs glk_stylehint_set that matters, but instead the timing of glk_window_clear vs glk_stylehint_set.

        garglk_set_zcolors(-1, $800020);
        glk(176, 0, 0, 8, $1F75FE); !glk_stylehint_set normal background Crayola blue
        glk(42, mainwin); !glk_window_clear

should be updated to

        garglk_set_zcolors(-1, $800020);
        glk(42, mainwin); !glk_window_clear
        glk(176, 0, 0, 8, $1F75FE); !glk_stylehint_set normal background Crayola blue

With my Remglk-rs, test 5 is still showing up with a red background/margin, which I don’t think is correct? I’m not sure why yet, will investigate more in the future.