wmii/cmd/wm/client.c

806 lines
17 KiB
C
Raw Normal View History

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 <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
#include "wm.h"
#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
static void
update_client_name(Client *c)
{
XTextProperty name;
XClassHint ch;
int n;
char **list = nil;
2006-04-24 18:03:37 +04:00
name.nitems = 0;
2006-04-24 18:03:37 +04:00
c->name[0] = 0;
XGetTextProperty(blz.display, c->win, &name, net_atom[NetWMName]);
if(!name.nitems)
XGetWMName(blz.display, c->win, &name);
if(!name.nitems)
return;
if(name.encoding == XA_STRING)
cext_strlcpy(c->name, (char *)name.value, sizeof(c->name));
else {
if(XmbTextPropertyToTextList(blz.display, &name, &list, &n) >= Success
&& n > 0 && *list)
2006-04-24 18:03:37 +04:00
{
cext_strlcpy(c->name, *list, sizeof(c->name));
XFreeStringList(list);
}
}
XFree(name.value);
if(XGetClassHint(blz.display, c->win, &ch)) {
snprintf(c->props, sizeof(c->props), "%s:%s:%s",
ch.res_class ? ch.res_class : "",
ch.res_name ? ch.res_name : "",
c->name);
if(ch.res_class)
XFree(ch.res_class);
if(ch.res_name)
XFree(ch.res_name);
}
}
2005-12-21 18:18:11 +03:00
Client *
2006-04-12 12:44:07 +04:00
create_client(Window w, XWindowAttributes *wa)
2005-11-18 18:54:58 +03:00
{
2006-06-08 12:54:19 +04:00
Client **t, *c = (Client *) cext_emallocz(sizeof(Client));
XSetWindowAttributes fwa;
long msize;
2006-06-08 12:54:19 +04:00
unsigned int i;
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++;
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(blz.display, c->win, 0);
c->proto = win_proto(c->win);
XGetTransientForHint(blz.display, c->win, &c->trans);
if(!XGetWMNormalHints(blz.display, c->win, &c->size, &msize) || !c->size.flags)
c->size.flags = PSize;
2006-05-23 23:08:24 +04:00
if(c->size.flags & PMinSize && c->size.flags & PMaxSize
&& c->size.min_width == c->size.max_width
&& c->size.min_height == c->size.max_height)
c->fixedsize = True;
else
c->fixedsize = False;
XAddToSaveSet(blz.display, c->win);
update_client_name(c);
fwa.override_redirect = 1;
fwa.background_pixmap = ParentRelative;
fwa.event_mask =
SubstructureRedirectMask | SubstructureNotifyMask | ExposureMask
| ButtonPressMask | PointerMotionMask | ButtonReleaseMask;
c->framewin = XCreateWindow(blz.display, blz.root, c->rect.x, c->rect.y,
c->rect.width + 2 * def.border,
2006-04-12 12:44:07 +04:00
c->rect.height + def.border + height_of_bar(), 0,
DefaultDepth(blz.display, blz.screen), CopyFromParent,
DefaultVisual(blz.display, blz.screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
c->gc = XCreateGC(blz.display, c->framewin, 0, 0);
XSync(blz.display, False);
2006-06-08 12:54:19 +04:00
for(t=&client, i=0; *t; t=&(*t)->next, i++);
c->next = *t; /* *t == nil */
*t = c;
write_event("CreateClient %d\n", i);
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
{
long data[] = { state, None };
XChangeProperty(blz.display, c->win, wm_atom[WMState], wm_atom[WMState], 32,
PropModeReplace, (unsigned char *) data, 2);
2005-11-18 18:54:58 +03:00
}
2006-04-27 20:32:37 +04:00
void
update_client_grab(Client *c, Bool is_sel)
{
if(is_sel) {
ungrab_mouse(c->framewin, AnyModifier, AnyButton);
grab_mouse(c->framewin, def.mod, Button1);
grab_mouse(c->framewin, def.mod, Button3);
}
else
grab_mouse(c->framewin, AnyModifier, Button1);
}
void
focus_client(Client *c, Bool restack)
2006-01-26 14:39:20 +03:00
{
Client *old;
Frame *f;
Client *old_in_area;
View *v;
if(!sel_screen)
return;
old = sel_client();
f = c->sel;
old_in_area = sel_client_of_area(f->area);
v = f->area->view;
2006-06-08 12:54:19 +04:00
v->sel = f->area;
f->area->sel = f;
c->floating = f->area->floating;
if(restack)
restack_view(v);
2006-04-27 20:32:37 +04:00
else {
if(old)
update_client_grab(old, False);
update_client_grab(c, True);
}
2006-06-08 12:54:19 +04:00
if(!c->floating && f->area->mode == Colstack)
arrange_column(f->area, False);
XSetInputFocus(blz.display, c->win, RevertToPointerRoot, CurrentTime);
if(old && old != old_in_area && old != c) {
update_frame_widget_colors(old->sel);
draw_frame(old->sel);
}
if(old_in_area && old_in_area != c) {
update_frame_widget_colors(old_in_area->sel);
draw_frame(old_in_area->sel);
}
update_frame_widget_colors(c->sel);
draw_frame(c->sel);
XSync(blz.display, False);
write_event("ClientFocus %d\n", idx_of_client(c));
}
2005-12-21 18:18:11 +03:00
void
map_client(Client *c)
2005-11-18 18:54:58 +03:00
{
XSelectInput(blz.display, c->win, CLIENT_MASK & ~StructureNotifyMask);
XMapWindow(blz.display, c->win);
XSelectInput(blz.display, c->win, CLIENT_MASK);
set_client_state(c, NormalState);
2005-11-18 18:54:58 +03:00
}
2005-12-21 18:18:11 +03:00
void
unmap_client(Client *c)
2005-11-18 18:54:58 +03:00
{
XSelectInput(blz.display, c->win, CLIENT_MASK & ~StructureNotifyMask);
XUnmapWindow(blz.display, c->win);
XSelectInput(blz.display, c->win, CLIENT_MASK);
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
{
XSelectInput(blz.display, c->win, CLIENT_MASK & ~StructureNotifyMask);
XReparentWindow(blz.display, c->win, w, x, y);
XSelectInput(blz.display, 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
{
XConfigureEvent e;
2006-06-08 12:54:19 +04:00
Frame *f = c->sel;
e.type = ConfigureNotify;
e.event = c->win;
e.window = c->win;
e.x = c->rect.x;
e.y = c->rect.y;
if(f) {
e.x += f->rect.x;
e.y += f->rect.y;
2006-01-25 21:41:12 +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(blz.display, c->win, CLIENT_MASK & ~StructureNotifyMask);
XSendEvent(blz.display, c->win, False, StructureNotifyMask, (XEvent *) & e);
XSelectInput(blz.display, c->win, CLIENT_MASK);
XSync(blz.display, False);
2005-11-18 18:54:58 +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(blz.display, w, False, NoEventMask, &e);
XSync(blz.display, 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
{
if(c->proto & WM_PROTOCOL_DELWIN)
send_client_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
else
XKillClient(blz.display, c->win);
2005-11-18 18:54:58 +03:00
}
2005-12-21 18:18:11 +03:00
void
2006-04-12 12:44:07 +04:00
prop_client(Client *c, XPropertyEvent *e)
2005-11-18 18:54:58 +03:00
{
long msize;
if(e->atom == wm_atom[WMProtocols]) {
/* update */
c->proto = win_proto(c->win);
return;
}
switch (e->atom) {
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(blz.display, c->win, &c->trans);
break;
case XA_WM_NORMAL_HINTS:
if(!XGetWMNormalHints(blz.display, c->win, &c->size, &msize) || !c->size.flags) {
c->size.flags = PSize;
}
2006-05-23 23:08:24 +04:00
if(c->size.flags & PMinSize && c->size.flags & PMaxSize
&& c->size.min_width == c->size.max_width
&& c->size.min_height == c->size.max_height)
c->fixedsize = True;
else
c->fixedsize = False;
break;
}
if(e->atom == XA_WM_NAME || e->atom == net_atom[NetWMName]) {
update_client_name(c);
2006-06-08 12:54:19 +04:00
if(c->frame)
draw_frame(c->sel);
}
2005-11-18 18:54:58 +03:00
}
2005-12-21 18:18:11 +03:00
void
2006-04-12 12:44:07 +04:00
gravitate_client(Client *c, Bool invert)
2005-11-18 18:54:58 +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:
2006-04-12 12:44:07 +04:00
dy = height_of_bar();
break;
case EastGravity:
case CenterGravity:
case WestGravity:
2006-04-12 12:44:07 +04:00
dy = -(c->rect.height / 2) + height_of_bar();
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
void
manage_client(Client *c)
{
XTextProperty tags;
2006-03-11 03:32:10 +03:00
Client *trans;
tags.nitems = 0;
XGetTextProperty(blz.display, c->win, &tags, tags_atom);
2006-04-12 12:44:07 +04:00
if(c->trans && (trans = client_of_win(c->trans)))
2006-04-06 14:19:20 +04:00
cext_strlcpy(c->tags, trans->tags, sizeof(c->tags));
else if(tags.nitems)
cext_strlcpy(c->tags, (char *)tags.value, sizeof(c->tags));
XFree(tags.value);
if(!strlen(c->tags))
2006-04-12 12:44:07 +04:00
apply_rules(c);
reparent_client(c, c->framewin, c->rect.x, c->rect.y);
2006-04-13 17:35:10 +04:00
update_views();
2006-04-27 16:17:18 +04:00
map_client(c);
XMapWindow(blz.display, c->framewin);
XSync(blz.display, False);
2006-06-08 12:54:19 +04:00
if(c->sel->area->view == sel)
2006-04-27 16:17:18 +04:00
focus_client(c, False);
flush_masked_events(EnterWindowMask);
2005-12-05 22:38:03 +03:00
}
2005-12-06 00:22:24 +03:00
static int
dummy_error_handler(Display *dpy, XErrorEvent *error)
{
return 0;
}
2006-03-06 01:38:50 +03:00
void
destroy_client(Client *c)
2006-03-06 01:38:50 +03:00
{
2006-06-08 12:54:19 +04:00
View *v;
Client **tc;
XGrabServer(blz.display);
XSetErrorHandler(dummy_error_handler);
2006-06-08 12:54:19 +04:00
if(c->frame) {
c->rect.x = c->sel->rect.x;
c->rect.y = c->sel->rect.y;
}
2006-06-08 12:54:19 +04:00
for(v=view; v; v=v->next)
detach_from_view(v, c);
*c->tags = '\0';
update_client_views(c);
2006-05-14 19:27:00 +04:00
unmap_client(c);
reparent_client(c, blz.root, c->rect.x, c->rect.y);
XFreeGC(blz.display, c->gc);
XDestroyWindow(blz.display, c->framewin);
for(tc=&client; *tc && *tc != c; tc=&(*tc)->next);
cext_assert(*tc == c);
*tc = c->next;
2006-04-13 17:35:10 +04:00
update_views();
free(c);
XSync(blz.display, False);
XSetErrorHandler(wmii_error_handler);
XUngrabServer(blz.display);
flush_masked_events(EnterWindowMask);
2006-03-06 01:38:50 +03:00
}
2006-01-26 20:29:49 +03:00
Client *
sel_client()
{
2006-06-08 12:54:19 +04:00
return sel && sel->sel->sel ? sel->sel->sel->client : nil;
2006-01-26 20:29:49 +03:00
}
void
2006-06-08 12:54:19 +04:00
match_sizehints(Client *c, XRectangle *r, Bool floating, BlitzAlign sticky)
{
XSizeHints *s = &c->size;
unsigned int dx = 2 * def.border;
unsigned int dy = def.border + height_of_bar();
unsigned int hdiff, wdiff;
2006-06-08 12:54:19 +04:00
if(floating && (s->flags & PMinSize)) {
if(r->width < s->min_width + dx) {
wdiff = (s->min_width + dx) - r->width;
r->width += wdiff;
if((sticky & EAST) && !(sticky & WEST))
r->x -= wdiff;
}
if(r->height < s->min_height + dy) {
hdiff = (s->min_height + dy) - r->height;
r->height += hdiff;
if((sticky & SOUTH) && !(sticky & NORTH))
r->y -= hdiff;
}
}
2006-06-08 12:54:19 +04:00
if(floating && (s->flags & PMaxSize)) {
if(r->width > s->max_width + dx) {
wdiff = r->width - (s->max_width + dx);
r->width -= wdiff;
if((sticky & EAST) && !(sticky & WEST))
r->x += wdiff;
}
if(r->height > s->max_height + dy) {
hdiff = r->height - (s->max_height + dy);
r->height -= hdiff;
if((sticky & SOUTH) && !(sticky & NORTH))
r->y += hdiff;
}
}
if(s->flags & PResizeInc) {
int w = 0, h = 0;
2006-05-25 20:53:09 +04:00
if(s->flags & PBaseSize) {
w = s->base_width;
h = s->base_height;
} else if(s->flags & PMinSize) {
/* base_{width,height} default to min_{width,height} */
2006-05-25 20:53:09 +04:00
w = s->min_width;
h = s->min_height;
}
2006-05-25 20:53:09 +04:00
/* client_width = base_width + i * s->width_inc for an integer i */
w = r->width - dx - w;
if(s->width_inc > 0) {
wdiff = w % s->width_inc;
r->width -= wdiff;
if((sticky & EAST) && !(sticky & WEST))
r->x += wdiff;
}
h = r->height - dy - h;
if(s->height_inc > 0) {
hdiff = h % s->height_inc;
r->height -= hdiff;
if((sticky & SOUTH) && !(sticky & NORTH))
r->y += hdiff;
}
}
}
void
resize_client(Client *c, XRectangle *r, Bool ignore_xcall)
{
2006-06-08 12:54:19 +04:00
Frame *f = c->sel;
Bool floating = f->area->floating;
BlitzAlign stickycorner = 0;;
if(f->rect.x != r->x && f->rect.x + f->rect.width == r->x + r->width)
stickycorner |= EAST;
else
stickycorner |= WEST;
if(f->rect.y != r->y && f->rect.y + f->rect.height == r->y + r->height)
stickycorner |= SOUTH;
else
stickycorner |= NORTH;
f->rect = *r;
2006-06-08 12:54:19 +04:00
if((f->area->mode != Colstack) || (f->area->sel == f))
match_sizehints(c, &c->sel->rect, floating, stickycorner);
if(!ignore_xcall) {
2006-06-08 12:54:19 +04:00
if(floating &&
2006-05-10 17:24:09 +04:00
(c->rect.width >= rect.width) &&
(c->rect.height >= rect.height))
{
f->rect.x = -def.border;
f->rect.y = -height_of_bar();
}
2006-06-08 12:54:19 +04:00
if(f->area->view == sel)
XMoveResizeWindow(blz.display, c->framewin, f->rect.x,
f->rect.y, f->rect.width, f->rect.height);
else
XMoveResizeWindow(blz.display, c->framewin, 2 * rect.width + f->rect.x,
f->rect.y, f->rect.width, f->rect.height);
}
c->rect.x = def.border;
c->rect.y = height_of_bar();
2006-06-08 12:54:19 +04:00
if((f->area->sel == f) || (f->area->mode != Colstack)) {
c->rect.width = f->rect.width - 2 * def.border;
2006-04-12 12:44:07 +04:00
c->rect.height = f->rect.height - def.border - height_of_bar();
2006-03-01 13:30:44 +03:00
}
XMoveResizeWindow(blz.display, c->win, c->rect.x, c->rect.y,
c->rect.width, c->rect.height);
configure_client(c);
}
void
newcol_client(Client *c, char *arg)
{
2006-06-08 12:54:19 +04:00
Frame *f = c->sel;
Area *to, *a = f->area;
View *v = a->view;
if(a->floating)
2006-06-08 12:54:19 +04:00
return;
if(!f->anext && f == a->frame)
return;
if(!strncmp(arg, "prev", 5)) {
2006-06-08 12:54:19 +04:00
for(to=v->area; to && to->next != a; to=to->next);
to = new_column(v, to, 0);
send_to_area(to, a, c);
}
else if(!strncmp(arg, "next", 5)) {
2006-06-08 12:54:19 +04:00
to = new_column(v, a, 0);
send_to_area(to, a, c);
}
else
return;
flush_masked_events(EnterWindowMask);
}
void
move_client(Client *c, char *arg)
{
2006-06-08 12:54:19 +04:00
Frame *f = c->sel;
XRectangle new = f->rect;
2006-05-29 13:18:18 +04:00
int x, y;
2006-05-29 13:18:18 +04:00
if(sscanf(arg, "%d %d", &x, &y) != 2)
return;
2006-05-29 13:18:18 +04:00
new.x += x;
new.y += y;
if(idx_of_area(f->area))
resize_column(f->client, &new, nil);
else
resize_client(f->client, &new, False);
}
void
size_client(Client *c, char *arg)
{
2006-06-08 12:54:19 +04:00
Frame *f = c->sel;
XRectangle new = f->rect;
2006-05-29 13:18:18 +04:00
int w, h;
2006-05-29 13:18:18 +04:00
if(sscanf(arg, "%d %d", &w, &h) != 2)
return;
2006-05-29 13:18:18 +04:00
new.width += w;
new.height += h;
if(!f->area->floating)
resize_column(f->client, &new, nil);
else
resize_client(f->client, &new, False);
}
char *
send_client(Frame *f, char *arg)
2006-03-02 19:38:15 +03:00
{
2006-06-20 02:25:49 +04:00
static char Ebadvalue[] = "bad value";
Area *to, *a;
Client *c;
Frame *tf;
View *v;
int i, j;
2006-06-20 02:25:49 +04:00
a = f->area;
v = a->view;
c = f->client;
i = idx_of_area(a);
j = idx_of_frame(f);
2006-05-19 19:38:45 +04:00
if((i == -1) || (j == -1))
return 0;
2006-06-20 02:25:49 +04:00
if(i && !strncmp(arg, "left", 5)) {
if(a->floating)
return Ebadvalue;
2006-06-08 12:54:19 +04:00
for(to=v->area->next; to && a != to->next; to=to->next);
if(!to && (f->anext || f != a->frame))
to=new_column(v, v->area, 0);
if(!to)
return Ebadvalue;
2006-05-19 19:38:45 +04:00
send_to_area(to, a, c);
}
2006-06-20 02:25:49 +04:00
else if(i && !strncmp(arg, "right", 5)) {
if(a->floating)
return Ebadvalue;
2006-06-08 12:54:19 +04:00
if(!(to = a->next) && (f->anext || f!= a->frame))
to = new_column(v, a, 0);
if(!to)
return Ebadvalue;
2006-05-19 19:38:45 +04:00
send_to_area(to, a, c);
}
else if(!strncmp(arg, "toggle", 7)) {
if(!a->floating)
2006-06-08 12:54:19 +04:00
to = v->area;
else if(c->revert && !c->revert->floating)
to = c->revert;
else
2006-06-08 12:54:19 +04:00
to = v->area->next;
2006-05-19 19:38:45 +04:00
send_to_area(to, a, c);
}
2006-05-19 19:38:45 +04:00
else if(i && !strncmp(arg, "up", 3)) {
2006-06-08 12:54:19 +04:00
for(tf=a->frame; tf && tf->anext != f; tf=tf->anext);
if(!tf)
return Ebadvalue;
2006-06-08 12:54:19 +04:00
remove_frame(f);
insert_frame(tf, f, True);
2006-05-19 19:38:45 +04:00
arrange_column(a, False);
focus_client(c, True);
}
else if(i && !strncmp(arg, "down", 5)) {
2006-06-08 12:54:19 +04:00
if(!f->anext)
return Ebadvalue;
2006-06-08 12:54:19 +04:00
remove_frame(f);
insert_frame(f->anext, f, False);
2006-05-19 19:38:45 +04:00
arrange_column(a, False);
focus_client(c, True);
}
else if(i) {
if(sscanf(arg, "%d", &j) != 1)
return Ebadvalue;
2006-06-08 12:54:19 +04:00
for(to=v->area; to && j; to=to->next, j--);
2006-05-19 19:38:45 +04:00
send_to_area(to, a, c);
}
2006-05-19 19:38:45 +04:00
else
return Ebadvalue;
flush_masked_events(EnterWindowMask);
return nil;
}
void
resize_all_clients()
{
2006-06-08 12:54:19 +04:00
Client *c;
for(c = client; c; c=c->next) {
if(c->frame && c->sel->area) {
if(idx_of_area(c->sel->area))
resize_column(c, &c->sel->rect, nil);
else
2006-06-08 12:54:19 +04:00
resize_client(c, &c->sel->rect, False);
}
}
flush_masked_events(EnterWindowMask);
}
/* convenience function */
void
focus(Client *c, Bool restack)
{
2006-06-08 12:54:19 +04:00
Frame *f = c->sel;
View *v;
if(!f)
return;
v = f->area->view;
2006-06-08 12:54:19 +04:00
if(sel != v)
focus_view(v);
focus_client(c, restack);
}
2006-03-07 19:22:36 +03:00
2006-06-08 12:54:19 +04:00
Client *
client_of_id(unsigned short id)
{
Client *c;
for(c=client; c && c->id != id; c=c->next);
return c;
}
2006-03-07 19:22:36 +03:00
int
2006-06-08 12:54:19 +04:00
idx_of_client(Client *c)
2006-03-07 19:22:36 +03:00
{
2006-06-08 12:54:19 +04:00
Client *cl;
int i = 0;
for(cl=client; cl && cl != c; cl=cl->next, i++);
return cl ? i : -1;
2006-03-07 19:22:36 +03:00
}
2006-04-12 12:44:07 +04:00
Client *
client_of_win(Window w)
{
2006-06-08 12:54:19 +04:00
Client *c;
2006-04-12 12:44:07 +04:00
2006-06-08 12:54:19 +04:00
for(c=client; c && c->win != w; c=c->next);
return c;
}
static Bool
permit_tag(const char *tag)
{
static char *exclude[] = { "sel", "status" };
unsigned int i;
for(i = 0; i < (sizeof(exclude) / sizeof(exclude[0])); i++)
if(!strcmp(exclude[i], tag))
return False;
return True;
}
void
apply_tags(Client *c, const char *tags)
{
unsigned int i, j = 0, n;
char buf[256];
char *toks[16], *apply[16];
cext_strlcpy(buf, tags, sizeof(buf));
if(!(n = cext_tokenize(toks, 16, buf, '+')))
return;
for(i = 0; i < n; i++) {
if(!strncmp(toks[i], "~", 2))
c->floating = True;
else if(!strncmp(toks[i], "!", 2)) {
2006-06-08 12:54:19 +04:00
if(view)
apply[j++] = sel->name;
else
apply[j++] = "nil";
}
else if(permit_tag(toks[i]))
apply[j++] = toks[i];
}
c->tags[0] = 0;
for(i = 0; i < j; i++) {
cext_strlcat(c->tags, apply[i], sizeof(c->tags) - strlen(c->tags) - 1);
if(i + 1 < j)
cext_strlcat(c->tags, "+", sizeof(c->tags) - strlen(c->tags) - 1);
}
if(!strlen(c->tags))
apply_tags(c, "nil");
XChangeProperty(blz.display, c->win, tags_atom, XA_STRING, 8,
PropModeReplace, c->tags, strlen(c->tags));
}
static void
match_tags(Client *c, const char *prop)
{
2006-06-08 12:54:19 +04:00
Rule *r;
regmatch_t tmpregm;
2006-06-17 15:32:49 +04:00
for(r=def.tagrules.rule; r; r=r->next)
if(!regexec(&r->regex, prop, 1, &tmpregm, 0))
if(!strlen(c->tags) || !strncmp(c->tags, "nil", 4))
apply_tags(c, r->value);
}
void
apply_rules(Client *c)
{
2006-06-17 15:32:49 +04:00
if(def.tagrules.string)
2006-06-02 09:13:23 +04:00
match_tags(c, c->props);
if(!strlen(c->tags))
apply_tags(c, "nil");
}
char *
message_client(Client *c, char *message)
{
static char Ebadcmd[] = "bad command";
if(!strncmp(message, "kill", 5)) {
kill_client(c);
return nil;
}
return Ebadcmd;
}