2005-12-07 17:06:16 +03:00
|
|
|
/*
|
|
|
|
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
|
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
2006-01-12 18:06:50 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2005-12-07 17:06:16 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
2006-01-12 18:06:50 +03:00
|
|
|
static void handle_after_write_layout(IXPServer * s, File * file);
|
|
|
|
|
|
|
|
Layout *
|
|
|
|
alloc_layout(Page * p, char *layout)
|
|
|
|
{
|
|
|
|
char buf[MAX_BUF], *name;
|
|
|
|
Layout *l = (Layout *) cext_emallocz(sizeof(Layout));
|
|
|
|
|
|
|
|
l->page = p;
|
|
|
|
if(strncmp(layout, "float", 6))
|
|
|
|
name = "managed";
|
|
|
|
else
|
|
|
|
name = "float";
|
|
|
|
snprintf(buf, MAX_BUF, "/%s/layout/%s", p->file[P_PREFIX]->name, name);
|
|
|
|
l->file[L_PREFIX] = ixp_create(ixps, buf);
|
|
|
|
snprintf(buf, MAX_BUF, "/%s/layout/%s/frame", p->file[P_PREFIX]->name,
|
|
|
|
name);
|
|
|
|
l->file[L_FRAME_PREFIX] = ixp_create(ixps, buf);
|
|
|
|
snprintf(buf, MAX_BUF, "/%s/layout/%s/frame/sel",
|
|
|
|
p->file[P_PREFIX]->name, name);
|
|
|
|
l->file[L_SEL_FRAME] = ixp_create(ixps, buf);
|
|
|
|
l->file[L_SEL_FRAME]->bind = 1;
|
|
|
|
snprintf(buf, MAX_BUF, "/%s/layout/%s/ctl", p->file[P_PREFIX]->name,
|
|
|
|
name);
|
|
|
|
l->file[L_CTL] = ixp_create(ixps, buf);
|
|
|
|
l->file[L_CTL]->after_write = handle_after_write_layout;
|
|
|
|
snprintf(buf, MAX_BUF, "/%s/layout/%s/name", p->file[P_PREFIX]->name,
|
|
|
|
name);
|
|
|
|
l->file[L_NAME] = wmii_create_ixpfile(ixps, buf, layout);
|
|
|
|
l->file[L_NAME]->after_write = handle_after_write_layout;
|
|
|
|
l->def = match_layout_def(layout);
|
|
|
|
l->def->init(l, nil);
|
2006-01-12 18:44:06 +03:00
|
|
|
p->file[P_SEL_LAYOUT]->content = l->file[L_PREFIX]->content;
|
2006-01-12 18:06:50 +03:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
destroy_layout(Layout *l)
|
|
|
|
{
|
|
|
|
l->def->deinit(l);
|
|
|
|
ixp_remove_file(ixps, l->file[L_PREFIX]);
|
|
|
|
free(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
focus_layout(Layout *l)
|
|
|
|
{
|
|
|
|
Page *p = l->page;
|
|
|
|
Frame *f;
|
|
|
|
p->sel = l;
|
2006-01-12 18:44:06 +03:00
|
|
|
p->file[P_SEL_LAYOUT]->content = l->file[L_PREFIX]->content;
|
2006-01-12 18:06:50 +03:00
|
|
|
if((f = l->def->sel(l)))
|
|
|
|
l->def->focus(f, False);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hide_layout(Layout *l)
|
|
|
|
{
|
|
|
|
Frame *f;
|
|
|
|
for(f = l->def->frames(l); f; f = f->next)
|
|
|
|
XMoveWindow(dpy, f->win, 2 * rect.width, 2 * rect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
show_layout(Layout *l, Bool raise)
|
|
|
|
{
|
|
|
|
Frame *f;
|
|
|
|
for(f = l->def->frames(l); f; f = f->next) {
|
|
|
|
XMoveWindow(dpy, f->win, f->rect.x, f->rect.y);
|
|
|
|
if(raise)
|
|
|
|
XRaiseWindow(dpy, f->win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
Layout *
|
2006-01-12 18:06:50 +03:00
|
|
|
sel_layout()
|
|
|
|
{
|
|
|
|
return selpage ? selpage->sel : nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
attach_frame_to_layout(Layout *l, Frame * f)
|
|
|
|
{
|
|
|
|
wmii_move_ixpfile(f->file[F_PREFIX], l->file[L_FRAME_PREFIX]);
|
|
|
|
l->file[L_SEL_FRAME]->content = f->file[F_PREFIX]->content;
|
|
|
|
f->layout = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
detach_frame_from_layout(Frame * f)
|
|
|
|
{
|
|
|
|
f->layout->file[L_SEL_FRAME]->content = 0;
|
|
|
|
f->layout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_after_write_layout(IXPServer * s, File * file)
|
|
|
|
{
|
|
|
|
Page *p;
|
|
|
|
for(p = pages; p; p = p->next) {
|
|
|
|
if(file == p->managed->file[L_CTL]) {
|
|
|
|
run_action(file, p->managed,
|
|
|
|
p->managed->def->actions(p->managed));
|
|
|
|
return;
|
|
|
|
} else if(file == p->floating->file[L_CTL]) {
|
|
|
|
run_action(file, p->floating,
|
|
|
|
p->floating->def->actions(p->floating));
|
|
|
|
return;
|
|
|
|
} else if(file == p->managed->file[L_NAME]) {
|
|
|
|
LayoutDef *l = match_layout_def(file->content);
|
|
|
|
if(l) {
|
|
|
|
Client *clients = p->managed->def->deinit(p->managed);
|
|
|
|
p->managed->def = l;
|
|
|
|
p->managed->def->init(p->managed, clients);
|
|
|
|
invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LayoutDef *
|
|
|
|
match_layout_def(char *name)
|
2005-12-07 17:06:16 +03:00
|
|
|
{
|
2006-01-12 18:06:50 +03:00
|
|
|
LayoutDef *l;
|
2005-12-21 18:18:11 +03:00
|
|
|
for(l = layouts; l; l = l->next)
|
|
|
|
if(!strncmp(name, l->name, strlen(l->name)))
|
|
|
|
return l;
|
|
|
|
return nil;
|
2005-12-07 17:06:16 +03:00
|
|
|
}
|