]> git.draconx.ca Git - rrace.git/blobdiff - src/x11.c
motif: Combine status details into a single flags member.
[rrace.git] / src / x11.c
index 6d09a7dcfc09f7359db1daeba62d980bae65cfd4..44bb8670ebec32c805917630acc9b3e32f1158d5 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -1,6 +1,6 @@
 /*
  * X11 GUI for slide puzzle game
- * Copyright © 2022 Nick Bowler
+ * Copyright © 2022-2023 Nick Bowler
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #  include <unistd.h>
 #endif
 
+/* status flags in the upper bits are ORed into the game mask which only
+ * needs the lower 25 bits */
+#define X11_TICK_INSTALLED (1ul << 31)
+#define X11_PROC_INSTALLED (1ul << 30)
+
 enum {
        NUM_TILE_COLOURS = COLOUR_MAX*(TILE_MAX-1),
        COLOUR_UI_GAMEBG = NUM_TILE_COLOURS,
@@ -209,7 +214,7 @@ static void set_icon(struct app_state *state, Display *display,
        XtVaSetValues(shell, XtNiconPixmap, None, (char *)NULL);
        XtVaSetValues(shell, XtNiconPixmap, state->icon_pixmap, (char *)NULL);
 
-       if (state->use_ewmh_icons) {
+       if (state->flags & FLAG_USE_EWMH_ICONS) {
                Atom net_wm_icon = XInternAtom(display, "_NET_WM_ICON", FALSE);
                Colormap cmap = DefaultColormapOfScreen(XtScreen(shell));
                XColor colours[(TILE_MAX-1)*COLOUR_MAX];
@@ -280,7 +285,7 @@ void x11_redraw_game(struct app_state *state, uint_fast32_t mask)
        unsigned sz = state->game_tile_sz;
        int i;
 
-       if (state->view_goal_on_game) {
+       if (state->flags & FLAG_VIEW_GOAL_ON_GAME) {
                for (i = 0; i < 3; i++) {
                        buf[i] = state->board.goal[i];
                        buf[i] = (gp[i] & ~GOAL_MASK) | (buf[i] << GOAL_SHIFT);
@@ -321,8 +326,6 @@ static Boolean do_render(void *data)
        x11_redraw_game(state, state->render_game_mask);
 
        state->render_goal_mask = state->render_game_mask = 0;
-       state->render_proc = 0;
-       state->render_tick = 0;
        return True;
 }
 
@@ -331,11 +334,12 @@ static void start_render(void *data, XtIntervalId *id)
        struct app_state *state = data;
        XtAppContext app;
 
-       if (state->render_proc)
+       if (state->render_game_mask & X11_PROC_INSTALLED)
                return;
 
+       state->render_game_mask |= X11_PROC_INSTALLED;
        app = XtWidgetToApplicationContext(state->game);
-       state->render_proc = XtAppAddWorkProc(app, do_render, state);
+       XtAppAddWorkProc(app, do_render, state);
 }
 
 void x11_queue_render(struct app_state *state, uint_fast32_t mask, int mode)
@@ -343,14 +347,16 @@ void x11_queue_render(struct app_state *state, uint_fast32_t mask, int mode)
        uint_fast32_t changed = 0;
        XtAppContext app;
 
+       mask &= GAME_MASK;
        if (mode & RENDER_MODE_GOAL)
                changed |= state->render_goal_mask |= mask;
        if (mode & RENDER_MODE_GAME)
                changed |= state->render_game_mask |= mask;
 
-       if (state->render_tick || !changed)
+       if (changed & X11_TICK_INSTALLED || !changed)
                return;
 
+       state->render_game_mask |= X11_TICK_INSTALLED;
        app = XtWidgetToApplicationContext(state->game);
-       state->render_tick = XtAppAddTimeOut(app, 3, start_render, state);
+       XtAppAddTimeOut(app, 3, start_render, state);
 }