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

466
client.c Executable file → Normal file
View file

@ -10,304 +10,296 @@
#include "fns.h" #include "fns.h"
#include "config.h" #include "config.h"
Client *clients; 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);
XSetInputFocus(dpy, c->window, RevertToPointerRoot, timestamp()); XSetInputFocus(dpy, c->window, RevertToPointerRoot, timestamp());
if(c->proto & Ptakefocus) if (c->proto & Ptakefocus)
sendcmessage(c->window, wm_protocols, wm_take_focus, 0, 1); sendcmessage(c->window, wm_protocols, wm_take_focus, 0, 1);
cmapfocus(c); cmapfocus(c);
}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,
draw_border(c, on); AnyModifier,
c->parent,
False,
ButtonMask,
GrabModeAsync,
GrabModeSync,
None,
None);
}
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) {
if(c->hold) if (c->hold)
pixel = c->screen->activeholdborder; pixel = c->screen->activeholdborder;
else else
pixel = c->screen->activeborder; pixel = c->screen->activeborder;
}else{ } else {
if(c->hold) if (c->hold)
pixel = c->screen->inactiveholdborder; pixel = c->screen->inactiveholdborder;
else else
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)
XSetWindowBackground(dpy, c->parent, pixel); fprintf(
XClearWindow(dpy, c->parent); stderr,
"draw_border %p pixel %ld active %d hold %d\n",
(void*)c,
pixel,
active,
c->hold);
XSetWindowBackground(dpy, c->parent, pixel);
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) return;
if(c == current)
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) cc->revert = c->revert;
if(cc->revert == c) c->revert = current;
cc->revert = c->revert; while (c->revert && !normal(c->revert)) c->revert = c->revert->revert;
c->revert = current; current = c;
while(c->revert && !normal(c->revert)) #ifdef DEBUG
c->revert = c->revert->revert; if (debug) dump_revert();
current = c;
#ifdef DEBUG
if(debug)
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; Client* c;
Client *c;
if(current){ if (current) {
setactive(current, 0); setactive(current, 0);
for(c = current->revert; c; c = c->revert) for (c = current->revert; c; c = c->revert)
if(normal(c)){ if (normal(c)) {
active(c); active(c);
return; return;
} }
cmapnofocus(current->screen); cmapnofocus(current->screen);
/* if no candidates to revert to, fall through */ /* if no candidates to revert to, fall through */
} }
current = 0; current = 0;
if(w == 0){ if (w == 0) {
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,
XMapWindow(dpy, w); screens[0].root,
} 0,
XSetInputFocus(dpy, w, RevertToPointerRoot, timestamp()); 0,
1,
1,
0,
0 /*screens[0].depth*/,
InputOnly,
screens[0].vis,
mask,
&attr);
XMapWindow(dpy, w);
}
XSetInputFocus(dpy, w, RevertToPointerRoot, timestamp());
} }
void void
top(Client *c) top(Client* c) {
{ Client **l, *cc;
Client **l, *cc;
l = &clients; l = &clients;
for(cc = *l; cc; cc = *l){ for (cc = *l; cc; cc = *l) {
if(cc == c){ if (cc == c) {
*l = c->next; *l = c->next;
c->next = clients; c->next = clients;
clients = c; clients = c;
return; return;
} }
l = &cc->next; l = &cc->next;
} }
fprintf(stderr, "rio: %p not on client list in top()\n", (void*)c); fprintf(stderr, "rio: %p not on client list in top()\n", (void*)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));
c->window = w; c->window = w;
/* c->parent will be set by the caller */ /* c->parent will be set by the caller */
c->parent = None; c->parent = None;
c->reparenting = 0; c->reparenting = 0;
c->state = WithdrawnState; c->state = WithdrawnState;
c->init = 0; c->init = 0;
c->cmap = None; c->cmap = None;
c->label = c->class = 0; c->label = c->class = 0;
c->revert = 0; c->revert = 0;
c->is9term = 0; c->is9term = 0;
c->hold = 0; c->hold = 0;
c->ncmapwins = 0; c->ncmapwins = 0;
c->cmapwins = 0; c->cmapwins = 0;
c->wmcmaps = 0; c->wmcmaps = 0;
c->next = clients; c->next = clients;
c->virt = virt; c->virt = virt;
clients = c; clients = c;
return c; return c;
} }
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) cc->next = cc->next->next;
if(cc->next == c)
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) {
current = c->revert; current = c->revert;
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); }
} }
} if (c->ncmapwins != 0) {
if(c->ncmapwins != 0){ XFree((char*)c->cmapwins);
XFree((char *)c->cmapwins); free((char*)c->wmcmaps);
free((char *)c->wmcmaps); }
} if (c->iconname != 0) XFree((char*)c->iconname);
if(c->iconname != 0) if (c->name != 0) XFree((char*)c->name);
XFree((char*) c->iconname); if (c->instance != 0) XFree((char*)c->instance);
if(c->name != 0) if (c->class != 0) XFree((char*)c->class);
XFree((char*) c->name); memset(c, 0, sizeof(Client)); /* paranoia */
if(c->instance != 0) free(c);
XFree((char*) c->instance);
if(c->class != 0)
XFree((char*) c->class);
memset(c, 0, sizeof(Client)); /* paranoia */
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) fprintf(stderr, "empty");
if(current == 0) fprintf(stderr, "\n");
fprintf(stderr, "empty");
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) return;
if(clients == 0 || clients->next == 0) if (!up) {
return; c = 0;
if(!up){ /*for(c=clients; c->next; c=c->next) */
c = 0; /* ; */
/*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);
}else{ } else {
c = clients; c = clients;
for(l=&clients; *l; l=&(*l)->next) for (l = &clients; *l; l = &(*l)->next)
; ;
clients = c->next; clients = c->next;
*l = c; *l = c;
c->next = 0; c->next = 0;
XLowerWindow(dpy, c->window); XLowerWindow(dpy, c->window);
} }
/* XMapRaised(dpy, clients->parent); */ /* XMapRaised(dpy, clients->parent); */
/* top(clients); */ /* top(clients); */
/* active(clients); */ /* active(clients); */
} }
#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

64
color.c Executable file → Normal file
View file

@ -8,38 +8,38 @@
#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,
int r, g, b; unsigned long def) {
int r, g, b;
r = rgb>>16; r = rgb >> 16;
g = (rgb>>8)&0xFF; g = (rgb >> 8) & 0xFF;
b = rgb&0xFF; b = rgb & 0xFF;
switch(depth){ switch (depth) {
case 1: case 1:
case 2: case 2:
case 4: case 4:
case 8: case 8:
default: default:
/* not going to waste color map entries */ /* not going to waste color map entries */
return def; return def;
case 15: case 15:
r >>= 3; r >>= 3;
g >>= 3; g >>= 3;
b >>= 3; b >>= 3;
return (r<<10) | (g<<5) | b; return (r << 10) | (g << 5) | b;
case 16: case 16:
r >>= 3; r >>= 3;
g >>= 2; g >>= 2;
b >>= 3; b >>= 3;
return (r<<11) | (g<<5) | b; return (r << 11) | (g << 5) | b;
case 24: case 24:
case 32: case 32:
/* try to find byte order */ /* try to find byte order */
if(s->vis->red_mask & 0xff) if (s->vis->red_mask & 0xff)
return (r) | (g<<8) | (b<<16); /* OK on Sun */ return (r) | (g << 8) | (b << 16); /* OK on Sun */
return rgb; return rgb;
} }
} }

28
config.h Executable file → Normal file
View file

@ -15,7 +15,7 @@
#define SMENUFGCOL 0x000000 #define SMENUFGCOL 0x000000
#define SMENUBGCOL 0x1F9B92 #define SMENUBGCOL 0x1F9B92
/* This sets the size ratio for windows spawned via keyboard or /* This sets the size ratio for windows spawned via keyboard or
* center-snapped * center-snapped
*/ */
#define CENTERNUM 2 #define CENTERNUM 2
@ -42,13 +42,13 @@
* Lock = (1<<1) * Lock = (1<<1)
* Control = (1<<2) * Control = (1<<2)
* Mod1 = (1<<3) * Mod1 = (1<<3)
* Mod2 = (1<<4) * Mod2 = (1<<4)
* Mod3 = (1<<5) * Mod3 = (1<<5)
* Mod4 = (1<<6) * Mod4 = (1<<6)
* Mod5 = (1<<7) * Mod5 = (1<<7)
*/ */
#define SHORTCUTMOD Mod4Mask #define SHORTCUTMOD Mod4Mask
#define MODBITS (1<<6) #define MODBITS (1 << 6)
/* Shortcut keys */ /* Shortcut keys */
@ -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\
}

560
cursor.c Executable file → Normal file
View file

