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"
|
|
|
|
|
2006-04-26 10:59:55 +04:00
|
|
|
#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
|
2006-03-23 16:37:54 +03:00
|
|
|
|
2006-04-03 15:40:34 +04:00
|
|
|
static Vector *
|
2006-04-13 17:35:10 +04:00
|
|
|
vector_of_clients(ClientVector *cv)
|
2006-04-03 00:53:56 +04:00
|
|
|
{
|
2006-04-03 15:40:34 +04:00
|
|
|
return (Vector *) cv;
|
2006-04-03 00:53:56 +04:00
|
|
|
}
|
|
|
|
|
2006-04-24 00:33:09 +04:00
|
|
|
static void
|
|
|
|
update_client_name(Client *c)
|
|
|
|
{
|
|
|
|
XTextProperty name;
|
2006-05-30 18:32:28 +04:00
|
|
|
XClassHint ch;
|
2006-04-25 15:33:30 +04:00
|
|
|
int n;
|
|
|
|
char **list = nil;
|
2006-04-24 18:03:37 +04:00
|
|
|
|
2006-04-25 15:33:30 +04:00
|
|
|
name.nitems = 0;
|
2006-04-24 18:03:37 +04:00
|
|
|
c->name[0] = 0;
|
2006-05-10 15:38:01 +04:00
|
|
|
XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
|
|
|
|
if(!name.nitems)
|
|
|
|
XGetWMName(dpy, c->win, &name);
|
2006-04-25 15:33:30 +04:00
|
|
|
if(!name.nitems)
|
|
|
|
return;
|
|
|
|
if(name.encoding == XA_STRING)
|
|
|
|
cext_strlcpy(c->name, (char *)name.value, sizeof(c->name));
|
|
|
|
else {
|
2006-05-10 17:33:53 +04:00
|
|
|
if(Xi18nTextPropertyToTextList(dpy, &name, &list, &n) >= Success
|
2006-05-10 15:38:01 +04:00
|
|
|
&& n > 0 && *list)
|
2006-04-24 18:03:37 +04:00
|
|
|
{
|
|
|
|
cext_strlcpy(c->name, *list, sizeof(c->name));
|
|
|
|
XFreeStringList(list);
|
2006-04-24 03:01:49 +04:00
|
|
|
}
|
2006-04-24 00:33:09 +04:00
|
|
|
}
|
2006-04-25 15:33:30 +04:00
|
|
|
XFree(name.value);
|
2006-05-30 18:32:28 +04:00
|
|
|
if(XGetClassHint(dpy, 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);
|
|
|
|
}
|
2006-04-24 00:33:09 +04:00
|
|
|
}
|
|
|
|
|
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-03-23 01:49:18 +03:00
|
|
|
Client *c = (Client *) cext_emallocz(sizeof(Client));
|
|
|
|
XSetWindowAttributes fwa;
|
|
|
|
long msize;
|
2006-03-07 19:22:36 +03:00
|
|
|
static unsigned int id = 1;
|
2006-05-01 23:58:31 +04:00
|
|
|
static char buf[256];
|
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;
|
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)
|
2006-05-23 00:35:20 +04:00
|
|
|
c->fixedsize = True;
|
|
|
|
else
|
|
|
|
c->fixedsize = False;
|
2006-03-23 01:49:18 +03:00
|
|
|
XAddToSaveSet(dpy, c->win);
|
2006-04-24 00:33:09 +04:00
|
|
|
update_client_name(c);
|
2006-03-23 01:49:18 +03:00
|
|
|
fwa.override_redirect = 1;
|
|
|
|
fwa.background_pixmap = ParentRelative;
|
|
|
|
fwa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
|
2006-04-26 10:59:55 +04:00
|
|
|
| ExposureMask | ButtonPressMask | ButtonReleaseMask;
|
2006-03-23 01:49:18 +03:00
|
|
|
|
|
|
|
c->framewin = XCreateWindow(dpy, 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,
|
2006-03-23 01:49:18 +03:00
|
|
|
DefaultDepth(dpy, screen), CopyFromParent,
|
|
|
|
DefaultVisual(dpy, screen),
|
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
|
|
|
|
c->gc = XCreateGC(dpy, c->framewin, 0, 0);
|
|
|
|
XSync(dpy, False);
|
2006-04-13 17:35:10 +04:00
|
|
|
cext_vattach(vector_of_clients(&client), c);
|
2006-05-01 23:58:31 +04:00
|
|
|
snprintf(buf, sizeof(buf), "CreateClient %d\n", client.size - 1);
|
|
|
|
write_event(buf);
|
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-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);
|
|
|
|
}
|
|
|
|
|
2006-01-19 17:02:18 +03:00
|
|
|
void
|
2006-04-26 10:59:55 +04:00
|
|
|
focus_client(Client *c, Bool restack)
|
2006-01-26 14:39:20 +03:00
|
|
|
{
|
|
|
|
Client *old = sel_client();
|
2006-04-03 00:53:56 +04:00
|
|
|
Frame *f = c->frame.data[c->sel];
|
2006-05-08 23:44:56 +04:00
|
|
|
Client *old_in_area = sel_client_of_area(f->area);
|
2006-03-31 09:57:33 +04:00
|
|
|
View *v = f->area->view;
|
2006-04-12 12:44:07 +04:00
|
|
|
int i = idx_of_area(f->area);
|
2006-04-26 10:59:55 +04:00
|
|
|
static char buf[256];
|
2006-03-23 01:49:18 +03:00
|
|
|
|
2006-03-31 09:57:33 +04:00
|
|
|
v->sel = i;
|
2006-04-12 12:44:07 +04:00
|
|
|
f->area->sel = idx_of_frame(f);
|
2006-05-30 02:00:16 +04:00
|
|
|
c->floating = !i;
|
2006-04-26 10:59:55 +04:00
|
|
|
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-03-09 15:19:12 +03:00
|
|
|
|
2006-03-05 03:55:45 +03:00
|
|
|
if(i > 0 && f->area->mode == Colstack)
|
2006-04-06 19:03:12 +04:00
|
|
|
arrange_column(f->area, False);
|
2006-04-28 00:55:15 +04:00
|
|
|
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
2006-05-09 23:08:07 +04:00
|
|
|
if(old && old != old_in_area && old != c)
|
2006-04-28 14:37:19 +04:00
|
|
|
draw_client(old);
|
2006-05-09 23:08:07 +04:00
|
|
|
if(old_in_area && old_in_area != c)
|
2006-05-08 23:44:56 +04:00
|
|
|
draw_client(old_in_area);
|
2006-04-28 00:55:15 +04:00
|
|
|
draw_client(c);
|
2006-04-28 14:37:19 +04:00
|
|
|
XSync(dpy, False);
|
2006-04-26 11:40:01 +04:00
|
|
|
snprintf(buf, sizeof(buf), "ClientFocus %d\n", idx_of_client_id(c->id));
|
2006-04-26 10:59:55 +04:00
|
|
|
write_event(buf);
|
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-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-04-03 00:53:56 +04:00
|
|
|
Frame *f = c->frame.data[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-04-12 12:44:07 +04:00
|
|
|
prop_client(Client *c, XPropertyEvent *e)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +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(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;
|
|
|
|
}
|
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)
|
2006-05-23 00:35:20 +04:00
|
|
|
c->fixedsize = True;
|
|
|
|
else
|
|
|
|
c->fixedsize = False;
|
2006-03-23 01:49:18 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-05-10 15:38:01 +04:00
|
|
|
if(e->atom == XA_WM_NAME || e->atom == net_atom[NetWMName]) {
|
2006-04-24 03:01:49 +04:00
|
|
|
update_client_name(c);
|
|
|
|
if(c->frame.size)
|
|
|
|
draw_client(c);
|
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
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-04-23 22:00:47 +04:00
|
|
|
BlitzDraw d = { 0 };
|
2006-04-26 20:46:54 +04:00
|
|
|
Frame *f;
|
2006-05-08 01:29:04 +04:00
|
|
|
char buf[256];
|
|
|
|
int fidx;
|
|
|
|
unsigned int w;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-04-03 00:53:56 +04:00
|
|
|
if(!c->frame.size)
|
2006-03-08 18:05:09 +03:00
|
|
|
return; /* might not have been attached atm */
|
|
|
|
|
2006-04-26 20:46:54 +04:00
|
|
|
f = c->frame.data[c->sel];
|
2006-05-08 01:29:04 +04:00
|
|
|
fidx = idx_of_frame(f);
|
2006-03-05 02:25:49 +03:00
|
|
|
d.drawable = c->framewin;
|
2006-04-23 22:00:47 +04:00
|
|
|
d.font = blitzfont;
|
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())
|
2006-05-19 22:14:06 +04:00
|
|
|
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) {
|
2006-04-26 20:46:54 +04:00
|
|
|
d.rect = f->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;
|
2006-04-12 12:44:07 +04:00
|
|
|
d.rect.height = height_of_bar();
|
2006-02-02 22:36:10 +03:00
|
|
|
d.notch = nil;
|
2006-03-15 15:18:05 +03:00
|
|
|
|
2006-05-08 01:29:04 +04:00
|
|
|
/* mode bar */
|
|
|
|
d.align = CENTER;
|
|
|
|
snprintf(buf, sizeof(buf), "%s%d/%d",
|
|
|
|
/* if */ !idx_of_area(f->area) ? "~" : "",
|
2006-05-08 01:58:06 +04:00
|
|
|
fidx + 1, f->area->frame.size);
|
2006-05-08 01:29:04 +04:00
|
|
|
w = d.rect.width = d.rect.height + blitz_textwidth(dpy, &blitzfont, buf);
|
2006-05-09 14:37:13 +04:00
|
|
|
if(w > f->rect.width)
|
|
|
|
return;
|
2006-05-08 01:29:04 +04:00
|
|
|
d.rect.x = f->rect.width - d.rect.width;
|
|
|
|
d.data = buf;
|
|
|
|
|
2006-05-19 22:14:06 +04:00
|
|
|
if(f->area->sel == fidx)
|
|
|
|
d.color = def.sel;
|
|
|
|
else
|
|
|
|
d.color = def.norm;
|
2006-05-08 01:29:04 +04:00
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
blitz_drawborder(dpy, &d);
|
|
|
|
d.rect.x = 0;
|
|
|
|
|
2006-05-19 22:14:06 +04:00
|
|
|
if(c == sel_client())
|
|
|
|
d.color = def.sel;
|
|
|
|
else
|
|
|
|
d.color = def.norm;
|
|
|
|
|
2006-04-12 14:24:04 +04:00
|
|
|
/* tag bar */
|
2006-04-25 15:33:30 +04:00
|
|
|
d.rect.width = d.rect.height + blitz_textwidth(dpy, &blitzfont, c->tags);
|
2006-05-09 14:37:13 +04:00
|
|
|
if(d.rect.width + w > f->rect.width)
|
|
|
|
return;
|
2006-05-08 01:29:04 +04:00
|
|
|
if(d.rect.width > f->rect.width / 3)
|
|
|
|
d.rect.width = f->rect.width / 3;
|
2006-04-06 13:31:54 +04:00
|
|
|
d.data = c->tags;
|
2006-03-24 17:30:48 +03:00
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
blitz_drawborder(dpy, &d);
|
2006-04-12 14:24:04 +04:00
|
|
|
d.rect.x += d.rect.width;
|
|
|
|
|
|
|
|
/* title bar */
|
|
|
|
d.align = WEST;
|
2006-05-09 14:37:13 +04:00
|
|
|
if(d.rect.x + w > f->rect.width)
|
|
|
|
return;
|
2006-05-08 01:29:04 +04:00
|
|
|
d.rect.width = f->rect.width - (d.rect.x + w);
|
2006-04-12 14:24:04 +04:00
|
|
|
d.data = c->name;
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
blitz_drawborder(dpy, &d);
|
2006-03-24 17:30:48 +03:00
|
|
|
|
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-04-12 12:44:07 +04:00
|
|
|
gravitate_client(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:
|
2006-04-12 12:44:07 +04:00
|
|
|
dy = height_of_bar();
|
2006-03-23 01:49:18 +03:00
|
|
|
break;
|
|
|
|
case EastGravity:
|
|
|
|
case CenterGravity:
|
|
|
|
case WestGravity:
|
2006-04-12 12:44:07 +04:00
|
|
|
dy = -(c->rect.height / 2) + height_of_bar();
|
2006-03-23 01:49:18 +03:00
|
|
|
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-11 03:32:10 +03:00
|
|
|
Client *trans;
|
2006-03-23 01:49:18 +03:00
|
|
|
|
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));
|
2006-05-13 23:15:44 +04:00
|
|
|
if(!strlen(c->tags))
|
2006-04-12 12:44:07 +04:00
|
|
|
apply_rules(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-04-13 17:35:10 +04:00
|
|
|
update_views();
|
2006-04-27 16:17:18 +04:00
|
|
|
map_client(c);
|
|
|
|
XMapWindow(dpy, c->framewin);
|
2006-04-28 14:37:19 +04:00
|
|
|
XSync(dpy, False);
|
2006-04-27 16:17:18 +04:00
|
|
|
if(c->frame.data[c->sel]->area->view == view.data[sel])
|
|
|
|
focus_client(c, False);
|
2006-05-01 23:15:24 +04:00
|
|
|
flush_masked_events(EnterWindowMask);
|
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
|
|
|
{
|
2006-04-10 19:43:13 +04:00
|
|
|
unsigned int i;
|
2006-03-09 01:53:52 +03:00
|
|
|
|
2006-03-09 22:25:50 +03:00
|
|
|
XGrabServer(dpy);
|
|
|
|
XSetErrorHandler(dummy_error_handler);
|
|
|
|
|
2006-04-03 00:53:56 +04:00
|
|
|
if(c->frame.size) {
|
|
|
|
c->rect.x = c->frame.data[c->sel]->rect.x;
|
|
|
|
c->rect.y = c->frame.data[c->sel]->rect.y;
|
2006-03-06 20:34:57 +03:00
|
|
|
}
|
2006-03-09 01:53:52 +03:00
|
|
|
|
2006-05-14 19:27:00 +04:00
|
|
|
for(i = 0; i < view.size; i++)
|
|
|
|
detach_from_view(view.data[i], c);
|
|
|
|
|
|
|
|
unmap_client(c);
|
|
|
|
|
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-04-13 17:35:10 +04:00
|
|
|
cext_vdetach(vector_of_clients(&client), c);
|
|
|
|
update_views();
|
2006-03-23 01:49:18 +03:00
|
|
|
free(c);
|
2006-03-09 01:53:52 +03:00
|
|
|
|
2006-03-09 22:25:50 +03:00
|
|
|
XSync(dpy, False);
|
|
|
|
XSetErrorHandler(wmii_error_handler);
|
|
|
|
XUngrabServer(dpy);
|
2006-05-01 23:15:24 +04:00
|
|
|
flush_masked_events(EnterWindowMask);
|
2006-03-06 01:38:50 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 20:29:49 +03:00
|
|
|
Client *
|
|
|
|
sel_client()
|
|
|
|
{
|
2006-04-03 00:53:56 +04:00
|
|
|
return view.size ? sel_client_of_view(view.data[sel]) : nil;
|
2006-01-26 20:29:49 +03:00
|
|
|
}
|
|
|
|
|
2006-06-05 07:47:09 +04:00
|
|
|
void
|
|
|
|
match_sizehints(Client *c, XRectangle *r, int aidx, BlitzAlign sticky)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-03-23 01:49:18 +03:00
|
|
|
XSizeHints *s = &c->size;
|
2006-05-26 16:29:04 +04:00
|
|
|
unsigned int dx = 2 * def.border;
|
|
|
|
unsigned int dy = def.border + height_of_bar();
|
2006-05-27 21:56:22 +04:00
|
|
|
unsigned int hdiff, wdiff;
|
2006-05-26 16:29:04 +04:00
|
|
|
|
2006-05-29 23:38:02 +04:00
|
|
|
if(!aidx && (s->flags & PMinSize)) {
|
2006-06-05 07:47:09 +04:00
|
|
|
if(r->width < s->min_width + dx) {
|
|
|
|
wdiff = (s->min_width + dx) - r->width;
|
|
|
|
r->width += wdiff;
|
2006-06-05 07:02:08 +04:00
|
|
|
if((sticky & EAST) && !(sticky & WEST))
|
2006-06-05 07:47:09 +04:00
|
|
|
r->x -= wdiff;
|
2006-05-27 21:56:22 +04:00
|
|
|
}
|
2006-06-05 07:47:09 +04:00
|
|
|
if(r->height < s->min_height + dy) {
|
|
|
|
hdiff = (s->min_height + dy) - r->height;
|
|
|
|
r->height += hdiff;
|
2006-06-05 07:02:08 +04:00
|
|
|
if((sticky & SOUTH) && !(sticky & NORTH))
|
2006-06-05 07:47:09 +04:00
|
|
|
r->y -= hdiff;
|
2006-05-27 21:56:22 +04:00
|
|
|
}
|
2006-03-23 01:49:18 +03:00
|
|
|
}
|
2006-05-29 23:38:02 +04:00
|
|
|
if(!aidx && (s->flags & PMaxSize)) {
|
2006-06-05 07:47:09 +04:00
|
|
|
if(r->width > s->max_width + dx) {
|
|
|
|
wdiff = r->width - (s->max_width + dx);
|
|
|
|
r->width -= wdiff;
|
2006-06-05 07:02:08 +04:00
|
|
|
if((sticky & EAST) && !(sticky & WEST))
|
2006-06-05 07:47:09 +04:00
|
|
|
r->x += wdiff;
|
2006-05-27 21:56:22 +04:00
|
|
|
}
|
2006-06-05 07:47:09 +04:00
|
|
|
if(r->height > s->max_height + dy) {
|
|
|
|
hdiff = r->height - (s->max_height + dy);
|
|
|
|
r->height -= hdiff;
|
2006-06-05 07:02:08 +04:00
|
|
|
if((sticky & SOUTH) && !(sticky & NORTH))
|
2006-06-05 07:47:09 +04:00
|
|
|
r->y += hdiff;
|
2006-05-27 21:56:22 +04:00
|
|
|
}
|
2006-03-23 01:49:18 +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
|
|
|
|
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) {
|
2006-03-23 01:49:18 +03:00
|
|
|
/* 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-03-23 01:49:18 +03:00
|
|
|
}
|
2006-05-25 20:53:09 +04:00
|
|
|
/* client_width = base_width + i * s->width_inc for an integer i */
|
2006-06-05 07:47:09 +04:00
|
|
|
w = r->width - dx - w;
|
2006-05-27 21:56:22 +04:00
|
|
|
if(s->width_inc > 0) {
|
|
|
|
wdiff = w % s->width_inc;
|
2006-06-05 07:47:09 +04:00
|
|
|
r->width -= wdiff;
|
2006-06-05 07:02:08 +04:00
|
|
|
if((sticky & EAST) && !(sticky & WEST))
|
2006-06-05 07:47:09 +04:00
|
|
|
r->x += wdiff;
|
2006-05-27 21:56:22 +04:00
|
|
|
}
|
2006-03-23 01:49:18 +03:00
|
|
|
|
2006-06-05 07:47:09 +04:00
|
|
|
h = r->height - dy - h;
|
2006-05-27 21:56:22 +04:00
|
|
|
if(s->height_inc > 0) {
|
|
|
|
hdiff = h % s->height_inc;
|
2006-06-05 07:47:09 +04:00
|
|
|
r->height -= hdiff;
|
2006-06-05 07:02:08 +04:00
|
|
|
if((sticky & SOUTH) && !(sticky & NORTH))
|
2006-06-05 07:47:09 +04:00
|
|
|
r->y += hdiff;
|
2006-05-27 21:56:22 +04:00
|
|
|
}
|
2006-03-23 01:49:18 +03:00
|
|
|
}
|
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-04-03 00:53:56 +04:00
|
|
|
Frame *f = c->frame.data[c->sel];
|
2006-04-27 23:32:45 +04:00
|
|
|
int fidx = idx_of_frame(f);
|
2006-05-29 23:38:02 +04:00
|
|
|
int aidx = idx_of_area(f->area);
|
2006-06-05 07:02:08 +04:00
|
|
|
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;
|
2006-03-15 18:00:39 +03:00
|
|
|
f->rect = *r;
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-04-27 23:32:45 +04:00
|
|
|
if((f->area->mode != Colstack) || (f->area->sel == fidx))
|
2006-06-05 07:47:09 +04:00
|
|
|
match_sizehints(c, &c->frame.data[c->sel]->rect, aidx, stickycorner);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-03-13 12:45:30 +03:00
|
|
|
if(!ignore_xcall) {
|
2006-05-29 23:38:02 +04:00
|
|
|
if(!aidx &&
|
2006-05-10 17:24:09 +04:00
|
|
|
(c->rect.width >= rect.width) &&
|
|
|
|
(c->rect.height >= rect.height))
|
|
|
|
{
|
2006-04-24 20:23:06 +04:00
|
|
|
f->rect.x = -def.border;
|
|
|
|
f->rect.y = -height_of_bar();
|
|
|
|
}
|
2006-04-03 00:53:56 +04:00
|
|
|
if(f->area->view == view.data[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-04-27 23:32:45 +04:00
|
|
|
c->rect.x = def.border;
|
|
|
|
c->rect.y = height_of_bar();
|
|
|
|
if((f->area->sel == fidx) || (f->area->mode != Colstack)) {
|
2006-03-05 03:55:45 +03:00
|
|
|
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
|
|
|
}
|
2006-04-27 23:32:45 +04:00
|
|
|
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-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-04-03 00:53:56 +04:00
|
|
|
Frame *f = c->frame.data[c->sel];
|
2006-03-05 03:55:45 +03:00
|
|
|
Area *a = f->area;
|
2006-04-12 12:44:07 +04:00
|
|
|
int i = idx_of_frame(f);
|
2006-02-19 18:21:01 +03:00
|
|
|
if(i == -1)
|
|
|
|
return;
|
|
|
|
if(!strncmp(arg, "prev", 5)) {
|
|
|
|
if(!i)
|
2006-04-03 00:53:56 +04:00
|
|
|
i = a->frame.size - 1;
|
2006-02-19 18:21:01 +03:00
|
|
|
else
|
|
|
|
i--;
|
|
|
|
} else if(!strncmp(arg, "next", 5)) {
|
2006-04-03 00:53:56 +04:00
|
|
|
if(i + 1 < a->frame.size)
|
2006-02-19 18:21:01 +03:00
|
|
|
i++;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
}
|
2006-02-13 12:31:38 +03:00
|
|
|
else {
|
2006-05-29 14:48:21 +04:00
|
|
|
if(sscanf(arg, "%d", &i) != 1)
|
2006-02-14 14:53:40 +03:00
|
|
|
return;
|
2006-02-13 12:31:38 +03:00
|
|
|
}
|
2006-04-26 10:59:55 +04:00
|
|
|
focus_client(a->frame.data[i]->client, True);
|
2006-05-01 23:15:24 +04:00
|
|
|
flush_masked_events(EnterWindowMask);
|
2006-02-13 12:31:38 +03:00
|
|
|
}
|
2006-02-23 22:52:55 +03:00
|
|
|
|
2006-02-24 11:52:20 +03:00
|
|
|
void
|
2006-05-21 21:21:37 +04:00
|
|
|
newcol_client(Client *c, char *arg)
|
|
|
|
{
|
|
|
|
Frame *f = c->frame.data[c->sel];
|
|
|
|
Area *to, *a = f->area;
|
|
|
|
View *v = a->view;
|
|
|
|
int i = idx_of_area(a);
|
|
|
|
|
|
|
|
if(i < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!strncmp(arg, "prev", 5)) {
|
2006-05-31 21:13:21 +04:00
|
|
|
to = new_column(v, i, 0);
|
2006-05-21 21:21:37 +04:00
|
|
|
send_to_area(to, a, c);
|
|
|
|
}
|
|
|
|
else if(!strncmp(arg, "next", 5)) {
|
2006-05-31 21:13:21 +04:00
|
|
|
to = new_column(v, i + 1, 0);
|
2006-05-21 21:21:37 +04:00
|
|
|
send_to_area(to, a, c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
flush_masked_events(EnterWindowMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
move_client(Client *c, char *arg)
|
2006-05-26 16:16:19 +04:00
|
|
|
{
|
|
|
|
Frame *f = c->frame.data[c->sel];
|
|
|
|
XRectangle new = f->rect;
|
2006-05-29 13:18:18 +04:00
|
|
|
int x, y;
|
2006-05-26 16:16:19 +04:00
|
|
|
|
2006-05-29 13:18:18 +04:00
|
|
|
if(sscanf(arg, "%d %d", &x, &y) != 2)
|
2006-05-26 16:16:19 +04:00
|
|
|
return;
|
2006-05-29 13:18:18 +04:00
|
|
|
new.x += x;
|
|
|
|
new.y += y;
|
2006-05-26 16:16:19 +04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
Frame *f = c->frame.data[c->sel];
|
|
|
|
XRectangle new = f->rect;
|
2006-05-29 13:18:18 +04:00
|
|
|
int w, h;
|
2006-05-26 16:16:19 +04:00
|
|
|
|
2006-05-29 13:18:18 +04:00
|
|
|
if(sscanf(arg, "%d %d", &w, &h) != 2)
|
2006-05-26 16:16:19 +04:00
|
|
|
return;
|
2006-05-29 13:18:18 +04:00
|
|
|
new.width += w;
|
|
|
|
new.height += h;
|
2006-05-26 16:16:19 +04:00
|
|
|
if(idx_of_area(f->area))
|
|
|
|
resize_column(f->client, &new, nil);
|
|
|
|
else
|
|
|
|
resize_client(f->client, &new, False);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_client(Client *c, char *arg)
|
2006-03-02 19:38:15 +03:00
|
|
|
{
|
2006-04-03 00:53:56 +04:00
|
|
|
Frame *f = c->frame.data[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-05-19 19:38:45 +04:00
|
|
|
int i = idx_of_area(a), j = idx_of_frame(f);
|
2006-02-24 11:52:20 +03:00
|
|
|
|
2006-05-19 19:38:45 +04:00
|
|
|
if((i == -1) || (j == -1))
|
2006-02-24 11:52:20 +03:00
|
|
|
return;
|
2006-04-11 17:54:14 +04:00
|
|
|
|
2006-05-19 19:38:45 +04:00
|
|
|
if(i && !strncmp(arg, "prev", 5)) {
|
2006-04-12 01:01:13 +04:00
|
|
|
if(i > 1)
|
|
|
|
to = v->area.data[i - 1];
|
2006-05-21 21:21:37 +04:00
|
|
|
else if(a->frame.size > 1)
|
2006-05-31 21:13:21 +04:00
|
|
|
to = new_column(v, 1, 0);
|
2006-05-15 20:01:37 +04:00
|
|
|
else
|
2006-04-12 13:36:17 +04:00
|
|
|
return;
|
2006-05-19 19:38:45 +04:00
|
|
|
send_to_area(to, a, c);
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
2006-05-19 19:38:45 +04:00
|
|
|
else if(i && !strncmp(arg, "next", 5)) {
|
2006-04-03 00:53:56 +04:00
|
|
|
if(i < v->area.size - 1)
|
|
|
|
to = v->area.data[i + 1];
|
2006-05-21 21:21:37 +04:00
|
|
|
else if(a->frame.size > 1)
|
2006-05-31 21:13:21 +04:00
|
|
|
to = new_column(v, v->area.size, 0);
|
2006-04-12 13:36:17 +04:00
|
|
|
else
|
|
|
|
return;
|
2006-05-19 19:38:45 +04:00
|
|
|
send_to_area(to, a, c);
|
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-04-03 00:53:56 +04:00
|
|
|
to = v->area.data[0];
|
|
|
|
else if(c->revert && c->revert != v->area.data[0])
|
2006-03-11 22:50:53 +03:00
|
|
|
to = c->revert;
|
2006-03-11 22:37:29 +03:00
|
|
|
else
|
2006-04-03 00:53:56 +04:00
|
|
|
to = v->area.data[1];
|
2006-05-19 19:38:45 +04:00
|
|
|
send_to_area(to, a, c);
|
2006-03-11 22:37:29 +03:00
|
|
|
}
|
2006-05-19 19:38:45 +04:00
|
|
|
else if(i && !strncmp(arg, "up", 3)) {
|
|
|
|
if(j)
|
|
|
|
i = j - 1;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
a->frame.data[j] = a->frame.data[i];
|
|
|
|
a->frame.data[i] = f;
|
|
|
|
arrange_column(a, False);
|
|
|
|
focus_client(c, True);
|
|
|
|
}
|
|
|
|
else if(i && !strncmp(arg, "down", 5)) {
|
|
|
|
if(j + 1 < a->frame.size)
|
|
|
|
i = j + 1;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
a->frame.data[j] = a->frame.data[i];
|
|
|
|
a->frame.data[i] = f;
|
|
|
|
arrange_column(a, False);
|
|
|
|
focus_client(c, True);
|
|
|
|
}
|
|
|
|
else if(i) {
|
2006-05-29 14:48:21 +04:00
|
|
|
if(sscanf(arg, "%d", &j) != 1)
|
2006-02-24 11:52:20 +03:00
|
|
|
return;
|
2006-05-19 19:38:45 +04:00
|
|
|
to = v->area.data[j];
|
|
|
|
send_to_area(to, a, c);
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
2006-05-19 19:38:45 +04:00
|
|
|
else
|
|
|
|
return;
|
2006-05-01 23:15:24 +04:00
|
|
|
flush_masked_events(EnterWindowMask);
|
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-04-03 00:53:56 +04:00
|
|
|
for(i = 0; i < client.size; i++) {
|
|
|
|
Client *c = client.data[i];
|
|
|
|
if(c->frame.size && c->frame.data[c->sel]->area) {
|
2006-04-12 12:44:07 +04:00
|
|
|
if(idx_of_area(c->frame.data[c->sel]->area))
|
|
|
|
resize_column(c, &c->frame.data[c->sel]->rect, nil);
|
2006-04-27 13:22:20 +04:00
|
|
|
else
|
2006-04-03 00:53:56 +04:00
|
|
|
resize_client(c, &c->frame.data[c->sel]->rect, False);
|
2006-03-16 10:06:31 +03:00
|
|
|
}
|
2006-03-09 13:39:15 +03:00
|
|
|
}
|
2006-05-01 23:15:24 +04:00
|
|
|
flush_masked_events(EnterWindowMask);
|
2006-02-24 12:38:48 +03:00
|
|
|
}
|
2006-02-28 10:51:53 +03:00
|
|
|
|
2006-05-01 22:40:33 +04:00
|
|
|
/* convenience function */
|
2006-02-28 10:51:53 +03:00
|
|
|
void
|
2006-04-26 10:59:55 +04:00
|
|
|
focus(Client *c, Bool restack)
|
2006-02-28 10:51:53 +03:00
|
|
|
{
|
2006-04-03 00:53:56 +04:00
|
|
|
Frame *f = c->frame.size ? c->frame.data[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;
|
2006-04-03 00:53:56 +04:00
|
|
|
if(view.data[sel] != v)
|
2006-03-23 12:43:57 +03:00
|
|
|
focus_view(v);
|
2006-04-26 10:59:55 +04:00
|
|
|
focus_client(c, restack);
|
2006-02-28 10:51:53 +03:00
|
|
|
}
|
2006-03-07 19:22:36 +03:00
|
|
|
|
|
|
|
int
|
2006-04-12 12:44:07 +04:00
|
|
|
idx_of_client_id(unsigned short id)
|
2006-03-07 19:22:36 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-04-03 00:53:56 +04:00
|
|
|
for(i = 0; i < client.size; i++)
|
|
|
|
if(client.data[i]->id == id)
|
2006-03-07 19:22:36 +03:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2006-04-12 12:44:07 +04:00
|
|
|
|
|
|
|
Client *
|
|
|
|
client_of_win(Window w)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for(i = 0; (i < client.size) && client.data[i]; i++)
|
|
|
|
if(client.data[i]->win == w)
|
|
|
|
return client.data[i];
|
|
|
|
return nil;
|
|
|
|
}
|
2006-04-13 17:35:10 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
draw_clients()
|
|
|
|
{
|
2006-04-28 14:37:19 +04:00
|
|
|
unsigned int i;
|
|
|
|
for(i = 0; i < client.size; i++) {
|
|
|
|
Client *c = client.data[i];
|
|
|
|
if(c->frame.size && (c->frame.data[c->sel]->area->view == view.data[sel]))
|
|
|
|
draw_client(c);
|
|
|
|
}
|
2006-04-13 17:35:10 +04:00
|
|
|
}
|
|
|
|
|
2006-05-30 20:42:42 +04:00
|
|
|
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)) {
|
|
|
|
if(view.size)
|
|
|
|
apply[j++] = view.data[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");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
match_tags(Client *c, const char *prop)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
regmatch_t tmpregm;
|
|
|
|
|
2006-05-31 21:48:44 +04:00
|
|
|
for(i = 0; i < trule.size; i++) {
|
|
|
|
Rule *r = trule.data[i];
|
2006-05-30 20:42:42 +04:00
|
|
|
if(!regexec(&r->regex, prop, 1, &tmpregm, 0))
|
|
|
|
if(!strlen(c->tags) || !strncmp(c->tags, "nil", 4))
|
2006-05-31 11:51:40 +04:00
|
|
|
apply_tags(c, r->value);
|
2006-05-30 20:42:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
apply_rules(Client *c)
|
|
|
|
{
|
2006-06-02 09:13:23 +04:00
|
|
|
if(def.tagrules)
|
|
|
|
match_tags(c, c->props);
|
2006-05-30 20:42:42 +04:00
|
|
|
|
|
|
|
if(!strlen(c->tags))
|
|
|
|
apply_tags(c, "nil");
|
|
|
|
}
|