xenocara/app/xev/xev.c

1562 lines
44 KiB
C
Raw Normal View History

2006-11-25 13:07:29 -07:00
/*
Copyright (c) 1988 X Consortium
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from the X Consortium.
*/
/*
* Author: Jim Fulton, MIT X Consortium
*/
2013-03-05 14:01:56 -07:00
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
2006-11-25 13:07:29 -07:00
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <X11/Xlocale.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
2012-02-28 13:44:03 -07:00
#include <X11/extensions/Xrandr.h>
2006-11-25 13:07:29 -07:00
#define INNER_WINDOW_WIDTH 50
#define INNER_WINDOW_HEIGHT 50
#define INNER_WINDOW_BORDER 4
#define INNER_WINDOW_X 10
#define INNER_WINDOW_Y 10
#define OUTER_WINDOW_MIN_WIDTH (INNER_WINDOW_WIDTH + \
2 * (INNER_WINDOW_BORDER + INNER_WINDOW_X))
#define OUTER_WINDOW_MIN_HEIGHT (INNER_WINDOW_HEIGHT + \
2 * (INNER_WINDOW_BORDER + INNER_WINDOW_Y))
#define OUTER_WINDOW_DEF_WIDTH (OUTER_WINDOW_MIN_WIDTH + 100)
#define OUTER_WINDOW_DEF_HEIGHT (OUTER_WINDOW_MIN_HEIGHT + 100)
#define OUTER_WINDOW_DEF_X 100
#define OUTER_WINDOW_DEF_Y 100
2012-02-28 13:44:03 -07:00
2006-11-25 13:07:29 -07:00
typedef unsigned long Pixel;
const char *Yes = "YES";
const char *No = "NO";
const char *Unknown = "unknown";
const char *ProgramName;
Display *dpy;
int screen;
XIC xic = NULL;
2008-04-19 10:59:34 -06:00
Atom wm_delete_window;
Atom wm_protocols;
2012-02-28 13:44:03 -07:00
Bool have_rr;
int rr_event_base, rr_error_base;
2013-03-05 14:01:56 -07:00
enum EventMaskIndex {
EVENT_MASK_INDEX_CORE,
EVENT_MASK_INDEX_RANDR,
NUM_EVENT_MASKS
};
2019-08-15 11:31:43 -06:00
static void usage(const char *errmsg) _X_NORETURN;
2012-02-28 13:44:03 -07:00
2006-11-25 13:07:29 -07:00
static void
2019-08-15 11:31:43 -06:00
prologue(XEvent *eventp, const char *event_name)
2006-11-25 13:07:29 -07:00
{
XAnyEvent *e = (XAnyEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf("\n%s event, serial %ld, synthetic %s, window 0x%lx,\n",
event_name, e->serial, e->send_event ? Yes : No, e->window);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
dump(char *str, int len)
2006-11-25 13:07:29 -07:00
{
printf("(");
len--;
while (len-- > 0)
printf("%02x ", (unsigned char) *str++);
printf("%02x)", (unsigned char) *str++);
}
static void
2019-08-15 11:31:43 -06:00
do_KeyPress(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XKeyEvent *e = (XKeyEvent *) eventp;
KeySym ks;
KeyCode kc = 0;
Bool kc_set = False;
2012-02-28 13:44:03 -07:00
const char *ksname;
2006-11-25 13:07:29 -07:00
int nbytes, nmbbytes = 0;
2019-08-15 11:31:43 -06:00
char str[256 + 1];
2006-11-25 13:07:29 -07:00
static char *buf = NULL;
static int bsize = 8;
Status status;
if (buf == NULL)
2019-08-15 11:31:43 -06:00
buf = malloc(bsize);
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
nbytes = XLookupString(e, str, 256, &ks, NULL);
2006-11-25 13:07:29 -07:00
/* not supposed to call XmbLookupString on a key release event */
if (e->type == KeyPress && xic) {
do {
2019-08-15 11:31:43 -06:00
nmbbytes = XmbLookupString(xic, e, buf, bsize - 1, &ks, &status);
2006-11-25 13:07:29 -07:00
buf[nmbbytes] = '\0';
if (status == XBufferOverflow) {
bsize = nmbbytes + 1;
2019-08-15 11:31:43 -06:00
buf = realloc(buf, bsize);
2006-11-25 13:07:29 -07:00
}
} while (status == XBufferOverflow);
}
if (ks == NoSymbol)
2019-08-15 11:31:43 -06:00
ksname = "NoSymbol";
2006-11-25 13:07:29 -07:00
else {
2019-08-15 11:31:43 -06:00
if (!(ksname = XKeysymToString(ks)))
ksname = "(no name)";
kc = XKeysymToKeycode(dpy, ks);
kc_set = True;
2006-11-25 13:07:29 -07:00
}
2012-02-28 13:44:03 -07:00
2019-08-15 11:31:43 -06:00
printf(" root 0x%lx, subw 0x%lx, time %lu, (%d,%d), root:(%d,%d),\n",
e->root, e->subwindow, e->time, e->x, e->y, e->x_root, e->y_root);
printf(" state 0x%x, keycode %u (keysym 0x%lx, %s), same_screen %s,\n",
e->state, e->keycode, (unsigned long) ks, ksname,
e->same_screen ? Yes : No);
2006-11-25 13:07:29 -07:00
if (kc_set && e->keycode != kc)
2019-08-15 11:31:43 -06:00
printf(" XKeysymToKeycode returns keycode: %u\n", kc);
if (nbytes < 0)
nbytes = 0;
if (nbytes > 256)
nbytes = 256;
2006-11-25 13:07:29 -07:00
str[nbytes] = '\0';
2019-08-15 11:31:43 -06:00
printf(" XLookupString gives %d bytes: ", nbytes);
2006-11-25 13:07:29 -07:00
if (nbytes > 0) {
2019-08-15 11:31:43 -06:00
dump(str, nbytes);
printf(" \"%s\"\n", str);
}
else {
printf("\n");
2006-11-25 13:07:29 -07:00
}
/* not supposed to call XmbLookupString on a key release event */
if (e->type == KeyPress && xic) {
2019-08-15 11:31:43 -06:00
printf(" XmbLookupString gives %d bytes: ", nmbbytes);
2006-11-25 13:07:29 -07:00
if (nmbbytes > 0) {
2019-08-15 11:31:43 -06:00
dump(buf, nmbbytes);
printf(" \"%s\"\n", buf);
}
else {
printf("\n");
2006-11-25 13:07:29 -07:00
}
}
2019-08-15 11:31:43 -06:00
printf(" XFilterEvent returns: %s\n",
XFilterEvent(eventp, e->window) ? "True" : "False");
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_KeyRelease(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
2019-08-15 11:31:43 -06:00
do_KeyPress(eventp); /* since it has the same info */
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_ButtonPress(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XButtonEvent *e = (XButtonEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" root 0x%lx, subw 0x%lx, time %lu, (%d,%d), root:(%d,%d),\n",
e->root, e->subwindow, e->time, e->x, e->y, e->x_root, e->y_root);
printf(" state 0x%x, button %u, same_screen %s\n",
e->state, e->button, e->same_screen ? Yes : No);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_ButtonRelease(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
2019-08-15 11:31:43 -06:00
do_ButtonPress(eventp); /* since it has the same info */
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_MotionNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XMotionEvent *e = (XMotionEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" root 0x%lx, subw 0x%lx, time %lu, (%d,%d), root:(%d,%d),\n",
e->root, e->subwindow, e->time, e->x, e->y, e->x_root, e->y_root);
printf(" state 0x%x, is_hint %u, same_screen %s\n",
e->state, e->is_hint, e->same_screen ? Yes : No);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_EnterNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XCrossingEvent *e = (XCrossingEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *mode, *detail;
2006-11-25 13:07:29 -07:00
char dmode[10], ddetail[10];
switch (e->mode) {
2019-08-15 11:31:43 -06:00
case NotifyNormal:
mode = "NotifyNormal";
break;
case NotifyGrab:
mode = "NotifyGrab";
break;
case NotifyUngrab:
mode = "NotifyUngrab";
break;
case NotifyWhileGrabbed:
mode = "NotifyWhileGrabbed";
break;
default:
mode = dmode;
snprintf(dmode, sizeof(dmode), "%u", e->mode);
break;
2006-11-25 13:07:29 -07:00
}
switch (e->detail) {
2019-08-15 11:31:43 -06:00
case NotifyAncestor:
detail = "NotifyAncestor";
break;
case NotifyVirtual:
detail = "NotifyVirtual";
break;
case NotifyInferior:
detail = "NotifyInferior";
break;
case NotifyNonlinear:
detail = "NotifyNonlinear";
break;
case NotifyNonlinearVirtual:
detail = "NotifyNonlinearVirtual";
break;
case NotifyPointer:
detail = "NotifyPointer";
break;
case NotifyPointerRoot:
detail = "NotifyPointerRoot";
break;
case NotifyDetailNone:
detail = "NotifyDetailNone";
break;
default:
detail = ddetail;
snprintf(ddetail, sizeof(ddetail), "%u", e->detail);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" root 0x%lx, subw 0x%lx, time %lu, (%d,%d), root:(%d,%d),\n",
e->root, e->subwindow, e->time, e->x, e->y, e->x_root, e->y_root);
printf(" mode %s, detail %s, same_screen %s,\n",
mode, detail, e->same_screen ? Yes : No);
printf(" focus %s, state %u\n", e->focus ? Yes : No, e->state);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_LeaveNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
2019-08-15 11:31:43 -06:00
do_EnterNotify(eventp); /* since it has same information */
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_FocusIn(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XFocusChangeEvent *e = (XFocusChangeEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *mode, *detail;
2006-11-25 13:07:29 -07:00
char dmode[10], ddetail[10];
switch (e->mode) {
2019-08-15 11:31:43 -06:00
case NotifyNormal:
mode = "NotifyNormal";
break;
case NotifyGrab:
mode = "NotifyGrab";
break;
case NotifyUngrab:
mode = "NotifyUngrab";
break;
case NotifyWhileGrabbed:
mode = "NotifyWhileGrabbed";
break;
default:
mode = dmode;
snprintf(dmode, sizeof(dmode), "%u", e->mode);
break;
2006-11-25 13:07:29 -07:00
}
switch (e->detail) {
2019-08-15 11:31:43 -06:00
case NotifyAncestor:
detail = "NotifyAncestor";
break;
case NotifyVirtual:
detail = "NotifyVirtual";
break;
case NotifyInferior:
detail = "NotifyInferior";
break;
case NotifyNonlinear:
detail = "NotifyNonlinear";
break;
case NotifyNonlinearVirtual:
detail = "NotifyNonlinearVirtual";
break;
case NotifyPointer:
detail = "NotifyPointer";
break;
case NotifyPointerRoot:
detail = "NotifyPointerRoot";
break;
case NotifyDetailNone:
detail = "NotifyDetailNone";
break;
default:
detail = ddetail;
snprintf(ddetail, sizeof(ddetail), "%u", e->detail);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" mode %s, detail %s\n", mode, detail);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_FocusOut(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
2019-08-15 11:31:43 -06:00
do_FocusIn(eventp); /* since it has same information */
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_KeymapNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XKeymapEvent *e = (XKeymapEvent *) eventp;
int i;
2019-08-15 11:31:43 -06:00
printf(" keys: ");
2006-11-25 13:07:29 -07:00
for (i = 0; i < 32; i++) {
2019-08-15 11:31:43 -06:00
if (i == 16)
printf("\n ");
printf("%-3u ", (unsigned int) e->key_vector[i]);
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf("\n");
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_Expose(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XExposeEvent *e = (XExposeEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" (%d,%d), width %d, height %d, count %d\n",
e->x, e->y, e->width, e->height, e->count);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_GraphicsExpose(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XGraphicsExposeEvent *e = (XGraphicsExposeEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *m;
2006-11-25 13:07:29 -07:00
char mdummy[10];
switch (e->major_code) {
2019-08-15 11:31:43 -06:00
case X_CopyArea:
m = "CopyArea";
break;
case X_CopyPlane:
m = "CopyPlane";
break;
default:
m = mdummy;
snprintf(mdummy, sizeof(mdummy), "%d", e->major_code);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" (%d,%d), width %d, height %d, count %d,\n",
e->x, e->y, e->width, e->height, e->count);
printf(" major %s, minor %d\n", m, e->minor_code);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_NoExpose(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XNoExposeEvent *e = (XNoExposeEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *m;
2006-11-25 13:07:29 -07:00
char mdummy[10];
switch (e->major_code) {
2019-08-15 11:31:43 -06:00
case X_CopyArea:
m = "CopyArea";
break;
case X_CopyPlane:
m = "CopyPlane";
break;
default:
m = mdummy;
snprintf(mdummy, sizeof(mdummy), "%d", e->major_code);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" major %s, minor %d\n", m, e->minor_code);
2006-11-25 13:07:29 -07:00
return;
}
static void
2019-08-15 11:31:43 -06:00
do_VisibilityNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XVisibilityEvent *e = (XVisibilityEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *v;
2006-11-25 13:07:29 -07:00
char vdummy[10];
switch (e->state) {
2019-08-15 11:31:43 -06:00
case VisibilityUnobscured:
v = "VisibilityUnobscured";
break;
case VisibilityPartiallyObscured:
v = "VisibilityPartiallyObscured";
break;
case VisibilityFullyObscured:
v = "VisibilityFullyObscured";
break;
default:
v = vdummy;
snprintf(vdummy, sizeof(vdummy), "%d", e->state);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" state %s\n", v);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_CreateNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XCreateWindowEvent *e = (XCreateWindowEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" parent 0x%lx, window 0x%lx, (%d,%d), width %d, height %d\n",
e->parent, e->window, e->x, e->y, e->width, e->height);
printf("border_width %d, override %s\n",
e->border_width, e->override_redirect ? Yes : No);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_DestroyNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XDestroyWindowEvent *e = (XDestroyWindowEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" event 0x%lx, window 0x%lx\n", e->event, e->window);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_UnmapNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XUnmapEvent *e = (XUnmapEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" event 0x%lx, window 0x%lx, from_configure %s\n",
e->event, e->window, e->from_configure ? Yes : No);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_MapNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XMapEvent *e = (XMapEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" event 0x%lx, window 0x%lx, override %s\n",
e->event, e->window, e->override_redirect ? Yes : No);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_MapRequest(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XMapRequestEvent *e = (XMapRequestEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" parent 0x%lx, window 0x%lx\n", e->parent, e->window);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_ReparentNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XReparentEvent *e = (XReparentEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" event 0x%lx, window 0x%lx, parent 0x%lx,\n",
e->event, e->window, e->parent);
printf(" (%d,%d), override %s\n", e->x, e->y,
e->override_redirect ? Yes : No);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_ConfigureNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XConfigureEvent *e = (XConfigureEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" event 0x%lx, window 0x%lx, (%d,%d), width %d, height %d,\n",
e->event, e->window, e->x, e->y, e->width, e->height);
printf(" border_width %d, above 0x%lx, override %s\n",
e->border_width, e->above, e->override_redirect ? Yes : No);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_ConfigureRequest(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XConfigureRequestEvent *e = (XConfigureRequestEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *detail;
2006-11-25 13:07:29 -07:00
char ddummy[10];
switch (e->detail) {
2019-08-15 11:31:43 -06:00
case Above:
detail = "Above";
break;
case Below:
detail = "Below";
break;
case TopIf:
detail = "TopIf";
break;
case BottomIf:
detail = "BottomIf";
break;
case Opposite:
detail = "Opposite";
break;
default:
detail = ddummy;
snprintf(ddummy, sizeof(ddummy), "%d", e->detail);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" parent 0x%lx, window 0x%lx, (%d,%d), width %d, height %d,\n",
e->parent, e->window, e->x, e->y, e->width, e->height);
printf(" border_width %d, above 0x%lx, detail %s, value 0x%lx\n",
e->border_width, e->above, detail, e->value_mask);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_GravityNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XGravityEvent *e = (XGravityEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" event 0x%lx, window 0x%lx, (%d,%d)\n",
e->event, e->window, e->x, e->y);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_ResizeRequest(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XResizeRequestEvent *e = (XResizeRequestEvent *) eventp;
2019-08-15 11:31:43 -06:00
printf(" width %d, height %d\n", e->width, e->height);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_CirculateNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XCirculateEvent *e = (XCirculateEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *p;
2006-11-25 13:07:29 -07:00
char pdummy[10];
switch (e->place) {
2019-08-15 11:31:43 -06:00
case PlaceOnTop:
p = "PlaceOnTop";
break;
case PlaceOnBottom:
p = "PlaceOnBottom";
break;
default:
p = pdummy;
snprintf(pdummy, sizeof(pdummy), "%d", e->place);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" event 0x%lx, window 0x%lx, place %s\n", e->event, e->window, p);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_CirculateRequest(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XCirculateRequestEvent *e = (XCirculateRequestEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *p;
2006-11-25 13:07:29 -07:00
char pdummy[10];
switch (e->place) {
2019-08-15 11:31:43 -06:00
case PlaceOnTop:
p = "PlaceOnTop";
break;
case PlaceOnBottom:
p = "PlaceOnBottom";
break;
default:
p = pdummy;
snprintf(pdummy, sizeof(pdummy), "%d", e->place);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" parent 0x%lx, window 0x%lx, place %s\n",
e->parent, e->window, p);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_PropertyNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XPropertyEvent *e = (XPropertyEvent *) eventp;
2019-08-15 11:31:43 -06:00
char *aname = XGetAtomName(dpy, e->atom);
2012-02-28 13:44:03 -07:00
const char *s;
2006-11-25 13:07:29 -07:00
char sdummy[10];
switch (e->state) {
2019-08-15 11:31:43 -06:00
case PropertyNewValue:
s = "PropertyNewValue";
break;
case PropertyDelete:
s = "PropertyDelete";
break;
default:
s = sdummy;
snprintf(sdummy, sizeof(sdummy), "%d", e->state);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" atom 0x%lx (%s), time %lu, state %s\n",
e->atom, aname ? aname : Unknown, e->time, s);
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
XFree(aname);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_SelectionClear(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XSelectionClearEvent *e = (XSelectionClearEvent *) eventp;
2019-08-15 11:31:43 -06:00
char *sname = XGetAtomName(dpy, e->selection);
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
printf(" selection 0x%lx (%s), time %lu\n",
e->selection, sname ? sname : Unknown, e->time);
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
XFree(sname);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_SelectionRequest(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XSelectionRequestEvent *e = (XSelectionRequestEvent *) eventp;
2019-08-15 11:31:43 -06:00
char *sname = XGetAtomName(dpy, e->selection);
char *tname = XGetAtomName(dpy, e->target);
char *pname = XGetAtomName(dpy, e->property);
printf(" owner 0x%lx, requestor 0x%lx, selection 0x%lx (%s),\n",
e->owner, e->requestor, e->selection, sname ? sname : Unknown);
printf(" target 0x%lx (%s), property 0x%lx (%s), time %lu\n",
e->target, tname ? tname : Unknown, e->property,
pname ? pname : Unknown, e->time);
XFree(sname);
XFree(tname);
XFree(pname);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_SelectionNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XSelectionEvent *e = (XSelectionEvent *) eventp;
2019-08-15 11:31:43 -06:00
char *sname = XGetAtomName(dpy, e->selection);
char *tname = XGetAtomName(dpy, e->target);
char *pname = XGetAtomName(dpy, e->property);
printf(" selection 0x%lx (%s), target 0x%lx (%s),\n",
e->selection, sname ? sname : Unknown, e->target,
tname ? tname : Unknown);
printf(" property 0x%lx (%s), time %lu\n",
e->property, pname ? pname : Unknown, e->time);
XFree(sname);
XFree(tname);
XFree(pname);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_ColormapNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XColormapEvent *e = (XColormapEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *s;
2006-11-25 13:07:29 -07:00
char sdummy[10];
switch (e->state) {
2019-08-15 11:31:43 -06:00
case ColormapInstalled:
s = "ColormapInstalled";
break;
case ColormapUninstalled:
s = "ColormapUninstalled";
break;
default:
s = sdummy;
snprintf(sdummy, sizeof(sdummy), "%d", e->state);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" colormap 0x%lx, new %s, state %s\n",
e->colormap, e->new ? Yes : No, s);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_ClientMessage(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XClientMessageEvent *e = (XClientMessageEvent *) eventp;
2019-08-15 11:31:43 -06:00
char *mname = XGetAtomName(dpy, e->message_type);
2006-11-25 13:07:29 -07:00
2008-04-19 10:59:34 -06:00
if (e->message_type == wm_protocols) {
2019-08-15 11:31:43 -06:00
char *message = XGetAtomName(dpy, e->data.l[0]);
printf(" message_type 0x%lx (%s), format %d, message 0x%lx (%s)\n",
e->message_type, mname ? mname : Unknown, e->format,
e->data.l[0], message);
XFree(message);
2008-04-19 10:59:34 -06:00
}
else {
2019-08-15 11:31:43 -06:00
printf(" message_type 0x%lx (%s), format %d\n",
e->message_type, mname ? mname : Unknown, e->format);
2008-04-19 10:59:34 -06:00
}
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
XFree(mname);
2008-04-19 10:59:34 -06:00
2012-02-28 13:44:03 -07:00
if (e->format == 32
&& e->message_type == wm_protocols
&& (Atom) e->data.l[0] == wm_delete_window)
2019-08-15 11:31:43 -06:00
exit(0);
2006-11-25 13:07:29 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_MappingNotify(XEvent *eventp)
2006-11-25 13:07:29 -07:00
{
XMappingEvent *e = (XMappingEvent *) eventp;
2012-02-28 13:44:03 -07:00
const char *r;
2006-11-25 13:07:29 -07:00
char rdummy[10];
switch (e->request) {
2019-08-15 11:31:43 -06:00
case MappingModifier:
r = "MappingModifier";
break;
case MappingKeyboard:
r = "MappingKeyboard";
break;
case MappingPointer:
r = "MappingPointer";
break;
default:
r = rdummy;
snprintf(rdummy, sizeof(rdummy), "%d", e->request);
break;
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
printf(" request %s, first_keycode %d, count %d\n",
r, e->first_keycode, e->count);
2006-11-25 13:07:29 -07:00
XRefreshKeyboardMapping(e);
}
2012-02-28 13:44:03 -07:00
static void
2019-08-15 11:31:43 -06:00
print_SubPixelOrder(SubpixelOrder subpixel_order)
2012-02-28 13:44:03 -07:00
{
switch (subpixel_order) {
2019-08-15 11:31:43 -06:00
case SubPixelUnknown:
printf("SubPixelUnknown");
return;
case SubPixelHorizontalRGB:
printf("SubPixelHorizontalRGB");
return;
case SubPixelHorizontalBGR:
printf("SubPixelHorizontalBGR");
return;
case SubPixelVerticalRGB:
printf("SubPixelVerticalRGB");
return;
case SubPixelVerticalBGR:
printf("SubPixelVerticalBGR");
return;
case SubPixelNone:
printf("SubPixelNone");
return;
default:
printf("%d", subpixel_order);
2012-02-28 13:44:03 -07:00
}
}
static void
2019-08-15 11:31:43 -06:00
print_Rotation(Rotation rotation)
2012-02-28 13:44:03 -07:00
{
if (rotation & RR_Rotate_0)
2019-08-15 11:31:43 -06:00
printf("RR_Rotate_0");
2012-02-28 13:44:03 -07:00
else if (rotation & RR_Rotate_90)
2019-08-15 11:31:43 -06:00
printf("RR_Rotate_90");
2012-02-28 13:44:03 -07:00
else if (rotation & RR_Rotate_180)
2019-08-15 11:31:43 -06:00
printf("RR_Rotate_180");
2012-02-28 13:44:03 -07:00
else if (rotation & RR_Rotate_270)
2019-08-15 11:31:43 -06:00
printf("RR_Rotate_270");
2012-02-28 13:44:03 -07:00
else {
2019-08-15 11:31:43 -06:00
printf("%d", rotation);
2012-02-28 13:44:03 -07:00
return;
}
if (rotation & RR_Reflect_X)
2019-08-15 11:31:43 -06:00
printf(", RR_Reflect_X");
2012-02-28 13:44:03 -07:00
if (rotation & RR_Reflect_Y)
2019-08-15 11:31:43 -06:00
printf(", RR_Reflect_Y");
2012-02-28 13:44:03 -07:00
}
static void
2019-08-15 11:31:43 -06:00
print_Connection(Connection connection)
2012-02-28 13:44:03 -07:00
{
switch (connection) {
2019-08-15 11:31:43 -06:00
case RR_Connected:
printf("RR_Connected");
return;
case RR_Disconnected:
printf("RR_Disconnected");
return;
case RR_UnknownConnection:
printf("RR_UnknownConnection");
return;
default:
printf("%d", connection);
2012-02-28 13:44:03 -07:00
}
}
static void
2019-08-15 11:31:43 -06:00
do_RRScreenChangeNotify(XEvent *eventp)
2012-02-28 13:44:03 -07:00
{
XRRScreenChangeNotifyEvent *e = (XRRScreenChangeNotifyEvent *) eventp;
2019-08-15 11:31:43 -06:00
XRRUpdateConfiguration(eventp);
printf(" root 0x%lx, timestamp %lu, config_timestamp %lu\n",
e->root, e->timestamp, e->config_timestamp);
printf(" size_index %hu", e->size_index);
printf(", subpixel_order ");
print_SubPixelOrder(e->subpixel_order);
printf("\n rotation ");
print_Rotation(e->rotation);
2012-02-28 13:44:03 -07:00
printf("\n width %d, height %d, mwidth %d, mheight %d\n",
e->width, e->height, e->mwidth, e->mheight);
}
static void
2019-08-15 11:31:43 -06:00
do_RRNotify_OutputChange(XEvent *eventp, XRRScreenResources *screen_resources)
2012-02-28 13:44:03 -07:00
{
XRROutputChangeNotifyEvent *e = (XRROutputChangeNotifyEvent *) eventp;
XRROutputInfo *output_info = NULL;
XRRModeInfo *mode_info = NULL;
if (screen_resources) {
int i;
2019-08-15 11:31:43 -06:00
output_info = XRRGetOutputInfo(dpy, screen_resources, e->output);
2012-02-28 13:44:03 -07:00
for (i = 0; i < screen_resources->nmode; i++)
if (screen_resources->modes[i].id == e->mode) {
2019-08-15 11:31:43 -06:00
mode_info = &screen_resources->modes[i];
break;
2012-02-28 13:44:03 -07:00
}
}
2019-08-15 11:31:43 -06:00
printf(" subtype XRROutputChangeNotifyEvent\n");
2012-02-28 13:44:03 -07:00
if (output_info)
2019-08-15 11:31:43 -06:00
printf(" output %s, ", output_info->name);
2012-02-28 13:44:03 -07:00
else
2019-08-15 11:31:43 -06:00
printf(" output %lu, ", e->output);
2012-02-28 13:44:03 -07:00
if (e->crtc)
printf("crtc %lu, ", e->crtc);
else
printf("crtc None, ");
if (mode_info)
2019-08-15 11:31:43 -06:00
printf("mode %s (%dx%d)\n", mode_info->name, mode_info->width,
mode_info->height);
2012-02-28 13:44:03 -07:00
else if (e->mode)
2019-08-15 11:31:43 -06:00
printf("mode %lu\n", e->mode);
2012-02-28 13:44:03 -07:00
else
printf("mode None\n");
2019-08-15 11:31:43 -06:00
printf(" rotation ");
print_Rotation(e->rotation);
printf("\n connection ");
print_Connection(e->connection);
printf(", subpixel_order ");
print_SubPixelOrder(e->subpixel_order);
printf("\n");
XRRFreeOutputInfo(output_info);
2012-02-28 13:44:03 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_RRNotify_CrtcChange(XEvent *eventp, XRRScreenResources *screen_resources)
2012-02-28 13:44:03 -07:00
{
XRRCrtcChangeNotifyEvent *e = (XRRCrtcChangeNotifyEvent *) eventp;
XRRModeInfo *mode_info = NULL;
2006-11-25 13:07:29 -07:00
2012-02-28 13:44:03 -07:00
if (screen_resources) {
int i;
for (i = 0; i < screen_resources->nmode; i++)
if (screen_resources->modes[i].id == e->mode) {
2019-08-15 11:31:43 -06:00
mode_info = &screen_resources->modes[i];
break;
2012-02-28 13:44:03 -07:00
}
}
2019-08-15 11:31:43 -06:00
printf(" subtype XRRCrtcChangeNotifyEvent\n");
2012-02-28 13:44:03 -07:00
if (e->crtc)
printf(" crtc %lu, ", e->crtc);
else
printf(" crtc None, ");
if (mode_info)
2019-08-15 11:31:43 -06:00
printf("mode %s, ", mode_info->name);
2012-02-28 13:44:03 -07:00
else if (e->mode)
2019-08-15 11:31:43 -06:00
printf("mode %lu, ", e->mode);
2012-02-28 13:44:03 -07:00
else
printf("mode None, ");
2019-08-15 11:31:43 -06:00
printf("rotation ");
print_Rotation(e->rotation);
printf("\n x %d, y %d, width %d, height %d\n",
e->x, e->y, e->width, e->height);
2012-02-28 13:44:03 -07:00
}
2006-11-25 13:07:29 -07:00
static void
2019-08-15 11:31:43 -06:00
do_RRNotify_OutputProperty(XEvent *eventp,
XRRScreenResources *screen_resources)
2012-02-28 13:44:03 -07:00
{
XRROutputPropertyNotifyEvent *e = (XRROutputPropertyNotifyEvent *) eventp;
XRROutputInfo *output_info = NULL;
2019-08-15 11:31:43 -06:00
char *property = XGetAtomName(dpy, e->property);
2012-02-28 13:44:03 -07:00
if (screen_resources)
2019-08-15 11:31:43 -06:00
output_info = XRRGetOutputInfo(dpy, screen_resources, e->output);
printf(" subtype XRROutputPropertyChangeNotifyEvent\n");
2012-02-28 13:44:03 -07:00
if (output_info)
2019-08-15 11:31:43 -06:00
printf(" output %s, ", output_info->name);
2012-02-28 13:44:03 -07:00
else
2019-08-15 11:31:43 -06:00
printf(" output %lu, ", e->output);
printf("property %s, timestamp %lu, state ", property, e->timestamp);
2012-02-28 13:44:03 -07:00
if (e->state == PropertyNewValue)
2019-08-15 11:31:43 -06:00
printf("NewValue\n");
2012-02-28 13:44:03 -07:00
else if (e->state == PropertyDelete)
2019-08-15 11:31:43 -06:00
printf("Delete\n");
2012-02-28 13:44:03 -07:00
else
2019-08-15 11:31:43 -06:00
printf("%d\n", e->state);
XRRFreeOutputInfo(output_info);
XFree(property);
2012-02-28 13:44:03 -07:00
}
static void
2019-08-15 11:31:43 -06:00
do_RRNotify(XEvent *eventp)
2012-02-28 13:44:03 -07:00
{
XRRNotifyEvent *e = (XRRNotifyEvent *) eventp;
XRRScreenResources *screen_resources;
2019-08-15 11:31:43 -06:00
XRRUpdateConfiguration(eventp);
screen_resources = XRRGetScreenResources(dpy, e->window);
prologue(eventp, "RRNotify");
2012-02-28 13:44:03 -07:00
switch (e->subtype) {
2019-08-15 11:31:43 -06:00
case RRNotify_OutputChange:
do_RRNotify_OutputChange(eventp, screen_resources);
break;
case RRNotify_CrtcChange:
do_RRNotify_CrtcChange(eventp, screen_resources);
break;
case RRNotify_OutputProperty:
do_RRNotify_OutputProperty(eventp, screen_resources);
break;
default:
printf(" subtype %d\n", e->subtype);
2012-02-28 13:44:03 -07:00
}
2019-08-15 11:31:43 -06:00
XRRFreeScreenResources(screen_resources);
2012-02-28 13:44:03 -07:00
}
static void
2019-08-15 11:31:43 -06:00
set_sizehints(XSizeHints *hintp, int min_width, int min_height,
int defwidth, int defheight, int defx, int defy, char *geom)
2006-11-25 13:07:29 -07:00
{
int geom_result;
/* set the size hints, algorithm from xlib xbiff */
hintp->width = hintp->min_width = min_width;
hintp->height = hintp->min_height = min_height;
hintp->flags = PMinSize;
hintp->x = hintp->y = 0;
geom_result = NoValue;
if (geom != NULL) {
2019-08-15 11:31:43 -06:00
geom_result = XParseGeometry(geom, &hintp->x, &hintp->y,
(unsigned int *) &hintp->width,
(unsigned int *) &hintp->height);
if ((geom_result & WidthValue) && (geom_result & HeightValue)) {
2006-11-25 13:07:29 -07:00
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
2019-08-15 11:31:43 -06:00
hintp->width = max(hintp->width, hintp->min_width);
hintp->height = max(hintp->height, hintp->min_height);
hintp->flags |= USSize;
}
if ((geom_result & XValue) && (geom_result & YValue)) {
hintp->flags += USPosition;
}
2006-11-25 13:07:29 -07:00
}
if (!(hintp->flags & USSize)) {
2019-08-15 11:31:43 -06:00
hintp->width = defwidth;
hintp->height = defheight;
hintp->flags |= PSize;
2006-11-25 13:07:29 -07:00
}
/*
if (!(hintp->flags & USPosition)) {
hintp->x = defx;
hintp->y = defy;
hintp->flags |= PPosition;
}
*/
if (geom_result & XNegative) {
2019-08-15 11:31:43 -06:00
hintp->x = DisplayWidth(dpy, DefaultScreen(dpy)) + hintp->x -
hintp->width;
2006-11-25 13:07:29 -07:00
}
if (geom_result & YNegative) {
2019-08-15 11:31:43 -06:00
hintp->y = DisplayHeight(dpy, DefaultScreen(dpy)) + hintp->y -
hintp->height;
2006-11-25 13:07:29 -07:00
}
}
static void
2019-08-15 11:31:43 -06:00
usage(const char *errmsg)
2006-11-25 13:07:29 -07:00
{
2019-08-15 11:31:43 -06:00
const char *msg =
" -display displayname X server to contact\n"
" -geometry geom size and location of window\n"
" -bw pixels border width in pixels\n"
" -bs {NotUseful,WhenMapped,Always} backingstore attribute\n"
" -id windowid use existing window\n"
" -root use root window\n"
" -s set save-unders attribute\n"
" -name string window name\n"
" -rv reverse video\n"
" -event event_mask select 'event_mask' events\n"
" Supported event masks: keyboard mouse expose visibility structure\n"
" substructure focus property colormap\n"
" owner_grab_button randr button\n"
" This option can be specified multiple times to select multiple\n"
" event masks.\n"
" -version print version and exit\n"
"\n";
2006-11-25 13:07:29 -07:00
2015-05-10 04:08:51 -06:00
if (errmsg != NULL)
2019-08-15 11:31:43 -06:00
fprintf(stderr, "%s: %s\n", ProgramName, errmsg);
2015-05-10 04:08:51 -06:00
2019-08-15 11:31:43 -06:00
fprintf(stderr, "usage: %s [-options ...]\n", ProgramName);
fprintf(stderr, "where options include:\n");
fputs(msg, stderr);
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
exit(1);
2006-11-25 13:07:29 -07:00
}
static int
2019-08-15 11:31:43 -06:00
parse_backing_store(const char *s)
2006-11-25 13:07:29 -07:00
{
2019-08-15 11:31:43 -06:00
size_t len = strlen(s);
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
if (strncasecmp(s, "NotUseful", len) == 0)
return (NotUseful);
if (strncasecmp(s, "WhenMapped", len) == 0)
return (WhenMapped);
if (strncasecmp(s, "Always", len) == 0)
return (Always);
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
fprintf(stderr, "%s: unrecognized argument '%s' for -bs\n", ProgramName, s);
usage(NULL);
2006-11-25 13:07:29 -07:00
}
2013-03-05 14:01:56 -07:00
static Bool
2019-08-15 11:31:43 -06:00
parse_event_mask(const char *s, long event_masks[])
2013-03-05 14:01:56 -07:00
{
const struct {
const char *name;
enum EventMaskIndex mask_index;
long mask;
} events[] = {
{ "keyboard",
EVENT_MASK_INDEX_CORE,
KeyPressMask | KeyReleaseMask | KeymapStateMask },
{ "mouse",
EVENT_MASK_INDEX_CORE,
ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
LeaveWindowMask | PointerMotionMask | Button1MotionMask |
Button2MotionMask | Button3MotionMask | Button4MotionMask |
Button5MotionMask | ButtonMotionMask },
2019-08-15 11:31:43 -06:00
{ "button",
2015-05-10 04:08:51 -06:00
EVENT_MASK_INDEX_CORE,
ButtonPressMask | ButtonReleaseMask },
2013-03-05 14:01:56 -07:00
{ "expose",
EVENT_MASK_INDEX_CORE,
ExposureMask },
{ "visibility",
EVENT_MASK_INDEX_CORE,
VisibilityChangeMask },
{ "structure",
EVENT_MASK_INDEX_CORE,
StructureNotifyMask },
{ "substructure",
EVENT_MASK_INDEX_CORE,
SubstructureNotifyMask | SubstructureRedirectMask },
{ "focus",
EVENT_MASK_INDEX_CORE,
FocusChangeMask },
{ "property",
EVENT_MASK_INDEX_CORE,
PropertyChangeMask },
{ "colormap",
EVENT_MASK_INDEX_CORE,
ColormapChangeMask },
{ "owner_grab_button",
EVENT_MASK_INDEX_CORE,
OwnerGrabButtonMask },
{ "randr",
EVENT_MASK_INDEX_RANDR,
RRScreenChangeNotifyMask | RRCrtcChangeNotifyMask |
RROutputChangeNotifyMask | RROutputPropertyNotifyMask },
{ NULL, 0, 0 }
};
int i;
for (i = 0; events[i].name; i++) {
if (!s || !strcmp(s, events[i].name)) {
event_masks[events[i].mask_index] |= events[i].mask;
if (s)
return True;
}
}
2015-05-10 04:08:51 -06:00
if (s != NULL)
2019-08-15 11:31:43 -06:00
fprintf(stderr, "%s: unrecognized event mask '%s'\n", ProgramName, s);
2015-05-10 04:08:51 -06:00
2013-03-05 14:01:56 -07:00
return False;
}
2006-11-25 13:07:29 -07:00
int
2019-08-15 11:31:43 -06:00
main(int argc, char **argv)
2006-11-25 13:07:29 -07:00
{
char *displayname = NULL;
char *geom = NULL;
int i;
XSizeHints hints;
int borderwidth = 2;
Window w, subw;
XSetWindowAttributes attr;
XWindowAttributes wattr;
unsigned long mask = 0L;
int done;
2012-02-28 13:44:03 -07:00
const char *name = "Event Tester";
2006-11-25 13:07:29 -07:00
Bool reverse = False;
2010-10-31 13:21:25 -06:00
Bool use_root = False;
2006-11-25 13:07:29 -07:00
unsigned long back, fore;
XIM xim;
XIMStyles *xim_styles;
XIMStyle xim_style = 0;
char *modifiers;
char *imvalret;
2013-03-05 14:01:56 -07:00
long event_masks[NUM_EVENT_MASKS];
Bool event_mask_specified = False;
2006-11-25 13:07:29 -07:00
ProgramName = argv[0];
2019-08-15 11:31:43 -06:00
if (setlocale(LC_ALL, "") == NULL) {
fprintf(stderr, "%s: warning: could not set default locale\n",
ProgramName);
2006-11-25 13:07:29 -07:00
}
2013-03-05 14:01:56 -07:00
memset(event_masks, 0, sizeof(event_masks));
2006-11-25 13:07:29 -07:00
w = 0;
for (i = 1; i < argc; i++) {
2019-08-15 11:31:43 -06:00
char *arg = argv[i];
if (arg[0] == '-') {
switch (arg[1]) {
case 'd': /* -display host:dpy */
if (++i >= argc)
usage("-display requires an argument");
displayname = argv[i];
continue;
case 'g': /* -geometry geom */
if (++i >= argc)
usage("-geometry requires an argument");
geom = argv[i];
continue;
case 'b':
switch (arg[2]) {
case 'w': /* -bw pixels */
if (++i >= argc)
usage("-bw requires an argument");
borderwidth = atoi(argv[i]);
continue;
case 's': /* -bs type */
if (++i >= argc)
usage("-bs requires an argument");
attr.backing_store = parse_backing_store(argv[i]);
mask |= CWBackingStore;
continue;
default:
goto unrecognized;
}
case 'i': /* -id */
if (++i >= argc)
usage("-id requires an argument");
sscanf(argv[i], "0x%lx", &w);
if (!w)
sscanf(argv[i], "%lu", &w);
if (!w) {
fprintf(stderr,
"%s: unable to parse argument '%s' for -id\n",
ProgramName, argv[i]);
usage(NULL);
}
continue;
case 'n': /* -name */
if (++i >= argc)
usage("-name requires an argument");
name = argv[i];
continue;
case 'r':
switch (arg[2]) {
case 'o': /* -root */
use_root = True;
continue;
case 'v': /* -rv */
reverse = True;
continue;
default:
goto unrecognized;
}
continue;
case 's': /* -s */
attr.save_under = True;
mask |= CWSaveUnder;
continue;
case 'e': /* -event */
if (++i >= argc)
usage("-event requires an argument");
if (!parse_event_mask(argv[i], event_masks))
usage(NULL);
event_mask_specified = True;
continue;
case 'v':
puts(PACKAGE_STRING);
exit(0);
default:
goto unrecognized;
} /* end switch on - */
}
else {
unrecognized:
fprintf(stderr, "%s: unrecognized argument '%s'\n",
ProgramName, arg);
usage(NULL);
}
} /* end for over argc */
2006-11-25 13:07:29 -07:00
2013-03-05 14:01:56 -07:00
/* if no -event options were specified, pretend all of them were */
if (!event_mask_specified)
2019-08-15 11:31:43 -06:00
parse_event_mask(NULL, event_masks);
2013-03-05 14:01:56 -07:00
2019-08-15 11:31:43 -06:00
dpy = XOpenDisplay(displayname);
2006-11-25 13:07:29 -07:00
if (!dpy) {
2019-08-15 11:31:43 -06:00
fprintf(stderr, "%s: unable to open display '%s'\n",
ProgramName, XDisplayName(displayname));
exit(1);
2006-11-25 13:07:29 -07:00
}
/* we're testing the default input method */
2019-08-15 11:31:43 -06:00
modifiers = XSetLocaleModifiers("@im=none");
2006-11-25 13:07:29 -07:00
if (modifiers == NULL) {
2019-08-15 11:31:43 -06:00
fprintf(stderr, "%s: XSetLocaleModifiers failed\n", ProgramName);
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
xim = XOpenIM(dpy, NULL, NULL, NULL);
2006-11-25 13:07:29 -07:00
if (xim == NULL) {
2019-08-15 11:31:43 -06:00
fprintf(stderr, "%s: XOpenIM failed\n", ProgramName);
2006-11-25 13:07:29 -07:00
}
if (xim) {
2019-08-15 11:31:43 -06:00
imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL);
2006-11-25 13:07:29 -07:00
if (imvalret != NULL || xim_styles == NULL) {
2019-08-15 11:31:43 -06:00
fprintf(stderr, "%s: input method doesn't support any styles\n",
ProgramName);
2006-11-25 13:07:29 -07:00
}
if (xim_styles) {
xim_style = 0;
2019-08-15 11:31:43 -06:00
for (i = 0; i < xim_styles->count_styles; i++) {
2006-11-25 13:07:29 -07:00
if (xim_styles->supported_styles[i] ==
(XIMPreeditNothing | XIMStatusNothing)) {
xim_style = xim_styles->supported_styles[i];
break;
}
}
if (xim_style == 0) {
2019-08-15 11:31:43 -06:00
fprintf(stderr,
"%s: input method doesn't support the style we support\n",
ProgramName);
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
XFree(xim_styles);
2006-11-25 13:07:29 -07:00
}
2012-02-28 13:44:03 -07:00
}
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
screen = DefaultScreen(dpy);
2006-11-25 13:07:29 -07:00
2013-03-05 14:01:56 -07:00
attr.event_mask = event_masks[EVENT_MASK_INDEX_CORE];
2006-11-25 13:07:29 -07:00
2010-10-31 13:21:25 -06:00
if (use_root)
2019-08-15 11:31:43 -06:00
w = RootWindow(dpy, screen);
2010-10-31 13:21:25 -06:00
2006-11-25 13:07:29 -07:00
if (w) {
2019-08-15 11:31:43 -06:00
XGetWindowAttributes(dpy, w, &wattr);
if (wattr.all_event_masks & ButtonPressMask)
attr.event_mask &= ~ButtonPressMask;
attr.event_mask &= ~SubstructureRedirectMask;
XSelectInput(dpy, w, attr.event_mask);
}
else {
set_sizehints(&hints, OUTER_WINDOW_MIN_WIDTH, OUTER_WINDOW_MIN_HEIGHT,
OUTER_WINDOW_DEF_WIDTH, OUTER_WINDOW_DEF_HEIGHT,
OUTER_WINDOW_DEF_X, OUTER_WINDOW_DEF_Y, geom);
if (reverse) {
back = BlackPixel(dpy, screen);
fore = WhitePixel(dpy, screen);
}
else {
back = WhitePixel(dpy, screen);
fore = BlackPixel(dpy, screen);
}
attr.background_pixel = back;
attr.border_pixel = fore;
mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
w = XCreateWindow(dpy, RootWindow(dpy, screen), hints.x, hints.y,
hints.width, hints.height, borderwidth, 0,
InputOutput, (Visual *) CopyFromParent, mask, &attr);
XSetStandardProperties(dpy, w, name, NULL, (Pixmap) 0,
argv, argc, &hints);
subw = XCreateSimpleWindow(dpy, w, INNER_WINDOW_X, INNER_WINDOW_Y,
INNER_WINDOW_WIDTH, INNER_WINDOW_HEIGHT,
INNER_WINDOW_BORDER,
attr.border_pixel, attr.background_pixel);
2006-11-25 13:07:29 -07:00
2008-04-19 10:59:34 -06:00
wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
XSetWMProtocols(dpy, w, &wm_delete_window, 1);
2019-08-15 11:31:43 -06:00
XMapWindow(dpy, subw); /* map before w so that it appears */
XMapWindow(dpy, w);
2006-11-25 13:07:29 -07:00
2019-08-15 11:31:43 -06:00
printf("Outer window is 0x%lx, inner window is 0x%lx\n", w, subw);
2006-11-25 13:07:29 -07:00
}
if (xim && xim_style) {
2019-08-15 11:31:43 -06:00
xic = XCreateIC(xim,
XNInputStyle, xim_style,
XNClientWindow, w, XNFocusWindow, w, NULL);
2006-11-25 13:07:29 -07:00
if (xic == NULL) {
2019-08-15 11:31:43 -06:00
fprintf(stderr, "XCreateIC failed\n");
2006-11-25 13:07:29 -07:00
}
}
2019-08-15 11:31:43 -06:00
have_rr = XRRQueryExtension(dpy, &rr_event_base, &rr_error_base);
2012-02-28 13:44:03 -07:00
if (have_rr) {
int rr_major, rr_minor;
2019-08-15 11:31:43 -06:00
if (XRRQueryVersion(dpy, &rr_major, &rr_minor)) {
2013-03-05 14:01:56 -07:00
int rr_mask = event_masks[EVENT_MASK_INDEX_RANDR];
if (rr_major == 1 && rr_minor <= 1) {
rr_mask &= ~(RRCrtcChangeNotifyMask |
RROutputChangeNotifyMask |
RROutputPropertyNotifyMask);
}
2012-02-28 13:44:03 -07:00
2019-08-15 11:31:43 -06:00
XRRSelectInput(dpy, w, rr_mask);
2012-02-28 13:44:03 -07:00
}
}
2019-08-15 11:31:43 -06:00
for (done = 0; !done;) {
XEvent event;
XNextEvent(dpy, &event);
switch (event.type) {
case KeyPress:
prologue(&event, "KeyPress");
do_KeyPress(&event);
break;
case KeyRelease:
prologue(&event, "KeyRelease");
do_KeyRelease(&event);
break;
case ButtonPress:
prologue(&event, "ButtonPress");
do_ButtonPress(&event);
break;
case ButtonRelease:
prologue(&event, "ButtonRelease");
do_ButtonRelease(&event);
break;
case MotionNotify:
prologue(&event, "MotionNotify");
do_MotionNotify(&event);
break;
case EnterNotify:
prologue(&event, "EnterNotify");
do_EnterNotify(&event);
break;
case LeaveNotify:
prologue(&event, "LeaveNotify");
do_LeaveNotify(&event);
break;
case FocusIn:
prologue(&event, "FocusIn");
do_FocusIn(&event);
break;
case FocusOut:
prologue(&event, "FocusOut");
do_FocusOut(&event);
break;
case KeymapNotify:
prologue(&event, "KeymapNotify");
do_KeymapNotify(&event);
break;
case Expose:
prologue(&event, "Expose");
do_Expose(&event);
break;
case GraphicsExpose:
prologue(&event, "GraphicsExpose");
do_GraphicsExpose(&event);
break;
case NoExpose:
prologue(&event, "NoExpose");
do_NoExpose(&event);
break;
case VisibilityNotify:
prologue(&event, "VisibilityNotify");
do_VisibilityNotify(&event);
break;
case CreateNotify:
prologue(&event, "CreateNotify");
do_CreateNotify(&event);
break;
case DestroyNotify:
prologue(&event, "DestroyNotify");
do_DestroyNotify(&event);
break;
case UnmapNotify:
prologue(&event, "UnmapNotify");
do_UnmapNotify(&event);
break;
case MapNotify:
prologue(&event, "MapNotify");
do_MapNotify(&event);
break;
case MapRequest:
prologue(&event, "MapRequest");
do_MapRequest(&event);
break;
case ReparentNotify:
prologue(&event, "ReparentNotify");
do_ReparentNotify(&event);
break;
case ConfigureNotify:
prologue(&event, "ConfigureNotify");
do_ConfigureNotify(&event);
break;
case ConfigureRequest:
prologue(&event, "ConfigureRequest");
do_ConfigureRequest(&event);
break;
case GravityNotify:
prologue(&event, "GravityNotify");
do_GravityNotify(&event);
break;
case ResizeRequest:
prologue(&event, "ResizeRequest");
do_ResizeRequest(&event);
break;
case CirculateNotify:
prologue(&event, "CirculateNotify");
do_CirculateNotify(&event);
break;
case CirculateRequest:
prologue(&event, "CirculateRequest");
do_CirculateRequest(&event);
break;
case PropertyNotify:
prologue(&event, "PropertyNotify");
do_PropertyNotify(&event);
break;
case SelectionClear:
prologue(&event, "SelectionClear");
do_SelectionClear(&event);
break;
case SelectionRequest:
prologue(&event, "SelectionRequest");
do_SelectionRequest(&event);
break;
case SelectionNotify:
prologue(&event, "SelectionNotify");
do_SelectionNotify(&event);
break;
case ColormapNotify:
prologue(&event, "ColormapNotify");
do_ColormapNotify(&event);
break;
case ClientMessage:
prologue(&event, "ClientMessage");
do_ClientMessage(&event);
break;
case MappingNotify:
prologue(&event, "MappingNotify");
do_MappingNotify(&event);
break;
default:
if (have_rr) {
if (event.type == rr_event_base + RRScreenChangeNotify) {
prologue(&event, "RRScreenChangeNotify");
do_RRScreenChangeNotify(&event);
break;
}
if (event.type == rr_event_base + RRNotify) {
do_RRNotify(&event);
break;
}
}
printf("Unknown event type %d\n", event.type);
break;
}
fflush(stdout);
2006-11-25 13:07:29 -07:00
}
2019-08-15 11:31:43 -06:00
XCloseDisplay(dpy);
2012-02-28 13:44:03 -07:00
return 0;
2006-11-25 13:07:29 -07:00
}