2005-11-18 18:54:58 +03:00
|
|
|
/*
|
2006-01-20 17:20:24 +03:00
|
|
|
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
2005-11-18 18:54:58 +03:00
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
static void handle_before_read_client(IXPServer * s, File * file);
|
|
|
|
static void handle_after_write_client(IXPServer * s, File * file);
|
|
|
|
|
2006-01-26 20:29:49 +03:00
|
|
|
static void max_client(void *obj, char *arg);
|
|
|
|
|
|
|
|
/* action table for /?/ namespace */
|
|
|
|
Action client_acttbl[] = {
|
|
|
|
{"max", max_client},
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
Client *
|
2006-01-25 20:39:08 +03:00
|
|
|
alloc_client(Window w, XWindowAttributes *wa)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
XTextProperty name;
|
|
|
|
Client *c = (Client *) cext_emallocz(sizeof(Client));
|
2006-01-25 20:39:08 +03:00
|
|
|
XSetWindowAttributes fwa;
|
|
|
|
static int id = 1;
|
|
|
|
char buf[MAX_BUF];
|
|
|
|
int bw, th;
|
|
|
|
long msize;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
/* client itself */
|
2005-12-21 18:18:11 +03:00
|
|
|
c->win = w;
|
2006-01-25 20:39:08 +03:00
|
|
|
c->rect.x = wa->x;
|
|
|
|
c->rect.y = wa->y;
|
|
|
|
c->border = wa->border_width;
|
|
|
|
c->rect.width = wa->width + 2 * c->border;
|
|
|
|
c->rect.height = wa->height + 2 * c->border;
|
|
|
|
XSetWindowBorderWidth(dpy, c->win, 0);
|
|
|
|
c->proto = win_proto(c->win);
|
|
|
|
XGetTransientForHint(dpy, c->win, &c->trans);
|
|
|
|
if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
|
|
|
|
c->size.flags = PSize;
|
|
|
|
XAddToSaveSet(dpy, c->win);
|
2005-12-21 18:18:11 +03:00
|
|
|
XGetWMName(dpy, c->win, &name);
|
2006-01-03 12:30:15 +03:00
|
|
|
if(name.value) {
|
2006-01-04 18:28:31 +03:00
|
|
|
cext_strlcpy(c->name, (char *)name.value, sizeof(c->name));
|
2006-01-03 12:30:15 +03:00
|
|
|
free(name.value);
|
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/%d", id);
|
|
|
|
c->file[C_PREFIX] = ixp_create(ixps, buf);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/%d/name", id);
|
|
|
|
c->file[C_NAME] = ixp_create(ixps, buf);
|
|
|
|
c->file[C_NAME]->before_read = handle_before_read_client;
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/%d/border", id);
|
|
|
|
c->file[C_BORDER] =
|
|
|
|
wmii_create_ixpfile(ixps, buf, def[WM_BORDER]->content);
|
|
|
|
c->file[C_BORDER]->after_write = handle_after_write_client;
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/%d/tab", id);
|
|
|
|
c->file[C_TAB] = wmii_create_ixpfile(ixps, buf, def[WM_TAB]->content);
|
|
|
|
c->file[C_TAB]->after_write = handle_after_write_client;
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/%d/handleinc", id);
|
|
|
|
c->file[C_HANDLE_INC] =
|
|
|
|
wmii_create_ixpfile(ixps, buf, def[WM_HANDLE_INC]->content);
|
|
|
|
c->file[C_HANDLE_INC]->after_write = handle_after_write_client;
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/%d/geometry", id);
|
|
|
|
c->file[C_GEOMETRY] = ixp_create(ixps, buf);
|
|
|
|
c->file[C_GEOMETRY]->before_read = handle_before_read_client;
|
|
|
|
c->file[C_GEOMETRY]->after_write = handle_after_write_client;
|
2006-01-26 20:29:49 +03:00
|
|
|
snprintf(buf, MAX_BUF, "/detached/%d/ctl", id);
|
|
|
|
c->file[C_CTL] = ixp_create(ixps, buf);
|
|
|
|
c->file[C_CTL]->after_write = handle_after_write_client;
|
2006-01-25 20:39:08 +03:00
|
|
|
id++;
|
|
|
|
|
|
|
|
/* client.frame */
|
|
|
|
fwa.override_redirect = 1;
|
|
|
|
fwa.background_pixmap = ParentRelative;
|
|
|
|
fwa.event_mask = SubstructureRedirectMask | ExposureMask | ButtonPressMask | PointerMotionMask;
|
|
|
|
|
|
|
|
bw = border_width(c);
|
|
|
|
th = tab_height(c);
|
2006-01-26 21:58:30 +03:00
|
|
|
c->frame.rect = c->rect;
|
2006-01-25 20:39:08 +03:00
|
|
|
c->frame.rect.width += 2 * bw;
|
|
|
|
c->frame.rect.height += bw + (th ? th : bw);
|
|
|
|
c->frame.win = XCreateWindow(dpy, root, c->frame.rect.x, c->frame.rect.y,
|
|
|
|
c->frame.rect.width, c->frame.rect.height, 0,
|
|
|
|
DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
|
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &fwa);
|
|
|
|
c->frame.cursor = normal_cursor;
|
|
|
|
XDefineCursor(dpy, c->frame.win, c->frame.cursor);
|
|
|
|
c->frame.gc = XCreateGC(dpy, c->frame.win, 0, 0);
|
|
|
|
XSync(dpy, False);
|
|
|
|
|
2006-01-29 15:41:16 +03:00
|
|
|
client = (Client **)cext_array_attach((void **)client, c, sizeof(Client *), &clientsz);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
return c;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
set_client_state(Client * c, int state)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
long data[2];
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
data[0] = (long) state;
|
|
|
|
data[1] = (long) None;
|
|
|
|
XChangeProperty(dpy, c->win, wm_state, wm_state, 32, PropModeReplace,
|
|
|
|
(unsigned char *) data, 2);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-01-19 17:02:18 +03:00
|
|
|
void
|
2006-01-26 14:39:20 +03:00
|
|
|
focus_client(Client *c)
|
|
|
|
{
|
2006-01-26 17:24:34 +03:00
|
|
|
Page *p = page ? page[sel_page] : nil;
|
2006-01-26 14:39:20 +03:00
|
|
|
size_t i, j;
|
|
|
|
Client *old = sel_client();
|
|
|
|
|
|
|
|
/* setup indexes */
|
2006-01-26 21:58:30 +03:00
|
|
|
if(c->page != p) {
|
2006-01-26 16:16:04 +03:00
|
|
|
focus_page(c->page);
|
2006-01-26 21:58:30 +03:00
|
|
|
p = c->page;
|
|
|
|
}
|
2006-02-01 18:27:53 +03:00
|
|
|
p->is_area = c->area != nil;
|
2006-01-26 21:58:30 +03:00
|
|
|
p->file[P_SEL_PREFIX]->content = c->file[P_PREFIX]->content;
|
2006-02-01 18:27:53 +03:00
|
|
|
if(p->is_area) {
|
|
|
|
for(i = 0; (i < p->areasz) && p->area[i]; i++) {
|
|
|
|
Area *col = p->area[i];
|
2006-01-26 17:24:34 +03:00
|
|
|
for(j = 0; (j < col->clientsz) && col->client[j] && (c != col->client[j]); j++);
|
|
|
|
if((j < col->clientsz) && col->client[j]) {
|
2006-02-01 18:27:53 +03:00
|
|
|
p->sel_area = i;
|
2006-01-26 14:39:20 +03:00
|
|
|
col->sel = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(i = 0; (i < p->floatingsz) && p->floating[i] && (p->floating[i] != c); i++);
|
2006-01-26 21:58:30 +03:00
|
|
|
if((i < p->floatingsz) && p->floating[i])
|
2006-01-26 14:39:20 +03:00
|
|
|
p->sel_float = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(old && (old != c)) {
|
2006-01-19 17:02:18 +03:00
|
|
|
ungrab_client(old, AnyModifier, AnyButton);
|
|
|
|
grab_client(old, AnyModifier, AnyButton);
|
2006-01-26 14:39:20 +03:00
|
|
|
draw_client(old);
|
2006-01-19 17:02:18 +03:00
|
|
|
}
|
2006-01-26 14:39:20 +03:00
|
|
|
ungrab_client(c, AnyModifier, AnyButton);
|
|
|
|
grab_client(c, Mod1Mask, Button1);
|
|
|
|
grab_client(c, Mod1Mask, Button3);
|
|
|
|
XRaiseWindow(dpy, c->frame.win);
|
|
|
|
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
|
|
|
XDefineCursor(dpy, c->win, normal_cursor);
|
|
|
|
draw_client(c);
|
2006-01-19 17:02:18 +03:00
|
|
|
XSync(dpy, False);
|
2006-01-26 14:39:20 +03:00
|
|
|
invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]);
|
2006-01-19 17:02:18 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-13 15:24:55 +03:00
|
|
|
map_client(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-01-10 16:43:09 +03:00
|
|
|
XMapRaised(dpy, c->win);
|
2005-12-21 18:18:11 +03:00
|
|
|
set_client_state(c, NormalState);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-13 15:24:55 +03:00
|
|
|
unmap_client(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-01-18 16:42:44 +03:00
|
|
|
ungrab_client(c, AnyModifier, AnyButton);
|
2005-12-21 18:18:11 +03:00
|
|
|
XUnmapWindow(dpy, c->win);
|
|
|
|
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-01-26 14:56:28 +03:00
|
|
|
c->attached = w == c->frame.win;
|
2005-12-21 18:18:11 +03:00
|
|
|
XReparentWindow(dpy, c->win, w, x, y);
|
|
|
|
c->ignore_unmap++;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
grab_client(Client * c, unsigned long mod, unsigned int button)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-01-18 16:42:44 +03:00
|
|
|
XGrabButton(dpy, button, mod, c->win, False,
|
2006-01-18 17:02:29 +03:00
|
|
|
ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
|
2005-12-21 18:18:11 +03:00
|
|
|
if((mod != AnyModifier) && num_lock_mask) {
|
2006-01-18 16:42:44 +03:00
|
|
|
XGrabButton(dpy, button, mod | num_lock_mask, c->win, False,
|
2006-01-18 17:02:29 +03:00
|
|
|
ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
|
2005-12-21 18:18:11 +03:00
|
|
|
XGrabButton(dpy, button, mod | num_lock_mask | LockMask, c->win,
|
2006-01-18 17:02:29 +03:00
|
|
|
False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
|
2005-12-21 18:18:11 +03:00
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
ungrab_client(Client * c, unsigned long mod, unsigned int button)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
XUngrabButton(dpy, button, mod, c->win);
|
|
|
|
if(mod != AnyModifier && num_lock_mask) {
|
|
|
|
XUngrabButton(dpy, button, mod | num_lock_mask, c->win);
|
|
|
|
XUngrabButton(dpy, button, mod | num_lock_mask | LockMask, c->win);
|
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
configure_client(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
XConfigureEvent e;
|
|
|
|
e.type = ConfigureNotify;
|
|
|
|
e.event = c->win;
|
|
|
|
e.window = c->win;
|
|
|
|
e.x = c->rect.x;
|
|
|
|
e.y = c->rect.y;
|
2006-01-26 14:56:28 +03:00
|
|
|
if(c->attached) {
|
2006-01-25 21:41:12 +03:00
|
|
|
e.x += c->frame.rect.x;
|
|
|
|
e.y += c->frame.rect.y;
|
|
|
|
}
|
2005-12-21 18:18:11 +03:00
|
|
|
e.width = c->rect.width;
|
|
|
|
e.height = c->rect.height;
|
|
|
|
e.border_width = c->border;
|
|
|
|
e.above = None;
|
|
|
|
e.override_redirect = False;
|
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
|
|
|
|
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *) & e);
|
|
|
|
XSelectInput(dpy, c->win, CLIENT_MASK);
|
|
|
|
XSync(dpy, False);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
close_client(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
if(c->proto & PROTO_DEL)
|
|
|
|
wmii_send_message(dpy, c->win, wm_protocols, wm_delete);
|
|
|
|
else
|
|
|
|
XKillClient(dpy, c->win);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-25 21:41:12 +03:00
|
|
|
handle_client_property(Client *c, XPropertyEvent *e)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
XTextProperty name;
|
|
|
|
long msize;
|
|
|
|
|
|
|
|
if(e->atom == wm_protocols) {
|
|
|
|
/* update */
|
|
|
|
c->proto = win_proto(c->win);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (e->atom) {
|
|
|
|
case XA_WM_NAME:
|
|
|
|
XGetWMName(dpy, c->win, &name);
|
2006-01-03 12:30:15 +03:00
|
|
|
if(name.value) {
|
2006-01-04 18:28:31 +03:00
|
|
|
cext_strlcpy(c->name, (char*) name.value, sizeof(c->name));
|
2006-01-03 12:30:15 +03:00
|
|
|
free(name.value);
|
|
|
|
}
|
2006-01-26 14:56:28 +03:00
|
|
|
if(c->attached)
|
2005-12-21 18:18:11 +03:00
|
|
|
draw_client(c);
|
|
|
|
invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]);
|
|
|
|
break;
|
|
|
|
case XA_WM_TRANSIENT_FOR:
|
|
|
|
XGetTransientForHint(dpy, c->win, &c->trans);
|
|
|
|
break;
|
|
|
|
case XA_WM_NORMAL_HINTS:
|
|
|
|
if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize)
|
|
|
|
|| !c->size.flags) {
|
|
|
|
c->size.flags = PSize;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
destroy_client(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
XFreeGC(dpy, c->frame.gc);
|
|
|
|
XDestroyWindow(dpy, c->frame.win);
|
|
|
|
ixp_remove_file(ixps, c->file[C_PREFIX]);
|
2006-01-29 15:41:16 +03:00
|
|
|
cext_array_detach((void **)detached, c, &detachedsz);
|
2005-12-21 18:18:11 +03:00
|
|
|
free(c);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* speed reasoned function for client property change */
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-23 22:00:25 +03:00
|
|
|
draw_client(Client *c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
Draw d = { 0 };
|
2006-01-26 14:39:20 +03:00
|
|
|
unsigned int tabh = tab_height(c);
|
|
|
|
int bw = border_width(c);
|
|
|
|
XRectangle notch;
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-01-26 14:39:20 +03:00
|
|
|
d.drawable = c->frame.win;
|
2006-01-30 21:08:58 +03:00
|
|
|
d.xfont = xfont;
|
2006-01-26 14:39:20 +03:00
|
|
|
d.gc = c->frame.gc;
|
|
|
|
|
|
|
|
if(c == sel_client()) {
|
|
|
|
d.bg = blitz_loadcolor(dpy, screen, def[WM_SEL_BG_COLOR]->content);
|
|
|
|
d.fg = blitz_loadcolor(dpy, screen, def[WM_SEL_FG_COLOR]->content);
|
|
|
|
d.border = blitz_loadcolor(dpy, screen, def[WM_SEL_BORDER_COLOR]->content);
|
|
|
|
} else {
|
|
|
|
d.bg = blitz_loadcolor(dpy, screen, def[WM_NORM_BG_COLOR]->content);
|
|
|
|
d.fg = blitz_loadcolor(dpy, screen, def[WM_NORM_FG_COLOR]->content);
|
|
|
|
d.border = blitz_loadcolor(dpy, screen, def[WM_NORM_BORDER_COLOR]->content);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw border */
|
|
|
|
if(bw) {
|
|
|
|
notch.x = bw;
|
|
|
|
notch.y = bw;
|
|
|
|
notch.width = c->frame.rect.width - 2 * bw;
|
|
|
|
notch.height = c->frame.rect.height - 2 * bw;
|
|
|
|
d.rect = c->frame.rect;
|
|
|
|
d.rect.x = d.rect.y = 0;
|
|
|
|
d.notch = ¬ch;
|
|
|
|
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
}
|
|
|
|
XSync(dpy, False);
|
|
|
|
|
|
|
|
/* draw tab */
|
2005-12-21 18:18:11 +03:00
|
|
|
if(!tabh)
|
|
|
|
return;
|
|
|
|
|
2006-01-23 22:00:25 +03:00
|
|
|
d.rect.x = 0;
|
2005-12-21 18:18:11 +03:00
|
|
|
d.rect.y = 0;
|
2006-01-25 21:41:12 +03:00
|
|
|
d.rect.width = c->frame.rect.width;
|
2005-12-21 18:18:11 +03:00
|
|
|
d.rect.height = tabh;
|
2006-01-03 12:30:15 +03:00
|
|
|
d.data = c->name;
|
2005-12-21 18:18:11 +03:00
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
XSync(dpy, False);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
|
|
|
gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
int dx = 0, dy = 0;
|
|
|
|
int gravity = NorthWestGravity;
|
|
|
|
|
|
|
|
if(c->size.flags & PWinGravity) {
|
|
|
|
gravity = c->size.win_gravity;
|
|
|
|
}
|
|
|
|
/* y */
|
|
|
|
switch (gravity) {
|
|
|
|
case StaticGravity:
|
|
|
|
case NorthWestGravity:
|
|
|
|
case NorthGravity:
|
|
|
|
case NorthEastGravity:
|
|
|
|
dy = tabh;
|
|
|
|
break;
|
|
|
|
case EastGravity:
|
|
|
|
case CenterGravity:
|
|
|
|
case WestGravity:
|
|
|
|
dy = -(c->rect.height / 2) + tabh;
|
|
|
|
break;
|
|
|
|
case SouthEastGravity:
|
|
|
|
case SouthGravity:
|
|
|
|
case SouthWestGravity:
|
|
|
|
dy = -c->rect.height;
|
|
|
|
break;
|
|
|
|
default: /* don't care */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* x */
|
|
|
|
switch (gravity) {
|
|
|
|
case StaticGravity:
|
|
|
|
case NorthWestGravity:
|
|
|
|
case WestGravity:
|
|
|
|
case SouthWestGravity:
|
|
|
|
dx = bw;
|
|
|
|
break;
|
|
|
|
case NorthGravity:
|
|
|
|
case CenterGravity:
|
|
|
|
case SouthGravity:
|
|
|
|
dx = -(c->rect.width / 2) + bw;
|
|
|
|
break;
|
|
|
|
case NorthEastGravity:
|
|
|
|
case EastGravity:
|
|
|
|
case SouthEastGravity:
|
|
|
|
dx = -(c->rect.width + bw);
|
|
|
|
break;
|
|
|
|
default: /* don't care */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(invert) {
|
|
|
|
dx = -dx;
|
|
|
|
dy = -dy;
|
|
|
|
}
|
|
|
|
c->rect.x += dx;
|
|
|
|
c->rect.y += dy;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2005-12-05 22:38:03 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-25 21:41:12 +03:00
|
|
|
attach_client(Client *c)
|
|
|
|
{
|
|
|
|
Page *p;
|
2006-01-26 17:24:34 +03:00
|
|
|
if(!page)
|
2006-01-26 21:58:30 +03:00
|
|
|
p = alloc_page();
|
|
|
|
else
|
|
|
|
p = page[sel_page];
|
2006-01-25 21:41:12 +03:00
|
|
|
|
|
|
|
reparent_client(c, c->frame.win, c->rect.x, c->rect.y);
|
|
|
|
c->page = p;
|
2006-01-26 21:58:30 +03:00
|
|
|
wmii_move_ixpfile(c->file[C_PREFIX], p->file[P_CLIENT_PREFIX]);
|
2006-01-25 21:41:12 +03:00
|
|
|
|
2006-02-01 18:27:53 +03:00
|
|
|
if(p->is_area)
|
|
|
|
attach_area(c);
|
2006-01-26 21:58:30 +03:00
|
|
|
else
|
2006-01-29 15:41:16 +03:00
|
|
|
p->floating = (Client **)cext_array_attach((void **)p->floating, c,
|
|
|
|
sizeof(Client *), &p->floatingsz);
|
2006-01-26 17:24:34 +03:00
|
|
|
map_client(c);
|
2006-01-26 21:58:30 +03:00
|
|
|
XMapWindow(dpy, c->frame.win);
|
2006-01-26 17:24:34 +03:00
|
|
|
focus_client(c);
|
2006-01-25 21:41:12 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]);
|
2005-12-05 22:38:03 +03:00
|
|
|
}
|
2005-12-06 00:22:24 +03:00
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-25 21:41:12 +03:00
|
|
|
detach_client(Client *c, Bool unmap)
|
|
|
|
{
|
2006-01-26 20:29:49 +03:00
|
|
|
wmii_move_ixpfile(c->file[C_PREFIX], def[WM_DETACHED_PREFIX]);
|
2006-02-01 18:27:53 +03:00
|
|
|
if(c->area)
|
|
|
|
detach_area(c);
|
2006-01-25 21:41:12 +03:00
|
|
|
else {
|
2006-01-29 15:41:16 +03:00
|
|
|
cext_array_detach((void **)c->page->floating, c, &c->page->floatingsz);
|
2006-01-25 21:41:12 +03:00
|
|
|
if(!c->destroyed) {
|
|
|
|
if(!unmap) {
|
2006-01-29 15:41:16 +03:00
|
|
|
detached = (Client **)cext_array_attach((void **)detached, c,
|
|
|
|
sizeof(Client *), &detachedsz);
|
2006-01-25 21:41:12 +03:00
|
|
|
unmap_client(c);
|
|
|
|
}
|
2006-01-26 14:39:20 +03:00
|
|
|
c->rect.x = c->frame.rect.x;
|
|
|
|
c->rect.y = c->frame.rect.y;
|
2006-01-25 21:41:12 +03:00
|
|
|
reparent_client(c, root, c->rect.x, c->rect.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c->page = nil;
|
2005-12-21 18:18:11 +03:00
|
|
|
if(c->destroyed)
|
|
|
|
destroy_client(c);
|
2006-01-26 17:24:34 +03:00
|
|
|
focus_page(page[sel_page]);
|
2005-12-16 04:59:27 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
Client *
|
2006-01-26 20:29:49 +03:00
|
|
|
sel_client_of_page(Page *p)
|
2005-12-16 04:59:27 +03:00
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
if(p) {
|
2006-02-01 18:27:53 +03:00
|
|
|
if(p->is_area) {
|
|
|
|
Area *col = p->area[p->sel_area];
|
2006-01-26 17:24:34 +03:00
|
|
|
return (col && col->client) ? col->client[col->sel] : nil;
|
2006-01-26 14:39:20 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return p->floating ? p->floating[p->sel_float] : nil;
|
|
|
|
}
|
|
|
|
return nil;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 20:29:49 +03:00
|
|
|
Client *
|
|
|
|
sel_client()
|
|
|
|
{
|
|
|
|
return page ? sel_client_of_page(page[sel_page]) : nil;
|
|
|
|
}
|
|
|
|
|
2006-01-25 20:39:08 +03:00
|
|
|
Client *
|
|
|
|
win_to_frame(Window w)
|
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
size_t i;
|
2006-01-26 21:58:30 +03:00
|
|
|
for(i = 0; (i < clientsz) && client[i]; i++)
|
2006-01-26 17:24:34 +03:00
|
|
|
if(client[i]->frame.win == w)
|
|
|
|
return client[i];
|
2006-01-26 14:39:20 +03:00
|
|
|
return nil;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
2006-01-26 14:39:20 +03:00
|
|
|
tab_height(Client * c)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
if(blitz_strtonum(c->file[C_TAB]->content, 0, 1))
|
2006-01-30 21:08:58 +03:00
|
|
|
return xfont->ascent + xfont->descent + 4;
|
2006-01-25 20:39:08 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
2006-01-26 14:39:20 +03:00
|
|
|
border_width(Client * c)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
if(blitz_strtonum(c->file[C_BORDER]->content, 0, 1))
|
2006-01-25 20:39:08 +03:00
|
|
|
return BORDER_WIDTH;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-26 14:39:20 +03:00
|
|
|
check_dimensions(Client *c, unsigned int tabh, unsigned int bw)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
|
|
|
if(c->size.flags & PMinSize) {
|
2006-01-26 14:39:20 +03:00
|
|
|
if(c->frame.rect.width - 2 * bw < c->size.min_width)
|
|
|
|
c->frame.rect.width = c->size.min_width + 2 * bw;
|
|
|
|
if(c->frame.rect.height - bw - (tabh ? tabh : bw) < c->size.min_height)
|
|
|
|
c->frame.rect.height = c->size.min_height + bw + (tabh ? tabh : bw);
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
if(c->size.flags & PMaxSize) {
|
2006-01-26 14:39:20 +03:00
|
|
|
if(c->frame.rect.width - 2 * bw > c->size.max_width)
|
|
|
|
c->frame.rect.width = c->size.max_width + 2 * bw;
|
|
|
|
if(c->frame.rect.height - bw - (tabh ? tabh : bw) > c->size.max_height)
|
|
|
|
c->frame.rect.height = c->size.max_height + bw + (tabh ? tabh : bw);
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-26 14:39:20 +03:00
|
|
|
resize_incremental(Client *c, unsigned int tabh, unsigned int bw)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
|
|
|
/* increment stuff, see chapter 4.1.2.3 of the ICCCM Manual */
|
|
|
|
if(c->size.flags & PResizeInc) {
|
|
|
|
int base_width = 0, base_height = 0;
|
|
|
|
|
|
|
|
if(c->size.flags & PBaseSize) {
|
|
|
|
base_width = c->size.base_width;
|
|
|
|
base_height = c->size.base_height;
|
|
|
|
} else if(c->size.flags & PMinSize) {
|
|
|
|
/* base_{width,height} default to min_{width,height} */
|
|
|
|
base_width = c->size.min_width;
|
|
|
|
base_height = c->size.min_height;
|
|
|
|
}
|
|
|
|
/* client_width = base_width + i * c->size.width_inc for an integer i */
|
2006-01-26 14:39:20 +03:00
|
|
|
c->frame.rect.width -=
|
|
|
|
(c->frame.rect.width - 2 * bw - base_width) % c->size.width_inc;
|
|
|
|
c->frame.rect.height -=
|
|
|
|
(c->frame.rect.height - bw - (tabh ? tabh : bw) - base_height) % c->size.height_inc;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-01-26 14:39:20 +03:00
|
|
|
resize_client(Client *c, XRectangle *r, XPoint *pt)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
unsigned int tabh = tab_height(c);
|
|
|
|
unsigned int bw = border_width(c);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-02-01 18:27:53 +03:00
|
|
|
if(c->area)
|
|
|
|
resize_area(c, r, pt);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
|
|
|
/* resize if client requests special size */
|
2006-01-26 14:39:20 +03:00
|
|
|
check_dimensions(c, tabh, bw);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-01-26 14:39:20 +03:00
|
|
|
if(c->file[C_HANDLE_INC]->content
|
|
|
|
&& ((char *) c->file[C_HANDLE_INC]->content)[0] == '1')
|
|
|
|
resize_incremental(c, tabh, bw);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-01-26 14:39:20 +03:00
|
|
|
XMoveResizeWindow(dpy, c->frame.win, c->frame.rect.x, c->frame.rect.y,
|
|
|
|
c->frame.rect.width, c->frame.rect.height);
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-01-26 14:39:20 +03:00
|
|
|
c->rect.x = bw;
|
|
|
|
c->rect.y = tabh ? tabh : bw;
|
|
|
|
c->rect.width = c->frame.rect.width - 2 * bw;
|
|
|
|
c->rect.height = c->frame.rect.height - bw - (tabh ? tabh : bw);
|
|
|
|
XMoveResizeWindow(dpy, c->win, c->rect.x, c->rect.y, c->rect.width, c->rect.height);
|
|
|
|
configure_client(c);
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 14:39:20 +03:00
|
|
|
static void
|
|
|
|
handle_before_read_client(IXPServer * s, File *file)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
size_t i;
|
|
|
|
char buf[32];
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-01-26 17:24:34 +03:00
|
|
|
for(i = 0; (i < clientsz) && client[i]; i++) {
|
|
|
|
Client *c = client[i];
|
2006-01-26 14:39:20 +03:00
|
|
|
if(file == c->file[C_GEOMETRY]) {
|
|
|
|
snprintf(buf, sizeof(buf), "%d %d %d %d", c->frame.rect.x, c->frame.rect.y,
|
|
|
|
c->frame.rect.width, c->frame.rect.height);
|
2006-01-25 20:39:08 +03:00
|
|
|
if(file->content)
|
|
|
|
free(file->content);
|
|
|
|
file->content = cext_estrdup(buf);
|
|
|
|
file->size = strlen(buf);
|
2006-01-26 14:39:20 +03:00
|
|
|
return;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
2006-01-26 14:39:20 +03:00
|
|
|
else if(file == c->file[C_NAME]) {
|
2006-01-25 20:39:08 +03:00
|
|
|
if(file->content)
|
|
|
|
free(file->content);
|
2006-01-26 14:39:20 +03:00
|
|
|
file->content = cext_estrdup(c->name);
|
|
|
|
file->size = strlen(c->name);
|
|
|
|
return ;
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-26 14:39:20 +03:00
|
|
|
handle_after_write_client(IXPServer *s, File *file)
|
2006-01-25 20:39:08 +03:00
|
|
|
{
|
2006-01-26 14:39:20 +03:00
|
|
|
size_t i;
|
2006-01-25 20:39:08 +03:00
|
|
|
|
2006-01-26 17:24:34 +03:00
|
|
|
for(i = 0; (i < clientsz) && client[i]; i++) {
|
|
|
|
Client *c = client[i];
|
2006-01-26 20:29:49 +03:00
|
|
|
if(file == c->file[C_CTL]) {
|
|
|
|
run_action(file, c, client_acttbl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(file == c->file[C_TAB] || file == c->file[C_BORDER]
|
2006-01-26 14:39:20 +03:00
|
|
|
|| file == c->file[C_HANDLE_INC])
|
|
|
|
{
|
|
|
|
resize_client(c, &c->frame.rect, nil);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(file == c->file[C_GEOMETRY]) {
|
|
|
|
char *geom = c->file[C_GEOMETRY]->content;
|
2006-01-25 20:39:08 +03:00
|
|
|
if(geom && strrchr(geom, ' ')) {
|
2006-01-26 14:39:20 +03:00
|
|
|
XRectangle frect = c->frame.rect;
|
2006-01-25 20:39:08 +03:00
|
|
|
blitz_strtorect(&rect, &frect, geom);
|
2006-01-26 14:39:20 +03:00
|
|
|
resize_client(c, &frect, 0);
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
|
|
|
return;
|
2006-01-26 14:39:20 +03:00
|
|
|
}
|
|
|
|
}
|
2006-01-25 20:39:08 +03:00
|
|
|
}
|
2006-01-26 20:29:49 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
max_client(void *obj, char *arg)
|
|
|
|
{
|
|
|
|
Client *c = obj;
|
|
|
|
|
|
|
|
if(c->maximized) {
|
|
|
|
/* XXX: do we really need this ? */ c->frame.rect = c->frame.revert;
|
|
|
|
resize_client(c, &c->frame.revert, nil);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c->frame.revert = c->frame.rect;
|
2006-02-01 18:27:53 +03:00
|
|
|
c->frame.rect = c->area ? c->area->rect : rect;
|
2006-01-26 20:29:49 +03:00
|
|
|
XRaiseWindow(dpy, c->frame.win);
|
|
|
|
resize_client(c, &c->frame.rect, nil);
|
|
|
|
}
|
|
|
|
c->maximized = !c->maximized;
|
|
|
|
}
|
|
|
|
|