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"
|
|
|
|
|
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
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
XTextProperty name;
|
|
|
|
Client *c = (Client *) cext_emallocz(sizeof(Client));
|
2006-01-25 20:39:08 +03:00
|
|
|
XSetWindowAttributes fwa;
|
2006-02-02 22:36:10 +03:00
|
|
|
int bw = def.border, bh;
|
2006-01-25 20:39:08 +03:00
|
|
|
long msize;
|
2006-02-03 20:11:22 +03:00
|
|
|
static unsigned short id = 1;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-02-03 18:15:36 +03:00
|
|
|
c->id = id++;
|
2005-12-21 18:18:11 +03:00
|
|
|
c->win = w;
|
2006-01-25 20:39:08 +03:00
|
|
|
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);
|
2005-12-21 18:18:11 +03:00
|
|
|
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-01-03 12:30:15 +03:00
|
|
|
free(name.value);
|
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
|
|
|
|
fwa.override_redirect = 1;
|
|
|
|
fwa.background_pixmap = ParentRelative;
|
|
|
|
fwa.event_mask = SubstructureRedirectMask | ExposureMask | ButtonPressMask | PointerMotionMask;
|
|
|
|
|
2006-02-24 12:38:48 +03:00
|
|
|
bh = bar_height();
|
2006-01-26 21:58:30 +03:00
|
|
|
c->frame.rect = c->rect;
|
2006-01-25 20:39:08 +03:00
|
|
|
c->frame.rect.width += 2 * bw;
|
2006-02-02 22:36:10 +03:00
|
|
|
c->frame.rect.height += bw + (bh ? bh : bw);
|
2006-01-25 20:39:08 +03:00
|
|
|
c->frame.win = XCreateWindow(dpy, root, c->frame.rect.x, c->frame.rect.y,
|
|
|
|
c->frame.rect.width, c->frame.rect.height, 0,
|
2006-02-02 22:36:10 +03:00
|
|
|
DefaultDepth(dpy, screen), CopyFromParent,
|
|
|
|
DefaultVisual(dpy, screen),
|
2006-01-25 20:39:08 +03:00
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
|
|
|
|
c->frame.cursor = normal_cursor;
|
|
|
|
XDefineCursor(dpy, c->frame.win, c->frame.cursor);
|
|
|
|
c->frame.gc = XCreateGC(dpy, c->frame.win, 0, 0);
|
|
|
|
XSync(dpy, False);
|
|
|
|
|
2006-01-29 15:41:16 +03:00
|
|
|
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
|
|
|
|
2005-12-21 18:18:11 +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
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
long data[2];
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
data[0] = (long) state;
|
|
|
|
data[1] = (long) None;
|
2006-03-05 02:11:08 +03:00
|
|
|
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-02-10 19:51:20 +03:00
|
|
|
static void
|
|
|
|
client_name_event(Client *c)
|
|
|
|
{
|
|
|
|
char buf[256];
|
2006-02-11 17:22:42 +03:00
|
|
|
snprintf(buf, sizeof(buf), "CN %s\n", c->name);
|
2006-02-16 13:53:10 +03:00
|
|
|
write_event(buf);
|
2006-02-10 19:51:20 +03:00
|
|
|
}
|
|
|
|
|
2006-02-16 03:55:21 +03:00
|
|
|
static void
|
|
|
|
client_focus_event(Client *c)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
snprintf(buf, sizeof(buf), "CF %d %d %d %d\n", c->frame.rect.x, c->frame.rect.y,
|
|
|
|
c->frame.rect.width, c->frame.rect.height);
|
2006-02-16 13:53:10 +03:00
|
|
|
write_event(buf);
|
2006-02-16 03:55:21 +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-01 09:51:04 +03:00
|
|
|
int i = area2index(c->area);
|
2006-01-26 14:39:20 +03:00
|
|
|
|
2006-03-04 11:23:17 +03:00
|
|
|
c->area->tag->sel = i;
|
2006-03-01 09:51:04 +03:00
|
|
|
c->area->sel = client2index(c);
|
2006-01-26 14:39:20 +03:00
|
|
|
if(old && (old != c)) {
|
2006-02-09 21:40:12 +03:00
|
|
|
grab_mouse(old->win, AnyModifier, Button1);
|
2006-01-26 14:39:20 +03:00
|
|
|
draw_client(old);
|
2006-01-19 17:02:18 +03:00
|
|
|
}
|
2006-02-09 21:40:12 +03:00
|
|
|
ungrab_mouse(c->win, AnyModifier, AnyButton);
|
|
|
|
grab_mouse(c->win, Mod1Mask, Button1);
|
|
|
|
grab_mouse(c->win, Mod1Mask, Button3);
|
2006-01-26 14:39:20 +03:00
|
|
|
XRaiseWindow(dpy, c->frame.win);
|
|
|
|
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
|
|
|
draw_client(c);
|
2006-01-19 17:02:18 +03:00
|
|
|
XSync(dpy, False);
|
2006-02-10 19:51:20 +03:00
|
|
|
client_name_event(c);
|
2006-02-28 10:51:53 +03:00
|
|
|
client_focus_event(c);
|
2006-03-05 02:11:08 +03:00
|
|
|
if(i > 0 && c->area->mode == Colstack)
|
2006-03-02 17:28:55 +03:00
|
|
|
arrange_area(c->area);
|
2006-01-19 17:02:18 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-13 15:24:55 +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-01-10 16:43:09 +03:00
|
|
|
XMapRaised(dpy, c->win);
|
2006-02-17 01:49:44 +03:00
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK);
|
2005-12-21 18:18:11 +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-01-13 15:24:55 +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);
|
2005-12-21 18:18:11 +03:00
|
|
|
XUnmapWindow(dpy, c->win);
|
2006-02-17 01:49:44 +03:00
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK);
|
2005-12-21 18:18:11 +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
|
|
|
|
configure_client(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
XConfigureEvent e;
|
|
|
|
e.type = ConfigureNotify;
|
|
|
|
e.event = c->win;
|
|
|
|
e.window = c->win;
|
|
|
|
e.x = c->rect.x;
|
|
|
|
e.y = c->rect.y;
|
2006-02-11 17:22:42 +03:00
|
|
|
if(c->area) {
|
2006-01-25 21:41:12 +03:00
|
|
|
e.x += c->frame.rect.x;
|
|
|
|
e.y += c->frame.rect.y;
|
|
|
|
}
|
2005-12-21 18:18:11 +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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
if(c->proto & PROTO_DEL)
|
2006-03-05 02:11:08 +03:00
|
|
|
send_client_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
|
2005-12-21 18:18:11 +03:00
|
|
|
else
|
|
|
|
XKillClient(dpy, c->win);
|
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
|
|
|
handle_client_property(Client *c, XPropertyEvent *e)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
XTextProperty name;
|
|
|
|
long msize;
|
|
|
|
|
2006-03-05 02:11:08 +03:00
|
|
|
if(e->atom == wm_atom[WMProtocols]) {
|
2005-12-21 18:18:11 +03:00
|
|
|
/* update */
|
|
|
|
c->proto = win_proto(c->win);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (e->atom) {
|
|
|
|
case XA_WM_NAME:
|
|
|
|
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-01-03 12:30:15 +03:00
|
|
|
free(name.value);
|
|
|
|
}
|
2006-02-11 17:22:42 +03:00
|
|
|
if(c->area)
|
2005-12-21 18:18:11 +03:00
|
|
|
draw_client(c);
|
2006-02-16 13:53:10 +03:00
|
|
|
if(c == sel_client())
|
|
|
|
client_name_event(c);
|
2005-12-21 18:18:11 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
destroy_client(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
XFreeGC(dpy, c->frame.gc);
|
|
|
|
XDestroyWindow(dpy, c->frame.win);
|
2006-02-03 18:15:36 +03:00
|
|
|
cext_array_detach((void **)client, c, &clientsz);
|
|
|
|
nclient--;
|
2005-12-21 18:18:11 +03:00
|
|
|
free(c);
|
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
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
Draw d = { 0 };
|
2006-02-24 12:38:48 +03:00
|
|
|
unsigned int bh = bar_height();
|
|
|
|
unsigned int bw = def.border;
|
2006-01-26 14:39:20 +03:00
|
|
|
XRectangle notch;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-02-07 19:55:33 +03:00
|
|
|
d.align = WEST;
|
2006-01-26 14:39:20 +03:00
|
|
|
d.drawable = c->frame.win;
|
2006-02-02 00:24:07 +03:00
|
|
|
d.font = xfont;
|
2006-01-26 14:39:20 +03:00
|
|
|
d.gc = c->frame.gc;
|
|
|
|
|
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 */
|
|
|
|
if(bw) {
|
|
|
|
notch.x = bw;
|
|
|
|
notch.y = bw;
|
|
|
|
notch.width = c->frame.rect.width - 2 * bw;
|
|
|
|
notch.height = c->frame.rect.height - 2 * bw;
|
|
|
|
d.rect = c->frame.rect;
|
|
|
|
d.rect.x = d.rect.y = 0;
|
|
|
|
d.notch = ¬ch;
|
|
|
|
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
}
|
|
|
|
XSync(dpy, False);
|
|
|
|
|
2006-02-02 22:36:10 +03:00
|
|
|
/* draw bar */
|
|
|
|
if(!bh)
|
2005-12-21 18:18:11 +03:00
|
|
|
return;
|
|
|
|
|
2006-01-23 22:00:25 +03:00
|
|
|
d.rect.x = 0;
|
2005-12-21 18:18:11 +03:00
|
|
|
d.rect.y = 0;
|
2006-01-25 21:41:12 +03:00
|
|
|
d.rect.width = c->frame.rect.width;
|
2006-02-02 22:36:10 +03:00
|
|
|
d.rect.height = bh;
|
|
|
|
d.notch = nil;
|
2006-01-03 12:30:15 +03:00
|
|
|
d.data = c->name;
|
2005-12-21 18:18:11 +03:00
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
XSync(dpy, False);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +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 = tabh;
|
|
|
|
break;
|
|
|
|
case EastGravity:
|
|
|
|
case CenterGravity:
|
|
|
|
case WestGravity:
|
|
|
|
dy = -(c->rect.height / 2) + tabh;
|
|
|
|
break;
|
|
|
|
case SouthEastGravity:
|
|
|
|
case SouthGravity:
|
|
|
|
case SouthWestGravity:
|
|
|
|
dy = -c->rect.height;
|
|
|
|
break;
|
|
|
|
default: /* don't care */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* x */
|
|
|
|
switch (gravity) {
|
|
|
|
case StaticGravity:
|
|
|
|
case NorthWestGravity:
|
|
|
|
case WestGravity:
|
|
|
|
case SouthWestGravity:
|
|
|
|
dx = bw;
|
|
|
|
break;
|
|
|
|
case NorthGravity:
|
|
|
|
case CenterGravity:
|
|
|
|
case SouthGravity:
|
|
|
|
dx = -(c->rect.width / 2) + bw;
|
|
|
|
break;
|
|
|
|
case NorthEastGravity:
|
|
|
|
case EastGravity:
|
|
|
|
case SouthEastGravity:
|
|
|
|
dx = -(c->rect.width + bw);
|
|
|
|
break;
|
|
|
|
default: /* don't care */
|
|
|
|
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
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-03-04 11:23:17 +03:00
|
|
|
attach_totag(Tag *t, Client *c)
|
2006-01-25 21:41:12 +03:00
|
|
|
{
|
2006-03-04 11:23:17 +03:00
|
|
|
Area *a = t->area[t->sel];
|
2006-01-25 21:41:12 +03:00
|
|
|
|
2006-02-27 18:09:13 +03:00
|
|
|
reparent_client(c, c->frame.win, c->rect.x, c->rect.y);
|
2006-03-02 19:38:15 +03:00
|
|
|
attach_toarea(a, c);
|
2006-01-26 17:24:34 +03:00
|
|
|
map_client(c);
|
2006-01-26 21:58:30 +03:00
|
|
|
XMapWindow(dpy, c->frame.win);
|
2006-02-27 18:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
attach_client(Client *c)
|
|
|
|
{
|
2006-03-04 11:23:17 +03:00
|
|
|
Tag *t;
|
|
|
|
if(!ntag)
|
|
|
|
t = alloc_tag();
|
2006-02-27 18:09:13 +03:00
|
|
|
else
|
2006-03-04 11:23:17 +03:00
|
|
|
t = tag[sel];
|
2006-02-27 18:09:13 +03:00
|
|
|
|
2006-03-04 11:23:17 +03:00
|
|
|
attach_totag(t, c);
|
2006-02-28 10:51:53 +03:00
|
|
|
focus_client(c);
|
2005-12-05 22:38:03 +03:00
|
|
|
}
|
2005-12-06 00:22:24 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-25 21:41:12 +03:00
|
|
|
detach_client(Client *c, Bool unmap)
|
|
|
|
{
|
2006-02-19 17:40:44 +03:00
|
|
|
Area *a = c->area;
|
|
|
|
if(a) {
|
|
|
|
if(!c->destroyed) {
|
2006-02-22 12:58:00 +03:00
|
|
|
if(!unmap)
|
2006-02-19 17:40:44 +03:00
|
|
|
unmap_client(c);
|
|
|
|
c->rect.x = c->frame.rect.x;
|
|
|
|
c->rect.y = c->frame.rect.y;
|
|
|
|
reparent_client(c, root, c->rect.x, c->rect.y);
|
|
|
|
XUnmapWindow(dpy, c->frame.win);
|
|
|
|
}
|
2006-03-02 19:38:15 +03:00
|
|
|
detach_fromarea(c);
|
2006-01-25 21:41:12 +03:00
|
|
|
}
|
2006-02-11 17:22:42 +03:00
|
|
|
c->area = nil;
|
2005-12-21 18:18:11 +03:00
|
|
|
if(c->destroyed)
|
|
|
|
destroy_client(c);
|
2005-12-16 04:59:27 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
Client *
|
2006-03-04 11:23:17 +03:00
|
|
|
sel_client_of_tag(Tag *t)
|
2005-12-16 04:59:27 +03:00
|
|
|
{
|
2006-03-04 11:23:17 +03:00
|
|
|
if(t) {
|
|
|
|
Area *a = t->narea ? t->area[t->sel] : nil;
|
2006-02-02 15:20:07 +03:00
|
|
|
return (a && a->nclient) ? a->client[a->sel] : nil;
|
2006-01-26 14:39:20 +03:00
|
|
|
}
|
|
|
|
return nil;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 20:29:49 +03:00
|
|
|
Client *
|
|
|
|
sel_client()
|
|
|
|
{
|
2006-03-04 11:23:17 +03:00
|
|
|
return ntag ? sel_client_of_tag(tag[sel]) : nil;
|
2006-01-26 20:29:49 +03:00
|
|
|
}
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
Client *
|
2006-03-01 09:51:04 +03:00
|
|
|
win2clientframe(Window w)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-03-01 13:55:46 +03:00
|
|
|
unsigned int 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]->frame.win == w)
|
|
|
|
return client[i];
|
2006-01-26 14:39:20 +03:00
|
|
|
return nil;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-01 17:23:34 +03:00
|
|
|
match_sizehints(Client *c, unsigned int tabh, unsigned int bw)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-03-01 17:23:34 +03:00
|
|
|
XSizeHints *s = &c->size;
|
|
|
|
|
|
|
|
if(s->flags & PMinSize) {
|
2006-02-28 19:24:44 +03:00
|
|
|
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;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
2006-03-01 17:23:34 +03:00
|
|
|
if(s->flags & PMaxSize) {
|
2006-02-28 19:24:44 +03:00
|
|
|
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;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
2006-02-06 23:03:04 +03:00
|
|
|
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
|
|
|
|
|
|
|
if(c->size.flags & PBaseSize) {
|
2006-02-06 22:53:05 +03:00
|
|
|
w = c->size.base_width;
|
|
|
|
h = c->size.base_height;
|
2006-01-25 20:39:08 +03:00
|
|
|
} else if(c->size.flags & PMinSize) {
|
|
|
|
/* base_{width,height} default to min_{width,height} */
|
2006-02-06 22:53:05 +03:00
|
|
|
w = c->size.min_width;
|
|
|
|
h = c->size.min_height;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
/* client_width = base_width + i * c->size.width_inc for an integer i */
|
2006-02-06 22:53:05 +03:00
|
|
|
w = c->frame.rect.width - 2 * bw - w;
|
2006-02-06 23:03:04 +03:00
|
|
|
if(s->width_inc > 0)
|
|
|
|
c->frame.rect.width -= w % s->width_inc;
|
2006-02-06 22:53:05 +03:00
|
|
|
|
|
|
|
h = c->frame.rect.height - bw - (tabh ? tabh : bw) - h;
|
2006-02-06 23:03:04 +03:00
|
|
|
if(s->height_inc > 0)
|
|
|
|
c->frame.rect.height -= h % s->height_inc;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-03-01 18:20:02 +03:00
|
|
|
resize_client(Client *c, XRectangle *r, XPoint *pt, Bool ignore_xcall)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-02-24 12:38:48 +03:00
|
|
|
unsigned int bh = bar_height();
|
|
|
|
unsigned int bw = def.border;
|
2006-03-04 11:23:17 +03:00
|
|
|
int pi = tag2index(c->area->tag);
|
2006-02-27 18:31:13 +03:00
|
|
|
int px = sel * rect.width;
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-01 09:51:04 +03:00
|
|
|
if(area2index(c->area) > 0)
|
2006-03-02 17:28:55 +03:00
|
|
|
resize_area(c, r, pt);
|
2006-02-02 21:22:27 +03:00
|
|
|
else
|
|
|
|
c->frame.rect = *r;
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-05 02:11:08 +03:00
|
|
|
if((c->area->mode != Colstack) || (c->area->sel == client2index(c)))
|
2006-03-01 17:23:34 +03:00
|
|
|
match_sizehints(c, bh, bw);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-01 18:20:02 +03:00
|
|
|
if(!ignore_xcall)
|
|
|
|
XMoveResizeWindow(dpy, c->frame.win, px - (pi * rect.width) + c->frame.rect.x, c->frame.rect.y,
|
|
|
|
c->frame.rect.width, c->frame.rect.height);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-05 02:11:08 +03:00
|
|
|
if((c->area->mode != Colstack) || (c->area->sel == client2index(c))) {
|
2006-03-01 13:30:44 +03:00
|
|
|
c->rect.x = bw;
|
|
|
|
c->rect.y = bh ? bh : bw;
|
|
|
|
c->rect.width = c->frame.rect.width - 2 * bw;
|
|
|
|
c->rect.height = c->frame.rect.height - bw - (bh ? bh : bw);
|
|
|
|
XMoveResizeWindow(dpy, c->win, c->rect.x, c->rect.y, c->rect.width, c->rect.height);
|
|
|
|
configure_client(c);
|
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 18:15:36 +03:00
|
|
|
int
|
2006-03-01 09:51:04 +03:00
|
|
|
cid2index(Area *a, unsigned short id)
|
2006-02-03 18:15:36 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < a->nclient; i++)
|
|
|
|
if(a->client[i]->id == id)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-02-11 17:22:42 +03:00
|
|
|
int
|
2006-03-01 09:51:04 +03:00
|
|
|
client2index(Client *c)
|
2006-02-11 17:22:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Area *a = c->area;
|
|
|
|
for(i = 0; i < a->nclient; i++)
|
|
|
|
if(a->client[i] == c)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
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-02-19 18:21:01 +03:00
|
|
|
Area *a = c->area;
|
2006-03-01 09:51:04 +03:00
|
|
|
int i = client2index(c);
|
2006-02-19 18:21:01 +03:00
|
|
|
if(i == -1)
|
|
|
|
return;
|
|
|
|
if(!strncmp(arg, "prev", 5)) {
|
|
|
|
if(!i)
|
|
|
|
i = a->nclient - 1;
|
|
|
|
else
|
|
|
|
i--;
|
|
|
|
} else if(!strncmp(arg, "next", 5)) {
|
|
|
|
if(i + 1 < a->nclient)
|
|
|
|
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-01 13:09:49 +03:00
|
|
|
i = cext_strtonum(arg, 0, a->nclient - 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-02-28 10:51:53 +03:00
|
|
|
focus_client(a->client[i]);
|
2006-02-13 12:31:38 +03:00
|
|
|
}
|
2006-02-23 22:52:55 +03:00
|
|
|
|
|
|
|
void
|
2006-03-04 11:23:17 +03:00
|
|
|
sendtotag_client(Client *c, char *arg)
|
2006-03-02 19:38:15 +03:00
|
|
|
{
|
2006-03-04 11:23:17 +03:00
|
|
|
Tag *t;
|
2006-03-02 12:26:30 +03:00
|
|
|
Client *to;
|
2006-02-23 22:52:55 +03:00
|
|
|
|
|
|
|
if(!strncmp(arg, "new", 4))
|
2006-03-04 11:23:17 +03:00
|
|
|
t = alloc_tag();
|
2006-02-28 16:46:10 +03:00
|
|
|
else if(!strncmp(arg, "sel", 4))
|
2006-03-04 11:23:17 +03:00
|
|
|
t = tag[sel];
|
2006-02-23 22:52:55 +03:00
|
|
|
else {
|
2006-02-27 18:09:13 +03:00
|
|
|
const char *errstr;
|
2006-03-04 11:23:17 +03:00
|
|
|
int i = cext_strtonum(arg, 0, ntag - 1, &errstr);
|
2006-02-23 22:52:55 +03:00
|
|
|
if(errstr)
|
|
|
|
return;
|
2006-03-04 11:23:17 +03:00
|
|
|
t = tag[i];
|
2006-02-23 22:52:55 +03:00
|
|
|
}
|
|
|
|
detach_client(c, False);
|
2006-03-04 11:23:17 +03:00
|
|
|
attach_totag(t, c);
|
|
|
|
if(t == tag[sel])
|
2006-03-01 13:47:14 +03:00
|
|
|
focus_client(c);
|
2006-03-04 11:23:17 +03:00
|
|
|
else if((to = sel_client_of_tag(tag[sel])))
|
2006-03-02 12:26:30 +03:00
|
|
|
focus_client(to);
|
2006-02-23 22:52:55 +03:00
|
|
|
}
|
2006-02-24 11:52:20 +03:00
|
|
|
|
|
|
|
void
|
2006-03-02 19:38:15 +03:00
|
|
|
sendtoarea_client(Client *c, char *arg)
|
|
|
|
{
|
2006-02-24 11:52:20 +03:00
|
|
|
const char *errstr;
|
2006-03-02 12:26:30 +03:00
|
|
|
Area *to, *a = c->area;
|
2006-03-04 11:23:17 +03:00
|
|
|
Tag *t = a->tag;
|
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-04 11:29:20 +03:00
|
|
|
if(!strncmp(arg, "new", 4)) {
|
|
|
|
to = alloc_area(t);
|
|
|
|
arrange_tag(t, True);
|
|
|
|
}
|
|
|
|
else if(!strncmp(arg, "prev", 5)) {
|
2006-02-24 11:52:20 +03:00
|
|
|
if(i == 1)
|
2006-03-04 11:23:17 +03:00
|
|
|
to = t->area[t->narea - 1];
|
2006-02-24 11:52:20 +03:00
|
|
|
else
|
2006-03-04 11:23:17 +03:00
|
|
|
to = t->area[i - 1];
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
|
|
|
else if(!strncmp(arg, "next", 5)) {
|
2006-03-04 11:23:17 +03:00
|
|
|
if(i < t->narea - 1)
|
|
|
|
to = t->area[i + 1];
|
2006-02-24 11:52:20 +03:00
|
|
|
else
|
2006-03-04 11:23:17 +03:00
|
|
|
to = t->area[1];
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
|
|
|
else {
|
2006-03-04 11:23:17 +03:00
|
|
|
i = cext_strtonum(arg, 0, t->narea - 1, &errstr);
|
2006-02-24 11:52:20 +03:00
|
|
|
if(errstr)
|
|
|
|
return;
|
2006-03-04 11:23:17 +03:00
|
|
|
to = t->area[i];
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
2006-03-02 19:38:15 +03:00
|
|
|
send_toarea(to, c);
|
2006-03-04 11:23:17 +03:00
|
|
|
arrange_area(a);
|
|
|
|
arrange_area(to);
|
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-02-24 12:38:48 +03:00
|
|
|
for(i = 0; i < nclient; i++)
|
|
|
|
if(client[i]->area)
|
2006-03-01 18:20:02 +03:00
|
|
|
resize_client(client[i], &client[i]->frame.rect, 0, False);
|
2006-02-24 12:38:48 +03:00
|
|
|
}
|
2006-02-28 10:51:53 +03:00
|
|
|
|
|
|
|
/* convenience function */
|
|
|
|
void
|
|
|
|
focus(Client *c)
|
|
|
|
{
|
2006-03-04 11:23:17 +03:00
|
|
|
Tag *t = c->area->tag;
|
|
|
|
if(tag[sel] != t)
|
|
|
|
focus_tag(t);
|
2006-02-28 10:51:53 +03:00
|
|
|
focus_client(c);
|
|
|
|
}
|