2019-12-02 18:23:00 +00:00
|
|
|
/* Copyright (c) 1994-1996 David Hogan, see README for licence details */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xproto.h>
|
2022-02-27 17:18:17 +00:00
|
|
|
#include <X11/extensions/Xrandr.h>
|
2019-12-02 18:23:00 +00:00
|
|
|
#include "dat.h"
|
|
|
|
#include "fns.h"
|
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
int ignore_badwindow;
|
2019-12-02 18:23:00 +00:00
|
|
|
|
2021-02-26 19:50:23 +00:00
|
|
|
void fatal(char* s) {
|
2021-02-26 18:01:22 +00:00
|
|
|
fprintf(stderr, "ryudo: ");
|
|
|
|
perror(s);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
exit(1);
|
2019-12-02 18:23:00 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 19:50:23 +00:00
|
|
|
int handler(Display* d, XErrorEvent* e) {
|
2021-02-26 18:01:22 +00:00
|
|
|
char msg[80], req[80], number[80];
|
2019-12-02 18:23:00 +00:00
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
if (
|
|
|
|
initting && (e->request_code == X_ChangeWindowAttributes) &&
|
|
|
|
(e->error_code == BadAccess)) {
|
|
|
|
fprintf(
|
|
|
|
stderr,
|
|
|
|
"ryudo: it looks like there's already a window manager running; ryudo "
|
|
|
|
"not started\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-12-02 18:23:00 +00:00
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
if (
|
|
|
|
ignore_badwindow &&
|
|
|
|
(e->error_code == BadWindow || e->error_code == BadColor))
|
|
|
|
return 0;
|
2019-12-02 18:23:00 +00:00
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
XGetErrorText(d, e->error_code, msg, sizeof(msg));
|
|
|
|
sprintf(number, "%d", e->request_code);
|
|
|
|
XGetErrorDatabaseText(d, "XRequest", number, "", req, sizeof(req));
|
2021-02-26 19:50:23 +00:00
|
|
|
if (req[0] == '\0')
|
|
|
|
sprintf(req, "<request-code-%d>", (int)e->request_code);
|
2019-12-02 18:23:00 +00:00
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
fprintf(stderr, "ryudo: %s(0x%x): %s\n", req, (int)e->resourceid, msg);
|
2019-12-02 18:23:00 +00:00
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
if (initting) {
|
|
|
|
fprintf(stderr, "ryudo: failure during initialisation; aborting\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return 0;
|
2019-12-02 18:23:00 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 19:50:23 +00:00
|
|
|
void graberror(char* f, int err) {
|
2021-02-26 18:01:22 +00:00
|
|
|
#ifdef DEBUG /* sick of "bug" reports; grab errors "just happen" */
|
|
|
|
char* s;
|
2019-12-02 18:23:00 +00:00
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
switch (err) {
|
2021-02-26 19:50:23 +00:00
|
|
|
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:
|
|
|
|
fprintf(stderr, "ryudo: %s: grab error: %d\n", f, err);
|
|
|
|
return;
|
2021-02-26 18:01:22 +00:00
|
|
|
}
|
|
|
|
fprintf(stderr, "ryudo: %s: grab error: %s\n", f, s);
|
2019-12-02 18:23:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
#ifdef DEBUG_EV
|
2019-12-02 18:23:00 +00:00
|
|
|
#include "showevent/ShowEvent.c"
|
|
|
|
#endif
|
|
|
|
|
2021-02-26 18:01:22 +00:00
|
|
|
#ifdef DEBUG
|
2019-12-02 18:23:00 +00:00
|
|
|
|
2021-02-26 19:50:23 +00:00
|
|
|
void dotrace(char* s, Client* c, XEvent* e) {
|
|
|
|
if (debug == 0)
|
|
|
|
return;
|
2021-02-26 18:01:22 +00:00
|
|
|
setbuf(stdout, 0);
|
|
|
|
fprintf(stderr, "ryudo: %s: c=%p", s, (void*)c);
|
|
|
|
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,
|
|
|
|
(int)c->window,
|
|
|
|
(int)c->parent);
|
|
|
|
#ifdef DEBUG_EV
|
|
|
|
if (e) {
|
|
|
|
fprintf(stderr, "\n\t");
|
|
|
|
ShowEvent(e);
|
|
|
|
}
|
2019-12-02 18:23:00 +00:00
|
|
|
#endif
|
2021-02-26 18:01:22 +00:00
|
|
|
fprintf(stderr, "\n");
|
2019-12-02 18:23:00 +00:00
|
|
|
}
|
|
|
|
#endif
|