2006-10-12 18:10:57 +04: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.
|
|
|
|
*/
|
2006-10-20 12:07:55 +04:00
|
|
|
#include "wmii.h"
|
2006-10-12 18:10:57 +04:00
|
|
|
#include <assert.h>
|
2005-11-18 18:54:58 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
2007-02-09 09:13:02 +03:00
|
|
|
static void update_client_name(Client *c);
|
|
|
|
|
2007-02-10 11:09:19 +03:00
|
|
|
static char Ebadcmd[] = "bad command",
|
|
|
|
Ebadvalue[] = "bad value";
|
2006-06-27 11:14:10 +04:00
|
|
|
|
2007-02-17 20:49:22 +03:00
|
|
|
#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask | FocusChangeMask)
|
2007-02-08 06:04:18 +03:00
|
|
|
#define ButtonMask (ButtonPressMask | ButtonReleaseMask)
|
2006-03-23 16:37:54 +03:00
|
|
|
|
2007-02-09 09:06:15 +03:00
|
|
|
Client *
|
|
|
|
create_client(Window w, XWindowAttributes *wa) {
|
2007-02-12 06:17:20 +03:00
|
|
|
Client **t, *c;
|
2007-02-09 09:06:15 +03:00
|
|
|
XSetWindowAttributes fwa;
|
|
|
|
long msize;
|
|
|
|
|
2007-02-15 07:20:47 +03:00
|
|
|
c = emallocz(sizeof(Client));
|
2007-02-09 09:06:15 +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;
|
|
|
|
c->rect.height = wa->height;
|
|
|
|
c->proto = win_proto(c->win);
|
2007-02-12 06:17:20 +03:00
|
|
|
update_client_name(c);
|
|
|
|
|
|
|
|
c->fixedsize = False;
|
2007-02-09 09:06:15 +03:00
|
|
|
XGetTransientForHint(blz.dpy, c->win, &c->trans);
|
|
|
|
if(!XGetWMNormalHints(blz.dpy, c->win, &c->size, &msize) || !c->size.flags)
|
|
|
|
c->size.flags = PSize;
|
|
|
|
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;
|
2007-02-15 10:43:33 +03:00
|
|
|
if(c->rect.width == screen->rect.width
|
|
|
|
&& c->rect.height == screen->rect.height)
|
|
|
|
c->fullscreen = True;
|
2007-02-12 06:17:20 +03:00
|
|
|
|
|
|
|
XSetWindowBorderWidth(blz.dpy, c->win, 0);
|
2007-02-09 09:06:15 +03:00
|
|
|
XAddToSaveSet(blz.dpy, c->win);
|
|
|
|
fwa.override_redirect = 1;
|
|
|
|
fwa.background_pixmap = ParentRelative;
|
2007-02-12 06:17:20 +03:00
|
|
|
fwa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
|
|
|
|
| ExposureMask | PointerMotionMask | KeyPressMask
|
|
|
|
| ButtonPressMask | ButtonReleaseMask;
|
|
|
|
c->framewin = XCreateWindow(
|
|
|
|
/* display */ blz.dpy,
|
|
|
|
/* parent */ blz.root,
|
|
|
|
/* x */ c->rect.x,
|
|
|
|
/* y */ c->rect.y,
|
|
|
|
/* width */ c->rect.width + 2 * def.border,
|
|
|
|
/* height */ c->rect.height + def.border + labelh(&def.font),
|
|
|
|
/* border */ 0,
|
|
|
|
/* depth */ DefaultDepth(blz.dpy, blz.screen),
|
|
|
|
/* class */ CopyFromParent,
|
|
|
|
/* visual */ DefaultVisual(blz.dpy, blz.screen),
|
2007-02-12 07:24:11 +03:00
|
|
|
/* valuemask */ CWOverrideRedirect | CWEventMask | CWBackPixmap,
|
2007-02-12 06:17:20 +03:00
|
|
|
/* attributes */&fwa
|
|
|
|
);
|
2007-02-09 09:06:15 +03:00
|
|
|
c->gc = XCreateGC(blz.dpy, c->framewin, 0, 0);
|
|
|
|
XSync(blz.dpy, False);
|
2007-02-12 06:17:20 +03:00
|
|
|
|
|
|
|
for(t=&client ;; t=&(*t)->next)
|
|
|
|
if(!*t) {
|
|
|
|
c->next = *t;
|
|
|
|
*t = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-02-09 09:06:15 +03:00
|
|
|
write_event("CreateClient 0x%x\n", c->win);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
manage_client(Client *c) {
|
|
|
|
XTextProperty tags;
|
|
|
|
Client *trans;
|
|
|
|
|
|
|
|
tags.nitems = 0;
|
|
|
|
XGetTextProperty(blz.dpy, c->win, &tags, tags_atom);
|
2007-02-12 06:17:20 +03:00
|
|
|
if((c->trans) && (trans = client_of_win(c->trans)))
|
2007-02-09 09:06:15 +03:00
|
|
|
strncpy(c->tags, trans->tags, sizeof(c->tags));
|
|
|
|
else if(tags.nitems)
|
|
|
|
strncpy(c->tags, (char *)tags.value, sizeof(c->tags));
|
|
|
|
XFree(tags.value);
|
2007-02-11 11:02:00 +03:00
|
|
|
|
2007-02-17 20:49:22 +03:00
|
|
|
gravitate_client(c, False);
|
|
|
|
reparent_client(c, c->framewin, def.border, labelh(&def.font));
|
2007-02-12 06:17:20 +03:00
|
|
|
|
2007-02-09 09:06:15 +03:00
|
|
|
if(!strlen(c->tags))
|
|
|
|
apply_rules(c);
|
2007-02-11 11:02:00 +03:00
|
|
|
else
|
|
|
|
apply_tags(c, c->tags);
|
|
|
|
|
2007-02-09 09:06:15 +03:00
|
|
|
if(!starting)
|
|
|
|
update_views();
|
|
|
|
XSync(blz.dpy, False);
|
2007-02-12 06:17:20 +03:00
|
|
|
|
2007-02-09 09:06:15 +03:00
|
|
|
if(c->sel->area->view == screen->sel)
|
2007-02-11 04:09:11 +03:00
|
|
|
focus(c, True);
|
2007-02-09 09:06:15 +03:00
|
|
|
flush_masked_events(EnterWindowMask);
|
|
|
|
}
|
|
|
|
|
2006-06-28 06:16:14 +04:00
|
|
|
Client *
|
2006-10-12 18:10:57 +04:00
|
|
|
sel_client() {
|
2007-02-12 06:17:20 +03:00
|
|
|
if(screen->sel && screen->sel->sel->sel)
|
|
|
|
return screen->sel->sel->sel->client;
|
|
|
|
return nil;
|
2006-06-28 06:16:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Client *
|
2006-10-12 18:10:57 +04:00
|
|
|
client_of_win(Window w) {
|
2006-06-28 06:16:14 +04:00
|
|
|
Client *c;
|
2007-02-12 06:17:20 +03:00
|
|
|
for(c=client; c; c=c->next)
|
|
|
|
if(c->win == w) break;
|
2006-06-28 06:16:14 +04:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2006-06-28 10:20:17 +04:00
|
|
|
Frame *
|
2006-10-12 18:10:57 +04:00
|
|
|
frame_of_win(Window w) {
|
2006-06-28 10:20:17 +04:00
|
|
|
Client *c;
|
2007-02-12 06:17:20 +03:00
|
|
|
for(c=client; c; c=c->next)
|
|
|
|
if(c->framewin == w) break;
|
|
|
|
if(c)
|
|
|
|
return c->frame;
|
|
|
|
return nil;
|
2006-06-28 10:20:17 +04:00
|
|
|
}
|
|
|
|
|
2006-04-24 00:33:09 +04:00
|
|
|
static void
|
2006-10-12 18:10:57 +04:00
|
|
|
update_client_name(Client *c) {
|
2006-04-24 00:33:09 +04:00
|
|
|
XTextProperty name;
|
2006-05-30 18:32:28 +04:00
|
|
|
XClassHint ch;
|
2006-04-25 15:33:30 +04:00
|
|
|
int n;
|
2007-02-05 05:02:05 +03:00
|
|
|
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-07-03 20:41:14 +04:00
|
|
|
XGetTextProperty(blz.dpy, c->win, &name, net_atom[NetWMName]);
|
2006-05-10 15:38:01 +04:00
|
|
|
if(!name.nitems)
|
2006-07-03 20:41:14 +04:00
|
|
|
XGetWMName(blz.dpy, c->win, &name);
|
2006-04-25 15:33:30 +04:00
|
|
|
if(!name.nitems)
|
|
|
|
return;
|
|
|
|
if(name.encoding == XA_STRING)
|
2006-10-12 18:10:57 +04:00
|
|
|
strncpy(c->name, (char *)name.value, sizeof(c->name));
|
2006-04-25 15:33:30 +04:00
|
|
|
else {
|
2006-07-03 20:41:14 +04:00
|
|
|
if(XmbTextPropertyToTextList(blz.dpy, &name, &list, &n) >= Success
|
2006-05-10 15:38:01 +04:00
|
|
|
&& n > 0 && *list)
|
2006-04-24 18:03:37 +04:00
|
|
|
{
|
2006-10-12 18:10:57 +04:00
|
|
|
strncpy(c->name, *list, sizeof(c->name));
|
2006-04-24 18:03:37 +04:00
|
|
|
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-07-03 20:41:14 +04:00
|
|
|
if(XGetClassHint(blz.dpy, c->win, &ch)) {
|
2007-02-12 06:17:20 +03:00
|
|
|
snprintf(c->props, sizeof(c->props),
|
|
|
|
"%s:%s:%s",
|
|
|
|
str_nil(ch.res_class),
|
|
|
|
str_nil(ch.res_name),
|
2006-05-30 18:32:28 +04:00
|
|
|
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
|
|
|
}
|
2007-02-12 06:17:20 +03:00
|
|
|
|
2007-02-10 05:19:26 +03:00
|
|
|
void
|
|
|
|
update_client_grab(Client *c) {
|
2007-02-10 05:29:21 +03:00
|
|
|
Frame *f;
|
|
|
|
f = c->sel;
|
2007-02-17 20:49:22 +03:00
|
|
|
if((f->client != sel_client())
|
|
|
|
|| (f->area->floating && f != f->area->stack)) {
|
|
|
|
if(verbose)
|
|
|
|
fprintf(stderr, "update_client_grab(%p) AnyButton => %s\n", c, str_nil(c->name));
|
|
|
|
grab_button(c->framewin, AnyButton, AnyModifier);
|
|
|
|
}else {
|
|
|
|
if(verbose)
|
|
|
|
fprintf(stderr, "update_client_grab(%p) def.mod => %s\n", c, str_nil(c->name));
|
2007-02-10 05:19:26 +03:00
|
|
|
XUngrabButton(blz.dpy, AnyButton, AnyModifier, c->framewin);
|
|
|
|
grab_button(c->framewin, Button1, def.mod);
|
|
|
|
grab_button(c->framewin, Button3, def.mod);
|
|
|
|
}
|
|
|
|
}
|
2006-04-24 00:33:09 +04:00
|
|
|
|
2007-02-10 10:13:29 +03:00
|
|
|
/* convenience function */
|
|
|
|
void
|
|
|
|
focus(Client *c, Bool restack) {
|
|
|
|
View *v;
|
|
|
|
Frame *f;
|
|
|
|
|
|
|
|
if(!(f = c->sel)) return;
|
|
|
|
v = f->area->view;
|
|
|
|
arrange_column(f->area, False);
|
|
|
|
focus_view(screen, v);
|
2007-02-11 04:09:11 +03:00
|
|
|
focus_frame(c->sel, restack);
|
2006-01-19 17:02:18 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 06:06:07 +03:00
|
|
|
void
|
|
|
|
set_client_state(Client * c, int state)
|
|
|
|
{
|
|
|
|
long data[] = { state, None };
|
2007-02-12 06:17:20 +03:00
|
|
|
XChangeProperty(
|
|
|
|
/* display */ blz.dpy,
|
|
|
|
/* parent */ c->win,
|
|
|
|
/* property */ wm_atom[WMState],
|
|
|
|
/* type */ wm_atom[WMState],
|
|
|
|
/* format */ 32,
|
|
|
|
/* mode */ PropModeReplace,
|
2007-02-12 09:24:24 +03:00
|
|
|
/* data */ (uchar *) data,
|
2007-02-12 06:17:20 +03:00
|
|
|
/* npositions */2
|
|
|
|
);
|
2007-02-10 06:06:07 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
map_client(Client *c) {
|
2007-02-10 10:44:57 +03:00
|
|
|
if(!c->mapped) {
|
|
|
|
XSelectInput(blz.dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
|
|
|
XMapWindow(blz.dpy, c->win);
|
|
|
|
XSelectInput(blz.dpy, c->win, CLIENT_MASK);
|
|
|
|
}
|
2007-01-28 15:26:01 +03:00
|
|
|
set_client_state(c, NormalState);
|
2007-02-10 06:06:07 +03:00
|
|
|
c->mapped = 1;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2007-02-10 06:06:07 +03:00
|
|
|
unmap_client(Client *c, int state) {
|
2007-02-10 10:44:57 +03:00
|
|
|
if(c->mapped) {
|
|
|
|
XSelectInput(blz.dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
|
|
|
XUnmapWindow(blz.dpy, c->win);
|
|
|
|
XSelectInput(blz.dpy, c->win, CLIENT_MASK);
|
|
|
|
/* Always set this, since we don't care anymore once it's been destroyed */
|
|
|
|
c->unmapped++;
|
|
|
|
}
|
2007-02-10 06:06:07 +03:00
|
|
|
set_client_state(c, state);
|
|
|
|
c->mapped = 0;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2007-02-11 09:09:00 +03:00
|
|
|
void
|
|
|
|
map_frame(Client *c) {
|
|
|
|
if(!c->frame_mapped) {
|
|
|
|
XMapWindow(blz.dpy, c->framewin);
|
|
|
|
c->frame_mapped = True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
unmap_frame(Client *c) {
|
|
|
|
if(c->frame_mapped) {
|
|
|
|
XUnmapWindow(blz.dpy, c->framewin);
|
|
|
|
c->frame_mapped = False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
reparent_client(Client *c, Window w, int x, int y) {
|
2006-07-03 20:41:14 +04:00
|
|
|
XSelectInput(blz.dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
|
|
|
XReparentWindow(blz.dpy, c->win, w, x, y);
|
|
|
|
XSelectInput(blz.dpy, c->win, CLIENT_MASK);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
configure_client(Client *c) {
|
2006-03-23 01:49:18 +03:00
|
|
|
XConfigureEvent e;
|
2007-02-15 07:20:47 +03:00
|
|
|
Frame *f;
|
|
|
|
|
|
|
|
f = c->sel;
|
|
|
|
if(!f)
|
|
|
|
return;
|
2006-10-12 18:10:57 +04:00
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
e.type = ConfigureNotify;
|
|
|
|
e.event = c->win;
|
|
|
|
e.window = c->win;
|
2007-02-15 07:20:47 +03:00
|
|
|
e.x = f->crect.x + f->rect.x - c->border;
|
|
|
|
e.y = f->crect.y + f->rect.y - c->border;
|
|
|
|
e.width = f->crect.width;
|
|
|
|
e.height = f->crect.height;
|
2006-03-23 01:49:18 +03:00
|
|
|
e.border_width = c->border;
|
|
|
|
e.above = None;
|
|
|
|
e.override_redirect = False;
|
2006-07-12 16:14:23 +04:00
|
|
|
XSendEvent(blz.dpy, c->win, False,
|
|
|
|
StructureNotifyMask, (XEvent *) & e);
|
2006-07-03 20:41:14 +04:00
|
|
|
XSync(blz.dpy, False);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-07-11 18:15:01 +04:00
|
|
|
static void
|
2006-10-12 18:10:57 +04:00
|
|
|
send_client_message(Window w, Atom a, long value) {
|
2006-07-11 18:15:01 +04:00
|
|
|
XEvent e;
|
2006-10-12 18:10:57 +04:00
|
|
|
|
2006-07-11 18:15:01 +04:00
|
|
|
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.dpy, w, False, NoEventMask, &e);
|
|
|
|
XSync(blz.dpy, False);
|
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
kill_client(Client * c) {
|
2006-07-11 18:15:01 +04:00
|
|
|
if(c->proto & WM_PROTOCOL_DELWIN)
|
|
|
|
send_client_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
|
|
|
|
else
|
|
|
|
XKillClient(blz.dpy, c->win);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2007-02-11 08:11:10 +03:00
|
|
|
static void
|
|
|
|
set_urgent(Client *c, Bool urgent, Bool write) {
|
|
|
|
XWMHints *wmh;
|
2007-02-13 07:32:00 +03:00
|
|
|
char *cwrite, *cnot;
|
2007-02-13 07:35:43 +03:00
|
|
|
Frame *f, *ff;
|
|
|
|
Area *a;
|
2007-02-11 08:11:10 +03:00
|
|
|
|
2007-02-13 06:44:42 +03:00
|
|
|
cwrite = "Client";
|
2007-02-11 08:11:10 +03:00
|
|
|
if(write)
|
2007-02-13 06:44:42 +03:00
|
|
|
cwrite = "Manager";
|
2007-02-13 07:32:00 +03:00
|
|
|
cnot = "Not";
|
|
|
|
if(urgent)
|
|
|
|
cnot = "";
|
2007-02-11 08:11:10 +03:00
|
|
|
|
|
|
|
if(urgent != c->urgent) {
|
2007-02-13 07:32:00 +03:00
|
|
|
write_event("%sUrgent 0x%x %s\n", cnot, client->win, cwrite);
|
2007-02-11 08:11:10 +03:00
|
|
|
c->urgent = urgent;
|
2007-02-13 07:32:00 +03:00
|
|
|
if(c->sel) {
|
|
|
|
if(c->sel->view == screen->sel) {
|
|
|
|
update_frame_widget_colors(c->sel);
|
|
|
|
draw_frame(c->sel);
|
|
|
|
}
|
|
|
|
if(!urgent || c->sel->view != screen->sel)
|
2007-02-13 07:35:43 +03:00
|
|
|
for(f=c->frame; f; f=f->cnext) {
|
|
|
|
for(a=f->view->area; a; a=a->next)
|
|
|
|
for(ff=a->frame; ff; ff=ff->anext)
|
2007-02-13 09:10:43 +03:00
|
|
|
if(ff->client->urgent) break;
|
2007-02-13 07:35:43 +03:00
|
|
|
if(!ff)
|
|
|
|
write_event("%sUrgentTag %s %s\n", cnot, cwrite, f->view->name);
|
|
|
|
}
|
2007-02-11 08:11:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(write) {
|
|
|
|
wmh = XGetWMHints(blz.dpy, c->win);
|
2007-02-12 06:17:20 +03:00
|
|
|
if(wmh) {
|
|
|
|
if(urgent)
|
|
|
|
wmh->flags |= XUrgencyHint;
|
|
|
|
else
|
|
|
|
wmh->flags &= ~XUrgencyHint;
|
|
|
|
XSetWMHints(blz.dpy, c->win, wmh);
|
|
|
|
XFree(wmh);
|
|
|
|
}
|
2007-02-11 08:11:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
prop_client(Client *c, XPropertyEvent *e) {
|
2007-02-09 05:50:49 +03:00
|
|
|
XWMHints *wmh;
|
2006-03-23 01:49:18 +03:00
|
|
|
long msize;
|
|
|
|
|
2006-07-11 18:15:01 +04:00
|
|
|
if(e->atom == wm_atom[WMProtocols]) {
|
|
|
|
c->proto = win_proto(c->win);
|
|
|
|
return;
|
|
|
|
}
|
2006-03-23 01:49:18 +03:00
|
|
|
switch (e->atom) {
|
|
|
|
case XA_WM_TRANSIENT_FOR:
|
2006-07-03 20:41:14 +04:00
|
|
|
XGetTransientForHint(blz.dpy, c->win, &c->trans);
|
2006-03-23 01:49:18 +03:00
|
|
|
break;
|
|
|
|
case XA_WM_NORMAL_HINTS:
|
2006-07-03 20:41:14 +04:00
|
|
|
if(!XGetWMNormalHints(blz.dpy, c->win, &c->size, &msize) || !c->size.flags) {
|
2006-03-23 01:49:18 +03:00
|
|
|
c->size.flags = PSize;
|
|
|
|
}
|
2007-02-12 06:17:20 +03:00
|
|
|
c->fixedsize = False;
|
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;
|
2006-03-23 01:49:18 +03:00
|
|
|
break;
|
2007-02-09 05:50:49 +03:00
|
|
|
case XA_WM_HINTS:
|
|
|
|
wmh = XGetWMHints(blz.dpy, c->win);
|
2007-02-13 06:44:42 +03:00
|
|
|
set_urgent(c, (wmh->flags & XUrgencyHint) != 0, False);
|
2007-02-11 08:11:10 +03:00
|
|
|
XFree(wmh);
|
2007-02-09 05:50:49 +03:00
|
|
|
break;
|
2006-03-23 01:49:18 +03:00
|
|
|
}
|
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);
|
2006-06-08 12:54:19 +04:00
|
|
|
if(c->frame)
|
2006-06-19 20:26:06 +04:00
|
|
|
draw_frame(c->sel);
|
2006-04-24 03:01:49 +04:00
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
gravitate_client(Client *c, Bool invert) {
|
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-10-12 18:12:22 +04:00
|
|
|
dy = labelh(&def.font);
|
2006-03-23 01:49:18 +03:00
|
|
|
break;
|
|
|
|
case EastGravity:
|
|
|
|
case CenterGravity:
|
|
|
|
case WestGravity:
|
2006-10-12 18:12:22 +04:00
|
|
|
dy = -(c->rect.height / 2) + labelh(&def.font);
|
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-03-09 22:25:50 +03:00
|
|
|
static int
|
2006-10-12 18:10:57 +04:00
|
|
|
dummy_error_handler(Display *dpy, XErrorEvent *error) {
|
2006-03-09 22:25:50 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-06 01:38:50 +03:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
destroy_client(Client *c) {
|
2007-02-05 05:02:05 +03:00
|
|
|
char *dummy = nil;
|
2006-06-10 03:57:00 +04:00
|
|
|
Client **tc;
|
2006-03-09 01:53:52 +03:00
|
|
|
|
2006-07-03 20:41:14 +04:00
|
|
|
XGrabServer(blz.dpy);
|
2006-03-09 22:25:50 +03:00
|
|
|
XSetErrorHandler(dummy_error_handler);
|
2007-02-12 06:17:20 +03:00
|
|
|
for(tc=&client; *tc; tc=&(*tc)->next)
|
|
|
|
if(*tc == c) {
|
|
|
|
*tc = c->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-25 17:16:03 +04:00
|
|
|
update_client_views(c, &dummy);
|
2007-02-12 06:17:20 +03:00
|
|
|
|
2007-02-10 06:06:07 +03:00
|
|
|
unmap_client(c, WithdrawnState);
|
2007-02-17 20:49:22 +03:00
|
|
|
gravitate_client(c, True);
|
2006-06-22 13:03:42 +04:00
|
|
|
reparent_client(c, blz.root, c->rect.x, c->rect.y);
|
2006-07-03 20:41:14 +04:00
|
|
|
XFreeGC(blz.dpy, c->gc);
|
|
|
|
XDestroyWindow(blz.dpy, c->framewin);
|
|
|
|
XSync(blz.dpy, False);
|
2007-02-12 06:17:20 +03:00
|
|
|
|
2006-03-09 22:25:50 +03:00
|
|
|
XSetErrorHandler(wmii_error_handler);
|
2006-07-03 20:41:14 +04:00
|
|
|
XUngrabServer(blz.dpy);
|
2006-05-01 23:15:24 +04:00
|
|
|
flush_masked_events(EnterWindowMask);
|
2007-02-12 06:17:20 +03:00
|
|
|
|
2007-02-02 19:43:22 +03:00
|
|
|
write_event("DestroyClient 0x%x\n", c->win);
|
2007-02-15 07:20:47 +03:00
|
|
|
free(c);
|
2006-03-06 01:38:50 +03:00
|
|
|
}
|
|
|
|
|
2006-06-05 07:47:09 +04:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
match_sizehints(Client *c, XRectangle *r, Bool floating, BlitzAlign sticky) {
|
2006-03-23 01:49:18 +03:00
|
|
|
XSizeHints *s = &c->size;
|
2007-02-12 09:24:24 +03:00
|
|
|
uint dx = 2 * def.border;
|
|
|
|
uint dy = def.border + labelh(&def.font);
|
|
|
|
uint hdiff, wdiff;
|
2006-05-26 16:29:04 +04:00
|
|
|
|
2006-06-08 12:54:19 +04:00
|
|
|
if(floating && (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-06-08 12:54:19 +04:00
|
|
|
if(floating && (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-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-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
|
|
|
}
|
|
|
|
|
2007-02-13 21:19:01 +03:00
|
|
|
void
|
|
|
|
focus_client(Client *c) {
|
2007-02-15 08:01:56 +03:00
|
|
|
if(verbose)
|
2007-02-17 20:49:22 +03:00
|
|
|
fprintf(stderr, "focus_client(%p) => %s\n", c, (c ? c->name : nil));
|
2007-02-13 21:19:01 +03:00
|
|
|
if(screen->focus != c) {
|
2007-02-17 21:22:52 +03:00
|
|
|
if(c)
|
2007-02-17 20:49:22 +03:00
|
|
|
if(verbose)
|
|
|
|
fprintf(stderr, "\t%s => %s\n", (screen->focus ? screen->focus->name : "<nil>"),
|
|
|
|
(c ? c->name : "<nil>"));
|
2007-02-17 21:22:52 +03:00
|
|
|
if(c) {
|
2007-02-13 21:19:01 +03:00
|
|
|
XSetInputFocus(blz.dpy, c->win, RevertToParent, CurrentTime);
|
2007-02-17 21:22:52 +03:00
|
|
|
update_client_grab(c);
|
|
|
|
}else
|
2007-02-13 21:19:01 +03:00
|
|
|
XSetInputFocus(blz.dpy, screen->barwin, RevertToParent, CurrentTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
void
|
2007-02-07 05:48:28 +03:00
|
|
|
resize_client(Client *c, XRectangle *r) {
|
|
|
|
Frame *f;
|
2006-06-10 03:57:00 +04:00
|
|
|
|
2007-02-07 05:48:28 +03:00
|
|
|
f = c->sel;
|
|
|
|
resize_frame(f, r);
|
|
|
|
|
2007-02-11 09:09:00 +03:00
|
|
|
if(f->area->view == screen->sel)
|
2007-02-12 06:17:20 +03:00
|
|
|
XMoveResizeWindow(blz.dpy, c->framewin,
|
|
|
|
f->rect.x, f->rect.y,
|
|
|
|
f->rect.width, f->rect.height);
|
2007-02-10 06:06:07 +03:00
|
|
|
else {
|
|
|
|
unmap_client(c, IconicState);
|
2007-02-11 09:09:00 +03:00
|
|
|
unmap_frame(c);
|
|
|
|
return;
|
2007-02-10 06:06:07 +03:00
|
|
|
}
|
2007-02-07 05:48:28 +03:00
|
|
|
|
2007-02-17 10:20:11 +03:00
|
|
|
c->rect = f->crect;
|
|
|
|
c->rect.x += f->rect.x;
|
|
|
|
c->rect.y += f->rect.y;
|
2007-02-15 07:20:47 +03:00
|
|
|
if(f->area->mode == Colmax
|
|
|
|
&& f->area->sel != f) {
|
|
|
|
unmap_frame(c);
|
|
|
|
unmap_client(c, IconicState);
|
|
|
|
}else if(f->collapsed) {
|
|
|
|
map_frame(c);
|
|
|
|
unmap_client(c, IconicState);
|
|
|
|
}else {
|
2007-02-12 06:17:20 +03:00
|
|
|
XMoveResizeWindow(blz.dpy, c->win,
|
2007-02-15 10:43:33 +03:00
|
|
|
f->crect.x, f->crect.y,
|
|
|
|
f->crect.width, f->crect.height);
|
2007-02-11 09:09:00 +03:00
|
|
|
map_client(c);
|
|
|
|
map_frame(c);
|
2007-02-15 10:43:33 +03:00
|
|
|
configure_client(c);
|
2007-02-11 09:09:00 +03:00
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
2006-02-24 11:52:20 +03:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
newcol_client(Client *c, char *arg) {
|
2006-06-08 12:54:19 +04:00
|
|
|
Frame *f = c->sel;
|
2006-05-21 21:21:37 +04:00
|
|
|
Area *to, *a = f->area;
|
|
|
|
View *v = a->view;
|
|
|
|
|
2006-06-24 05:22:04 +04:00
|
|
|
if(a->floating)
|
2006-06-08 12:54:19 +04:00
|
|
|
return;
|
|
|
|
if(!f->anext && f == a->frame)
|
2006-05-21 21:21:37 +04:00
|
|
|
return;
|
|
|
|
if(!strncmp(arg, "prev", 5)) {
|
2007-02-12 06:17:20 +03:00
|
|
|
for(to=v->area; to; to=to->next)
|
|
|
|
if(to->next == a) break;
|
2006-06-08 12:54:19 +04:00
|
|
|
to = new_column(v, to, 0);
|
2007-02-15 07:20:47 +03:00
|
|
|
send_to_area(to, f);
|
2006-05-21 21:21:37 +04:00
|
|
|
}
|
|
|
|
else if(!strncmp(arg, "next", 5)) {
|
2006-06-08 12:54:19 +04:00
|
|
|
to = new_column(v, a, 0);
|
2007-02-15 07:20:47 +03:00
|
|
|
send_to_area(to, f);
|
2006-05-21 21:21:37 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
flush_masked_events(EnterWindowMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
move_client(Client *c, char *arg) {
|
2006-06-08 12:54:19 +04:00
|
|
|
Frame *f = c->sel;
|
2006-05-26 16:16:19 +04:00
|
|
|
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-06-28 06:16:14 +04:00
|
|
|
if(!f->area->floating)
|
2007-02-05 09:00:42 +03:00
|
|
|
resize_column(f->client, &new);
|
2006-05-26 16:16:19 +04:00
|
|
|
else
|
2007-02-07 05:48:28 +03:00
|
|
|
resize_client(f->client, &new);
|
2006-05-26 16:16:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
size_client(Client *c, char *arg) {
|
2006-06-08 12:54:19 +04:00
|
|
|
Frame *f = c->sel;
|
2006-05-26 16:16:19 +04:00
|
|
|
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-06-24 05:22:04 +04:00
|
|
|
if(!f->area->floating)
|
2007-02-05 09:00:42 +03:00
|
|
|
resize_column(f->client, &new);
|
2006-05-26 16:16:19 +04:00
|
|
|
else
|
2007-02-07 05:48:28 +03:00
|
|
|
resize_client(f->client, &new);
|
2006-05-26 16:16:19 +04:00
|
|
|
}
|
|
|
|
|
2006-06-19 12:38:21 +04:00
|
|
|
char *
|
2007-02-13 09:10:43 +03:00
|
|
|
send_client(Frame *f, char *arg, Bool swap) {
|
2006-06-19 00:58:10 +04:00
|
|
|
Area *to, *a;
|
|
|
|
Client *c;
|
|
|
|
Frame *tf;
|
|
|
|
View *v;
|
2007-02-13 20:04:42 +03:00
|
|
|
Bool before;
|
2006-06-28 06:16:14 +04:00
|
|
|
int j;
|
2006-06-20 02:25:49 +04:00
|
|
|
|
2006-06-19 00:58:10 +04:00
|
|
|
a = f->area;
|
|
|
|
v = a->view;
|
|
|
|
c = f->client;
|
2006-06-28 06:16:14 +04:00
|
|
|
if(!strncmp(arg, "toggle", 7)) {
|
2006-06-24 05:22:04 +04:00
|
|
|
if(!a->floating)
|
2006-06-08 12:54:19 +04:00
|
|
|
to = v->area;
|
2006-06-24 05:22:04 +04:00
|
|
|
else if(c->revert && !c->revert->floating)
|
2006-03-11 22:50:53 +03:00
|
|
|
to = c->revert;
|
2006-03-11 22:37:29 +03:00
|
|
|
else
|
2006-06-08 12:54:19 +04:00
|
|
|
to = v->area->next;
|
2007-02-13 09:10:43 +03:00
|
|
|
goto send_area;
|
2006-06-28 06:16:14 +04:00
|
|
|
}else if(!a->floating) {
|
|
|
|
if(!strncmp(arg, "left", 5)) {
|
|
|
|
if(a->floating)
|
|
|
|
return Ebadvalue;
|
2007-02-12 06:17:20 +03:00
|
|
|
for(to=v->area->next; to; to=to->next)
|
|
|
|
if(a == to->next) break;
|
2006-06-28 06:16:14 +04:00
|
|
|
if(!to && (f->anext || f != a->frame))
|
2007-02-12 06:17:20 +03:00
|
|
|
to=new_column(v, v->area, 0);
|
2007-02-13 09:10:43 +03:00
|
|
|
goto send_area;
|
2006-06-28 06:16:14 +04:00
|
|
|
}
|
|
|
|
else if(!strncmp(arg, "right", 5)) {
|
|
|
|
if(a->floating)
|
|
|
|
return Ebadvalue;
|
2007-02-12 06:17:20 +03:00
|
|
|
if(!(to = a->next) && (f->anext || f != a->frame))
|
2006-06-28 06:16:14 +04:00
|
|
|
to = new_column(v, a, 0);
|
2007-02-13 09:10:43 +03:00
|
|
|
goto send_area;
|
2006-06-28 06:16:14 +04:00
|
|
|
}
|
|
|
|
else if(!strncmp(arg, "up", 3)) {
|
2007-02-12 06:17:20 +03:00
|
|
|
for(tf=a->frame; tf; tf=tf->anext)
|
|
|
|
if(tf->anext == f) break;
|
2007-02-13 20:04:42 +03:00
|
|
|
before = True;
|
2007-02-13 09:10:43 +03:00
|
|
|
goto send_frame;
|
2006-06-28 06:16:14 +04:00
|
|
|
}
|
|
|
|
else if(!strncmp(arg, "down", 5)) {
|
2007-02-13 09:10:43 +03:00
|
|
|
tf = f->anext;
|
2007-02-13 20:04:42 +03:00
|
|
|
before = False;
|
2007-02-13 09:10:43 +03:00
|
|
|
goto send_frame;
|
2006-06-28 06:16:14 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(sscanf(arg, "%d", &j) != 1)
|
|
|
|
return Ebadvalue;
|
2007-02-10 11:09:19 +03:00
|
|
|
for(to=v->area; to; to=to->next)
|
|
|
|
if(!--j) break;
|
2007-02-13 09:10:43 +03:00
|
|
|
goto send_area;
|
2006-06-28 06:16:14 +04:00
|
|
|
}
|
2007-02-13 09:20:09 +03:00
|
|
|
}
|
|
|
|
return Ebadvalue;
|
|
|
|
|
2007-02-13 09:10:43 +03:00
|
|
|
send_frame:
|
2007-02-13 20:04:42 +03:00
|
|
|
if(!tf)
|
|
|
|
return Ebadvalue;
|
2007-02-13 09:10:43 +03:00
|
|
|
if(!swap) {
|
|
|
|
remove_frame(f);
|
2007-02-13 22:58:18 +03:00
|
|
|
insert_frame(tf, f, before);
|
2007-02-13 09:10:43 +03:00
|
|
|
}else
|
|
|
|
swap_frames(f, tf);
|
|
|
|
arrange_column(a, False);
|
|
|
|
|
|
|
|
flush_masked_events(EnterWindowMask);
|
|
|
|
focus_frame(f, True);
|
|
|
|
update_views();
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
send_area:
|
2007-02-13 20:04:42 +03:00
|
|
|
if(!to)
|
|
|
|
return Ebadvalue;
|
2007-02-13 09:10:43 +03:00
|
|
|
if(!swap)
|
2007-02-15 07:20:47 +03:00
|
|
|
send_to_area(to, f);
|
2007-02-13 09:10:43 +03:00
|
|
|
else if(to->sel)
|
|
|
|
swap_frames(f, to->sel);
|
|
|
|
|
2006-05-01 23:15:24 +04:00
|
|
|
flush_masked_events(EnterWindowMask);
|
2007-02-11 04:09:11 +03:00
|
|
|
focus_frame(f, True);
|
2006-06-25 17:16:03 +04:00
|
|
|
update_views();
|
2007-02-05 05:02:05 +03:00
|
|
|
return nil;
|
2006-02-24 11:52:20 +03:00
|
|
|
}
|
2006-02-24 12:38:48 +03:00
|
|
|
|
2006-06-25 17:16:03 +04:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
update_client_views(Client *c, char **tags) {
|
2006-06-25 17:16:03 +04:00
|
|
|
int cmp;
|
|
|
|
Frame *f;
|
|
|
|
Frame **fp = &c->frame;
|
2006-10-12 18:10:57 +04:00
|
|
|
|
2006-06-25 17:16:03 +04:00
|
|
|
while(*fp || *tags) {
|
2007-02-12 06:17:20 +03:00
|
|
|
while(*fp) {
|
|
|
|
if(*tags) {
|
|
|
|
cmp = strcmp((*fp)->view->name, *tags);
|
|
|
|
if(cmp >= 0)
|
|
|
|
break;
|
|
|
|
}
|
2006-06-25 17:16:03 +04:00
|
|
|
f = *fp;
|
2007-02-15 07:20:47 +03:00
|
|
|
detach_from_area(f);
|
2006-06-25 17:16:03 +04:00
|
|
|
*fp = f->cnext;
|
|
|
|
free(f);
|
|
|
|
if(c->sel == f)
|
|
|
|
c->sel = *fp;
|
|
|
|
}
|
|
|
|
if(*tags) {
|
|
|
|
if(!*fp || cmp > 0) {
|
|
|
|
f = create_frame(c, get_view(*tags));
|
2006-06-30 04:02:52 +04:00
|
|
|
if(f->view == screen->sel || !c->sel)
|
2006-06-25 17:16:03 +04:00
|
|
|
c->sel = f;
|
|
|
|
attach_to_view(f->view, f);
|
|
|
|
f->cnext = *fp;
|
|
|
|
*fp = f;
|
|
|
|
}
|
|
|
|
if(*fp) fp=&(*fp)->cnext;
|
|
|
|
tags++;
|
|
|
|
}
|
|
|
|
}
|
2007-02-12 06:17:20 +03:00
|
|
|
update_views();
|
2006-05-30 20:42:42 +04:00
|
|
|
}
|
|
|
|
|
2006-06-27 11:14:10 +04:00
|
|
|
static int
|
|
|
|
compare_tags(const void *a, const void *b) {
|
|
|
|
return strcmp(*(char **)a, *(char **)b);
|
|
|
|
}
|
|
|
|
|
2006-05-30 20:42:42 +04:00
|
|
|
void
|
2006-10-12 18:10:57 +04:00
|
|
|
apply_tags(Client *c, const char *tags) {
|
2007-02-12 09:24:24 +03:00
|
|
|
uint i, j, k, n;
|
2007-02-12 06:17:20 +03:00
|
|
|
Bool add;
|
|
|
|
char buf[512], last;
|
|
|
|
char *toks[32], *cur;
|
|
|
|
|
|
|
|
buf[0] = 0;
|
|
|
|
for(n = 0; tags[n]; n++)
|
|
|
|
if(tags[n] != ' ' && tags[n] != '\t') break;
|
|
|
|
if(tags[n] == '+' || tags[n] == '-')
|
|
|
|
strncpy(buf, c->tags, sizeof(c->tags));
|
2007-02-17 10:20:11 +03:00
|
|
|
ixp_strlcat(buf, &tags[n], sizeof(buf));
|
2007-01-04 04:22:07 +03:00
|
|
|
trim(buf, " \t/");
|
2007-02-12 06:17:20 +03:00
|
|
|
|
|
|
|
n = 0;
|
|
|
|
j = 0;
|
|
|
|
add = True;
|
|
|
|
if(buf[0] == '+')
|
|
|
|
n++;
|
|
|
|
else if(buf[0] == '-') {
|
|
|
|
n++;
|
|
|
|
add = False;
|
|
|
|
}
|
|
|
|
while(buf[n] && n < sizeof(buf) && j < 32) {
|
|
|
|
for(i = n; i < sizeof(buf) - 1; i++)
|
|
|
|
if(buf[i] == '+'
|
|
|
|
|| buf[i] == '-'
|
|
|
|
|| buf[i] == '\0')
|
|
|
|
break;
|
|
|
|
last = buf[i];
|
|
|
|
buf[i] = '\0';
|
|
|
|
|
|
|
|
cur = nil;
|
|
|
|
if(!strncmp(&buf[n], "~", 2))
|
|
|
|
c->floating = add;
|
|
|
|
else if(!strncmp(&buf[n], "!", 2))
|
|
|
|
cur = view ? screen->sel->name : "nil";
|
|
|
|
else if(strncmp(&buf[n], "sel", 4)
|
|
|
|
&& strncmp(&buf[n], ".", 2)
|
|
|
|
&& strncmp(&buf[n], "..", 3))
|
|
|
|
cur = &buf[n];
|
|
|
|
|
|
|
|
n = i + 1;
|
|
|
|
if(cur) {
|
|
|
|
if(add)
|
|
|
|
toks[j++] = cur;
|
|
|
|
else {
|
|
|
|
for(i = 0, k = 0; i < j; i++)
|
|
|
|
if(strcmp(toks[i], cur))
|
|
|
|
toks[k++] = toks[i];
|
|
|
|
j = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(last) {
|
|
|
|
case '+':
|
|
|
|
add = True;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
add = False;
|
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
buf[n] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
2006-06-25 17:16:03 +04:00
|
|
|
}
|
|
|
|
c->tags[0] = '\0';
|
2006-06-26 23:45:59 +04:00
|
|
|
qsort(toks, j, sizeof(char *), compare_tags);
|
2007-01-04 04:22:07 +03:00
|
|
|
if(!j) return;
|
2007-02-17 10:20:11 +03:00
|
|
|
for(i=0, n=0; i < j; i++)
|
2006-06-25 17:16:03 +04:00
|
|
|
if(!n || strcmp(toks[i], toks[n-1])) {
|
2006-12-23 22:09:55 +03:00
|
|
|
if(i)
|
2007-02-17 10:20:11 +03:00
|
|
|
ixp_strlcat(c->tags, "+", sizeof(c->tags));
|
|
|
|
ixp_strlcat(c->tags, toks[i], sizeof(c->tags));
|
2006-06-25 17:16:03 +04:00
|
|
|
toks[n++] = toks[i];
|
2006-05-30 20:42:42 +04:00
|
|
|
}
|
2007-02-05 05:02:05 +03:00
|
|
|
toks[n] = nil;
|
2006-06-25 17:16:03 +04:00
|
|
|
update_client_views(c, toks);
|
2006-07-03 20:41:14 +04:00
|
|
|
XChangeProperty(blz.dpy, c->win, tags_atom, XA_STRING, 8,
|
2007-02-12 09:24:24 +03:00
|
|
|
PropModeReplace, (uchar *)c->tags, strlen(c->tags));
|
2006-05-30 20:42:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-10-12 18:10:57 +04:00
|
|
|
match_tags(Client *c, const char *prop) {
|
2006-06-08 12:54:19 +04:00
|
|
|
Rule *r;
|
2006-05-30 20:42:42 +04:00
|
|
|
regmatch_t tmpregm;
|
|
|
|
|
2006-06-17 15:32:49 +04:00
|
|
|
for(r=def.tagrules.rule; r; r=r->next)
|
2006-05-30 20:42:42 +04:00
|
|
|
if(!regexec(&r->regex, prop, 1, &tmpregm, 0))
|
2007-02-05 05:02:05 +03:00
|
|
|
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
|
2006-10-12 18:10:57 +04:00
|
|
|
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);
|
2006-05-30 20:42:42 +04:00
|
|
|
if(!strlen(c->tags))
|
2007-02-05 05:02:05 +03:00
|
|
|
apply_tags(c, "nil");
|
2006-05-30 20:42:42 +04:00
|
|
|
}
|
2006-06-19 18:05:02 +04:00
|
|
|
|
|
|
|
char *
|
2006-10-12 18:10:57 +04:00
|
|
|
message_client(Client *c, char *message) {
|
2007-02-11 08:11:10 +03:00
|
|
|
if(!strncmp(message, "kill", 5))
|
2006-06-19 18:05:02 +04:00
|
|
|
kill_client(c);
|
2007-02-11 20:33:05 +03:00
|
|
|
else if(!strncmp(message, "Urgent", 7))
|
2007-02-11 08:11:10 +03:00
|
|
|
set_urgent(c, True, True);
|
2007-02-11 20:33:05 +03:00
|
|
|
else if(!strncmp(message, "NotUrgent", 10))
|
2007-02-11 08:11:10 +03:00
|
|
|
set_urgent(c, False, True);
|
|
|
|
else
|
|
|
|
return Ebadcmd;
|
|
|
|
return nil;
|
2006-06-19 18:05:02 +04:00
|
|
|
}
|