@ -7,142 +7,129 @@
#include "fns.h" #include "fns.h"
typedef struct { typedef struct {
int width; int width;
int hot[2]; int hot[2];
unsigned char mask[64]; unsigned char mask[64];
unsigned char fore[64]; unsigned char fore[64];
} Cursordata; } Cursordata;
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,232 +137,227 @@ 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) ScreenInfo* s;
Cursordata *c;
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,
s->bordcurs[BorderN] = XCreateFontCursor(dpy, 138); grey_width,
s->bordcurs[BorderNNE] = XCreateFontCursor(dpy, 136); grey_height,
s->bordcurs[BorderENE] = s->bordcurs[BorderNNE] ; s->black,
s->bordcurs[BorderE] = XCreateFontCursor(dpy, 96); s->white,
s->bordcurs[BorderESE] = XCreateFontCursor(dpy, 14); s->depth);
s->bordcurs[BorderSSE] = s->bordcurs[BorderESE];
s->bordcurs[BorderS] = XCreateFontCursor(dpy, 16); s->bordcurs[BorderN] = XCreateFontCursor(dpy, 138);
s->bordcurs[BorderSSW] = XCreateFontCursor(dpy, 12); s->bordcurs[BorderNNE] = XCreateFontCursor(dpy, 136);
s->bordcurs[BorderWSW] = s->bordcurs[BorderSSW]; s->bordcurs[BorderENE] = s->bordcurs[BorderNNE];
s->bordcurs[BorderW] = XCreateFontCursor(dpy, 70); s->bordcurs[BorderE] = XCreateFontCursor(dpy, 96);
s->bordcurs[BorderWNW] = XCreateFontCursor(dpy, 134); s->bordcurs[BorderESE] = XCreateFontCursor(dpy, 14);
s->bordcurs[BorderNNW] = s->bordcurs[BorderWNW]; s->bordcurs[BorderSSE] = s->bordcurs[BorderESE];
s->bordcurs[BorderS] = XCreateFontCursor(dpy, 16);
s->bordcurs[BorderSSW] = XCreateFontCursor(dpy, 12);
s->bordcurs[BorderWSW] = s->bordcurs[BorderSSW];
s->bordcurs[BorderW] = XCreateFontCursor(dpy, 70);
s->bordcurs[BorderWNW] = XCreateFontCursor(dpy, 134);
s->bordcurs[BorderNNW] = s->bordcurs[BorderWNW];
} }
/* RIO /* RIO
Cursor crosscursor = { Cursor crosscursor = {
{-7, -7}, {-7, -7},
{0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, {0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0,
0x03, 0xC0, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0x03, 0xC0,
0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, }, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, },
{0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, {0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x7F, 0xFE,
0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, } 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, }
}; };
Cursor boxcursor = { Cursor boxcursor = {
{-7, -7}, {-7, -7},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F,
0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, },
{0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, {0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE,
0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00, } 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00, }
}; };
Cursor sightcursor = { Cursor sightcursor = {
{-7, -7}, {-7, -7},
{0x1F, 0xF8, 0x3F, 0xFC, 0x7F, 0xFE, 0xFB, 0xDF, {0x1F, 0xF8, 0x3F, 0xFC, 0x7F, 0xFE, 0xFB, 0xDF,
0xF3, 0xCF, 0xE3, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF, 0xF3, 0xCF, 0xE3, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC7, 0xF3, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC7, 0xF3, 0xCF,
0x7B, 0xDF, 0x7F, 0xFE, 0x3F, 0xFC, 0x1F, 0xF8, }, 0x7B, 0xDF, 0x7F, 0xFE, 0x3F, 0xFC, 0x1F, 0xF8, },
{0x00, 0x00, 0x0F, 0xF0, 0x31, 0x8C, 0x21, 0x84, {0x00, 0x00, 0x0F, 0xF0, 0x31, 0x8C, 0x21, 0x84,
0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE,
0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82,
0x21, 0x84, 0x31, 0x8C, 0x0F, 0xF0, 0x00, 0x00, } 0x21, 0x84, 0x31, 0x8C, 0x0F, 0xF0, 0x00, 0x00, }
}; };
Cursor whitearrow = { Cursor whitearrow = {
{0, 0}, {0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC, {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC,
0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0xF8, 0xFF, 0xFC, 0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0xF8, 0xFF, 0xFC,
0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC,
0xF3, 0xF8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, }, 0xF3, 0xF8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, },
{0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x06, 0xC0, 0x1C, {0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x06, 0xC0, 0x1C,
0xC0, 0x30, 0xC0, 0x30, 0xC0, 0x38, 0xC0, 0x1C, 0xC0, 0x30, 0xC0, 0x30, 0xC0, 0x38, 0xC0, 0x1C,
0xC0, 0x0E, 0xC0, 0x07, 0xCE, 0x0E, 0xDF, 0x1C, 0xC0, 0x0E, 0xC0, 0x07, 0xCE, 0x0E, 0xDF, 0x1C,
0xD3, 0xB8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, } 0xD3, 0xB8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, }
}; };
Cursor query = { Cursor query = {
{-7,-7}, {-7,-7},
{0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, {0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe,
0x7c, 0x7e, 0x78, 0x7e, 0x00, 0xfc, 0x01, 0xf8, 0x7c, 0x7e, 0x78, 0x7e, 0x00, 0xfc, 0x01, 0xf8,
0x03, 0xf0, 0x07, 0xe0, 0x07, 0xc0, 0x07, 0xc0, 0x03, 0xf0, 0x07, 0xe0, 0x07, 0xc0, 0x07, 0xc0,
0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, }, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, },
{0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf8, 0x3c, 0x3c, {0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf8, 0x3c, 0x3c,
0x38, 0x1c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0, 0x38, 0x1c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0,
0x01, 0xe0, 0x03, 0xc0, 0x03, 0x80, 0x03, 0x80, 0x01, 0xe0, 0x03, 0xc0, 0x03, 0x80, 0x03, 0x80,
0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, } 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, }
}; };
Cursor tl = { Cursor tl = {
{-4, -4}, {-4, -4},
{0xfe, 0x00, 0x82, 0x00, 0x8c, 0x00, 0x87, 0xff, {0xfe, 0x00, 0x82, 0x00, 0x8c, 0x00, 0x87, 0xff,
0xa0, 0x01, 0xb0, 0x01, 0xd0, 0x01, 0x11, 0xff, 0xa0, 0x01, 0xb0, 0x01, 0xd0, 0x01, 0x11, 0xff,
0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00,
0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x1f, 0x00, }, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x1f, 0x00, },
{0x00, 0x00, 0x7c, 0x00, 0x70, 0x00, 0x78, 0x00, {0x00, 0x00, 0x7c, 0x00, 0x70, 0x00, 0x78, 0x00,
0x5f, 0xfe, 0x4f, 0xfe, 0x0f, 0xfe, 0x0e, 0x00, 0x5f, 0xfe, 0x4f, 0xfe, 0x0f, 0xfe, 0x0e, 0x00,
0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00,
0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x00, 0x00, } 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x00, 0x00, }
}; };
Cursor t = { Cursor t = {
{-7, -8}, {-7, -8},
{0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x06, 0xc0, {0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x06, 0xc0,
0x1c, 0x70, 0x10, 0x10, 0x0c, 0x60, 0xfc, 0x7f, 0x1c, 0x70, 0x10, 0x10, 0x0c, 0x60, 0xfc, 0x7f,
0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xff, 0xff, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x03, 0x80, 0x0f, 0xe0, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x0f, 0xe0, 0x03, 0x80, 0x03, 0x80,
0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }
}; };
Cursor tr = { Cursor tr = {
{-11, -4}, {-11, -4},
{0x00, 0x7f, 0x00, 0x41, 0x00, 0x31, 0xff, 0xe1, {0x00, 0x7f, 0x00, 0x41, 0x00, 0x31, 0xff, 0xe1,
0x80, 0x05, 0x80, 0x0d, 0x80, 0x0b, 0xff, 0x88, 0x80, 0x05, 0x80, 0x0d, 0x80, 0x0b, 0xff, 0x88,
0x00, 0x88, 0x0, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x0, 0x88, 0x00, 0x88, 0x00, 0x88,
0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0xf8, }, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0xf8, },
{0x00, 0x00, 0x00, 0x3e, 0x00, 0x0e, 0x00, 0x1e, {0x00, 0x00, 0x00, 0x3e, 0x00, 0x0e, 0x00, 0x1e,
0x7f, 0xfa, 0x7f, 0xf2, 0x7f, 0xf0, 0x00, 0x70, 0x7f, 0xfa, 0x7f, 0xf2, 0x7f, 0xf0, 0x00, 0x70,
0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70,
0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x00, } 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x00, }
}; };
Cursor r = { Cursor r = {
{-8, -7}, {-8, -7},
{0x07, 0xc0, 0x04, 0x40, 0x04, 0x40, 0x04, 0x58, {0x07, 0xc0, 0x04, 0x40, 0x04, 0x40, 0x04, 0x58,
0x04, 0x68, 0x04, 0x6c, 0x04, 0x06, 0x04, 0x02, 0x04, 0x68, 0x04, 0x6c, 0x04, 0x06, 0x04, 0x02,
0x04, 0x06, 0x04, 0x6c, 0x04, 0x68, 0x04, 0x58, 0x04, 0x06, 0x04, 0x6c, 0x04, 0x68, 0x04, 0x58,
0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x07, 0xc0, }, 0x04, 0x40, 0x04, 0x40, 0x04, 0x40, 0x07, 0xc0, },
{0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, {0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80,
0x03, 0x90, 0x03, 0x90, 0x03, 0xf8, 0x03, 0xfc, 0x03, 0x90, 0x03, 0x90, 0x03, 0xf8, 0x03, 0xfc,
0x03, 0xf8, 0x03, 0x90, 0x03, 0x90, 0x03, 0x80, 0x03, 0xf8, 0x03, 0x90, 0x03, 0x90, 0x03, 0x80,
0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, } 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, }
}; };
Cursor br = { Cursor br = {
{-11, -11}, {-11, -11},
{0x00, 0xf8, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, {0x00, 0xf8, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88,
0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88, 0x00, 0x88,
0xff, 0x88, 0x80, 0x0b, 0x80, 0x0d, 0x80, 0x05, 0xff, 0x88, 0x80, 0x0b, 0x80, 0x0d, 0x80, 0x05,
0xff, 0xe1, 0x00, 0x31, 0x00, 0x41, 0x00, 0x7f, }, 0xff, 0xe1, 0x00, 0x31, 0x00, 0x41, 0x00, 0x7f, },
{0x00, 0x00, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, {0x00, 0x00, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70,
0x0, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x0, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70,
0x00, 0x70, 0x7f, 0xf0, 0x7f, 0xf2, 0x7f, 0xfa, 0x00, 0x70, 0x7f, 0xf0, 0x7f, 0xf2, 0x7f, 0xfa,
0x00, 0x1e, 0x00, 0x0e, 0x00, 0x3e, 0x00, 0x00, } 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x3e, 0x00, 0x00, }
}; };
Cursor b = { Cursor b = {
{-7, -7}, {-7, -7},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xff, 0xff, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
0xfc, 0x7f, 0x0c, 0x60, 0x10, 0x10, 0x1c, 0x70, 0xfc, 0x7f, 0x0c, 0x60, 0x10, 0x10, 0x1c, 0x70,
0x06, 0xc0, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, }, 0x06, 0xc0, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, },
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe,
0x03, 0x80, 0x03, 0x80, 0x0f, 0xe0, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x0f, 0xe0, 0x03, 0x80,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }
}; };
Cursor bl = { Cursor bl = {
{-4, -11}, {-4, -11},
{0x1f, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, {0x1f, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00,
0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00,
0x11, 0xff, 0xd0, 0x01, 0xb0, 0x01, 0xa0, 0x01, 0x11, 0xff, 0xd0, 0x01, 0xb0, 0x01, 0xa0, 0x01,
0x87, 0xff, 0x8c, 0x00, 0x82, 0x00, 0xfe, 0x00, }, 0x87, 0xff, 0x8c, 0x00, 0x82, 0x00, 0xfe, 0x00, },
{0x00, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, {0x00, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00,
0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x0e, 0x00,
0x0e, 0x00, 0x0f, 0xfe, 0x4f, 0xfe, 0x5f, 0xfe, 0x0e, 0x00, 0x0f, 0xfe, 0x4f, 0xfe, 0x5f, 0xfe,
0x78, 0x00, 0x70, 0x00, 0x7c, 0x00, 0x00, 0x0, } 0x78, 0x00, 0x70, 0x00, 0x7c, 0x00, 0x00, 0x0, }
}; };
Cursor l = { Cursor l = {
{-7, -7}, {-7, -7},
{0x03, 0xe0, 0x02, 0x20, 0x02, 0x20, 0x1a, 0x20, {0x03, 0xe0, 0x02, 0x20, 0x02, 0x20, 0x1a, 0x20,
0x16, 0x20, 0x36, 0x20, 0x60, 0x20, 0x40, 0x20, 0x16, 0x20, 0x36, 0x20, 0x60, 0x20, 0x40, 0x20,
0x60, 0x20, 0x36, 0x20, 0x16, 0x20, 0x1a, 0x20, 0x60, 0x20, 0x36, 0x20, 0x16, 0x20, 0x1a, 0x20,
0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x03, 0xe0, }, 0x02, 0x20, 0x02, 0x20, 0x02, 0x20, 0x03, 0xe0, },
{0x00, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, {0x00, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0,
0x09, 0xc0, 0x09, 0xc0, 0x1f, 0xc0, 0x3f, 0xc0, 0x09, 0xc0, 0x09, 0xc0, 0x1f, 0xc0, 0x3f, 0xc0,
0x1f, 0xc0, 0x09, 0xc0, 0x09, 0xc0, 0x01, 0xc0, 0x1f, 0xc0, 0x09, 0xc0, 0x09, 0xc0, 0x01, 0xc0,
0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, } 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, }
}; };
Cursor *corners[9] = { Cursor *corners[9] = {
&tl, &t, &tr, &tl, &t, &tr,
&l, nil, &r, &l, nil, &r,
&bl, &b, &br &bl, &b, &br
}; };
*/ */

292
dat.h Executable file → Normal file
View file

@ -1,28 +1,28 @@
/* Copyright (c) 1994-1996 David Hogan, see README for licence details */ /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
#ifndef BORDER #ifndef BORDER
#define BORDER _border #define BORDER _border
#endif #endif
#define CORNER _corner #define CORNER _corner
#define INSET _inset #define INSET _inset
#define MAXHIDDEN 128 #define MAXHIDDEN 128
#ifdef SHOWSTICK #ifdef SHOWSTICK
#define B3FIXED 6 #define B3FIXED 6
#else #else
#define B3FIXED 5 #define B3FIXED 5
#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)
#ifdef Plan9 #ifdef Plan9
#define DEFSHELL "/bin/rc" #define DEFSHELL "/bin/rc"
#else #else
#define DEFSHELL "/bin/sh" #define DEFSHELL "/bin/sh"
#endif #endif
typedef struct Client Client; typedef struct Client Client;
@ -30,166 +30,166 @@ typedef struct Menu Menu;
typedef struct ScreenInfo ScreenInfo; typedef struct ScreenInfo ScreenInfo;
struct Client { struct Client {
Window window; Window window;
Window parent; Window parent;
Window trans; Window trans;
Client *next; Client* next;
Client *revert; Client* revert;
int x; int x;
int y; int y;
int dx; int dx;
int dy; int dy;
int border; int border;
XSizeHints size; XSizeHints size;
int min_dx; int min_dx;
int min_dy; int min_dy;
int state; int state;
int init; int init;
int reparenting; int reparenting;
int is9term; int is9term;
int hold; int hold;
int proto; int proto;
int virt; int virt;
char *label; char* label;
char *instance; char* instance;
char *class; char* class;
char *name; char* name;
char *iconname; char* iconname;
Colormap cmap; Colormap cmap;
int ncmapwins; int ncmapwins;
Window *cmapwins; Window* cmapwins;
Colormap *wmcmaps; Colormap* wmcmaps;
ScreenInfo *screen; ScreenInfo* screen;
}; };
#define hidden(c) ((c)->state == IconicState) #define hidden(c) ((c)->state == IconicState)
#define withdrawn(c) ((c)->state == WithdrawnState) #define withdrawn(c) ((c)->state == WithdrawnState)
#define normal(c) ((c)->state == NormalState) #define normal(c) ((c)->state == NormalState)
/* c->proto */ /* c->proto */
#define Pdelete 1 #define Pdelete 1
#define Ptakefocus 2 #define Ptakefocus 2
#define Plosefocus 4 #define Plosefocus 4
struct Menu { struct Menu {
char **item; char** item;
char *(*gen)(); char* (*gen)();
int lasthit; int lasthit;
}; };
enum BorderOrient { enum BorderOrient {
BorderUnknown = 0, /* we depend on this!*/ BorderUnknown = 0, /* we depend on this!*/
BorderN, BorderN,
BorderNNE, BorderNNE,
BorderENE, BorderENE,
BorderE, BorderE,
BorderESE, BorderESE,
BorderSSE, BorderSSE,
BorderS, BorderS,
BorderSSW, BorderSSW,
BorderWSW, BorderWSW,
BorderW, BorderW,
BorderWNW, BorderWNW,
BorderNNW, BorderNNW,
NBorder NBorder
}; };
typedef enum BorderOrient BorderOrient; typedef enum BorderOrient BorderOrient;
struct ScreenInfo { struct ScreenInfo {
int num; int num;
int depth; int depth;
Visual *vis; Visual* vis;
int width; int width;
int height; int height;
Window root; Window root;
Window menuwin; Window menuwin;
Window sweepwin; Window sweepwin;
Colormap def_cmap; Colormap def_cmap;
GC gc; GC gc;
GC gccopy; GC gccopy;
GC gcred; GC gcred;
GC gcsweep; GC gcsweep;
GC gcmenubg; GC gcmenubg;
GC gcmenubgs; GC gcmenubgs;
GC gcmenufg; GC gcmenufg;
GC gcmenufgs; GC gcmenufgs;
unsigned long black; unsigned long black;
unsigned long white; unsigned long white;
unsigned long activeholdborder; unsigned long activeholdborder;
unsigned long inactiveholdborder; unsigned long inactiveholdborder;
unsigned long activeborder; unsigned long activeborder;
unsigned long inactiveborder; unsigned long inactiveborder;
unsigned long red; unsigned long red;
Pixmap bkup[2]; Pixmap bkup[2];
int min_cmaps; int min_cmaps;
Cursor target; Cursor target;
Cursor sweep0; Cursor sweep0;
Cursor boxcurs; Cursor boxcurs;
Cursor arrow; Cursor arrow;
Cursor bordcurs[NBorder]; Cursor bordcurs[NBorder];
Pixmap root_pixmap; Pixmap root_pixmap;
char display[256]; /* arbitrary limit */ char display[256]; /* arbitrary limit */
}; };
/* main.c */ /* main.c */
extern Display *dpy; extern Display* dpy;
extern ScreenInfo *screens; extern ScreenInfo* screens;
extern int num_screens; extern int num_screens;
extern int initting; extern int initting;
extern XFontStruct *font; extern XFontStruct* font;
extern int nostalgia; extern int nostalgia;
extern char **myargv; extern char** myargv;
extern Bool shape; extern Bool shape;
extern char *termprog; extern char* termprog;
extern char *shell; extern char* shell;
extern char *version[]; extern char* version[];
extern int _border; extern int _border;
extern int _corner; extern int _corner;
extern int _inset; extern int _inset;
extern int curtime; extern int curtime;
extern int debug; extern int debug;
extern int solidsweep; extern int solidsweep;
extern int numvirtuals; extern int numvirtuals;
extern int scrolling; extern int scrolling;
extern int ffm; /* focus follows mouse */ extern int ffm; /* focus follows mouse */
extern Atom exit_rio; extern Atom exit_rio;
extern Atom restart_rio; extern Atom restart_rio;
extern Atom wm_state; extern Atom wm_state;
extern Atom wm_change_state; extern Atom wm_change_state;
extern Atom _rio_hold_mode; extern Atom _rio_hold_mode;
extern Atom wm_protocols; extern Atom wm_protocols;
extern Atom wm_delete; extern Atom wm_delete;
extern Atom wm_take_focus; extern Atom wm_take_focus;
extern Atom wm_lose_focus; extern Atom wm_lose_focus;
extern Atom wm_colormaps; extern Atom wm_colormaps;
extern Atom wm_state_fullscreen; extern Atom wm_state_fullscreen;
extern Atom wm_state; extern Atom wm_state;
/* client.c */ /* client.c */
extern Client *clients; extern Client* clients;
extern Client *current; extern Client* current;
extern Client *currents[]; extern Client* currents[];
/* menu.c */ /* menu.c */
extern Client *hiddenc[]; extern Client* hiddenc[];
extern int numhidden; extern int numhidden;
extern char *b2items[]; extern char* b2items[];
extern Menu b2menu; extern Menu b2menu;
extern char *b3items[]; extern char* b3items[];
extern Menu b3menu; extern Menu b3menu;
extern int virt; extern int virt;
/* manage.c */ /* manage.c */
extern int isNew; extern int isNew;
/* error.c */ /* error.c */
extern int ignore_badwindow; extern int ignore_badwindow;
/* key.c and event.c share this */ /* key.c and event.c share this */
extern int kbLaunch; extern int kbLaunch;

