#include <X11/StringDefs.h>
#include <X11/Xatom.h>
#include <X11/Shell.h>
+
#include "motif.h"
+#include "ewmhicon.h"
/* Size of the traditional icon pixmap (multiple of 3) */
#define ICON_SIZE 48
{
Display *display = XtDisplay(shell);
Dimension tilesz = ICON_SIZE/3;
- int i, j, tile;
-
- XColor colours[(TILE_MAX-1)*COLOUR_MAX];
- unsigned long *icons[ICON_MAX];
- void *wm_icon = NULL;
-
- if (state->use_ewmh_icons && (wm_icon = ewmh_icon_alloc(icons))) {
- Colormap cmap = DefaultColormapOfScreen(XtScreen(shell));
-
- for (i = 0; i < TILE_MAX-1; i++) {
- for (j = 0; j < COLOUR_MAX; j++) {
- XColor *c = &colours[i*COLOUR_MAX+j];
- c->pixel = state->tile_colour[i][j];
- }
- }
-
- XQueryColors(display, cmap, colours, i*j);
- }
+ 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);
+ i%3, i/3, tilesz, tilesz);
- if (wm_icon) {
- XColor *c = &colours[(tile-1)*COLOUR_MAX];
- ewmh_tile16(icons[ICON_16x16], c, i%3, i/3);
- ewmh_tile24(icons[ICON_24x24], c, i%3, i/3);
- ewmh_tile32(icons[ICON_32x32], c, i%3, i/3);
- ewmh_tile48(icons[ICON_48x48], c, i%3, i/3);
- }
+ ewmhseq[i] = COLOUR_MAX*0x10101 * (tile-1) + 0x20100;
}
/*
XtVaSetValues(shell, XtNiconPixmap, None, (char *)NULL);
XtVaSetValues(shell, XtNiconPixmap, state->icon_pixmap, (char *)NULL);
- if (wm_icon) {
+ if (state->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];
+ void *wm_icon;
- XChangeProperty(display, XtWindow(shell), net_wm_icon,
- XA_CARDINAL, 32, PropModeReplace,
- wm_icon, EWMH_ICON_NELEM);
+ for (i = 0; i < XtNumber(colours); i++) {
+ uint_least32_t *p = state->tile_colour[0];
+ colours[i].pixel = p[i];
+ }
+ XQueryColors(display, cmap, colours, XtNumber(colours));
+ wm_icon = ewmh_icon_generate(ewmhseq, colours);
+ if (wm_icon) {
+ XChangeProperty(display, XtWindow(shell), net_wm_icon,
+ XA_CARDINAL, 32, PropModeReplace,
+ wm_icon, EWMH_ICON_NELEM);
+ }
free(wm_icon);
}
}
mask >>= 1;
}
}
+
+/*
+ * Deferred redraw of tiles after resize/expose to avoid redundant drawing.
+ *
+ * Record any tiles that need to be redrawn due to resizes or expose events,
+ * then, after a short delay, perform all the accumulated redraws at once.
+ *
+ * This is implemented using both a work proc and a timeout, because it seems
+ * that rendering directly inside the timeout callback gives poor results:
+ * possibly redrawing outdated intermediate positions during "fast" resizes
+ * long after the resizing has stopped. This does not happen when drawing
+ * from a work proc.
+ */
+static Boolean do_render(void *data)
+{
+ struct app_state *state = data;
+
+ x11_redraw_goal(state, state->render_goal_mask);
+ 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;
+}
+
+static void start_render(void *data, XtIntervalId *id)
+{
+ struct app_state *state = data;
+ XtAppContext app;
+
+ if (state->render_proc)
+ return;
+
+ app = XtWidgetToApplicationContext(state->game);
+ state->render_proc = XtAppAddWorkProc(app, do_render, state);
+}
+
+void x11_queue_render(struct app_state *state, uint_fast32_t mask, int mode)
+{
+ uint_fast32_t changed = 0;
+ XtAppContext app;
+
+ 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)
+ return;
+
+ app = XtWidgetToApplicationContext(state->game);
+ state->render_tick = XtAppAddTimeOut(app, 3, start_render, state);
+}