commit a9cbbb6004f5675d1c974a4909da96fe4ba452a3
parent d6599a6cb90a3c0ebdbf783c6e3f40ec4eaf82df
Author: Kyle Milz <krwmilz@gmail.com>
Date: Thu, 9 Sep 2021 20:23:42 +0000
remove timer interfaces
This is not a critical feature and added significant complexity.
Diffstat:
M | dvi-draw.c | | | 67 | ++----------------------------------------------------------------- |
M | events.c | | | 110 | +------------------------------------------------------------------------------ |
M | events.h | | | 12 | ------------ |
M | popups.c | | | 169 | ++----------------------------------------------------------------------------- |
M | popups.h | | | 13 | ------------- |
5 files changed, 6 insertions(+), 365 deletions(-)
diff --git a/dvi-draw.c b/dvi-draw.c
@@ -30,16 +30,10 @@ NOTE:
#include <ctype.h>
#include <stdarg.h>
-#include <X11/StringDefs.h>
-#include <X11/Xaw/Label.h>
-#include <X11/XKBlib.h>
-#define XBell(dpy, percent) XkbBell(dpy, mane.win, percent, (Atom) None)
-
#include "dvi-draw.h" /* drawing_mag */
#include "dvi-init.h" /* check_dvi_file() */
-#include "events.h" /* read_events(), do_color_change(), set_timer(), ... */
+#include "events.h" /* read_events(), do_color_change(), ... */
#include "font.h" /* load_ft_font() XXX more */
-#include "popups.h" /* simple_popdown(), simple_popup() */
#include "special.h" /* scan_special(), ... */
#include "util.h" /* xfopen(), snum() */
#include "xdvi.h"
@@ -676,63 +670,17 @@ spcl_scan(spcl_proc)
* `header=' and `!'.
*/
-
-static void show_status(struct xtimer *);
-
-static struct xtimer pst = TIMER_INIT(show_status);
-
-struct prescan_rec {
- Boolean timer_active;
- Boolean popup_active;
- struct status_popup *pp;
- char *scanmsg;
-};
-
-static struct prescan_rec *psrp = NULL;
-
-/* Window manager destroy callback */
-/* ARGSUSED */
-static void
-status_cb_destroy(w, client_data, call_data)
- Widget w;
- XtPointer client_data;
- XtPointer call_data;
-{
- psrp->popup_active = False;
- simple_popdown(psrp->pp);
-}
-
-static void
-show_status(arg)
- struct xtimer *arg;
-{
- psrp->timer_active = False;
- psrp->popup_active = True;
- simple_popup(psrp->pp, psrp->scanmsg, status_cb_destroy);
-}
-
-
void
prescan(void)
{
int nextreportpage;
- char scanmsg[40];
- static struct status_popup popup = {NULL, NULL, 0, False, False};
- struct prescan_rec pr;
dvi_file_ready = False;
nextreportpage = scanned_page;
- (void) fseek(dvi_file, page_info[scanned_page + 1].offset,
- SEEK_SET);
+ fseek(dvi_file, page_info[scanned_page + 1].offset, SEEK_SET);
currinf.pos = currinf.end = dvi_buffer;
- pr.timer_active = True;
- pr.popup_active = False;
- pr.pp = &popup;
- pr.scanmsg = scanmsg;
- psrp = ≺
- set_timer(&pst, 1000);
for (;;) {
page_info[scanned_page + 1].pw = page_info[scanned_page].pw;
page_info[scanned_page + 1].ph = page_info[scanned_page].ph;
@@ -745,11 +693,6 @@ prescan(void)
nextreportpage += REPORT_INCR;
if (nextreportpage > current_page)
nextreportpage = current_page;
- Sprintf(scanmsg, "Scanning pages %d-%d",
- scanned_page + 1 + pageno_correct,
- nextreportpage + pageno_correct);
- if (pr.popup_active)
- XtVaSetValues(popup.label, XtNlabel, scanmsg, NULL);
}
if (read_events(EV_NOWAIT) & EV_GE_NEWPAGE) break;
@@ -765,12 +708,6 @@ prescan(void)
if (scanned_page >= current_page) break;
}
-
- if (pr.popup_active)
- simple_popdown(&popup);
- else if (pr.timer_active)
- cancel_timer(&pst);
-
}
/*
diff --git a/events.c b/events.c
@@ -1706,11 +1706,9 @@ volatile unsigned int sig_flags = 0;
static void do_sigterm(void);
static void do_sigchld(void);
static void do_sigpoll(void);
-static void do_sigalrm(void);
static void do_sigusr(void);
#define SP0 do_sigusr /* these must be in the same order as SF_* */
-#define SP1 do_sigalrm
#define SP2 do_sigpoll
#define SP3 do_sigchld
#define SP4 do_sigterm /* highest priority */
@@ -1718,13 +1716,12 @@ static void do_sigusr(void);
typedef void (*signalproc)(void);
static const signalproc flags_to_sigproc[32]
- = {NULL, SP0, SP1, SP1, SP2, SP2, SP2, SP2,
+ = {NULL, SP0, SP4, SP4, SP2, SP2, SP2, SP2,
SP3, SP3, SP3, SP3, SP3, SP3, SP3, SP3,
SP4, SP4, SP4, SP4, SP4, SP4, SP4, SP4,
SP4, SP4, SP4, SP4, SP4, SP4, SP4, SP4};
#undef SP0
-#undef SP1
#undef SP2
#undef SP3
#undef SP4
@@ -2027,111 +2024,6 @@ do_sigpoll()
/*
- * Timer-related routines. Call set_timer() to set a timer a given number
- * of milliseconds in the future. At that time, the timer will be cleared
- * and the given procedure will be called with argument set to the struct
- * passed to set_timer(). The timer routine may call set_timer() or
- * cancel_timer().
- */
-
-
-static struct xtimer *timers = NULL; /* head of timer list */
-
-static struct itimerval itv = {{0, 0}, {0, 0}};
-
-#ifndef timercmp
-#define timercmp(a, b, cmp) ((a)->tv_sec cmp (b)->tv_sec || \
- ((a)->tv_sec == (b)->tv_sec && (a)->tv_usec cmp (b)->tv_usec))
-#endif /* timercmp */
-
-void
-set_timer(tp, ms)
- struct xtimer *tp;
- int ms;
-{
- struct xtimer **tpp;
- struct xtimer *tp2;
-
- gettimeofday(&tp->when, NULL);
- itv.it_value.tv_sec = ms / 1000;
- itv.it_value.tv_usec = (ms % 1000) * 1000;
- tp->when.tv_sec += itv.it_value.tv_sec;
- tp->when.tv_usec += itv.it_value.tv_usec;
- if (tp->when.tv_usec >= 1000000) {
- tp->when.tv_usec -= 1000000;
- ++tp->when.tv_sec;
- }
-
- for (tpp = &timers;;) { /* add timer to list */
- tp2 = *tpp;
- if (tp2 == NULL || timercmp(&tp->when, &tp2->when, <))
- break;
- tpp = &tp2->next;
- }
- tp->next = tp2;
- *tpp = tp;
-
- if (tpp == &timers) {
- setitimer(ITIMER_REAL, &itv, NULL);
- if (ms == 0)
- sig_flags |= SF_ALRM;
- }
-}
-
-void
-cancel_timer(tp)
- struct xtimer *tp;
-{
- struct xtimer **tpp;
-
- for (tpp = &timers;;) { /* remove from list */
- if (*tpp == tp)
- break;
- tpp = &(*tpp)->next;
- }
-
- *tpp = (*tpp)->next; /* unlink it */
-
- if (timers == NULL) { /* cancel SIGALRM */
- itv.it_value.tv_sec = itv.it_value.tv_usec = 0;
- setitimer(ITIMER_REAL, &itv, NULL);
- }
-}
-
-static void
-do_sigalrm()
-{
- struct timeval now;
-
- sig_flags &= ~SF_ALRM;
-
- gettimeofday(&now, NULL);
-
- while (timers != NULL && timercmp(&timers->when, &now, <=)) {
- struct xtimer *tp;
-
- tp = timers;
- timers = timers->next; /* unlink it _first_ */
- (tp->proc)(tp);
- }
-
- if (timers != NULL) { /* set next timer */
- int i;
-
- itv.it_value.tv_sec = timers->when.tv_sec - now.tv_sec;
- i = timers->when.tv_usec - now.tv_usec;
- if (i < 0) {
- --itv.it_value.tv_sec;
- i += 1000000;
- }
- itv.it_value.tv_usec = i;
-
- setitimer(ITIMER_REAL, &itv, NULL);
- }
-}
-
-
-/*
* Handle SIGUSR1 signal. Pretty straightforward.
*/
diff --git a/events.h b/events.h
@@ -1,5 +1,3 @@
-#include <sys/time.h> /* struct timeval */
-
#include <X11/Intrinsic.h>
#include <poll.h> /* struct pollfd */
@@ -23,13 +21,6 @@ struct wheel_acts {
struct wheel_acts *wheel_actions;
-struct xtimer {
- struct xtimer *next; /* link to next in chain */
- struct timeval when; /* when to call the routine */
- void (*proc)(struct xtimer *); /* procedure to call */
-};
-#define TIMER_INIT(proc) {NULL, {0, 0}, proc}
-
struct xio {
struct xio *next; /* link to next in list */
int fd; /* file descriptor */
@@ -103,9 +94,6 @@ void handle_resize(Widget, XtPointer, XEvent *, Boolean *);
void handle_messages(Widget, XtPointer, XEvent *, Boolean *);
unsigned int read_events(unsigned int);
-void set_timer(struct xtimer *, int);
-void cancel_timer(struct xtimer *);
-
void set_io(struct xio *);
void clear_io(struct xio *);
diff --git a/popups.c b/popups.c
@@ -47,7 +47,7 @@ IN THE SOFTWARE.
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Viewport.h>
-#include "events.h" /* struct xtimer, TIMER_INIT, set_timer(), ... */
+#include "events.h" /* handle_messages(), mane, struct xio */
#include "popups.h"
#include "xdvi.h"
#include "util.h" /* prep_fd(), xfopen(), xputenv() */
@@ -143,145 +143,6 @@ XdviXawRealizePopup(shell, callback)
}
-
-/*
- * Simple popup - Just a text message. May not be done before realizing
- * the main window.
- */
-
-/*
- * In reality, the "simple" popup is not so simple, because certain
- * window managers (e.g., twm, fvwm1) leave the window showing if you
- * pop it down too soon after popping it up. To remedy this, we delay
- * calling XtPopdown() until the previous call to XtPopup() has generated
- * a MapNotify event. Likewise, we delay XtPopup() until the previous
- * XtPopdown() call has produced an UnmapNotify event.
- *
- * To make it just a little more complicated, for some reason the popup
- * may get mapped after being unmapped. If so, we call XtPopup() to
- * inform the toolkit of its mistake, and arrange to expect some spurious
- * events. To reproduce this bug, remove the "spurious" code, run xdvi,
- * move the mouse a little, then hit "n" a few times. This happens only
- * with twm.
- */
-
-/* ARGSUSED */
-static void
-handle_popup_events(widget, rec, ev, cont)
- Widget widget;
- XtPointer rec;
- XEvent *ev;
- Boolean *cont; /* unused */
-{
-#define prec ((struct status_popup *) rec)
-
- if (ev->type == MapNotify) {
- if (prec->expected_type == MapNotify) {
- prec->expected_type = 0;
- if (!prec->popped) {
- prec->expected_type = UnmapNotify;
- XtPopdown(prec->shell);
- }
- }
- else {
- if (debug & DBG_EVENT)
- fprintf(stderr,
- "handle_popup_events: got spurious MapNotify\n");
- prec->expected_type = UnmapNotify;
- prec->spurious = True;
- XtPopup(prec->shell, XtGrabNone);
- }
- }
- else if (ev->type == UnmapNotify) {
- if (prec->expected_type == UnmapNotify) {
- prec->expected_type = 0;
- if (prec->spurious) {
- prec->expected_type = MapNotify;
- prec->spurious = False;
- }
- else if (prec->popped) {
- prec->expected_type = MapNotify;
- XtPopup(prec->shell, XtGrabNone);
- }
- }
- else
- if (debug & DBG_EVENT)
- fprintf(stderr,
- "handle_popup_events: got spurious UnmapNotify\n");
- }
-
-#undef prec
-}
-
-
-
-void
-simple_popup(rec, message, callback)
- struct status_popup *rec;
- const char *message;
- XtCallbackProc callback;
-{
- Position x, y;
- Dimension w1, h1, w2, h2;
- Boolean old_rec_popped = rec->popped;
-
- rec->popped = True;
- if (rec->shell == NULL) {
- rec->shell = XtVaCreatePopupShell("status",
- transientShellWidgetClass, top_level,
- XtNtitle, "Xdvi status",
- XtNmappedWhenManaged, False,
- XtNallowShellResize, True,
- XtNtransientFor, top_level,
- NULL);
- XtAddEventHandler(rec->shell, StructureNotifyMask, False,
- handle_popup_events, (XtPointer) rec);
-
- rec->label = XtVaCreateManagedWidget("label", labelWidgetClass,
- rec->shell,
- XtNlabel, message,
- NULL);
-
- XdviXawRealizePopup(rec->shell, callback);
- }
- else
- XtVaSetValues(rec->label, XtNlabel, message, NULL);
-
- if (mane.win != (Window) 0)
- XtVaGetValues(top_level, XtNx, &x, XtNy, &y,
- XtNwidth, &w1, XtNheight, &h1, NULL);
- else {
- x = y = 0;
- w1 = WidthOfScreen(SCRN);
- h1 = HeightOfScreen(SCRN);
- }
-
- /* Get the size of the popup window */
- XtVaGetValues(rec->label, XtNwidth, &w2, XtNheight, &h2, NULL);
-
- /* Center the popup over the main window */
- XtVaSetValues(rec->shell, XtNx, x + (w1 - w2) / 2,
- XtNy, y + (h1 - h2) / 2, NULL);
-
- if (!rec->expected_type && !old_rec_popped) {
- rec->expected_type = MapNotify;
- XtPopup(rec->shell, XtGrabNone);
- }
-}
-
-
-void
-simple_popdown(rec)
- struct status_popup *rec;
-{
- rec->popped = False;
- if (!rec->expected_type) {
- rec->expected_type = UnmapNotify;
- XtPopdown(rec->shell);
- }
-}
-
-
/*
* Warning popup - used for most error and notice conditions.
* It includes a message and a button (and, in the case of the Motif
@@ -1079,8 +940,6 @@ static void read_from_dvips(void);
static struct xio print_xio = {NULL, 0, XIO_IN, NULL,
read_from_dvips, NULL};
-static void dvips_alarm(struct xtimer *);
-static struct xtimer dvips_timer = TIMER_INIT(dvips_alarm);
static int dvips_status;
#define DVIPS_STAT_NONE 0
#define DVIPS_STAT_RUN 1
@@ -1615,7 +1474,6 @@ static void
dvips_ended(status)
{
char *str;
- int ms;
read_from_dvips();
clear_io(&print_xio);
@@ -1638,21 +1496,13 @@ dvips_ended(status)
str = mprintf("\nPrint process returned unknown status 0x%x.\n",
status);
- ms = resource.dvips_hang;
if (str != NULL) {
- ms = resource.dvips_fail_hang;
printlog_append(str, strlen(str));
free(str);
}
- if (ms > 0) {
- set_timer(&dvips_timer, ms);
- dvips_status = DVIPS_STAT_WAIT;
- }
- else {
- printlog_act_keep(NULL, NULL, NULL, NULL);
- dvips_status = DVIPS_STAT_NONE;
- }
+ printlog_act_keep(NULL, NULL, NULL, NULL);
+ dvips_status = DVIPS_STAT_NONE;
XtSetSensitive(printlog_close, True);
XtSetSensitive(printlog_cancel, False);
@@ -1665,18 +1515,6 @@ dvips_pop_down()
printlog_active = False;
}
-static void
-dvips_alarm(arg)
- struct xtimer *arg;
-{
- Boolean state;
-
- XtVaGetValues(printlog_keep, XtNstate, &state, NULL);
- if (!state)
- dvips_pop_down();
- dvips_status = DVIPS_STAT_NONE;
-}
-
/* ARGSUSED */
static void
cb_dvips_close(w, client_data, call_data)
@@ -1689,7 +1527,6 @@ cb_dvips_close(w, client_data, call_data)
if (dvips_status == DVIPS_STAT_WAIT) {
dvips_status = DVIPS_STAT_NONE;
- cancel_timer(&dvips_timer);
}
dvips_pop_down();
diff --git a/popups.h b/popups.h
@@ -1,21 +1,8 @@
#include <X11/Intrinsic.h>
-/*
- * Structure to use for status popups.
- */
-
-struct status_popup {
- Widget shell;
- Widget label;
- int expected_type;
- Boolean popped;
- Boolean spurious;
-};
void Act_print(Widget, XEvent *, String *, Cardinal *);
void do_popup(Widget);
-void simple_popdown(struct status_popup *);
-void simple_popup(struct status_popup *, const char *, XtCallbackProc);
Widget warning_popup(const char *, const char *, XtCallbackProc);
Widget warning_popup_long(const char *, const char *, XtCallbackProc, ...);