132
error.c Executable file → Normal file
View file

@ -8,95 +8,93 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
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"); exit(1);
exit(1);
} }
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) &&
exit(1); (e->error_code == BadAccess)) {
} fprintf(
stderr,
"ryudo: it looks like there's already a window manager running; ryudo "
"not started\n");
exit(1);
}
if(ignore_badwindow && (e->error_code == BadWindow || e->error_code == BadColor)) if (
return 0; ignore_badwindow &&
(e->error_code == BadWindow || e->error_code == BadColor))
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);
if(initting){ if (initting) {
fprintf(stderr, "ryudo: failure during initialisation; aborting\n"); fprintf(stderr, "ryudo: failure during initialisation; aborting\n");
exit(1); exit(1);
} }
return 0; return 0;
} }
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"; fprintf(stderr, "ryudo: %s: grab error: %s\n", f, s);
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);
#endif #endif
} }
#ifdef DEBUG_EV #ifdef DEBUG_EV
#include "showevent/ShowEvent.c" #include "showevent/ShowEvent.c"
#endif #endif
#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) setbuf(stdout, 0);
return; fprintf(stderr, "ryudo: %s: c=%p", s, (void*)c);
setbuf(stdout, 0); if (c)
fprintf(stderr, "ryudo: %s: c=%p", s, (void*)c); fprintf(
if(c) stderr,
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); " x %d y %d dx %d dy %d w 0x%x parent 0x%x",
#ifdef DEBUG_EV c->x,
if(e){ c->y,
fprintf(stderr, "\n\t"); c->dx,
ShowEvent(e); c->dy,
} (int)c->window,
(int)c->parent);
#ifdef DEBUG_EV
if (e) {
fprintf(stderr, "\n\t");
ShowEvent(e);
}
#endif #endif
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
#endif #endif

1000
event.c Executable file → Normal file

File diff suppressed because it is too large Load diff

169
fns.h Executable file → Normal file
View file

@ -1,121 +1,120 @@
/* Copyright (c) 1994-1996 David Hogan, see README for licence details */ /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
#ifdef DEBUG #ifdef DEBUG
#define trace(s, c, e) dotrace((s), (c), (e)) #define trace(s, c, e) dotrace((s), (c), (e))
#else #else
#define trace(s, c, e) #define trace(s, c, e)
#endif #endif
#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();
void initscreen(); void initscreen();
ScreenInfo *getscreen(); ScreenInfo* getscreen();
Time timestamp(); Time timestamp();
void sendcmessage(); void sendcmessage();
void sendconfig(); void sendconfig();
void sighandler(); void sighandler();
void getevent(); void getevent();
void cleanup(); void cleanup();
/* event.c */ /* event.c */
void mainloop(); void mainloop();
void configurereq(); void configurereq();
void mapreq(); void mapreq();
void circulatereq(); void circulatereq();
void unmap(); void unmap();
void newwindow(); void newwindow();
void destroy(); void destroy();
void clientmesg(); void clientmesg();
void cmap(); void cmap();
void property(); void property();
void shapenotify(); void shapenotify();
void enter(); void enter();
void leave(); void leave();
void focusin(); void focusin();
void reparent(); void reparent();
void motionnotify(); void motionnotify();
BorderOrient borderorient(); BorderOrient borderorient();
/* manage.c */ /* manage.c */
int manage(); int manage();
void scanwins(); void scanwins();
void setshape(); void setshape();
void withdraw(); void withdraw();
void gravitate(); void gravitate();
void cmapfocus(); void cmapfocus();
void cmapnofocus(); void cmapnofocus();
void getcmaps(); void getcmaps();
int _getprop(); int _getprop();
char *getprop(); char* getprop();
Window getwprop(); Window getwprop();
int getiprop(); int getiprop();
int getstate(); int getstate();
void setstate(); void setstate();
void setlabel(); void setlabel();
void getproto(); void getproto();
void gettrans(); void gettrans();
/* key.c */ /* key.c */
void keypress(); void keypress();
void keyrelease(); void keyrelease();
void keysetup(); void keysetup();
void quickreshape(Client *c, int x, int y, int dx, int dy); void quickreshape(Client* c, int x, int y, int dx, int dy);
void stickystack(int); void stickystack(int);
void centercurrent(XWindowAttributes ra); void centercurrent(XWindowAttributes ra);
/* menu.c */ /* menu.c */
void button(); void button();
void spawn(); void spawn();
void reshape(); void reshape();
void move(); void move();
void delete(); void delete ();
void hide(); void hide();
void unhide(); void unhide();
void unhidec(); void unhidec();
void renamec(); void renamec();
void button2(); void button2();
void initb2menu(); void initb2menu();
void switch_to(); 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();
void active(); void active();
void nofocus(); void nofocus();
void top(); void top();
Client *getclient(); Client* getclient();
void rmclient(); void rmclient();
void dump_revert(); void dump_revert();
void dump_clients(); void dump_clients();
void shuffle(int); void shuffle(int);
int isautostick(Client* c); int isautostick(Client* c);
/* grab.c */ /* grab.c */
int menuhit(); int menuhit();
Client *selectwin(); Client* selectwin();
int sweep(); int sweep();
int drag(); int drag();
int pull(); int pull();
void getmouse(); void getmouse();
void setmouse(); void setmouse();
/* error.c */ /* error.c */
int handler(); int handler();
void fatal(); void fatal();
void graberror(); void graberror();
void showhints(); void showhints();
void dotrace(); void dotrace();
/* cursor.c */ /* cursor.c */
void initcurs(); void initcurs();
void ShowEvent(XEvent*); void ShowEvent(XEvent*);

1142
grab.c Executable file → Normal file

File diff suppressed because it is too large Load diff

