From: Nick Bowler Date: Tue, 13 Dec 2022 06:07:25 +0000 (-0500) Subject: Combine x11_redraw_icon and x11_redraw_goal. X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/commitdiff_plain/174f6502f73fa29e1102938029d7b9f59b245c1b Combine x11_redraw_icon and x11_redraw_goal. 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. --- diff --git a/src/motif.c b/src/motif.c index c8261fc..891fe47 100644 --- a/src/motif.c +++ b/src/motif.c @@ -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; } diff --git a/src/motif.h b/src/motif.h index 076f4f6..361abd9 100644 --- a/src/motif.h +++ b/src/motif.h @@ -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 diff --git a/src/x11.c b/src/x11.c index 34f43a9..b15e7d6 100644 --- 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;