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"
|
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
static void handle_after_write_page(IXPServer *s, File *file);
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
static void toggle_area(void *obj, char *arg);
|
2005-12-12 19:04:40 +03:00
|
|
|
|
2005-12-06 01:51:01 +03:00
|
|
|
/* action table for /?/ namespace */
|
2005-12-05 01:45:59 +03:00
|
|
|
Action page_acttbl[] = {
|
2005-12-16 04:59:27 +03:00
|
|
|
{"toggle", toggle_area},
|
2005-11-18 18:54:58 +03:00
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2005-12-05 22:38:03 +03:00
|
|
|
Page *alloc_page()
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-16 04:59:27 +03:00
|
|
|
Page *p, *new = cext_emallocz(sizeof(Page));
|
2005-12-06 01:51:01 +03:00
|
|
|
char buf[MAX_BUF], buf2[16];
|
2005-12-16 04:59:27 +03:00
|
|
|
|
|
|
|
snprintf(buf2, sizeof(buf2), "%d", npages);
|
|
|
|
snprintf(buf, sizeof(buf), "/%d", npages);
|
|
|
|
new->file[P_PREFIX] = ixp_create(ixps, buf);
|
|
|
|
snprintf(buf, sizeof(buf), "/%d/name", npages);
|
|
|
|
new->file[P_NAME] = wmii_create_ixpfile(ixps, buf, buf2);
|
|
|
|
snprintf(buf, sizeof(buf), "/%d/layout/", npages);
|
|
|
|
new->file[P_AREA_PREFIX] = ixp_create(ixps, buf);
|
|
|
|
snprintf(buf, sizeof(buf), "/%d/layout/sel", npages);
|
|
|
|
new->file[P_SEL_AREA] = ixp_create(ixps, buf);
|
|
|
|
new->file[P_SEL_AREA]->bind = 1; /* mount point */
|
|
|
|
snprintf(buf, sizeof(buf), "/%d/ctl", npages);
|
|
|
|
new->file[P_CTL] = ixp_create(ixps, buf);
|
|
|
|
new->file[P_CTL]->after_write = handle_after_write_page;
|
|
|
|
new->floating = alloc_area(new, "float");
|
|
|
|
new->sel = new->managed = alloc_area(new, def[WM_LAYOUT]->content);
|
|
|
|
for (p = pages; p && p->next; p = p->next);
|
|
|
|
if (!p)
|
|
|
|
pages = new;
|
|
|
|
else {
|
|
|
|
new->prev = p;
|
|
|
|
p->next = new;
|
|
|
|
}
|
|
|
|
selpage = new;
|
2005-12-16 22:05:42 +03:00
|
|
|
def[WM_SEL_PAGE]->content = new->file[P_PREFIX]->content;
|
2005-12-09 01:48:32 +03:00
|
|
|
invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]);
|
2005-12-17 16:59:25 +03:00
|
|
|
npages++;
|
2005-12-16 22:05:42 +03:00
|
|
|
return new;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
void destroy_page(Page *p)
|
2005-12-05 03:36:39 +03:00
|
|
|
{
|
2005-12-16 04:59:27 +03:00
|
|
|
destroy_area(p->floating);
|
|
|
|
destroy_area(p->managed);
|
2005-12-05 04:50:02 +03:00
|
|
|
def[WM_SEL_PAGE]->content = 0;
|
2005-12-05 22:38:03 +03:00
|
|
|
ixp_remove_file(ixps, p->file[P_PREFIX]);
|
2005-12-16 04:59:27 +03:00
|
|
|
if (p == selpage) {
|
|
|
|
if (p->prev)
|
|
|
|
selpage = p->prev;
|
|
|
|
else
|
|
|
|
selpage = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p == pages) {
|
|
|
|
if (p->next)
|
|
|
|
p->next->prev = nil;
|
|
|
|
pages = p->next;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p->prev->next = p->next;
|
|
|
|
if (p->next)
|
|
|
|
p->next->prev = p->prev;
|
|
|
|
}
|
|
|
|
|
2005-11-18 18:54:58 +03:00
|
|
|
free(p);
|
2005-12-16 04:59:27 +03:00
|
|
|
if (!selpage)
|
|
|
|
selpage = pages;
|
2005-12-17 16:59:25 +03:00
|
|
|
npages--;
|
2005-12-16 04:59:27 +03:00
|
|
|
|
|
|
|
if (selpage)
|
|
|
|
focus_page(selpage);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
void focus_page(Page *p)
|
2005-12-05 03:36:39 +03:00
|
|
|
{
|
2005-12-16 04:59:27 +03:00
|
|
|
if (selpage != p)
|
|
|
|
hide_page(selpage);
|
|
|
|
selpage = p;
|
|
|
|
show_page(p);
|
2005-12-07 03:37:37 +03:00
|
|
|
def[WM_SEL_PAGE]->content = p->file[P_PREFIX]->content;
|
2005-12-05 22:38:03 +03:00
|
|
|
invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]);
|
2005-12-16 04:59:27 +03:00
|
|
|
focus_area(sel_area());
|
2005-12-07 03:37:37 +03:00
|
|
|
}
|
|
|
|
|
2005-12-05 01:45:59 +03:00
|
|
|
XRectangle *rectangles(unsigned int *num)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-05 01:45:59 +03:00
|
|
|
XRectangle *result = 0;
|
|
|
|
int i, j = 0;
|
|
|
|
Window d1, d2;
|
|
|
|
Window *wins;
|
2005-11-18 18:54:58 +03:00
|
|
|
XWindowAttributes wa;
|
2005-12-05 01:45:59 +03:00
|
|
|
XRectangle r;
|
2005-11-18 18:54:58 +03:00
|
|
|
|
|
|
|
if (XQueryTree(dpy, root, &d1, &d2, &wins, num)) {
|
2005-12-08 03:31:23 +03:00
|
|
|
result = cext_emallocz(*num * sizeof(XRectangle));
|
2005-11-18 18:54:58 +03:00
|
|
|
for (i = 0; i < *num; i++) {
|
|
|
|
if (!XGetWindowAttributes(dpy, wins[i], &wa))
|
|
|
|
continue;
|
|
|
|
if (wa.override_redirect && (wa.map_state == IsViewable)) {
|
|
|
|
r.x = wa.x;
|
|
|
|
r.y = wa.y;
|
|
|
|
r.width = wa.width;
|
|
|
|
r.height = wa.height;
|
|
|
|
result[j++] = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wins) {
|
|
|
|
XFree(wins);
|
|
|
|
}
|
|
|
|
*num = j;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
void hide_page(Page *p)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-16 04:59:27 +03:00
|
|
|
hide_area(p->managed);
|
|
|
|
hide_area(p->floating);
|
2005-12-07 03:37:37 +03:00
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
void show_page(Page *p)
|
2005-12-07 03:37:37 +03:00
|
|
|
{
|
2005-12-16 04:59:27 +03:00
|
|
|
show_area(p->managed, False);
|
|
|
|
show_area(p->floating, False);
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
static void handle_after_write_page(IXPServer *s, File *file)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-16 04:59:27 +03:00
|
|
|
Page *p;
|
|
|
|
for (p = pages; p; p = p->next) {
|
|
|
|
if (file == p->file[P_CTL]) {
|
|
|
|
run_action(file, p, page_acttbl);
|
|
|
|
return;
|
|
|
|
}
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
static void toggle_area(void *obj, char *arg)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-16 04:59:27 +03:00
|
|
|
Page *p = obj;
|
2005-12-06 20:58:52 +03:00
|
|
|
|
2005-12-16 04:59:27 +03:00
|
|
|
if (p->sel == p->managed)
|
|
|
|
p->sel = p->floating;
|
|
|
|
else
|
|
|
|
p->sel = p->managed;
|
|
|
|
|
2005-12-16 19:18:00 +03:00
|
|
|
focus_area(p->sel);
|
2005-12-16 04:59:27 +03:00
|
|
|
invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]);
|
2005-12-06 20:58:52 +03:00
|
|
|
}
|
2005-12-12 19:04:40 +03:00
|
|
|
|
2005-12-16 19:18:00 +03:00
|
|
|
Page *pageat(unsigned int idx)
|
2005-12-12 19:04:40 +03:00
|
|
|
{
|
2005-12-16 04:59:27 +03:00
|
|
|
unsigned int i = 0;
|
2005-12-17 16:59:25 +03:00
|
|
|
Page *p;
|
|
|
|
for (p = pages; p && i != idx; p = p->next);
|
2005-12-16 04:59:27 +03:00
|
|
|
return p;
|
2005-12-12 19:04:40 +03:00
|
|
|
}
|