497
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,252 +28,329 @@ 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); int icode = XKeysymToKeycode(dpy, ICON_KEY);
int icode = XKeysymToKeycode(dpy, ICON_KEY); int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY);
int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY); int mcode = XKeysymToKeycode(dpy, MAX_KEY);
int mcode = XKeysymToKeycode(dpy, MAX_KEY); int vcode = XKeysymToKeycode(dpy, MOVE_KEY);
int vcode = XKeysymToKeycode(dpy, MOVE_KEY); int rcode = XKeysymToKeycode(dpy, RESIZE_KEY);
int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); int scode = XKeysymToKeycode(dpy, STICK_KEY);
int scode = XKeysymToKeycode(dpy, STICK_KEY); int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY);
int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY);
int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY); int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_KEY);
int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_KEY); int kcode = XKeysymToKeycode(dpy, SNAPTOP_KEY);
int kcode = XKeysymToKeycode(dpy, SNAPTOP_KEY); int qcode = XKeysymToKeycode(dpy, SNAPTOPLEFT_KEY);
int qcode = XKeysymToKeycode(dpy, SNAPTOPLEFT_KEY); int wcode = XKeysymToKeycode(dpy, SNAPBOTTOMLEFT_KEY);
int wcode = XKeysymToKeycode(dpy, SNAPBOTTOMLEFT_KEY); int ocode = XKeysymToKeycode(dpy, SNAPBOTTOMRIGHT_KEY);
int ocode = XKeysymToKeycode(dpy, SNAPBOTTOMRIGHT_KEY); int pcode = XKeysymToKeycode(dpy, SNAPTOPRIGHT_KEY);
int pcode = XKeysymToKeycode(dpy, SNAPTOPRIGHT_KEY); int ccode = XKeysymToKeycode(dpy, SNAPCENTER_KEY);
int ccode = XKeysymToKeycode(dpy, SNAPCENTER_KEY); int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY);
int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY); int rightcode = XKeysymToKeycode(dpy, NEXTVIRT_KEY);
int rightcode = XKeysymToKeycode(dpy, NEXTVIRT_KEY); int leftcode = XKeysymToKeycode(dpy, PREVVIRT_KEY);
int leftcode = XKeysymToKeycode(dpy, PREVVIRT_KEY);
#ifdef DEVEL #ifdef DEVEL
int tcode = XKeysymToKeycode(dpy, STICKYTOFRONT_KEY); int tcode = XKeysymToKeycode(dpy, STICKYTOFRONT_KEY);
int bcode = XKeysymToKeycode(dpy, STICKYTOBACK_KEY); int bcode = XKeysymToKeycode(dpy, STICKYTOBACK_KEY);
#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 */
*/ int tabcode = XKeysymToKeycode(dpy, XK_Tab);
int tabcode = XKeysymToKeycode(dpy, XK_Tab); int dcode = XKeysymToKeycode(dpy, DESTROY_KEY);
int dcode = XKeysymToKeycode(dpy, DESTROY_KEY); int icode = XKeysymToKeycode(dpy, ICON_KEY);
int icode = XKeysymToKeycode(dpy, ICON_KEY); int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY);
int ucode = XKeysymToKeycode(dpy, UNHIDE_KEY); int mcode = XKeysymToKeycode(dpy, MAX_KEY);
int mcode = XKeysymToKeycode(dpy, MAX_KEY); int vcode = XKeysymToKeycode(dpy, MOVE_KEY);
int vcode = XKeysymToKeycode(dpy, MOVE_KEY); int scode = XKeysymToKeycode(dpy, STICK_KEY);
int scode = XKeysymToKeycode(dpy, STICK_KEY); int rcode = XKeysymToKeycode(dpy, RESIZE_KEY);
int rcode = XKeysymToKeycode(dpy, RESIZE_KEY); int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY);
int slcode = XKeysymToKeycode(dpy, LAUNCH_KEY); int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY);
int hcode = XKeysymToKeycode(dpy, SNAPLEFT_KEY); int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY);
int lcode = XKeysymToKeycode(dpy, SNAPRIGHT_KEY); int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_KEY);
int jcode = XKeysymToKeycode(dpy, SNAPBOTTOM_KEY); int kcode = XKeysymToKeycode(dpy, SNAPTOP_KEY);
int kcode = XKeysymToKeycode(dpy, SNAPTOP_KEY); int qcode = XKeysymToKeycode(dpy, SNAPTOPLEFT_KEY);
int qcode = XKeysymToKeycode(dpy, SNAPTOPLEFT_KEY); int wcode = XKeysymToKeycode(dpy, SNAPBOTTOMLEFT_KEY);
int wcode = XKeysymToKeycode(dpy, SNAPBOTTOMLEFT_KEY); int ocode = XKeysymToKeycode(dpy, SNAPBOTTOMRIGHT_KEY);
int ocode = XKeysymToKeycode(dpy, SNAPBOTTOMRIGHT_KEY); int pcode = XKeysymToKeycode(dpy, SNAPTOPRIGHT_KEY);
int pcode = XKeysymToKeycode(dpy, SNAPTOPRIGHT_KEY); int ccode = XKeysymToKeycode(dpy, SNAPCENTER_KEY);
int ccode = XKeysymToKeycode(dpy, SNAPCENTER_KEY); int rightcode = XKeysymToKeycode(dpy, NEXTVIRT_KEY);
int rightcode = XKeysymToKeycode(dpy, NEXTVIRT_KEY); int leftcode = XKeysymToKeycode(dpy, PREVVIRT_KEY);
int leftcode = XKeysymToKeycode(dpy, PREVVIRT_KEY);
#ifdef DEVEL #ifdef DEVEL
int tcode = XKeysymToKeycode(dpy, STICKYTOFRONT_KEY); int tcode = XKeysymToKeycode(dpy, STICKYTOFRONT_KEY);
int bcode = XKeysymToKeycode(dpy, STICKYTOBACK_KEY); int bcode = XKeysymToKeycode(dpy, STICKYTOBACK_KEY);
#endif #endif
static XWindowAttributes ra;
XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &ra);
static XWindowAttributes 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);
else if(e->keycode == dcode && (e->state&SHORTCUTMOD) == (MODBITS)) else if (e->keycode == dcode && (e->state & SHORTCUTMOD) == (MODBITS))
delete(current, 0); delete (current, 0);
else if (e->keycode == icode && (e->state&SHORTCUTMOD) == (MODBITS)) else if (e->keycode == icode && (e->state & SHORTCUTMOD) == (MODBITS))
hide(current); hide(current);
else if (e->keycode == ucode && (e->state&SHORTCUTMOD) == (MODBITS)) else if (e->keycode == ucode && (e->state & SHORTCUTMOD) == (MODBITS))
unhide(0, 1); unhide(0, 1);
else if (e->keycode == vcode && (e->state&SHORTCUTMOD) == (MODBITS)) else if (e->keycode == vcode && (e->state & SHORTCUTMOD) == (MODBITS))
move(current, Button3); move(current, Button3);
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(
else if (e->keycode == scode && (e->state&SHORTCUTMOD) == (MODBITS)) current, -BORDER, -BORDER, ra.width + 2 * BORDER, ra.height + 2 * BORDER);
stick(current); else if (e->keycode == scode && (e->state & SHORTCUTMOD) == (MODBITS))
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(
else if (e->keycode == lcode && (e->state&SHORTCUTMOD) == (MODBITS)) current, 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 == lcode && (e->state & SHORTCUTMOD) == (MODBITS))
else if (e->keycode == jcode && (e->state&SHORTCUTMOD) == (MODBITS)) quickreshape(
quickreshape(current, GAPSZ, ra.height/2 + 0.5*GAPSZ, ra.width - 2*GAPSZ, ra.height/2 - 1.5*GAPSZ); current,
else if (e->keycode == kcode && (e->state&SHORTCUTMOD) == (MODBITS)) ra.width / 2 + 0.5 * GAPSZ,
quickreshape(current, GAPSZ, GAPSZ, ra.width - 2*GAPSZ, ra.height/2 - 1.5*GAPSZ); GAPSZ,
ra.width / 2 - 1.5 * GAPSZ,
ra.height - 2 * GAPSZ);
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);
else if (e->keycode == kcode && (e->state & SHORTCUTMOD) == (MODBITS))
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(
else if (e->keycode == wcode && (e->state&SHORTCUTMOD) == (MODBITS)) current,
quickreshape(current, GAPSZ, ra.height/2 + 0.5*GAPSZ, ra.width/2 - 1.5*GAPSZ, ra.height/2 - 1.5*GAPSZ); GAPSZ,
else if (e->keycode == ocode && (e->state&SHORTCUTMOD) == (MODBITS)) 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); ra.width / 2 - 1.5 * GAPSZ,
else if (e->keycode == pcode && (e->state&SHORTCUTMOD) == (MODBITS)) 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); 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);
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);
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);
/* center snap */ /* center snap */
else if (e->keycode == ccode && (e->state&SHORTCUTMOD) == (MODBITS)){ else if (e->keycode == ccode && (e->state & SHORTCUTMOD) == (MODBITS)) {
centercurrent(ra); centercurrent(ra);
}
#ifdef DEVEL
/* manage autostuck windows */
if (e->keycode == tcode && (e->state&SHORTCUTMOD) == (MODBITS))
stickystack(1);
if (e->keycode == bcode && (e->state&SHORTCUTMOD) == (MODBITS))
stickystack(0);
#endif
/* launch */
if (e->keycode == slcode && (e->state&SHORTCUTMOD) == (MODBITS)){
kbLaunch = 1;
if(fork() == 0){
close(ConnectionNumber(dpy));
if(dpy != '\0')
putenv(dpy);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
if(termprog != NULL){
execl(shell, shell, "-c", termprog, (char*)0);
fprintf(stderr, "ryudo: exec %s", shell);
perror(" failed");
}
execlp("urxvt", "urxvt", (char*)0);
execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
execlp("xterm", "xterm", "-ut", (char*)0);
perror("ryudo: exec urxvt/9term/xterm failed");
}
} }
/* switch virts */ #ifdef DEVEL
if (e->keycode == rightcode && (e->state&SHORTCUTMOD) == (MODBITS)) /* manage autostuck windows */
if (numvirtuals > 1) if (e->keycode == tcode && (e->state & SHORTCUTMOD) == (MODBITS))
if (virt < numvirtuals - 1) stickystack(1);
switch_to(virt + 1); if (e->keycode == bcode && (e->state & SHORTCUTMOD) == (MODBITS))
else stickystack(0);
switch_to(0); #endif
if (e->keycode == leftcode && (e->state&SHORTCUTMOD) == (MODBITS)) /* launch */
if (numvirtuals >1) if (e->keycode == slcode && (e->state & SHORTCUTMOD) == (MODBITS)) {
if (virt > 0) kbLaunch = 1;
switch_to(virt - 1); if (fork() == 0) {
else close(ConnectionNumber(dpy));
switch_to(numvirtuals - 1); if (dpy != '\0') putenv(dpy);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
if (termprog != NULL) {
execl(shell, shell, "-c", termprog, (char*)0);
fprintf(stderr, "ryudo: exec %s", shell);
perror(" failed");
}
execlp("urxvt", "urxvt", (char*)0);
execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
execlp("xterm", "xterm", "-ut", (char*)0);
perror("ryudo: exec urxvt/9term/xterm failed");
}
}
XAllowEvents(dpy, SyncKeyboard, e->time); /* switch virts */
if (e->keycode == rightcode && (e->state & SHORTCUTMOD) == (MODBITS))
if (numvirtuals > 1)
if (virt < numvirtuals - 1)
switch_to(virt + 1);
else
switch_to(0);
if (e->keycode == leftcode && (e->state & SHORTCUTMOD) == (MODBITS))
if (numvirtuals > 1)
if (virt > 0)
switch_to(virt - 1);
else
switch_to(numvirtuals - 1);
XAllowEvents(dpy, SyncKeyboard, e->time);
} }
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) XMoveResizeWindow(dpy, c->parent, x, y, dx, dy);
return; c->x = x + BORDER;
XMoveResizeWindow(dpy, c->parent, x,y, dx, dy); c->y = y + BORDER;
c->x = x + BORDER; c->dx = dx - 2 * BORDER;
c->y = y + BORDER; c->dy = dy - 2 * BORDER;
c->dx = dx-2*BORDER; XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy);
c->dy = dy-2*BORDER; sendconfig(c);
XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy);
sendconfig(c);
} }
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(
#else current,
quickreshape(current, centeroffsetnum*ra.width/centerofsetden, centeroffsetnum*ra.height/centeroffsetden, CENTERNUM*ra.width/CENTERDEN, CENTERNUM*ra.height/CENTERDEN); centeroffsetnum * ra.width / centeroffsetden,
#endif GAPSZ,
CENTERNUM * ra.width / CENTERDEN,
ra.height - 2 * GAPSZ);
#else
quickreshape(
current,
centeroffsetnum * ra.width / centerofsetden,
centeroffsetnum * ra.height / centeroffsetden,
CENTERNUM * ra.width / CENTERDEN,
CENTERNUM * ra.height / CENTERDEN);
#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)) top(c);
if(c && isautostick(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);
} }
} }
} }

835
main.c Executable file → Normal file
View file

