2005-11-18 18:54:58 +03:00
|
|
|
/*
|
2006-01-20 17:20:24 +03:00
|
|
|
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
2005-11-18 18:54:58 +03:00
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/wait.h>
|
2006-02-02 00:24:07 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <X11/cursorfont.h>
|
2005-11-18 18:54:58 +03:00
|
|
|
#include <X11/Xproto.h>
|
2005-12-21 18:18:11 +03:00
|
|
|
#include <X11/keysym.h>
|
2005-12-05 04:15:25 +03:00
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xproto.h>
|
2005-11-18 18:54:58 +03:00
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
2005-12-06 20:58:52 +03:00
|
|
|
static XRectangle initial_rect;
|
2005-12-05 01:45:59 +03:00
|
|
|
static int other_wm_running;
|
|
|
|
static int (*x_error_handler) (Display *, XErrorEvent *);
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2006-02-04 17:31:52 +03:00
|
|
|
static char version[] = "wmiiwm - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n";
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
2006-02-04 17:31:52 +03:00
|
|
|
fprintf(stderr, "%s", "usage: wmiiwm -a <address> [-c] [-v]\n");
|
2005-12-21 18:18:11 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scale_rect(XRectangle * from_dim, XRectangle * to_dim,
|
|
|
|
XRectangle * src, XRectangle * tgt)
|
2005-12-05 04:15:25 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
double wfact = (double) to_dim->width / (double) from_dim->width;
|
|
|
|
double hfact = (double) to_dim->height / (double) from_dim->height;
|
|
|
|
|
|
|
|
tgt->x = to_dim->x + (src->x * wfact);
|
|
|
|
tgt->y = to_dim->y + (src->y * hfact);
|
|
|
|
tgt->width = (src->width * wfact);
|
|
|
|
tgt->height = (src->height * hfact);
|
|
|
|
|
|
|
|
if(tgt->width < 1)
|
|
|
|
tgt->width = 1;
|
|
|
|
if(tgt->height < 1)
|
|
|
|
tgt->height = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-25 20:39:08 +03:00
|
|
|
draw_pager_client(Client *c, Draw *d)
|
|
|
|
{
|
2006-02-02 18:44:45 +03:00
|
|
|
if(c == sel_client())
|
|
|
|
d->color = def.sel;
|
|
|
|
else
|
|
|
|
d->color = def.norm;
|
2006-01-25 20:39:08 +03:00
|
|
|
d->data = c->name;
|
|
|
|
scale_rect(&rect, &initial_rect, &c->frame.rect, &d->rect);
|
|
|
|
blitz_drawlabel(dpy, d);
|
|
|
|
XSync(dpy, False); /* do not clear upwards */
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-25 20:39:08 +03:00
|
|
|
draw_pager_page(size_t idx, Draw *d)
|
2005-12-21 18:18:11 +03:00
|
|
|
{
|
2006-02-06 11:46:52 +03:00
|
|
|
int i, j;
|
2005-12-21 18:18:11 +03:00
|
|
|
char name[4];
|
|
|
|
initial_rect = d->rect;
|
|
|
|
|
2006-02-02 18:44:45 +03:00
|
|
|
if(idx == sel)
|
|
|
|
d->color = def.sel;
|
|
|
|
else
|
|
|
|
d->color = def.norm;
|
2006-01-25 20:39:08 +03:00
|
|
|
snprintf(name, sizeof(name), "%d", idx + 1);
|
2005-12-21 18:18:11 +03:00
|
|
|
d->data = name;
|
|
|
|
blitz_drawlabel(dpy, d);
|
|
|
|
XSync(dpy, False);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-02-06 11:46:52 +03:00
|
|
|
for(i = 0; i < page[idx]->narea; i++) {
|
2006-02-02 00:24:07 +03:00
|
|
|
Area *a = page[idx]->area[i];
|
2006-02-06 11:46:52 +03:00
|
|
|
if(!a->nclient)
|
|
|
|
continue;
|
2006-02-06 19:33:10 +03:00
|
|
|
for(j = 0; j < a->nclient; j++)
|
2006-02-02 00:24:07 +03:00
|
|
|
draw_pager_client(a->client[j], d);
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
2005-12-05 04:15:25 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
static void
|
|
|
|
draw_pager()
|
|
|
|
{
|
|
|
|
Draw d = { 0 };
|
2006-01-25 20:39:08 +03:00
|
|
|
unsigned int i, ic, ir, tw, th, rows, cols;
|
2005-12-21 18:18:11 +03:00
|
|
|
int dx;
|
|
|
|
|
2006-01-26 17:24:34 +03:00
|
|
|
for(i = 0; (i < pagesz) && page[i]; i++);
|
2006-01-25 20:39:08 +03:00
|
|
|
blitz_getbasegeometry(i, &cols, &rows);
|
2006-02-02 21:32:25 +03:00
|
|
|
dx = (cols - 1) * DEF_PAGER_GAP; /* DEF_PAGER_GAPpx space */
|
2005-12-21 18:18:11 +03:00
|
|
|
tw = (rect.width - dx) / cols;
|
|
|
|
th = ((double) tw / rect.width) * rect.height;
|
|
|
|
d.drawable = transient;
|
2006-01-25 20:39:08 +03:00
|
|
|
d.gc = gc_transient;
|
2006-02-02 00:24:07 +03:00
|
|
|
d.font = xfont;
|
2006-02-07 02:32:57 +03:00
|
|
|
d.align = CENTER;
|
2006-01-25 20:39:08 +03:00
|
|
|
i = 0;
|
2005-12-21 18:18:11 +03:00
|
|
|
for(ir = 0; ir < rows; ir++) {
|
|
|
|
for(ic = 0; ic < cols; ic++) {
|
2006-02-02 21:32:25 +03:00
|
|
|
d.rect.x = ic * tw + (ic * DEF_PAGER_GAP);
|
2005-12-21 18:18:11 +03:00
|
|
|
d.rect.width = tw;
|
|
|
|
if(rows == 1)
|
|
|
|
d.rect.y = 0;
|
|
|
|
else
|
|
|
|
d.rect.y = ir * (rect.height - th) / (rows - 1);
|
|
|
|
d.rect.height = th;
|
2006-01-25 20:39:08 +03:00
|
|
|
draw_pager_page(i++, &d);
|
2006-01-26 17:24:34 +03:00
|
|
|
if(!page[i])
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
static int
|
2005-12-21 18:18:11 +03:00
|
|
|
xy_to_pager_page(int x, int y)
|
|
|
|
{
|
2006-01-25 20:39:08 +03:00
|
|
|
unsigned int i, ic, ir, tw, th, rows, cols;
|
2005-12-21 18:18:11 +03:00
|
|
|
int dx;
|
|
|
|
XRectangle r;
|
|
|
|
|
2006-01-26 17:24:34 +03:00
|
|
|
for(i = 0; (i < pagesz) && page[i]; i++);
|
2006-01-25 20:39:08 +03:00
|
|
|
blitz_getbasegeometry(i, &cols, &rows);
|
2006-02-02 21:32:25 +03:00
|
|
|
dx = (cols - 1) * DEF_PAGER_GAP; /* DEF_PAGER_GAPpx space */
|
2005-12-21 18:18:11 +03:00
|
|
|
tw = (rect.width - dx) / cols;
|
|
|
|
th = ((double) tw / rect.width) * rect.height;
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
i = 0;
|
2005-12-21 18:18:11 +03:00
|
|
|
for(ir = 0; ir < rows; ir++) {
|
|
|
|
for(ic = 0; ic < cols; ic++) {
|
2006-02-02 21:32:25 +03:00
|
|
|
r.x = ic * tw + (ic * DEF_PAGER_GAP);
|
2005-12-21 18:18:11 +03:00
|
|
|
r.width = tw;
|
|
|
|
if(rows == 1)
|
|
|
|
r.y = 0;
|
|
|
|
else
|
|
|
|
r.y = ir * (rect.height - th) / (rows - 1);
|
|
|
|
r.height = th;
|
|
|
|
if(blitz_ispointinrect(x, y, &r))
|
2006-01-25 20:39:08 +03:00
|
|
|
return i;
|
|
|
|
i++;
|
2006-01-26 17:24:34 +03:00
|
|
|
if(!page[i])
|
2006-01-25 20:39:08 +03:00
|
|
|
return -1;
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
return -1;
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
handle_kpress(XKeyEvent * e)
|
|
|
|
{
|
|
|
|
KeySym ksym = XKeycodeToKeysym(dpy, e->keycode, 0);
|
|
|
|
|
2006-01-18 19:45:27 +03:00
|
|
|
if(ksym >= XK_1 && ksym <= XK_9)
|
|
|
|
return ksym - XK_1;
|
|
|
|
else if(ksym == XK_0)
|
|
|
|
return 9;
|
2005-12-21 18:18:11 +03:00
|
|
|
else if(ksym >= XK_a && ksym <= XK_z)
|
|
|
|
return 10 + ksym - XK_a;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-02-06 11:46:52 +03:00
|
|
|
void
|
|
|
|
pager()
|
2005-12-21 18:18:11 +03:00
|
|
|
{
|
|
|
|
XEvent ev;
|
|
|
|
int i;
|
2006-01-25 20:39:08 +03:00
|
|
|
size_t j;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-01-26 17:24:34 +03:00
|
|
|
if(!page)
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
|
|
|
|
2006-01-26 17:24:34 +03:00
|
|
|
for(j = 0; (j < pagesz) && page[j]; j++);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
XClearWindow(dpy, transient);
|
|
|
|
XMapRaised(dpy, transient);
|
|
|
|
draw_pager();
|
|
|
|
|
|
|
|
while(XGrabKeyboard
|
|
|
|
(dpy, transient, True, GrabModeAsync, GrabModeAsync,
|
|
|
|
CurrentTime) != GrabSuccess)
|
|
|
|
usleep(20000);
|
|
|
|
|
|
|
|
while(XGrabPointer
|
|
|
|
(dpy, transient, False, ButtonPressMask, GrabModeAsync,
|
|
|
|
GrabModeAsync, None, normal_cursor, CurrentTime) != GrabSuccess)
|
|
|
|
usleep(20000);
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
while(!XCheckWindowEvent
|
|
|
|
(dpy, transient, ButtonPressMask | KeyPressMask, &ev)) {
|
|
|
|
usleep(20000);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ev.type) {
|
|
|
|
case KeyPress:
|
|
|
|
XUnmapWindow(dpy, transient);
|
|
|
|
if((i = handle_kpress(&ev.xkey)) != -1)
|
2006-01-25 20:39:08 +03:00
|
|
|
if(i < j)
|
2006-01-26 17:24:34 +03:00
|
|
|
focus_page(page[i]);
|
2005-12-21 18:18:11 +03:00
|
|
|
XUngrabKeyboard(dpy, CurrentTime);
|
|
|
|
XUngrabPointer(dpy, CurrentTime /* ev.xbutton.time */ );
|
2006-02-08 14:33:25 +03:00
|
|
|
XSync(dpy, False);
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
XUnmapWindow(dpy, transient);
|
2006-01-17 19:01:35 +03:00
|
|
|
if(ev.xbutton.button == Button1)
|
2006-01-26 17:24:34 +03:00
|
|
|
focus_page(page[xy_to_pager_page(ev.xbutton.x, ev.xbutton.y)]);
|
2005-12-21 18:18:11 +03:00
|
|
|
XUngrabKeyboard(dpy, CurrentTime);
|
|
|
|
XUngrabPointer(dpy, CurrentTime /* ev.xbutton.time */ );
|
2006-02-08 14:33:25 +03:00
|
|
|
XSync(dpy, False);
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-12-05 04:15:25 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
static void
|
2006-02-06 11:46:52 +03:00
|
|
|
map_detached_clients()
|
2005-12-21 18:18:11 +03:00
|
|
|
{
|
2006-01-25 20:39:08 +03:00
|
|
|
unsigned int i, ic, ir, tw, th, rows, cols;
|
2005-12-21 18:18:11 +03:00
|
|
|
int dx, dy;
|
|
|
|
XRectangle cr;
|
|
|
|
|
2006-02-02 00:24:07 +03:00
|
|
|
for(i = 0; i < ndet; i++);
|
2006-01-25 20:39:08 +03:00
|
|
|
blitz_getbasegeometry(i, &cols, &rows);
|
2006-01-19 18:01:01 +03:00
|
|
|
if(!cols)
|
|
|
|
cols = 1;
|
|
|
|
if(!rows)
|
|
|
|
rows = 1;
|
2006-02-02 21:32:25 +03:00
|
|
|
dx = (cols - 1) * DEF_PAGER_GAP; /* DEF_PAGER_GAPpx space */
|
|
|
|
dy = (rows - 1) * DEF_PAGER_GAP; /* DEF_PAGER_GAPpx space */
|
2005-12-21 18:18:11 +03:00
|
|
|
tw = (rect.width - dx) / cols;
|
|
|
|
th = (rect.height - dy) / rows;
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
i = 0;
|
2005-12-21 18:18:11 +03:00
|
|
|
for(ir = 0; ir < rows; ir++) {
|
|
|
|
for(ic = 0; ic < cols; ic++) {
|
2006-02-02 00:24:07 +03:00
|
|
|
if(!det[i++])
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
2006-02-02 21:32:25 +03:00
|
|
|
cr.x = ic * tw + (ic * DEF_PAGER_GAP);
|
|
|
|
cr.y = ir * th + (ir * DEF_PAGER_GAP);
|
2005-12-21 18:18:11 +03:00
|
|
|
cr.width = tw;
|
|
|
|
cr.height = th;
|
2006-02-02 00:24:07 +03:00
|
|
|
XMoveResizeWindow(dpy, det[i]->win, cr.x, cr.y, cr.width, cr.height);
|
|
|
|
configure_client(det[i]);
|
|
|
|
map_client(det[i]);
|
2006-02-03 21:00:00 +03:00
|
|
|
grab_window(det[i]->win, AnyModifier, Button1);
|
2006-02-02 00:24:07 +03:00
|
|
|
XRaiseWindow(dpy, det[i]->win);
|
2005-12-21 18:18:11 +03:00
|
|
|
XSync(dpy, False);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-06 11:46:52 +03:00
|
|
|
void
|
|
|
|
detached_clients()
|
2005-12-21 18:18:11 +03:00
|
|
|
{
|
|
|
|
XEvent ev;
|
|
|
|
int n;
|
2006-02-02 00:24:07 +03:00
|
|
|
size_t i;
|
2006-01-25 20:39:08 +03:00
|
|
|
Client *c;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-02-02 00:24:07 +03:00
|
|
|
if(!ndet)
|
2006-01-18 21:34:10 +03:00
|
|
|
return;
|
2005-12-21 18:18:11 +03:00
|
|
|
XClearWindow(dpy, transient);
|
|
|
|
XMapRaised(dpy, transient);
|
2006-02-06 11:46:52 +03:00
|
|
|
map_detached_clients();
|
2005-12-21 18:18:11 +03:00
|
|
|
while(XGrabKeyboard
|
|
|
|
(dpy, transient, True, GrabModeAsync, GrabModeAsync,
|
|
|
|
CurrentTime) != GrabSuccess)
|
|
|
|
usleep(20000);
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
while(!XCheckMaskEvent(dpy, ButtonPressMask | KeyPressMask, &ev)) {
|
|
|
|
usleep(20000);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (ev.type) {
|
|
|
|
case KeyPress:
|
|
|
|
XUnmapWindow(dpy, transient);
|
2006-02-02 00:24:07 +03:00
|
|
|
for(i = 0; i < ndet; i++)
|
|
|
|
unmap_client(det[i]);
|
2005-12-21 18:18:11 +03:00
|
|
|
if((n = handle_kpress(&ev.xkey)) != -1) {
|
2006-02-02 00:24:07 +03:00
|
|
|
if(n < ndet) {
|
|
|
|
c = det[n];
|
|
|
|
cext_array_detach((void **)det, c, &detsz);
|
|
|
|
ndet--;
|
2006-01-26 14:39:20 +03:00
|
|
|
attach_client(c);
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
XUngrabKeyboard(dpy, CurrentTime);
|
2006-02-08 14:33:25 +03:00
|
|
|
XSync(dpy, False);
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
XUnmapWindow(dpy, transient);
|
2006-02-02 00:24:07 +03:00
|
|
|
for(i = 0; i < ndet; i++)
|
|
|
|
unmap_client(det[i]);
|
2005-12-21 18:18:11 +03:00
|
|
|
if((ev.xbutton.button == Button1)
|
|
|
|
&& (c = win_to_client(ev.xbutton.window))) {
|
2006-02-02 00:24:07 +03:00
|
|
|
cext_array_detach((void **)det, c, &detsz);
|
|
|
|
ndet--;
|
2005-12-21 18:18:11 +03:00
|
|
|
attach_client(c);
|
|
|
|
}
|
|
|
|
XUngrabKeyboard(dpy, CurrentTime);
|
2006-02-08 14:33:25 +03:00
|
|
|
XSync(dpy, False);
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-06 11:46:52 +03:00
|
|
|
void
|
|
|
|
attach_detached_client()
|
2005-12-21 18:18:11 +03:00
|
|
|
{
|
2006-02-02 00:24:07 +03:00
|
|
|
Client *c = ndet ? det[0] : nil;
|
2005-12-21 18:18:11 +03:00
|
|
|
if(c) {
|
2006-02-02 00:24:07 +03:00
|
|
|
cext_array_detach((void **)det, c, &detsz);
|
|
|
|
ndet--;
|
2005-12-21 18:18:11 +03:00
|
|
|
attach_client(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-06 11:46:52 +03:00
|
|
|
void
|
|
|
|
select_page(char *arg)
|
2005-12-21 18:18:11 +03:00
|
|
|
{
|
2006-02-02 00:24:07 +03:00
|
|
|
size_t new = sel;
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-02-02 00:24:07 +03:00
|
|
|
if(!npage || !arg)
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
|
|
|
if(!strncmp(arg, "prev", 5)) {
|
2006-01-26 14:56:28 +03:00
|
|
|
if(new > 0)
|
2006-01-26 17:24:34 +03:00
|
|
|
for(new = 0; page[new]; new++);
|
2006-01-26 14:56:28 +03:00
|
|
|
new--;
|
2005-12-21 18:18:11 +03:00
|
|
|
} else if(!strncmp(arg, "next", 5)) {
|
2006-01-26 17:24:34 +03:00
|
|
|
if(page[new + 1])
|
2006-01-26 14:56:28 +03:00
|
|
|
new++;
|
2006-01-18 19:45:27 +03:00
|
|
|
else
|
2006-01-26 14:56:28 +03:00
|
|
|
new = 0;
|
2006-01-25 20:39:08 +03:00
|
|
|
} else {
|
2006-02-02 00:24:07 +03:00
|
|
|
int idx = blitz_strtonum(arg, 0, npage);
|
|
|
|
if(idx < npage)
|
2006-01-26 14:56:28 +03:00
|
|
|
new = idx;
|
2006-01-18 19:45:27 +03:00
|
|
|
}
|
2006-01-26 17:24:34 +03:00
|
|
|
focus_page(page[new]);
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Client *
|
|
|
|
win_to_client(Window w)
|
|
|
|
{
|
2006-01-25 20:39:08 +03:00
|
|
|
size_t i;
|
|
|
|
|
2006-01-26 21:58:30 +03:00
|
|
|
for(i = 0; (i < clientsz) && client[i]; i++)
|
2006-01-26 17:24:34 +03:00
|
|
|
if(client[i]->win == w)
|
|
|
|
return client[i];
|
2006-01-25 20:39:08 +03:00
|
|
|
return nil;
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scan_wins()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned int num;
|
|
|
|
Window *wins;
|
|
|
|
XWindowAttributes wa;
|
|
|
|
Window d1, d2;
|
|
|
|
Client *c;
|
|
|
|
|
|
|
|
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
|
|
|
|
for(i = 0; i < num; i++) {
|
|
|
|
if(!XGetWindowAttributes(dpy, wins[i], &wa))
|
|
|
|
continue;
|
|
|
|
if(wa.override_redirect
|
|
|
|
|| XGetTransientForHint(dpy, wins[i], &d1))
|
|
|
|
continue;
|
|
|
|
if(wa.map_state == IsViewable) {
|
2006-01-25 20:39:08 +03:00
|
|
|
c = alloc_client(wins[i], &wa);
|
2005-12-21 18:18:11 +03:00
|
|
|
attach_client(c);
|
|
|
|
c->ignore_unmap++; /* was viewable already */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(wins)
|
|
|
|
XFree(wins);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
win_proto(Window w)
|
|
|
|
{
|
|
|
|
Atom *protocols;
|
|
|
|
long res;
|
|
|
|
int protos = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
res =
|
|
|
|
wmii_property(dpy, w, wm_protocols, XA_ATOM, 20L,
|
|
|
|
((unsigned char **) &protocols));
|
|
|
|
if(res <= 0) {
|
|
|
|
return protos;
|
|
|
|
}
|
|
|
|
for(i = 0; i < res; i++) {
|
|
|
|
if(protocols[i] == wm_delete) {
|
|
|
|
protos |= PROTO_DEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free((char *) protocols);
|
|
|
|
return protos;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
win_state(Window w)
|
|
|
|
{
|
|
|
|
/* state hints */
|
|
|
|
XWMHints *hints = XGetWMHints(dpy, w);
|
|
|
|
int res;
|
|
|
|
|
|
|
|
long *prop = 0;
|
|
|
|
if(wmii_property
|
|
|
|
(dpy, w, wm_state, wm_state, 2L, ((unsigned char **) &prop)) > 0) {
|
|
|
|
res = (int) *prop;
|
|
|
|
free((long *) prop);
|
|
|
|
} else {
|
|
|
|
res = hints ? hints->initial_state : NormalState;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hints) {
|
|
|
|
free(hints);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_atoms()
|
|
|
|
{
|
|
|
|
wm_state = XInternAtom(dpy, "WM_STATE", False);
|
|
|
|
wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False);
|
|
|
|
wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
|
|
|
wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
|
|
|
motif_wm_hints = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
|
2005-12-27 23:13:50 +03:00
|
|
|
net_atoms[NET_NUMBER_OF_DESKTOPS] = XInternAtom(dpy, "_NET_NUMBER_OF_DESKTOPS", False);
|
|
|
|
net_atoms[NET_CURRENT_DESKTOP] = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False);
|
|
|
|
net_atoms[NET_WM_DESKTOP] = XInternAtom(dpy, "_NET_WM_DESKTOP", False);
|
|
|
|
XChangeProperty(dpy, root, XInternAtom(dpy, "_NET_SUPPORTED", False), XA_ATOM, 32, PropModeReplace, (unsigned char *) net_atoms, NET_ATOM_COUNT);
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_cursors()
|
|
|
|
{
|
|
|
|
normal_cursor = XCreateFontCursor(dpy, XC_left_ptr);
|
|
|
|
resize_cursor = XCreateFontCursor(dpy, XC_sizing);
|
|
|
|
move_cursor = XCreateFontCursor(dpy, XC_fleur);
|
|
|
|
drag_cursor = XCreateFontCursor(dpy, XC_cross);
|
|
|
|
w_cursor = XCreateFontCursor(dpy, XC_left_side);
|
|
|
|
e_cursor = XCreateFontCursor(dpy, XC_right_side);
|
|
|
|
n_cursor = XCreateFontCursor(dpy, XC_top_side);
|
|
|
|
s_cursor = XCreateFontCursor(dpy, XC_bottom_side);
|
|
|
|
nw_cursor = XCreateFontCursor(dpy, XC_top_left_corner);
|
|
|
|
ne_cursor = XCreateFontCursor(dpy, XC_top_right_corner);
|
|
|
|
sw_cursor = XCreateFontCursor(dpy, XC_bottom_left_corner);
|
|
|
|
se_cursor = XCreateFontCursor(dpy, XC_bottom_right_corner);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_screen()
|
|
|
|
{
|
|
|
|
XGCValues gcv;
|
|
|
|
XSetWindowAttributes wa;
|
|
|
|
|
|
|
|
gcv.subwindow_mode = IncludeInferiors;
|
|
|
|
gcv.function = GXxor;
|
2006-02-02 22:08:34 +03:00
|
|
|
gcv.foreground = def.sel.bg;
|
2005-12-21 18:18:11 +03:00
|
|
|
gcv.line_width = 4;
|
|
|
|
gcv.plane_mask = AllPlanes;
|
|
|
|
gcv.graphics_exposures = False;
|
2006-01-25 20:39:08 +03:00
|
|
|
gc_xor = XCreateGC(dpy, root, GCForeground | GCGraphicsExposures
|
2005-12-21 18:18:11 +03:00
|
|
|
| GCFunction | GCSubwindowMode | GCLineWidth
|
|
|
|
| GCPlaneMask, &gcv);
|
|
|
|
rect.x = rect.y = 0;
|
2006-01-25 20:39:08 +03:00
|
|
|
rect.width = DisplayWidth(dpy, screen);
|
|
|
|
rect.height = DisplayHeight(dpy, screen);
|
2005-12-21 18:18:11 +03:00
|
|
|
|
|
|
|
wa.override_redirect = 1;
|
|
|
|
wa.background_pixmap = ParentRelative;
|
|
|
|
wa.event_mask = ExposureMask | ButtonPressMask;
|
|
|
|
transient =
|
|
|
|
XCreateWindow(dpy, root, 0, 0, rect.width, rect.height, 0,
|
2006-01-25 20:39:08 +03:00
|
|
|
DefaultDepth(dpy, screen), CopyFromParent,
|
|
|
|
DefaultVisual(dpy, screen),
|
2005-12-21 18:18:11 +03:00
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask,
|
|
|
|
&wa);
|
|
|
|
|
|
|
|
XSync(dpy, False);
|
2006-01-25 20:39:08 +03:00
|
|
|
gc_transient = XCreateGC(dpy, transient, 0, 0);
|
2005-12-21 18:18:11 +03:00
|
|
|
XDefineCursor(dpy, transient, normal_cursor);
|
|
|
|
XDefineCursor(dpy, root, normal_cursor);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There's no way to check accesses to destroyed windows, thus
|
|
|
|
* those cases are ignored (especially on UnmapNotify's).
|
|
|
|
* Other types of errors call Xlib's default error handler, which
|
|
|
|
* calls exit().
|
|
|
|
*/
|
2005-12-21 18:18:11 +03:00
|
|
|
static int
|
|
|
|
wmii_error_handler(Display * dpy, XErrorEvent * error)
|
|
|
|
{
|
|
|
|
if(error->error_code == BadWindow
|
|
|
|
|| (error->request_code == X_SetInputFocus
|
|
|
|
&& error->error_code == BadMatch)
|
|
|
|
|| (error->request_code == X_PolyText8
|
|
|
|
&& error->error_code == BadDrawable)
|
|
|
|
|| (error->request_code == X_PolyFillRectangle
|
|
|
|
&& error->error_code == BadDrawable)
|
|
|
|
|| (error->request_code == X_PolySegment
|
|
|
|
&& error->error_code == BadDrawable)
|
|
|
|
|| (error->request_code == X_ConfigureWindow
|
|
|
|
&& error->error_code == BadMatch))
|
|
|
|
return 0;
|
|
|
|
fprintf(stderr, "%s", "wmiiwm: fatal error");
|
|
|
|
return x_error_handler(dpy, error); /* calls exit() */
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Startup Error handler to check if another window manager
|
|
|
|
* is already running.
|
|
|
|
*/
|
2005-12-21 18:18:11 +03:00
|
|
|
static int
|
|
|
|
startup_error_handler(Display * dpy, XErrorEvent * error)
|
|
|
|
{
|
|
|
|
other_wm_running = 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup()
|
|
|
|
{
|
2006-01-25 20:39:08 +03:00
|
|
|
size_t i;
|
|
|
|
Client *c;
|
2006-01-26 17:24:34 +03:00
|
|
|
for(i = 0; client && client[i]; i++) {
|
|
|
|
c = client[i];
|
2006-01-25 20:39:08 +03:00
|
|
|
reparent_client(c, root, c->frame.rect.x + c->rect.x, c->frame.rect.y + c->rect.y);
|
|
|
|
}
|
2005-12-21 18:18:11 +03:00
|
|
|
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
2006-01-10 16:43:09 +03:00
|
|
|
XSync(dpy, False);
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 21:00:00 +03:00
|
|
|
void
|
|
|
|
grab_window(Window w, unsigned long mod, unsigned int button)
|
|
|
|
{
|
|
|
|
XGrabButton(dpy, button, mod, w, False,
|
|
|
|
ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
|
|
|
|
if((mod != AnyModifier) && num_lock_mask) {
|
|
|
|
XGrabButton(dpy, button, mod | num_lock_mask, w, False,
|
|
|
|
ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
|
|
|
|
XGrabButton(dpy, button, mod | num_lock_mask | LockMask, w,
|
|
|
|
False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ungrab_window(Window w, unsigned long mod, unsigned int button)
|
|
|
|
{
|
|
|
|
XUngrabButton(dpy, button, mod, w);
|
|
|
|
if(mod != AnyModifier && num_lock_mask) {
|
|
|
|
XUngrabButton(dpy, button, mod | num_lock_mask, w);
|
|
|
|
XUngrabButton(dpy, button, mod | num_lock_mask | LockMask, w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-08 12:50:09 +03:00
|
|
|
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int checkwm = 0;
|
2006-02-03 20:11:22 +03:00
|
|
|
char *address = nil, *errstr;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
|
|
|
/* command line args */
|
|
|
|
if(argc > 1) {
|
|
|
|
for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
|
|
|
|
switch (argv[i][1]) {
|
|
|
|
case 'v':
|
2006-02-04 17:31:52 +03:00
|
|
|
fprintf(stdout, "%s", version);
|
2005-12-21 18:18:11 +03:00
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
checkwm = 1;
|
|
|
|
break;
|
2006-02-02 18:44:45 +03:00
|
|
|
case 'a':
|
2005-12-21 18:18:11 +03:00
|
|
|
if(i + 1 < argc)
|
2006-02-02 00:24:07 +03:00
|
|
|
address = argv[++i];
|
2005-12-21 18:18:11 +03:00
|
|
|
else
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-06 17:46:02 +03:00
|
|
|
|
|
|
|
if(!address)
|
|
|
|
usage();
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
dpy = XOpenDisplay(0);
|
|
|
|
if(!dpy) {
|
|
|
|
fprintf(stderr, "%s", "wmiiwm: cannot open display\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
screen = DefaultScreen(dpy);
|
|
|
|
root = RootWindow(dpy, screen);
|
2005-12-21 18:18:11 +03:00
|
|
|
|
|
|
|
/* check if another WM is already running */
|
|
|
|
other_wm_running = 0;
|
|
|
|
XSetErrorHandler(startup_error_handler);
|
|
|
|
/* this causes an error if some other WM is running */
|
|
|
|
XSelectInput(dpy, root, ROOT_MASK);
|
|
|
|
XSync(dpy, False);
|
|
|
|
|
|
|
|
if(other_wm_running) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"wmiiwm: another window manager is already running\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if(checkwm) {
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
XSetErrorHandler(0);
|
|
|
|
x_error_handler = XSetErrorHandler(wmii_error_handler);
|
2006-02-02 16:50:04 +03:00
|
|
|
errstr = nil;
|
|
|
|
i = ixp_create_sock(address, &errstr);
|
|
|
|
if(i < 0) {
|
|
|
|
fprintf(stderr, "wmii: fatal: %s\n", errstr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IXP server */
|
2006-02-03 20:11:22 +03:00
|
|
|
ixp_server_open_conn(&srv, i, new_ixp_conn, ixp_server_close_conn);
|
2006-02-02 18:44:45 +03:00
|
|
|
root_qid.type = IXP_QTDIR;
|
|
|
|
root_qid.version = 0;
|
|
|
|
root_qid.path = mkqpath(Droot, 0, 0, 0);
|
2006-02-02 16:50:04 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
/* X server */
|
|
|
|
ixp_server_open_conn(&srv, ConnectionNumber(dpy), check_x_event, nil);
|
2006-02-02 19:23:04 +03:00
|
|
|
init_x_event_handler();
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-02-02 00:24:07 +03:00
|
|
|
ndet = npage = nclient = aqsz = detsz = pagesz = clientsz = sel = 0;
|
2006-01-26 17:24:34 +03:00
|
|
|
page = nil;
|
2006-02-02 00:24:07 +03:00
|
|
|
client = det = nil;
|
|
|
|
aq = nil;
|
|
|
|
|
2006-02-02 22:36:10 +03:00
|
|
|
def.font = strdup(BLITZ_FONT);
|
2006-02-02 21:32:25 +03:00
|
|
|
def.border = DEF_BORDER;
|
|
|
|
def.snap = DEF_SNAP;
|
2006-02-04 21:55:37 +03:00
|
|
|
def.inc = def.bar = True;
|
2006-02-02 18:44:45 +03:00
|
|
|
cext_strlcpy(def.selcolor, BLITZ_SEL_COLOR, sizeof(def.selcolor));
|
2006-02-02 19:23:04 +03:00
|
|
|
blitz_loadcolor(dpy, screen, def.selcolor, &def.sel);
|
2006-02-02 22:36:10 +03:00
|
|
|
cext_strlcpy(def.normcolor, BLITZ_NORM_COLOR, sizeof(def.normcolor));
|
2006-02-02 19:23:04 +03:00
|
|
|
blitz_loadcolor(dpy, screen, def.normcolor, &def.norm);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
init_atoms();
|
|
|
|
init_cursors();
|
2006-02-02 00:24:07 +03:00
|
|
|
xfont = blitz_getfont(dpy, def.font);
|
2005-12-21 18:18:11 +03:00
|
|
|
wmii_init_lock_modifiers(dpy, &valid_mask, &num_lock_mask);
|
|
|
|
init_screen();
|
|
|
|
scan_wins();
|
|
|
|
/* main event loop */
|
2006-02-02 16:50:04 +03:00
|
|
|
errstr = ixp_server_loop(&srv);
|
|
|
|
if(errstr)
|
|
|
|
fprintf(stderr, "wmii: fatal: %s\n", errstr);
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
ixp_server_close(&srv);
|
2005-12-21 18:18:11 +03:00
|
|
|
cleanup();
|
2006-02-02 19:23:04 +03:00
|
|
|
XCloseDisplay(dpy);
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
return errstr ? 1 : 0;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|