]> git.draconx.ca Git - rrace.git/commitdiff
Combine x11_redraw_icon and x11_redraw_goal.
authorNick Bowler <nbowler@draconx.ca>
Tue, 13 Dec 2022 06:07:25 +0000 (01:07 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 14 Dec 2022 03:10:21 +0000 (22:10 -0500)
These functions do basically the same thing -- the main difference is the
destination drawable.  They are also often called together.  No need for
this duplication.

src/motif.c
src/motif.h
src/x11.c

index c8261fc85176d11b25d54175012ecff2d3239ff3..891fe471235f997260c222049c1c0b5fbeccf814 100644 (file)
@@ -233,9 +233,8 @@ static void proc_new_game(Widget w, XEvent *e, String *argv, Cardinal *argc)
 {
        game_reset(&state.board);
 
-       x11_redraw_goal(&state, -1);
+       x11_redraw_goal(&state, -1, get_shell(w));
        x11_redraw_game(&state, -1);
-       x11_redraw_icon(&state, get_shell(w));
 
        if (!state.timer_tick) {
                XtAppContext app = XtWidgetToApplicationContext(w);
@@ -282,7 +281,7 @@ static XtAppContext app_initialize(int argc, char **argv)
        state.use_ewmh_icons = ewmh_probe_wm_icon(shell);
        XtRealizeWidget(shell);
 
-       x11_redraw_icon(&state, shell);
+       x11_redraw_goal(&state, 0, shell);
 
        return app;
 }
index 076f4f60cfd58da466a9e8b78b02cc3b45a8b3cc..361abd98b12690807dff01e59e1166e794625e41 100644 (file)
@@ -55,9 +55,21 @@ void ui_timer_update(struct app_state *state, int_fast32_t elapsed);
 
 void x11_initialize(struct app_state *state, Widget shell);
 void x11_redraw_icon(struct app_state *state, Widget shell);
-void x11_redraw_goal(struct app_state *state, uint_fast32_t mask);
 void x11_redraw_game(struct app_state *state, uint_fast32_t mask);
 
+/*
+ * Redraw goal tiles immediately.  The mask specifies which tiles will
+ * be redrawn, in the same bit arrangement as the board goal bitmaps.
+ * Tiles corresponding to set bits in mask are redrawn, and tiles
+ * corresponding to clear bits are not redrawn.
+ *
+ * Additionally, if icon_shell is non-null (with the caller passing the
+ * application shell widget), the program's icon pixmap is updated to
+ * match the current goal.
+ */
+void x11_redraw_goal(struct app_state *state, uint_fast32_t mask,
+                                              Widget icon_shell);
+
 /*
  * Mark tiles for redraw.  The redraw is not performed immediately, but
  * rather a background task is installed to perform the redraw at a later
index 34f43a9e66de6cd28401ec1019eaaf93a6e96e37..b15e7d67c18b4dd9d084c4f061b27d6b4cbddd24 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -197,60 +197,9 @@ redraw_tile(struct app_state *state, Display *display, Drawable d,
        return tile;
 }
 
-static int
-redraw_goal_tile(struct app_state *state, Display *display, Drawable d,
-                 int x, int y, Dimension w, Dimension h)
-{
-       uint_least32_t gp[3] = {
-               state->board.goal[0],
-               state->board.goal[1],
-               state->board.goal[2]
-       };
-
-       return redraw_tile(state, display, d, gp, x, y, w, h);
-}
-
-void x11_redraw_goal(struct app_state *state, uint_fast32_t mask)
+static void set_icon(struct app_state *state, Display *display,
+                     Widget shell, unsigned long *ewmhseq)
 {
-       Display *display = XtDisplay(state->goal);
-       Window goal = XtWindow(state->goal);
-       Dimension w, h;
-       int i;
-
-       XtVaGetValues(state->goal, XtNwidth, &w, XtNheight, &h, (char *)NULL);
-       w /= 3; h /= 3;
-
-       for (i = 0; i < 9; i++) {
-               int x = i%3, y = i/3;
-
-               if (mask & 1)
-                       redraw_goal_tile(state, display, goal, x, y, w, h);
-
-               /*
-                * Goal bitmaps have a gap of 2 tiles between each row.
-                * This funny shift will accomodate that.
-                */
-               mask >>= 1|x;
-       }
-}
-
-/* Render the goal area as the window's icon */
-void x11_redraw_icon(struct app_state *state, Widget shell)
-{
-       Display *display = XtDisplay(shell);
-       Dimension tilesz = ICON_SIZE/3;
-       unsigned long ewmhseq[9];
-       unsigned i;
-
-       for (i = 0; i < 9; i++) {
-               int tile;
-
-               tile = redraw_goal_tile(state, display, state->icon_pixmap,
-                                              i%3, i/3, tilesz, tilesz);
-
-               ewmhseq[i] = COLOUR_MAX*0x10101 * (tile-1) + 0x20100;
-       }
-
        /*
         * Clear and reset XtNiconPixmap otherwise it seems dtwm will not
         * notice the changed icon.
@@ -263,6 +212,7 @@ void x11_redraw_icon(struct app_state *state, Widget shell)
                Colormap cmap = DefaultColormapOfScreen(XtScreen(shell));
                XColor colours[(TILE_MAX-1)*COLOUR_MAX];
                void *wm_icon;
+               int i;
 
                for (i = 0; i < XtNumber(colours); i++) {
                        uint_least32_t *p = state->tile_colour[0];
@@ -280,6 +230,49 @@ void x11_redraw_icon(struct app_state *state, Widget shell)
        }
 }
 
+void
+x11_redraw_goal(struct app_state *state, uint_fast32_t mask, Widget icon_shell)
+{
+       Display *display = XtDisplay(state->goal);
+       Window goal = XtWindow(state->goal);
+       unsigned long ewmhseq[9];
+       Dimension w, h;
+       int i;
+
+       uint_least32_t gp[3] = {
+               state->board.goal[0],
+               state->board.goal[1],
+               state->board.goal[2]
+       };
+
+       XtVaGetValues(state->goal, XtNwidth, &w, XtNheight, &h, (char *)NULL);
+       w /= 3; h /= 3;
+
+       for (i = 0; i < 9; i++) {
+               int x = i%3, y = i/3;
+
+               if (icon_shell) {
+                       unsigned tile;
+
+                       tile = redraw_tile(state, display, state->icon_pixmap,
+                                          gp, x, y, ICON_SIZE/3, ICON_SIZE/3);
+                       ewmhseq[i] = COLOUR_MAX*0x10101 * (tile-1) + 0x20100;
+               }
+
+               if (mask & 1)
+                       redraw_tile(state, display, goal, gp, x, y, w, h);
+
+               /*
+                * Goal bitmaps have a gap of 2 tiles between each row.
+                * This funny shift will accomodate that.
+                */
+               mask >>= 1|x;
+       }
+
+       if (icon_shell)
+               set_icon(state, display, icon_shell, ewmhseq);
+}
+
 void x11_redraw_game(struct app_state *state, uint_fast32_t mask)
 {
        Display *display = XtDisplay(state->goal);
@@ -328,7 +321,7 @@ static Boolean do_render(void *data)
 {
        struct app_state *state = data;
 
-       x11_redraw_goal(state, state->render_goal_mask);
+       x11_redraw_goal(state, state->render_goal_mask, NULL);
        x11_redraw_game(state, state->render_game_mask);
 
        state->render_goal_mask = state->render_game_mask = 0;