@ -17,510 +17,501 @@
#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;
int initting; int initting;
XFontStruct *font; XFontStruct* font;
int nostalgia; int nostalgia;
char **myargv; char** myargv;
char *termprog; char* termprog;
char *shell; char* shell;
Bool shape; Bool shape;
int _border = 4; int _border = 4;
int _corner = 25; int _corner = 25;
int _inset = 1; int _inset = 1;
int curtime; int curtime;
int debug; int debug;
int signalled; int signalled;
int scrolling; int scrolling;
int num_screens; int num_screens;
int solidsweep = 0; int solidsweep = 0;
int numvirtuals = 0; int numvirtuals = 0;
int ffm = 0; int ffm = 0;
int kbLaunch = 0; int kbLaunch = 0;
Atom exit_rio; Atom exit_rio;
Atom restart_rio; Atom restart_rio;
Atom wm_state; Atom wm_state;
Atom wm_change_state; Atom wm_change_state;
Atom wm_protocols; Atom wm_protocols;
Atom wm_delete; Atom wm_delete;
Atom wm_take_focus; Atom wm_take_focus;
Atom wm_lose_focus; Atom wm_lose_focus;
Atom wm_colormaps; Atom wm_colormaps;
Atom _rio_running; Atom _rio_running;
Atom _rio_hold_mode; Atom _rio_hold_mode;
Atom wm_state_fullscreen; Atom wm_state_fullscreen;
Atom wm_state; 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,
exit(1); "usage: ryudo [-ffm] [-font fname] [-s] [-term prog] [-version] [-virtuals "
"num] [exit|restart]\n");
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;
#ifdef SHAPE #ifdef SHAPE
int dummy; int dummy;
#endif #endif
shape_event = 0; shape_event = 0;
myargv = argv; /* for restart */ myargv = argv; /* for restart */
do_exit = do_restart = 0; do_exit = do_restart = 0;
font = 0; font = 0;
fname = 0; fname = 0;
for(i = 1; i < argc; i++) for (i = 1; i < argc; i++)
if(strcmp(argv[i], "-nostalgia") == 0) if (strcmp(argv[i], "-nostalgia") == 0)
nostalgia++; nostalgia++;
else if(strcmp(argv[i], "-debug") == 0) else if (strcmp(argv[i], "-debug") == 0)
debug++; debug++;
else if(strcmp(argv[i], "-ffm") == 0) else if (strcmp(argv[i], "-ffm") == 0)
ffm++; ffm++;
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(
fprintf(stderr, "ryudo: wrong number of virtual displays, defaulting to 4\n"); 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) {
} scrolling = 1;
else if(strcmp(argv[i], "-s") == 0){ } else if (argv[i][0] == '-')
scrolling = 1; usage();
} else
else if(argv[i][0] == '-') break;
usage(); for (; i < argc; i++)
else if (strcmp(argv[i], "exit") == 0)
break; do_exit++;
for(; i < argc; i++) else if (strcmp(argv[i], "restart") == 0)
if(strcmp(argv[i], "exit") == 0) do_restart++;
do_exit++; else
else if(strcmp(argv[i], "restart") == 0) usage();
do_restart++;
else
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);
curtime = -1; /* don't care */ curtime = -1; /* don't care */
if(do_exit){ if (do_exit) {
sendcmessage(DefaultRootWindow(dpy), exit_rio, 0L, 1, 1); sendcmessage(DefaultRootWindow(dpy), exit_rio, 0L, 1, 1);
XSync(dpy, False); XSync(dpy, False);
exit(0); exit(0);
} }
if(do_restart){ if (do_restart) {
sendcmessage(DefaultRootWindow(dpy), restart_rio, 0L, 1, 1); sendcmessage(DefaultRootWindow(dpy), restart_rio, 0L, 1, 1);
XSync(dpy, False); XSync(dpy, False);
exit(0); exit(0);
} }
if(0) XSynchronize(dpy, True); if (0) XSynchronize(dpy, True);
wm_state = XInternAtom(dpy, "WM_STATE", False); wm_state = XInternAtom(dpy, "WM_STATE", False);
wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False); wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False);
wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False); wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False); wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False); wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
wm_lose_focus = XInternAtom(dpy, "_9WM_LOSE_FOCUS", False); wm_lose_focus = XInternAtom(dpy, "_9WM_LOSE_FOCUS", False);
wm_colormaps = XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); wm_colormaps = XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False);
_rio_running = XInternAtom(dpy, "_9WM_RUNNING", False); _rio_running = XInternAtom(dpy, "_9WM_RUNNING", False);
_rio_hold_mode = XInternAtom(dpy, "_9WM_HOLD_MODE", False); _rio_hold_mode = XInternAtom(dpy, "_9WM_HOLD_MODE", False);
wm_state = XInternAtom(dpy, "_NET_WM_STATE", False); wm_state = XInternAtom(dpy, "_NET_WM_STATE", False);
wm_state_fullscreen = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); wm_state_fullscreen = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
if(fname != 0) if (fname != 0)
if((font = XLoadQueryFont(dpy, fname)) == 0) if ((font = XLoadQueryFont(dpy, fname)) == 0)
fprintf(stderr, "ryudo: warning: can't load font %s\n", fname); fprintf(stderr, "ryudo: warning: can't load font %s\n", fname);
if(font == 0){ if (font == 0) {
i = 0; i = 0;
for(;;){ for (;;) {
fname = fontlist[i++]; fname = fontlist[i++];
if(fname == 0){ if (fname == 0) {
fprintf(stderr, "ryudo: warning: can't find a font\n"); fprintf(stderr, "ryudo: warning: can't find a font\n");
break; break;
} }
font = XLoadQueryFont(dpy, fname); font = XLoadQueryFont(dpy, fname);
if(font != 0) if (font != 0) break;
break; }
} }
} if (nostalgia) {
if(nostalgia){ _border--;
_border--; _inset--;
_inset--; }
}
#ifdef SHAPE #ifdef SHAPE
shape = XShapeQueryExtension(dpy, &shape_event, &dummy); shape = XShapeQueryExtension(dpy, &shape_event, &dummy);
#endif #endif
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);
/* set selection so that 9term knows we're running */ /* set selection so that 9term knows we're running */
curtime = CurrentTime; curtime = CurrentTime;
XSetSelectionOwner(dpy, _rio_running, screens[0].menuwin, timestamp()); XSetSelectionOwner(dpy, _rio_running, screens[0].menuwin, timestamp());
XSync(dpy, False); XSync(dpy, False);
initting = 0; initting = 0;
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);
return 0; return 0;
} }
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; XGCValues gv;
XGCValues gv; XSetWindowAttributes attr;
XSetWindowAttributes attr; XVisualInfo xvi;
XVisualInfo xvi; XSetWindowAttributes attrs;
XSetWindowAttributes attrs;
s->num = i; s->num = i;
s->root = RootWindow(dpy, i); s->root = RootWindow(dpy, i);
s->def_cmap = DefaultColormap(dpy, i); s->def_cmap = DefaultColormap(dpy, i);
s->min_cmaps = MinCmapsOfScreen(ScreenOfDisplay(dpy, i)); s->min_cmaps = MinCmapsOfScreen(ScreenOfDisplay(dpy, i));
s->depth = DefaultDepth(dpy, i); s->depth = DefaultDepth(dpy, i);
/* /*
* 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) ||
s->vis = xvi.visual; XMatchVisualInfo(dpy, i, 16, DirectColor, &xvi)) {
s->depth = 16; s->vis = xvi.visual;
} s->depth = 16;
else } else if (
if(XMatchVisualInfo(dpy, i, 15, TrueColor, &xvi) 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 (
} XMatchVisualInfo(dpy, i, 8, PseudoColor, &xvi) ||
else XMatchVisualInfo(dpy, i, 8, StaticColor, &xvi)) {
if(XMatchVisualInfo(dpy, i, 8, PseudoColor, &xvi) s->vis = xvi.visual;
|| XMatchVisualInfo(dpy, i, 8, StaticColor, &xvi)){ s->depth = 8;
s->vis = xvi.visual; } else {
s->depth = 8; s->depth = DefaultDepth(dpy, i);
} if (s->depth != 8) {
else{ fprintf(stderr, "can't understand depth %d screen", s->depth);
s->depth = DefaultDepth(dpy, i); exit(1);
if(s->depth != 8){ }
fprintf(stderr, "can't understand depth %d screen", s->depth); s->vis = DefaultVisual(dpy, i);
exit(1); }
} if (DefaultDepth(dpy, i) != s->depth) {
s->vis = DefaultVisual(dpy, i); s->def_cmap = XCreateColormap(dpy, s->root, s->vis, AllocNone);
} }
if(DefaultDepth(dpy, i) != s->depth){
s->def_cmap = XCreateColormap(dpy, s->root, s->vis, AllocNone);
}
ds = DisplayString(dpy); ds = DisplayString(dpy);
colon = rindex(ds, ':'); colon = rindex(ds, ':');
if(colon && num_screens > 1){ if (colon && num_screens > 1) {
strcpy(s->display, "DISPLAY="); strcpy(s->display, "DISPLAY=");
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
} s->display[0] = '\0';
else
s->display[0] = '\0';
s->black = BlackPixel(dpy, i); s->black = BlackPixel(dpy, i);
s->white = WhitePixel(dpy, i); s->white = WhitePixel(dpy, i);
s->activeholdborder = colorpixel(dpy, s, s->depth, SHOLDCOL, s->white); s->activeholdborder = colorpixel(dpy, s, s->depth, SHOLDCOL, s->white);
s->inactiveholdborder = colorpixel(dpy, s, s->depth, HOLDCOL, s->black); s->inactiveholdborder = colorpixel(dpy, s, s->depth, HOLDCOL, s->black);
s->activeborder = colorpixel(dpy, s, s->depth, SBORDERCOL, s->black); s->activeborder = colorpixel(dpy, s, s->depth, SBORDERCOL, s->black);
s->inactiveborder = colorpixel(dpy, s, s->depth, BORDERCOL, s->white); s->inactiveborder = colorpixel(dpy, s, s->depth, BORDERCOL, s->white);
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;
} }
s->gc = XCreateGC(dpy, s->root, gmask, &gv); s->gc = XCreateGC(dpy, s->root, gmask, &gv);
gv.function = GXcopy; gv.function = GXcopy;
s->gccopy = XCreateGC(dpy, s->root, gmask, &gv); s->gccopy = XCreateGC(dpy, s->root, gmask, &gv);
gv.foreground = s->red; gv.foreground = s->red;
s->gcred = XCreateGC(dpy, s->root, gmask, &gv); s->gcred = XCreateGC(dpy, s->root, gmask, &gv);
gv.foreground = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black); gv.foreground = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black);
s->gcsweep = XCreateGC(dpy, s->root, gmask, &gv); s->gcsweep = XCreateGC(dpy, s->root, gmask, &gv);
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);
attrs.border_pixel = colorpixel(dpy, s, s->depth, MBORDERCOL, s->black); attrs.border_pixel = colorpixel(dpy, s, s->depth, MBORDERCOL, s->black);
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(
s->depth, dpy,
CopyFromParent, s->root,
s->vis, 0,
CWBackPixel | CWBorderPixel | CWColormap, 0,
&attrs 1,
); 1,
MENUBORDER,
s->depth,
CopyFromParent,
s->vis,
CWBackPixel | CWBorderPixel | CWColormap,
&attrs);
gv.foreground = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black);
s->gcmenubg = XCreateGC(dpy, s->menuwin, gmask, &gv);
gv.foreground = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black); gv.foreground = colorpixel(dpy, s, s->depth, SMENUBGCOL, s->white);
s->gcmenubg = XCreateGC(dpy, s->menuwin, gmask, &gv); s->gcmenubgs = XCreateGC(dpy, s->menuwin, gmask, &gv);
gv.foreground = colorpixel(dpy, s, s->depth, SMENUBGCOL, s->white); gv.foreground = colorpixel(dpy, s, s->depth, MENUFGCOL, s->white);
s->gcmenubgs = XCreateGC(dpy, s->menuwin, gmask, &gv); gv.background = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black);
s->gcmenufg = XCreateGC(dpy, s->menuwin, gmask, &gv);
gv.foreground = colorpixel(dpy, s, s->depth, MENUFGCOL, s->white); gv.foreground = colorpixel(dpy, s, s->depth, SMENUFGCOL, s->white);
gv.background = colorpixel(dpy, s, s->depth, MENUBGCOL, s->black); gv.background = colorpixel(dpy, s, s->depth, SMENUBGCOL, s->black);
s->gcmenufg = XCreateGC(dpy, s->menuwin, gmask, &gv); s->gcmenufgs = XCreateGC(dpy, s->menuwin, gmask, &gv);
gv.foreground = colorpixel(dpy, s, s->depth, SMENUFGCOL, s->white); attrs.border_pixel = s->red;
gv.background = colorpixel(dpy, s, s->depth, SMENUBGCOL, s->black); attrs.background_pixel = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black);
s->gcmenufgs = XCreateGC(dpy, s->menuwin, gmask, &gv); attrs.colormap = s->def_cmap;
s->sweepwin = XCreateWindow(
attrs.border_pixel = s->red; dpy,
attrs.background_pixel = colorpixel(dpy, s, s->depth, 0xEEEEEE, s->black); s->root,
attrs.colormap = s->def_cmap; 0,
s->sweepwin = XCreateWindow(dpy, s->root, 0, 0, 1, 1, 4, 0,
s->depth, 1,
CopyFromParent, 1,
s->vis, 4,
CWBackPixel | CWBorderPixel | CWColormap, s->depth,
&attrs CopyFromParent,
); s->vis,
CWBackPixel | CWBorderPixel | CWColormap,
&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,
XMaskEvent(dpy, PropertyChangeMask, &ev); screens[0].root,
curtime = ev.xproperty.time; _rio_running,
} _rio_running,
return curtime; 8,
PropModeAppend,
(unsigned char*)"",
0);
XMaskEvent(dpy, PropertyChangeMask, &ev);
curtime = ev.xproperty.time;
}
return curtime;
} }
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;
memset(&ev, 0, sizeof(ev)); memset(&ev, 0, sizeof(ev));
ev.xclient.type = ClientMessage; ev.xclient.type = ClientMessage;
ev.xclient.window = w; ev.xclient.window = w;
ev.xclient.message_type = a; ev.xclient.message_type = a;
ev.xclient.format = 32; ev.xclient.format = 32;
ev.xclient.data.l[0] = x; ev.xclient.data.l[0] = x;
ev.xclient.data.l[1] = timestamp(); ev.xclient.data.l[1] = timestamp();
mask = 0; mask = 0;
if(usemask){ if (usemask) {
mask |= KeyPressMask; /* seems to be necessary */ mask |= KeyPressMask; /* seems to be necessary */
if(isroot) if (isroot)
mask |= SubstructureRedirectMask; /* magic! */ mask |= SubstructureRedirectMask; /* magic! */
else else
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;
ce.event = c->window; ce.event = c->window;
ce.window = c->window; ce.window = c->window;
ce.x = c->x; ce.x = c->x;
ce.y = c->y; ce.y = c->y;
ce.width = c->dx; ce.width = c->dx;
ce.height = c->dy; ce.height = c->dy;
ce.border_width = c->border; ce.border_width = c->border;
ce.above = None; ce.above = None;
ce.override_redirect = 0; ce.override_redirect = 0;
XSendEvent(dpy, c->window, False, StructureNotifyMask, (XEvent*)&ce); XSendEvent(dpy, c->window, False, StructureNotifyMask, (XEvent*)&ce);
} }
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;
if(!signalled){ if (!signalled) {
if(QLength(dpy) > 0){ if (QLength(dpy) > 0) {
XNextEvent(dpy, e); XNextEvent(dpy, e);
return; return;
} }
fd = ConnectionNumber(dpy); fd = ConnectionNumber(dpy);
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(fd, &rfds); FD_SET(fd, &rfds);
t.tv_sec = t.tv_usec = 0; t.tv_sec = t.tv_usec = 0;
if(select(fd+1, &rfds, NULL, NULL, &t) == 1){ if (select(fd + 1, &rfds, NULL, NULL, &t) == 1) {
XNextEvent(dpy, e); XNextEvent(dpy, e);
return; return;
} }
XFlush(dpy); XFlush(dpy);
FD_SET(fd, &rfds); FD_SET(fd, &rfds);
if(select(fd+1, &rfds, NULL, NULL, NULL) == 1){ if (select(fd + 1, &rfds, NULL, NULL, NULL) == 1) {
XNextEvent(dpy, e); XNextEvent(dpy, e);
return; return;
} }
if(errno != EINTR || !signalled){ if (errno != EINTR || !signalled) {
perror("ryudo: select failed"); perror("ryudo: select failed");
exit(1); exit(1);
} }
} }
fprintf(stderr, "ryudo: exiting on signal\n"); fprintf(stderr, "ryudo: exiting on signal\n");
cleanup(); cleanup();
exit(1); exit(1);
} }
void void
cleanup(void) cleanup(void) {
{ Client *c, *cc[2], *next;
Client *c, *cc[2], *next; XWindowChanges wc;
XWindowChanges wc; int i;
int i;
/* order of un-reparenting determines final stacking order... */ /* order of un-reparenting determines final stacking order... */
cc[0] = cc[1] = 0; cc[0] = cc[1] = 0;
for(c = clients; c; c = next){ for (c = clients; c; c = next) {
next = c->next; next = c->next;
i = normal(c); i = normal(c);
c->next = cc[i]; c->next = cc[i];
cc[i] = c; cc[i] = c;
} }
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); }
} }
}
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);
} }

789
manage.c Executable file → Normal file
View file

