modularized focus stuff somewhat (focus_page don't implies focus_client and vice versa)

This commit is contained in:
Anselm R. Garbe 2006-02-28 08:51:53 +01:00
parent 67c0cfbd9b
commit d61117a3db
9 changed files with 77 additions and 76 deletions

View File

@ -91,8 +91,7 @@ select_area(Area *a, char *arg)
}
new = p->area[i];
if(new->nclient)
focus_client(new->client[new->sel], True);
else
focus_client(new->client[new->sel]);
p->sel = i;
}
@ -109,8 +108,9 @@ sendto_area(Area *new, Client *c)
new->client = (Client **)cext_array_attach(
(void **)new->client, c, sizeof(Client *), &new->clientsz);
new->nclient++;
c->area = new;
arrange_column(a);
arrange_column(new);
focus_client(c, True);
focus_client(c);
}

View File

@ -20,7 +20,6 @@ alloc_client(Window w, XWindowAttributes *wa)
long msize;
static unsigned short id = 1;
/* client itself */
c->id = id++;
c->win = w;
c->rect.x = wa->x;
@ -40,7 +39,6 @@ alloc_client(Window w, XWindowAttributes *wa)
free(name.value);
}
/* client.frame */
fwa.override_redirect = 1;
fwa.background_pixmap = ParentRelative;
fwa.event_mask = SubstructureRedirectMask | ExposureMask | ButtonPressMask | PointerMotionMask;
@ -94,27 +92,12 @@ client_focus_event(Client *c)
}
void
focus_client(Client *c, Bool fevent)
focus_client(Client *c)
{
Page *p = page ? page[sel] : nil;
size_t i, j;
Client *old = sel_client();
/* setup indexes */
if(c->area->page != p) {
focus_page(c->area->page);
p = c->area->page;
}
for(i = 0; i < p->narea; i++) {
Area *a = p->area[i];
for(j = 0; j < a->nclient && (c != a->client[j]); j++);
if(j < a->nclient) {
p->sel = i;
a->sel = j;
break;
}
}
c->area->page->sel = area_to_index(c->area);
c->area->sel = client_to_index(c);
if(old && (old != c)) {
c->revert = old;
grab_mouse(old->win, AnyModifier, Button1);
@ -128,7 +111,6 @@ focus_client(Client *c, Bool fevent)
draw_client(c);
XSync(dpy, False);
client_name_event(c);
if(fevent)
client_focus_event(c);
}
@ -388,7 +370,7 @@ attach_client(Client *c)
p = page[sel];
attach_client_to_page(p, c);
focus_client(c, True);
focus_client(c);
}
void
@ -427,7 +409,7 @@ detach_client(Client *c, Bool unmap)
}
c->area = nil;
if(c->revert)
focus_client(c->revert, True);
focus_client(c->revert);
if(c->destroyed)
destroy_client(c);
}
@ -449,7 +431,7 @@ sel_client()
}
Client *
win_to_frame(Window w)
win_to_clientframe(Window w)
{
size_t i;
for(i = 0; (i < clientsz) && client[i]; i++)
@ -580,13 +562,13 @@ select_client(Client *c, char *arg)
return;
i--;
}
focus_client(a->client[i], True);
focus_client(a->client[i]);
}
void
sendtopage_client(Client *c, char *arg) {
Page *p;
Client *new;
Client *next;
if(!strncmp(arg, "new", 4))
p = alloc_page();
@ -599,15 +581,14 @@ sendtopage_client(Client *c, char *arg) {
}
detach_client(c, False);
attach_client_to_page(p, c);
if((new = sel_client_of_page(page[sel])))
focus_client(new, True);
if((next = sel_client_of_page(page[sel])))
focus_client(next);
}
void
sendtoarea_client(Client *c, char *arg) {
const char *errstr;
Area *new, *a = c->area;
Area *next, *a = c->area;
Page *p = a->page;
int i = area_to_index(a);
@ -615,24 +596,23 @@ sendtoarea_client(Client *c, char *arg) {
return;
if(!strncmp(arg, "prev", 5)) {
if(i == 1)
new = p->area[p->narea - 1];
next = p->area[p->narea - 1];
else
new = p->area[i - 1];
next = p->area[i - 1];
}
else if(!strncmp(arg, "next", 5)) {
if(i < p->narea - 1)
new = p->area[i + 1];
next = p->area[i + 1];
else
new = p->area[1];
next = p->area[1];
}
else {
i = cext_strtonum(arg, 1, p->narea, &errstr);
if(errstr)
return;
new = p->area[i - 1];
next = p->area[i - 1];
}
sendto_area(new, c);
sendto_area(next, c);
}
void
@ -643,3 +623,13 @@ resize_all_clients()
if(client[i]->area)
resize_client(client[i], &client[i]->frame.rect, 0);
}
/* convenience function */
void
focus(Client *c)
{
Page *p = c->area->page;
if(page[sel] != p)
focus_page(p);
focus_client(c);
}

View File

@ -138,9 +138,9 @@ drop_moving(Client *c, XRectangle *new, XPoint * pt)
src->client[j] = src->client[i];
src->client[i] = tmp;
arrange_column(src);
focus_client(c);
}
}
focus_client(c, False);
}
}
@ -175,6 +175,6 @@ new_column(Area *old)
c->area = col;
arrange_page(p, True);
focus_client(c, True);
focus_client(c);
return col;
}

View File

@ -72,10 +72,10 @@ handle_buttonpress(XEvent *e)
write_event(buf);
}
}
else if((c = win_to_frame(ev->window))) {
else if((c = win_to_clientframe(ev->window))) {
if(ev->button == Button1) {
if(sel_client() != c) {
focus_client(c, False);
focus(c);
return;
}
align = cursor_to_align(c->frame.cursor);
@ -96,11 +96,10 @@ handle_buttonpress(XEvent *e)
XRaiseWindow(dpy, c->frame.win);
switch (ev->button) {
case Button1:
focus_client(c, False);
mouse_move(c);
focus(c);
break;
case Button3:
focus_client(c, False);
focus(c);
align = xy_to_align(&c->rect, ev->x, ev->y);
if(align == CENTER)
mouse_move(c);
@ -110,9 +109,9 @@ handle_buttonpress(XEvent *e)
}
}
else if(ev->button == Button1)
focus_client(c, False);
focus(c);
if(c && c->area) {
if(c) {
snprintf(buf, sizeof(buf), "CB %d %d\n", client_to_index(c) + 1, ev->button);
write_event(buf);
}
@ -132,7 +131,6 @@ handle_configurerequest(XEvent *e)
ev->value_mask &= ~CWSibling;
if(c) {
if(c->area) {
bw = def.border;
bh = bar_height();
@ -205,7 +203,7 @@ handle_expose(XEvent *e)
if(ev->count == 0) {
if(ev->window == winbar)
draw_bar();
else if((c = win_to_frame(ev->window)))
else if((c = win_to_clientframe(ev->window)))
draw_client(c);
}
}
@ -254,7 +252,7 @@ handle_maprequest(XEvent *e)
static void
handle_motionnotify(XEvent *e)
{
Client *c = win_to_frame(e->xmotion.window);
Client *c = win_to_clientframe(e->xmotion.window);
if(c) {
Cursor cursor = cursor_for_motion(c, e->xmotion.x, e->xmotion.y);
if(cursor != c->frame.cursor) {
@ -291,11 +289,17 @@ handle_unmapnotify(XEvent *e)
static void handle_clientmessage(XEvent *e)
{
XClientMessageEvent *ev = &e->xclient;
Client *c;
if (ev->message_type == net_atoms[NET_NUMBER_OF_DESKTOPS] && ev->format == 32)
return; /* ignore */
else if (ev->message_type == net_atoms[NET_CURRENT_DESKTOP] && ev->format == 32) {
focus_page(page[ev->data.l[0]]);
return;
int i = ev->data.l[0];
if(i < npage) {
Page *p = page[i];
focus_page(p);
if((c = sel_client_of_page(p)))
focus_client(c);
}
}
}

View File

@ -314,7 +314,6 @@ mkqid(Qid *dir, char *wname, Qid *new, Bool iswalk)
if(iswalk) {
Page *p = alloc_page();
new->path = mkqpath(Dpage, p->id, 0, 0);
focus_page(p);
}
else
new->path = mkqpath(Dpage, 0, 0, 0);

View File

@ -31,7 +31,9 @@ void
destroy_page(Page *p)
{
unsigned int i;
Page *new = p->revert;
Page *old = p->revert;
Client *c;
while(p->narea)
destroy_area(p->area[0]);
@ -46,8 +48,11 @@ destroy_page(Page *p)
}
free(p);
if(npage && new)
focus_page(new);
if(npage && old) {
focus_page(old);
if((c = sel_client_of_page(old)))
focus_client(c);
}
else
write_event("PN -\n");
}
@ -78,6 +83,7 @@ focus_page(Page *p)
p->revert = old;
sel = pi;
px = sel * rect.width;
/* gives all(!) clients proper geometry (for use of different pagers) */
for(i = 0; i < nclient; i++) {
c = client[i];
if(c->area) {
@ -87,8 +93,6 @@ focus_page(Page *p)
draw_client(c);
}
}
if((c = sel_client_of_page(p)))
focus_client(c, False);
snprintf(buf, sizeof(buf), "PN %d\n", sel + 1);
write_event(buf);
XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL,
@ -141,6 +145,7 @@ select_page(char *arg)
{
size_t new = sel;
const char *err;
Client *c;
if(!npage)
return;
@ -159,4 +164,6 @@ select_page(char *arg)
new = idx - 1;
}
focus_page(page[new]);
if((c = sel_client_of_page(page[new])))
focus_client(c);
}

View File

@ -172,13 +172,11 @@ pager()
{
XEvent ev;
int i;
size_t j;
Client *c;
if(!page)
if(!npage)
return;
for(j = 0; (j < pagesz) && page[j]; j++);
XClearWindow(dpy, transient);
XMapRaised(dpy, transient);
draw_pager();
@ -204,8 +202,11 @@ pager()
case KeyPress:
XUnmapWindow(dpy, transient);
if((i = handle_kpress(&ev.xkey)) != -1)
if(i < j)
if(i < npage) {
focus_page(page[i]);
if((c = sel_client_of_page(page[i])))
focus_client(c);
}
XUngrabKeyboard(dpy, CurrentTime);
XUngrabPointer(dpy, CurrentTime /* ev.xbutton.time */ );
XSync(dpy, False);
@ -213,8 +214,12 @@ pager()
break;
case ButtonPress:
XUnmapWindow(dpy, transient);
if(ev.xbutton.button == Button1)
focus_page(page[xy_to_pager_page(ev.xbutton.x, ev.xbutton.y)]);
if(ev.xbutton.button == Button1) {
i = xy_to_pager_page(ev.xbutton.x, ev.xbutton.y);
focus_page(page[i]);
if((c = sel_client_of_page(page[i])))
focus_client(c);
}
XUngrabKeyboard(dpy, CurrentTime);
XUngrabPointer(dpy, CurrentTime /* ev.xbutton.time */ );
XSync(dpy, False);

View File

@ -217,8 +217,8 @@ void attach_client_to_page(Page *p, Client *c);
void detach_client(Client *c, Bool unmap);
Client *sel_client();
Client *sel_client_of_page(Page *p);
void focus_client(Client *c, Bool fevent);
Client *win_to_frame(Window w);
void focus_client(Client *c);
Client *win_to_clientframe(Window w);
void resize_client(Client *c, XRectangle *r, XPoint *pt);
int cid_to_index(Area *a, unsigned short id);
int client_to_index(Client *c);
@ -226,6 +226,7 @@ void select_client(Client *c, char *arg);
void sendtopage_client(Client *c, char *arg);
void sendtoarea_client(Client *c, char *arg);
void resize_all_clients();
void focus(Client *c);
/* event.c */
void init_x_event_handler();

View File

@ -39,11 +39,6 @@ write_data(unsigned int fid)
}
offset += len;
}
if(offset == 0) /* do an explicit empty write when no writing has been done yet */
if (ixp_client_write(&c, fid, offset, 0, 0) != 0)
fprintf(stderr, "wmiir: cannot write file: %s\n", c.errstr);
free(data);
}