[go: up one dir, main page]

Menu

[3cb4b9]: / src / testmap.cc  Maximize  Restore  History

Download this file

113 lines (93 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/time.h>
#include <X11/Xproto.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include <X11/keysym.h>
#include "WinMgr.h"
/// _SET would be nice to have
#define _NET_WM_STATE_REMOVE 0
#define _NET_WM_STATE_ADD 1
#define _NET_WM_STATE_TOGGLE 2
#define KEY_MODMASK(x) ((x) & (ControlMask | ShiftMask | Mod1Mask))
#define BUTTON_MASK(x) ((x) & (Button1Mask | Button2Mask | Button3Mask))
#define BUTTON_MODMASK(x) ((x) & (ControlMask | ShiftMask | Mod1Mask | Button1Mask | Button2Mask | Button3Mask))
static char *displayName = 0;
static Display *display = 0;
static Colormap defaultColormap;
static Window root = None;
static Window window = None;
int rx = -1, ry = -1;
int wx = -1, wy = -1;
unsigned int ww = 0, wh = 0;
int main(int argc, char ** /*argv*/) {
XSetWindowAttributes attr;
//Atom state[1];
assert((display = XOpenDisplay(displayName)) != 0);
root = RootWindow(display, DefaultScreen(display));
defaultColormap = DefaultColormap(display, DefaultScreen(display));
window = XCreateWindow(display, root,
100,
100,
64, 64,
0,
CopyFromParent, InputOutput, CopyFromParent,
0, &attr);
XSetWindowBackground(display, window, BlackPixel(display, DefaultScreen(display)));
XSelectInput(display, window,
StructureNotifyMask |
ButtonPressMask | ButtonReleaseMask |
KeyPressMask | KeyReleaseMask |
PropertyChangeMask);
XSelectInput(display, root, PropertyChangeMask);
XMapRaised(display, window);
while (1) {
if (argc > 1) {
int nwx, nwy;
unsigned int nww, nwh;
int nrx, nry;
unsigned int bw;
unsigned int depth;
Window xroot, child;
XGetGeometry(display, window, &xroot, &nwx, &nwy, &nww, &nwh, &bw, &depth);
XTranslateCoordinates(display, window, root, 0, 0, &nrx, &nry, &child);
if (nwx != wx || nwy != wy || nww != ww || nwh != nwh || nrx != rx || nry != ry) {
fprintf(stderr, "%d %d %d %d %d %d\n", nwx, nwy, nww, nwh, nrx, nry);
wx = nwx;
wy = nwy;
ww = nww;
wh = nwh;
rx = nrx;
ry = nry;
}
XFlush(display);
} else {
XEvent xev;
XConfigureEvent &configure = xev.xconfigure;
// XMapEvent &map = xev.xmap;
XNextEvent(display, &xev);
switch (xev.type) {
case ConfigureNotify:
fprintf(stderr, "ConfigureNotify %d %d %d %d %d\n",
configure.x, configure.y,
configure.width, configure.height,
configure.send_event);
break;
case MapNotify:
fprintf(stderr, "MapNotify\n");
break;
case PropertyNotify:
break;
default:
fprintf(stderr, "event=%d\n", xev.type);
break;
}
}
}
}