@ -23,497 +23,504 @@
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);
XSelectInput(dpy, c->window, ColormapChangeMask | EnterWindowMask | PropertyChangeMask | FocusChangeMask | KeyPressMask);
/* Get loads of hints */ trace("manage", c, 0);
XSelectInput(
dpy,
c->window,
ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
FocusChangeMask | KeyPressMask);
if(XGetClassHint(dpy, c->window, &class) != 0){ /* ``Success'' */ /* Get loads of hints */
c->instance = class.res_name;
c->class = class.res_class;
c->is9term = 0;
if(isNew){
c->is9term = strstr(c->class, "term") || strstr(c->class, "Term")
|| strstr(c->class, "urxvt") || strstr(c->class, "URxvt")
|| strstr(c->class, "onsole") || strstr(c->class, "Alacritty");
isNew = 0;
}
printf("%s: is9term = %d", c->class, c->is9term);
}
else {
c->instance = 0;
c->class = 0;
c->is9term = 0;
}
c->iconname = getprop(c->window, XA_WM_ICON_NAME);
c->name = getprop(c->window, XA_WM_NAME);
setlabel(c);
hints = XGetWMHints(dpy, c->window); if (XGetClassHint(dpy, c->window, &class) != 0) { /* ``Success'' */
if(XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0) c->instance = class.res_name;
c->size.flags = PSize; /* not specified - punt */ c->class = class.res_class;
c->is9term = 0;
if (isNew) {
c->is9term = strstr(c->class, "term") || strstr(c->class, "Term") ||
strstr(c->class, "urxvt") || strstr(c->class, "URxvt") ||
strstr(c->class, "onsole") || strstr(c->class, "Alacritty");
isNew = 0;
}
printf("%s: is9term = %d", c->class, c->is9term);
} else {
c->instance = 0;
c->class = 0;
c->is9term = 0;
}
c->iconname = getprop(c->window, XA_WM_ICON_NAME);
c->name = getprop(c->window, XA_WM_NAME);
setlabel(c);
getcmaps(c); hints = XGetWMHints(dpy, c->window);
getproto(c); if (
gettrans(c); XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 ||
if(c->is9term) c->size.flags == 0)
c->hold = getiprop(c->window, _rio_hold_mode); c->size.flags = PSize; /* not specified - punt */
/* Figure out what to do with the window from hints */ getcmaps(c);
getproto(c);
gettrans(c);
if (c->is9term) c->hold = getiprop(c->window, _rio_hold_mode);
if(!getstate(c->window, &state)) /* Figure out what to do with the window from hints */
state = hints ? hints->initial_state : NormalState;
dohide = (state == IconicState);
fixsize = 0; if (!getstate(c->window, &state))
if((c->size.flags & (USSize|PSize))) state = hints ? hints->initial_state : NormalState;
fixsize = 1; dohide = (state == IconicState);
if((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;
doreshape = !mapped;
if(fixsize){
if(c->size.flags & USPosition)
doreshape = 0;
if(dohide && (c->size.flags & PPosition))
doreshape = 0;
if(c->trans != None)
doreshape = 0;
}
if(c->is9term)
fixsize = 0;
if(c->size.flags & PBaseSize){
c->min_dx = c->size.base_width;
c->min_dy = c->size.base_height;
}
else if(c->size.flags & PMinSize){
c->min_dx = c->size.min_width;
c->min_dy = c->size.min_height;
}
else if(c->is9term){
c->min_dx = 100;
c->min_dy = 50;
}
else
c->min_dx = c->min_dy = 0;
if(hints) fixsize = 0;
XFree(hints); if ((c->size.flags & (USSize | PSize))) fixsize = 1;
if (
(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;
doreshape = !mapped;
if (fixsize) {
if (c->size.flags & USPosition) doreshape = 0;
if (dohide && (c->size.flags & PPosition)) doreshape = 0;
if (c->trans != None) doreshape = 0;
}
if (c->is9term) fixsize = 0;
if (c->size.flags & PBaseSize) {
c->min_dx = c->size.base_width;
c->min_dy = c->size.base_height;
} else if (c->size.flags & PMinSize) {
c->min_dx = c->size.min_width;
c->min_dy = c->size.min_height;
} else if (c->is9term) {
c->min_dx = 100;
c->min_dy = 50;
} else
c->min_dx = c->min_dy = 0;
/* Now do it!!! */ if (hints) XFree(hints);
if(doreshape){ /* Now do it!!! */
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",
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){
static int nwin;
c->x = 20*nwin+BORDER; if (doreshape) {
c->y = 20*nwin+BORDER; if (0)
nwin++; fprintf(
nwin %= 10; stderr,
} "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) {
static int nwin;
if(c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))){ c->x = 20 * nwin + BORDER;
XKillClient(dpy, c->window); c->y = 20 * nwin + BORDER;
rmclient(c); nwin++;
if(current && current->screen == c->screen) nwin %= 10;
cmapfocus(current); }
return 0;
}
}
attrs.border_pixel = c->screen->black; if (c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))) {
attrs.background_pixel = c->screen->white; XKillClient(dpy, c->window);
attrs.colormap = c->screen->def_cmap; rmclient(c);
c->parent = XCreateWindow(dpy, c->screen->root, if (current && current->screen == c->screen) cmapfocus(current);
c->x - BORDER, c->y - BORDER, return 0;
c->dx + 2*BORDER, c->dy + 2*BORDER, }
0, }
c->screen->depth,
CopyFromParent,
c->screen->vis,
CWBackPixel | CWBorderPixel | CWColormap,
&attrs);
XSelectInput(dpy, c->parent, SubstructureRedirectMask | SubstructureNotifyMask|ButtonPressMask| PointerMotionMask|LeaveWindowMask|KeyPressMask); attrs.border_pixel = c->screen->black;
if(mapped) attrs.background_pixel = c->screen->white;
c->reparenting = 1; attrs.colormap = c->screen->def_cmap;
if(doreshape && !fixsize) c->parent = XCreateWindow(
XResizeWindow(dpy, c->window, c->dx, c->dy); dpy,
XSetWindowBorderWidth(dpy, c->window, 0); c->screen->root,
c->x - BORDER,
c->y - BORDER,
c->dx + 2 * BORDER,
c->dy + 2 * BORDER,
0,
c->screen->depth,
CopyFromParent,
c->screen->vis,
CWBackPixel | CWBorderPixel | CWColormap,
&attrs);
/* XSelectInput(
* To have something more than only a big white or black border dpy,
* XXX should replace this by a pattern in the white or black c->parent,
* such that we can see the border also if all our SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask |
* windows are black and/or white PointerMotionMask | LeaveWindowMask | KeyPressMask);
* (black (or white) border around black (or white) window if (mapped) c->reparenting = 1;
* is not very helpful. if (doreshape && !fixsize) XResizeWindow(dpy, c->window, c->dx, c->dy);
*/ XSetWindowBorderWidth(dpy, c->window, 0);
if(c->screen->depth <= 8){
XSetWindowBorderWidth(dpy, c->parent, 1);
}
XReparentWindow(dpy, c->window, c->parent, BORDER, BORDER); /*
#ifdef SHAPE * To have something more than only a big white or black border
if(shape){ * XXX should replace this by a pattern in the white or black
XShapeSelectInput(dpy, c->window, ShapeNotifyMask); * such that we can see the border also if all our
ignore_badwindow = 1; /* magic */ * windows are black and/or white
setshape(c); * (black (or white) border around black (or white) window
ignore_badwindow = 0; * is not very helpful.
} */
if (c->screen->depth <= 8) { XSetWindowBorderWidth(dpy, c->parent, 1); }
XReparentWindow(dpy, c->window, c->parent, BORDER, BORDER);
#ifdef SHAPE
if (shape) {
XShapeSelectInput(dpy, c->window, ShapeNotifyMask);
ignore_badwindow = 1; /* magic */
setshape(c);
ignore_badwindow = 0;
}
#endif #endif
XAddToSaveSet(dpy, c->window); XAddToSaveSet(dpy, c->window);
if(dohide) if (dohide)
hide(c); hide(c);
else { else {
XMapWindow(dpy, c->window); XMapWindow(dpy, c->window);
XMapWindow(dpy, c->parent); XMapWindow(dpy, c->parent);
XUnmapWindow(dpy, c->screen->sweepwin); XUnmapWindow(dpy, c->screen->sweepwin);
#ifdef AUTOSTICK #ifdef AUTOSTICK
if(!isautostick(c)) if (!isautostick(c))
#endif #endif
active(c); active(c);
/*else if(c->trans != None && current && current->window == c->trans) /*else if(c->trans != None && current && current->window == c->trans)
active(c);*/ active(c);*/
else else
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 */
/* 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 {
if (c->x < BORDER){ if (c->x < BORDER) {
quickreshape(c, 0, c->y - BORDER, c->dx + 2*BORDER, c->dy + 2*BORDER); quickreshape(c, 0, c->y - BORDER, c->dx + 2 * BORDER, c->dy + 2 * BORDER);
} }
if (c->y < BORDER){ if (c->y < BORDER) {
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,
if (c->y + c->dy + BORDER > ra.height){ ra.width - (c->dx + 2 * BORDER),
quickreshape(c, c->x - BORDER, ra.height - (c->dy + 2*BORDER), c->dx + 2*BORDER, c->dy + 2*BORDER); c->y - BORDER,
} c->dx + 2 * BORDER,
c->dy + 2 * BORDER);
}
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);
}
} }
/* /*
* If we swept the window, let's send a resize event to the * If we swept the window, let's send a resize event to the
* guy who just got resized. It's not clear whether the apps * guy who just got resized. It's not clear whether the apps
* should notice their new size via other means. Try as I might, * should notice their new size via other means. Try as I might,
* 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; XWindowAttributes attr;
XWindowAttributes attr;
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; c->y = attr.y;
c->y = attr.y; c->dx = attr.width;
c->dx = attr.width; c->dy = attr.height;
c->dy = attr.height; 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) manage(c, 1);
if(attr.map_state == IsViewable) }
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;
if(XGetTransientForHint(dpy, c->window, &trans) != 0) if (XGetTransientForHint(dpy, c->window, &trans) != 0)
c->trans = trans; c->trans = trans;
else else
c->trans = None; c->trans = None;
} }
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); setstate(c, WithdrawnState);
setstate(c, WithdrawnState);
/* flush any errors */ /* flush any errors */
ignore_badwindow = 1; ignore_badwindow = 1;
XSync(dpy, False); XSync(dpy, False);
ignore_badwindow = 0; ignore_badwindow = 0;
} }
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 XInstallColormap(dpy, cmap);
XInstallColormap(dpy, cmap);
} }
void void
cmapfocus(Client *c) cmapfocus(Client* c) {
{ int i, found;
int i, found; Client* cc;
Client *cc;
if(c == 0) if (c == 0)
return; return;
else if(c->ncmapwins != 0){ else if (c->ncmapwins != 0) {
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) installcmap(c->screen, c->cmap);
if(!found) } else if (
installcmap(c->screen, c->cmap); c->trans != None && (cc = getclient(c->trans, 0)) != 0 &&
} cc->ncmapwins != 0)
else if(c->trans != None && (cc = getclient(c->trans, 0)) != 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;
if(!c->init){ if (!c->init) {
ignore_badwindow = 1; ignore_badwindow = 1;
XGetWindowAttributes(dpy, c->window, &attr); XGetWindowAttributes(dpy, c->window, &attr);
c->cmap = attr.colormap; c->cmap = attr.colormap;
XSync(dpy, False); XSync(dpy, False);
ignore_badwindow = 0; ignore_badwindow = 0;
} }
n = _getprop(c->window, wm_colormaps, XA_WINDOW, 100L, (void*)&cw); n = _getprop(c->window, wm_colormaps, XA_WINDOW, 100L, (void*)&cw);
if(c->ncmapwins != 0){ if (c->ncmapwins != 0) {
XFree((char *)c->cmapwins); XFree((char*)c->cmapwins);
free((char *)c->wmcmaps); free((char*)c->wmcmaps);
} }
if(n <= 0){ if (n <= 0) {
c->ncmapwins = 0; c->ncmapwins = 0;
return; return;
} }
c->ncmapwins = n; c->ncmapwins = n;
c->cmapwins = cw; c->cmapwins = cw;
c->wmcmaps = (Colormap*)malloc(n*sizeof(Colormap)); c->wmcmaps = (Colormap*)malloc(n * sizeof(Colormap));
for(i = 0; i < n; i++){ for (i = 0; i < n; i++) {
if(cw[i] == c->window) if (cw[i] == c->window)
c->wmcmaps[i] = c->cmap; c->wmcmaps[i] = c->cmap;
else { else {
/* flush any errors (e.g., caused by mozilla tabs) */ /* flush any errors (e.g., caused by mozilla tabs) */
ignore_badwindow = 1; ignore_badwindow = 1;
XSelectInput(dpy, cw[i], ColormapChangeMask); XSelectInput(dpy, cw[i], ColormapChangeMask);
XGetWindowAttributes(dpy, cw[i], &attr); XGetWindowAttributes(dpy, cw[i], &attr);
c->wmcmaps[i] = attr.colormap; c->wmcmaps[i] = attr.colormap;
XSync(dpy, False); XSync(dpy, False);
ignore_badwindow = 0; ignore_badwindow = 0;
} }
} }
} }
void void
setlabel(Client *c) setlabel(Client* c) {
{ char *label, *p, *lc;
char *label, *p, *lc;
int i; int i;
if(c->iconname != 0) if (c->iconname != 0)
label = c->iconname; label = c->iconname;
else if(c->name != 0) else if (c->name != 0)
label = c->name; label = c->name;
else if(c->instance != 0) else if (c->instance != 0)
label = c->instance; label = c->instance;
else if(c->class != 0) else if (c->class != 0)
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] = '~'; label[23] = '\0';
label[23] = '\0'; }
} }
}
c->label = label; c->label = label;
} }
#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,
XFree((void*)rect); c->parent,
ShapeBounding,
BORDER,
BORDER,
c->window,
ShapeBounding,
ShapeSet);
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);
return 1; return 1;
} }
void void
getproto(Client *c) getproto(Client* c) {
{ Atom* p;
Atom *p; int i;
int i; long n;
long n; Window w;
Window w;
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)
c->proto |= Pdelete; c->proto |= Pdelete;
else if(p[i] == wm_take_focus) else if (p[i] == wm_take_focus)
c->proto |= Ptakefocus; c->proto |= Ptakefocus;
else if(p[i] == wm_lose_focus) else if (p[i] == wm_lose_focus)
c->proto |= Plosefocus; c->proto |= Plosefocus;
XFree((char *) p); XFree((char*)p);
} }

