int afmt(Fmt *f) { Area *a; a = va_arg(f->args, Area*); if(a == nil) return fmtstrcpy(f, "<nil>"); if(a->floating) return fmtstrcpy(f, "~"); if(a->screen > 0 || (f->flags & FmtSharp)) return fmtprint(f, "%d:%d", a->screen, area_idx(a)); return fmtprint(f, "%d", area_idx(a)); }
void area_focus(Area *a) { Frame *f; View *v; Area *old_a; v = a->view; f = a->sel; old_a = v->sel; if(!a->floating && view_fullscreen_p(v, a->screen)) return; v->sel = a; if(!a->floating) { v->selcol = area_idx(a); v->selscreen = a->screen; } if(a != old_a) v->oldsel = nil; if(old_a && a->floating != old_a->floating) { v->revert = old_a; if(v->floating->max) view_update(v); } if(v == selview) { move_focus(old_a->sel, f); client_focus(f ? f->client : nil); if(a != old_a) event("AreaFocus %a\n", a); } }
void area_focus(Area *a) { Frame *f; View *v; Area *old_a; v = a->view; f = a->sel; old_a = v->sel; if(!a->floating && view_fullscreen_p(v, a->screen)) return; v->sel = a; if(!a->floating) { v->selcol = area_idx(a); v->selscreen = a->screen; } if(a != old_a) v->oldsel = nil; if((old_a) && (a->floating != old_a->floating)) { v->revert = old_a; if(v->floating->max) view_update(v); } if(v != selview) return; move_focus(old_a->sel, f); if(f) client_focus(f->client); else client_focus(nil); if(a != old_a) { event("AreaFocus %a\n", a); /* Deprecated */ if(a->floating) event("FocusFloating\n"); else event("ColumnFocus %d\n", area_idx(a)); } }
char* area_name(Area *a) { if(a == nil) return "<nil>"; if(a->floating) return "~"; return sxprint("%d", area_idx(a)); }
void column_insert(Area *a, Frame *f, Frame *pos) { f->area = a; f->client->floating = false; f->screen = a->screen; f->column = area_idx(a); frame_insert(f, pos); if(a->sel == nil) area_setsel(a, f); }
void column_settle(Area *a) { Frame *f; uint yoff, yoffcr; int surplus, n_uncol, n; n_uncol = 0; surplus = column_surplus(a); for(f=a->frame; f; f=f->anext) if(!f->collapsed) n_uncol++; if(n_uncol == 0) { fprint(2, "%s: Badness: No uncollapsed frames, column %d, view %q\n", argv0, area_idx(a), a->view->name); return; } if(surplus < 0) fprint(2, "%s: Badness: surplus = %d in column_settle, column %d, view %q\n", argv0, surplus, area_idx(a), a->view->name); yoff = a->r.min.y; yoffcr = yoff; n = surplus % n_uncol; surplus /= n_uncol; for(f=a->frame; f; f=f->anext) { f->r = rectsetorigin(f->r, Pt(a->r.min.x, yoff)); f->colr = rectsetorigin(f->colr, Pt(a->r.min.x, yoffcr)); f->r.min.x = a->r.min.x; f->r.max.x = a->r.max.x; if(def.incmode == ISqueeze && !resizing) if(!f->collapsed) { f->r.max.y += surplus; if(n-- > 0) f->r.max.y++; } yoff = f->r.max.y; yoffcr = f->colr.max.y; } }
void area_destroy(Area *a) { Area *newfocus; View *v; int idx; v = a->view; if(a->frame) die("destroying non-empty area"); if(v->revert == a) v->revert = nil; if(v->oldsel == a) v->oldsel = nil; idx = area_idx(a); if(a->prev && !a->prev->floating) newfocus = a->prev; else newfocus = a->next; /* Can only destroy the floating area when destroying a * view---after destroying all columns. */ assert(!a->floating || !v->areas[0]); if(a->prev) a->prev->next = a->next; else if(!a->floating) v->areas[a->screen] = a->next; else v->floating = nil; if(a->next) a->next->prev = a->prev; if(newfocus && v->sel == a) area_focus(newfocus); view_arrange(v); event("DestroyArea %d\n", idx); free(a); }
Area* area_create(View *v, Area *pos, int scrn, uint width) { static ushort id = 1; int i, j; uint minwidth, index; int numcols; Area *a; assert(!pos || pos->screen == scrn); SET(index); if(v->areas) { /* Creating a column. */ minwidth = column_minwidth(); index = pos ? area_idx(pos) : 1; numcols = 0; for(a=v->areas[scrn]; a; a=a->next) numcols++; /* TODO: Need a better sizing/placing algorithm. */ if(width == 0) { if(numcols >= 0) { width = view_newcolwidth(v, index); if (width == 0) width = Dx(v->r[scrn]) / (numcols + 1); } else width = Dx(v->r[scrn]); } if(width < minwidth) width = minwidth; minwidth = numcols * minwidth + minwidth; if(minwidth > Dx(v->r[scrn])) return nil; i = minwidth - Dx(v->pad[scrn]) - Dx(v->r[scrn]); if(i > 0 && Dx(v->pad[scrn])) { j = min(i/2, v->pad[scrn].min.x); v->pad[scrn].min.x -= j; v->pad[scrn].max.x += i - j; } view_scale(v, scrn, Dx(v->r[scrn]) - width); } a = emallocz(sizeof *a); a->view = v; a->screen = scrn; a->id = id++; a->floating = !v->floating; if(a->floating) a->mode = Coldefault; else a->mode = def.colmode; a->frame = nil; a->sel = nil; a->r = v->r[scrn]; a->r.min.x = 0; a->r.max.x = width; if(a->floating) { v->floating = a; a->screen = -1; } else if(pos) { a->next = pos->next; a->prev = pos; } else { a->next = v->areas[scrn]; v->areas[scrn] = a; } if(a->prev) a->prev->next = a; if(a->next) a->next->prev = a; if(v->sel == nil && !a->floating) area_focus(a); if(!a->floating) event("CreateColumn %ud\n", index); return a; }