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 <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
2006-03-23 16:37:54 +03:00
|
|
|
#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask)
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
Client *
|
2006-01-25 20:39:08 +03:00
|
|
|
alloc_client(Window w, XWindowAttributes *wa)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
XTextProperty name;
|
|
|
|
Client *c = (Client *) cext_emallocz(sizeof(Client));
|
|
|
|
XSetWindowAttributes fwa;
|
2006-03-10 13:59:26 +03:00
|
|
|
XClassHint ch;
|
2006-03-23 01:49:18 +03:00
|
|
|
long msize;
|
2006-03-07 19:22:36 +03:00
|
|
|
static unsigned int id = 1;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-03-07 19:22:36 +03:00
|
|
|
c->id = id++;
|
2006-03-23 01:49:18 +03:00
|
|
|
c->win = w;
|
|
|
|
c->rect.x = wa->x;
|
|
|
|
c->rect.y = wa->y;
|
|
|
|
c->border = wa->border_width;
|
|
|
|
c->rect.width = wa->width + 2 * c->border;
|
|
|
|
c->rect.height = wa->height + 2 * c->border;
|
|
|
|
XSetWindowBorderWidth(dpy, c->win, 0);
|
|
|
|
c->proto = win_proto(c->win);
|
|
|
|
XGetTransientForHint(dpy, c->win, &c->trans);
|
|
|
|
if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
|
|
|
|
c->size.flags = PSize;
|
|
|
|
XAddToSaveSet(dpy, c->win);
|
|
|
|
XGetWMName(dpy, c->win, &name);
|
2006-01-03 12:30:15 +03:00
|
|
|
if(name.value) {
|
2006-01-04 18:28:31 +03:00
|
|
|
cext_strlcpy(c->name, (char *)name.value, sizeof(c->name));
|
2006-03-23 01:49:18 +03:00
|
|
|
free(name.value);
|
2006-01-03 12:30:15 +03:00
|
|
|
}
|
2006-03-10 17:41:57 +03:00
|
|
|
if(XGetClassHint(dpy, c->win, &ch)) {
|
2006-03-23 01:49:18 +03:00
|
|
|
snprintf(c->classinst, sizeof(c->classinst), "%s:%s", ch.res_class,
|
|
|
|
ch.res_name);
|
2006-03-10 19:17:59 +03:00
|
|
|
XFree(ch.res_class);
|
|
|
|
XFree(ch.res_name);
|
2006-03-10 17:41:57 +03:00
|
|
|
}
|
2006-03-23 01:49:18 +03:00
|
|
|
fwa.override_redirect = 1;
|
|
|
|
fwa.background_pixmap = ParentRelative;
|
|
|
|
fwa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
|
|
|
|
| ExposureMask | ButtonPressMask;
|
|
|
|
|
|
|
|
c->framewin = XCreateWindow(dpy, root, c->rect.x, c->rect.y,
|
|
|
|
c->rect.width + 2 * def.border,
|
|
|
|
c->rect.height + def.border + bar_height(), 0,
|
|
|
|
DefaultDepth(dpy, screen), CopyFromParent,
|
|
|
|
DefaultVisual(dpy, screen),
|
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
|
|
|
|
c->gc = XCreateGC(dpy, c->framewin, 0, 0);
|
|
|
|
XSync(dpy, False);
|
|
|
|
client = (Client **)cext_array_attach((void **)client, c,
|
|
|
|
sizeof(Client *), &clientsz);
|
2006-02-03 18:15:36 +03:00
|
|
|
nclient++;
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
return c;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
set_client_state(Client * c, int state)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
long data[2];
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
data[0] = (long) state;
|
|
|
|
data[1] = (long) None;
|
|
|
|
XChangeProperty(dpy, c->win, wm_atom[WMState], wm_atom[WMState], 32,
|
|
|
|
PropModeReplace, (unsigned char *) data, 2);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-01-19 17:02:18 +03:00
|
|
|
void
|
2006-02-28 10:51:53 +03:00
|
|
|
focus_client(Client *c)
|
2006-01-26 14:39:20 +03:00
|
|
|
{
|
|
|
|
Client *old = sel_client();
|
2006-03-07 01:55:47 +03:00
|
|
|
Frame *f = c->frame[c->sel];
|
2006-03-05 03:55:45 +03:00
|
|
|
int i = area2index(f->area);
|
2006-03-23 01:49:18 +03:00
|
|
|
|
2006-03-23 12:36:51 +03:00
|
|
|
f->area->view->sel = i;
|
2006-03-05 03:55:45 +03:00
|
|
|
f->area->sel = frame2index(f);
|
2006-01-26 14:39:20 +03:00
|
|
|
if(old && (old != c)) {
|
2006-03-23 18:04:22 +03:00
|
|
|
grab_mouse(old->framewin, AnyModifier, Button1);
|
2006-03-23 01:49:18 +03:00
|
|
|
draw_client(old);
|
2006-01-19 17:02:18 +03:00
|
|
|
}
|
2006-03-23 18:04:22 +03:00
|
|
|
ungrab_mouse(c->framewin, AnyModifier, AnyButton);
|
|
|
|
grab_mouse(c->framewin, Mod1Mask, Button1);
|
|
|
|
grab_mouse(c->framewin, Mod1Mask, Button3);
|
2006-03-09 15:19:12 +03:00
|
|
|
|
2006-03-23 12:43:57 +03:00
|
|
|
restack_view(f->area->view);
|
2006-03-09 15:19:12 +03:00
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
|
|
|
draw_client(c);
|
2006-01-19 17:02:18 +03:00
|
|
|
XSync(dpy, False);
|
2006-03-05 03:55:45 +03:00
|
|
|
if(i > 0 && f->area->mode == Colstack)
|
2006-03-27 10:38:17 +04:00
|
|
|
arrange_column(f->area);
|
2006-01-19 17:02:18 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-03-09 14:22:53 +03:00
|
|
|
map_client(Client *c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-02-17 01:49:44 +03:00
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
2006-03-23 01:49:18 +03:00
|
|
|
XMapWindow(dpy, c->win);
|
2006-02-17 01:49:44 +03:00
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK);
|
2006-03-23 01:49:18 +03:00
|
|
|
set_client_state(c, NormalState);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-03-09 14:22:53 +03:00
|
|
|
unmap_client(Client *c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-02-09 21:40:12 +03:00
|
|
|
ungrab_mouse(c->win, AnyModifier, AnyButton);
|
2006-02-17 01:49:44 +03:00
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
2006-03-23 01:49:18 +03:00
|
|
|
XUnmapWindow(dpy, c->win);
|
2006-02-17 01:49:44 +03:00
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK);
|
2006-03-23 01:49:18 +03:00
|
|
|
set_client_state(c, WithdrawnState);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-25 21:41:12 +03:00
|
|
|
reparent_client(Client *c, Window w, int x, int y)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-02-17 01:49:44 +03:00
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
|
|
|
XReparentWindow(dpy, c->win, w, x, y);
|
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-03-05 03:55:45 +03:00
|
|
|
configure_client(Client *c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
XConfigureEvent e;
|
2006-03-07 01:55:47 +03:00
|
|
|
Frame *f = c->frame[c->sel];
|
2006-03-23 01:49:18 +03:00
|
|
|
e.type = ConfigureNotify;
|
|
|
|
e.event = c->win;
|
|
|
|
e.window = c->win;
|
|
|
|
e.x = c->rect.x;
|
|
|
|
e.y = c->rect.y;
|
2006-03-05 03:55:45 +03:00
|
|
|
if(f) {
|
2006-03-23 01:49:18 +03:00
|
|
|
e.x += f->rect.x;
|
|
|
|
e.y += f->rect.y;
|
2006-01-25 21:41:12 +03:00
|
|
|
}
|
2006-03-23 01:49:18 +03:00
|
|
|
e.width = c->rect.width;
|
|
|
|
e.height = c->rect.height;
|
|
|
|
e.border_width = c->border;
|
|
|
|
e.above = None;
|
|
|
|
e.override_redirect = False;
|
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
|
|
|
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *) & e);
|
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK);
|
|
|
|
XSync(dpy, False);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-02-10 00:48:01 +03:00
|
|
|
static void
|
|
|
|
send_client_message(Window w, Atom a, long value)
|
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
XEvent e;
|
|
|
|
e.type = ClientMessage;
|
|
|
|
e.xclient.window = w;
|
|
|
|
e.xclient.message_type = a;
|
|
|
|
e.xclient.format = 32;
|
|
|
|
e.xclient.data.l[0] = value;
|
|
|
|
e.xclient.data.l[1] = CurrentTime;
|
|
|
|
|
|
|
|
XSendEvent(dpy, w, False, NoEventMask, &e);
|
|
|
|
XSync(dpy, False);
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-02-16 17:28:51 +03:00
|
|
|
kill_client(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
if(c->proto & WM_PROTOCOL_DELWIN)
|
|
|
|
send_client_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
|
|
|
|
else
|
|
|
|
XKillClient(dpy, c->win);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-03-09 01:53:52 +03:00
|
|
|
update_client_property(Client *c, XPropertyEvent *e)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
XTextProperty name;
|
|
|
|
long msize;
|
|
|
|
|
|
|
|
if(e->atom == wm_atom[WMProtocols]) {
|
|
|
|
/* update */
|
|
|
|
c->proto = win_proto(c->win);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (e->atom) {
|
|
|
|
case XA_WM_NAME:
|
|
|
|
XGetWMName(dpy, c->win, &name);
|
|
|
|
if(name.value) {
|
2006-01-04 18:28:31 +03:00
|
|
|
cext_strlcpy(c->name, (char*) name.value, sizeof(c->name));
|
2006-03-23 01:49:18 +03:00
|
|
|
free(name.value);
|
2006-01-03 12:30:15 +03:00
|
|
|
}
|
2006-03-26 18:37:03 +04:00
|
|
|
if(c->nframe)
|
2006-03-23 01:49:18 +03:00
|
|
|
draw_client(c);
|
|
|
|
break;
|
|
|
|
case XA_WM_TRANSIENT_FOR:
|
|
|
|
XGetTransientForHint(dpy, c->win, &c->trans);
|
|
|
|
break;
|
|
|
|
case XA_WM_NORMAL_HINTS:
|
|
|
|
if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags) {
|
|
|
|
c->size.flags = PSize;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* speed reasoned function for client property change */
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-23 22:00:25 +03:00
|
|
|
draw_client(Client *c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
Draw d = { 0 };
|
2006-03-05 21:20:27 +03:00
|
|
|
char buf[512];
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-03-08 18:05:09 +03:00
|
|
|
if(!c->nframe)
|
|
|
|
return; /* might not have been attached atm */
|
|
|
|
|
2006-03-05 02:25:49 +03:00
|
|
|
d.drawable = c->framewin;
|
2006-02-02 00:24:07 +03:00
|
|
|
d.font = xfont;
|
2006-03-05 02:25:49 +03:00
|
|
|
d.gc = c->gc;
|
2006-01-26 14:39:20 +03:00
|
|
|
|
2006-02-02 18:44:45 +03:00
|
|
|
if(c == sel_client())
|
|
|
|
d.color = def.sel;
|
|
|
|
else
|
|
|
|
d.color = def.norm;
|
2006-01-26 14:39:20 +03:00
|
|
|
|
|
|
|
/* draw border */
|
2006-03-23 01:49:18 +03:00
|
|
|
if(def.border) {
|
|
|
|
d.rect = c->frame[c->sel]->rect;
|
2006-03-05 02:38:40 +03:00
|
|
|
d.rect.x = d.rect.y = 0;
|
2006-03-23 01:49:18 +03:00
|
|
|
d.notch = &c->rect;
|
|
|
|
blitz_drawlabel(dpy, &d);
|
2006-03-10 20:22:48 +03:00
|
|
|
blitz_drawborder(dpy, &d);
|
2006-03-23 01:49:18 +03:00
|
|
|
}
|
|
|
|
d.rect.x = 0;
|
|
|
|
d.rect.y = 0;
|
|
|
|
d.rect.height = bar_height();
|
2006-02-02 22:36:10 +03:00
|
|
|
d.notch = nil;
|
2006-03-15 15:18:05 +03:00
|
|
|
|
|
|
|
tags2str(buf, sizeof(buf), c->tag, c->ntag);
|
2006-03-26 18:37:03 +04:00
|
|
|
d.align = WEST;
|
2006-03-24 17:30:48 +03:00
|
|
|
d.rect.x = d.rect.height + XTextWidth(xfont, buf, strlen(buf));
|
2006-03-24 17:23:21 +03:00
|
|
|
d.rect.width = c->frame[c->sel]->rect.width - d.rect.x;
|
|
|
|
d.data = c->name;
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
blitz_drawborder(dpy, &d);
|
2006-03-24 17:30:48 +03:00
|
|
|
|
|
|
|
if(c->frame[c->sel]->area->mode == Colmax) {
|
|
|
|
/* invert tag label */
|
|
|
|
unsigned long tmp = d.color.fg;
|
|
|
|
d.color.fg = d.color.bg;
|
|
|
|
d.color.bg = tmp;
|
|
|
|
}
|
2006-03-26 18:37:03 +04:00
|
|
|
d.align = CENTER;
|
2006-03-24 17:30:48 +03:00
|
|
|
d.rect.width = d.rect.x;
|
|
|
|
d.rect.x = 0;
|
|
|
|
d.data = buf;
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
blitz_drawborder(dpy, &d);
|
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
XSync(dpy, False);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-03-05 02:38:40 +03:00
|
|
|
gravitate(Client *c, Bool invert)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
int dx = 0, dy = 0;
|
|
|
|
int gravity = NorthWestGravity;
|
|
|
|
|
|
|
|
if(c->size.flags & PWinGravity) {
|
|
|
|
gravity = c->size.win_gravity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* y */
|
|
|
|
switch (gravity) {
|
|
|
|
case StaticGravity:
|
|
|
|
case NorthWestGravity:
|
|
|
|
case NorthGravity:
|
|
|
|
case NorthEastGravity:
|
|
|
|
dy = bar_height();
|
|
|
|
break;
|
|
|
|
case EastGravity:
|
|
|
|
case CenterGravity:
|
|
|
|
case WestGravity:
|
|
|
|
dy = -(c->rect.height / 2) + bar_height();
|
|
|
|
break;
|
|
|
|
case SouthEastGravity:
|
|
|
|
case SouthGravity:
|
|
|
|
case SouthWestGravity:
|
|
|
|
dy = -c->rect.height;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* x */
|
|
|
|
switch (gravity) {
|
|
|
|
case StaticGravity:
|
|
|
|
case NorthWestGravity:
|
|
|
|
case WestGravity:
|
|
|
|
case SouthWestGravity:
|
|
|
|
dx = def.border;
|
|
|
|
break;
|
|
|
|
case NorthGravity:
|
|
|
|
case CenterGravity:
|
|
|
|
case SouthGravity:
|
|
|
|
dx = -(c->rect.width / 2) + def.border;
|
|
|
|
break;
|
|
|
|
case NorthEastGravity:
|
|
|
|
case EastGravity:
|
|
|
|
case SouthEastGravity:
|
|
|
|
dx = -(c->rect.width + def.border);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(invert) {
|
|
|
|
dx = -dx;
|
|
|
|
dy = -dy;
|
|
|
|
}
|
|
|
|
c->rect.x += dx;
|
|
|
|
c->rect.y += dy;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2005-12-05 22:38:03 +03:00
|
|
|
|
2006-02-27 18:09:13 +03:00
|
|
|
void
|
2006-03-09 01:53:52 +03:00
|
|
|
manage_client(Client *c)
|
2006-02-27 18:09:13 +03:00
|
|
|
{
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v;
|
2006-03-11 03:32:10 +03:00
|
|
|
Client *trans;
|
2006-03-15 11:02:25 +03:00
|
|
|
unsigned int i;
|
2006-03-23 01:49:18 +03:00
|
|
|
|
2006-03-15 11:02:25 +03:00
|
|
|
if(c->trans && (trans = win2client(c->trans))) {
|
|
|
|
for(i = 0; i < trans->ntag; i++)
|
|
|
|
cext_strlcpy(c->tag[i], trans->tag[i], sizeof(c->tag[i]));
|
|
|
|
c->ntag = trans->ntag;
|
|
|
|
}
|
2006-03-11 03:32:10 +03:00
|
|
|
else
|
|
|
|
match_tags(c);
|
2006-03-09 01:53:52 +03:00
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
reparent_client(c, c->framewin, c->rect.x, c->rect.y);
|
2006-03-13 12:09:37 +03:00
|
|
|
|
2006-03-23 12:43:57 +03:00
|
|
|
v = nview ? view[sel] : alloc_view(def.tag);
|
2006-03-15 11:02:25 +03:00
|
|
|
if(!c->ntag) {
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 0; i < v->ntag; i++) {
|
|
|
|
cext_strlcpy(c->tag[i], v->tag[i], sizeof(c->tag[i]));
|
2006-03-15 15:18:05 +03:00
|
|
|
c->ntag++;
|
|
|
|
}
|
2006-03-15 12:44:54 +03:00
|
|
|
}
|
2006-03-15 12:51:57 +03:00
|
|
|
else if((c->ntag == 1) && !strncmp(c->tag[0], "~", 2)) {
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 0; i < v->ntag && i + 1 < MAX_TAGS; i++) {
|
|
|
|
cext_strlcpy(c->tag[i + 1], v->tag[i], sizeof(c->tag[i + 1]));
|
2006-03-15 15:18:05 +03:00
|
|
|
c->ntag++;
|
|
|
|
}
|
2006-03-14 10:53:56 +03:00
|
|
|
}
|
2006-03-10 00:43:24 +03:00
|
|
|
|
2006-03-09 01:53:52 +03:00
|
|
|
update_tags();
|
2005-12-05 22:38:03 +03:00
|
|
|
}
|
2005-12-06 00:22:24 +03:00
|
|
|
|
2006-03-09 22:25:50 +03:00
|
|
|
static int
|
|
|
|
dummy_error_handler(Display *dpy, XErrorEvent *error)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-06 01:38:50 +03:00
|
|
|
void
|
2006-03-09 22:25:50 +03:00
|
|
|
destroy_client(Client *c)
|
2006-03-06 01:38:50 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-03-08 14:45:28 +03:00
|
|
|
Client *cl;
|
2006-03-09 01:53:52 +03:00
|
|
|
|
2006-03-09 22:25:50 +03:00
|
|
|
XGrabServer(dpy);
|
|
|
|
XSetErrorHandler(dummy_error_handler);
|
|
|
|
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 0; i < nview; i++)
|
2006-03-23 12:43:57 +03:00
|
|
|
detach_fromview(view[i], c);
|
2006-03-09 22:25:50 +03:00
|
|
|
|
|
|
|
unmap_client(c);
|
|
|
|
|
2006-03-07 01:55:47 +03:00
|
|
|
if(c->nframe) {
|
|
|
|
c->rect.x = c->frame[c->sel]->rect.x;
|
|
|
|
c->rect.y = c->frame[c->sel]->rect.y;
|
2006-03-06 20:34:57 +03:00
|
|
|
}
|
2006-03-09 01:53:52 +03:00
|
|
|
|
2006-03-13 11:57:56 +03:00
|
|
|
reparent_client(c, root, c->rect.x, c->rect.y);
|
2006-03-23 01:49:18 +03:00
|
|
|
XFreeGC(dpy, c->gc);
|
|
|
|
XDestroyWindow(dpy, c->framewin);
|
2006-03-09 01:53:52 +03:00
|
|
|
cext_array_detach((void **)client, c, &clientsz);
|
|
|
|
nclient--;
|
|
|
|
update_tags();
|
2006-03-23 01:49:18 +03:00
|
|
|
free(c);
|
2006-03-09 01:53:52 +03:00
|
|
|
|
2006-03-23 12:43:57 +03:00
|
|
|
if((cl = sel_client_of_view(view[sel])))
|
2006-03-08 14:45:28 +03:00
|
|
|
focus_client(cl);
|
2006-03-09 22:25:50 +03:00
|
|
|
|
|
|
|
XSync(dpy, False);
|
|
|
|
XSetErrorHandler(wmii_error_handler);
|
|
|
|
XUngrabServer(dpy);
|
2006-03-06 01:38:50 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 20:29:49 +03:00
|
|
|
Client *
|
|
|
|
sel_client()
|
|
|
|
{
|
2006-03-23 12:43:57 +03:00
|
|
|
return nview ? sel_client_of_view(view[sel]) : nil;
|
2006-01-26 20:29:49 +03:00
|
|
|
}
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
static void
|
2006-03-05 02:38:40 +03:00
|
|
|
match_sizehints(Client *c)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
XSizeHints *s = &c->size;
|
|
|
|
|
|
|
|
if(s->flags & PMinSize) {
|
|
|
|
if(c->rect.width < c->size.min_width)
|
|
|
|
c->rect.width = c->size.min_width;
|
|
|
|
if(c->rect.height < c->size.min_height)
|
|
|
|
c->rect.height = c->size.min_height;
|
|
|
|
}
|
|
|
|
if(s->flags & PMaxSize) {
|
|
|
|
if(c->rect.width > c->size.max_width)
|
|
|
|
c->rect.width = c->size.max_width;
|
|
|
|
if(c->rect.height > c->size.max_height)
|
|
|
|
c->rect.height = c->size.max_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s->flags & PResizeInc) {
|
2006-02-06 22:53:05 +03:00
|
|
|
int w = 0, h = 0;
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
if(c->size.flags & PBaseSize) {
|
|
|
|
w = c->size.base_width;
|
|
|
|
h = c->size.base_height;
|
|
|
|
} else if(c->size.flags & PMinSize) {
|
|
|
|
/* base_{width,height} default to min_{width,height} */
|
|
|
|
w = c->size.min_width;
|
|
|
|
h = c->size.min_height;
|
|
|
|
}
|
|
|
|
/* client_width = base_width + i * c->size.width_inc for an integer i */
|
|
|
|
w = c->frame[c->sel]->rect.width - 2 * def.border - w;
|
|
|
|
if(s->width_inc > 0)
|
|
|
|
c->frame[c->sel]->rect.width -= w % s->width_inc;
|
|
|
|
|
|
|
|
h = c->frame[c->sel]->rect.height - def.border - bar_height() - h;
|
|
|
|
if(s->height_inc > 0)
|
|
|
|
c->frame[c->sel]->rect.height -= h % s->height_inc;
|
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(Client *c, XRectangle *r, Bool ignore_xcall)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-03-07 01:55:47 +03:00
|
|
|
Frame *f = c->frame[c->sel];
|
2006-03-15 18:00:39 +03:00
|
|
|
f->rect = *r;
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-05 03:55:45 +03:00
|
|
|
if((f->area->mode != Colstack) || (f->area->sel == frame2index(f)))
|
2006-03-05 02:38:40 +03:00
|
|
|
match_sizehints(c);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-13 12:45:30 +03:00
|
|
|
if(!ignore_xcall) {
|
2006-03-23 12:36:51 +03:00
|
|
|
if(f->area->view == view[sel])
|
2006-03-23 01:49:18 +03:00
|
|
|
XMoveResizeWindow(dpy, c->framewin, f->rect.x,
|
|
|
|
f->rect.y, f->rect.width, f->rect.height);
|
2006-03-13 12:45:30 +03:00
|
|
|
else
|
2006-03-23 01:49:18 +03:00
|
|
|
XMoveResizeWindow(dpy, c->framewin, 2 * rect.width + f->rect.x,
|
|
|
|
f->rect.y, f->rect.width, f->rect.height);
|
2006-03-13 12:45:30 +03:00
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-05 03:55:45 +03:00
|
|
|
if((f->area->mode != Colstack) || (f->area->sel == frame2index(f))) {
|
2006-03-05 02:38:40 +03:00
|
|
|
c->rect.x = def.border;
|
|
|
|
c->rect.y = bar_height();
|
2006-03-05 03:55:45 +03:00
|
|
|
c->rect.width = f->rect.width - 2 * def.border;
|
|
|
|
c->rect.height = f->rect.height - def.border - bar_height();
|
2006-03-23 01:49:18 +03:00
|
|
|
XMoveResizeWindow(dpy, c->win, c->rect.x, c->rect.y,
|
|
|
|
c->rect.width, c->rect.height);
|
2006-03-01 13:30:44 +03:00
|
|
|
configure_client(c);
|
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
2006-02-13 12:31:38 +03:00
|
|
|
void
|
2006-02-14 14:06:16 +03:00
|
|
|
select_client(Client *c, char *arg)
|
2006-02-13 12:31:38 +03:00
|
|
|
{
|
2006-03-07 01:55:47 +03:00
|
|
|
Frame *f = c->frame[c->sel];
|
2006-03-05 03:55:45 +03:00
|
|
|
Area *a = f->area;
|
|
|
|
int i = frame2index(f);
|
2006-02-19 18:21:01 +03:00
|
|
|
if(i == -1)
|
|
|
|
return;
|
|
|
|
if(!strncmp(arg, "prev", 5)) {
|
|
|
|
if(!i)
|
2006-03-05 03:55:45 +03:00
|
|
|
i = a->nframe - 1;
|
2006-02-19 18:21:01 +03:00
|
|
|
else
|
|
|
|
i--;
|
|
|
|
} else if(!strncmp(arg, "next", 5)) {
|
2006-03-05 03:55:45 +03:00
|
|
|
if(i + 1 < a->nframe)
|
2006-02-19 18:21:01 +03:00
|
|
|
i++;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
}
|
2006-02-13 12:31:38 +03:00
|
|
|
else {
|
2006-02-19 18:21:01 +03:00
|
|
|
const char *errstr;
|
2006-03-05 03:55:45 +03:00
|
|
|
i = cext_strtonum(arg, 0, a->nframe - 1, &errstr);
|
2006-02-19 18:21:01 +03:00
|
|
|
if(errstr)
|
2006-02-14 14:53:40 +03:00
|
|
|
return;
|
2006-02-13 12:31:38 +03:00
|
|
|
}
|
2006-03-05 03:55:45 +03:00
|
|
|
focus_client(a->frame[i]->client);
|
2006-02-13 12:31:38 +03:00
|
|
|
}
|
2006-02-23 22:52:55 +03:00
|
|
|
|
2006-03-27 09:46:12 +04:00
|
|
|
void
|
|
|
|
restack_client(Client *c, char *arg)
|
|
|
|
{
|
|
|
|
Frame *f = c->frame[c->sel];
|
|
|
|
Area *a = f->area;
|
|
|
|
int i = area2index(a), j = frame2index(f);
|
|
|
|
|
|
|
|
if(i == -1 || j == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!strncmp(arg, "up", 3)) {
|
|
|
|
if(j)
|
|
|
|
i = j - 1;
|
|
|
|
else
|
|
|
|
i = a->nframe - 1;
|
|
|
|
}
|
|
|
|
else if(!strncmp(arg, "down", 5)) {
|
|
|
|
if(j + 1 < a->nframe)
|
|
|
|
i = j + 1;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
a->frame[j] = a->frame[i];
|
|
|
|
a->frame[i] = f;
|
2006-03-27 10:38:17 +04:00
|
|
|
arrange_column(a);
|
2006-03-27 09:46:12 +04:00
|
|
|
focus_client(c);
|
|
|
|
}
|
|
|
|
|
2006-02-24 11:52:20 +03:00
|
|
|
void
|
2006-03-08 18:05:09 +03:00
|
|
|
send2area_client(Client *c, char *arg)
|
2006-03-02 19:38:15 +03:00
|
|
|
{
|
2006-02-24 11:52:20 +03:00
|
|
|
const char *errstr;
|
2006-03-07 01:55:47 +03:00
|
|
|
Frame *f = c->frame[c->sel];
|
2006-03-05 03:55:45 +03:00
|
|
|
Area *to, *a = f->area;
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v = a->view;
|
2006-03-01 09:51:04 +03:00
|
|
|
int i = area2index(a);
|
2006-02-24 11:52:20 +03:00
|
|
|
|
2006-03-02 12:36:03 +03:00
|
|
|
if(i == -1)
|
2006-02-24 11:52:20 +03:00
|
|
|
return;
|
2006-03-09 21:55:24 +03:00
|
|
|
if(!strncmp(arg, "new", 4) && i) {
|
2006-03-27 09:17:47 +04:00
|
|
|
if(a->nframe == 1 || v->narea - 1 >= rect.width / (2 * MIN_COLWIDTH))
|
2006-03-08 14:45:28 +03:00
|
|
|
return;
|
2006-03-23 12:36:51 +03:00
|
|
|
to = alloc_area(v);
|
2006-03-27 09:17:47 +04:00
|
|
|
arrange_view(v, True);
|
2006-03-04 11:29:20 +03:00
|
|
|
}
|
2006-03-09 21:55:24 +03:00
|
|
|
else if(!strncmp(arg, "prev", 5) && i) {
|
2006-02-24 11:52:20 +03:00
|
|
|
if(i == 1)
|
2006-03-23 12:36:51 +03:00
|
|
|
to = v->area[v->narea - 1];
|
2006-02-24 11:52:20 +03:00
|
|
|
else
|
2006-03-23 12:36:51 +03:00
|
|
|
to = v->area[i - 1];
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
2006-03-09 21:55:24 +03:00
|
|
|
else if(!strncmp(arg, "next", 5) && i) {
|
2006-03-23 12:36:51 +03:00
|
|
|
if(i < v->narea - 1)
|
|
|
|
to = v->area[i + 1];
|
2006-02-24 11:52:20 +03:00
|
|
|
else
|
2006-03-23 12:36:51 +03:00
|
|
|
to = v->area[1];
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
2006-03-11 22:37:29 +03:00
|
|
|
else if(!strncmp(arg, "toggle", 7)) {
|
|
|
|
if(i)
|
2006-03-23 12:36:51 +03:00
|
|
|
to = v->area[0];
|
|
|
|
else if(c->revert && c->revert != v->area[0])
|
2006-03-11 22:50:53 +03:00
|
|
|
to = c->revert;
|
2006-03-11 22:37:29 +03:00
|
|
|
else
|
2006-03-23 12:36:51 +03:00
|
|
|
to = v->area[1];
|
2006-03-11 22:37:29 +03:00
|
|
|
}
|
2006-02-24 11:52:20 +03:00
|
|
|
else {
|
2006-03-23 12:36:51 +03:00
|
|
|
i = cext_strtonum(arg, 0, v->narea - 1, &errstr);
|
2006-02-24 11:52:20 +03:00
|
|
|
if(errstr)
|
|
|
|
return;
|
2006-03-23 12:36:51 +03:00
|
|
|
to = v->area[i];
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
2006-03-08 18:05:09 +03:00
|
|
|
send2area(to, a, c);
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
2006-02-24 12:38:48 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
resize_all_clients()
|
|
|
|
{
|
2006-03-01 13:55:46 +03:00
|
|
|
unsigned int i;
|
2006-03-09 13:39:15 +03:00
|
|
|
for(i = 0; i < nclient; i++) {
|
|
|
|
Client *c = client[i];
|
2006-03-16 10:06:31 +03:00
|
|
|
if(c->nframe && c->frame[c->sel]->area) {
|
|
|
|
if(area2index(c->frame[c->sel]->area))
|
|
|
|
resize_area(c, &c->frame[c->sel]->rect, nil);
|
|
|
|
else
|
|
|
|
resize_client(c, &c->frame[c->sel]->rect, False);
|
|
|
|
}
|
2006-03-09 13:39:15 +03:00
|
|
|
}
|
2006-02-24 12:38:48 +03:00
|
|
|
}
|
2006-02-28 10:51:53 +03:00
|
|
|
|
|
|
|
/* convenience function */
|
|
|
|
void
|
|
|
|
focus(Client *c)
|
|
|
|
{
|
2006-03-09 14:38:02 +03:00
|
|
|
Frame *f = c->nframe ? c->frame[c->sel] : nil;
|
2006-03-23 12:36:51 +03:00
|
|
|
View *v;
|
2006-03-09 14:38:02 +03:00
|
|
|
|
|
|
|
if(!f)
|
|
|
|
return;
|
|
|
|
|
2006-03-23 12:36:51 +03:00
|
|
|
v = f->area->view;
|
|
|
|
if(view[sel] != v)
|
2006-03-23 12:43:57 +03:00
|
|
|
focus_view(v);
|
2006-02-28 10:51:53 +03:00
|
|
|
focus_client(c);
|
|
|
|
}
|
2006-03-07 19:22:36 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
cid2index(unsigned short id)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < nclient; i++)
|
|
|
|
if(client[i]->id == id)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2006-03-15 11:02:25 +03:00
|
|
|
|
|
|
|
Bool
|
|
|
|
clienthastag(Client *c, const char *t)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for(i = 0; i < c->ntag; i++)
|
|
|
|
if(!strncmp(c->tag[i], t, sizeof(c->tag[i])))
|
|
|
|
return True;
|
|
|
|
return False;
|
|
|
|
}
|