710
menu.c Executable file → Normal file
View file

@ -3,7 +3,7 @@
*/ */
/* Copyright (c) 1994-1996 David Hogan, see README for licence details */ /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
#define _SVID_SOURCE 1 /* putenv in glibc */ #define _SVID_SOURCE 1 /* putenv in glibc */
#define _DEFAULT_SOURCE 1 #define _DEFAULT_SOURCE 1
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
@ -18,459 +18,405 @@
#include "dat.h" #include "dat.h"
#include "fns.h" #include "fns.h"
Client *hiddenc[MAXHIDDEN]; Client* hiddenc[MAXHIDDEN];
int numhidden; 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", "Four",
"Four", "Five",
"Five", "Six",
"Six", "Seven",
"Seven", "Eight",
"Eight", "Nine",
"Nine", "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", "Delete",
"Delete", "Hide",
"Hide",
#ifdef SHOWSTICK #ifdef SHOWSTICK
"Stick", "Stick",
#endif #endif
0 0};
};
enum enum {
{ New,
New, Reshape,
Reshape, Move,
Move, Delete,
Delete,
#ifdef SHOWSTICK #ifdef SHOWSTICK
Hide, Hide,
Stick Stick
#else #else
Hide Hide
#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; ScreenInfo* s;
ScreenInfo *s;
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)
if(debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n", fprintf(
e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER); stderr,
if(borderorient(c, e->x, e->y) != BorderUnknown){ "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n",
switch (e->button){ e->x,
case Button1: e->y,
case Button2: c->x,
reshape(c, e->button, pull, e); c->y,
return; c->dx,
case Button3: c->dy,
move(c, Button3); BORDER);
return; if (borderorient(c, e->x, e->y) != BorderUnknown) {
default: switch (e->button) {
return; case Button1:
} case Button2: reshape(c, e->button, pull, e); return;
} case Button3: move(c, Button3); return;
e->x += c->x - BORDER; default: return;
e->y += c->y - BORDER; }
} else if(e->window != e->root){ }
if(debug) fprintf(stderr, "but no client: e x=%d y=%d\n", e->x += c->x - BORDER;
e->x, e->y); e->y += c->y - BORDER;
XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y, } else if (e->window != e->root) {
&e->x, &e->y, &dw); if (debug) fprintf(stderr, "but no client: e x=%d y=%d\n", e->x, e->y);
} XTranslateCoordinates(
switch (e->button){ dpy, e->window, s->root, e->x, e->y, &e->x, &e->y, &dw);
case Button1: }
fflush(stdout); switch (e->button) {
if(c){ case Button1:
if (ffm) fflush(stdout);
XRaiseWindow(dpy, c->window); if (c) {
XMapRaised(dpy, c->parent); if (ffm) XRaiseWindow(dpy, c->window);
top(c); XMapRaised(dpy, c->parent);
active(c); top(c);
} active(c);
return; }
case Button2: return;
if(c){ case Button2:
XMapRaised(dpy, c->parent); if (c) {
active(c); XMapRaised(dpy, c->parent);
XAllowEvents (dpy, ReplayPointer, curtime); active(c);
} else if((e->state&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)){ XAllowEvents(dpy, ReplayPointer, curtime);
menuhit(e, &egg); } else if (
} else if(numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1) (e->state & (ShiftMask | ControlMask)) == (ShiftMask | ControlMask)) {
button2(n); menuhit(e, &egg);
return; } else if (numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1)
case Button3: button2(n);
break; return;
case Button4: case Button3: break;
/* scroll up changes to previous virtual screen */ case Button4:
if(!c && e->type == ButtonPress) /* scroll up changes to previous virtual screen */
if(numvirtuals > 1 && virt > 0) if (!c && e->type == ButtonPress)
switch_to(virt - 1); if (numvirtuals > 1 && virt > 0) 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;
return; default: 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: spawn(s); break;
case New: case Reshape: reshape(selectwin(1, 0, s), Button3, sweep, 0); break;
spawn(s); case Move: move(selectwin(0, 0, s), Button3); break;
break; case Delete:
case Reshape: shift = 0;
reshape(selectwin(1, 0, s), Button3, sweep, 0); c = selectwin(1, &shift, s);
break; delete (c, shift);
case Move: break;
move(selectwin(0, 0, s), Button3); case Hide: hide(selectwin(1, 0, s)); break;
break;
case Delete:
shift = 0;
c = selectwin(1, &shift, s);
delete(c, shift);
break;
case Hide:
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 */ if (current && current->screen == s) cmapfocus(current);
break;
}
if(current && current->screen == s)
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. * hope it's created by the program we're about to
* hope it's created by the program we're about to * exec!
* exec! */
*/ isNew = 1;
isNew = 1; /*
/* * ugly dance to avoid leaving zombies. Could use SIGCHLD,
* ugly dance to avoid leaving zombies. Could use SIGCHLD, * but it's not very portable.
* but it's not very portable. */
*/ if (fork() == 0) {
if(fork() == 0){ if (fork() == 0) {
if(fork() == 0){ close(ConnectionNumber(dpy));
close(ConnectionNumber(dpy)); if (s->display[0] != '\0') putenv(s->display);
if(s->display[0] != '\0') signal(SIGINT, SIG_DFL);
putenv(s->display); signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL); signal(SIGHUP, SIG_DFL);
signal(SIGTERM, SIG_DFL); if (termprog != NULL) {
signal(SIGHUP, SIG_DFL); execl(shell, shell, "-c", termprog, (char*)0);
if(termprog != NULL){ fprintf(stderr, "ryudo: exec %s", shell);
execl(shell, shell, "-c", termprog, (char*)0); perror(" failed");
fprintf(stderr, "ryudo: exec %s", shell); }
perror(" failed"); execlp("urxvt", "urxvt", (char*)0);
} execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
execlp("urxvt", "urxvt", (char*)0); execlp("xterm", "xterm", "-ut", (char*)0);
execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0); perror("ryudo: exec urxvt/9term/xterm failed");
execlp("xterm", "xterm", "-ut", (char*)0); exit(1);
perror("ryudo: exec urxvt/9term/xterm failed"); }
exit(1); exit(0);
} }
exit(0); wait((int*)0);
}
wait((int *) 0);
} }
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) return;
if(fn(c, but, e) == 0) active(c);
return; top(c);
active(c); XRaiseWindow(dpy, c->parent);
top(c); XMoveResizeWindow(
XRaiseWindow(dpy, c->parent); dpy,
XMoveResizeWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER, c->parent,
c->dx+2*BORDER, c->dy+2*BORDER); c->x - BORDER,
if(c->dx == odx && c->dy == ody) c->y - BORDER,
sendconfig(c); c->dx + 2 * BORDER,
else c->dy + 2 * BORDER);
XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy); if (c->dx == odx && c->dy == ody)
sendconfig(c);
else
XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy);
} }
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; active(c);
if(drag(c, but) == 0) top(c);
return; XRaiseWindow(dpy, c->parent);
active(c); XMoveWindow(dpy, c->parent, c->x - BORDER, c->y - BORDER);
top(c); sendconfig(c);
XRaiseWindow(dpy, c->parent); }
XMoveWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER);
sendconfig(c); void delete (Client* c, int shift) {
if (c == 0) return;
if ((c->proto & Pdelete) && !shift)
sendcmessage(c->window, wm_protocols, wm_delete, 0, 0);
else
XKillClient(dpy, c->window); /* let event clean up */
} }
void void
delete(Client *c, int shift) hide(Client* c) {
{ if (c == 0 || numhidden == MAXHIDDEN) return;
if(c == 0) if (hidden(c)) {
return; fprintf(stderr, "ryudo: already hidden: %s\n", c->label);
if((c->proto & Pdelete) && !shift) return;
sendcmessage(c->window, wm_protocols, wm_delete, 0, 0); }
else XUnmapWindow(dpy, c->parent);
XKillClient(dpy, c->window); /* let event clean up */ XUnmapWindow(dpy, c->window);
setstate(c, IconicState);
if (c == current) nofocus();
if (reversehide) {
memmove(hiddenc + 1, hiddenc, numhidden * sizeof hiddenc[0]);
memmove(
b3items + B3FIXED + 1, b3items + B3FIXED, numhidden * sizeof b3items[0]);
hiddenc[0] = c;
b3items[B3FIXED] = c->label;
} else {
hiddenc[numhidden] = c;
b3items[B3FIXED + numhidden] = c->label;
}
numhidden++;
b3items[B3FIXED + numhidden] = 0;
} }
void void
hide(Client *c) unhide(int n, int map) {
{ Client* c;
if(c == 0 || numhidden == MAXHIDDEN) int i;
return;
if(hidden(c)){ if (n >= numhidden) {
fprintf(stderr, "ryudo: already hidden: %s\n", c->label); fprintf(stderr, "ryudo: unhide: n %d numhidden %d\n", n, numhidden);
return; return;
} }
XUnmapWindow(dpy, c->parent); c = hiddenc[n];
XUnmapWindow(dpy, c->window); if (!hidden(c)) {
setstate(c, IconicState); fprintf(
if(c == current) stderr,
nofocus(); "ryudo: unhide: not hidden: %s(0x%x)\n",
if(reversehide){ c->label,
memmove(hiddenc+1, hiddenc, numhidden*sizeof hiddenc[0]); (int)c->window);
memmove(b3items+B3FIXED+1, b3items+B3FIXED, numhidden*sizeof b3items[0]); return;
hiddenc[0] = c; }
b3items[B3FIXED] = c->label; c->virt = virt;
}else{
hiddenc[numhidden] = c; if (map) {
b3items[B3FIXED+numhidden] = c->label; XMapWindow(dpy, c->window);
} XMapRaised(dpy, c->parent);
numhidden++; setstate(c, NormalState);
b3items[B3FIXED+numhidden] = 0; active(c);
top(c);
}
numhidden--;
for (i = n; i < numhidden; i++) {
hiddenc[i] = hiddenc[i + 1];
b3items[B3FIXED + i] = b3items[B3FIXED + i + 1];
}
b3items[B3FIXED + numhidden] = 0;
} }
void void
unhide(int n, int map) unhidec(Client* c, int map) {
{ int i;
Client *c;
int i;
if(n >= numhidden){ for (i = 0; i < numhidden; i++)
fprintf(stderr, "ryudo: unhide: n %d numhidden %d\n", n, numhidden); if (c == hiddenc[i]) {
return; unhide(i, map);
} return;
c = hiddenc[n]; }
if(!hidden(c)){ fprintf(
fprintf(stderr, "ryudo: unhide: not hidden: %s(0x%x)\n", stderr, "ryudo: unhidec: not hidden: %s(0x%x)\n", c->label, (int)c->window);
c->label, (int)c->window);
return;
}
c->virt = virt;
if(map){
XMapWindow(dpy, c->window);
XMapRaised(dpy, c->parent);
setstate(c, NormalState);
active(c);
top(c);
}
numhidden--;
for(i = n; i < numhidden; i++){
hiddenc[i] = hiddenc[i+1];
b3items[B3FIXED+i] = b3items[B3FIXED+i+1];
}
b3items[B3FIXED+numhidden] = 0;
} }
void void
unhidec(Client *c, int map) stick(Client* c) {
{ if (numvirtuals > 1 && c->virt >= 0)
int i;
for(i = 0; i < numhidden; i++)
if(c == hiddenc[i]){
unhide(i, map);
return;
}
fprintf(stderr, "ryudo: unhidec: not hidden: %s(0x%x)\n",
c->label, (int)c->window);
}
void
stick(Client *c)
{
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)) return;
if(!hidden(c)) for (i = 0; i < numhidden; i++)
return; if (c == hiddenc[i]) {
for(i = 0; i < numhidden; i++) b3items[B3FIXED + i] = name;
if(c == hiddenc[i]){ return;
b3items[B3FIXED+i] = name; }
return;
}
} }
void void
button2(int n) button2(int n) {
{ switch_to(n);
switch_to(n); if (current) cmapfocus(current);
if(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
if (c->virt != virt && c->state == NormalState && c->virt >= 0) {
XUnmapWindow(dpy, c->parent);
XUnmapWindow(dpy, c->window);
setstate(c, IconicState);
if (c == current) nofocus();
} else if (c->virt == virt && c->state == IconicState) {
int i;
for (i = 0; i < numhidden; i++)
if (c == hiddenc[i]) break;
if (i == numhidden) {
XMapWindow(dpy, c->window);
XMapWindow(dpy, c->parent);
setstate(c, NormalState);
if (currents[virt] == c) active(c);
} }
#endif }
if(c->virt != virt && c->state == NormalState && c->virt >= 0){
XUnmapWindow(dpy, c->parent);
XUnmapWindow(dpy, c->window);
setstate(c, IconicState);
if(c == current)
nofocus();
} else if(c->virt == virt && c->state == IconicState){
int i;
for(i = 0; i < numhidden; i++)
if(c == hiddenc[i])
break;
if(i == numhidden){
XMapWindow(dpy, c->window);
XMapWindow(dpy, c->parent);
setstate(c, NormalState);
if(currents[virt] == 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;
/* redundant when called from a menu switch /* redundant when called from a menu switch
* but needed for scroll-button switches * but needed for scroll-button switches
*/ */
b2menu.lasthit = n; b2menu.lasthit = 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') putenv(dpy);
if(dpy != '\0') signal(SIGINT, SIG_DFL);
putenv(dpy); signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL); signal(SIGHUP, SIG_DFL);
signal(SIGTERM, 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;
} }

1147
printevent.c Executable file → Normal file

File diff suppressed because it is too large Load diff

2
printevent.h Executable file → Normal file
View file

@ -1,2 +1,2 @@
char *eventtype(XEvent*); char* eventtype(XEvent*);
void printevent(XEvent*); void printevent(XEvent*);

1135
showevent/ShowEvent.c Executable file → Normal file

File diff suppressed because it is too large Load diff

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

@ -5,44 +5,53 @@
* "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;
int screen; int screen;
Window window; Window window;
XEvent event; XEvent event;
extern Boolean use_separate_lines; extern Boolean use_separate_lines;
if (!(dpy = XOpenDisplay(""))) { if (!(dpy = XOpenDisplay(""))) {
printf("Failed to open display...\n"); printf("Failed to open display...\n");
exit(1); exit(1);
} }
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);
/* set this to false to make ShowEvent take up less vertival space */ /* set this to false to make ShowEvent take up less vertival space */
use_separate_lines = True; use_separate_lines = True;
while (1) { while (1) {
XNextEvent(dpy, &event); XNextEvent(dpy, &event);
printf("Detail of %s event:\n", GetType(&event)); printf("Detail of %s event:\n", GetType(&event));
ShowEvent(&event); ShowEvent(&event);
printf("\n\n"); printf("\n\n");
} }
} }

67
xevents.c Executable file → Normal file
View file

@ -9,37 +9,46 @@
#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; XEvent event;
XEvent event;
if (!(dpy = XOpenDisplay(""))) {
printf("Failed to open display...\n");
exit(1);
}
screen = DefaultScreen(dpy);
window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), 100, 100, if (!(dpy = XOpenDisplay(""))) {
300, 200, 2, BlackPixel(dpy, screen), WhitePixel(dpy, screen)); printf("Failed to open display...\n");
exit(1);
}
XSelectInput(dpy, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | screen = DefaultScreen(dpy);
ButtonReleaseMask | EnterWindowMask | LeaveWindowMask |
PointerMotionMask | PointerMotionHintMask | Button1MotionMask |
Button2MotionMask | Button3MotionMask | Button4MotionMask |
Button5MotionMask | ButtonMotionMask | KeymapStateMask |
ExposureMask | VisibilityChangeMask | StructureNotifyMask |
SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask |
PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask);
XMapWindow(dpy, window); window = XCreateSimpleWindow(
dpy,
RootWindow(dpy, screen),
100,
100,
300,
200,
2,
BlackPixel(dpy, screen),
WhitePixel(dpy, screen));
for(;;){ XSelectInput(
XNextEvent(dpy, &event); dpy,
printevent(&event); window,
} KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
EnterWindowMask | LeaveWindowMask | PointerMotionMask |
PointerMotionHintMask | Button1MotionMask | Button2MotionMask |
Button3MotionMask | Button4MotionMask | Button5MotionMask |
ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask |
StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask |
FocusChangeMask | PropertyChangeMask | ColormapChangeMask |
OwnerGrabButtonMask);
XMapWindow(dpy, window);
for (;;) {
XNextEvent(dpy, &event);
printevent(&event);
}
} }

