13 extern Wintab *tabs[];
16 Win *actw, *actf, *cmdw;
26 sysfatal("malloc: %r");
28 setmalloctag(v, getcallerpc(&sz));
38 scr = allocscreen(screen, display->white, 0);
40 sysfatal("allocscreen: %r");
41 for(i = 0; i < NTYPES; i++)
42 for(j = 0; j < NCOLS; j++)
43 tabs[i]->cols[j] = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, tabs[i]->hexcols[j]);
44 invcol = allocimage(display, Rect(0, 0, 2, 2), screen->chan, 1, 0);
45 draw(invcol, Rect(1, 0, 2, 1), display->white, nil, ZP);
46 draw(invcol, Rect(0, 1, 1, 2), display->white, nil, ZP);
47 wlist.next = wlist.prev = &wlist;
48 flist.next = flist.prev = &flist;
50 r.max.y = r.min.y + Dy(r) / 5;
51 cmdw = newwin(CMD, r, nil);
53 sysfatal("newwin: %r");
57 newwin(int t, Rectangle r, File *f)
61 w = emalloc(sizeof(*w));
69 w->inner = insetrect(r, BORDSIZ);
70 w->im = allocwindow(scr, r, Refbackup, 0);
71 draw(w->im, w->inner, w->tab->cols[BACK], nil, ZP);
74 w->wprev = f->wins.wprev;
76 f->wins.wprev->wnext = w;
87 newwinsel(int t, Mousectl *mc, File *f)
92 if(Dx(u) < MINSIZ || Dy(u) < MINSIZ)
94 rectclip(&u, screen->r);
95 return newwin(t, u, f);
99 winzerox(Win *w, Mousectl *mc)
103 if(w->tab->zerox == nil){
107 v = newwinsel(w->type, mc, w->f);
122 if(w->f->change > 0){
133 w->wnext->wprev = w->wprev;
134 w->wprev->wnext = w->wnext;
136 w->next->prev = w->prev;
137 w->prev->next = w->next;
149 border(actw->im, actw->entire, BORDSIZ, actw->tab->cols[DISB], ZP);
156 sysfatal("setfocus: phase error");
158 w->prev->next = w->next;
159 w->next->prev = w->prev;
160 w->prev = wlist.prev;
164 border(w->im, w->entire, BORDSIZ, w->tab->cols[BORD], ZP);
172 for(w = wlist.prev; w != &wlist; w = w->prev)
173 if(ptinrect(p, w->entire))
179 winclick(Mousectl *mc)
183 w = winpoint(mc->xy);
187 w->tab->click(w, mc);
189 while((mc->buttons & 1) != 0)
194 winsel(Mousectl *mc, int but)
196 extern Cursor crosscursor;
201 setcursor(mc, &crosscursor);
204 if((mc->buttons & ~m) != 0){
208 if((mc->buttons & m) != 0)
211 w = winpoint(mc->xy);
213 while(readmouse(mc), mc->buttons != 0)
220 winresize(Win *w, Mousectl *mc)
227 if(Dx(r) < MINSIZ || Dy(r) < MINSIZ)
229 rectclip(&r, screen->r);
232 w->inner = insetrect(r, BORDSIZ);
233 w->im = allocwindow(scr, r, Refbackup, 0);
234 draw(w->im, w->inner, w->tab->cols[BACK], nil, ZP);
243 int dxo, dyo, dxn, dyn;
249 if(getwindow(display, Refnone) < 0)
250 sysfatal("resize failed: %r");
254 scr = allocscreen(screen, display->white, 0);
256 sysfatal("allocscreen: %r");
257 for(w = wlist.next; w != &wlist; w = w->next){
258 r = rectsubpt(w->entire, old.min);
259 r.min.x = muldiv(r.min.x, dxn, dxo);
260 r.max.x = muldiv(r.max.x, dxn, dxo);
261 r.min.y = muldiv(r.min.y, dyn, dyo);
262 r.max.y = muldiv(r.max.y, dyn, dyo);
263 w->entire = rectaddpt(r, screen->r.min);
264 w->inner = insetrect(w->entire, BORDSIZ);
266 w->im = allocwindow(scr, w->entire, Refbackup, 0);
268 sysfatal("allocwindow: %r");
269 draw(w->im, w->inner, w->tab->cols[BACK], nil, ZP);
270 border(w->im, w->entire, BORDSIZ, w->tab->cols[w == actw ? BORD : DISB], ZP);
275 extern Wintab cmdtab, paltab, sprtab;