wmii/cmd/wm/layout_float.c

152 lines
3.3 KiB
C
Raw Normal View History

2005-12-05 04:09:27 +03:00
/*
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "wm.h"
#include "layoutdef.h"
2005-12-05 04:09:27 +03:00
static void init_float(Area *a);
static void deinit_float(Area *a);
static void arrange_float(Area *a);
static Bool attach_float(Area *a, Client *c);
2005-12-11 18:24:52 +03:00
static void detach_float(Area *a, Client *c, Bool unmap);
static void resize_float(Frame *f, XRectangle *new, XPoint *pt);
2005-12-11 01:43:45 +03:00
static void select_float(Frame *f, Bool raise);
static Container *get_frames_float(Area *a);
2005-12-11 01:43:45 +03:00
static Action *get_actions_float(Area *a);
static void select_frame(void *obj, char *arg);
Action lfloat_acttbl[] = {
{"select", select_frame},
{0, 0}
};
2005-12-05 04:09:27 +03:00
static Layout lfloat = { "float", init_float, deinit_float, arrange_float, attach_float,
2005-12-11 01:43:45 +03:00
detach_float, resize_float, select_float, get_frames_float, get_actions_float };
2005-12-05 04:09:27 +03:00
void init_layout_float()
{
2005-12-14 21:42:00 +03:00
cext_attach_item(layouts, &lfloat);
2005-12-05 04:09:27 +03:00
}
static void arrange_float(Area *a)
2005-12-05 04:09:27 +03:00
{
}
static void iter_attach_float(void *client, void *area)
{
attach_float(area, client);
}
static void init_float(Area *a)
2005-12-05 04:09:27 +03:00
{
Container *c = cext_emallocz(sizeof(Container));
2005-12-07 20:06:20 +03:00
a->aux = c;
cext_list_iterate(&a->clients, a, iter_attach_float);
}
static void iter_detach_float(void *client, void *area)
{
2005-12-11 18:24:52 +03:00
Area *a = area;
detach_float(a, client, a->page != get_sel_page());
2005-12-05 04:09:27 +03:00
}
static void deinit_float(Area *a)
2005-12-05 04:09:27 +03:00
{
cext_list_iterate(&a->clients, a, iter_detach_float);
free(a->aux);
a->aux = nil;
2005-12-05 04:09:27 +03:00
}
static Bool attach_float(Area *a, Client *c)
2005-12-05 04:09:27 +03:00
{
Frame *f = get_sel_frame_of_area(a);
2005-12-05 22:38:03 +03:00
/* check for tabbing? */
if (f && (((char *) f->file[F_LOCKED]->content)[0] == '1'))
f = 0;
if (!f) {
if (c->rect.y < area_rect.y)
c->rect.y = area_rect.y;
if (c->rect.x < area_rect.x)
c->rect.x = area_rect.x;
2005-12-05 22:38:03 +03:00
f = alloc_frame(&c->rect);
attach_frame_to_area(a, f);
cext_attach_item((Container *)a->aux, f);
2005-12-05 22:38:03 +03:00
}
attach_client_to_frame(f, c);
if (a->page == get_sel_page())
XMapWindow(dpy, f->win);
2005-12-11 01:43:45 +03:00
select_float(f, True);
return True;
2005-12-05 04:09:27 +03:00
}
2005-12-11 18:24:52 +03:00
static void detach_float(Area *a, Client *c, Bool unmap)
2005-12-05 04:09:27 +03:00
{
2005-12-06 00:22:24 +03:00
Frame *f = c->frame;
2005-12-11 18:24:52 +03:00
detach_client_from_frame(c, unmap);
if (!cext_sizeof_container(&f->clients)) {
detach_frame_from_area(f);
cext_detach_item((Container *)a->aux, f);
2005-12-06 00:22:24 +03:00
destroy_frame(f);
}
2005-12-05 04:09:27 +03:00
}
static void resize_float(Frame *f, XRectangle *new, XPoint *pt)
2005-12-05 04:09:27 +03:00
{
f->rect = *new;
2005-12-05 04:09:27 +03:00
}
2005-12-11 01:43:45 +03:00
static void select_float(Frame *f, Bool raise)
{
Area *a = f->area;
Frame *old = get_sel_frame();
2005-12-11 01:43:45 +03:00
sel_client(cext_stack_get_top_item(&f->clients));
cext_stack_top_item(a->aux, f);
a->file[A_SEL_FRAME]->content = f->file[F_PREFIX]->content;
2005-12-11 17:47:23 +03:00
if (raise) {
2005-12-11 01:43:45 +03:00
XRaiseWindow(dpy, f->win);
2005-12-11 17:47:23 +03:00
center_pointer(f);
}
if (old && old != f)
draw_frame(old);
draw_frame(f);
2005-12-11 01:43:45 +03:00
}
static Container *get_frames_float(Area *a)
{
return a->aux;
}
static void select_frame(void *obj, char *arg)
{
2005-12-11 01:43:45 +03:00
Area *a = obj;
Container *c = a->aux;
Frame *f;
f = cext_stack_get_top_item(c);
if (!f || !arg)
return;
if (!strncmp(arg, "prev", 5))
f = cext_list_get_prev_item(c, f);
else if (!strncmp(arg, "next", 5))
f = cext_list_get_next_item(c, f);
else
f = cext_list_get_item(c, blitz_strtonum(arg, 0, cext_sizeof_container(c) - 1));
select_float(f, True);
center_pointer(f);
}
2005-12-11 01:43:45 +03:00
static Action *get_actions_float(Area *a)
{
2005-12-11 01:43:45 +03:00
return lfloat_acttbl;
}