bohonghuang / cl-gtk4

GTK4/Libadwaita/WebKit2 bindings for Common Lisp.
GNU Lesser General Public License v3.0
215 stars 9 forks source link

Getting the "root" window #32

Closed jonathanabennett closed 1 year ago

jonathanabennett commented 1 year ago

What's the best way to get the current root window? Should I be storing it in a global variable or is there already a global variable that has it?

In the game I am building, there are different phases of play, each phase of play needs to modify the contents of the window. I'm just now getting to the point where I need to find the best way to manage the transitions between phases and I'm running into a conceptual problem figuring out the best way to handle passing the window around to change it.

So for example, I have created a *game* global variable which has a CLOS class containing all the relevant global variables for the game's state (current turn, current phase, list of units, initiative order, etc). Then I write a advance-phase function that calls (incf (game/current-phase *game*)) which dispatches to a set of functions that I have written to build the display for each screen, like draw-initiative-phase, draw-deployment-phase. Each of those functions creates a gtk:container such as (let ((layout (gtk:make-grid))) ...) or make-box. How do I then get that container passed to my main window?

bohonghuang commented 1 year ago

Simply using (gtk:application-get-window-by-id gtk:*application* 1) should work. Alternatively, you can use (mapcar (alexandria:rcurry #'gobj:pointer-object 'gtk:window) (glib:glist-list (gtk:application-windows gtk:*application*))) to retrieve all windows and then filter them.