481
xshove.c Executable file → Normal file
View file

@ -9,34 +9,32 @@
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; } min, max;
} min, max;
}; };
#define Dx(r) ((r).max.x - (r).min.x) #define Dx(r) ((r).max.x - (r).min.x)
#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; int dx;
int dx; int dy;
int dy; char* class;
char *class; char* instance;
char *instance; char* name;
char *name; char* iconname;
char *iconname;
}; };
Display *dpy; Display* dpy;
Window root; Window root;
Win *w; Win* w;
int nw; int nw;
void getinfo(void); void getinfo(void);
@ -45,274 +43,243 @@ 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;
ARGBEGIN{
case 's':
screen = atoi(EARGF(usage()));
break;
default:
usage();
break;
}ARGEND
dpy = XOpenDisplay("");
if(dpy == nil)
sysfatal("open display: %r");
root = RootWindow(dpy, screen); screen = 0;
getinfo(); ARGBEGIN {
case 's': screen = atoi(EARGF(usage())); break;
default: usage(); break;
}
ARGEND
if(argc == 0){ dpy = XOpenDisplay("");
listwindows(); if (dpy == nil) sysfatal("open display: %r");
exits(0);
} root = RootWindow(dpy, screen);
if(argc != 2) getinfo();
usage();
shove(argv[0], argv[1]); if (argc == 0) {
exits(0); listwindows();
exits(0);
}
if (argc != 2) usage();
shove(argv[0], argv[1]);
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; ulong n, dummy;
ulong n, dummy;
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 strdup((char*)p);
return nil;
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)) for (i = 0; i < nxwin; i++)
return 0; if ((w = findname(xwin[i])) != 0) return w;
for(i=0; i<nxwin; i++) return 0;
if((w = findname(xwin[i])) != 0)
return w;
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) sysfatal("malloc: %r");
if(w == 0)
sysfatal("malloc: %r");
Win *ww = w;
for(i=0; i<nxwin; i++){
memset(&attr, 0, sizeof attr);
xwin[i] = findname(xwin[i]);
if(xwin[i] == 0)
continue;
XGetWindowAttributes(dpy, xwin[i], &attr);
if(attr.width <= 0 || attr.override_redirect || attr.map_state != IsViewable)
continue;
ww->xw = xwin[i];
ww->x = attr.x;
ww->y = attr.y;
ww->dx = attr.width;
ww->dy = attr.height;
XTranslateCoordinates(dpy, ww->xw, root, 0, 0, &ww->x, &ww->y, &dw1);
if(XGetClassHint(dpy, ww->xw, &class)){
ww->class = strdup(class.res_class);
ww->instance = strdup(class.res_name);
}
ww->iconname = getproperty(ww->xw, XA_WM_ICON_NAME);
ww->name = getproperty(ww->xw, XA_WM_NAME);
ww++;
}
nw = ww - w;
}
void Win* ww = w;
listwindows(void) for (i = 0; i < nxwin; i++) {
{ memset(&attr, 0, sizeof attr);
int i; xwin[i] = findname(xwin[i]);
if (xwin[i] == 0) continue;
for(i=0; i<nw; i++){ XGetWindowAttributes(dpy, xwin[i], &attr);
Win *ww = &w[i]; if (
char rect[50]; attr.width <= 0 || attr.override_redirect || attr.map_state != IsViewable)
snprint(rect, sizeof rect, "%d,%d,%d,%d", ww->x, ww->y, ww->x+ww->dx, ww->y+ww->dy); continue;
print("%08x %-20s %-10s %s\n", ww->xw = xwin[i];
(uint)ww->xw, ww->x = attr.x;
rect, ww->y = attr.y;
ww->instance, ww->dx = attr.width;
ww->class); ww->dy = attr.height;
} XTranslateCoordinates(dpy, ww->xw, root, 0, 0, &ww->x, &ww->y, &dw1);
if (XGetClassHint(dpy, ww->xw, &class)) {
ww->class = strdup(class.res_class);
ww->instance = strdup(class.res_name);
}
ww->iconname = getproperty(ww->xw, XA_WM_ICON_NAME);
ww->name = getproperty(ww->xw, XA_WM_NAME);
ww++;
}
nw = ww - w;
} }
void void
shove(char *name, char *geom) listwindows(void) {
{ int i;
int i;
int isdelta, havemin, havesize;
int old, new;
Rectangle r;
if(parsewinsize(geom, &r, &isdelta, &havemin, &havesize) < 0) for (i = 0; i < nw; i++) {
sysfatal("bad window spec: %s", name); Win* ww = &w[i];
char rect[50];
snprint(
rect,
sizeof rect,
"%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);
}
}
old = 0; void
new = 1; shove(char* name, char* geom) {
if(isdelta){ int i;
old = 1; int isdelta, havemin, havesize;
new = isdelta; int old, new;
} Rectangle r;
for(i=0; i<nw; i++){
Win *ww = &w[i];
if(ww->instance && strstr(ww->instance, name)
|| ww->class && strstr(ww->class, name)){
int value_mask;
XWindowChanges e;
memset(&e, 0, sizeof e); if (parsewinsize(geom, &r, &isdelta, &havemin, &havesize) < 0)
if(havemin){ sysfatal("bad window spec: %s", name);
e.x = old*ww->x + new*r.min.x;
e.y = old*ww->y + new*r.min.y; old = 0;
}else{ new = 1;
e.x = ww->x; if (isdelta) {
e.y = ww->y; old = 1;
} new = isdelta;
if(havesize){ }
e.width = old*ww->dx + new*Dx(r); for (i = 0; i < nw; i++) {
e.height = old*ww->dy + new*Dy(r); Win* ww = &w[i];
}else{ if (
e.width = ww->dx; ww->instance && strstr(ww->instance, name) ||
e.height = ww->dy; ww->class && strstr(ww->class, name)) {
} int value_mask;
value_mask = CWX | CWY | CWWidth | CWHeight; XWindowChanges e;
XConfigureWindow(dpy, ww->xw, value_mask, &e);
XFlush(dpy); memset(&e, 0, sizeof e);
} if (havemin) {
} e.x = old * ww->x + new* r.min.x;
e.y = old * ww->y + new* r.min.y;
} else {
e.x = ww->x;
e.y = ww->y;
}
if (havesize) {
e.width = old * ww->dx + new* Dx(r);
e.height = old * ww->dy + new* Dy(r);
} else {
e.width = ww->dx;
e.height = ww->dy;
}
value_mask = CWX | CWY | CWWidth | CWHeight;
XConfigureWindow(dpy, ww->xw, value_mask, &e);
XFlush(dpy);
}
}
} }
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;
os = s; os = s;
if(*s == '-'){ if (*s == '-') {
s++; s++;
*isdelta = -1; *isdelta = -1;
}else if(*s == '+'){ } else if (*s == '+') {
s++; s++;
*isdelta = 1; *isdelta = 1;
}else } else
*isdelta = 0; *isdelta = 0;
*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)) goto oops;
if(!isdigit((uchar)*s)) j = strtol(s, &s, 0);
goto oops; r->max.x = i;
j = strtol(s, &s, 0); r->max.y = j;
r->max.x = i; *havesize = 1;
r->max.y = j; if (*s == 0) return 0;
*havesize = 1; if (*s != '@') goto oops;
if(*s == 0)
return 0;
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 != ' ') goto oops;
if(*s != ',' && *s != ' ') s++;
goto oops; if (!isdigit((uchar)*s)) goto oops;
s++; j = strtol(s, &s, 0);
if(!isdigit((uchar)*s)) if (*s != 0) goto oops;
goto oops; r->min.x += i;
j = strtol(s, &s, 0); r->max.x += i;
if(*s != 0) r->min.y += j;
goto oops; r->max.y += j;
r->min.x += i; *havesize = 1;
r->max.x += i; *havemin = 1;
r->min.y += j; return 0;
r->max.y += j; }
*havesize = 1;
*havemin = 1;
return 0;
}
c = *s; c = *s;
if(c != ' ' && c != ',') if (c != ' ' && c != ',') goto oops;
goto oops; s++;
s++; if (!isdigit((uchar)*s)) goto oops;
if(!isdigit((uchar)*s)) j = strtol(s, &s, 0);
goto oops; if (*s == 0) {
j = strtol(s, &s, 0); r->min.x = i;
if(*s == 0){ r->min.y = j;
r->min.x = i; *havemin = 1;
r->min.y = j; return 0;
*havemin = 1; }
return 0; if (*s != c) goto oops;
} s++;
if(*s != c) if (!isdigit((uchar)*s)) goto oops;
goto oops; k = strtol(s, &s, 0);
s++; if (*s != c) goto oops;
if(!isdigit((uchar)*s)) s++;
goto oops; if (!isdigit((uchar)*s)) goto oops;
k = strtol(s, &s, 0); l = strtol(s, &s, 0);
if(*s != c) if (*s != 0) goto oops;
goto oops; r->min.x = i;
s++; r->min.y = j;
if(!isdigit((uchar)*s)) r->max.x = k;
goto oops; r->max.y = l;
l = strtol(s, &s, 0); *havemin = 1;
if(*s != 0) *havesize = 1;
goto oops; return 0;
r->min.x = i;
r->min.y = j;
r->max.x = k;
r->max.y = l;
*havemin = 1;
*havesize = 1;
return 0;
oops: oops:
werrstr("bad syntax in window size '%s'", os); werrstr("bad syntax in window size '%s'", os);
return -1; return -1;
} }