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 <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
2005-12-05 01:45:59 +03:00
|
|
|
static void select_client(void *obj, char *cmd);
|
|
|
|
static void handle_after_write_frame(IXPServer * s, File * f);
|
|
|
|
static void handle_before_read_frame(IXPServer * s, File * f);
|
2005-11-18 18:54:58 +03:00
|
|
|
|
|
|
|
/* action table for /frame/?/ namespace */
|
2005-12-05 01:45:59 +03:00
|
|
|
Action frame_acttbl[] = {
|
2005-11-18 18:54:58 +03:00
|
|
|
{"select", select_client},
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2005-12-05 22:38:03 +03:00
|
|
|
Frame *alloc_frame(XRectangle * r)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
|
|
|
XSetWindowAttributes wa;
|
2005-12-05 01:45:59 +03:00
|
|
|
static int id = 0;
|
|
|
|
char buf[MAX_BUF];
|
2005-12-08 03:31:23 +03:00
|
|
|
Frame *f = (Frame *) cext_emallocz(sizeof(Frame));
|
2005-12-05 22:38:03 +03:00
|
|
|
int bw, th;
|
2005-11-18 18:54:58 +03:00
|
|
|
|
|
|
|
f->rect = *r;
|
|
|
|
f->cursor = normal_cursor;
|
|
|
|
|
2005-12-05 22:38:03 +03:00
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d", id);
|
|
|
|
f->file[F_PREFIX] = ixp_create(ixps, buf);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/c", id);
|
|
|
|
f->file[F_CLIENT_PREFIX] = ixp_create(ixps, buf);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/c/sel", id);
|
|
|
|
f->file[F_SEL_CLIENT] = ixp_create(ixps, buf);
|
|
|
|
f->file[F_SEL_CLIENT]->bind = 1;
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/ctl", id);
|
|
|
|
f->file[F_CTL] = ixp_create(ixps, buf);
|
|
|
|
f->file[F_CTL]->after_write = handle_after_write_frame;
|
2005-12-06 01:51:01 +03:00
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/geometry", id);
|
|
|
|
f->file[F_GEOMETRY] = ixp_create(ixps, buf);
|
|
|
|
f->file[F_GEOMETRY]->before_read = handle_before_read_frame;
|
|
|
|
f->file[F_GEOMETRY]->after_write = handle_after_write_frame;
|
2005-12-05 22:38:03 +03:00
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/border", id);
|
|
|
|
f->file[F_BORDER] = wmii_create_ixpfile(ixps, buf, def[WM_BORDER]->content);
|
|
|
|
f->file[F_BORDER]->after_write = handle_after_write_frame;
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/tab", id);
|
|
|
|
f->file[F_TAB] = wmii_create_ixpfile(ixps, buf, def[WM_TAB]->content);
|
|
|
|
f->file[F_TAB]->after_write = handle_after_write_frame;
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/handleinc", id);
|
|
|
|
f->file[F_HANDLE_INC] = wmii_create_ixpfile(ixps, buf, def[WM_HANDLE_INC]->content);
|
|
|
|
f->file[F_HANDLE_INC]->after_write = handle_after_write_frame;
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/locked", id);
|
|
|
|
f->file[F_LOCKED] = wmii_create_ixpfile(ixps, buf, def[WM_LOCKED]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/sstyle/bgcolor", id);
|
|
|
|
f->file[F_SEL_BG_COLOR] = wmii_create_ixpfile(ixps, buf, def[WM_SEL_BG_COLOR]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/sstyle/fgcolor", id);
|
|
|
|
f->file[F_SEL_FG_COLOR] = wmii_create_ixpfile(ixps, buf, def[WM_SEL_FG_COLOR]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/sstyle/bordercolor", id);
|
|
|
|
f->file[F_SEL_BORDER_COLOR] = wmii_create_ixpfile(ixps, buf, def[WM_SEL_BORDER_COLOR]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/nstyle/bgcolor", id);
|
|
|
|
f->file[F_NORM_BG_COLOR] = wmii_create_ixpfile(ixps, buf, def[WM_NORM_BG_COLOR]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/nstyle/fgcolor", id);
|
|
|
|
f->file[F_NORM_FG_COLOR] = wmii_create_ixpfile(ixps, buf, def[WM_NORM_FG_COLOR]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/nstyle/bordercolor", id);
|
|
|
|
f->file[F_NORM_BORDER_COLOR] = wmii_create_ixpfile(ixps, buf, def[WM_NORM_BORDER_COLOR]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/event/b2press", id);
|
|
|
|
f->file[F_EVENT_B2PRESS] = wmii_create_ixpfile(ixps, buf, def[WM_EVENT_B2PRESS]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/event/b3press", id);
|
|
|
|
f->file[F_EVENT_B3PRESS] = wmii_create_ixpfile(ixps, buf, def[WM_EVENT_B3PRESS]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/event/b4press", id);
|
|
|
|
f->file[F_EVENT_B4PRESS] = wmii_create_ixpfile(ixps, buf, def[WM_EVENT_B4PRESS]->content);
|
|
|
|
snprintf(buf, MAX_BUF, "/detached/f/%d/event/b5press", id);
|
|
|
|
f->file[F_EVENT_B5PRESS] = wmii_create_ixpfile(ixps, buf, def[WM_EVENT_B5PRESS]->content);
|
2005-11-18 18:54:58 +03:00
|
|
|
id++;
|
|
|
|
|
|
|
|
wa.override_redirect = 1;
|
|
|
|
wa.background_pixmap = ParentRelative;
|
|
|
|
wa.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask
|
|
|
|
| PointerMotionMask | SubstructureRedirectMask
|
|
|
|
| SubstructureNotifyMask;
|
|
|
|
|
2005-12-05 22:38:03 +03:00
|
|
|
bw = border_width(f);
|
|
|
|
th = tab_height(f);
|
|
|
|
f->rect.width += 2 * bw;
|
|
|
|
f->rect.height += bw + (th ? th : bw);
|
|
|
|
f->win = XCreateWindow(dpy, root, f->rect.x, f->rect.y, f->rect.width,
|
|
|
|
f->rect.height, 0, DefaultDepth(dpy, screen_num),
|
|
|
|
CopyFromParent, DefaultVisual(dpy, screen_num),
|
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
2005-11-18 18:54:58 +03:00
|
|
|
XDefineCursor(dpy, f->win, f->cursor);
|
|
|
|
f->gc = XCreateGC(dpy, f->win, 0, 0);
|
|
|
|
XSync(dpy, False);
|
2005-12-07 00:14:35 +03:00
|
|
|
cext_attach_item(&frames, f);
|
2005-11-18 18:54:58 +03:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2005-12-07 03:37:37 +03:00
|
|
|
void sel_frame(Frame * f, Bool raise)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
|
|
|
Area *a = f->area;
|
2005-12-08 19:35:40 +03:00
|
|
|
sel_client(cext_stack_get_top_item(&f->clients));
|
|
|
|
cext_stack_top_item(a->layout->get_frames(a), f);
|
2005-12-05 22:38:03 +03:00
|
|
|
a->file[A_SEL_FRAME]->content = f->file[F_PREFIX]->content;
|
2005-12-06 00:22:24 +03:00
|
|
|
if (raise)
|
2005-11-18 18:54:58 +03:00
|
|
|
XRaiseWindow(dpy, f->win);
|
|
|
|
}
|
|
|
|
|
2005-12-07 00:14:35 +03:00
|
|
|
static int comp_frame_win(void *pattern, void *frame)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 00:14:35 +03:00
|
|
|
Window w = *(Window *)pattern;
|
|
|
|
Frame *f = frame;
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2005-12-07 00:14:35 +03:00
|
|
|
return w == f->win;
|
|
|
|
}
|
|
|
|
|
|
|
|
Frame *win_to_frame(Window w)
|
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
return cext_find_item(&frames, &w, comp_frame_win);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-05 01:45:59 +03:00
|
|
|
void destroy_frame(Frame * f)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
cext_detach_item(&frames, f);
|
2005-11-18 18:54:58 +03:00
|
|
|
XFreeGC(dpy, f->gc);
|
|
|
|
XDestroyWindow(dpy, f->win);
|
2005-12-05 22:38:03 +03:00
|
|
|
ixp_remove_file(ixps, f->file[F_PREFIX]);
|
2005-11-18 18:54:58 +03:00
|
|
|
if (ixps->errstr)
|
2005-12-03 14:36:00 +03:00
|
|
|
fprintf(stderr, "wmiiwm: destroy_frame(): %s\n", ixps->errstr);
|
2005-11-18 18:54:58 +03:00
|
|
|
free(f);
|
|
|
|
}
|
|
|
|
|
2005-12-05 03:36:39 +03:00
|
|
|
unsigned int tab_height(Frame * f)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-05 22:38:03 +03:00
|
|
|
if (_strtonum(f->file[F_TAB]->content, 0, 1))
|
2005-12-05 03:36:39 +03:00
|
|
|
return font->ascent + font->descent + 4;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int border_width(Frame * f)
|
|
|
|
{
|
2005-12-05 22:38:03 +03:00
|
|
|
if (_strtonum(f->file[F_BORDER]->content, 0, 1))
|
2005-12-05 03:36:39 +03:00
|
|
|
return BORDER_WIDTH;
|
|
|
|
return 0;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-07 03:37:37 +03:00
|
|
|
typedef struct {
|
|
|
|
unsigned int tabh;
|
|
|
|
unsigned int bw;
|
|
|
|
} Twouint;
|
|
|
|
|
|
|
|
static void iter_resize_client(void *item, void *aux)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
Client *c = item;
|
|
|
|
Twouint *v = aux;
|
|
|
|
c->rect.x = v->bw;
|
|
|
|
c->rect.y = v->tabh ? v->tabh : v->bw;
|
|
|
|
c->rect.width = c->frame->rect.width - 2 * v->bw;
|
|
|
|
c->rect.height = c->frame->rect.height - v->bw - (v->tabh ? v->tabh : v->bw);
|
|
|
|
XMoveResizeWindow(dpy, c->win, c->rect.x, c->rect.y, c->rect.width, c->rect.height);
|
|
|
|
configure_client(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resize_clients(Frame * f, int tabh, int bw)
|
|
|
|
{
|
|
|
|
Twouint aux = { tabh, bw };
|
|
|
|
cext_iterate(&f->clients, &aux, iter_resize_client);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-05 01:45:59 +03:00
|
|
|
static void check_dimensions(Frame * f, unsigned int tabh, unsigned int bw)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
Client *c = get_sel_client();
|
2005-11-18 18:54:58 +03:00
|
|
|
if (!c)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (c->size.flags & PMinSize) {
|
2005-11-22 13:05:39 +03:00
|
|
|
if (f->rect.width - 2 * bw < c->size.min_width) {
|
|
|
|
f->rect.width = c->size.min_width + 2 * bw;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2005-11-22 13:05:39 +03:00
|
|
|
if (f->rect.height - bw - (tabh ? tabh : bw) < c->size.min_height) {
|
|
|
|
f->rect.height = c->size.min_height + bw + (tabh ? tabh : bw);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c->size.flags & PMaxSize) {
|
2005-11-22 13:05:39 +03:00
|
|
|
if (f->rect.width - 2 * bw > c->size.max_width) {
|
|
|
|
f->rect.width = c->size.max_width + 2 * bw;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2005-11-22 13:05:39 +03:00
|
|
|
if (f->rect.height - bw - (tabh ? tabh : bw) > c->size.max_height) {
|
|
|
|
f->rect.height = c->size.max_height + bw + (tabh ? tabh : bw);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-06 01:51:01 +03:00
|
|
|
static void resize_incremental(Frame * f, unsigned int tabh, unsigned int bw)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
Client *c = get_sel_client();
|
2005-11-18 18:54:58 +03:00
|
|
|
if (!c)
|
|
|
|
return;
|
2005-11-22 13:05:39 +03:00
|
|
|
/* increment stuff, see chapter 4.1.2.3 of the ICCCM Manual */
|
2005-11-18 18:54:58 +03:00
|
|
|
if (c->size.flags & PResizeInc) {
|
2005-12-05 01:45:59 +03:00
|
|
|
int base_width = 0, base_height = 0;
|
2005-11-18 18:54:58 +03:00
|
|
|
|
|
|
|
if (c->size.flags & PBaseSize) {
|
|
|
|
base_width = c->size.base_width;
|
|
|
|
base_height = c->size.base_height;
|
|
|
|
} else if (c->size.flags & PMinSize) {
|
2005-12-05 04:50:02 +03:00
|
|
|
/* base_{width,height} default to min_{width,height} */
|
2005-11-18 18:54:58 +03:00
|
|
|
base_width = c->size.min_width;
|
|
|
|
base_height = c->size.min_height;
|
|
|
|
}
|
2005-11-22 13:05:39 +03:00
|
|
|
/* client_width = base_width + i * c->size.width_inc for an integer i */
|
2005-12-05 01:45:59 +03:00
|
|
|
f->rect.width -=
|
|
|
|
(f->rect.width - 2 * bw - base_width) % c->size.width_inc;
|
|
|
|
f->rect.height -=
|
|
|
|
(f->rect.height - bw - (tabh ? tabh : bw) -
|
|
|
|
base_height) % c->size.height_inc;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-06 01:51:01 +03:00
|
|
|
void resize_frame(Frame * f, XRectangle * r, XPoint * pt)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-06 01:51:01 +03:00
|
|
|
Area *a = f->area;
|
2005-12-05 01:45:59 +03:00
|
|
|
unsigned int tabh = tab_height(f);
|
|
|
|
unsigned int bw = border_width(f);
|
2005-12-06 01:51:01 +03:00
|
|
|
|
|
|
|
a->layout->resize(f, r, pt);
|
2005-11-18 18:54:58 +03:00
|
|
|
|
|
|
|
/* resize if client requests special size */
|
|
|
|
check_dimensions(f, tabh, bw);
|
|
|
|
|
2005-12-07 19:30:34 +03:00
|
|
|
if (f->file[F_HANDLE_INC]->content && ((char *) f->file[F_HANDLE_INC]->content)[0] == '1')
|
2005-11-18 18:54:58 +03:00
|
|
|
resize_incremental(f, tabh, bw);
|
|
|
|
|
2005-12-06 01:51:01 +03:00
|
|
|
XMoveResizeWindow(dpy, f->win, f->rect.x, f->rect.y, f->rect.width, f->rect.height);
|
2005-12-07 03:37:37 +03:00
|
|
|
resize_clients(f, (tabh ? tabh : bw), bw);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-05 01:45:59 +03:00
|
|
|
void draw_tab(Frame * f, char *text, int x, int y, int w, int h, int sel)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-05 01:45:59 +03:00
|
|
|
Draw d = { 0 };
|
2005-11-18 18:54:58 +03:00
|
|
|
d.drawable = f->win;
|
|
|
|
d.gc = f->gc;
|
|
|
|
d.rect.x = x;
|
|
|
|
d.rect.y = y;
|
|
|
|
d.rect.width = w;
|
|
|
|
d.rect.height = h;
|
|
|
|
d.data = text;
|
2005-12-05 22:38:03 +03:00
|
|
|
d.font = font;
|
2005-11-18 18:54:58 +03:00
|
|
|
if (sel) {
|
2005-12-05 22:38:03 +03:00
|
|
|
d.bg = blitz_loadcolor(dpy, screen_num, f->file[F_SEL_BG_COLOR]->content);
|
|
|
|
d.fg = blitz_loadcolor(dpy, screen_num, f->file[F_SEL_FG_COLOR]->content);
|
|
|
|
d.border = blitz_loadcolor(dpy, screen_num, f->file[F_SEL_BORDER_COLOR]->content);
|
2005-11-18 18:54:58 +03:00
|
|
|
} else {
|
2005-12-05 22:38:03 +03:00
|
|
|
d.bg = blitz_loadcolor(dpy, screen_num, f->file[F_NORM_BG_COLOR]->content);
|
|
|
|
d.fg = blitz_loadcolor(dpy, screen_num, f->file[F_NORM_FG_COLOR]->content);
|
|
|
|
d.border = blitz_loadcolor(dpy, screen_num, f->file[F_NORM_BORDER_COLOR]->content);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
XSync(dpy, False);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-12-05 22:38:03 +03:00
|
|
|
* Assumes following file:
|
2005-11-18 18:54:58 +03:00
|
|
|
*
|
|
|
|
* ./sel-style/text-font "<value>"
|
|
|
|
* ./sel-style/text-size "<int>"
|
|
|
|
* ./sel-style/text-color "#RRGGBBAA"
|
|
|
|
* ./sel-style/bg-color "#RRGGBBAA"
|
|
|
|
* ./sel-style/border-color "#RRGGBBAA [#RRGGBBAA [#RRGGBBAA [#RRGGBBAA]]]"
|
|
|
|
* ./norm-style/text-font "<value>"
|
|
|
|
* ./norm-style/text-size "<int>"
|
|
|
|
* ./norm-style/text-color "#RRGGBBAA"
|
|
|
|
* ./norm-style/bg-color "#RRGGBBAA"
|
|
|
|
* ./norm-style/border-color "#RRGGBBAA [#RRGGBBAA [#RRGGBBAA [#RRGGBBAA]]]"
|
|
|
|
*/
|
2005-12-07 03:37:37 +03:00
|
|
|
void draw_frame(void *frame, void *aux)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
Frame *f = frame;
|
2005-12-05 01:45:59 +03:00
|
|
|
Draw d = { 0 };
|
|
|
|
int bw = border_width(f);
|
|
|
|
XRectangle notch;
|
2005-11-18 18:54:58 +03:00
|
|
|
if (bw) {
|
|
|
|
notch.x = bw;
|
|
|
|
notch.y = bw;
|
2005-11-22 13:05:39 +03:00
|
|
|
notch.width = f->rect.width - 2 * bw;
|
|
|
|
notch.height = f->rect.height - 2 * bw;
|
2005-11-18 18:54:58 +03:00
|
|
|
d.drawable = f->win;
|
2005-12-05 22:38:03 +03:00
|
|
|
d.font = font;
|
2005-11-18 18:54:58 +03:00
|
|
|
d.gc = f->gc;
|
|
|
|
|
|
|
|
/* define ground plate (i = 0) */
|
2005-12-07 03:37:37 +03:00
|
|
|
if (f == get_sel_frame()) {
|
2005-12-05 22:38:03 +03:00
|
|
|
d.bg = blitz_loadcolor(dpy, screen_num, f->file[F_SEL_BG_COLOR]->content);
|
|
|
|
d.fg = blitz_loadcolor(dpy, screen_num, f->file[F_SEL_FG_COLOR]->content);
|
|
|
|
d.border = blitz_loadcolor(dpy, screen_num, f->file[F_SEL_BORDER_COLOR]->content);
|
2005-11-18 18:54:58 +03:00
|
|
|
} else {
|
2005-12-05 22:38:03 +03:00
|
|
|
d.bg = blitz_loadcolor(dpy, screen_num, f->file[F_NORM_BG_COLOR]->content);
|
|
|
|
d.fg = blitz_loadcolor(dpy, screen_num, f->file[F_NORM_FG_COLOR]->content);
|
|
|
|
d.border = blitz_loadcolor(dpy, screen_num, f->file[F_NORM_BORDER_COLOR]->content);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2005-11-22 13:05:39 +03:00
|
|
|
d.rect = f->rect;
|
2005-11-18 18:54:58 +03:00
|
|
|
d.rect.x = d.rect.y = 0;
|
|
|
|
d.notch = ¬ch;
|
|
|
|
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
}
|
|
|
|
draw_clients(f);
|
|
|
|
XSync(dpy, False);
|
|
|
|
}
|
|
|
|
|
2005-12-05 01:45:59 +03:00
|
|
|
void handle_frame_buttonpress(XButtonEvent * e, Frame * f)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-06 01:51:01 +03:00
|
|
|
Align align;
|
2005-12-07 03:37:37 +03:00
|
|
|
size_t size = cext_sizeof(&f->clients);
|
|
|
|
int bindex, cindex = e->x / f->rect.width / size;
|
2005-12-08 19:35:40 +03:00
|
|
|
Client *c = cext_list_get_item(&f->clients, cindex);
|
2005-12-07 03:37:37 +03:00
|
|
|
XRaiseWindow(dpy, f->win);
|
|
|
|
if (get_sel_client() != c) {
|
|
|
|
sel_client(c);
|
|
|
|
draw_frame(f, nil);
|
2005-11-18 18:54:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (e->button == Button1) {
|
2005-12-06 01:51:01 +03:00
|
|
|
align = cursor_to_align(f->cursor);
|
|
|
|
if (align == CENTER)
|
|
|
|
mouse_move(f);
|
|
|
|
else
|
|
|
|
mouse_resize(f, align);
|
2005-11-18 18:54:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
bindex = F_EVENT_B2PRESS - 2 + e->button;
|
|
|
|
/* frame mouse handling */
|
2005-12-05 22:38:03 +03:00
|
|
|
if (f->file[bindex]->content)
|
|
|
|
spawn(dpy, f->file[bindex]->content);
|
2005-12-07 03:37:37 +03:00
|
|
|
draw_frame(f, nil);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-05 01:45:59 +03:00
|
|
|
void attach_client_to_frame(Frame * f, Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-05 22:38:03 +03:00
|
|
|
wmii_move_ixpfile(c->file[C_PREFIX], f->file[F_CLIENT_PREFIX]);
|
|
|
|
f->file[F_SEL_CLIENT]->content = c->file[C_PREFIX]->content;
|
2005-12-07 03:37:37 +03:00
|
|
|
cext_attach_item(&f->clients, c);
|
2005-11-18 18:54:58 +03:00
|
|
|
c->frame = f;
|
2005-11-22 13:05:39 +03:00
|
|
|
reparent_client(c, f->win, border_width(f), tab_height(f));
|
2005-12-06 01:51:01 +03:00
|
|
|
resize_frame(f, &f->rect, 0);
|
2005-11-18 18:54:58 +03:00
|
|
|
show_client(c);
|
2005-12-06 00:22:24 +03:00
|
|
|
sel_client(c);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-06 00:22:24 +03:00
|
|
|
void detach_client_from_frame(Client * c)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
Client *client;
|
2005-12-05 01:45:59 +03:00
|
|
|
Frame *f = c->frame;
|
2005-12-05 22:38:03 +03:00
|
|
|
wmii_move_ixpfile(c->file[C_PREFIX], def[WM_DETACHED_CLIENT]);
|
2005-11-18 18:54:58 +03:00
|
|
|
c->frame = 0;
|
2005-12-07 03:37:37 +03:00
|
|
|
cext_detach_item(&f->clients, c);
|
2005-12-06 00:22:24 +03:00
|
|
|
if (!c->destroyed) {
|
|
|
|
if (f) {
|
2005-11-18 18:54:58 +03:00
|
|
|
hide_client(c);
|
2005-12-07 03:37:37 +03:00
|
|
|
cext_attach_item(&detached, c);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2005-11-22 13:05:39 +03:00
|
|
|
reparent_client(c, root, border_width(f), tab_height(f));
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2005-12-08 19:35:40 +03:00
|
|
|
if ((client = cext_stack_get_top_item(&f->clients))) {
|
2005-12-07 03:37:37 +03:00
|
|
|
sel_client(client);
|
|
|
|
draw_frame(f, nil);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-05 01:45:59 +03:00
|
|
|
static void select_client(void *obj, char *cmd)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-05 01:45:59 +03:00
|
|
|
Frame *f = obj;
|
2005-12-07 03:37:37 +03:00
|
|
|
size_t size = cext_sizeof(&f->clients);
|
2005-11-18 18:54:58 +03:00
|
|
|
if (!f || !cmd || size == 1)
|
|
|
|
return;
|
2005-12-07 03:37:37 +03:00
|
|
|
if (!strncmp(cmd, "prev", 5))
|
2005-12-08 19:35:40 +03:00
|
|
|
cext_stack_top_item(&f->clients, cext_stack_get_up_item(&f->clients, cext_stack_get_top_item(&f->clients)));
|
2005-12-07 03:37:37 +03:00
|
|
|
else if (!strncmp(cmd, "next", 5))
|
2005-12-08 19:35:40 +03:00
|
|
|
cext_stack_top_item(&f->clients, cext_stack_get_down_item(&f->clients, cext_stack_get_top_item(&f->clients)));
|
|
|
|
sel_client(cext_stack_get_top_item(&f->clients));
|
2005-12-07 03:37:37 +03:00
|
|
|
draw_frame(f, nil);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-07 03:37:37 +03:00
|
|
|
static void iter_before_read_frame(void *item, void *aux)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
Frame *f = item;
|
|
|
|
File *file = aux;
|
|
|
|
if (file == f->file[F_GEOMETRY]) {
|
|
|
|
char buf[64];
|
|
|
|
snprintf(buf, 64, "%d,%d,%d,%d", f->rect.x, f->rect.y, f->rect.width, f->rect.height);
|
|
|
|
if (file->content)
|
|
|
|
free(file->content);
|
|
|
|
file->content = cext_estrdup(buf);
|
|
|
|
file->size = strlen(buf);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-07 03:37:37 +03:00
|
|
|
static void handle_before_read_frame(IXPServer *s, File *f)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-07 03:37:37 +03:00
|
|
|
cext_iterate(&frames, f, iter_before_read_frame);
|
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2005-12-07 03:37:37 +03:00
|
|
|
static void iter_after_write_frame(void *item, void *aux)
|
|
|
|
{
|
|
|
|
Frame *f = item;
|
|
|
|
File *file = aux;
|
|
|
|
if (file == f->file[F_CTL]) {
|
|
|
|
run_action(file, f, frame_acttbl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (file == f->file[F_TAB] || file == f->file[F_BORDER] || file == f->file[F_HANDLE_INC]) {
|
|
|
|
f->area->layout->arrange(f->area);
|
|
|
|
draw_page(f->area->page);
|
|
|
|
return;
|
|
|
|
} else if (file == f->file[F_GEOMETRY]) {
|
|
|
|
char *size = f->file[F_GEOMETRY]->content;
|
|
|
|
if (size && strrchr(size, ',')) {
|
|
|
|
XRectangle frect;
|
|
|
|
blitz_strtorect(&rect, &frect, size);
|
|
|
|
resize_frame(f, &frect, 0);
|
|
|
|
draw_page(f->area->page);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
2005-12-07 03:37:37 +03:00
|
|
|
return;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
}
|
2005-12-06 20:58:52 +03:00
|
|
|
|
2005-12-07 03:37:37 +03:00
|
|
|
static void handle_after_write_frame(IXPServer * s, File * f)
|
|
|
|
{
|
|
|
|
cext_iterate(&frames, f, iter_after_write_frame);
|
|
|
|
}
|
|
|
|
|
2005-12-06 20:58:52 +03:00
|
|
|
Frame *get_sel_frame_of_area(Area *a)
|
|
|
|
{
|
2005-12-08 19:35:40 +03:00
|
|
|
return cext_stack_get_top_item(a->layout->get_frames(a));
|
2005-12-06 20:58:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Frame *get_sel_frame()
|
|
|
|
{
|
|
|
|
Page *p = get_sel_page();
|
|
|
|
if (!p)
|
|
|
|
return nil;
|
|
|
|
return get_sel_frame_of_area(get_sel_area(p));
|
|
|
|
}
|