📄 rio.c
字号:
}}voidresized(void){ Image *im; int i, j, ishidden; Rectangle r; Point o, n; Window *w; if(getwindow(display, Refnone) < 0) error("failed to re-attach window"); freescrtemps(); view = screen; freescreen(wscreen); wscreen = allocscreen(screen, background, 0); if(wscreen == nil) error("can't re-allocate screen"); draw(view, view->r, background, nil, ZP); o = subpt(viewr.max, viewr.min); n = subpt(view->clipr.max, view->clipr.min); for(i=0; i<nwindow; i++){ w = window[i]; if(w->deleted) continue; r = rectsubpt(w->i->r, viewr.min); r.min.x = (r.min.x*n.x)/o.x; r.min.y = (r.min.y*n.y)/o.y; r.max.x = (r.max.x*n.x)/o.x; r.max.y = (r.max.y*n.y)/o.y; r = rectaddpt(r, screen->clipr.min); ishidden = 0; for(j=0; j<nhidden; j++) if(w == hidden[j]){ ishidden = 1; break; } if(ishidden) im = allocimage(display, r, screen->chan, 0, DWhite); else im = allocwindow(wscreen, r, Refbackup, DWhite); if(im) wsendctlmesg(w, Reshaped, r, im); } viewr = screen->r; flushimage(display, 1);}voidbutton3menu(void){ int i; for(i=0; i<nhidden; i++) menu3str[i+Hidden] = hidden[i]->label; menu3str[i+Hidden] = nil; sweeping = 1; switch(i = menuhit(3, mousectl, &menu3, wscreen)){ case -1: break; case New: new(sweep(), FALSE, scrolling, 0, nil, "/bin/rc", nil); break; case Reshape: resize(); break; case Move: move(); break; case Delete: delete(); break; case Hide: hide(); break; case Exit: if(Hidden > Exit){ send(exitchan, nil); break; } /* else fall through */ default: unhide(i); break; } sweeping = 0;}voidbutton2menu(Window *w){ if(w->deleted) return; incref(w); if(w->scrolling) menu2str[Scroll] = "noscroll"; else menu2str[Scroll] = "scroll"; switch(menuhit(2, mousectl, &menu2, wscreen)){ case Cut: wsnarf(w); wcut(w); wscrdraw(w); break; case Snarf: wsnarf(w); break; case Paste: getsnarf(); wpaste(w); wscrdraw(w); break; case Plumb: wplumb(w); break; case Send: getsnarf(); wsnarf(w); if(nsnarf == 0) break; if(w->rawing){ waddraw(w, snarf, nsnarf); if(snarf[nsnarf-1]!='\n' && snarf[nsnarf-1]!='\004') waddraw(w, L"\n", 1); }else{ winsert(w, snarf, nsnarf, w->nr); if(snarf[nsnarf-1]!='\n' && snarf[nsnarf-1]!='\004') winsert(w, L"\n", 1, w->nr); } wsetselect(w, w->nr, w->nr); wshow(w, w->nr); break; case Scroll: if(w->scrolling ^= 1) wshow(w, w->nr); break; } wclose(w); wsendctlmesg(w, Wakeup, ZR, nil); flushimage(display, 1);}Pointonscreen(Point p){ p.x = max(screen->clipr.min.x, p.x); p.x = min(screen->clipr.max.x, p.x); p.y = max(screen->clipr.min.y, p.y); p.y = min(screen->clipr.max.y, p.y); return p;}Image*sweep(void){ Image *i, *oi; Rectangle r; Point p0, p; i = nil; menuing = TRUE; riosetcursor(&crosscursor, 1); while(mouse->buttons == 0) readmouse(mousectl); p0 = onscreen(mouse->xy); p = p0; r.min = p; r.max = p; oi = nil; while(mouse->buttons == 4){ readmouse(mousectl); if(mouse->buttons != 4 && mouse->buttons != 0) break; if(!eqpt(mouse->xy, p)){ p = onscreen(mouse->xy); r = canonrect(Rpt(p0, p)); if(Dx(r)>5 && Dy(r)>5){ i = allocwindow(wscreen, r, Refnone, 0xEEEEEEFF); /* grey */ freeimage(oi); if(i == nil) goto Rescue; oi = i; border(i, r, Selborder, red, ZP); flushimage(display, 1); } } } if(mouse->buttons != 0) goto Rescue; if(i==nil || Dx(i->r)<100 || Dy(i->r)<3*font->height) goto Rescue; oi = i; i = allocwindow(wscreen, oi->r, Refbackup, DWhite); freeimage(oi); if(i == nil) goto Rescue; border(i, r, Selborder, red, ZP); cornercursor(input, mouse->xy, 1); goto Return; Rescue: freeimage(i); i = nil; cornercursor(input, mouse->xy, 1); while(mouse->buttons) readmouse(mousectl); Return: moveto(mousectl, mouse->xy); /* force cursor update; ugly */ menuing = FALSE; return i;}voiddrawedge(Image **bp, Rectangle r){ Image *b = *bp; if(b != nil && Dx(b->r) == Dx(r) && Dy(b->r) == Dy(r)) originwindow(b, r.min, r.min); else{ freeimage(b); *bp = allocwindow(wscreen, r, Refbackup, DRed); }}voiddrawborder(Rectangle r, int show){ static Image *b[4]; int i; if(show == 0){ for(i = 0; i < 4; i++){ freeimage(b[i]); b[i] = nil; } }else{ r = canonrect(r); drawedge(&b[0], Rect(r.min.x, r.min.y, r.min.x+Borderwidth, r.max.y)); drawedge(&b[1], Rect(r.min.x+Borderwidth, r.min.y, r.max.x-Borderwidth, r.min.y+Borderwidth)); drawedge(&b[2], Rect(r.max.x-Borderwidth, r.min.y, r.max.x, r.max.y)); drawedge(&b[3], Rect(r.min.x+Borderwidth, r.max.y-Borderwidth, r.max.x-Borderwidth, r.max.y)); }}Image*drag(Window *w, Rectangle *rp){ Image *i, *ni; Point p, op, d, dm, om; Rectangle r; i = w->i; menuing = TRUE; om = mouse->xy; riosetcursor(&boxcursor, 1); dm = subpt(mouse->xy, w->screenr.min); d = subpt(i->r.max, i->r.min); op = subpt(mouse->xy, dm); drawborder(Rect(op.x, op.y, op.x+d.x, op.y+d.y), 1); flushimage(display, 1); while(mouse->buttons == 4){ p = subpt(mouse->xy, dm); if(!eqpt(p, op)){ drawborder(Rect(p.x, p.y, p.x+d.x, p.y+d.y), 1); flushimage(display, 1); op = p; } readmouse(mousectl); } r = Rect(op.x, op.y, op.x+d.x, op.y+d.y); drawborder(r, 0); cornercursor(w, mouse->xy, 1); moveto(mousectl, mouse->xy); /* force cursor update; ugly */ menuing = FALSE; flushimage(display, 1); if(mouse->buttons!=0 || (ni=allocwindow(wscreen, r, Refbackup, DWhite))==nil){ moveto(mousectl, om); while(mouse->buttons) readmouse(mousectl); *rp = Rect(0, 0, 0, 0); return nil; } draw(ni, ni->r, i, nil, i->r.min); *rp = r; return ni;}Pointcornerpt(Rectangle r, Point p, int which){ switch(which){ case 0: /* top left */ p = Pt(r.min.x, r.min.y); break; case 2: /* top right */ p = Pt(r.max.x,r.min.y); break; case 6: /* bottom left */ p = Pt(r.min.x, r.max.y); break; case 8: /* bottom right */ p = Pt(r.max.x, r.max.y); break; case 1: /* top edge */ p = Pt(p.x,r.min.y); break; case 5: /* right edge */ p = Pt(r.max.x, p.y); break; case 7: /* bottom edge */ p = Pt(p.x, r.max.y); break; case 3: /* left edge */ p = Pt(r.min.x, p.y); break; } return p;}Rectanglewhichrect(Rectangle r, Point p, int which){ switch(which){ case 0: /* top left */ r = Rect(p.x, p.y, r.max.x, r.max.y); break; case 2: /* top right */ r = Rect(r.min.x, p.y, p.x, r.max.y); break; case 6: /* bottom left */ r = Rect(p.x, r.min.y, r.max.x, p.y); break; case 8: /* bottom right */ r = Rect(r.min.x, r.min.y, p.x, p.y); break; case 1: /* top edge */ r = Rect(r.min.x, p.y, r.max.x, r.max.y); break; case 5: /* right edge */ r = Rect(r.min.x, r.min.y, p.x, r.max.y); break; case 7: /* bottom edge */ r = Rect(r.min.x, r.min.y, r.max.x, p.y); break; case 3: /* left edge */ r = Rect(p.x, r.min.y, r.max.x, r.max.y); break; } return canonrect(r);}Image*bandsize(Window *w){ Image *i; Rectangle r, or; Point p, startp; int which, but; p = mouse->xy; but = mouse->buttons; which = whichcorner(w, p); p = cornerpt(w->screenr, p, which); wmovemouse(w, p); readmouse(mousectl); r = whichrect(w->screenr, p, which); drawborder(r, 1); or = r; startp = p; while(mouse->buttons == but){ p = onscreen(mouse->xy); r = whichrect(w->screenr, p, which); if(!eqrect(r, or) && goodrect(r)){ drawborder(r, 1); flushimage(display, 1); or = r; } readmouse(mousectl); } p = mouse->xy; drawborder(or, 0); flushimage(display, 1); wsetcursor(w, 1); if(mouse->buttons!=0 || Dx(or)<100 || Dy(or)<3*font->height){ while(mouse->buttons) readmouse(mousectl); return nil; } if(abs(p.x-startp.x)+abs(p.y-startp.y) <= 1) return nil; i = allocwindow(wscreen, or, Refbackup, DWhite); if(i == nil) return nil; border(i, r, Selborder, red, ZP); return i;}Window*pointto(int wait){ Window *w; menuing = TRUE; riosetcursor(&sightcursor, 1); while(mouse->buttons == 0) readmouse(mousectl); if(mouse->buttons == 4) w = wpointto(mouse->xy); else w = nil; if(wait){ while(mouse->buttons){ if(mouse->buttons!=4 && w !=nil){ /* cancel */ cornercursor(input, mouse->xy, 0); w = nil; } readmouse(mousectl); } if(w != nil && wpointto(mouse->xy) != w) w = nil; } cornercursor(input, mouse->xy, 0); moveto(mousectl, mouse->xy); /* force cursor update; ugly */ menuing = FALSE; return w;}voiddelete(void){ Window *w; w = pointto(TRUE); if(w) wsendctlmesg(w, Deleted, ZR, nil);}voidresize(void){ Window *w; Image *i; w = pointto(TRUE); if(w == nil) return; i = sweep(); if(i) wsendctlmesg(w, Reshaped, i->r, i);}voidmove(void){ Window *w; Image *i; Rectangle r; w = pointto(FALSE); if(w == nil) return; i = drag(w, &r); if(i) wsendctlmesg(w, Moved, r, i); cornercursor(input, mouse->xy, 1);}intwhide(Window *w){ Image *i; int j; for(j=0; j<nhidden; j++) if(hidden[j] == w) /* already hidden */ return -1; i = allocimage(display, w->screenr, w->i->chan, 0, DWhite); if(i){ hidden[nhidden++] = w; wsendctlmesg(w, Reshaped, ZR, i); return 1; } return 0;}intwunhide(int h){ Image *i; Window *w; w = hidden[h]; i = allocwindow(wscreen, w->i->r, Refbackup, DWhite); if(i){ --nhidden; memmove(hidden+h, hidden+h+1, (nhidden-h)*sizeof(Window*)); wsendctlmesg(w, Reshaped, w->i->r, i); return 1; } return 0;}voidhide(void){ Window *w; w = pointto(TRUE); if(w == nil) return; whide(w);}voidunhide(int h){ Window *w; h -= Hidden; w = hidden[h]; if(w == nil) return; wunhide(h);}Window*new(Image *i, int hideit, int scrollit, int pid, char *dir, char *cmd, char **argv){ Window *w; Mousectl *mc; Channel *cm, *ck, *cctl, *cpid; void **arg; if(i == nil) return nil; cm = chancreate(sizeof(Mouse), 0); ck = chancreate(sizeof(Rune*), 0); cctl = chancreate(sizeof(Wctlmesg), 4); cpid = chancreate(sizeof(int), 0); if(cm==nil || ck==nil || cctl==nil) error("new: channel alloc failed"); mc = emalloc(sizeof(Mousectl)); *mc = *mousectl; mc->image = i; mc->c = cm; w = wmk(i, mc, ck, cctl, scrollit); free(mc); /* wmk copies *mc */ window = erealloc(window, ++nwindow*sizeof(Window*)); window[nwindow-1] = w; if(hideit){ hidden[nhidden++] = w; w->screenr = ZR; } threadcreate(winctl, w, 8192); if(!hideit) wcurrent(w); flushimage(display, 1); if(pid == 0){ arg = emalloc(5*sizeof(void*)); arg[0] = w; arg[1] = cpid; arg[2] = cmd; if(argv == nil) arg[3] = rcargv; else arg[3] = argv; arg[4] = dir; proccreate(winshell, arg, 8192); pid = recvul(cpid); free(arg); } if(pid == 0){ /* window creation failed */ wsendctlmesg(w, Deleted, ZR, nil); chanfree(cpid); return nil; } wsetpid(w, pid, 1); wsetname(w); if(dir) w->dir = estrdup(dir); chanfree(cpid); return w;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -