2005-11-18 18:54:58 +03:00
|
|
|
/*
|
2006-01-20 17:20:24 +03:00
|
|
|
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
2005-11-18 18:54:58 +03:00
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-12-27 23:13:50 +03:00
|
|
|
#include <X11/Xatom.h>
|
2005-11-18 18:54:58 +03:00
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
Page *
|
|
|
|
alloc_page()
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +03:00
|
|
|
static unsigned short id = 1;
|
2006-01-26 21:58:30 +03:00
|
|
|
Page *p = cext_emallocz(sizeof(Page));
|
2005-12-21 18:18:11 +03:00
|
|
|
|
2006-02-03 18:15:36 +03:00
|
|
|
p->id = id++;
|
2006-02-10 19:09:59 +03:00
|
|
|
alloc_area(p);
|
2006-01-29 15:41:16 +03:00
|
|
|
page = (Page **)cext_array_attach((void **)page, p, sizeof(Page *), &pagesz);
|
2006-02-02 15:20:07 +03:00
|
|
|
npage++;
|
2006-01-26 21:58:30 +03:00
|
|
|
focus_page(p);
|
2006-01-21 20:01:28 +03:00
|
|
|
XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL,
|
2006-02-02 15:20:07 +03:00
|
|
|
32, PropModeReplace, (unsigned char *) &npage, 1);
|
2006-01-26 21:58:30 +03:00
|
|
|
return p;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-26 16:16:04 +03:00
|
|
|
destroy_page(Page *p)
|
2005-12-05 03:36:39 +03:00
|
|
|
{
|
2006-01-26 16:16:04 +03:00
|
|
|
unsigned int i;
|
2006-02-16 13:53:10 +03:00
|
|
|
Page *new = p->revert;
|
2006-02-03 18:15:36 +03:00
|
|
|
for(i = 0; i < p->narea; i++)
|
|
|
|
destroy_area(p->area[i]);
|
|
|
|
free(p->area);
|
2006-01-26 16:16:04 +03:00
|
|
|
|
2006-02-11 17:58:47 +03:00
|
|
|
cext_array_detach((void **)page, p, &pagesz);
|
2006-02-02 15:20:07 +03:00
|
|
|
npage--;
|
2005-12-27 23:13:50 +03:00
|
|
|
|
2006-02-16 03:05:16 +03:00
|
|
|
for(i = 0; i < npage; i++) {
|
|
|
|
if(page[i]->revert == p)
|
|
|
|
page[i]->revert = nil;
|
|
|
|
XChangeProperty(dpy, root, net_atoms[NET_NUMBER_OF_DESKTOPS], XA_CARDINAL,
|
|
|
|
32, PropModeReplace, (unsigned char *) &i, 1);
|
|
|
|
}
|
2006-01-23 18:06:14 +03:00
|
|
|
|
2006-02-16 03:05:16 +03:00
|
|
|
free(p);
|
2006-02-16 13:53:10 +03:00
|
|
|
if(npage && new)
|
|
|
|
focus_page(new);
|
|
|
|
else
|
|
|
|
write_event("PN -\n");
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-02-11 17:58:47 +03:00
|
|
|
int
|
|
|
|
page_to_index(Page *p)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < npage; i++)
|
|
|
|
if(p == page[i])
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
void
|
2006-01-26 16:16:04 +03:00
|
|
|
focus_page(Page *p)
|
2005-12-05 03:36:39 +03:00
|
|
|
{
|
2006-02-02 15:20:07 +03:00
|
|
|
Page *old = page ? page[sel] : nil;
|
2006-02-10 19:51:20 +03:00
|
|
|
char buf[16];
|
|
|
|
Client *c;
|
2006-02-11 17:58:47 +03:00
|
|
|
int i = page_to_index(p);
|
2006-01-18 19:45:27 +03:00
|
|
|
|
2006-02-16 13:53:10 +03:00
|
|
|
if(!npage || (i == -1))
|
2006-01-26 16:16:04 +03:00
|
|
|
return;
|
2006-02-16 13:53:10 +03:00
|
|
|
|
|
|
|
if(old && old != p)
|
|
|
|
p->revert = old;
|
2006-02-02 15:20:07 +03:00
|
|
|
sel = i;
|
|
|
|
for(i = 0; i < nclient; i++) {
|
2006-02-10 19:51:20 +03:00
|
|
|
c = client[i];
|
2006-02-12 01:54:00 +03:00
|
|
|
if(old && (old != p) && (c->area && c->area->page == old))
|
2006-01-26 21:58:30 +03:00
|
|
|
XMoveWindow(dpy, c->frame.win, 2 * rect.width, 2 * rect.height);
|
2006-02-11 17:22:42 +03:00
|
|
|
else if(c->area && c->area->page == p) {
|
2006-01-26 21:58:30 +03:00
|
|
|
XMoveWindow(dpy, c->frame.win, c->frame.rect.x, c->frame.rect.y);
|
2006-02-08 20:33:01 +03:00
|
|
|
draw_client(c);
|
|
|
|
}
|
2006-01-26 16:16:04 +03:00
|
|
|
}
|
2006-02-10 19:51:20 +03:00
|
|
|
if((c = sel_client_of_page(p)))
|
2006-02-16 03:55:21 +03:00
|
|
|
focus_client(c, False);
|
2006-02-11 17:22:42 +03:00
|
|
|
snprintf(buf, sizeof(buf), "PN %d\n", sel + 1);
|
2006-02-16 13:53:10 +03:00
|
|
|
write_event(buf);
|
2006-01-12 20:03:49 +03:00
|
|
|
XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL,
|
2006-02-02 15:20:07 +03:00
|
|
|
32, PropModeReplace, (unsigned char *) &sel, 1);
|
2006-02-04 21:55:37 +03:00
|
|
|
XSync(dpy, False);
|
2005-12-07 03:37:37 +03:00
|
|
|
}
|
|
|
|
|
2005-12-21 18:18:11 +03:00
|
|
|
XRectangle *
|
|
|
|
rectangles(unsigned int *num)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2005-12-21 18:18:11 +03:00
|
|
|
XRectangle *result = 0;
|
|
|
|
int i, j = 0;
|
|
|
|
Window d1, d2;
|
|
|
|
Window *wins;
|
|
|
|
XWindowAttributes wa;
|
|
|
|
XRectangle r;
|
|
|
|
|
|
|
|
if(XQueryTree(dpy, root, &d1, &d2, &wins, num)) {
|
|
|
|
result = cext_emallocz(*num * sizeof(XRectangle));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-03 13:36:47 +03:00
|
|
|
if(wins)
|
2005-12-21 18:18:11 +03:00
|
|
|
XFree(wins);
|
|
|
|
*num = j;
|
|
|
|
return result;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|
|
|
|
|
2006-02-02 15:20:07 +03:00
|
|
|
int
|
2006-02-10 17:59:30 +03:00
|
|
|
pid_to_index(unsigned short id)
|
2006-02-02 15:20:07 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-02-03 18:15:36 +03:00
|
|
|
for(i = 0; i < npage; i++)
|
|
|
|
if(page[i]->id == id)
|
2006-02-02 15:20:07 +03:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2006-02-10 19:51:20 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
select_page(char *arg)
|
|
|
|
{
|
|
|
|
size_t new = sel;
|
|
|
|
const char *err;
|
|
|
|
|
2006-02-13 12:31:38 +03:00
|
|
|
if(!npage)
|
2006-02-10 19:51:20 +03:00
|
|
|
return;
|
|
|
|
if(!strncmp(arg, "prev", 5)) {
|
2006-02-11 17:22:42 +03:00
|
|
|
if(!new)
|
|
|
|
new = npage;
|
2006-02-10 19:51:20 +03:00
|
|
|
new--;
|
|
|
|
} else if(!strncmp(arg, "next", 5)) {
|
2006-02-11 17:22:42 +03:00
|
|
|
if(new < npage - 1)
|
2006-02-10 19:51:20 +03:00
|
|
|
new++;
|
|
|
|
else
|
|
|
|
new = 0;
|
|
|
|
} else {
|
2006-02-12 01:54:00 +03:00
|
|
|
int idx = cext_strtonum(arg, 1, npage, &err);
|
2006-02-11 17:22:42 +03:00
|
|
|
if(idx && (idx - 1 < npage))
|
2006-02-12 01:54:00 +03:00
|
|
|
new = idx - 1;
|
2006-02-10 19:51:20 +03:00
|
|
|
}
|
|
|
|
focus_page(page[new]);
|
|
|
|
}
|