plan9port/src/cmd/rio/error.c

100 lines
2 KiB
C
Raw Normal View History

2004-03-21 04:27:28 +00:00
/* Copyright (c) 1994-1996 David Hogan, see README for licence details */
#include <stdio.h>
#include <stdlib.h>
2004-03-21 04:27:28 +00:00
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include "dat.h"
#include "fns.h"
int ignore_badwindow;
void
fatal(char *s)
{
2004-04-19 19:35:17 +00:00
fprintf(stderr, "rio: ");
2004-03-21 04:27:28 +00:00
perror(s);
fprintf(stderr, "\n");
exit(1);
}
int
handler(Display *d, XErrorEvent *e)
{
char msg[80], req[80], number[80];
if (initting && (e->request_code == X_ChangeWindowAttributes) && (e->error_code == BadAccess)) {
2004-04-19 19:35:17 +00:00
fprintf(stderr, "rio: it looks like there's already a window manager running; rio not started\n");
2004-03-21 04:27:28 +00:00
exit(1);
}
if (ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor))
return 0;
XGetErrorText(d, e->error_code, msg, sizeof(msg));
sprintf(number, "%d", e->request_code);
XGetErrorDatabaseText(d, "XRequest", number, "", req, sizeof(req));
if (req[0] == '\0')
sprintf(req, "<request-code-%d>", (int)e->request_code);
2004-03-21 04:27:28 +00:00
2004-04-19 19:35:17 +00:00
fprintf(stderr, "rio: %s(0x%x): %s\n", req, (int)e->resourceid, msg);
2004-03-21 04:27:28 +00:00
if (initting) {
2004-04-19 19:35:17 +00:00
fprintf(stderr, "rio: failure during initialisation; aborting\n");
2004-03-21 04:27:28 +00:00
exit(1);
}
return 0;
}
void
graberror(char *f, int err)
{
#ifdef DEBUG /* sick of "bug" reports; grab errors "just happen" */
char *s;
switch (err) {
case GrabNotViewable:
s = "not viewable";
break;
case AlreadyGrabbed:
s = "already grabbed";
break;
case GrabFrozen:
s = "grab frozen";
break;
case GrabInvalidTime:
s = "invalid time";
break;
case GrabSuccess:
return;
default:
2004-04-19 19:35:17 +00:00
fprintf(stderr, "rio: %s: grab error: %d\n", f, err);
2004-03-21 04:27:28 +00:00
return;
}
2004-04-19 19:35:17 +00:00
fprintf(stderr, "rio: %s: grab error: %s\n", f, s);
2004-03-21 04:27:28 +00:00
#endif
}
#ifdef DEBUG_EV
#include "showevent/ShowEvent.c"
#endif
#ifdef DEBUG
void
dotrace(char *s, Client *c, XEvent *e)
{
2004-04-19 19:35:17 +00:00
fprintf(stderr, "rio: %s: c=0x%x", s, c);
2004-03-21 04:27:28 +00:00
if (c)
fprintf(stderr, " x %d y %d dx %d dy %d w 0x%x parent 0x%x", c->x, c->y, c->dx, c->dy, c->window, c->parent);
#ifdef DEBUG_EV
if (e) {
fprintf(stderr, "\n\t");
ShowEvent(e);
}
#endif
fprintf(stderr, "\n");
}
#endif