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
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.
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];
}
}
+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);
{
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;