wmii/cmd/wm/area.c

100 lines
2.5 KiB
C
Raw Normal View History

2005-11-18 18:54:58 +03:00
/*
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "wm.h"
#include <cext.h>
2005-12-05 01:45:59 +03:00
static Area zero_area = {0};
2005-11-18 18:54:58 +03:00
2005-12-05 22:38:03 +03:00
Area *alloc_area(Page *p, XRectangle * r, char *layout)
2005-12-05 01:45:59 +03:00
{
char buf[MAX_BUF];
Area *a = (Area *) emalloc(sizeof(Area));
2005-12-05 22:38:03 +03:00
int id = count_items((void **) p->area) + 1;
2005-12-05 01:45:59 +03:00
*a = zero_area;
a->rect = *r;
a->page = p;
2005-12-05 22:38:03 +03:00
snprintf(buf, MAX_BUF, "/p/%s/a/%d", p->file[P_PREFIX]->name, id);
a->file[A_PREFIX] = ixp_create(ixps, buf);
snprintf(buf, MAX_BUF, "/p/%s/a/%d/f", p->file[P_PREFIX]->name, id);
a->file[A_FRAME_PREFIX] = ixp_create(ixps, buf);
snprintf(buf, MAX_BUF, "/p/%s/a/%d/f/sel", p->file[P_PREFIX]->name, id);
a->file[A_SEL_FRAME] = ixp_create(ixps, buf);
snprintf(buf, MAX_BUF, "/p/%s/a/%d/ctl", p->file[P_PREFIX]->name, id);
a->file[A_CTL] = ixp_create(ixps, buf);
snprintf(buf, MAX_BUF, "/p/%s/a/%d/geometry", p->file[P_PREFIX]->name, id);
a->file[A_GEOMETRY] = ixp_create(ixps, buf);
snprintf(buf, MAX_BUF, "/p/%s/a/%d/layout", p->file[P_PREFIX]->name, id);
a->file[A_LAYOUT] = wmii_create_ixpfile(ixps, buf, layout);
a->layout = get_layout(layout);
p->area = (Area **) attach_item_end((void **) p->area, a, sizeof(Area *));
2005-12-05 04:50:02 +03:00
p->sel = index_item((void **) p->area, a);
2005-12-05 01:45:59 +03:00
return a;
}
void destroy_area(Area * a)
2005-11-18 18:54:58 +03:00
{
unsigned int i;
a->layout->deinit(a);
2005-12-05 04:50:02 +03:00
for (i = 0; a->frame && a->frame[i]; i++);
destroy_frame(a->frame[i]);
free(a->frame);
2005-12-05 22:38:03 +03:00
ixp_remove_file(ixps, a->file[A_PREFIX]);
free(a);
2005-11-18 18:54:58 +03:00
}
2005-12-06 00:22:24 +03:00
void sel_area(Area * a, int raise)
2005-11-18 18:54:58 +03:00
{
2005-12-05 01:45:59 +03:00
Page *p = a->page;
2005-12-06 00:22:24 +03:00
if (raise && a->frame) {
int i;
for (i = 0; a->frame[i]; i++)
if (i != a->sel)
XRaiseWindow(dpy, a->frame[i]->win);
}
2005-12-05 04:50:02 +03:00
p->sel = index_item((void **) p->area, a);
2005-12-05 22:38:03 +03:00
p->file[P_SEL_AREA]->content = a->file[A_PREFIX]->content;
2005-12-06 00:22:24 +03:00
if (a->frame)
sel_frame(a->frame[a->sel], raise);
2005-11-18 18:54:58 +03:00
}
2005-12-05 01:45:59 +03:00
void attach_frame_to_area(Area * a, Frame * f)
{
2005-12-05 22:38:03 +03:00
wmii_move_ixpfile(f->file[F_PREFIX], a->file[A_FRAME_PREFIX]);
a->file[A_SEL_FRAME]->content = f->file[F_PREFIX]->content;
a->frame = (Frame **) attach_item_end((void **) a->frame, f, sizeof(Frame *));
a->sel = index_item((void **) a->frame, f);
f->area = a;
2005-12-03 20:02:39 +03:00
}
2005-12-05 22:38:03 +03:00
void detach_frame_from_area(Frame * f, int ignore_sel_and_destroy)
2005-12-03 20:02:39 +03:00
{
2005-12-06 00:22:24 +03:00
Area *a = f->area;
a->frame = (Frame **) detach_item((void **) a->frame, f, sizeof(Frame *));
f->area = 0;
if (a->sel)
a->sel--;
else
a->sel = 0;
2005-12-03 20:02:39 +03:00
}
2005-12-05 01:45:59 +03:00
void draw_area(Area * a)
2005-12-03 20:02:39 +03:00
{
}
2005-12-05 01:45:59 +03:00
void hide_area(Area * a)
2005-12-03 20:02:39 +03:00
{
}
2005-12-05 01:45:59 +03:00
void show_area(Area * a)
2005-12-03 20:02:39 +03:00
{
}