Turns out that just getting the widget width from Xt represents
the vast majority of the time spent on the timer update. It is
very simple to query the width only when it changes, instead,
and save that result for later rendering.
/*
* Helpers for implementing a rapid-update counter display in Motif.
/*
* Helpers for implementing a rapid-update counter display in Motif.
- * 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
*
* 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
Pixmap pixmap;
uint_least32_t render_mask;
Pixmap pixmap;
uint_least32_t render_mask;
+
+ /* Cached width of the widget */
+ uint_least16_t render_width;
+
unsigned char seq[23], num_strings;
/*
unsigned char seq[23], num_strings;
/*
xc->widget = w;
for (i = 0; i < nstr; i++) {
xc->widget = w;
for (i = 0; i < nstr; i++) {
if ((h = XmStringHeight(rt, strings[i])) > height)
height = h + 2*MARGIN;
if ((h = XmStringHeight(rt, strings[i])) > height)
height = h + 2*MARGIN;
Drawable d = XtWindow(xc->widget);
unsigned out_x = MARGIN, src_x, w;
Drawable d = XtWindow(xc->widget);
unsigned out_x = MARGIN, src_x, w;
- XtVaGetValues(xc->widget, XmNwidth, &max_w,
- (char *)NULL);
- max_w = MAX(MARGIN, max_w) - MARGIN;
-
+ max_w = MAX(MARGIN, xc->render_width) - MARGIN;
xc_foreach_seq(xc, i, out_x, src_x, w, mask) {
if (out_x + w > max_w) {
w = max_w - out_x;
xc_foreach_seq(xc, i, out_x, src_x, w, mask) {
if (out_x + w > max_w) {
w = max_w - out_x;
void xcounter_resize_cb(Widget w, void *data, void *cb_data)
{
void xcounter_resize_cb(Widget w, void *data, void *cb_data)
{
- xc_queue_render(data, XC_RESIZING);
+ struct xcounter *xc = data;
+ Dimension width;
+
+ XtVaGetValues(xc->widget, XmNwidth, &width, (char *)NULL);
+ xc->render_width = width;
+
+ xc_queue_render(xc, XC_RESIZING);
}
void xcounter_expose_cb(Widget w, void *data, void *cb_data)
}
void xcounter_expose_cb(Widget w, void *data, void *cb_data)
/*
* Helpers for implementing a rapid-update counter display in Motif.
/*
* Helpers for implementing a rapid-update counter display in Motif.
- * 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
*
* 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
void xcounter_expose_cb(Widget w, void *data, void *cb_data);
/*
void xcounter_expose_cb(Widget w, void *data, void *cb_data);
/*
- * Clear the margins of the counter after resizing the widget.
+ * Call after the widget is resized to update the internal dimensions,
+ * and clear the margins.
*
* Since the pre-rendered text never changes, this is all that is needed:
* existing portions of the window do not need to be redrawn (except when
*
* Since the pre-rendered text never changes, this is all that is needed:
* existing portions of the window do not need to be redrawn (except when