fix clang-format, no sort includes!

This commit is contained in:
Iris Lightshard 2021-02-26 13:01:22 -05:00
parent 2281498ceb
commit 1af2175f2e
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
20 changed files with 4586 additions and 5023 deletions

18
.clang-format Normal file
View file

@ -0,0 +1,18 @@
TabWidth: 2
IndentWidth: 2
ContinuationIndentWidth: 2
UseTab: Never
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: TopLevel
IndentCaseLabels: true
SpaceBeforeParens: ControlStatements
AlignAfterOpenBracket: AlwaysBreak
BinPackArguments: false
BinPackArguments: false
PointerAlignment: Left
BreakBeforeBraces: Attach
SortIncludes: false

168
client.c Executable file → Normal file
View file

@ -14,12 +14,10 @@ Client *clients;
Client* current; Client* current;
void void
setactive(Client *c, int on) setactive(Client* c, int on) {
{
/* dbg("setactive client %x %d", c->window, c->on); */ /* dbg("setactive client %x %d", c->window, c->on); */
if(c->parent == c->screen->root) if (c->parent == c->screen->root) return;
return;
if (on) { if (on) {
XUngrabButton(dpy, AnyButton, AnyModifier, c->parent); XUngrabButton(dpy, AnyButton, AnyModifier, c->parent);
@ -30,15 +28,23 @@ setactive(Client *c, int on)
} else { } else {
if (c->proto & Plosefocus) if (c->proto & Plosefocus)
sendcmessage(c->window, wm_protocols, wm_lose_focus, 0, 1); sendcmessage(c->window, wm_protocols, wm_lose_focus, 0, 1);
XGrabButton(dpy, AnyButton, AnyModifier, c->parent, False, XGrabButton(
ButtonMask, GrabModeAsync, GrabModeSync, None, None); dpy,
AnyButton,
AnyModifier,
c->parent,
False,
ButtonMask,
GrabModeAsync,
GrabModeSync,
None,
None);
} }
draw_border(c, on); draw_border(c, on);
} }
void void
draw_border(Client *c, int active) draw_border(Client* c, int active) {
{
unsigned long pixel; unsigned long pixel;
if (active) { if (active) {
@ -53,49 +59,47 @@ draw_border(Client *c, int active)
pixel = c->screen->inactiveborder; pixel = c->screen->inactiveborder;
} }
if(debug) fprintf(stderr, "draw_border %p pixel %ld active %d hold %d\n", (void*)c, pixel, active, c->hold); if (debug)
fprintf(
stderr,
"draw_border %p pixel %ld active %d hold %d\n",
(void*)c,
pixel,
active,
c->hold);
XSetWindowBackground(dpy, c->parent, pixel); XSetWindowBackground(dpy, c->parent, pixel);
XClearWindow(dpy, c->parent); XClearWindow(dpy, c->parent);
} }
void void
active(Client *c) active(Client* c) {
{
Client* cc; Client* cc;
if (c == 0) { if (c == 0) {
fprintf(stderr, "ryudo: active(c==0)\n"); fprintf(stderr, "ryudo: active(c==0)\n");
return; return;
} }
if(c == current) if (c == current) return;
return;
#ifdef AUTOSTICK #ifdef AUTOSTICK
if (isautostick(c)) if (isautostick(c)) return;
return;
#endif #endif
if (current) { if (current) {
setactive(current, 0); setactive(current, 0);
if(current->screen != c->screen) if (current->screen != c->screen) cmapnofocus(current->screen);
cmapnofocus(current->screen);
} }
setactive(c, 1); setactive(c, 1);
for (cc = clients; cc; cc = cc->next) for (cc = clients; cc; cc = cc->next)
if(cc->revert == c) if (cc->revert == c) cc->revert = c->revert;
cc->revert = c->revert;
c->revert = current; c->revert = current;
while(c->revert && !normal(c->revert)) while (c->revert && !normal(c->revert)) c->revert = c->revert->revert;
c->revert = c->revert->revert;
current = c; current = c;
#ifdef DEBUG #ifdef DEBUG
if(debug) if (debug) dump_revert();
dump_revert();
#endif #endif
} }
void void
nofocus(void) nofocus(void) {
{
static Window w = 0; static Window w = 0;
int mask; int mask;
XSetWindowAttributes attr; XSetWindowAttributes attr;
@ -116,16 +120,26 @@ nofocus(void)
mask = CWOverrideRedirect /*|CWColormap*/; mask = CWOverrideRedirect /*|CWColormap*/;
attr.override_redirect = 1; attr.override_redirect = 1;
/* attr.colormap = screens[0].def_cmap;*/ /* attr.colormap = screens[0].def_cmap;*/
w = XCreateWindow(dpy, screens[0].root, 0, 0, 1, 1, 0, w = XCreateWindow(
0 /*screens[0].depth*/, InputOnly, screens[0].vis, mask, &attr); dpy,
screens[0].root,
0,
0,
1,
1,
0,
0 /*screens[0].depth*/,
InputOnly,
screens[0].vis,
mask,
&attr);
XMapWindow(dpy, w); XMapWindow(dpy, w);
} }
XSetInputFocus(dpy, w, RevertToPointerRoot, timestamp()); XSetInputFocus(dpy, w, RevertToPointerRoot, timestamp());
} }
void void
top(Client *c) top(Client* c) {
{
Client **l, *cc; Client **l, *cc;
l = &clients; l = &clients;
@ -142,19 +156,15 @@ top(Client *c)
} }
Client* Client*
getclient(Window w, int create) getclient(Window w, int create) {
{
Client* c; Client* c;
if(w == 0 || getscreen(w)) if (w == 0 || getscreen(w)) return 0;
return 0;
for (c = clients; c; c = c->next) for (c = clients; c; c = c->next)
if(c->window == w || c->parent == w) if (c->window == w || c->parent == w) return c;
return c;
if(!create) if (!create) return 0;
return 0;
c = (Client*)malloc(sizeof(Client)); c = (Client*)malloc(sizeof(Client));
memset(c, 0, sizeof(Client)); memset(c, 0, sizeof(Client));
@ -179,25 +189,19 @@ getclient(Window w, int create)
} }
void void
rmclient(Client *c) rmclient(Client* c) {
{
Client* cc; Client* cc;
for (cc = current; cc && cc->revert; cc = cc->revert) for (cc = current; cc && cc->revert; cc = cc->revert)
if(cc->revert == c) if (cc->revert == c) cc->revert = cc->revert->revert;
cc->revert = cc->revert->revert;
if(c == clients) if (c == clients) clients = c->next;
clients = c->next;
for (cc = clients; cc && cc->next; cc = cc->next) for (cc = clients; cc && cc->next; cc = cc->next)
if(cc->next == c) if (cc->next == c) cc->next = cc->next->next;
cc->next = cc->next->next;
if(hidden(c)) if (hidden(c)) unhidec(c, 0);
unhidec(c, 0);
if(c->parent != c->screen->root) if (c->parent != c->screen->root) XDestroyWindow(dpy, c->parent);
XDestroyWindow(dpy, c->parent);
c->parent = c->window = None; /* paranoia */ c->parent = c->window = None; /* paranoia */
if (current == c) { if (current == c) {
@ -205,8 +209,7 @@ rmclient(Client *c)
if (current == 0) if (current == 0)
nofocus(); nofocus();
else { else {
if(current->screen != c->screen) if (current->screen != c->screen) cmapnofocus(c->screen);
cmapnofocus(c->screen);
setactive(current, 1); setactive(current, 1);
} }
} }
@ -214,69 +217,62 @@ rmclient(Client *c)
XFree((char*)c->cmapwins); XFree((char*)c->cmapwins);
free((char*)c->wmcmaps); free((char*)c->wmcmaps);
} }
if(c->iconname != 0) if (c->iconname != 0) XFree((char*)c->iconname);
XFree((char*) c->iconname); if (c->name != 0) XFree((char*)c->name);
if(c->name != 0) if (c->instance != 0) XFree((char*)c->instance);
XFree((char*) c->name); if (c->class != 0) XFree((char*)c->class);
if(c->instance != 0)
XFree((char*) c->instance);
if(c->class != 0)
XFree((char*) c->class);
memset(c, 0, sizeof(Client)); /* paranoia */ memset(c, 0, sizeof(Client)); /* paranoia */
free(c); free(c);
} }
#ifdef DEBUG #ifdef DEBUG
void void
dump_revert(void) dump_revert(void) {
{
Client* c; Client* c;
int i; int i;
i = 0; i = 0;
for (c = current; c; c = c->revert) { for (c = current; c; c = c->revert) {
fprintf(stderr, "%s(%x:%d)", c->label ? c->label : "?", (int)c->window, c->state); fprintf(
if(i++ > 100) stderr, "%s(%x:%d)", c->label ? c->label : "?", (int)c->window, c->state);
break; if (i++ > 100) break;
if(c->revert) if (c->revert) fprintf(stderr, " -> ");
fprintf(stderr, " -> ");
} }
if(current == 0) if (current == 0) fprintf(stderr, "empty");
fprintf(stderr, "empty");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
void void
dump_clients(void) dump_clients(void) {
{
Client* c; Client* c;
for (c = clients; c; c = c->next) for (c = clients; c; c = c->next)
fprintf(stderr, "w 0x%x parent 0x%x @ (%d, %d)\n", (int)c->window, (int)c->parent, c->x, c->y); fprintf(
stderr,
"w 0x%x parent 0x%x @ (%d, %d)\n",
(int)c->window,
(int)c->parent,
c->x,
c->y);
} }
#endif #endif
void void
shuffle(int up) shuffle(int up) {
{
Client **l, *c; Client **l, *c;
if(clients == 0 || clients->next == 0) if (clients == 0 || clients->next == 0) return;
return;
if (!up) { if (!up) {
c = 0; c = 0;
/*for(c=clients; c->next; c=c->next) */ /*for(c=clients; c->next; c=c->next) */
/* ; */ /* ; */
for (l = &clients; (*l)->next; l = &(*l)->next) for (l = &clients; (*l)->next; l = &(*l)->next)
#ifdef AUTOSTICK #ifdef AUTOSTICK
if ((*l)->state == 1 && !isautostick(*l)) if ((*l)->state == 1 && !isautostick(*l)) c = *l;
c = *l;
#else #else
if ((*l)->state == 1) if ((*l)->state == 1) c = *l;
c = *l;
#endif #endif
if (c == 0) if (c == 0) return;
return;
XMapRaised(dpy, c->parent); XMapRaised(dpy, c->parent);
top(c); top(c);
active(c); active(c);
@ -296,18 +292,14 @@ shuffle(int up)
#ifdef AUTOSTICK #ifdef AUTOSTICK
int int
isautostick(Client *c) isautostick(Client* c) {
{
static char* autostick[] = AUTOSTICK; static char* autostick[] = AUTOSTICK;
char** a = autostick; char** a = autostick;
while (*a) { while (*a) {
if(c && c->class && strstr(c->class, *a)) { if (c && c->class && strstr(c->class, *a)) { return 1; }
return 1;
}
++a; ++a;
} }
return 0; return 0;
} }
#endif #endif

6
color.c Executable file → Normal file
View file

@ -8,8 +8,9 @@
#include "fns.h" #include "fns.h"
unsigned long unsigned long
colorpixel(Display *dpy, ScreenInfo *s, int depth, unsigned long rgb, unsigned long def) colorpixel(
{ Display* dpy, ScreenInfo* s, int depth, unsigned long rgb,
unsigned long def) {
int r, g, b; int r, g, b;
r = rgb >> 16; r = rgb >> 16;
@ -42,4 +43,3 @@ colorpixel(Display *dpy, ScreenInfo *s, int depth, unsigned long rgb, unsigned l
return rgb; return rgb;
} }
} }

20
config.h Executable file → Normal file
View file

@ -86,23 +86,15 @@
* Remember the backslash at the end of non-terminating lines! * Remember the backslash at the end of non-terminating lines!
*/ */
#define AUTOSTICK {\ #define AUTOSTICK \
"XOsview",\ { "XOsview", "XClock", 0 }
"XClock",\
0\
}
/* List of fonts to try, in order, for rendering the menus. /* List of fonts to try, in order, for rendering the menus.
* Remember the backslash at the end of non-terminating lines! * Remember the backslash at the end of non-terminating lines!
*/ */
#define FONTLIST {\ #define FONTLIST \
"*-lucidatypewriter-medium-*-12-*-75-*",\ { \
"lucm.latin1.9",\ "*-lucidatypewriter-medium-*-12-*-75-*", "lucm.latin1.9", "blit", \
"blit",\ "*-lucidatypewriter-bold-*-14-*-75-*", "9x15bold", "fixed", "*", 0 \
"*-lucidatypewriter-bold-*-14-*-75-*",\
"9x15bold",\
"fixed",\
"*",\
0\
} }

220
cursor.c Executable file → Normal file
View file

@ -16,133 +16,120 @@ typedef struct {
Cursordata bigarrow = { Cursordata bigarrow = {
16, 16,
{0, 0}, {0, 0},
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0x3F, {
0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x1F, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0x3F, 0xFF, 0x0F, 0xFF,
0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0x3F, 0x0F, 0xFF, 0x1F, 0xFF, 0x3F, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F,
0xCF, 0x1F, 0x8F, 0x0F, 0x07, 0x07, 0x03, 0x02, 0xFF, 0x3F, 0xCF, 0x1F, 0x8F, 0x0F, 0x07, 0x07, 0x03, 0x02,
}, },
{ 0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x3F, 0xFE, 0x0F, {
0xFE, 0x07, 0xFE, 0x07, 0xFE, 0x0F, 0xFE, 0x1F, 0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x3F, 0xFE, 0x0F, 0xFE, 0x07, 0xFE,
0xFE, 0x3F, 0xFE, 0x7F, 0xFE, 0x3F, 0xCE, 0x1F, 0x07, 0xFE, 0x0F, 0xFE, 0x1F, 0xFE, 0x3F, 0xFE, 0x7F, 0xFE, 0x3F,
0x86, 0x0F, 0x06, 0x07, 0x02, 0x02, 0x00, 0x00, 0xCE, 0x1F, 0x86, 0x0F, 0x06, 0x07, 0x02, 0x02, 0x00, 0x00,
} }};
};
Cursordata sweep0data = { Cursordata sweep0data = {
16, 16,
{7, 7}, {7, 7},
{0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, {0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0,
0xC0, 0x03, 0xC0, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x03,
0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03},
0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03}, {0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
{0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x01, 0x80, 0x01, 0xFE, 0x7F, 0xFE, 0x7F, 0x80, 0x01, 0x80, 0x01,
0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xFE, 0x7F, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00}};
0xFE, 0x7F, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00}
};
Cursordata boxcursdata = { Cursordata boxcursdata = {
16, 16,
{7, 7}, {7, 7},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F,
0xFF, 0xFF, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8,
0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, {0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0x0E, 0x70, 0x0E,
{0x00, 0x00, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70,
0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0x00, 0x00}};
0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70,
0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0x00, 0x00}
};
Cursordata sightdata = { Cursordata sightdata = {
16, 16,
{7, 7}, {7, 7},
{0xF8, 0x1F, 0xFC, 0x3F, 0xFE, 0x7F, 0xDF, 0xFB, {
0xCF, 0xF3, 0xC7, 0xE3, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x1F, 0xFC, 0x3F, 0xFE, 0x7F, 0xDF, 0xFB, 0xCF, 0xF3, 0xC7,
0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0xE3, 0xCF, 0xF3, 0xE3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0xE3,
0xDF, 0x7B, 0xFE, 0x7F, 0xFC, 0x3F, 0xF8, 0x1F,}, 0xCF, 0xF3, 0xDF, 0x7B, 0xFE, 0x7F, 0xFC, 0x3F, 0xF8, 0x1F,
{0x00, 0x00, 0xF0, 0x0F, 0x8C, 0x31, 0x84, 0x21, },
0x82, 0x41, 0x82, 0x41, 0x82, 0x41, 0xFE, 0x7F, {
0xFE, 0x7F, 0x82, 0x41, 0x82, 0x41, 0x82, 0x41, 0x00, 0x00, 0xF0, 0x0F, 0x8C, 0x31, 0x84, 0x21, 0x82, 0x41, 0x82,
0x84, 0x21, 0x8C, 0x31, 0xF0, 0x0F, 0x00, 0x00,} 0x41, 0x82, 0x41, 0xFE, 0x7F, 0xFE, 0x7F, 0x82, 0x41, 0x82, 0x41,
}; 0x82, 0x41, 0x84, 0x21, 0x8C, 0x31, 0xF0, 0x0F, 0x00, 0x00,
}};
Cursordata arrowdata = { Cursordata arrowdata = {
16, 16,
{1, 1}, {1, 1},
{0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00, {
0xFF, 0x00, 0xFF, 0x01, 0xFF, 0x03, 0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F, 0x00, 0x7F, 0x01, 0xFF, 0x03, 0xFF, 0x07, 0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F,
0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10,}, 0x00, 0x7F, 0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10,
{0x00, 0x00, 0xFE, 0x03, 0xFE, 0x00, 0x3E, 0x00, },
0x7E, 0x00, 0xFE, 0x00, 0xF6, 0x01, 0xE6, 0x03, {
0xC2, 0x07, 0x82, 0x0F, 0x00, 0x1F, 0x00, 0x3E, 0x00, 0x00, 0xFE, 0x03, 0xFE, 0x00, 0x3E, 0x00, 0x7E, 0x00, 0xFE,
0x00, 0x7C, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00,} 0x00, 0xF6, 0x01, 0xE6, 0x03, 0xC2, 0x07, 0x82, 0x0F, 0x00, 0x1F,
}; 0x00, 0x3E, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00,
}};
Cursordata whitearrow = { Cursordata whitearrow = {
16, 16,
{0, 0}, {0, 0},
{0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00, {
0xFF, 0x00, 0xFF, 0x01, 0xFF, 0x03, 0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x07, 0xFF, 0x03, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F, 0x00, 0x7F, 0x01, 0xFF, 0x03, 0xFF, 0x07, 0xE7, 0x0F, 0xC7, 0x1F, 0x83, 0x3F,
0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10,}, 0x00, 0x7F, 0x00, 0xFE, 0x00, 0x7C, 0x00, 0x38, 0x00, 0x10,
{0xFF, 0x07, 0xFF, 0x07, 0x83, 0x03, 0xC3, 0x00, },
0xC3, 0x00, 0x83, 0x01, 0x1B, 0x03, 0x3F, 0x06, {
0x67, 0x0C, 0xC7, 0x18, 0x83, 0x31, 0x00, 0x63, 0xFF, 0x07, 0xFF, 0x07, 0x83, 0x03, 0xC3, 0x00, 0xC3, 0x00, 0x83,
0x00, 0xC6, 0x00, 0x6C, 0x00, 0x38, 0x00, 0x10,} 0x01, 0x1B, 0x03, 0x3F, 0x06, 0x67, 0x0C, 0xC7, 0x18, 0x83, 0x31,
}; 0x00, 0x63, 0x00, 0xC6, 0x00, 0x6C, 0x00, 0x38, 0x00, 0x10,
}};
Cursordata blittarget = { Cursordata blittarget = {
18, 18,
{8, 8}, {8, 8},
{0xe0, 0x1f, 0x00, 0xf0, 0x3f, 0x00, 0xf8, 0x7f, 0x00, {0xe0, 0x1f, 0x00, 0xf0, 0x3f, 0x00, 0xf8, 0x7f, 0x00, 0xfc, 0xff,
0xfc, 0xff, 0x00, 0xfe, 0xff, 0x01, 0xff, 0xff, 0x03, 0x00, 0xfe, 0xff, 0x01, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff,
0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03,
0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xfe, 0xff, 0x01, 0xfc, 0xff,
0xff, 0xff, 0x03, 0xfe, 0xff, 0x01, 0xfc, 0xff, 0x00, 0x00, 0xf8, 0x7f, 0x00, 0xf0, 0x3f, 0x00, 0xe0, 0x1f, 0x00},
0xf8, 0x7f, 0x00, 0xf0, 0x3f, 0x00, 0xe0, 0x1f, 0x00}, {0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00, 0x38, 0x73,
{0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x8c, 0xc7, 0x00, 0xec, 0xdf, 0x00, 0x66, 0x9b, 0x01, 0x36,
0x38, 0x73, 0x00, 0x8c, 0xc7, 0x00, 0xec, 0xdf, 0x00, 0xb3, 0x01, 0xfe, 0xff, 0x01, 0xfe, 0xff, 0x01, 0x36, 0xb3, 0x01,
0x66, 0x9b, 0x01, 0x36, 0xb3, 0x01, 0xfe, 0xff, 0x01, 0x66, 0x9b, 0x01, 0xec, 0xdf, 0x00, 0x8c, 0xc7, 0x00, 0x38, 0x73,
0xfe, 0xff, 0x01, 0x36, 0xb3, 0x01, 0x66, 0x9b, 0x01, 0x00, 0xf0, 0x3f, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00}};
0xec, 0xdf, 0x00, 0x8c, 0xc7, 0x00, 0x38, 0x73, 0x00,
0xf0, 0x3f, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00}
};
Cursordata blitarrow = { Cursordata blitarrow = {
18, 18,
{1, 1}, {1, 1},
{0xff, 0x0f, 0x00, 0xff, 0x07, 0x00, 0xff, 0x03, 0x00, {0xff, 0x0f, 0x00, 0xff, 0x07, 0x00, 0xff, 0x03, 0x00, 0xff, 0x00,
0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x01, 0x00, 0xff, 0x03, 0x00, 0xff,
0xff, 0x03, 0x00, 0xff, 0x07, 0x00, 0xe7, 0x0f, 0x00, 0x07, 0x00, 0xe7, 0x0f, 0x00, 0xc7, 0x1f, 0x00, 0x87, 0x3f, 0x00,
0xc7, 0x1f, 0x00, 0x87, 0x3f, 0x00, 0x03, 0x7f, 0x00, 0x03, 0x7f, 0x00, 0x01, 0xfe, 0x00, 0x00, 0xfc, 0x01, 0x00, 0xf8,
0x01, 0xfe, 0x00, 0x00, 0xfc, 0x01, 0x00, 0xf8, 0x03, 0x03, 0x00, 0xf0, 0x01, 0x00, 0xe0, 0x00, 0x00, 0x40, 0x00},
0x00, 0xf0, 0x01, 0x00, 0xe0, 0x00, 0x00, 0x40, 0x00}, {0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0xfe, 0x00, 0x00, 0x3e, 0x00,
{0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xf6, 0x01, 0x00, 0xe6,
0x3e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x03, 0x00, 0xc2, 0x07, 0x00, 0x82, 0x0f, 0x00, 0x00, 0x1f, 0x00,
0xf6, 0x01, 0x00, 0xe6, 0x03, 0x00, 0xc2, 0x07, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x7c, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf0,
0x82, 0x0f, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x3e, 0x00, 0x01, 0x00, 0xe0, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}};
0x00, 0x7c, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf0, 0x01,
0x00, 0xe0, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}
};
Cursordata blitsweep = { Cursordata blitsweep = {
18, 18,
{8, 8}, {8, 8},
{0xc4, 0xff, 0x03, 0xce, 0xff, 0x03, 0xdf, 0xff, 0x03, {0xc4, 0xff, 0x03, 0xce, 0xff, 0x03, 0xdf, 0xff, 0x03, 0x3e, 0x80,
0x3e, 0x80, 0x03, 0x7c, 0x83, 0x03, 0xf8, 0x83, 0x03, 0x03, 0x7c, 0x83, 0x03, 0xf8, 0x83, 0x03, 0xf7, 0x83, 0x03, 0xe7,
0xf7, 0x83, 0x03, 0xe7, 0x83, 0x03, 0xf7, 0x83, 0x03, 0x83, 0x03, 0xf7, 0x83, 0x03, 0xf7, 0x83, 0x03, 0x07, 0x80, 0x03,
0xf7, 0x83, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80,
0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x07, 0x80, 0x03, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03},
0xff, 0xff, 0x03, 0xff, 0xff, 0x03, 0xff, 0xff, 0x03}, {0x00, 0x00, 0x00, 0x84, 0xff, 0x01, 0x0e, 0x00, 0x01, 0x1c, 0x00,
{0x00, 0x00, 0x00, 0x84, 0xff, 0x01, 0x0e, 0x00, 0x01, 0x01, 0x38, 0x00, 0x01, 0x70, 0x01, 0x01, 0xe0, 0x01, 0x01, 0xc2,
0x1c, 0x00, 0x01, 0x38, 0x00, 0x01, 0x70, 0x01, 0x01, 0x01, 0x01, 0xe2, 0x01, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01,
0xe0, 0x01, 0x01, 0xc2, 0x01, 0x01, 0xe2, 0x01, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00,
0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x01, 0x02, 0x00, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00}};
0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01,
0x02, 0x00, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00}
};
/* /*
* Grey tile pattern for root background * Grey tile pattern for root background
@ -150,54 +137,50 @@ Cursordata blitsweep = {
#define grey_width 4 #define grey_width 4
#define grey_height 2 #define grey_height 2
static char grey_bits[] = { static char grey_bits[] = {0x01, 0x04};
0x01, 0x04
};
static XColor bl, wh; static XColor bl, wh;
Cursor Cursor getcursor(c, s) Cursordata* c;
getcursor(c, s)
Cursordata *c;
ScreenInfo* s; ScreenInfo* s;
{ {
Pixmap f, m; Pixmap f, m;
f = XCreatePixmapFromBitmapData(dpy, s->root, (char *)c->fore, f = XCreatePixmapFromBitmapData(
c->width, c->width, 1, 0, 1); dpy, s->root, (char*)c->fore, c->width, c->width, 1, 0, 1);
m = XCreatePixmapFromBitmapData(dpy, s->root, (char *)c->mask, m = XCreatePixmapFromBitmapData(
c->width, c->width, 1, 0, 1); dpy, s->root, (char*)c->mask, c->width, c->width, 1, 0, 1);
return XCreatePixmapCursor(dpy, f, m, &bl, &wh, return XCreatePixmapCursor(dpy, f, m, &bl, &wh, c->hot[0], c->hot[1]);
c->hot[0], c->hot[1]);
} }
void void initcurs(s) ScreenInfo* s;
initcurs(s)
ScreenInfo *s;
{ {
XColor dummy; XColor dummy;
XAllocNamedColor(dpy, DefaultColormap(dpy, s->num), XAllocNamedColor(dpy, DefaultColormap(dpy, s->num), "black", &bl, &dummy);
"black", &bl, &dummy); XAllocNamedColor(dpy, DefaultColormap(dpy, s->num), "white", &wh, &dummy);
XAllocNamedColor(dpy, DefaultColormap(dpy, s->num),
"white", &wh, &dummy);
if (nostalgia) { if (nostalgia) {
s->arrow = getcursor(&blitarrow, s); s->arrow = getcursor(&blitarrow, s);
s->target = getcursor(&blittarget, s); s->target = getcursor(&blittarget, s);
s->sweep0 = getcursor(&blitsweep, s); s->sweep0 = getcursor(&blitsweep, s);
s->boxcurs = getcursor(&blitsweep, s); s->boxcurs = getcursor(&blitsweep, s);
} } else {
else {
s->arrow = getcursor(&bigarrow, s); s->arrow = getcursor(&bigarrow, s);
s->target = getcursor(&sightdata, s); s->target = getcursor(&sightdata, s);
s->sweep0 = getcursor(&sweep0data, s); s->sweep0 = getcursor(&sweep0data, s);
s->boxcurs = getcursor(&boxcursdata, s); s->boxcurs = getcursor(&boxcursdata, s);
} }
s->root_pixmap = XCreatePixmapFromBitmapData(dpy, s->root_pixmap = XCreatePixmapFromBitmapData(
s->root, grey_bits, grey_width, grey_height, dpy,
s->black, s->white, s->depth); s->root,
grey_bits,
grey_width,
grey_height,
s->black,
s->white,
s->depth);
s->bordcurs[BorderN] = XCreateFontCursor(dpy, 138); s->bordcurs[BorderN] = XCreateFontCursor(dpy, 138);
s->bordcurs[BorderNNE] = XCreateFontCursor(dpy, 136); s->bordcurs[BorderNNE] = XCreateFontCursor(dpy, 136);
@ -213,7 +196,6 @@ ScreenInfo *s;
s->bordcurs[BorderNNW] = s->bordcurs[BorderWNW]; s->bordcurs[BorderNNW] = s->bordcurs[BorderWNW];
} }
/* RIO /* RIO
Cursor crosscursor = { Cursor crosscursor = {

4
dat.h Executable file → Normal file
View file

@ -13,8 +13,8 @@
#endif #endif
#define NUMVIRTUALS 12 #define NUMVIRTUALS 12
#define AllButtonMask (Button1Mask|Button2Mask|Button3Mask \ #define AllButtonMask \
|Button4Mask|Button5Mask) (Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask)
#define ButtonMask (ButtonPressMask | ButtonReleaseMask) #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
#define MenuMask (ButtonMask | ButtonMotionMask | ExposureMask) #define MenuMask (ButtonMask | ButtonMotionMask | ExposureMask)
#define MenuGrabMask (ButtonMask | ButtonMotionMask | StructureNotifyMask) #define MenuGrabMask (ButtonMask | ButtonMotionMask | StructureNotifyMask)

64
error.c Executable file → Normal file
View file

@ -11,8 +11,7 @@
int ignore_badwindow; int ignore_badwindow;
void void
fatal(char *s) fatal(char* s) {
{
fprintf(stderr, "ryudo: "); fprintf(stderr, "ryudo: ");
perror(s); perror(s);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -20,23 +19,28 @@ fatal(char *s)
} }
int int
handler(Display *d, XErrorEvent *e) handler(Display* d, XErrorEvent* e) {
{
char msg[80], req[80], number[80]; char msg[80], req[80], number[80];
if(initting && (e->request_code == X_ChangeWindowAttributes) && (e->error_code == BadAccess)){ if (
fprintf(stderr, "ryudo: it looks like there's already a window manager running; ryudo not started\n"); 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); exit(1);
} }
if(ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor)) if (
ignore_badwindow &&
(e->error_code == BadWindow || e->error_code == BadColor))
return 0; return 0;
XGetErrorText(d, e->error_code, msg, sizeof(msg)); XGetErrorText(d, e->error_code, msg, sizeof(msg));
sprintf(number, "%d", e->request_code); sprintf(number, "%d", e->request_code);
XGetErrorDatabaseText(d, "XRequest", number, "", req, sizeof(req)); XGetErrorDatabaseText(d, "XRequest", number, "", req, sizeof(req));
if(req[0] == '\0') if (req[0] == '\0') sprintf(req, "<request-code-%d>", (int)e->request_code);
sprintf(req, "<request-code-%d>", (int)e->request_code);
fprintf(stderr, "ryudo: %s(0x%x): %s\n", req, (int)e->resourceid, msg); fprintf(stderr, "ryudo: %s(0x%x): %s\n", req, (int)e->resourceid, msg);
@ -48,29 +52,17 @@ handler(Display *d, XErrorEvent *e)
} }
void void
graberror(char *f, int err) graberror(char* f, int err) {
{
#ifdef DEBUG /* sick of "bug" reports; grab errors "just happen" */ #ifdef DEBUG /* sick of "bug" reports; grab errors "just happen" */
char* s; char* s;
switch (err) { switch (err) {
case GrabNotViewable: case GrabNotViewable: s = "not viewable"; break;
s = "not viewable"; case AlreadyGrabbed: s = "already grabbed"; break;
break; case GrabFrozen: s = "grab frozen"; break;
case AlreadyGrabbed: case GrabInvalidTime: s = "invalid time"; break;
s = "already grabbed"; case GrabSuccess: return;
break; default: fprintf(stderr, "ryudo: %s: grab error: %d\n", f, err); return;
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;
} }
fprintf(stderr, "ryudo: %s: grab error: %s\n", f, s); fprintf(stderr, "ryudo: %s: grab error: %s\n", f, s);
#endif #endif
@ -83,14 +75,20 @@ graberror(char *f, int err)
#ifdef DEBUG #ifdef DEBUG
void void
dotrace(char *s, Client *c, XEvent *e) dotrace(char* s, Client* c, XEvent* e) {
{ if (debug == 0) return;
if(debug == 0)
return;
setbuf(stdout, 0); setbuf(stdout, 0);
fprintf(stderr, "ryudo: %s: c=%p", s, (void*)c); fprintf(stderr, "ryudo: %s: c=%p", s, (void*)c);
if (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); 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 #ifdef DEBUG_EV
if (e) { if (e) {
fprintf(stderr, "\n\t"); fprintf(stderr, "\n\t");

286
event.c Executable file → Normal file
View file

@ -18,8 +18,7 @@
#include "config.h" #include "config.h"
void void
mainloop(int shape_event) mainloop(int shape_event) {
{
XEvent ev; XEvent ev;
for (;;) { for (;;) {
@ -39,44 +38,19 @@ mainloop(int shape_event)
#endif #endif
fprintf(stderr, "ryudo: unknown ev.type %d\n", ev.type); fprintf(stderr, "ryudo: unknown ev.type %d\n", ev.type);
break; break;
case KeyPress: case KeyPress: keypress(&ev.xkey); break;
keypress(&ev.xkey); case KeyRelease: keyrelease(&ev.xkey); break;
break; case ButtonPress: button(&ev.xbutton); break;
case KeyRelease: case ButtonRelease: break;
keyrelease(&ev.xkey); case MapRequest: mapreq(&ev.xmaprequest); break;
break; case ConfigureRequest: configurereq(&ev.xconfigurerequest); break;
case ButtonPress: case CirculateRequest: circulatereq(&ev.xcirculaterequest); break;
button(&ev.xbutton); case UnmapNotify: unmap(&ev.xunmap); break;
break; case CreateNotify: newwindow(&ev.xcreatewindow); break;
case ButtonRelease: case DestroyNotify: destroy(ev.xdestroywindow.window); break;
break; case ClientMessage: clientmesg(&ev.xclient); break;
case MapRequest: case ColormapNotify: cmap(&ev.xcolormap); break;
mapreq(&ev.xmaprequest); case PropertyNotify: property(&ev.xproperty); break;
break;
case ConfigureRequest:
configurereq(&ev.xconfigurerequest);
break;
case CirculateRequest:
circulatereq(&ev.xcirculaterequest);
break;
case UnmapNotify:
unmap(&ev.xunmap);
break;
case CreateNotify:
newwindow(&ev.xcreatewindow);
break;
case DestroyNotify:
destroy(ev.xdestroywindow.window);
break;
case ClientMessage:
clientmesg(&ev.xclient);
break;
case ColormapNotify:
cmap(&ev.xcolormap);
break;
case PropertyNotify:
property(&ev.xproperty);
break;
case SelectionClear: case SelectionClear:
fprintf(stderr, "ryudo: SelectionClear (this should not happen)\n"); fprintf(stderr, "ryudo: SelectionClear (this should not happen)\n");
break; break;
@ -86,21 +60,11 @@ mainloop(int shape_event)
case SelectionRequest: case SelectionRequest:
fprintf(stderr, "ryudo: SelectionRequest (this should not happen)\n"); fprintf(stderr, "ryudo: SelectionRequest (this should not happen)\n");
break; break;
case EnterNotify: case EnterNotify: enter(&ev.xcrossing); break;
enter(&ev.xcrossing); case LeaveNotify: leave(&ev.xcrossing); break;
break; case ReparentNotify: reparent(&ev.xreparent); break;
case LeaveNotify: case FocusIn: focusin(&ev.xfocus); break;
leave(&ev.xcrossing); case MotionNotify: motionnotify(&ev.xmotion); break;
break;
case ReparentNotify:
reparent(&ev.xreparent);
break;
case FocusIn:
focusin(&ev.xfocus);
break;
case MotionNotify:
motionnotify(&ev.xmotion);
break;
case Expose: case Expose:
case NoExpose: case NoExpose:
case FocusOut: case FocusOut:
@ -115,10 +79,8 @@ mainloop(int shape_event)
} }
} }
void void
configurereq(XConfigureRequestEvent *e) configurereq(XConfigureRequestEvent* e) {
{
XWindowChanges wc; XWindowChanges wc;
Client* c; Client* c;
@ -129,16 +91,11 @@ configurereq(XConfigureRequestEvent *e)
e->value_mask &= ~CWSibling; e->value_mask &= ~CWSibling;
if (c) { if (c) {
if(e->value_mask & CWX) if (e->value_mask & CWX) c->x = e->x;
c->x = e->x; if (e->value_mask & CWY) c->y = e->y;
if(e->value_mask & CWY) if (e->value_mask & CWWidth) c->dx = e->width;
c->y = e->y; if (e->value_mask & CWHeight) c->dy = e->height;
if(e->value_mask & CWWidth) if (e->value_mask & CWBorderWidth) c->border = e->border_width;
c->dx = e->width;
if(e->value_mask & CWHeight)
c->dy = e->height;
if(e->value_mask & CWBorderWidth)
c->border = e->border_width;
if (c->dx >= c->screen->width && c->dy >= c->screen->height) if (c->dx >= c->screen->width && c->dy >= c->screen->height)
c->border = 0; c->border = 0;
@ -188,8 +145,7 @@ configurereq(XConfigureRequestEvent *e)
} }
void void
mapreq(XMapRequestEvent *e) mapreq(XMapRequestEvent* e) {
{
Client* c; Client* c;
int i; int i;
@ -199,10 +155,12 @@ mapreq(XMapRequestEvent *e)
if (c == 0 || c->window != e->window) { if (c == 0 || c->window != e->window) {
/* workaround for stupid NCDware */ /* workaround for stupid NCDware */
fprintf(stderr, "ryudo: bad mapreq c %p w %x, rescanning\n", fprintf(
(void*)c, (int)e->window); stderr,
for(i = 0; i < num_screens; i++) "ryudo: bad mapreq c %p w %x, rescanning\n",
scanwins(&screens[i]); (void*)c,
(int)e->window);
for (i = 0; i < num_screens; i++) scanwins(&screens[i]);
c = getclient(e->window, 0); c = getclient(e->window, 0);
if (c == 0 || c->window != e->window) { if (c == 0 || c->window != e->window) {
fprintf(stderr, "ryudo: window not found after rescan\n"); fprintf(stderr, "ryudo: window not found after rescan\n");
@ -213,8 +171,7 @@ mapreq(XMapRequestEvent *e)
switch (c->state) { switch (c->state) {
case WithdrawnState: case WithdrawnState:
if (c->parent == c->screen->root) { if (c->parent == c->screen->root) {
if(!manage(c, 0)) if (!manage(c, 0)) return;
return;
break; break;
} }
XReparentWindow(dpy, c->window, c->parent, BORDER - 1, BORDER - 1); XReparentWindow(dpy, c->window, c->parent, BORDER - 1, BORDER - 1);
@ -225,18 +182,14 @@ mapreq(XMapRequestEvent *e)
XMapRaised(dpy, c->parent); XMapRaised(dpy, c->parent);
top(c); top(c);
setstate(c, NormalState); setstate(c, NormalState);
if(c->trans != None && current && c->trans == current->window) if (c->trans != None && current && c->trans == current->window) active(c);
active(c);
break;
case IconicState:
unhidec(c, 1);
break; break;
case IconicState: unhidec(c, 1); break;
} }
} }
void void
unmap(XUnmapEvent *e) unmap(XUnmapEvent* e) {
{
Client* c; Client* c;
curtime = CurrentTime; curtime = CurrentTime;
@ -250,10 +203,8 @@ unmap(XUnmapEvent *e)
} }
break; break;
case NormalState: case NormalState:
if(c == current) if (c == current) nofocus();
nofocus(); if (!c->reparenting) withdraw(c);
if(!c->reparenting)
withdraw(c);
break; break;
} }
c->reparenting = 0; c->reparenting = 0;
@ -261,23 +212,19 @@ unmap(XUnmapEvent *e)
} }
void void
circulatereq(XCirculateRequestEvent *e) circulatereq(XCirculateRequestEvent* e) {
{
fprintf(stderr, "It must be the warlock Krill!\n"); /* ☺ */ fprintf(stderr, "It must be the warlock Krill!\n"); /* ☺ */
} }
void void
newwindow(XCreateWindowEvent *e) newwindow(XCreateWindowEvent* e) {
{
Client* c; Client* c;
ScreenInfo* s; ScreenInfo* s;
static XWindowAttributes ra; static XWindowAttributes ra;
XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra); XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra);
/* we don't set curtime as nothing here uses it */ /* we don't set curtime as nothing here uses it */
if(e->override_redirect) if (e->override_redirect) return;
return;
c = getclient(e->window, 1); c = getclient(e->window, 1);
if (c && c->window == e->window && (s = getscreen(e->parent))) { if (c && c->window == e->window && (s = getscreen(e->parent))) {
c->x = e->x; c->x = e->x;
@ -286,32 +233,28 @@ newwindow(XCreateWindowEvent *e)
c->dy = e->height; c->dy = e->height;
c->border = e->border_width; c->border = e->border_width;
c->screen = s; c->screen = s;
if(c->parent == None) if (c->parent == None) c->parent = c->screen->root;
c->parent = c->screen->root;
} }
if (kbLaunch) if (kbLaunch) {
{
usleep(100000); usleep(100000);
quickreshape(c, ra.width/6, GAPSZ, 2*ra.width/3, ra.height - 2*GAPSZ); quickreshape(
c, ra.width / 6, GAPSZ, 2 * ra.width / 3, ra.height - 2 * GAPSZ);
kbLaunch = 0; kbLaunch = 0;
} }
} }
void void
destroy(Window w) destroy(Window w) {
{
int i; int i;
Client* c; Client* c;
curtime = CurrentTime; curtime = CurrentTime;
c = getclient(w, 0); c = getclient(w, 0);
if(c == 0) if (c == 0) return;
return;
if (numvirtuals > 1) if (numvirtuals > 1)
for (i = 0; i < numvirtuals; i++) for (i = 0; i < numvirtuals; i++)
if(currents[i] == c) if (currents[i] == c) currents[i] = 0;
currents[i] = 0;
rmclient(c); rmclient(c);
@ -322,8 +265,7 @@ destroy(Window w)
} }
void void
clientmesg(XClientMessageEvent *e) clientmesg(XClientMessageEvent* e) {
{
Client* c; Client* c;
curtime = CurrentTime; curtime = CurrentTime;
@ -338,35 +280,42 @@ clientmesg(XClientMessageEvent *e)
perror("ryudo: exec failed"); perror("ryudo: exec failed");
exit(1); exit(1);
} }
if(e->message_type == wm_protocols) if (e->message_type == wm_protocols) return;
return;
if (e->message_type == wm_change_state) { if (e->message_type == wm_change_state) {
c = getclient(e->window, 0); c = getclient(e->window, 0);
if (e->format == 32 && e->data.l[0] == IconicState && c != 0) { if (e->format == 32 && e->data.l[0] == IconicState && c != 0) {
if(normal(c)) if (normal(c)) hide(c);
hide(c); } else
} fprintf(
else stderr,
fprintf(stderr, "ryudo: WM_CHANGE_STATE: format %d data %d w 0x%x\n", "ryudo: WM_CHANGE_STATE: format %d data %d w 0x%x\n",
(int)e->format, (int)e->data.l[0], (int)e->window); (int)e->format,
(int)e->data.l[0],
(int)e->window);
return; return;
} }
if (e->message_type == wm_state) { if (e->message_type == wm_state) {
// c = getclient(e->window, 0); // c = getclient(e->window, 0);
// if(e->format == 32 && e->data.l[1] == wm_state_fullscreen){ // if(e->format == 32 && e->data.l[1] == wm_state_fullscreen){
// }else // }else
fprintf(stderr, "ryudo: WM_STATE: format %d data %d %d w 0x%x\n", fprintf(
(int)e->format, (int)e->data.l[0], (int)e->data.l[1], stderr,
"ryudo: WM_STATE: format %d data %d %d w 0x%x\n",
(int)e->format,
(int)e->data.l[0],
(int)e->data.l[1],
(int)e->window); (int)e->window);
return; return;
} }
fprintf(stderr, "ryudo: strange ClientMessage, type 0x%x window 0x%x\n", fprintf(
(int)e->message_type, (int)e->window); stderr,
"ryudo: strange ClientMessage, type 0x%x window 0x%x\n",
(int)e->message_type,
(int)e->window);
} }
void void
cmap(XColormapEvent *e) cmap(XColormapEvent* e) {
{
Client* c; Client* c;
int i; int i;
@ -375,16 +324,13 @@ cmap(XColormapEvent *e)
c = getclient(e->window, 0); c = getclient(e->window, 0);
if (c) { if (c) {
c->cmap = e->colormap; c->cmap = e->colormap;
if(c == current) if (c == current) cmapfocus(c);
cmapfocus(c); } else
}
else
for (c = clients; c; c = c->next) { for (c = clients; c; c = c->next) {
for (i = 0; i < c->ncmapwins; i++) for (i = 0; i < c->ncmapwins; i++)
if (c->cmapwins[i] == e->window) { if (c->cmapwins[i] == e->window) {
c->wmcmaps[i] = e->colormap; c->wmcmaps[i] = e->colormap;
if(c == current) if (c == current) cmapfocus(c);
cmapfocus(c);
return; return;
} }
} }
@ -392,8 +338,7 @@ cmap(XColormapEvent *e)
} }
void void
property(XPropertyEvent *e) property(XPropertyEvent* e) {
{
Atom a; Atom a;
int delete; int delete;
Client* c; Client* c;
@ -403,59 +348,51 @@ property(XPropertyEvent *e)
a = e->atom; a = e->atom;
delete = (e->state == PropertyDelete); delete = (e->state == PropertyDelete);
c = getclient(e->window, 0); c = getclient(e->window, 0);
if(c == 0) if (c == 0) return;
return;
switch (a) { switch (a) {
case XA_WM_ICON_NAME: case XA_WM_ICON_NAME:
if(c->iconname != 0) if (c->iconname != 0) XFree((char*)c->iconname);
XFree((char*) c->iconname);
c->iconname = delete ? 0 : getprop(c->window, a); c->iconname = delete ? 0 : getprop(c->window, a);
setlabel(c); setlabel(c);
renamec(c, c->label); renamec(c, c->label);
return; return;
case XA_WM_NAME: case XA_WM_NAME:
if(c->name != 0) if (c->name != 0) XFree((char*)c->name);
XFree((char*) c->name);
c->name = delete ? 0 : getprop(c->window, a); c->name = delete ? 0 : getprop(c->window, a);
setlabel(c); setlabel(c);
renamec(c, c->label); renamec(c, c->label);
return; return;
case XA_WM_TRANSIENT_FOR: case XA_WM_TRANSIENT_FOR: gettrans(c); return;
gettrans(c);
return;
case XA_WM_HINTS: case XA_WM_HINTS:
case XA_WM_SIZE_HINTS: case XA_WM_SIZE_HINTS:
case XA_WM_ZOOM_HINTS: case XA_WM_ZOOM_HINTS:
/* placeholders to not forget. ignore for now. -Axel */ /* placeholders to not forget. ignore for now. -Axel */
return; return;
case XA_WM_NORMAL_HINTS: case XA_WM_NORMAL_HINTS:
if(XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0) if (
XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 ||
c->size.flags == 0)
c->size.flags = PSize; /* not specified - punt */ c->size.flags = PSize; /* not specified - punt */
return; return;
} }
if (a == _rio_hold_mode) { if (a == _rio_hold_mode) {
c->hold = getiprop(c->window, _rio_hold_mode); c->hold = getiprop(c->window, _rio_hold_mode);
if(c == current) if (c == current) draw_border(c, 1);
draw_border(c, 1); } else if (a == wm_colormaps) {
}
else if(a == wm_colormaps){
getcmaps(c); getcmaps(c);
if(c == current) if (c == current) cmapfocus(c);
cmapfocus(c);
} }
} }
void void
reparent(XReparentEvent *e) reparent(XReparentEvent* e) {
{
Client* c; Client* c;
XWindowAttributes attr; XWindowAttributes attr;
ScreenInfo* s; ScreenInfo* s;
/* we don't set curtime as nothing here uses it */ /* we don't set curtime as nothing here uses it */
if(!getscreen(e->event) || e->override_redirect) if (!getscreen(e->event) || e->override_redirect) return;
return;
if ((s = getscreen(e->parent)) != 0) { if ((s = getscreen(e->parent)) != 0) {
c = getclient(e->window, 1); c = getclient(e->window, 1);
if (c != 0 && (c->dx == 0 || c->dy == 0)) { if (c != 0 && (c->dx == 0 || c->dy == 0)) {
@ -471,70 +408,58 @@ reparent(XReparentEvent *e)
c->dy = attr.height; c->dy = attr.height;
c->border = attr.border_width; c->border = attr.border_width;
c->screen = s; c->screen = s;
if(c->parent == None) if (c->parent == None) c->parent = c->screen->root;
c->parent = c->screen->root;
} }
} } else {
else {
c = getclient(e->window, 0); c = getclient(e->window, 0);
if(c != 0 && (c->parent == c->screen->root || withdrawn(c))) if (c != 0 && (c->parent == c->screen->root || withdrawn(c))) rmclient(c);
rmclient(c);
} }
} }
#ifdef SHAPE #ifdef SHAPE
void void
shapenotify(XShapeEvent *e) shapenotify(XShapeEvent* e) {
{
Client* c; Client* c;
/* we don't set curtime as nothing here uses it */ /* we don't set curtime as nothing here uses it */
c = getclient(e->window, 0); c = getclient(e->window, 0);
if(c == 0) if (c == 0) return;
return;
setshape(c); setshape(c);
} }
#endif #endif
void void
enter(XCrossingEvent *e) enter(XCrossingEvent* e) {
{
Client* c; Client* c;
curtime = e->time; curtime = e->time;
if (!ffm) if (!ffm)
if(e->mode != NotifyGrab || e->detail != NotifyNonlinearVirtual) if (e->mode != NotifyGrab || e->detail != NotifyNonlinearVirtual) return;
return;
c = getclient(e->window, 0); c = getclient(e->window, 0);
if (c != 0 && c != current) { if (c != 0 && c != current) {
/* someone grabbed the pointer; make them current */ /* someone grabbed the pointer; make them current */
if(!ffm) if (!ffm) XMapRaised(dpy, c->parent);
XMapRaised(dpy, c->parent);
top(c); top(c);
active(c); active(c);
} }
} }
void void
leave(XCrossingEvent *e) leave(XCrossingEvent* e) {
{
Client* c; Client* c;
c = getclient(e->window, 0); c = getclient(e->window, 0);
if(c) if (c) XUndefineCursor(dpy, c->parent);
XUndefineCursor(dpy, c->parent);
/* XDefineCursor(dpy, c->parent, c->screen->arrow); */ /* XDefineCursor(dpy, c->parent, c->screen->arrow); */
} }
void void
focusin(XFocusChangeEvent *e) focusin(XFocusChangeEvent* e) {
{
Client* c; Client* c;
curtime = CurrentTime; curtime = CurrentTime;
if(e->detail != NotifyNonlinearVirtual) if (e->detail != NotifyNonlinearVirtual) return;
return;
c = getclient(e->window, 0); c = getclient(e->window, 0);
if (c != 0 && c->window == e->window && c != current) { if (c != 0 && c->window == e->window && c != current) {
#ifdef AUTOSTICK #ifdef AUTOSTICK
@ -551,8 +476,7 @@ focusin(XFocusChangeEvent *e)
} }
BorderOrient BorderOrient
borderorient(Client *c, int x, int y) borderorient(Client* c, int x, int y) {
{
if (x <= BORDER) { if (x <= BORDER) {
if (y <= CORNER) { if (y <= CORNER) {
if (debug) fprintf(stderr, "topleft\n"); if (debug) fprintf(stderr, "topleft\n");
@ -562,8 +486,7 @@ borderorient(Client *c, int x, int y)
if (debug) fprintf(stderr, "botleft\n"); if (debug) fprintf(stderr, "botleft\n");
return BorderWSW; return BorderWSW;
} }
if(y > CORNER && if (y > CORNER && y < (c->dy + 2 * BORDER) - CORNER) {
y < (c->dy + 2*BORDER) - CORNER){
if (debug) fprintf(stderr, "left\n"); if (debug) fprintf(stderr, "left\n");
return BorderW; return BorderW;
} }
@ -585,8 +508,7 @@ borderorient(Client *c, int x, int y)
if (debug) fprintf(stderr, "botright\n"); if (debug) fprintf(stderr, "botright\n");
return BorderESE; return BorderESE;
} }
if(y > CORNER && if (y > CORNER && y < (c->dy + 2 * BORDER) - CORNER) {
y < (c->dy + 2*BORDER) - CORNER){
if (debug) fprintf(stderr, "right\n"); if (debug) fprintf(stderr, "right\n");
return BorderE; return BorderE;
} }
@ -599,8 +521,7 @@ borderorient(Client *c, int x, int y)
if (debug) fprintf(stderr, "botright\n"); if (debug) fprintf(stderr, "botright\n");
return BorderSSE; return BorderSSE;
} }
} else if(x > CORNER && } else if (x > CORNER && x < (c->dx + 2 * BORDER) - CORNER) {
x < (c->dx + 2*BORDER) - CORNER){
if (y <= BORDER) { if (y <= BORDER) {
if (debug) fprintf(stderr, "top\n"); if (debug) fprintf(stderr, "top\n");
return BorderN; return BorderN;
@ -614,8 +535,7 @@ borderorient(Client *c, int x, int y)
} }
void void
motionnotify(XMotionEvent *e) motionnotify(XMotionEvent* e) {
{
Client* c; Client* c;
BorderOrient bl; BorderOrient bl;

5
fns.h Executable file → Normal file
View file

@ -8,9 +8,9 @@
#define setstate setstaterio #define setstate setstaterio
/* color.c */ /* color.c */
unsigned long colorpixel(Display*, ScreenInfo*, int, unsigned long, unsigned long); unsigned long
colorpixel(Display*, ScreenInfo*, int, unsigned long, unsigned long);
/* main.c */ /* main.c */
void usage(); void usage();
@ -85,7 +85,6 @@ void switch_to();
void switch_to_c(); void switch_to_c();
void stick(); void stick();
/* client.c */ /* client.c */
void setactive(); void setactive();
void draw_border(); void draw_border();

246
grab.c Executable file → Normal file
View file

@ -17,56 +17,64 @@ nobuttons(XButtonEvent *e) /* Einstuerzende */
} }
int int
grab(Window w, Window constrain, int mask, Cursor curs, int t) grab(Window w, Window constrain, int mask, Cursor curs, int t) {
{
int status; int status;
if(t == 0) if (t == 0) t = timestamp();
t = timestamp(); status = XGrabPointer(
status = XGrabPointer(dpy, w, False, mask, dpy, w, False, mask, GrabModeAsync, GrabModeAsync, constrain, curs, t);
GrabModeAsync, GrabModeAsync, constrain, curs, t);
return status; return status;
} }
void void
ungrab(XButtonEvent *e) ungrab(XButtonEvent* e) {
{
XEvent ev; XEvent ev;
if (!nobuttons(e)) if (!nobuttons(e))
for (;;) { for (;;) {
XMaskEvent(dpy, ButtonMask | ButtonMotionMask, &ev); XMaskEvent(dpy, ButtonMask | ButtonMotionMask, &ev);
if(ev.type == MotionNotify) if (ev.type == MotionNotify) continue;
continue;
e = &ev.xbutton; e = &ev.xbutton;
if(nobuttons(e)) if (nobuttons(e)) break;
break;
} }
XUngrabPointer(dpy, e->time); XUngrabPointer(dpy, e->time);
curtime = e->time; curtime = e->time;
} }
static void static void
drawstring(Display *dpy, ScreenInfo *s, Menu *m, int wide, int high, int i, int selected) drawstring(
{ Display* dpy, ScreenInfo* s, Menu* m, int wide, int high, int i,
int selected) {
int tx, ty; int tx, ty;
tx = (wide - XTextWidth(font, m->item[i], strlen(m->item[i]))) / 2; tx = (wide - XTextWidth(font, m->item[i], strlen(m->item[i]))) / 2;
ty = i * high + font->ascent + 1; ty = i * high + font->ascent + 1;
XFillRectangle(dpy, s->menuwin, selected ? s->gcmenubgs : s->gcmenubg, 0, i*high, wide, high); XFillRectangle(
XDrawString(dpy, s->menuwin, selected ? s->gcmenufgs : s->gcmenufg, tx, ty, m->item[i], strlen(m->item[i])); dpy,
s->menuwin,
selected ? s->gcmenubgs : s->gcmenubg,
0,
i * high,
wide,
high);
XDrawString(
dpy,
s->menuwin,
selected ? s->gcmenufgs : s->gcmenufg,
tx,
ty,
m->item[i],
strlen(m->item[i]));
} }
int int
menuhit(XButtonEvent *e, Menu *m) menuhit(XButtonEvent* e, Menu* m) {
{
XEvent ev; XEvent ev;
int i, n, cur, old, wide, high, status, drawn, warp; int i, n, cur, old, wide, high, status, drawn, warp;
int x, y, dx, dy, xmax, ymax; int x, y, dx, dy, xmax, ymax;
ScreenInfo* s; ScreenInfo* s;
if(font == 0) if (font == 0) return -1;
return -1;
s = getscreen(e->root); s = getscreen(e->root);
if (s == 0 || e->window == s->menuwin) /* ugly event mangling */ if (s == 0 || e->window == s->menuwin) /* ugly event mangling */
return -1; return -1;
@ -74,13 +82,11 @@ menuhit(XButtonEvent *e, Menu *m)
dx = 0; dx = 0;
for (n = 0; m->item[n]; n++) { for (n = 0; m->item[n]; n++) {
wide = XTextWidth(font, m->item[n], strlen(m->item[n])) + 4; wide = XTextWidth(font, m->item[n], strlen(m->item[n])) + 4;
if(wide > dx) if (wide > dx) dx = wide;
dx = wide;
} }
wide = dx; wide = dx;
cur = m->lasthit; cur = m->lasthit;
if(cur >= n) if (cur >= n) cur = n - 1;
cur = n - 1;
high = font->ascent + font->descent + 1; high = font->ascent + font->descent + 1;
dy = n * high; dy = n * high;
@ -109,8 +115,7 @@ menuhit(XButtonEvent *e, Menu *m)
y = ymax - dy; y = ymax - dy;
warp++; warp++;
} }
if(warp) if (warp) setmouse(e->x, e->y, s);
setmouse(e->x, e->y, s);
XMoveResizeWindow(dpy, s->menuwin, x, y, dx, dy); XMoveResizeWindow(dpy, s->menuwin, x, y, dx, dy);
XSelectInput(dpy, s->menuwin, MenuMask); XSelectInput(dpy, s->menuwin, MenuMask);
XMapRaised(dpy, s->menuwin); XMapRaised(dpy, s->menuwin);
@ -127,11 +132,9 @@ menuhit(XButtonEvent *e, Menu *m)
default: default:
fprintf(stderr, "ryudo: menuhit: unknown ev.type %d\n", ev.type); fprintf(stderr, "ryudo: menuhit: unknown ev.type %d\n", ev.type);
break; break;
case ButtonPress: case ButtonPress: break;
break;
case ButtonRelease: case ButtonRelease:
if(ev.xbutton.button != e->button) if (ev.xbutton.button != e->button) break;
break;
x = ev.xbutton.x; x = ev.xbutton.x;
y = ev.xbutton.y; y = ev.xbutton.y;
i = y / high; i = y / high;
@ -143,14 +146,12 @@ menuhit(XButtonEvent *e, Menu *m)
i = -1; i = -1;
else else
m->lasthit = i; m->lasthit = i;
if(!nobuttons(&ev.xbutton)) if (!nobuttons(&ev.xbutton)) i = -1;
i = -1;
ungrab(&ev.xbutton); ungrab(&ev.xbutton);
XUnmapWindow(dpy, s->menuwin); XUnmapWindow(dpy, s->menuwin);
return i; return i;
case MotionNotify: case MotionNotify:
if(!drawn) if (!drawn) break;
break;
x = ev.xbutton.x; x = ev.xbutton.x;
y = ev.xbutton.y; y = ev.xbutton.y;
old = cur; old = cur;
@ -161,25 +162,20 @@ menuhit(XButtonEvent *e, Menu *m)
cur = -1; cur = -1;
else if (cur < 0 || cur >= n) else if (cur < 0 || cur >= n)
cur = -1; cur = -1;
if(cur == old) if (cur == old) break;
break; if (old >= 0 && old < n) drawstring(dpy, s, m, wide, high, old, 0);
if(old >= 0 && old < n) if (cur >= 0 && cur < n) drawstring(dpy, s, m, wide, high, cur, 1);
drawstring(dpy, s, m, wide, high, old, 0);
if(cur >= 0 && cur < n)
drawstring(dpy, s, m, wide, high, cur, 1);
break; break;
case Expose: case Expose:
XClearWindow(dpy, s->menuwin); XClearWindow(dpy, s->menuwin);
for(i = 0; i < n; i++) for (i = 0; i < n; i++) drawstring(dpy, s, m, wide, high, i, cur == i);
drawstring(dpy, s, m, wide, high, i, cur==i);
drawn = 1; drawn = 1;
} }
} }
} }
Client* Client*
selectwin(int release, int *shift, ScreenInfo *s) selectwin(int release, int* shift, ScreenInfo* s) {
{
XEvent ev; XEvent ev;
XButtonEvent* e; XButtonEvent* e;
int status; int status;
@ -204,27 +200,22 @@ selectwin(int release, int *shift, ScreenInfo *s)
w = e->subwindow; w = e->subwindow;
if (!release) { if (!release) {
c = getclient(w, 0); c = getclient(w, 0);
if(c == 0) if (c == 0) ungrab(e);
ungrab(e); if (shift != 0) *shift = (e->state & ShiftMask) != 0;
if(shift != 0)
*shift = (e->state&ShiftMask) != 0;
return c; return c;
} }
break; break;
case ButtonRelease: case ButtonRelease:
ungrab(e); ungrab(e);
if(e->button != Button3 || e->subwindow != w) if (e->button != Button3 || e->subwindow != w) return 0;
return 0; if (shift != 0) *shift = (e->state & ShiftMask) != 0;
if(shift != 0)
*shift = (e->state&ShiftMask) != 0;
return getclient(w, 0); return getclient(w, 0);
} }
} }
} }
int int
sweepcalc(Client *c, int x, int y, BorderOrient bl, int ignored) sweepcalc(Client* c, int x, int y, BorderOrient bl, int ignored) {
{
int dx, dy, sx, sy; int dx, dy, sx, sy;
dx = x - c->x; dx = x - c->x;
@ -245,10 +236,8 @@ sweepcalc(Client *c, int x, int y, BorderOrient bl, int ignored)
dy -= 2 * BORDER; dy -= 2 * BORDER;
if (!c->is9term) { if (!c->is9term) {
if(dx < c->min_dx) if (dx < c->min_dx) dx = c->min_dx;
dx = c->min_dx; if (dy < c->min_dy) dy = c->min_dy;
if(dy < c->min_dy)
dy = c->min_dy;
} }
if (c->size.flags & PResizeInc) { if (c->size.flags & PResizeInc) {
@ -257,10 +246,8 @@ sweepcalc(Client *c, int x, int y, BorderOrient bl, int ignored)
} }
if (c->size.flags & PMaxSize) { if (c->size.flags & PMaxSize) {
if(dx > c->size.max_width) if (dx > c->size.max_width) dx = c->size.max_width;
dx = c->size.max_width; if (dy > c->size.max_height) dy = c->size.max_height;
if(dy > c->size.max_height)
dy = c->size.max_height;
} }
c->dx = sx * (dx + 2 * BORDER); c->dx = sx * (dx + 2 * BORDER);
c->dy = sy * (dy + 2 * BORDER); c->dy = sy * (dy + 2 * BORDER);
@ -269,8 +256,7 @@ sweepcalc(Client *c, int x, int y, BorderOrient bl, int ignored)
} }
int int
dragcalc(Client *c, int x, int y, BorderOrient bl, int ignored) dragcalc(Client* c, int x, int y, BorderOrient bl, int ignored) {
{
c->x += x; c->x += x;
c->y += y; c->y += y;
@ -278,8 +264,7 @@ dragcalc(Client *c, int x, int y, BorderOrient bl, int ignored)
} }
int int
pullcalc(Client *c, int x, int y, BorderOrient bl, int init) pullcalc(Client* c, int x, int y, BorderOrient bl, int init) {
{
int dx, dy, sx, sy, px, py, spx, spy, rdx, rdy, xoff, yoff, xcorn, ycorn; int dx, dy, sx, sy, px, py, spx, spy, rdx, rdy, xoff, yoff, xcorn, ycorn;
px = c->x; px = c->x;
@ -348,33 +333,44 @@ pullcalc(Client *c, int x, int y, BorderOrient bl, int init)
xoff = x - c->x; xoff = x - c->x;
yoff = (c->y + c->dy) - y; yoff = (c->y + c->dy) - y;
break; break;
default: default: break;
break;
} }
switch (bl) { switch (bl) {
case BorderNNW: case BorderNNW:
case BorderNNE: case BorderNNE:
case BorderSSW: case BorderSSW:
case BorderSSE: case BorderSSE: xcorn = 1; break;
xcorn = 1;
break;
case BorderWNW: case BorderWNW:
case BorderENE: case BorderENE:
case BorderWSW: case BorderWSW:
case BorderESE: case BorderESE: ycorn = 1; break;
ycorn = 1;
break;
} }
if(!init if (
|| xoff < 0 || (xcorn && xoff > CORNER) || (!xcorn && xoff > BORDER) !init || xoff < 0 || (xcorn && xoff > CORNER) ||
|| yoff < 0 || (ycorn && yoff > CORNER) || (!ycorn && yoff > BORDER)){ (!xcorn && xoff > BORDER) || yoff < 0 || (ycorn && yoff > CORNER) ||
(!ycorn && yoff > BORDER)) {
xoff = 0; xoff = 0;
yoff = 0; yoff = 0;
init = 0; init = 0;
} }
if(debug) fprintf(stderr, "c %dx%d+%d+%d m +%d+%d r %dx%d+%d+%d sp (%d,%d) bl %d\n", if (debug)
c->dx, c->dy, c->x, c->y, x, y, dx, dy, px, py, spx, spy, bl); fprintf(
stderr,
"c %dx%d+%d+%d m +%d+%d r %dx%d+%d+%d sp (%d,%d) bl %d\n",
c->dx,
c->dy,
c->x,
c->y,
x,
y,
dx,
dy,
px,
py,
spx,
spy,
bl);
if (dx < 0) { if (dx < 0) {
dx = -dx; dx = -dx;
sx = -1; sx = -1;
@ -395,10 +391,8 @@ pullcalc(Client *c, int x, int y, BorderOrient bl, int init)
dy -= (2 * BORDER - yoff); dy -= (2 * BORDER - yoff);
if (!c->is9term) { if (!c->is9term) {
if(dx < c->min_dx) if (dx < c->min_dx) dx = c->min_dx;
dx = c->min_dx; if (dy < c->min_dy) dy = c->min_dy;
if(dy < c->min_dy)
dy = c->min_dy;
} }
if (c->size.flags & PResizeInc) { if (c->size.flags & PResizeInc) {
@ -407,10 +401,8 @@ pullcalc(Client *c, int x, int y, BorderOrient bl, int init)
} }
if (c->size.flags & PMaxSize) { if (c->size.flags & PMaxSize) {
if(dx > c->size.max_width) if (dx > c->size.max_width) dx = c->size.max_width;
dx = c->size.max_width; if (dy > c->size.max_height) dy = c->size.max_height;
if(dy > c->size.max_height)
dy = c->size.max_height;
} }
/* set size and position */ /* set size and position */
@ -420,17 +412,16 @@ pullcalc(Client *c, int x, int y, BorderOrient bl, int init)
c->y = py; c->y = py;
/* compensate position for size changed due to size hints */ /* compensate position for size changed due to size hints */
if(spx) if (spx) c->x -= c->dx - rdx;
c->x -= c->dx - rdx; if (spy) c->y -= c->dy - rdy;
if(spy)
c->y -= c->dy - rdy;
return init; return init;
} }
static void static void
xcopy(int fwd, Display *dpy, Drawable src, Drawable dst, GC gc, int x, int y, int dx, int dy, int x1, int y1) xcopy(
{ int fwd, Display* dpy, Drawable src, Drawable dst, GC gc, int x, int y,
int dx, int dy, int x1, int y1) {
if (fwd) if (fwd)
XCopyArea(dpy, src, dst, gc, x, y, dx, dy, x1, y1); XCopyArea(dpy, src, dst, gc, x, y, dx, dy, x1, y1);
else else
@ -438,12 +429,13 @@ xcopy(int fwd, Display *dpy, Drawable src, Drawable dst, GC gc, int x, int y, in
} }
void void
drawbound(Client *c, int drawing) drawbound(Client* c, int drawing) {
{
int x, y, dx, dy; int x, y, dx, dy;
ScreenInfo* s; ScreenInfo* s;
if(debug) fprintf(stderr, "drawbound %d %dx%d+%d+%d\n", drawing, c->dx, c->dy, c->x, c->y); if (debug)
fprintf(
stderr, "drawbound %d %dx%d+%d+%d\n", drawing, c->dx, c->dy, c->x, c->y);
s = c->screen; s = c->screen;
x = c->x; x = c->x;
@ -458,8 +450,7 @@ drawbound(Client *c, int drawing)
y += dy; y += dy;
dy = -dy; dy = -dy;
} }
if(dx <= 2 || dy <= 2) if (dx <= 2 || dy <= 2) return;
return;
if (solidsweep) { if (solidsweep) {
if (drawing == -1) { if (drawing == -1) {
@ -480,13 +471,34 @@ drawbound(Client *c, int drawing)
return; return;
} }
if(drawing == -1) if (drawing == -1) return;
return;
xcopy(drawing, dpy, s->root, s->bkup[0], s->gccopy, x, y, dx, BORDER, 0, 0); xcopy(drawing, dpy, s->root, s->bkup[0], s->gccopy, x, y, dx, BORDER, 0, 0);
xcopy(drawing, dpy, s->root, s->bkup[0], s->gccopy, x, y+dy-BORDER, dx, BORDER, dx, 0); xcopy(
drawing,
dpy,
s->root,
s->bkup[0],
s->gccopy,
x,
y + dy - BORDER,
dx,
BORDER,
dx,
0);
xcopy(drawing, dpy, s->root, s->bkup[1], s->gccopy, x, y, BORDER, dy, 0, 0); xcopy(drawing, dpy, s->root, s->bkup[1], s->gccopy, x, y, BORDER, dy, 0, 0);
xcopy(drawing, dpy, s->root, s->bkup[1], s->gccopy, x+dx-BORDER, y, BORDER, dy, 0, dy); xcopy(
drawing,
dpy,
s->root,
s->bkup[1],
s->gccopy,
x + dx - BORDER,
y,
BORDER,
dy,
0,
dy);
if (drawing) { if (drawing) {
XFillRectangle(dpy, s->root, s->gcred, x, y, dx, BORDER); XFillRectangle(dpy, s->root, s->gcred, x, y, dx, BORDER);
@ -497,8 +509,7 @@ drawbound(Client *c, int drawing)
} }
void void
misleep(int msec) misleep(int msec) {
{
struct timeval t; struct timeval t;
t.tv_sec = msec / 1000; t.tv_sec = msec / 1000;
@ -507,8 +518,9 @@ misleep(int msec)
} }
int int
sweepdrag(Client *c, int but, XButtonEvent *e0, BorderOrient bl, int (*recalc)(Client*, int, int, BorderOrient, int)) sweepdrag(
{ Client* c, int but, XButtonEvent* e0, BorderOrient bl,
int (*recalc)(Client*, int, int, BorderOrient, int)) {
XEvent ev; XEvent ev;
int idle; int idle;
int cx, cy, rx, ry; int cx, cy, rx, ry;
@ -530,9 +542,7 @@ sweepdrag(Client *c, int but, XButtonEvent *e0, BorderOrient bl, int (*recalc)(C
else else
getmouse(&c->x, &c->y, c->screen); getmouse(&c->x, &c->y, c->screen);
XGrabServer(dpy); XGrabServer(dpy);
if(bl != BorderUnknown){ if (bl != BorderUnknown) { notmoved = recalc(c, cx, cy, bl, notmoved); }
notmoved = recalc(c, cx, cy, bl, notmoved);
}
drawbound(c, 1); drawbound(c, 1);
idle = 0; idle = 0;
for (;;) { for (;;) {
@ -566,8 +576,7 @@ sweepdrag(Client *c, int but, XButtonEvent *e0, BorderOrient bl, int (*recalc)(C
drawbound(c, 0); drawbound(c, 0);
ungrab(e); ungrab(e);
XUngrabServer(dpy); XUngrabServer(dpy);
if(e->button != but && c->init) if (e->button != but && c->init) goto bad;
goto bad;
if (c->dx < 0) { if (c->dx < 0) {
c->x += c->dx; c->x += c->dx;
c->dx = -c->dx; c->dx = -c->dx;
@ -596,8 +605,7 @@ bad:
} }
int int
sweep(Client *c, int but, XButtonEvent *ignored) sweep(Client* c, int but, XButtonEvent* ignored) {
{
XEvent ev; XEvent ev;
int status; int status;
XButtonEvent* e; XButtonEvent* e;
@ -623,8 +631,7 @@ sweep(Client *c, int but, XButtonEvent *ignored)
} }
int int
pull(Client *c, int but, XButtonEvent *e) pull(Client* c, int but, XButtonEvent* e) {
{
int status; int status;
ScreenInfo* s; ScreenInfo* s;
BorderOrient bl; BorderOrient bl;
@ -643,8 +650,7 @@ pull(Client *c, int but, XButtonEvent *e)
} }
int int
drag(Client *c, int but) drag(Client* c, int but) {
{
int status; int status;
ScreenInfo* s; ScreenInfo* s;
@ -658,8 +664,7 @@ drag(Client *c, int but)
} }
void void
getmouse(int *x, int *y, ScreenInfo *s) getmouse(int* x, int* y, ScreenInfo* s) {
{
Window dw1, dw2; Window dw1, dw2;
int t1, t2; int t1, t2;
unsigned int t3; unsigned int t3;
@ -669,7 +674,6 @@ getmouse(int *x, int *y, ScreenInfo *s)
} }
void void
setmouse(int x, int y, ScreenInfo *s) setmouse(int x, int y, ScreenInfo* s) {
{
XWarpPointer(dpy, None, s->root, None, None, None, None, x, y); XWarpPointer(dpy, None, s->root, None, None, None, None, x, y);
} }

217
key.c Executable file → Normal file
View file

@ -18,11 +18,7 @@
#include "fns.h" #include "fns.h"
#include "patchlevel.h" #include "patchlevel.h"
enum enum { GrabAltTab, GrabAltAny };
{
GrabAltTab,
GrabAltAny
};
/*static int tabcode = 0x17; */ /*static int tabcode = 0x17; */
/*static int altcode = 0x40; */ /*static int altcode = 0x40; */
@ -32,8 +28,7 @@ enum
static void alttab(int shift); static void alttab(int shift);
void void
keysetup(void) keysetup(void) {
{
int i; int i;
int tabcode = XKeysymToKeycode(dpy, XK_Tab); int tabcode = XKeysymToKeycode(dpy, XK_Tab);
int dcode = XKeysymToKeycode(dpy, DESTROY_KEY); int dcode = XKeysymToKeycode(dpy, DESTROY_KEY);
@ -61,40 +56,89 @@ keysetup(void)
#endif #endif
for (i = 0; i < num_screens; i++) { for (i = 0; i < num_screens; i++) {
XGrabKey(dpy, tabcode, Mod1Mask, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, dcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, tabcode, Mod1Mask, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, icode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, ucode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, dcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, rcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, vcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, icode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, mcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, scode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, ucode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, hcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, lcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, rcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, jcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, kcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, vcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, qcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, wcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, mcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, ocode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, pcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, scode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, ccode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, leftcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, hcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, rightcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, slcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, lcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(dpy, tabcode, Mod1Mask|ShiftMask, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
dpy, jcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(
dpy, kcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(
dpy, qcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(
dpy, wcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(
dpy, ocode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(
dpy, pcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(
dpy, ccode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(
dpy,
leftcode,
SHORTCUTMOD,
screens[i].root,
0,
GrabModeSync,
GrabModeAsync);
XGrabKey(
dpy,
rightcode,
SHORTCUTMOD,
screens[i].root,
0,
GrabModeSync,
GrabModeAsync);
XGrabKey(
dpy,
slcode,
SHORTCUTMOD,
screens[i].root,
0,
GrabModeSync,
GrabModeAsync);
XGrabKey(
dpy,
tabcode,
Mod1Mask | ShiftMask,
screens[i].root,
0,
GrabModeSync,
GrabModeAsync);
#ifdef DEVEL #ifdef DEVEL
XGrabKey(dpy, tcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); XGrabKey(
XGrabKey(dpy, bcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync); dpy, tcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
XGrabKey(
dpy, bcode, SHORTCUTMOD, screens[i].root, 0, GrabModeSync, GrabModeAsync);
#endif #endif
/* XGrabKey(dpy, pgupcode, Mod1Mask, screens[i].root, 0, GrabModeSync, GrabModeAsync); */ /* XGrabKey(dpy, pgupcode, Mod1Mask, screens[i].root, 0, GrabModeSync,
/* XGrabKey(dpy, pgdowncode, Mod1Mask, screens[i].root, 0, GrabModeSync, GrabModeAsync); */ * GrabModeAsync); */
/* XGrabKey(dpy, altcode, 0, screens[i].root, 0, GrabModeSync, GrabModeAsync); */ /* XGrabKey(dpy, pgdowncode, Mod1Mask, screens[i].root, 0, GrabModeSync,
* GrabModeAsync); */
/* XGrabKey(dpy, altcode, 0, screens[i].root, 0, GrabModeSync,
* GrabModeAsync); */
} }
} }
void void
keypress(XKeyEvent *e) keypress(XKeyEvent* e) {
{
/* /*
* process key press here * process key press here
*/ */
@ -126,7 +170,6 @@ keypress(XKeyEvent *e)
static XWindowAttributes ra; static XWindowAttributes ra;
XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra); XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra);
/* basic wm functionality */ /* basic wm functionality */
if (e->keycode == tabcode && (e->state & Mod1Mask) == (1 << 3)) if (e->keycode == tabcode && (e->state & Mod1Mask) == (1 << 3))
alttab(e->state & ShiftMask); alttab(e->state & ShiftMask);
@ -141,29 +184,62 @@ keypress(XKeyEvent *e)
else if (e->keycode == rcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == rcode && (e->state & SHORTCUTMOD) == (MODBITS))
reshape(current, Button3, sweep, 0); reshape(current, Button3, sweep, 0);
else if (e->keycode == mcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == mcode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, -BORDER, -BORDER, ra.width + 2*BORDER, ra.height + 2*BORDER); quickreshape(
current, -BORDER, -BORDER, ra.width + 2 * BORDER, ra.height + 2 * BORDER);
else if (e->keycode == scode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == scode && (e->state & SHORTCUTMOD) == (MODBITS))
stick(current); stick(current);
/* half snap */ /* half snap */
else if (e->keycode == hcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == hcode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, GAPSZ, GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height - 2*GAPSZ); quickreshape(
current, GAPSZ, GAPSZ, ra.width / 2 - 1.5 * GAPSZ, ra.height - 2 * GAPSZ);
else if (e->keycode == lcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == lcode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, ra.width/2 + 0.5*GAPSZ, GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height - 2*GAPSZ); quickreshape(
current,
ra.width / 2 + 0.5 * GAPSZ,
GAPSZ,
ra.width / 2 - 1.5 * GAPSZ,
ra.height - 2 * GAPSZ);
else if (e->keycode == jcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == jcode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, GAPSZ, ra.height/2 + 0.5*GAPSZ, ra.width - 2*GAPSZ, ra.height/2 - 1.5*GAPSZ); quickreshape(
current,
GAPSZ,
ra.height / 2 + 0.5 * GAPSZ,
ra.width - 2 * GAPSZ,
ra.height / 2 - 1.5 * GAPSZ);
else if (e->keycode == kcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == kcode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, GAPSZ, GAPSZ, ra.width - 2*GAPSZ, ra.height/2 - 1.5*GAPSZ); quickreshape(
current, GAPSZ, GAPSZ, ra.width - 2 * GAPSZ, ra.height / 2 - 1.5 * GAPSZ);
/* quarter snap */ /* quarter snap */
else if (e->keycode == qcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == qcode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, GAPSZ, GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); quickreshape(
current,
GAPSZ,
GAPSZ,
ra.width / 2 - 1.5 * GAPSZ,
ra.height / 2 - 1.5 * GAPSZ);
else if (e->keycode == wcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == wcode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, GAPSZ, ra.height/2 + 0.5*GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); quickreshape(
current,
GAPSZ,
ra.height / 2 + 0.5 * GAPSZ,
ra.width / 2 - 1.5 * GAPSZ,
ra.height / 2 - 1.5 * GAPSZ);
else if (e->keycode == ocode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == ocode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, ra.width/2 + 0.5*GAPSZ, ra.height/2 + 0.5*GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); quickreshape(
current,
ra.width / 2 + 0.5 * GAPSZ,
ra.height / 2 + 0.5 * GAPSZ,
ra.width / 2 - 1.5 * GAPSZ,
ra.height / 2 - 1.5 * GAPSZ);
else if (e->keycode == pcode && (e->state & SHORTCUTMOD) == (MODBITS)) else if (e->keycode == pcode && (e->state & SHORTCUTMOD) == (MODBITS))
quickreshape(current, ra.width/2 + 0.5*GAPSZ, GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); quickreshape(
current,
ra.width / 2 + 0.5 * GAPSZ,
GAPSZ,
ra.width / 2 - 1.5 * GAPSZ,
ra.height / 2 - 1.5 * GAPSZ);
/* center snap */ /* center snap */
else if (e->keycode == ccode && (e->state & SHORTCUTMOD) == (MODBITS)) { else if (e->keycode == ccode && (e->state & SHORTCUTMOD) == (MODBITS)) {
@ -178,14 +254,12 @@ keypress(XKeyEvent *e)
stickystack(0); stickystack(0);
#endif #endif
/* launch */ /* launch */
if (e->keycode == slcode && (e->state & SHORTCUTMOD) == (MODBITS)) { if (e->keycode == slcode && (e->state & SHORTCUTMOD) == (MODBITS)) {
kbLaunch = 1; kbLaunch = 1;
if (fork() == 0) { if (fork() == 0) {
close(ConnectionNumber(dpy)); close(ConnectionNumber(dpy));
if(dpy != '\0') if (dpy != '\0') putenv(dpy);
putenv(dpy);
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL); signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL); signal(SIGHUP, SIG_DFL);
@ -220,16 +294,13 @@ keypress(XKeyEvent *e)
} }
void void
keyrelease(XKeyEvent *e) keyrelease(XKeyEvent* e) {
{
XAllowEvents(dpy, SyncKeyboard, e->time); XAllowEvents(dpy, SyncKeyboard, e->time);
} }
void void
quickreshape(Client *c, int x, int y, int dx, int dy) quickreshape(Client* c, int x, int y, int dx, int dy) {
{ if (c == 0) return;
if (c == 0)
return;
XMoveResizeWindow(dpy, c->parent, x, y, dx, dy); XMoveResizeWindow(dpy, c->parent, x, y, dx, dy);
c->x = x + BORDER; c->x = x + BORDER;
c->y = y + BORDER; c->y = y + BORDER;
@ -240,44 +311,46 @@ quickreshape(Client *c, int x, int y, int dx, int dy)
} }
void void
centercurrent(XWindowAttributes ra) centercurrent(XWindowAttributes ra) {
{ static int centeroffsetnum =
static int centeroffsetnum = CENTERNUM%2 == 0 ? CENTERNUM % 2 == 0 ? CENTERDEN - CENTERNUM : (CENTERDEN - CENTERNUM) / 2;
CENTERDEN - CENTERNUM :
(CENTERDEN - CENTERNUM)/2;
static int centeroffsetden = CENTERNUM%2 == 0 ? static int centeroffsetden = CENTERNUM % 2 == 0 ? CENTERDEN * 2 : CENTERDEN;
CENTERDEN*2 :
CENTERDEN;
#ifdef CENTERVMAX #ifdef CENTERVMAX
quickreshape(current, centeroffsetnum*ra.width/centeroffsetden, GAPSZ, CENTERNUM*ra.width/CENTERDEN, ra.height - 2*GAPSZ); quickreshape(
current,
centeroffsetnum * ra.width / centeroffsetden,
GAPSZ,
CENTERNUM * ra.width / CENTERDEN,
ra.height - 2 * GAPSZ);
#else #else
quickreshape(current, centeroffsetnum*ra.width/centerofsetden, centeroffsetnum*ra.height/centeroffsetden, CENTERNUM*ra.width/CENTERDEN, CENTERNUM*ra.height/CENTERDEN); quickreshape(
current,
centeroffsetnum * ra.width / centerofsetden,
centeroffsetnum * ra.height / centeroffsetden,
CENTERNUM * ra.width / CENTERDEN,
CENTERNUM * ra.height / CENTERDEN);
#endif #endif
} }
static void static void
alttab(int shift) alttab(int shift) {
{
shuffle(shift); shuffle(shift);
/* fprintf(stderr, "%sTab\n", shift ? "Back" : ""); */ /* fprintf(stderr, "%sTab\n", shift ? "Back" : ""); */
} }
#ifdef DEVEL #ifdef DEVEL
void void
stickystack(int toTop) stickystack(int toTop) {
{
Client* c; Client* c;
if (toTop) { if (toTop) {
for (c = clients; c->next; c = c->next) { for (c = clients; c->next; c = c->next) {
if(c && isautostick(c)) if (c && isautostick(c)) top(c);
top(c);
} }
} else { } else {
for (c = clients; c->next; c = c->next) { for (c = clients; c->next; c = c->next) {
if(c && !isautostick(c)) if (c && !isautostick(c)) top(c);
top(c);
} }
} }
} }

185
main.c Executable file → Normal file
View file

@ -17,10 +17,10 @@
#include "fns.h" #include "fns.h"
#include "patchlevel.h" #include "patchlevel.h"
char *version[] = char* version[] = {
{ "ryudo version 0.4\nCopyright (c) 1994-1996 David Hogan,\n(c) 2004 Russ "
"ryudo version 0.4\nCopyright (c) 1994-1996 David Hogan,\n(c) 2004 Russ Cox,\n(c) 2019-2021 Derek Stevens", 0 "Cox,\n(c) 2019-2021 Derek Stevens",
}; 0};
Display* dpy; Display* dpy;
ScreenInfo* screens; ScreenInfo* screens;
@ -61,15 +61,16 @@ Atom wm_state;
char* fontlist[] = FONTLIST; char* fontlist[] = FONTLIST;
void void
usage(void) usage(void) {
{ fprintf(
fprintf(stderr, "usage: ryudo [-ffm] [-font fname] [-s] [-term prog] [-version] [-virtuals num] [exit|restart]\n"); stderr,
"usage: ryudo [-ffm] [-font fname] [-s] [-term prog] [-version] [-virtuals "
"num] [exit|restart]\n");
exit(1); exit(1);
} }
int int
main(int argc, char *argv[]) main(int argc, char* argv[]) {
{
int i, do_exit, do_restart; int i, do_exit, do_restart;
char* fname; char* fname;
int shape_event; int shape_event;
@ -95,26 +96,23 @@ main(int argc, char *argv[])
else if (strcmp(argv[i], "-font") == 0 && i + 1 < argc) { else if (strcmp(argv[i], "-font") == 0 && i + 1 < argc) {
i++; i++;
fname = argv[i]; fname = argv[i];
} } else if (strcmp(argv[i], "-term") == 0 && i + 1 < argc)
else if(strcmp(argv[i], "-term") == 0 && i+1<argc)
termprog = argv[++i]; termprog = argv[++i];
else if (strcmp(argv[i], "-virtuals") == 0 && i + 1 < argc) { else if (strcmp(argv[i], "-virtuals") == 0 && i + 1 < argc) {
numvirtuals = atoi(argv[++i]); numvirtuals = atoi(argv[++i]);
if (numvirtuals < 0 || numvirtuals > 12) { if (numvirtuals < 0 || numvirtuals > 12) {
fprintf(stderr, "ryudo: wrong number of virtual displays, defaulting to 4\n"); fprintf(
stderr, "ryudo: wrong number of virtual displays, defaulting to 4\n");
numvirtuals = 4; numvirtuals = 4;
} }
} else if (strcmp(argv[i], "-version") == 0) { } else if (strcmp(argv[i], "-version") == 0) {
fprintf(stderr, "%s", version[0]); fprintf(stderr, "%s", version[0]);
if(PATCHLEVEL > 0) if (PATCHLEVEL > 0) fprintf(stderr, "; patch level %d", PATCHLEVEL);
fprintf(stderr, "; patch level %d", PATCHLEVEL);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
exit(0); exit(0);
} } else if (strcmp(argv[i], "-s") == 0) {
else if(strcmp(argv[i], "-s") == 0){
scrolling = 1; scrolling = 1;
} } else if (argv[i][0] == '-')
else if(argv[i][0] == '-')
usage(); usage();
else else
break; break;
@ -126,25 +124,19 @@ main(int argc, char *argv[])
else else
usage(); usage();
if(do_exit && do_restart) if (do_exit && do_restart) usage();
usage();
shell = (char*)getenv("SHELL"); shell = (char*)getenv("SHELL");
if(shell == NULL) if (shell == NULL) shell = DEFSHELL;
shell = DEFSHELL;
dpy = XOpenDisplay(""); dpy = XOpenDisplay("");
if(dpy == 0) if (dpy == 0) fatal("can't open display");
fatal("can't open display");
initting = 1; initting = 1;
XSetErrorHandler(handler); XSetErrorHandler(handler);
if(signal(SIGTERM, sighandler) == SIG_IGN) if (signal(SIGTERM, sighandler) == SIG_IGN) signal(SIGTERM, SIG_IGN);
signal(SIGTERM, SIG_IGN); if (signal(SIGINT, sighandler) == SIG_IGN) signal(SIGINT, SIG_IGN);
if(signal(SIGINT, sighandler) == SIG_IGN) if (signal(SIGHUP, sighandler) == SIG_IGN) signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN);
if(signal(SIGHUP, sighandler) == SIG_IGN)
signal(SIGHUP, SIG_IGN);
exit_rio = XInternAtom(dpy, "9WM_EXIT", False); exit_rio = XInternAtom(dpy, "9WM_EXIT", False);
restart_rio = XInternAtom(dpy, "9WM_RESTART", False); restart_rio = XInternAtom(dpy, "9WM_RESTART", False);
@ -188,8 +180,7 @@ main(int argc, char *argv[])
break; break;
} }
font = XLoadQueryFont(dpy, fname); font = XLoadQueryFont(dpy, fname);
if(font != 0) if (font != 0) break;
break;
} }
} }
if (nostalgia) { if (nostalgia) {
@ -204,8 +195,7 @@ main(int argc, char *argv[])
num_screens = ScreenCount(dpy); num_screens = ScreenCount(dpy);
screens = (ScreenInfo*)malloc(sizeof(ScreenInfo) * num_screens); screens = (ScreenInfo*)malloc(sizeof(ScreenInfo) * num_screens);
for(i = 0; i < num_screens; i++) for (i = 0; i < num_screens; i++) initscreen(&screens[i], i, 0);
initscreen(&screens[i], i, 0);
initb2menu(numvirtuals); initb2menu(numvirtuals);
@ -218,8 +208,7 @@ main(int argc, char *argv[])
nofocus(); nofocus();
for(i = 0; i < num_screens; i++) for (i = 0; i < num_screens; i++) scanwins(&screens[i]);
scanwins(&screens[i]);
keysetup(); keysetup();
mainloop(shape_event); mainloop(shape_event);
@ -227,8 +216,7 @@ main(int argc, char *argv[])
} }
void void
initscreen(ScreenInfo *s, int i, int background) initscreen(ScreenInfo* s, int i, int background) {
{
char *ds, *colon, *dot1; char *ds, *colon, *dot1;
unsigned long mask; unsigned long mask;
unsigned long gmask; unsigned long gmask;
@ -246,30 +234,27 @@ initscreen(ScreenInfo *s, int i, int background)
/* /*
* Figure out underlying screen format. * Figure out underlying screen format.
*/ */
if(XMatchVisualInfo(dpy, i, 16, TrueColor, &xvi) if (
|| XMatchVisualInfo(dpy, i, 16, DirectColor, &xvi)){ XMatchVisualInfo(dpy, i, 16, TrueColor, &xvi) ||
XMatchVisualInfo(dpy, i, 16, DirectColor, &xvi)) {
s->vis = xvi.visual; s->vis = xvi.visual;
s->depth = 16; s->depth = 16;
} } else if (
else XMatchVisualInfo(dpy, i, 15, TrueColor, &xvi) ||
if(XMatchVisualInfo(dpy, i, 15, TrueColor, &xvi) XMatchVisualInfo(dpy, i, 15, DirectColor, &xvi)) {
|| XMatchVisualInfo(dpy, i, 15, DirectColor, &xvi)){
s->vis = xvi.visual; s->vis = xvi.visual;
s->depth = 15; s->depth = 15;
} } else if (
else XMatchVisualInfo(dpy, i, 24, TrueColor, &xvi) ||
if(XMatchVisualInfo(dpy, i, 24, TrueColor, &xvi) XMatchVisualInfo(dpy, i, 24, DirectColor, &xvi)) {
|| XMatchVisualInfo(dpy, i, 24, DirectColor, &xvi)){
s->vis = xvi.visual; s->vis = xvi.visual;
s->depth = 24; s->depth = 24;
} } else if (
else XMatchVisualInfo(dpy, i, 8, PseudoColor, &xvi) ||
if(XMatchVisualInfo(dpy, i, 8, PseudoColor, &xvi) XMatchVisualInfo(dpy, i, 8, StaticColor, &xvi)) {
|| XMatchVisualInfo(dpy, i, 8, StaticColor, &xvi)){
s->vis = xvi.visual; s->vis = xvi.visual;
s->depth = 8; s->depth = 8;
} } else {
else{
s->depth = DefaultDepth(dpy, i); s->depth = DefaultDepth(dpy, i);
if (s->depth != 8) { if (s->depth != 8) {
fprintf(stderr, "can't understand depth %d screen", s->depth); fprintf(stderr, "can't understand depth %d screen", s->depth);
@ -288,11 +273,9 @@ initscreen(ScreenInfo *s, int i, int background)
strcat(s->display, ds); strcat(s->display, ds);
colon = s->display + 8 + (colon - ds); /* use version in buf */ colon = s->display + 8 + (colon - ds); /* use version in buf */
dot1 = index(colon, '.'); /* first period after colon */ dot1 = index(colon, '.'); /* first period after colon */
if(!dot1) if (!dot1) dot1 = colon + strlen(colon); /* if not there, append */
dot1 = colon + strlen(colon); /* if not there, append */
sprintf(dot1, ".%d", i); sprintf(dot1, ".%d", i);
} } else
else
s->display[0] = '\0'; s->display[0] = '\0';
s->black = BlackPixel(dpy, i); s->black = BlackPixel(dpy, i);
@ -304,16 +287,18 @@ initscreen(ScreenInfo *s, int i, int background)
s->red = colorpixel(dpy, s, s->depth, GHOSTCOL, s->white); s->red = colorpixel(dpy, s, s->depth, GHOSTCOL, s->white);
s->width = WidthOfScreen(ScreenOfDisplay(dpy, i)); s->width = WidthOfScreen(ScreenOfDisplay(dpy, i));
s->height = HeightOfScreen(ScreenOfDisplay(dpy, i)); s->height = HeightOfScreen(ScreenOfDisplay(dpy, i));
s->bkup[0] = XCreatePixmap(dpy, s->root, 2*s->width, BORDER, DefaultDepth(dpy, i)); s->bkup[0] =
s->bkup[1] = XCreatePixmap(dpy, s->root, BORDER, 2*s->height, DefaultDepth(dpy, i)); XCreatePixmap(dpy, s->root, 2 * s->width, BORDER, DefaultDepth(dpy, i));
s->bkup[1] =
XCreatePixmap(dpy, s->root, BORDER, 2 * s->height, DefaultDepth(dpy, i));
gv.foreground = s->black ^ s->white; gv.foreground = s->black ^ s->white;
gv.background = s->white; gv.background = s->white;
gv.function = GXxor; gv.function = GXxor;
gv.line_width = 0; gv.line_width = 0;
gv.subwindow_mode = IncludeInferiors; gv.subwindow_mode = IncludeInferiors;
gmask = GCForeground | GCBackground | GCFunction | GCLineWidth gmask =
| GCSubwindowMode; GCForeground | GCBackground | GCFunction | GCLineWidth | GCSubwindowMode;
if (font != 0) { if (font != 0) {
gv.font = font->fid; gv.font = font->fid;
gmask |= GCFont; gmask |= GCFont;
@ -332,10 +317,9 @@ initscreen(ScreenInfo *s, int i, int background)
initcurs(s); initcurs(s);
attr.cursor = s->arrow; attr.cursor = s->arrow;
attr.event_mask = SubstructureRedirectMask attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
| SubstructureNotifyMask | ColormapChangeMask ColormapChangeMask | ButtonPressMask | ButtonReleaseMask |
| ButtonPressMask | ButtonReleaseMask | PropertyChangeMask PropertyChangeMask | KeyPressMask | EnterWindowMask;
| KeyPressMask | EnterWindowMask;
mask = CWCursor | CWEventMask; mask = CWCursor | CWEventMask;
XChangeWindowAttributes(dpy, s->root, mask, &attr); XChangeWindowAttributes(dpy, s->root, mask, &attr);
XSync(dpy, False); XSync(dpy, False);
@ -344,14 +328,19 @@ initscreen(ScreenInfo *s, int i, int background)
attrs.background_pixel = colorpixel(dpy, s, s->depth, MENUBGCOL, s->white); attrs.background_pixel = colorpixel(dpy, s, s->depth, MENUBGCOL, s->white);
attrs.colormap = s->def_cmap; attrs.colormap = s->def_cmap;
s->menuwin = XCreateWindow(dpy, s->root, 0, 0, 1, 1, MENUBORDER, s->menuwin = XCreateWindow(
dpy,
s->root,
0,
0,
1,
1,
MENUBORDER,
s->depth, s->depth,
CopyFromParent, CopyFromParent,
s->vis, s->vis,
CWBackPixel | CWBorderPixel | CWColormap, CWBackPixel | CWBorderPixel | CWColormap,
&attrs &attrs);
);
gv.foreground = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black); gv.foreground = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black);
s->gcmenubg = XCreateGC(dpy, s->menuwin, gmask, &gv); s->gcmenubg = XCreateGC(dpy, s->menuwin, gmask, &gv);
@ -370,35 +359,45 @@ initscreen(ScreenInfo *s, int i, int background)
attrs.border_pixel = s->red; attrs.border_pixel = s->red;
attrs.background_pixel = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black); attrs.background_pixel = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black);
attrs.colormap = s->def_cmap; attrs.colormap = s->def_cmap;
s->sweepwin = XCreateWindow(dpy, s->root, 0, 0, 1, 1, 4, s->sweepwin = XCreateWindow(
dpy,
s->root,
0,
0,
1,
1,
4,
s->depth, s->depth,
CopyFromParent, CopyFromParent,
s->vis, s->vis,
CWBackPixel | CWBorderPixel | CWColormap, CWBackPixel | CWBorderPixel | CWColormap,
&attrs &attrs);
);
} }
ScreenInfo* ScreenInfo*
getscreen(Window w) getscreen(Window w) {
{
int i; int i;
for (i = 0; i < num_screens; i++) for (i = 0; i < num_screens; i++)
if(screens[i].root == w) if (screens[i].root == w) return &screens[i];
return &screens[i];
return 0; return 0;
} }
Time Time
timestamp(void) timestamp(void) {
{
XEvent ev; XEvent ev;
if (curtime == CurrentTime) { if (curtime == CurrentTime) {
XChangeProperty(dpy, screens[0].root, _rio_running, _rio_running, 8, XChangeProperty(
PropModeAppend, (unsigned char *)"", 0); dpy,
screens[0].root,
_rio_running,
_rio_running,
8,
PropModeAppend,
(unsigned char*)"",
0);
XMaskEvent(dpy, PropertyChangeMask, &ev); XMaskEvent(dpy, PropertyChangeMask, &ev);
curtime = ev.xproperty.time; curtime = ev.xproperty.time;
} }
@ -406,8 +405,7 @@ timestamp(void)
} }
void void
sendcmessage(Window w, Atom a, long x, int isroot, int usemask) sendcmessage(Window w, Atom a, long x, int isroot, int usemask) {
{
XEvent ev; XEvent ev;
int status; int status;
long mask; long mask;
@ -428,13 +426,11 @@ sendcmessage(Window w, Atom a, long x, int isroot, int usemask)
mask |= ExposureMask; /* not really correct but so be it */ mask |= ExposureMask; /* not really correct but so be it */
} }
status = XSendEvent(dpy, w, False, mask, &ev); status = XSendEvent(dpy, w, False, mask, &ev);
if(status == 0) if (status == 0) fprintf(stderr, "ryudo: sendcmessage failed\n");
fprintf(stderr, "ryudo: sendcmessage failed\n");
} }
void void
sendconfig(Client *c) sendconfig(Client* c) {
{
XConfigureEvent ce; XConfigureEvent ce;
ce.type = ConfigureNotify; ce.type = ConfigureNotify;
@ -451,14 +447,12 @@ sendconfig(Client *c)
} }
void void
sighandler(void) sighandler(void) {
{
signalled = 1; signalled = 1;
} }
void void
getevent(XEvent *e) getevent(XEvent* e) {
{
int fd; int fd;
fd_set rfds; fd_set rfds;
struct timeval t; struct timeval t;
@ -493,8 +487,7 @@ getevent(XEvent *e)
} }
void void
cleanup(void) cleanup(void) {
{
Client *c, *cc[2], *next; Client *c, *cc[2], *next;
XWindowChanges wc; XWindowChanges wc;
int i; int i;
@ -511,8 +504,7 @@ cleanup(void)
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
for (c = cc[i]; c; c = c->next) { for (c = cc[i]; c; c = c->next) {
if (!withdrawn(c)) { if (!withdrawn(c)) {
XReparentWindow(dpy, c->window, c->screen->root, XReparentWindow(dpy, c->window, c->screen->root, c->x, c->y);
c->x, c->y);
} }
wc.border_width = c->border; wc.border_width = c->border;
XConfigureWindow(dpy, c->window, CWBorderWidth, &wc); XConfigureWindow(dpy, c->window, CWBorderWidth, &wc);
@ -520,7 +512,6 @@ cleanup(void)
} }
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, timestamp()); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, timestamp());
for(i = 0; i < num_screens; i++) for (i = 0; i < num_screens; i++) cmapnofocus(&screens[i]);
cmapnofocus(&screens[i]);
XCloseDisplay(dpy); XCloseDisplay(dpy);
} }

245
manage.c Executable file → Normal file
View file

@ -23,20 +23,22 @@
int isNew; int isNew;
int int
manage(Client *c, int mapped) manage(Client* c, int mapped) {
{
int fixsize, dohide, doreshape, state; int fixsize, dohide, doreshape, state;
long msize; long msize;
XClassHint class; XClassHint class;
XWMHints* hints; XWMHints* hints;
XSetWindowAttributes attrs; XSetWindowAttributes attrs;
static XWindowAttributes ra; static XWindowAttributes ra;
XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra); XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra);
trace("manage", c, 0); trace("manage", c, 0);
XSelectInput(dpy, c->window, ColormapChangeMask | EnterWindowMask | PropertyChangeMask | FocusChangeMask | KeyPressMask); XSelectInput(
dpy,
c->window,
ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
FocusChangeMask | KeyPressMask);
/* Get loads of hints */ /* Get loads of hints */
@ -45,14 +47,13 @@ manage(Client *c, int mapped)
c->class = class.res_class; c->class = class.res_class;
c->is9term = 0; c->is9term = 0;
if (isNew) { if (isNew) {
c->is9term = strstr(c->class, "term") || strstr(c->class, "Term") c->is9term = strstr(c->class, "term") || strstr(c->class, "Term") ||
|| strstr(c->class, "urxvt") || strstr(c->class, "URxvt") strstr(c->class, "urxvt") || strstr(c->class, "URxvt") ||
|| strstr(c->class, "onsole") || strstr(c->class, "Alacritty"); strstr(c->class, "onsole") || strstr(c->class, "Alacritty");
isNew = 0; isNew = 0;
} }
printf("%s: is9term = %d", c->class, c->is9term); printf("%s: is9term = %d", c->class, c->is9term);
} } else {
else {
c->instance = 0; c->instance = 0;
c->class = 0; c->class = 0;
c->is9term = 0; c->is9term = 0;
@ -62,14 +63,15 @@ manage(Client *c, int mapped)
setlabel(c); setlabel(c);
hints = XGetWMHints(dpy, c->window); hints = XGetWMHints(dpy, c->window);
if(XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0) if (
XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 ||
c->size.flags == 0)
c->size.flags = PSize; /* not specified - punt */ c->size.flags = PSize; /* not specified - punt */
getcmaps(c); getcmaps(c);
getproto(c); getproto(c);
gettrans(c); gettrans(c);
if(c->is9term) if (c->is9term) c->hold = getiprop(c->window, _rio_hold_mode);
c->hold = getiprop(c->window, _rio_hold_mode);
/* Figure out what to do with the window from hints */ /* Figure out what to do with the window from hints */
@ -78,46 +80,50 @@ manage(Client *c, int mapped)
dohide = (state == IconicState); dohide = (state == IconicState);
fixsize = 0; fixsize = 0;
if((c->size.flags & (USSize|PSize))) if ((c->size.flags & (USSize | PSize))) fixsize = 1;
fixsize = 1; if (
if((c->size.flags & (PMinSize|PMaxSize)) == (PMinSize|PMaxSize) && c->size.min_width == c->size.max_width && c->size.min_height == c->size.max_height) (c->size.flags & (PMinSize | PMaxSize)) == (PMinSize | PMaxSize) &&
c->size.min_width == c->size.max_width &&
c->size.min_height == c->size.max_height)
fixsize = 1; fixsize = 1;
doreshape = !mapped; doreshape = !mapped;
if (fixsize) { if (fixsize) {
if(c->size.flags & USPosition) if (c->size.flags & USPosition) doreshape = 0;
doreshape = 0; if (dohide && (c->size.flags & PPosition)) doreshape = 0;
if(dohide && (c->size.flags & PPosition)) if (c->trans != None) doreshape = 0;
doreshape = 0;
if(c->trans != None)
doreshape = 0;
} }
if(c->is9term) if (c->is9term) fixsize = 0;
fixsize = 0;
if (c->size.flags & PBaseSize) { if (c->size.flags & PBaseSize) {
c->min_dx = c->size.base_width; c->min_dx = c->size.base_width;
c->min_dy = c->size.base_height; c->min_dy = c->size.base_height;
} } else if (c->size.flags & PMinSize) {
else if(c->size.flags & PMinSize){
c->min_dx = c->size.min_width; c->min_dx = c->size.min_width;
c->min_dy = c->size.min_height; c->min_dy = c->size.min_height;
} } else if (c->is9term) {
else if(c->is9term){
c->min_dx = 100; c->min_dx = 100;
c->min_dy = 50; c->min_dy = 50;
} } else
else
c->min_dx = c->min_dy = 0; c->min_dx = c->min_dy = 0;
if(hints) if (hints) XFree(hints);
XFree(hints);
/* Now do it!!! */ /* Now do it!!! */
if (doreshape) { if (doreshape) {
if(0) fprintf(stderr, "in doreshape is9term=%d fixsize=%d, x=%d, y=%d, min_dx=%d, min_dy=%d, dx=%d, dy=%d\n", if (0)
c->is9term, fixsize, c->x, c->y, c->min_dx, c->min_dy, c->dx, c->dy); fprintf(
if(current && current->screen == c->screen) stderr,
cmapnofocus(c->screen); "in doreshape is9term=%d fixsize=%d, x=%d, y=%d, min_dx=%d, min_dy=%d, "
"dx=%d, dy=%d\n",
c->is9term,
fixsize,
c->x,
c->y,
c->min_dx,
c->min_dy,
c->dx,
c->dy);
if (current && current->screen == c->screen) cmapnofocus(c->screen);
if (!c->is9term && c->x == 0 && c->y == 0) { if (!c->is9term && c->x == 0 && c->y == 0) {
static int nwin; static int nwin;
@ -130,8 +136,7 @@ manage(Client *c, int mapped)
if (c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))) { if (c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))) {
XKillClient(dpy, c->window); XKillClient(dpy, c->window);
rmclient(c); rmclient(c);
if(current && current->screen == c->screen) if (current && current->screen == c->screen) cmapfocus(current);
cmapfocus(current);
return 0; return 0;
} }
} }
@ -139,9 +144,13 @@ manage(Client *c, int mapped)
attrs.border_pixel = c->screen->black; attrs.border_pixel = c->screen->black;
attrs.background_pixel = c->screen->white; attrs.background_pixel = c->screen->white;
attrs.colormap = c->screen->def_cmap; attrs.colormap = c->screen->def_cmap;
c->parent = XCreateWindow(dpy, c->screen->root, c->parent = XCreateWindow(
c->x - BORDER, c->y - BORDER, dpy,
c->dx + 2*BORDER, c->dy + 2*BORDER, c->screen->root,
c->x - BORDER,
c->y - BORDER,
c->dx + 2 * BORDER,
c->dy + 2 * BORDER,
0, 0,
c->screen->depth, c->screen->depth,
CopyFromParent, CopyFromParent,
@ -149,11 +158,13 @@ manage(Client *c, int mapped)
CWBackPixel | CWBorderPixel | CWColormap, CWBackPixel | CWBorderPixel | CWColormap,
&attrs); &attrs);
XSelectInput(dpy, c->parent, SubstructureRedirectMask | SubstructureNotifyMask|ButtonPressMask| PointerMotionMask|LeaveWindowMask|KeyPressMask); XSelectInput(
if(mapped) dpy,
c->reparenting = 1; c->parent,
if(doreshape && !fixsize) SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask |
XResizeWindow(dpy, c->window, c->dx, c->dy); PointerMotionMask | LeaveWindowMask | KeyPressMask);
if (mapped) c->reparenting = 1;
if (doreshape && !fixsize) XResizeWindow(dpy, c->window, c->dx, c->dy);
XSetWindowBorderWidth(dpy, c->window, 0); XSetWindowBorderWidth(dpy, c->window, 0);
/* /*
@ -164,9 +175,7 @@ manage(Client *c, int mapped)
* (black (or white) border around black (or white) window * (black (or white) border around black (or white) window
* is not very helpful. * is not very helpful.
*/ */
if(c->screen->depth <= 8){ if (c->screen->depth <= 8) { XSetWindowBorderWidth(dpy, c->parent, 1); }
XSetWindowBorderWidth(dpy, c->parent, 1);
}
XReparentWindow(dpy, c->window, c->parent, BORDER, BORDER); XReparentWindow(dpy, c->window, c->parent, BORDER, BORDER);
#ifdef SHAPE #ifdef SHAPE
@ -194,8 +203,7 @@ manage(Client *c, int mapped)
setactive(c, 0); setactive(c, 0);
setstate(c, NormalState); setstate(c, NormalState);
} }
if(current && (current != c)) if (current && (current != c)) cmapfocus(current);
cmapfocus(current);
c->init = 1; c->init = 1;
/* If the window is out of bounds of the screen, try to wrangle it */ /* If the window is out of bounds of the screen, try to wrangle it */
@ -203,9 +211,11 @@ manage(Client *c, int mapped)
/* If it's bigger than the screen, try to set it maximized */ /* If it's bigger than the screen, try to set it maximized */
if (c->dx >= ra.width || c->dy >= ra.width) { if (c->dx >= ra.width || c->dy >= ra.width) {
if (c->dx >= ra.width) if (c->dx >= ra.width)
quickreshape(c, -BORDER, c->y - BORDER, ra.width + 2*BORDER, c->dy + 2*BORDER); quickreshape(
c, -BORDER, c->y - BORDER, ra.width + 2 * BORDER, c->dy + 2 * BORDER);
if (c->dy >= ra.height) if (c->dy >= ra.height)
quickreshape(c, c->x - BORDER, -BORDER, c->dx + 2*BORDER, ra.height + 2*BORDER); quickreshape(
c, c->x - BORDER, -BORDER, c->dx + 2 * BORDER, ra.height + 2 * BORDER);
/* and if it's got an edge out of bounds, nudge it into bounds */ /* and if it's got an edge out of bounds, nudge it into bounds */
} else { } else {
@ -216,10 +226,20 @@ manage(Client *c, int mapped)
quickreshape(c, c->x - BORDER, 0, c->dx + 2 * BORDER, c->dy + 2 * BORDER); quickreshape(c, c->x - BORDER, 0, c->dx + 2 * BORDER, c->dy + 2 * BORDER);
} }
if (c->x + c->dx + BORDER > ra.width) { if (c->x + c->dx + BORDER > ra.width) {
quickreshape(c, ra.width - (c->dx + 2*BORDER), c->y - BORDER, c->dx + 2*BORDER, c->dy + 2*BORDER); quickreshape(
c,
ra.width - (c->dx + 2 * BORDER),
c->y - BORDER,
c->dx + 2 * BORDER,
c->dy + 2 * BORDER);
} }
if (c->y + c->dy + BORDER > ra.height) { if (c->y + c->dy + BORDER > ra.height) {
quickreshape(c, c->x - BORDER, ra.height - (c->dy + 2*BORDER), c->dx + 2*BORDER, c->dy + 2*BORDER); quickreshape(
c,
c->x - BORDER,
ra.height - (c->dy + 2 * BORDER),
c->dx + 2 * BORDER,
c->dy + 2 * BORDER);
} }
} }
@ -230,14 +250,12 @@ manage(Client *c, int mapped)
* I can't find a way to have them notice during initdraw, so * I can't find a way to have them notice during initdraw, so
* I solve the problem this way instead. -rsc * I solve the problem this way instead. -rsc
*/ */
if(c->is9term) if (c->is9term) sendconfig(c);
sendconfig(c);
return 1; return 1;
} }
void void
scanwins(ScreenInfo *s) scanwins(ScreenInfo* s) {
{
unsigned int i, nwins; unsigned int i, nwins;
Client* c; Client* c;
Window dw1, dw2, *wins; Window dw1, dw2, *wins;
@ -246,8 +264,7 @@ scanwins(ScreenInfo *s)
XQueryTree(dpy, s->root, &dw1, &dw2, &wins, &nwins); XQueryTree(dpy, s->root, &dw1, &dw2, &wins, &nwins);
for (i = 0; i < nwins; i++) { for (i = 0; i < nwins; i++) {
XGetWindowAttributes(dpy, wins[i], &attr); XGetWindowAttributes(dpy, wins[i], &attr);
if(attr.override_redirect || wins[i] == s->menuwin) if (attr.override_redirect || wins[i] == s->menuwin) continue;
continue;
c = getclient(wins[i], 1); c = getclient(wins[i], 1);
if (c != 0 && c->window == wins[i] && !c->init) { if (c != 0 && c->window == wins[i] && !c->init) {
c->x = attr.x; c->x = attr.x;
@ -257,16 +274,14 @@ scanwins(ScreenInfo *s)
c->border = attr.border_width; c->border = attr.border_width;
c->screen = s; c->screen = s;
c->parent = s->root; c->parent = s->root;
if(attr.map_state == IsViewable) if (attr.map_state == IsViewable) manage(c, 1);
manage(c, 1);
} }
} }
XFree((void*)wins); /* cast is to shut stoopid compiler up */ XFree((void*)wins); /* cast is to shut stoopid compiler up */
} }
void void
gettrans(Client *c) gettrans(Client* c) {
{
Window trans; Window trans;
trans = None; trans = None;
@ -277,8 +292,7 @@ gettrans(Client *c)
} }
void void
withdraw(Client *c) withdraw(Client* c) {
{
XUnmapWindow(dpy, c->parent); XUnmapWindow(dpy, c->parent);
XReparentWindow(dpy, c->window, c->screen->root, c->x, c->y); XReparentWindow(dpy, c->window, c->screen->root, c->x, c->y);
XRemoveFromSaveSet(dpy, c->window); XRemoveFromSaveSet(dpy, c->window);
@ -291,8 +305,7 @@ withdraw(Client *c)
} }
static void static void
installcmap(ScreenInfo *s, Colormap cmap) installcmap(ScreenInfo* s, Colormap cmap) {
{
if (cmap == None) if (cmap == None)
XInstallColormap(dpy, s->def_cmap); XInstallColormap(dpy, s->def_cmap);
else else
@ -300,8 +313,7 @@ installcmap(ScreenInfo *s, Colormap cmap)
} }
void void
cmapfocus(Client *c) cmapfocus(Client* c) {
{
int i, found; int i, found;
Client* cc; Client* cc;
@ -311,27 +323,24 @@ cmapfocus(Client *c)
found = 0; found = 0;
for (i = c->ncmapwins - 1; i >= 0; i--) { for (i = c->ncmapwins - 1; i >= 0; i--) {
installcmap(c->screen, c->wmcmaps[i]); installcmap(c->screen, c->wmcmaps[i]);
if(c->cmapwins[i] == c->window) if (c->cmapwins[i] == c->window) found++;
found++;
} }
if(!found) if (!found) installcmap(c->screen, c->cmap);
installcmap(c->screen, c->cmap); } else if (
} c->trans != None && (cc = getclient(c->trans, 0)) != 0 &&
else if(c->trans != None && (cc = getclient(c->trans, 0)) != 0 && cc->ncmapwins != 0) cc->ncmapwins != 0)
cmapfocus(cc); cmapfocus(cc);
else else
installcmap(c->screen, c->cmap); installcmap(c->screen, c->cmap);
} }
void void
cmapnofocus(ScreenInfo *s) cmapnofocus(ScreenInfo* s) {
{
installcmap(s, None); installcmap(s, None);
} }
void void
getcmaps(Client *c) getcmaps(Client* c) {
{
int n, i; int n, i;
Window* cw; Window* cw;
XWindowAttributes attr; XWindowAttributes attr;
@ -374,8 +383,7 @@ getcmaps(Client *c)
} }
void void
setlabel(Client *c) setlabel(Client* c) {
{
char *label, *p, *lc; char *label, *p, *lc;
int i; int i;
@ -389,8 +397,7 @@ setlabel(Client *c)
label = c->class; label = c->class;
else else
label = "no label"; label = "no label";
if((p = index(label, ':')) != 0) if ((p = index(label, ':')) != 0) *p = '\0';
*p = '\0';
for (i = 0, lc = label; *lc != '\0'; lc++, i++) { for (i = 0, lc = label; *lc != '\0'; lc++, i++) {
if (i >= 23) { if (i >= 23) {
label[22] = '~'; label[22] = '~';
@ -403,91 +410,93 @@ setlabel(Client *c)
#ifdef SHAPE #ifdef SHAPE
void void
setshape(Client *c) setshape(Client* c) {
{
int n, order; int n, order;
XRectangle* rect; XRectangle* rect;
/* don't try to add a border if the window is non-rectangular */ /* don't try to add a border if the window is non-rectangular */
rect = XShapeGetRectangles(dpy, c->window, ShapeBounding, &n, &order); rect = XShapeGetRectangles(dpy, c->window, ShapeBounding, &n, &order);
if (n > 1) if (n > 1)
XShapeCombineShape(dpy, c->parent, ShapeBounding, BORDER, BORDER, XShapeCombineShape(
c->window, ShapeBounding, ShapeSet); dpy,
c->parent,
ShapeBounding,
BORDER,
BORDER,
c->window,
ShapeBounding,
ShapeSet);
XFree((void*)rect); XFree((void*)rect);
} }
#endif #endif
int int
_getprop(Window w, Atom a, Atom type, long len, unsigned char **p) _getprop(Window w, Atom a, Atom type, long len, unsigned char** p) {
{
Atom real_type; Atom real_type;
int format; int format;
unsigned long n, extra; unsigned long n, extra;
int status; int status;
status = XGetWindowProperty(dpy, w, a, 0L, len, False, type, &real_type, &format, &n, &extra, p); status = XGetWindowProperty(
if(status != Success || *p == 0) dpy, w, a, 0L, len, False, type, &real_type, &format, &n, &extra, p);
return -1; if (status != Success || *p == 0) return -1;
if(n == 0) if (n == 0) XFree((void*)*p);
XFree((void*) *p);
/* could check real_type, format, extra here... */ /* could check real_type, format, extra here... */
return n; return n;
} }
char* char*
getprop(Window w, Atom a) getprop(Window w, Atom a) {
{
unsigned char* p; unsigned char* p;
if(_getprop(w, a, XA_STRING, 100L, &p) <= 0) if (_getprop(w, a, XA_STRING, 100L, &p) <= 0) return 0;
return 0;
return (char*)p; return (char*)p;
} }
int int
get1prop(Window w, Atom a, Atom type) get1prop(Window w, Atom a, Atom type) {
{
char **p, *x; char **p, *x;
if(_getprop(w, a, type, 1L, (void*)&p) <= 0) if (_getprop(w, a, type, 1L, (void*)&p) <= 0) return 0;
return 0;
x = *p; x = *p;
XFree((void*)p); XFree((void*)p);
return (int)(uintptr_t)x; return (int)(uintptr_t)x;
} }
Window Window
getwprop(Window w, Atom a) getwprop(Window w, Atom a) {
{
return get1prop(w, a, XA_WINDOW); return get1prop(w, a, XA_WINDOW);
} }
int int
getiprop(Window w, Atom a) getiprop(Window w, Atom a) {
{
return get1prop(w, a, XA_INTEGER); return get1prop(w, a, XA_INTEGER);
} }
void void
setstate(Client *c, int state) setstate(Client* c, int state) {
{
long data[2]; long data[2];
data[0] = (long)state; data[0] = (long)state;
data[1] = (long)None; data[1] = (long)None;
c->state = state; c->state = state;
XChangeProperty(dpy, c->window, wm_state, wm_state, 32, XChangeProperty(
PropModeReplace, (unsigned char *)data, 2); dpy,
c->window,
wm_state,
wm_state,
32,
PropModeReplace,
(unsigned char*)data,
2);
} }
int int
getstate(Window w, int *state) getstate(Window w, int* state) {
{
long* p = 0; long* p = 0;
if(_getprop(w, wm_state, wm_state, 2L, (void*)&p) <= 0) if (_getprop(w, wm_state, wm_state, 2L, (void*)&p) <= 0) return 0;
return 0;
*state = (int)*p; *state = (int)*p;
XFree((char*)p); XFree((char*)p);
@ -495,8 +504,7 @@ getstate(Window w, int *state)
} }
void void
getproto(Client *c) getproto(Client* c) {
{
Atom* p; Atom* p;
int i; int i;
long n; long n;
@ -504,8 +512,7 @@ getproto(Client *c)
w = c->window; w = c->window;
c->proto = 0; c->proto = 0;
if((n = _getprop(w, wm_protocols, XA_ATOM, 20L, (void*)&p)) <= 0) if ((n = _getprop(w, wm_protocols, XA_ATOM, 20L, (void*)&p)) <= 0) return;
return;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
if (p[i] == wm_delete) if (p[i] == wm_delete)

264
menu.c Executable file → Normal file
View file

@ -25,13 +25,9 @@ int numhidden;
int virt; int virt;
int reversehide = 1; int reversehide = 1;
Client * currents[NUMVIRTUALS] = Client* currents[NUMVIRTUALS] = {NULL, NULL, NULL, NULL};
{
NULL, NULL, NULL, NULL
};
char *b2items[NUMVIRTUALS+1] = char* b2items[NUMVIRTUALS + 1] = {
{
"One", "One",
"Two", "Two",
"Three", "Three",
@ -44,16 +40,11 @@ char *b2items[NUMVIRTUALS+1] =
"Ten", "Ten",
"Eleven", "Eleven",
"Twelve", "Twelve",
0 0};
};
Menu b2menu = Menu b2menu = {b2items};
{
b2items
};
char *b3items[B3FIXED+MAXHIDDEN+1] = char* b3items[B3FIXED + MAXHIDDEN + 1] = {
{
"New", "New",
"Reshape", "Reshape",
"Move", "Move",
@ -62,11 +53,9 @@ char *b3items[B3FIXED+MAXHIDDEN+1] =
#ifdef SHOWSTICK #ifdef SHOWSTICK
"Stick", "Stick",
#endif #endif
0 0};
};
enum enum {
{
New, New,
Reshape, Reshape,
Move, Move,
@ -79,19 +68,12 @@ enum
#endif #endif
}; };
Menu b3menu = Menu b3menu = {b3items};
{
b3items
};
Menu egg = Menu egg = {version};
{
version
};
void void
button(XButtonEvent *e) button(XButtonEvent* e) {
{
int n, shift; int n, shift;
Client* c; Client* c;
Window dw; Window dw;
@ -99,39 +81,40 @@ button(XButtonEvent *e)
curtime = e->time; curtime = e->time;
s = getscreen(e->root); s = getscreen(e->root);
if(s == 0) if (s == 0) return;
return;
c = getclient(e->window, 0); c = getclient(e->window, 0);
if (c) { if (c) {
if(debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n", if (debug)
e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER); fprintf(
stderr,
"but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n",
e->x,
e->y,
c->x,
c->y,
c->dx,
c->dy,
BORDER);
if (borderorient(c, e->x, e->y) != BorderUnknown) { if (borderorient(c, e->x, e->y) != BorderUnknown) {
switch (e->button) { switch (e->button) {
case Button1: case Button1:
case Button2: case Button2: reshape(c, e->button, pull, e); return;
reshape(c, e->button, pull, e); case Button3: move(c, Button3); return;
return; default: return;
case Button3:
move(c, Button3);
return;
default:
return;
} }
} }
e->x += c->x - BORDER; e->x += c->x - BORDER;
e->y += c->y - BORDER; e->y += c->y - BORDER;
} else if (e->window != e->root) { } else if (e->window != e->root) {
if(debug) fprintf(stderr, "but no client: e x=%d y=%d\n", if (debug) fprintf(stderr, "but no client: e x=%d y=%d\n", e->x, e->y);
e->x, e->y); XTranslateCoordinates(
XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y, dpy, e->window, s->root, e->x, e->y, &e->x, &e->y, &dw);
&e->x, &e->y, &dw);
} }
switch (e->button) { switch (e->button) {
case Button1: case Button1:
fflush(stdout); fflush(stdout);
if (c) { if (c) {
if (ffm) if (ffm) XRaiseWindow(dpy, c->window);
XRaiseWindow(dpy, c->window);
XMapRaised(dpy, c->parent); XMapRaised(dpy, c->parent);
top(c); top(c);
active(c); active(c);
@ -142,67 +125,48 @@ button(XButtonEvent *e)
XMapRaised(dpy, c->parent); XMapRaised(dpy, c->parent);
active(c); active(c);
XAllowEvents(dpy, ReplayPointer, curtime); XAllowEvents(dpy, ReplayPointer, curtime);
} else if((e->state&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)){ } else if (
(e->state & (ShiftMask | ControlMask)) == (ShiftMask | ControlMask)) {
menuhit(e, &egg); menuhit(e, &egg);
} else if (numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1) } else if (numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1)
button2(n); button2(n);
return; return;
case Button3: case Button3: break;
break;
case Button4: case Button4:
/* scroll up changes to previous virtual screen */ /* scroll up changes to previous virtual screen */
if (!c && e->type == ButtonPress) if (!c && e->type == ButtonPress)
if(numvirtuals > 1 && virt > 0) if (numvirtuals > 1 && virt > 0) switch_to(virt - 1);
switch_to(virt - 1);
return; return;
case Button5: case Button5:
/* scroll down changes to next virtual screen */ /* scroll down changes to next virtual screen */
if (!c && e->type == ButtonPress) if (!c && e->type == ButtonPress)
if(numvirtuals > 1 && virt < numvirtuals - 1) if (numvirtuals > 1 && virt < numvirtuals - 1) switch_to(virt + 1);
switch_to(virt + 1);
return;
default:
return; return;
default: return;
} }
if(current && current->screen == s) if (current && current->screen == s) cmapnofocus(s);
cmapnofocus(s);
switch (n = menuhit(e, &b3menu)) { switch (n = menuhit(e, &b3menu)) {
case New: case New: spawn(s); break;
spawn(s); case Reshape: reshape(selectwin(1, 0, s), Button3, sweep, 0); break;
break; case Move: move(selectwin(0, 0, s), Button3); break;
case Reshape:
reshape(selectwin(1, 0, s), Button3, sweep, 0);
break;
case Move:
move(selectwin(0, 0, s), Button3);
break;
case Delete: case Delete:
shift = 0; shift = 0;
c = selectwin(1, &shift, s); c = selectwin(1, &shift, s);
delete (c, shift); delete (c, shift);
break; break;
case Hide: case Hide: hide(selectwin(1, 0, s)); break;
hide(selectwin(1, 0, s));
break;
#ifdef SHOWSTICK #ifdef SHOWSTICK
case Stick: case Stick: stick(selectwin(1, 0, s)); break;
stick(selectwin(1, 0, s));
break;
#endif #endif
default: /* unhide window */ default: /* unhide window */ unhide(n - B3FIXED, 1); break;
unhide(n - B3FIXED, 1); case -1: /* nothing */ break;
break;
case -1: /* nothing */
break;
} }
if(current && current->screen == s) if (current && current->screen == s) cmapfocus(current);
cmapfocus(current);
} }
void void
spawn(ScreenInfo *s) spawn(ScreenInfo* s) {
{
/* /*
* ugly dance to cause sweeping for terminals. * ugly dance to cause sweeping for terminals.
* the very next window created will require sweeping. * the very next window created will require sweeping.
@ -217,8 +181,7 @@ spawn(ScreenInfo *s)
if (fork() == 0) { if (fork() == 0) {
if (fork() == 0) { if (fork() == 0) {
close(ConnectionNumber(dpy)); close(ConnectionNumber(dpy));
if(s->display[0] != '\0') if (s->display[0] != '\0') putenv(s->display);
putenv(s->display);
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL); signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL); signal(SIGHUP, SIG_DFL);
@ -239,21 +202,24 @@ spawn(ScreenInfo *s)
} }
void void
reshape(Client *c, int but, int (*fn)(Client*, int, XButtonEvent *), XButtonEvent *e) reshape(
{ Client* c, int but, int (*fn)(Client*, int, XButtonEvent*), XButtonEvent* e) {
int odx, ody; int odx, ody;
if(c == 0) if (c == 0) return;
return;
odx = c->dx; odx = c->dx;
ody = c->dy; ody = c->dy;
if(fn(c, but, e) == 0) if (fn(c, but, e) == 0) return;
return;
active(c); active(c);
top(c); top(c);
XRaiseWindow(dpy, c->parent); XRaiseWindow(dpy, c->parent);
XMoveResizeWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER, XMoveResizeWindow(
c->dx+2*BORDER, c->dy+2*BORDER); dpy,
c->parent,
c->x - BORDER,
c->y - BORDER,
c->dx + 2 * BORDER,
c->dy + 2 * BORDER);
if (c->dx == odx && c->dy == ody) if (c->dx == odx && c->dy == ody)
sendconfig(c); sendconfig(c);
else else
@ -261,12 +227,9 @@ reshape(Client *c, int but, int (*fn)(Client*, int, XButtonEvent *), XButtonEven
} }
void void
move(Client *c, int but) move(Client* c, int but) {
{ if (c == 0) return;
if(c == 0) if (drag(c, but) == 0) return;
return;
if(drag(c, but) == 0)
return;
active(c); active(c);
top(c); top(c);
XRaiseWindow(dpy, c->parent); XRaiseWindow(dpy, c->parent);
@ -274,11 +237,8 @@ move(Client *c, int but)
sendconfig(c); sendconfig(c);
} }
void void delete (Client* c, int shift) {
delete(Client *c, int shift) if (c == 0) return;
{
if(c == 0)
return;
if ((c->proto & Pdelete) && !shift) if ((c->proto & Pdelete) && !shift)
sendcmessage(c->window, wm_protocols, wm_delete, 0, 0); sendcmessage(c->window, wm_protocols, wm_delete, 0, 0);
else else
@ -286,10 +246,8 @@ delete(Client *c, int shift)
} }
void void
hide(Client *c) hide(Client* c) {
{ if (c == 0 || numhidden == MAXHIDDEN) return;
if(c == 0 || numhidden == MAXHIDDEN)
return;
if (hidden(c)) { if (hidden(c)) {
fprintf(stderr, "ryudo: already hidden: %s\n", c->label); fprintf(stderr, "ryudo: already hidden: %s\n", c->label);
return; return;
@ -297,11 +255,11 @@ hide(Client *c)
XUnmapWindow(dpy, c->parent); XUnmapWindow(dpy, c->parent);
XUnmapWindow(dpy, c->window); XUnmapWindow(dpy, c->window);
setstate(c, IconicState); setstate(c, IconicState);
if(c == current) if (c == current) nofocus();
nofocus();
if (reversehide) { if (reversehide) {
memmove(hiddenc + 1, hiddenc, numhidden * sizeof hiddenc[0]); memmove(hiddenc + 1, hiddenc, numhidden * sizeof hiddenc[0]);
memmove(b3items+B3FIXED+1, b3items+B3FIXED, numhidden*sizeof b3items[0]); memmove(
b3items + B3FIXED + 1, b3items + B3FIXED, numhidden * sizeof b3items[0]);
hiddenc[0] = c; hiddenc[0] = c;
b3items[B3FIXED] = c->label; b3items[B3FIXED] = c->label;
} else { } else {
@ -313,8 +271,7 @@ hide(Client *c)
} }
void void
unhide(int n, int map) unhide(int n, int map) {
{
Client* c; Client* c;
int i; int i;
@ -324,8 +281,11 @@ unhide(int n, int map)
} }
c = hiddenc[n]; c = hiddenc[n];
if (!hidden(c)) { if (!hidden(c)) {
fprintf(stderr, "ryudo: unhide: not hidden: %s(0x%x)\n", fprintf(
c->label, (int)c->window); stderr,
"ryudo: unhide: not hidden: %s(0x%x)\n",
c->label,
(int)c->window);
return; return;
} }
c->virt = virt; c->virt = virt;
@ -347,8 +307,7 @@ unhide(int n, int map)
} }
void void
unhidec(Client *c, int map) unhidec(Client* c, int map) {
{
int i; int i;
for (i = 0; i < numhidden; i++) for (i = 0; i < numhidden; i++)
@ -356,28 +315,25 @@ unhidec(Client *c, int map)
unhide(i, map); unhide(i, map);
return; return;
} }
fprintf(stderr, "ryudo: unhidec: not hidden: %s(0x%x)\n", fprintf(
c->label, (int)c->window); stderr, "ryudo: unhidec: not hidden: %s(0x%x)\n", c->label, (int)c->window);
} }
void void
stick(Client *c) stick(Client* c) {
{
if (numvirtuals > 1 && c->virt >= 0) if (numvirtuals > 1 && c->virt >= 0)
c->virt = -1; c->virt = -1;
else c->virt = virt; else
c->virt = virt;
} }
void void
renamec(Client *c, char *name) renamec(Client* c, char* name) {
{
int i; int i;
if(name == 0) if (name == 0) name = "???";
name = "???";
c->label = name; c->label = name;
if(!hidden(c)) if (!hidden(c)) return;
return;
for (i = 0; i < numhidden; i++) for (i = 0; i < numhidden; i++)
if (c == hiddenc[i]) { if (c == hiddenc[i]) {
b3items[B3FIXED + i] = name; b3items[B3FIXED + i] = name;
@ -386,63 +342,49 @@ renamec(Client *c, char *name)
} }
void void
button2(int n) button2(int n) {
{
switch_to(n); switch_to(n);
if(current) if (current) cmapfocus(current);
cmapfocus(current);
} }
void void
switch_to_c(int n, Client *c) switch_to_c(int n, Client* c) {
{ if (c == 0) return;
if(c == 0)
return;
if(c->next) if (c->next) switch_to_c(n, c->next);
switch_to_c(n, c->next);
if(c->parent == DefaultRootWindow(dpy)) if (c->parent == DefaultRootWindow(dpy)) return;
return;
#ifdef AUTOSTICK #ifdef AUTOSTICK
if(c->virt >= 0 && isautostick(c)){ if (c->virt >= 0 && isautostick(c)) { stick(c); }
stick(c);
}
#endif #endif
if (c->virt != virt && c->state == NormalState && c->virt >= 0) { if (c->virt != virt && c->state == NormalState && c->virt >= 0) {
XUnmapWindow(dpy, c->parent); XUnmapWindow(dpy, c->parent);
XUnmapWindow(dpy, c->window); XUnmapWindow(dpy, c->window);
setstate(c, IconicState); setstate(c, IconicState);
if(c == current) if (c == current) nofocus();
nofocus();
} else if (c->virt == virt && c->state == IconicState) { } else if (c->virt == virt && c->state == IconicState) {
int i; int i;
for (i = 0; i < numhidden; i++) for (i = 0; i < numhidden; i++)
if(c == hiddenc[i]) if (c == hiddenc[i]) break;
break;
if (i == numhidden) { if (i == numhidden) {
XMapWindow(dpy, c->window); XMapWindow(dpy, c->window);
XMapWindow(dpy, c->parent); XMapWindow(dpy, c->parent);
setstate(c, NormalState); setstate(c, NormalState);
if(currents[virt] == c) if (currents[virt] == c) active(c);
active(c);
} }
} }
} }
void void
switch_to(int n) switch_to(int n) {
{
#ifdef VIRTNOTIFY #ifdef VIRTNOTIFY
static char virtmsg[32]; static char virtmsg[32];
#endif #endif
if(n == virt) if (n == virt) return;
return;
currents[virt] = current; currents[virt] = current;
virt = n; virt = n;
@ -454,23 +396,27 @@ switch_to(int n)
switch_to_c(n, clients); switch_to_c(n, clients);
current = currents[virt]; current = currents[virt];
top(current); top(current);
if(fork() == 0) if (fork() == 0) {
{
close(ConnectionNumber(dpy)); close(ConnectionNumber(dpy));
if(dpy != '\0') if (dpy != '\0') putenv(dpy);
putenv(dpy);
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL); signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL); signal(SIGHUP, SIG_DFL);
#ifdef VIRTNOTIFY #ifdef VIRTNOTIFY
sprintf(virtmsg, VIRTMSG, b2items[virt]); sprintf(virtmsg, VIRTMSG, b2items[virt]);
execlp("notify-send", "notify-send", "-c", "virtual", VIRTHEADER, virtmsg, (char*)0); execlp(
"notify-send",
"notify-send",
"-c",
"virtual",
VIRTHEADER,
virtmsg,
(char*)0);
#endif #endif
} }
} }
void void
initb2menu(int n) initb2menu(int n) {
{
b2items[n] = 0; b2items[n] = 0;
} }

565
printevent.c Executable file → Normal file
View file

@ -56,59 +56,45 @@ static char* sep = " ";
/* Returns the string equivalent of a boolean parameter */ /* Returns the string equivalent of a boolean parameter */
static char* static char*
TorF(int bool) TorF(int bool) {
{
switch (bool) { switch (bool) {
case True: case True: return ("True");
return ("True");
case False: case False: return ("False");
return ("False");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a property notify state */ /* Returns the string equivalent of a property notify state */
static char* static char*
PropertyState(int state) PropertyState(int state) {
{
switch (state) { switch (state) {
case PropertyNewValue: case PropertyNewValue: return ("PropertyNewValue");
return ("PropertyNewValue");
case PropertyDelete: case PropertyDelete: return ("PropertyDelete");
return ("PropertyDelete");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a visibility notify state */ /* Returns the string equivalent of a visibility notify state */
static char* static char*
VisibilityState(int state) VisibilityState(int state) {
{
switch (state) { switch (state) {
case VisibilityUnobscured: case VisibilityUnobscured: return ("VisibilityUnobscured");
return ("VisibilityUnobscured");
case VisibilityPartiallyObscured: case VisibilityPartiallyObscured: return ("VisibilityPartiallyObscured");
return ("VisibilityPartiallyObscured");
case VisibilityFullyObscured: case VisibilityFullyObscured: return ("VisibilityFullyObscured");
return ("VisibilityFullyObscured");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a timestamp */ /* Returns the string equivalent of a timestamp */
static char* static char*
ServerTime(Time time) ServerTime(Time time) {
{
unsigned long msec; unsigned long msec;
unsigned long sec; unsigned long sec;
unsigned long min; unsigned long min;
@ -127,8 +113,15 @@ ServerTime(Time time)
day = time; day = time;
if (0) if (0)
sprintf(buffer, "%lu day%s %02lu:%02lu:%02lu.%03lu", sprintf(
day, day == 1 ? "" : "(s)", hr, min, sec, msec); buffer,
"%lu day%s %02lu:%02lu:%02lu.%03lu",
day,
day == 1 ? "" : "(s)",
hr,
min,
sec,
msec);
sprintf(buffer, "%lud%luh%lum%lu.%03lds", day, hr, min, sec, msec); sprintf(buffer, "%lud%luh%lum%lu.%03lds", day, hr, min, sec, msec);
return (buffer); return (buffer);
@ -136,16 +129,14 @@ if(0)
/* Simple structure to ease the interpretation of masks */ /* Simple structure to ease the interpretation of masks */
typedef struct MaskType MaskType; typedef struct MaskType MaskType;
struct MaskType struct MaskType {
{
unsigned int value; unsigned int value;
char* string; char* string;
}; };
/* Returns the string equivalent of a mask of buttons and/or modifier keys */ /* Returns the string equivalent of a mask of buttons and/or modifier keys */
static char* static char*
ButtonAndOrModifierState(unsigned int state) ButtonAndOrModifierState(unsigned int state) {
{
static char buffer[256]; static char buffer[256];
static MaskType masks[] = { static MaskType masks[] = {
{Button1Mask, "Button1Mask"}, {Button1Mask, "Button1Mask"},
@ -182,8 +173,7 @@ ButtonAndOrModifierState(unsigned int state)
/* Returns the string equivalent of a mask of configure window values */ /* Returns the string equivalent of a mask of configure window values */
static char* static char*
ConfigureValueMask(unsigned int valuemask) ConfigureValueMask(unsigned int valuemask) {
{
static char buffer[256]; static char buffer[256];
static MaskType masks[] = { static MaskType masks[] = {
{CWX, "CWX"}, {CWX, "CWX"},
@ -215,24 +205,19 @@ ConfigureValueMask(unsigned int valuemask)
/* Returns the string equivalent of a motion hint */ /* Returns the string equivalent of a motion hint */
static char* static char*
IsHint(char is_hint) IsHint(char is_hint) {
{
switch (is_hint) { switch (is_hint) {
case NotifyNormal: case NotifyNormal: return ("NotifyNormal");
return ("NotifyNormal");
case NotifyHint: case NotifyHint: return ("NotifyHint");
return ("NotifyHint");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of an id or the value "None" */ /* Returns the string equivalent of an id or the value "None" */
static char* static char*
MaybeNone(int value) MaybeNone(int value) {
{
static char buffer[16]; static char buffer[16];
if (value == None) if (value == None)
@ -245,184 +230,135 @@ MaybeNone(int value)
/* Returns the string equivalent of a colormap state */ /* Returns the string equivalent of a colormap state */
static char* static char*
ColormapState(int state) ColormapState(int state) {
{
switch (state) { switch (state) {
case ColormapInstalled: case ColormapInstalled: return ("ColormapInstalled");
return ("ColormapInstalled");
case ColormapUninstalled: case ColormapUninstalled: return ("ColormapUninstalled");
return ("ColormapUninstalled");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a crossing detail */ /* Returns the string equivalent of a crossing detail */
static char* static char*
CrossingDetail(int detail) CrossingDetail(int detail) {
{
switch (detail) { switch (detail) {
case NotifyAncestor: case NotifyAncestor: return ("NotifyAncestor");
return ("NotifyAncestor");
case NotifyInferior: case NotifyInferior: return ("NotifyInferior");
return ("NotifyInferior");
case NotifyVirtual: case NotifyVirtual: return ("NotifyVirtual");
return ("NotifyVirtual");
case NotifyNonlinear: case NotifyNonlinear: return ("NotifyNonlinear");
return ("NotifyNonlinear");
case NotifyNonlinearVirtual: case NotifyNonlinearVirtual: return ("NotifyNonlinearVirtual");
return ("NotifyNonlinearVirtual");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a focus change detail */ /* Returns the string equivalent of a focus change detail */
static char* static char*
FocusChangeDetail(int detail) FocusChangeDetail(int detail) {
{
switch (detail) { switch (detail) {
case NotifyAncestor: case NotifyAncestor: return ("NotifyAncestor");
return ("NotifyAncestor");
case NotifyInferior: case NotifyInferior: return ("NotifyInferior");
return ("NotifyInferior");
case NotifyVirtual: case NotifyVirtual: return ("NotifyVirtual");
return ("NotifyVirtual");
case NotifyNonlinear: case NotifyNonlinear: return ("NotifyNonlinear");
return ("NotifyNonlinear");
case NotifyNonlinearVirtual: case NotifyNonlinearVirtual: return ("NotifyNonlinearVirtual");
return ("NotifyNonlinearVirtual");
case NotifyPointer: case NotifyPointer: return ("NotifyPointer");
return ("NotifyPointer");
case NotifyPointerRoot: case NotifyPointerRoot: return ("NotifyPointerRoot");
return ("NotifyPointerRoot");
case NotifyDetailNone: case NotifyDetailNone: return ("NotifyDetailNone");
return ("NotifyDetailNone");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a configure detail */ /* Returns the string equivalent of a configure detail */
static char* static char*
ConfigureDetail(int detail) ConfigureDetail(int detail) {
{
switch (detail) { switch (detail) {
case Above: case Above: return ("Above");
return ("Above");
case Below: case Below: return ("Below");
return ("Below");
case TopIf: case TopIf: return ("TopIf");
return ("TopIf");
case BottomIf: case BottomIf: return ("BottomIf");
return ("BottomIf");
case Opposite: case Opposite: return ("Opposite");
return ("Opposite");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a grab mode */ /* Returns the string equivalent of a grab mode */
static char* static char*
GrabMode(int mode) GrabMode(int mode) {
{
switch (mode) { switch (mode) {
case NotifyNormal: case NotifyNormal: return ("NotifyNormal");
return ("NotifyNormal");
case NotifyGrab: case NotifyGrab: return ("NotifyGrab");
return ("NotifyGrab");
case NotifyUngrab: case NotifyUngrab: return ("NotifyUngrab");
return ("NotifyUngrab");
case NotifyWhileGrabbed: case NotifyWhileGrabbed: return ("NotifyWhileGrabbed");
return ("NotifyWhileGrabbed");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a mapping request */ /* Returns the string equivalent of a mapping request */
static char* static char*
MappingRequest(int request) MappingRequest(int request) {
{
switch (request) { switch (request) {
case MappingModifier: case MappingModifier: return ("MappingModifier");
return ("MappingModifier");
case MappingKeyboard: case MappingKeyboard: return ("MappingKeyboard");
return ("MappingKeyboard");
case MappingPointer: case MappingPointer: return ("MappingPointer");
return ("MappingPointer");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a stacking order place */ /* Returns the string equivalent of a stacking order place */
static char* static char*
Place(int place) Place(int place) {
{
switch (place) { switch (place) {
case PlaceOnTop: case PlaceOnTop: return ("PlaceOnTop");
return ("PlaceOnTop");
case PlaceOnBottom: case PlaceOnBottom: return ("PlaceOnBottom");
return ("PlaceOnBottom");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a major code */ /* Returns the string equivalent of a major code */
static char* static char*
MajorCode(int code) MajorCode(int code) {
{
static char buffer[32]; static char buffer[32];
switch (code) { switch (code) {
case X_CopyArea: case X_CopyArea: return ("X_CopyArea");
return ("X_CopyArea");
case X_CopyPlane: case X_CopyPlane: return ("X_CopyPlane");
return ("X_CopyPlane");
default: default: sprintf(buffer, "0x%x", code); return (buffer);
sprintf(buffer, "0x%x", code);
return (buffer);
} }
} }
/* Returns the string equivalent the keycode contained in the key event */ /* Returns the string equivalent the keycode contained in the key event */
static char* static char*
Keycode(XKeyEvent *ev) Keycode(XKeyEvent* ev) {
{
static char buffer[256]; static char buffer[256];
KeySym keysym_str; KeySym keysym_str;
char* keysym_name; char* keysym_name;
@ -434,20 +370,22 @@ Keycode(XKeyEvent *ev)
keysym_name = "NoSymbol"; keysym_name = "NoSymbol";
else if (!(keysym_name = XKeysymToString(keysym_str))) else if (!(keysym_name = XKeysymToString(keysym_str)))
keysym_name = "(no name)"; keysym_name = "(no name)";
sprintf(buffer, "%u (keysym 0x%x \"%s\")", sprintf(
(int)ev->keycode, (int)keysym_str, keysym_name); buffer,
"%u (keysym 0x%x \"%s\")",
(int)ev->keycode,
(int)keysym_str,
keysym_name);
return (buffer); return (buffer);
} }
/* Returns the string equivalent of an atom or "None"*/ /* Returns the string equivalent of an atom or "None"*/
static char* static char*
AtomName(Display *dpy, Atom atom) AtomName(Display* dpy, Atom atom) {
{
static char buffer[256]; static char buffer[256];
char* atom_name; char* atom_name;
if (atom == None) if (atom == None) return ("None");
return ("None");
atom_name = XGetAtomName(dpy, atom); atom_name = XGetAtomName(dpy, atom);
strncpy(buffer, atom_name, 256); strncpy(buffer, atom_name, 256);
@ -460,8 +398,7 @@ AtomName(Display *dpy, Atom atom)
/******************************************************************************/ /******************************************************************************/
static void static void
VerbMotion(XMotionEvent *ev) VerbMotion(XMotionEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("root=0x%x%s", (int)ev->root, sep); printf("root=0x%x%s", (int)ev->root, sep);
printf("subwindow=0x%x%s", (int)ev->subwindow, sep); printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
@ -474,8 +411,7 @@ VerbMotion(XMotionEvent *ev)
} }
static void static void
VerbButton(XButtonEvent *ev) VerbButton(XButtonEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("root=0x%x%s", (int)ev->root, sep); printf("root=0x%x%s", (int)ev->root, sep);
printf("subwindow=0x%x%s", (int)ev->subwindow, sep); printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
@ -488,8 +424,7 @@ VerbButton(XButtonEvent *ev)
} }
static void static void
VerbColormap(XColormapEvent *ev) VerbColormap(XColormapEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("colormap=%s%s", MaybeNone(ev->colormap), sep); printf("colormap=%s%s", MaybeNone(ev->colormap), sep);
printf("new=%s%s", TorF(ev->new), sep); printf("new=%s%s", TorF(ev->new), sep);
@ -497,8 +432,7 @@ VerbColormap(XColormapEvent *ev)
} }
static void static void
VerbCrossing(XCrossingEvent *ev) VerbCrossing(XCrossingEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("root=0x%x%s", (int)ev->root, sep); printf("root=0x%x%s", (int)ev->root, sep);
printf("subwindow=0x%x%s", (int)ev->subwindow, sep); printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
@ -513,8 +447,7 @@ VerbCrossing(XCrossingEvent *ev)
} }
static void static void
VerbExpose(XExposeEvent *ev) VerbExpose(XExposeEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
printf("width=%d height=%d%s", ev->width, ev->height, sep); printf("width=%d height=%d%s", ev->width, ev->height, sep);
@ -522,8 +455,7 @@ VerbExpose(XExposeEvent *ev)
} }
static void static void
VerbGraphicsExpose(XGraphicsExposeEvent *ev) VerbGraphicsExpose(XGraphicsExposeEvent* ev) {
{
printf("drawable=0x%x%s", (int)ev->drawable, sep); printf("drawable=0x%x%s", (int)ev->drawable, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
printf("width=%d height=%d%s", ev->width, ev->height, sep); printf("width=%d height=%d%s", ev->width, ev->height, sep);
@ -532,48 +464,40 @@ VerbGraphicsExpose(XGraphicsExposeEvent *ev)
} }
static void static void
VerbNoExpose(XNoExposeEvent *ev) VerbNoExpose(XNoExposeEvent* ev) {
{
printf("drawable=0x%x%s", (int)ev->drawable, sep); printf("drawable=0x%x%s", (int)ev->drawable, sep);
printf("major_code=%s%s", MajorCode(ev->major_code), sep); printf("major_code=%s%s", MajorCode(ev->major_code), sep);
printf("minor_code=%d\n", ev->minor_code); printf("minor_code=%d\n", ev->minor_code);
} }
static void static void
VerbFocus(XFocusChangeEvent *ev) VerbFocus(XFocusChangeEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("mode=%s%s", GrabMode(ev->mode), sep); printf("mode=%s%s", GrabMode(ev->mode), sep);
printf("detail=%s\n", FocusChangeDetail(ev->detail)); printf("detail=%s\n", FocusChangeDetail(ev->detail));
} }
static void static void
VerbKeymap(XKeymapEvent *ev) VerbKeymap(XKeymapEvent* ev) {
{
int i; int i;
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("key_vector="); printf("key_vector=");
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++) printf("%02x", ev->key_vector[i]);
printf("%02x", ev->key_vector[i]);
printf("\n"); printf("\n");
} }
static void static void
VerbKey(XKeyEvent *ev) VerbKey(XKeyEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("root=0x%x%s", (int)ev->root, sep); printf("root=0x%x%s", (int)ev->root, sep);
if(ev->subwindow) if (ev->subwindow) printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
printf("subwindow=0x%x%s", (int)ev->subwindow, sep);
printf("time=%s%s", ServerTime(ev->time), sep); printf("time=%s%s", ServerTime(ev->time), sep);
printf("[%d,%d]%s", ev->x, ev->y, sep); printf("[%d,%d]%s", ev->x, ev->y, sep);
printf("root=[%d,%d]%s", ev->x_root, ev->y_root, sep); printf("root=[%d,%d]%s", ev->x_root, ev->y_root, sep);
if(ev->state) if (ev->state) printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
printf("state=%s%s", ButtonAndOrModifierState(ev->state), sep);
printf("keycode=%s%s", Keycode(ev), sep); printf("keycode=%s%s", Keycode(ev), sep);
if(!ev->same_screen) if (!ev->same_screen) printf("!same_screen", TorF(ev->same_screen));
printf("!same_screen", TorF(ev->same_screen));
printf("\n"); printf("\n");
return; return;
@ -589,8 +513,7 @@ VerbKey(XKeyEvent *ev)
} }
static void static void
VerbProperty(XPropertyEvent *ev) VerbProperty(XPropertyEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("atom=%s%s", AtomName(ev->display, ev->atom), sep); printf("atom=%s%s", AtomName(ev->display, ev->atom), sep);
printf("time=%s%s", ServerTime(ev->time), sep); printf("time=%s%s", ServerTime(ev->time), sep);
@ -598,23 +521,20 @@ VerbProperty(XPropertyEvent *ev)
} }
static void static void
VerbResizeRequest(XResizeRequestEvent *ev) VerbResizeRequest(XResizeRequestEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("width=%d height=%d\n", ev->width, ev->height); printf("width=%d height=%d\n", ev->width, ev->height);
} }
static void static void
VerbCirculate(XCirculateEvent *ev) VerbCirculate(XCirculateEvent* ev) {
{
printf("event=0x%x%s", (int)ev->event, sep); printf("event=0x%x%s", (int)ev->event, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("place=%s\n", Place(ev->place)); printf("place=%s\n", Place(ev->place));
} }
static void static void
VerbConfigure(XConfigureEvent *ev) VerbConfigure(XConfigureEvent* ev) {
{
printf("event=0x%x%s", (int)ev->event, sep); printf("event=0x%x%s", (int)ev->event, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
@ -625,8 +545,7 @@ VerbConfigure(XConfigureEvent *ev)
} }
static void static void
VerbCreateWindow(XCreateWindowEvent *ev) VerbCreateWindow(XCreateWindowEvent* ev) {
{
printf("parent=0x%x%s", (int)ev->parent, sep); printf("parent=0x%x%s", (int)ev->parent, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
@ -636,31 +555,27 @@ VerbCreateWindow(XCreateWindowEvent *ev)
} }
static void static void
VerbDestroyWindow(XDestroyWindowEvent *ev) VerbDestroyWindow(XDestroyWindowEvent* ev) {
{
printf("event=0x%x%s", (int)ev->event, sep); printf("event=0x%x%s", (int)ev->event, sep);
printf("window=0x%x\n", (int)ev->window); printf("window=0x%x\n", (int)ev->window);
} }
static void static void
VerbGravity(XGravityEvent *ev) VerbGravity(XGravityEvent* ev) {
{
printf("event=0x%x%s", (int)ev->event, sep); printf("event=0x%x%s", (int)ev->event, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("x=%d y=%d\n", ev->x, ev->y); printf("x=%d y=%d\n", ev->x, ev->y);
} }
static void static void
VerbMap(XMapEvent *ev) VerbMap(XMapEvent* ev) {
{
printf("event=0x%x%s", (int)ev->event, sep); printf("event=0x%x%s", (int)ev->event, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("override_redirect=%s\n", TorF(ev->override_redirect)); printf("override_redirect=%s\n", TorF(ev->override_redirect));
} }
static void static void
VerbReparent(XReparentEvent *ev) VerbReparent(XReparentEvent* ev) {
{
printf("event=0x%x%s", (int)ev->event, sep); printf("event=0x%x%s", (int)ev->event, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("parent=0x%x%s", (int)ev->parent, sep); printf("parent=0x%x%s", (int)ev->parent, sep);
@ -669,24 +584,21 @@ VerbReparent(XReparentEvent *ev)
} }
static void static void
VerbUnmap(XUnmapEvent *ev) VerbUnmap(XUnmapEvent* ev) {
{
printf("event=0x%x%s", (int)ev->event, sep); printf("event=0x%x%s", (int)ev->event, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("from_configure=%s\n", TorF(ev->from_configure)); printf("from_configure=%s\n", TorF(ev->from_configure));
} }
static void static void
VerbCirculateRequest(XCirculateRequestEvent *ev) VerbCirculateRequest(XCirculateRequestEvent* ev) {
{
printf("parent=0x%x%s", (int)ev->parent, sep); printf("parent=0x%x%s", (int)ev->parent, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("place=%s\n", Place(ev->place)); printf("place=%s\n", Place(ev->place));
} }
static void static void
VerbConfigureRequest(XConfigureRequestEvent *ev) VerbConfigureRequest(XConfigureRequestEvent* ev) {
{
printf("parent=0x%x%s", (int)ev->parent, sep); printf("parent=0x%x%s", (int)ev->parent, sep);
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
@ -698,29 +610,25 @@ VerbConfigureRequest(XConfigureRequestEvent *ev)
} }
static void static void
VerbMapRequest(XMapRequestEvent *ev) VerbMapRequest(XMapRequestEvent* ev) {
{
printf("parent=0x%x%s", (int)ev->parent, sep); printf("parent=0x%x%s", (int)ev->parent, sep);
printf("window=0x%x\n", (int)ev->window); printf("window=0x%x\n", (int)ev->window);
} }
static void static void
VerbClient(XClientMessageEvent *ev) VerbClient(XClientMessageEvent* ev) {
{
int i; int i;
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep); printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep);
printf("format=%d\n", ev->format); printf("format=%d\n", ev->format);
printf("data (shown as longs)="); printf("data (shown as longs)=");
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++) printf(" 0x%08lx", ev->data.l[i]);
printf(" 0x%08lx", ev->data.l[i]);
printf("\n"); printf("\n");
} }
static void static void
VerbMapping(XMappingEvent *ev) VerbMapping(XMappingEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("request=%s%s", MappingRequest(ev->request), sep); printf("request=%s%s", MappingRequest(ev->request), sep);
printf("first_keycode=0x%x%s", ev->first_keycode, sep); printf("first_keycode=0x%x%s", ev->first_keycode, sep);
@ -728,16 +636,14 @@ VerbMapping(XMappingEvent *ev)
} }
static void static void
VerbSelectionClear(XSelectionClearEvent *ev) VerbSelectionClear(XSelectionClearEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
printf("time=%s\n", ServerTime(ev->time)); printf("time=%s\n", ServerTime(ev->time));
} }
static void static void
VerbSelection(XSelectionEvent *ev) VerbSelection(XSelectionEvent* ev) {
{
printf("requestor=0x%x%s", (int)ev->requestor, sep); printf("requestor=0x%x%s", (int)ev->requestor, sep);
printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
printf("target=%s%s", AtomName(ev->display, ev->target), sep); printf("target=%s%s", AtomName(ev->display, ev->target), sep);
@ -746,8 +652,7 @@ VerbSelection(XSelectionEvent *ev)
} }
static void static void
VerbSelectionRequest(XSelectionRequestEvent *ev) VerbSelectionRequest(XSelectionRequestEvent* ev) {
{
printf("owner=0x%x%s", (int)ev->owner, sep); printf("owner=0x%x%s", (int)ev->owner, sep);
printf("requestor=0x%x%s", (int)ev->requestor, sep); printf("requestor=0x%x%s", (int)ev->requestor, sep);
printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
@ -757,8 +662,7 @@ VerbSelectionRequest(XSelectionRequestEvent *ev)
} }
static void static void
VerbVisibility(XVisibilityEvent *ev) VerbVisibility(XVisibilityEvent* ev) {
{
printf("window=0x%x%s", (int)ev->window, sep); printf("window=0x%x%s", (int)ev->window, sep);
printf("state=%s\n", VisibilityState(ev->state)); printf("state=%s\n", VisibilityState(ev->state));
} }
@ -767,77 +671,44 @@ VerbVisibility(XVisibilityEvent *ev)
/************ Return the string representation for type of an event ***********/ /************ Return the string representation for type of an event ***********/
/******************************************************************************/ /******************************************************************************/
char *eventtype(XEvent *ev) char*
{ eventtype(XEvent* ev) {
static char buffer[20]; static char buffer[20];
switch (ev->type) { switch (ev->type) {
case KeyPress: case KeyPress: return ("KeyPress");
return ("KeyPress"); case KeyRelease: return ("KeyRelease");
case KeyRelease: case ButtonPress: return ("ButtonPress");
return ("KeyRelease"); case ButtonRelease: return ("ButtonRelease");
case ButtonPress: case MotionNotify: return ("MotionNotify");
return ("ButtonPress"); case EnterNotify: return ("EnterNotify");
case ButtonRelease: case LeaveNotify: return ("LeaveNotify");
return ("ButtonRelease"); case FocusIn: return ("FocusIn");
case MotionNotify: case FocusOut: return ("FocusOut");
return ("MotionNotify"); case KeymapNotify: return ("KeymapNotify");
case EnterNotify: case Expose: return ("Expose");
return ("EnterNotify"); case GraphicsExpose: return ("GraphicsExpose");
case LeaveNotify: case NoExpose: return ("NoExpose");
return ("LeaveNotify"); case VisibilityNotify: return ("VisibilityNotify");
case FocusIn: case CreateNotify: return ("CreateNotify");
return ("FocusIn"); case DestroyNotify: return ("DestroyNotify");
case FocusOut: case UnmapNotify: return ("UnmapNotify");
return ("FocusOut"); case MapNotify: return ("MapNotify");
case KeymapNotify: case MapRequest: return ("MapRequest");
return ("KeymapNotify"); case ReparentNotify: return ("ReparentNotify");
case Expose: case ConfigureNotify: return ("ConfigureNotify");
return ("Expose"); case ConfigureRequest: return ("ConfigureRequest");
case GraphicsExpose: case GravityNotify: return ("GravityNotify");
return ("GraphicsExpose"); case ResizeRequest: return ("ResizeRequest");
case NoExpose: case CirculateNotify: return ("CirculateNotify");
return ("NoExpose"); case CirculateRequest: return ("CirculateRequest");
case VisibilityNotify: case PropertyNotify: return ("PropertyNotify");
return ("VisibilityNotify"); case SelectionClear: return ("SelectionClear");
case CreateNotify: case SelectionRequest: return ("SelectionRequest");
return ("CreateNotify"); case SelectionNotify: return ("SelectionNotify");
case DestroyNotify: case ColormapNotify: return ("ColormapNotify");
return ("DestroyNotify"); case ClientMessage: return ("ClientMessage");
case UnmapNotify: case MappingNotify: return ("MappingNotify");
return ("UnmapNotify");
case MapNotify:
return ("MapNotify");
case MapRequest:
return ("MapRequest");
case ReparentNotify:
return ("ReparentNotify");
case ConfigureNotify:
return ("ConfigureNotify");
case ConfigureRequest:
return ("ConfigureRequest");
case GravityNotify:
return ("GravityNotify");
case ResizeRequest:
return ("ResizeRequest");
case CirculateNotify:
return ("CirculateNotify");
case CirculateRequest:
return ("CirculateRequest");
case PropertyNotify:
return ("PropertyNotify");
case SelectionClear:
return ("SelectionClear");
case SelectionRequest:
return ("SelectionRequest");
case SelectionNotify:
return ("SelectionNotify");
case ColormapNotify:
return ("ColormapNotify");
case ClientMessage:
return ("ClientMessage");
case MappingNotify:
return ("MappingNotify");
} }
sprintf(buffer, "%d", ev->type); sprintf(buffer, "%d", ev->type);
return buffer; return buffer;
@ -847,13 +718,12 @@ char *eventtype(XEvent *ev)
/**************** Print the values of all fields for any event ****************/ /**************** Print the values of all fields for any event ****************/
/******************************************************************************/ /******************************************************************************/
void printevent(XEvent *e) void
{ printevent(XEvent* e) {
XAnyEvent* ev = (void*)e; XAnyEvent* ev = (void*)e;
printf("%3ld %-20s ", ev->serial, eventtype(e)); printf("%3ld %-20s ", ev->serial, eventtype(e));
if(ev->send_event) if (ev->send_event) printf("(sendevent) ");
printf("(sendevent) ");
if (0) { if (0) {
printf("type=%s%s", eventtype(e), sep); printf("type=%s%s", eventtype(e), sep);
printf("serial=%lu%s", ev->serial, sep); printf("serial=%lu%s", ev->serial, sep);
@ -862,125 +732,66 @@ void printevent(XEvent *e)
} }
switch (ev->type) { switch (ev->type) {
case MotionNotify: case MotionNotify: VerbMotion((void*)ev); break;
VerbMotion((void*)ev);
break;
case ButtonPress: case ButtonPress:
case ButtonRelease: case ButtonRelease: VerbButton((void*)ev); break;
VerbButton((void*)ev);
break;
case ColormapNotify: case ColormapNotify: VerbColormap((void*)ev); break;
VerbColormap((void*)ev);
break;
case EnterNotify: case EnterNotify:
case LeaveNotify: case LeaveNotify: VerbCrossing((void*)ev); break;
VerbCrossing((void*)ev);
break;
case Expose: case Expose: VerbExpose((void*)ev); break;
VerbExpose((void*)ev);
break;
case GraphicsExpose: case GraphicsExpose: VerbGraphicsExpose((void*)ev); break;
VerbGraphicsExpose((void*)ev);
break;
case NoExpose: case NoExpose: VerbNoExpose((void*)ev); break;
VerbNoExpose((void*)ev);
break;
case FocusIn: case FocusIn:
case FocusOut: case FocusOut: VerbFocus((void*)ev); break;
VerbFocus((void*)ev);
break;
case KeymapNotify: case KeymapNotify: VerbKeymap((void*)ev); break;
VerbKeymap((void*)ev);
break;
case KeyPress: case KeyPress:
case KeyRelease: case KeyRelease: VerbKey((void*)ev); break;
VerbKey((void*)ev);
break;
case PropertyNotify: case PropertyNotify: VerbProperty((void*)ev); break;
VerbProperty((void*)ev);
break;
case ResizeRequest: case ResizeRequest: VerbResizeRequest((void*)ev); break;
VerbResizeRequest((void*)ev);
break;
case CirculateNotify: case CirculateNotify: VerbCirculate((void*)ev); break;
VerbCirculate((void*)ev);
break;
case ConfigureNotify: case ConfigureNotify: VerbConfigure((void*)ev); break;
VerbConfigure((void*)ev);
break;
case CreateNotify: case CreateNotify: VerbCreateWindow((void*)ev); break;
VerbCreateWindow((void*)ev);
break;
case DestroyNotify: case DestroyNotify: VerbDestroyWindow((void*)ev); break;
VerbDestroyWindow((void*)ev);
break;
case GravityNotify: case GravityNotify: VerbGravity((void*)ev); break;
VerbGravity((void*)ev);
break;
case MapNotify: case MapNotify: VerbMap((void*)ev); break;
VerbMap((void*)ev);
break;
case ReparentNotify: case ReparentNotify: VerbReparent((void*)ev); break;
VerbReparent((void*)ev);
break;
case UnmapNotify: case UnmapNotify: VerbUnmap((void*)ev); break;
VerbUnmap((void*)ev);
break;
case CirculateRequest: case CirculateRequest: VerbCirculateRequest((void*)ev); break;
VerbCirculateRequest((void*)ev);
break;
case ConfigureRequest: case ConfigureRequest: VerbConfigureRequest((void*)ev); break;
VerbConfigureRequest((void*)ev);
break;
case MapRequest: case MapRequest: VerbMapRequest((void*)ev); break;
VerbMapRequest((void*)ev);
break;
case ClientMessage: case ClientMessage: VerbClient((void*)ev); break;
VerbClient((void*)ev);
break;
case MappingNotify: case MappingNotify: VerbMapping((void*)ev); break;
VerbMapping((void*)ev);
break;
case SelectionClear: case SelectionClear: VerbSelectionClear((void*)ev); break;
VerbSelectionClear((void*)ev);
break;
case SelectionNotify: case SelectionNotify: VerbSelection((void*)ev); break;
VerbSelection((void*)ev);
break;
case SelectionRequest: case SelectionRequest: VerbSelectionRequest((void*)ev); break;
VerbSelectionRequest((void*)ev);
break;
case VisibilityNotify: case VisibilityNotify: VerbVisibility((void*)ev); break;
VerbVisibility((void*)ev);
break;
} }
} }

0
printevent.h Executable file → Normal file
View file

579
showevent/ShowEvent.c Executable file → Normal file
View file

@ -9,59 +9,45 @@ static char *sep;
/******************************************************************************/ /******************************************************************************/
/* Returns the string equivalent of a boolean parameter */ /* Returns the string equivalent of a boolean parameter */
static char *TorF(bool) static char* TorF(bool) int bool;
int bool;
{ {
switch (bool) { switch (bool) {
case True: case True: return ("True");
return ("True");
case False: case False: return ("False");
return ("False");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a property notify state */ /* Returns the string equivalent of a property notify state */
static char *PropertyState(state) static char* PropertyState(state) int state;
int state;
{ {
switch (state) { switch (state) {
case PropertyNewValue: case PropertyNewValue: return ("PropertyNewValue");
return ("PropertyNewValue");
case PropertyDelete: case PropertyDelete: return ("PropertyDelete");
return ("PropertyDelete");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a visibility notify state */ /* Returns the string equivalent of a visibility notify state */
static char *VisibilityState(state) static char* VisibilityState(state) int state;
int state;
{ {
switch (state) { switch (state) {
case VisibilityUnobscured: case VisibilityUnobscured: return ("VisibilityUnobscured");
return ("VisibilityUnobscured");
case VisibilityPartiallyObscured: case VisibilityPartiallyObscured: return ("VisibilityPartiallyObscured");
return ("VisibilityPartiallyObscured");
case VisibilityFullyObscured: case VisibilityFullyObscured: return ("VisibilityFullyObscured");
return ("VisibilityFullyObscured");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a timestamp */ /* Returns the string equivalent of a timestamp */
static char *ServerTime(time) static char* ServerTime(time) Time time;
Time time;
{ {
unsigned long msec; unsigned long msec;
unsigned long sec; unsigned long sec;
@ -80,8 +66,15 @@ Time time;
time /= 24; time /= 24;
day = time; day = time;
sprintf(buffer, "%ld day%s %02ld:%02ld:%02ld.%03ld", sprintf(
day, day == 1 ? "" : "(s)", hr, min, sec, msec); buffer,
"%ld day%s %02ld:%02ld:%02ld.%03ld",
day,
day == 1 ? "" : "(s)",
hr,
min,
sec,
msec);
return (buffer); return (buffer);
} }
@ -92,8 +85,7 @@ typedef struct _MaskType {
} MaskType; } MaskType;
/* Returns the string equivalent of a mask of buttons and/or modifier keys */ /* Returns the string equivalent of a mask of buttons and/or modifier keys */
static char *ButtonAndOrModifierState(state) static char* ButtonAndOrModifierState(state) unsigned int state;
unsigned int state;
{ {
static char buffer[256]; static char buffer[256];
static MaskType masks[] = { static MaskType masks[] = {
@ -130,8 +122,7 @@ unsigned int state;
} }
/* Returns the string equivalent of a mask of configure window values */ /* Returns the string equivalent of a mask of configure window values */
static char *ConfigureValueMask(valuemask) static char* ConfigureValueMask(valuemask) unsigned int valuemask;
unsigned int valuemask;
{ {
static char buffer[256]; static char buffer[256];
static MaskType masks[] = { static MaskType masks[] = {
@ -163,24 +154,19 @@ unsigned int valuemask;
} }
/* Returns the string equivalent of a motion hint */ /* Returns the string equivalent of a motion hint */
static char *IsHint(is_hint) static char* IsHint(is_hint) char is_hint;
char is_hint;
{ {
switch (is_hint) { switch (is_hint) {
case NotifyNormal: case NotifyNormal: return ("NotifyNormal");
return ("NotifyNormal");
case NotifyHint: case NotifyHint: return ("NotifyHint");
return ("NotifyHint");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of an id or the value "None" */ /* Returns the string equivalent of an id or the value "None" */
static char *MaybeNone(value) static char* MaybeNone(value) int value;
int value;
{ {
static char buffer[16]; static char buffer[16];
@ -193,184 +179,135 @@ int value;
} }
/* Returns the string equivalent of a colormap state */ /* Returns the string equivalent of a colormap state */
static char *ColormapState(state) static char* ColormapState(state) int state;
int state;
{ {
switch (state) { switch (state) {
case ColormapInstalled: case ColormapInstalled: return ("ColormapInstalled");
return ("ColormapInstalled");
case ColormapUninstalled: case ColormapUninstalled: return ("ColormapUninstalled");
return ("ColormapUninstalled");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a crossing detail */ /* Returns the string equivalent of a crossing detail */
static char *CrossingDetail(detail) static char* CrossingDetail(detail) int detail;
int detail;
{ {
switch (detail) { switch (detail) {
case NotifyAncestor: case NotifyAncestor: return ("NotifyAncestor");
return ("NotifyAncestor");
case NotifyInferior: case NotifyInferior: return ("NotifyInferior");
return ("NotifyInferior");
case NotifyVirtual: case NotifyVirtual: return ("NotifyVirtual");
return ("NotifyVirtual");
case NotifyNonlinear: case NotifyNonlinear: return ("NotifyNonlinear");
return ("NotifyNonlinear");
case NotifyNonlinearVirtual: case NotifyNonlinearVirtual: return ("NotifyNonlinearVirtual");
return ("NotifyNonlinearVirtual");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a focus change detail */ /* Returns the string equivalent of a focus change detail */
static char *FocusChangeDetail(detail) static char* FocusChangeDetail(detail) int detail;
int detail;
{ {
switch (detail) { switch (detail) {
case NotifyAncestor: case NotifyAncestor: return ("NotifyAncestor");
return ("NotifyAncestor");
case NotifyInferior: case NotifyInferior: return ("NotifyInferior");
return ("NotifyInferior");
case NotifyVirtual: case NotifyVirtual: return ("NotifyVirtual");
return ("NotifyVirtual");
case NotifyNonlinear: case NotifyNonlinear: return ("NotifyNonlinear");
return ("NotifyNonlinear");
case NotifyNonlinearVirtual: case NotifyNonlinearVirtual: return ("NotifyNonlinearVirtual");
return ("NotifyNonlinearVirtual");
case NotifyPointer: case NotifyPointer: return ("NotifyPointer");
return ("NotifyPointer");
case NotifyPointerRoot: case NotifyPointerRoot: return ("NotifyPointerRoot");
return ("NotifyPointerRoot");
case NotifyDetailNone: case NotifyDetailNone: return ("NotifyDetailNone");
return ("NotifyDetailNone");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a configure detail */ /* Returns the string equivalent of a configure detail */
static char *ConfigureDetail(detail) static char* ConfigureDetail(detail) int detail;
int detail;
{ {
switch (detail) { switch (detail) {
case Above: case Above: return ("Above");
return ("Above");
case Below: case Below: return ("Below");
return ("Below");
case TopIf: case TopIf: return ("TopIf");
return ("TopIf");
case BottomIf: case BottomIf: return ("BottomIf");
return ("BottomIf");
case Opposite: case Opposite: return ("Opposite");
return ("Opposite");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a grab mode */ /* Returns the string equivalent of a grab mode */
static char *GrabMode(mode) static char* GrabMode(mode) int mode;
int mode;
{ {
switch (mode) { switch (mode) {
case NotifyNormal: case NotifyNormal: return ("NotifyNormal");
return ("NotifyNormal");
case NotifyGrab: case NotifyGrab: return ("NotifyGrab");
return ("NotifyGrab");
case NotifyUngrab: case NotifyUngrab: return ("NotifyUngrab");
return ("NotifyUngrab");
case NotifyWhileGrabbed: case NotifyWhileGrabbed: return ("NotifyWhileGrabbed");
return ("NotifyWhileGrabbed");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a mapping request */ /* Returns the string equivalent of a mapping request */
static char *MappingRequest(request) static char* MappingRequest(request) int request;
int request;
{ {
switch (request) { switch (request) {
case MappingModifier: case MappingModifier: return ("MappingModifier");
return ("MappingModifier");
case MappingKeyboard: case MappingKeyboard: return ("MappingKeyboard");
return ("MappingKeyboard");
case MappingPointer: case MappingPointer: return ("MappingPointer");
return ("MappingPointer");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a stacking order place */ /* Returns the string equivalent of a stacking order place */
static char *Place(place) static char* Place(place) int place;
int place;
{ {
switch (place) { switch (place) {
case PlaceOnTop: case PlaceOnTop: return ("PlaceOnTop");
return ("PlaceOnTop");
case PlaceOnBottom: case PlaceOnBottom: return ("PlaceOnBottom");
return ("PlaceOnBottom");
default: default: return ("?");
return ("?");
} }
} }
/* Returns the string equivalent of a major code */ /* Returns the string equivalent of a major code */
static char *MajorCode(code) static char* MajorCode(code) int code;
int code;
{ {
static char buffer[32]; static char buffer[32];
switch (code) { switch (code) {
case X_CopyArea: case X_CopyArea: return ("X_CopyArea");
return ("X_CopyArea");
case X_CopyPlane: case X_CopyPlane: return ("X_CopyPlane");
return ("X_CopyPlane");
default: default: sprintf(buffer, "0x%x", code); return (buffer);
sprintf(buffer, "0x%x", code);
return (buffer);
} }
} }
/* Returns the string equivalent the keycode contained in the key event */ /* Returns the string equivalent the keycode contained in the key event */
static char *Keycode(ev) static char* Keycode(ev) XKeyEvent* ev;
XKeyEvent *ev;
{ {
static char buffer[256]; static char buffer[256];
KeySym keysym_str; KeySym keysym_str;
@ -383,19 +320,22 @@ XKeyEvent *ev;
keysym_name = "NoSymbol"; keysym_name = "NoSymbol";
else if (!(keysym_name = XKeysymToString(keysym_str))) else if (!(keysym_name = XKeysymToString(keysym_str)))
keysym_name = "(no name)"; keysym_name = "(no name)";
sprintf(buffer, "%u (keysym 0x%x \"%s\")", sprintf(
ev->keycode, (unsigned)keysym_str, keysym_name); buffer,
"%u (keysym 0x%x \"%s\")",
ev->keycode,
(unsigned)keysym_str,
keysym_name);
return (buffer); return (buffer);
} }
/* Returns the string equivalent of an atom or "None"*/ /* Returns the string equivalent of an atom or "None"*/
static char *AtomName(Display *dpy, Atom atom) static char*
{ AtomName(Display* dpy, Atom atom) {
static char buffer[256]; static char buffer[256];
char* atom_name; char* atom_name;
if (atom == None) if (atom == None) return ("None");
return ("None");
atom_name = XGetAtomName(dpy, atom); atom_name = XGetAtomName(dpy, atom);
strncpy(buffer, atom_name, 256); strncpy(buffer, atom_name, 256);
@ -407,8 +347,8 @@ static char *AtomName(Display *dpy, Atom atom)
/**** Routines to print out readable values for the field of various events ***/ /**** Routines to print out readable values for the field of various events ***/
/******************************************************************************/ /******************************************************************************/
static void VerbMotion(XMotionEvent *ev) static void
{ VerbMotion(XMotionEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("root=0x%x%s", (unsigned)ev->root, sep); printf("root=0x%x%s", (unsigned)ev->root, sep);
printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
@ -420,8 +360,8 @@ static void VerbMotion(XMotionEvent *ev)
printf("same_screen=%s\n", TorF(ev->same_screen)); printf("same_screen=%s\n", TorF(ev->same_screen));
} }
static void VerbButton(XButtonEvent *ev) static void
{ VerbButton(XButtonEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("root=0x%x%s", (unsigned)ev->root, sep); printf("root=0x%x%s", (unsigned)ev->root, sep);
printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
@ -433,16 +373,16 @@ static void VerbButton(XButtonEvent *ev)
printf("same_screen=%s\n", TorF(ev->same_screen)); printf("same_screen=%s\n", TorF(ev->same_screen));
} }
static void VerbColormap(XColormapEvent *ev) static void
{ VerbColormap(XColormapEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("colormap=%s%s", MaybeNone(ev->colormap), sep); printf("colormap=%s%s", MaybeNone(ev->colormap), sep);
printf("new=%s%s", TorF(ev->new), sep); printf("new=%s%s", TorF(ev->new), sep);
printf("state=%s\n", ColormapState(ev->state)); printf("state=%s\n", ColormapState(ev->state));
} }
static void VerbCrossing(XCrossingEvent *ev) static void
{ VerbCrossing(XCrossingEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("root=0x%x%s", (unsigned)ev->root, sep); printf("root=0x%x%s", (unsigned)ev->root, sep);
printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
@ -456,16 +396,16 @@ static void VerbCrossing(XCrossingEvent *ev)
printf("state=%s\n", ButtonAndOrModifierState(ev->state)); printf("state=%s\n", ButtonAndOrModifierState(ev->state));
} }
static void VerbExpose(XExposeEvent *ev) static void
{ VerbExpose(XExposeEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
printf("width=%d height=%d%s", ev->width, ev->height, sep); printf("width=%d height=%d%s", ev->width, ev->height, sep);
printf("count=%d\n", ev->count); printf("count=%d\n", ev->count);
} }
static void VerbGraphicsExpose(XGraphicsExposeEvent *ev) static void
{ VerbGraphicsExpose(XGraphicsExposeEvent* ev) {
printf("drawable=0x%x%s", (unsigned)ev->drawable, sep); printf("drawable=0x%x%s", (unsigned)ev->drawable, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
printf("width=%d height=%d%s", ev->width, ev->height, sep); printf("width=%d height=%d%s", ev->width, ev->height, sep);
@ -473,33 +413,32 @@ static void VerbGraphicsExpose(XGraphicsExposeEvent *ev)
printf("minor_code=%d\n", ev->minor_code); printf("minor_code=%d\n", ev->minor_code);
} }
static void VerbNoExpose(XNoExposeEvent *ev) static void
{ VerbNoExpose(XNoExposeEvent* ev) {
printf("drawable=0x%x%s", (unsigned)ev->drawable, sep); printf("drawable=0x%x%s", (unsigned)ev->drawable, sep);
printf("major_code=%s%s", MajorCode(ev->major_code), sep); printf("major_code=%s%s", MajorCode(ev->major_code), sep);
printf("minor_code=%d\n", ev->minor_code); printf("minor_code=%d\n", ev->minor_code);
} }
static void VerbFocus(XFocusChangeEvent *ev) static void
{ VerbFocus(XFocusChangeEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("mode=%s%s", GrabMode(ev->mode), sep); printf("mode=%s%s", GrabMode(ev->mode), sep);
printf("detail=%s\n", FocusChangeDetail(ev->detail)); printf("detail=%s\n", FocusChangeDetail(ev->detail));
} }
static void VerbKeymap(XKeymapEvent *ev) static void
{ VerbKeymap(XKeymapEvent* ev) {
int i; int i;
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("key_vector="); printf("key_vector=");
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++) printf("%02x", ev->key_vector[i]);
printf("%02x", ev->key_vector[i]);
printf("\n"); printf("\n");
} }
static void VerbKey(XKeyEvent *ev) static void
{ VerbKey(XKeyEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("root=0x%x%s", (unsigned)ev->root, sep); printf("root=0x%x%s", (unsigned)ev->root, sep);
printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep); printf("subwindow=0x%x%s", (unsigned)ev->subwindow, sep);
@ -511,29 +450,29 @@ static void VerbKey(XKeyEvent *ev)
printf("same_screen=%s\n", TorF(ev->same_screen)); printf("same_screen=%s\n", TorF(ev->same_screen));
} }
static void VerbProperty(XPropertyEvent *ev) static void
{ VerbProperty(XPropertyEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("atom=%s%s", AtomName(ev->display, ev->atom), sep); printf("atom=%s%s", AtomName(ev->display, ev->atom), sep);
printf("time=%s%s", ServerTime(ev->time), sep); printf("time=%s%s", ServerTime(ev->time), sep);
printf("state=%s\n", PropertyState(ev->state)); printf("state=%s\n", PropertyState(ev->state));
} }
static void VerbResizeRequest(XResizeRequestEvent *ev) static void
{ VerbResizeRequest(XResizeRequestEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("width=%d height=%d\n", ev->width, ev->height); printf("width=%d height=%d\n", ev->width, ev->height);
} }
static void VerbCirculate(XCirculateEvent *ev) static void
{ VerbCirculate(XCirculateEvent* ev) {
printf("event=0x%x%s", (unsigned)ev->event, sep); printf("event=0x%x%s", (unsigned)ev->event, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("place=%s\n", Place(ev->place)); printf("place=%s\n", Place(ev->place));
} }
static void VerbConfigure(XConfigureEvent *ev) static void
{ VerbConfigure(XConfigureEvent* ev) {
printf("event=0x%x%s", (unsigned)ev->event, sep); printf("event=0x%x%s", (unsigned)ev->event, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
@ -543,8 +482,8 @@ static void VerbConfigure(XConfigureEvent *ev)
printf("override_redirect=%s\n", TorF(ev->override_redirect)); printf("override_redirect=%s\n", TorF(ev->override_redirect));
} }
static void VerbCreateWindow(XCreateWindowEvent *ev) static void
{ VerbCreateWindow(XCreateWindowEvent* ev) {
printf("parent=0x%x%s", (unsigned)ev->parent, sep); printf("parent=0x%x%s", (unsigned)ev->parent, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
@ -553,28 +492,28 @@ static void VerbCreateWindow(XCreateWindowEvent *ev)
printf("override_redirect=%s\n", TorF(ev->override_redirect)); printf("override_redirect=%s\n", TorF(ev->override_redirect));
} }
static void VerbDestroyWindow(XDestroyWindowEvent *ev) static void
{ VerbDestroyWindow(XDestroyWindowEvent* ev) {
printf("event=0x%x%s", (unsigned)ev->event, sep); printf("event=0x%x%s", (unsigned)ev->event, sep);
printf("window=0x%x\n", (unsigned)ev->window); printf("window=0x%x\n", (unsigned)ev->window);
} }
static void VerbGravity(XGravityEvent *ev) static void
{ VerbGravity(XGravityEvent* ev) {
printf("event=0x%x%s", (unsigned)ev->event, sep); printf("event=0x%x%s", (unsigned)ev->event, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("x=%d y=%d\n", ev->x, ev->y); printf("x=%d y=%d\n", ev->x, ev->y);
} }
static void VerbMap(XMapEvent *ev) static void
{ VerbMap(XMapEvent* ev) {
printf("event=0x%x%s", (unsigned)ev->event, sep); printf("event=0x%x%s", (unsigned)ev->event, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("override_redirect=%s\n", TorF(ev->override_redirect)); printf("override_redirect=%s\n", TorF(ev->override_redirect));
} }
static void VerbReparent(XReparentEvent *ev) static void
{ VerbReparent(XReparentEvent* ev) {
printf("event=0x%x%s", (unsigned)ev->event, sep); printf("event=0x%x%s", (unsigned)ev->event, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("parent=0x%x%s", (unsigned)ev->parent, sep); printf("parent=0x%x%s", (unsigned)ev->parent, sep);
@ -582,22 +521,22 @@ static void VerbReparent(XReparentEvent *ev)
printf("override_redirect=%s\n", TorF(ev->override_redirect)); printf("override_redirect=%s\n", TorF(ev->override_redirect));
} }
static void VerbUnmap(XUnmapEvent *ev) static void
{ VerbUnmap(XUnmapEvent* ev) {
printf("event=0x%x%s", (unsigned)ev->event, sep); printf("event=0x%x%s", (unsigned)ev->event, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("from_configure=%s\n", TorF(ev->from_configure)); printf("from_configure=%s\n", TorF(ev->from_configure));
} }
static void VerbCirculateRequest(XCirculateRequestEvent *ev) static void
{ VerbCirculateRequest(XCirculateRequestEvent* ev) {
printf("parent=0x%x%s", (unsigned)ev->parent, sep); printf("parent=0x%x%s", (unsigned)ev->parent, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("place=%s\n", Place(ev->place)); printf("place=%s\n", Place(ev->place));
} }
static void VerbConfigureRequest(XConfigureRequestEvent *ev) static void
{ VerbConfigureRequest(XConfigureRequestEvent* ev) {
printf("parent=0x%x%s", (unsigned)ev->parent, sep); printf("parent=0x%x%s", (unsigned)ev->parent, sep);
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("x=%d y=%d%s", ev->x, ev->y, sep); printf("x=%d y=%d%s", ev->x, ev->y, sep);
@ -608,42 +547,41 @@ static void VerbConfigureRequest(XConfigureRequestEvent *ev)
printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask)); printf("value_mask=%s\n", ConfigureValueMask(ev->value_mask));
} }
static void VerbMapRequest(XMapRequestEvent *ev) static void
{ VerbMapRequest(XMapRequestEvent* ev) {
printf("parent=0x%x%s", (unsigned)ev->parent, sep); printf("parent=0x%x%s", (unsigned)ev->parent, sep);
printf("window=0x%x\n", (unsigned)ev->window); printf("window=0x%x\n", (unsigned)ev->window);
} }
static void VerbClient(XClientMessageEvent *ev) static void
{ VerbClient(XClientMessageEvent* ev) {
int i; int i;
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep); printf("message_type=%s%s", AtomName(ev->display, ev->message_type), sep);
printf("format=%d\n", ev->format); printf("format=%d\n", ev->format);
printf("data (shown as longs)="); printf("data (shown as longs)=");
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++) printf(" 0x%08lx", ev->data.l[i]);
printf(" 0x%08lx", ev->data.l[i]);
printf("\n"); printf("\n");
} }
static void VerbMapping(XMappingEvent *ev) static void
{ VerbMapping(XMappingEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("request=%s%s", MappingRequest(ev->request), sep); printf("request=%s%s", MappingRequest(ev->request), sep);
printf("first_keycode=0x%x%s", ev->first_keycode, sep); printf("first_keycode=0x%x%s", ev->first_keycode, sep);
printf("count=0x%x\n", ev->count); printf("count=0x%x\n", ev->count);
} }
static void VerbSelectionClear(XSelectionClearEvent *ev) static void
{ VerbSelectionClear(XSelectionClearEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
printf("time=%s\n", ServerTime(ev->time)); printf("time=%s\n", ServerTime(ev->time));
} }
static void VerbSelection(XSelectionEvent *ev) static void
{ VerbSelection(XSelectionEvent* ev) {
printf("requestor=0x%x%s", (unsigned)ev->requestor, sep); printf("requestor=0x%x%s", (unsigned)ev->requestor, sep);
printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
printf("target=%s%s", AtomName(ev->display, ev->target), sep); printf("target=%s%s", AtomName(ev->display, ev->target), sep);
@ -651,8 +589,8 @@ static void VerbSelection(XSelectionEvent *ev)
printf("time=%s\n", ServerTime(ev->time)); printf("time=%s\n", ServerTime(ev->time));
} }
static void VerbSelectionRequest(XSelectionRequestEvent *ev) static void
{ VerbSelectionRequest(XSelectionRequestEvent* ev) {
printf("owner=0x%x%s", (unsigned)ev->owner, sep); printf("owner=0x%x%s", (unsigned)ev->owner, sep);
printf("requestor=0x%x%s", (unsigned)ev->requestor, sep); printf("requestor=0x%x%s", (unsigned)ev->requestor, sep);
printf("selection=%s%s", AtomName(ev->display, ev->selection), sep); printf("selection=%s%s", AtomName(ev->display, ev->selection), sep);
@ -661,8 +599,8 @@ static void VerbSelectionRequest(XSelectionRequestEvent *ev)
printf("time=%s\n", ServerTime(ev->time)); printf("time=%s\n", ServerTime(ev->time));
} }
static void VerbVisibility(XVisibilityEvent *ev) static void
{ VerbVisibility(XVisibilityEvent* ev) {
printf("window=0x%x%s", (unsigned)ev->window, sep); printf("window=0x%x%s", (unsigned)ev->window, sep);
printf("state=%s\n", VisibilityState(ev->state)); printf("state=%s\n", VisibilityState(ev->state));
} }
@ -671,76 +609,42 @@ static void VerbVisibility(XVisibilityEvent *ev)
/************ Return the string representation for type of an event ***********/ /************ Return the string representation for type of an event ***********/
/******************************************************************************/ /******************************************************************************/
char *GetType(ev) char* GetType(ev) XEvent* ev;
XEvent *ev;
{ {
switch (ev->type) { switch (ev->type) {
case KeyPress: case KeyPress: return ("KeyPress");
return ("KeyPress"); case KeyRelease: return ("KeyRelease");
case KeyRelease: case ButtonPress: return ("ButtonPress");
return ("KeyRelease"); case ButtonRelease: return ("ButtonRelease");
case ButtonPress: case MotionNotify: return ("MotionNotify");
return ("ButtonPress"); case EnterNotify: return ("EnterNotify");
case ButtonRelease: case LeaveNotify: return ("LeaveNotify");
return ("ButtonRelease"); case FocusIn: return ("FocusIn");
case MotionNotify: case FocusOut: return ("FocusOut");
return ("MotionNotify"); case KeymapNotify: return ("KeymapNotify");
case EnterNotify: case Expose: return ("Expose");
return ("EnterNotify"); case GraphicsExpose: return ("GraphicsExpose");
case LeaveNotify: case NoExpose: return ("NoExpose");
return ("LeaveNotify"); case VisibilityNotify: return ("VisibilityNotify");
case FocusIn: case CreateNotify: return ("CreateNotify");
return ("FocusIn"); case DestroyNotify: return ("DestroyNotify");
case FocusOut: case UnmapNotify: return ("UnmapNotify");
return ("FocusOut"); case MapNotify: return ("MapNotify");
case KeymapNotify: case MapRequest: return ("MapRequest");
return ("KeymapNotify"); case ReparentNotify: return ("ReparentNotify");
case Expose: case ConfigureNotify: return ("ConfigureNotify");
return ("Expose"); case ConfigureRequest: return ("ConfigureRequest");
case GraphicsExpose: case GravityNotify: return ("GravityNotify");
return ("GraphicsExpose"); case ResizeRequest: return ("ResizeRequest");
case NoExpose: case CirculateNotify: return ("CirculateNotify");
return ("NoExpose"); case CirculateRequest: return ("CirculateRequest");
case VisibilityNotify: case PropertyNotify: return ("PropertyNotify");
return ("VisibilityNotify"); case SelectionClear: return ("SelectionClear");
case CreateNotify: case SelectionRequest: return ("SelectionRequest");
return ("CreateNotify"); case SelectionNotify: return ("SelectionNotify");
case DestroyNotify: case ColormapNotify: return ("ColormapNotify");
return ("DestroyNotify"); case ClientMessage: return ("ClientMessage");
case UnmapNotify: case MappingNotify: return ("MappingNotify");
return ("UnmapNotify");
case MapNotify:
return ("MapNotify");
case MapRequest:
return ("MapRequest");
case ReparentNotify:
return ("ReparentNotify");
case ConfigureNotify:
return ("ConfigureNotify");
case ConfigureRequest:
return ("ConfigureRequest");
case GravityNotify:
return ("GravityNotify");
case ResizeRequest:
return ("ResizeRequest");
case CirculateNotify:
return ("CirculateNotify");
case CirculateRequest:
return ("CirculateRequest");
case PropertyNotify:
return ("PropertyNotify");
case SelectionClear:
return ("SelectionClear");
case SelectionRequest:
return ("SelectionRequest");
case SelectionNotify:
return ("SelectionNotify");
case ColormapNotify:
return ("ColormapNotify");
case ClientMessage:
return ("ClientMessage");
case MappingNotify:
return ("MappingNotify");
} }
return "???"; return "???";
} }
@ -749,8 +653,8 @@ XEvent *ev;
/**************** Print the values of all fields for any event ****************/ /**************** Print the values of all fields for any event ****************/
/******************************************************************************/ /******************************************************************************/
void ShowEvent(XEvent *eev) void
{ ShowEvent(XEvent* eev) {
XAnyEvent* ev = (XAnyEvent*)eev; XAnyEvent* ev = (XAnyEvent*)eev;
/* determine which field separator to use */ /* determine which field separator to use */
if (use_separate_lines) if (use_separate_lines)
@ -764,125 +668,66 @@ void ShowEvent(XEvent *eev)
printf("display=0x%p%s", ev->display, sep); printf("display=0x%p%s", ev->display, sep);
switch (ev->type) { switch (ev->type) {
case MotionNotify: case MotionNotify: VerbMotion((void*)ev); break;
VerbMotion((void*)ev);
break;
case ButtonPress: case ButtonPress:
case ButtonRelease: case ButtonRelease: VerbButton((void*)ev); break;
VerbButton((void*)ev);
break;
case ColormapNotify: case ColormapNotify: VerbColormap((void*)ev); break;
VerbColormap((void*)ev);
break;
case EnterNotify: case EnterNotify:
case LeaveNotify: case LeaveNotify: VerbCrossing((void*)ev); break;
VerbCrossing((void*)ev);
break;
case Expose: case Expose: VerbExpose((void*)ev); break;
VerbExpose((void*)ev);
break;
case GraphicsExpose: case GraphicsExpose: VerbGraphicsExpose((void*)ev); break;
VerbGraphicsExpose((void*)ev);
break;
case NoExpose: case NoExpose: VerbNoExpose((void*)ev); break;
VerbNoExpose((void*)ev);
break;
case FocusIn: case FocusIn:
case FocusOut: case FocusOut: VerbFocus((void*)ev); break;
VerbFocus((void*)ev);
break;
case KeymapNotify: case KeymapNotify: VerbKeymap((void*)ev); break;
VerbKeymap((void*)ev);
break;
case KeyPress: case KeyPress:
case KeyRelease: case KeyRelease: VerbKey((void*)ev); break;
VerbKey((void*)ev);
break;
case PropertyNotify: case PropertyNotify: VerbProperty((void*)ev); break;
VerbProperty((void*)ev);
break;
case ResizeRequest: case ResizeRequest: VerbResizeRequest((void*)ev); break;
VerbResizeRequest((void*)ev);
break;
case CirculateNotify: case CirculateNotify: VerbCirculate((void*)ev); break;
VerbCirculate((void*)ev);
break;
case ConfigureNotify: case ConfigureNotify: VerbConfigure((void*)ev); break;
VerbConfigure((void*)ev);
break;
case CreateNotify: case CreateNotify: VerbCreateWindow((void*)ev); break;
VerbCreateWindow((void*)ev);
break;
case DestroyNotify: case DestroyNotify: VerbDestroyWindow((void*)ev); break;
VerbDestroyWindow((void*)ev);
break;
case GravityNotify: case GravityNotify: VerbGravity((void*)ev); break;
VerbGravity((void*)ev);
break;
case MapNotify: case MapNotify: VerbMap((void*)ev); break;
VerbMap((void*)ev);
break;
case ReparentNotify: case ReparentNotify: VerbReparent((void*)ev); break;
VerbReparent((void*)ev);
break;
case UnmapNotify: case UnmapNotify: VerbUnmap((void*)ev); break;
VerbUnmap((void*)ev);
break;
case CirculateRequest: case CirculateRequest: VerbCirculateRequest((void*)ev); break;
VerbCirculateRequest((void*)ev);
break;
case ConfigureRequest: case ConfigureRequest: VerbConfigureRequest((void*)ev); break;
VerbConfigureRequest((void*)ev);
break;
case MapRequest: case MapRequest: VerbMapRequest((void*)ev); break;
VerbMapRequest((void*)ev);
break;
case ClientMessage: case ClientMessage: VerbClient((void*)ev); break;
VerbClient((void*)ev);
break;
case MappingNotify: case MappingNotify: VerbMapping((void*)ev); break;
VerbMapping((void*)ev);
break;
case SelectionClear: case SelectionClear: VerbSelectionClear((void*)ev); break;
VerbSelectionClear((void*)ev);
break;
case SelectionNotify: case SelectionNotify: VerbSelection((void*)ev); break;
VerbSelection((void*)ev);
break;
case SelectionRequest: case SelectionRequest: VerbSelectionRequest((void*)ev); break;
VerbSelectionRequest((void*)ev);
break;
case VisibilityNotify:
VerbVisibility((void*)ev);
break;
case VisibilityNotify: VerbVisibility((void*)ev); break;
} }
} }

35
showevent/sample.c Executable file → Normal file
View file

@ -5,8 +5,7 @@
* "Quick-n-Dirty", plain, vanilla, "No ups, No extras" piece of code. * "Quick-n-Dirty", plain, vanilla, "No ups, No extras" piece of code.
*/ */
main(argc, argv) main(argc, argv) int argc;
int argc;
char** argv; char** argv;
{ {
Display* dpy; Display* dpy;
@ -21,17 +20,28 @@ char **argv;
} }
screen = DefaultScreen(dpy); screen = DefaultScreen(dpy);
window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100, window = XCreateSimpleWindow(
300, 200, 2, BlackPixel(dpy, screen), WhitePixel(dpy, screen)); dpy,
RootWindow(dpy, screen),
100,
100,
300,
200,
2,
BlackPixel(dpy, screen),
WhitePixel(dpy, screen));
XSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | XSelectInput(
ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | dpy,
PointerMotionMask | PointerMotionHintMask | Button1MotionMask | window,
Button2MotionMask | Button3MotionMask | Button4MotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
Button5MotionMask | ButtonMotionMask | KeymapStateMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
ExposureMask | VisibilityChangeMask | StructureNotifyMask | PointerMotionHintMask | Button1MotionMask | Button2MotionMask |
SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | Button3MotionMask | Button4MotionMask | Button5MotionMask |
PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask); ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask |
StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask |
FocusChangeMask | PropertyChangeMask | ColormapChangeMask |
OwnerGrabButtonMask);
XMapWindow(dpy, window); XMapWindow(dpy, window);
@ -45,4 +55,3 @@ char **argv;
printf("\n\n"); printf("\n\n");
} }
} }

35
xevents.c Executable file → Normal file
View file

@ -9,8 +9,7 @@
#include "printevent.h" #include "printevent.h"
int int
main(int argc, char **argv) main(int argc, char** argv) {
{
int screen; int screen;
Display* dpy; Display* dpy;
Window window; Window window;
@ -23,17 +22,28 @@ main(int argc, char **argv)
screen = DefaultScreen(dpy); screen = DefaultScreen(dpy);
window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100, window = XCreateSimpleWindow(
300, 200, 2, BlackPixel(dpy, screen), WhitePixel(dpy, screen)); dpy,
RootWindow(dpy, screen),
100,
100,
300,
200,
2,
BlackPixel(dpy, screen),
WhitePixel(dpy, screen));
XSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | XSelectInput(
ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | dpy,
PointerMotionMask | PointerMotionHintMask | Button1MotionMask | window,
Button2MotionMask | Button3MotionMask | Button4MotionMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
Button5MotionMask | ButtonMotionMask | KeymapStateMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
ExposureMask | VisibilityChangeMask | StructureNotifyMask | PointerMotionHintMask | Button1MotionMask | Button2MotionMask |
SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | Button3MotionMask | Button4MotionMask | Button5MotionMask |
PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask); ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask |
StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask |
FocusChangeMask | PropertyChangeMask | ColormapChangeMask |
OwnerGrabButtonMask);
XMapWindow(dpy, window); XMapWindow(dpy, window);
@ -42,4 +52,3 @@ main(int argc, char **argv)
printevent(&event); printevent(&event);
} }
} }

139
xshove.c Executable file → Normal file
View file

@ -9,8 +9,7 @@
AUTOLIB(X11); AUTOLIB(X11);
typedef struct Rectangle Rectangle; typedef struct Rectangle Rectangle;
struct Rectangle struct Rectangle {
{
struct { struct {
int x; int x;
int y; int y;
@ -20,8 +19,7 @@ struct Rectangle
#define Dy(r) ((r).max.y - (r).min.y) #define Dy(r) ((r).max.y - (r).min.y)
typedef struct Win Win; typedef struct Win Win;
struct Win struct Win {
{
Window xw; Window xw;
int x; int x;
int y; int y;
@ -45,30 +43,24 @@ int parsewinsize(char*, Rectangle*, int*, int*, int*);
void shove(char*, char*); void shove(char*, char*);
void void
usage(void) usage(void) {
{
fprint(2, "usage: xshove [window rectangle]\n"); fprint(2, "usage: xshove [window rectangle]\n");
exits("usage"); exits("usage");
} }
void void
main(int argc, char **argv) main(int argc, char** argv) {
{
int screen; int screen;
screen = 0; screen = 0;
ARGBEGIN { ARGBEGIN {
case 's': case 's': screen = atoi(EARGF(usage())); break;
screen = atoi(EARGF(usage())); default: usage(); break;
break; }
default: ARGEND
usage();
break;
}ARGEND
dpy = XOpenDisplay(""); dpy = XOpenDisplay("");
if(dpy == nil) if (dpy == nil) sysfatal("open display: %r");
sysfatal("open display: %r");
root = RootWindow(dpy, screen); root = RootWindow(dpy, screen);
getinfo(); getinfo();
@ -77,15 +69,13 @@ main(int argc, char **argv)
listwindows(); listwindows();
exits(0); exits(0);
} }
if(argc != 2) if (argc != 2) usage();
usage();
shove(argv[0], argv[1]); shove(argv[0], argv[1]);
exits(0); exits(0);
} }
char* char*
getproperty(Window w, Atom a) getproperty(Window w, Atom a) {
{
uchar* p; uchar* p;
int fmt; int fmt;
Atom type; Atom type;
@ -93,54 +83,45 @@ getproperty(Window w, Atom a)
n = 100; n = 100;
p = nil; p = nil;
XGetWindowProperty(dpy, w, a, 0, 100L, 0, XGetWindowProperty(
AnyPropertyType, &type, &fmt, dpy, w, a, 0, 100L, 0, AnyPropertyType, &type, &fmt, &n, &dummy, &p);
&n, &dummy, &p); if (p == nil || *p == 0) return nil;
if(p == nil || *p == 0)
return nil;
return strdup((char*)p); return strdup((char*)p);
} }
Window Window
findname(Window w) findname(Window w) {
{
int i; int i;
uint nxwin; uint nxwin;
Window dw1, dw2, *xwin; Window dw1, dw2, *xwin;
if(getproperty(w, XA_WM_NAME)) if (getproperty(w, XA_WM_NAME)) return w;
return w; if (!XQueryTree(dpy, w, &dw1, &dw2, &xwin, &nxwin)) return 0;
if(!XQueryTree(dpy, w, &dw1, &dw2, &xwin, &nxwin))
return 0;
for (i = 0; i < nxwin; i++) for (i = 0; i < nxwin; i++)
if((w = findname(xwin[i])) != 0) if ((w = findname(xwin[i])) != 0) return w;
return w;
return 0; return 0;
} }
void void
getinfo(void) getinfo(void) {
{
int i; int i;
uint nxwin; uint nxwin;
Window dw1, dw2, *xwin; Window dw1, dw2, *xwin;
XClassHint class; XClassHint class;
XWindowAttributes attr; XWindowAttributes attr;
if(!XQueryTree(dpy, root, &dw1, &dw2, &xwin, &nxwin)) if (!XQueryTree(dpy, root, &dw1, &dw2, &xwin, &nxwin)) return;
return;
w = mallocz(nxwin * sizeof w[0], 1); w = mallocz(nxwin * sizeof w[0], 1);
if(w == 0) if (w == 0) sysfatal("malloc: %r");
sysfatal("malloc: %r");
Win* ww = w; Win* ww = w;
for (i = 0; i < nxwin; i++) { for (i = 0; i < nxwin; i++) {
memset(&attr, 0, sizeof attr); memset(&attr, 0, sizeof attr);
xwin[i] = findname(xwin[i]); xwin[i] = findname(xwin[i]);
if(xwin[i] == 0) if (xwin[i] == 0) continue;
continue;
XGetWindowAttributes(dpy, xwin[i], &attr); XGetWindowAttributes(dpy, xwin[i], &attr);
if(attr.width <= 0 || attr.override_redirect || attr.map_state != IsViewable) if (
attr.width <= 0 || attr.override_redirect || attr.map_state != IsViewable)
continue; continue;
ww->xw = xwin[i]; ww->xw = xwin[i];
ww->x = attr.x; ww->x = attr.x;
@ -160,25 +141,26 @@ getinfo(void)
} }
void void
listwindows(void) listwindows(void) {
{
int i; int i;
for (i = 0; i < nw; i++) { for (i = 0; i < nw; i++) {
Win* ww = &w[i]; Win* ww = &w[i];
char rect[50]; char rect[50];
snprint(rect, sizeof rect, "%d,%d,%d,%d", ww->x, ww->y, ww->x+ww->dx, ww->y+ww->dy); snprint(
print("%08x %-20s %-10s %s\n",
(uint)ww->xw,
rect, rect,
ww->instance, sizeof rect,
ww->class); "%d,%d,%d,%d",
ww->x,
ww->y,
ww->x + ww->dx,
ww->y + ww->dy);
print("%08x %-20s %-10s %s\n", (uint)ww->xw, rect, ww->instance, ww->class);
} }
} }
void void
shove(char *name, char *geom) shove(char* name, char* geom) {
{
int i; int i;
int isdelta, havemin, havesize; int isdelta, havemin, havesize;
int old, new; int old, new;
@ -195,8 +177,9 @@ shove(char *name, char *geom)
} }
for (i = 0; i < nw; i++) { for (i = 0; i < nw; i++) {
Win* ww = &w[i]; Win* ww = &w[i];
if(ww->instance && strstr(ww->instance, name) if (
|| ww->class && strstr(ww->class, name)){ ww->instance && strstr(ww->instance, name) ||
ww->class && strstr(ww->class, name)) {
int value_mask; int value_mask;
XWindowChanges e; XWindowChanges e;
@ -223,8 +206,7 @@ shove(char *name, char *geom)
} }
int int
parsewinsize(char *s, Rectangle *r, int *isdelta, int *havemin, int *havesize) parsewinsize(char* s, Rectangle* r, int* isdelta, int* havemin, int* havesize) {
{
char c, *os; char c, *os;
int i, j, k, l; int i, j, k, l;
@ -240,34 +222,26 @@ parsewinsize(char *s, Rectangle *r, int *isdelta, int *havemin, int *havesize)
*havemin = 0; *havemin = 0;
*havesize = 0; *havesize = 0;
memset(r, 0, sizeof *r); memset(r, 0, sizeof *r);
if(!isdigit((uchar)*s)) if (!isdigit((uchar)*s)) goto oops;
goto oops;
i = strtol(s, &s, 0); i = strtol(s, &s, 0);
if (*s == 'x') { if (*s == 'x') {
s++; s++;
if(!isdigit((uchar)*s)) if (!isdigit((uchar)*s)) goto oops;
goto oops;
j = strtol(s, &s, 0); j = strtol(s, &s, 0);
r->max.x = i; r->max.x = i;
r->max.y = j; r->max.y = j;
*havesize = 1; *havesize = 1;
if(*s == 0) if (*s == 0) return 0;
return 0; if (*s != '@') goto oops;
if(*s != '@')
goto oops;
s++; s++;
if(!isdigit((uchar)*s)) if (!isdigit((uchar)*s)) goto oops;
goto oops;
i = strtol(s, &s, 0); i = strtol(s, &s, 0);
if(*s != ',' && *s != ' ') if (*s != ',' && *s != ' ') goto oops;
goto oops;
s++; s++;
if(!isdigit((uchar)*s)) if (!isdigit((uchar)*s)) goto oops;
goto oops;
j = strtol(s, &s, 0); j = strtol(s, &s, 0);
if(*s != 0) if (*s != 0) goto oops;
goto oops;
r->min.x += i; r->min.x += i;
r->max.x += i; r->max.x += i;
r->min.y += j; r->min.y += j;
@ -278,11 +252,9 @@ parsewinsize(char *s, Rectangle *r, int *isdelta, int *havemin, int *havesize)
} }
c = *s; c = *s;
if(c != ' ' && c != ',') if (c != ' ' && c != ',') goto oops;
goto oops;
s++; s++;
if(!isdigit((uchar)*s)) if (!isdigit((uchar)*s)) goto oops;
goto oops;
j = strtol(s, &s, 0); j = strtol(s, &s, 0);
if (*s == 0) { if (*s == 0) {
r->min.x = i; r->min.x = i;
@ -290,20 +262,15 @@ parsewinsize(char *s, Rectangle *r, int *isdelta, int *havemin, int *havesize)
*havemin = 1; *havemin = 1;
return 0; return 0;
} }
if(*s != c) if (*s != c) goto oops;
goto oops;
s++; s++;
if(!isdigit((uchar)*s)) if (!isdigit((uchar)*s)) goto oops;
goto oops;
k = strtol(s, &s, 0); k = strtol(s, &s, 0);
if(*s != c) if (*s != c) goto oops;
goto oops;
s++; s++;
if(!isdigit((uchar)*s)) if (!isdigit((uchar)*s)) goto oops;
goto oops;
l = strtol(s, &s, 0); l = strtol(s, &s, 0);
if(*s != 0) if (*s != 0) goto oops;
goto oops;
r->min.x = i; r->min.x = i;
r->min.y = j; r->min.y = j;
r->max.x = k; r->max.x = k;