예제 #1
0
파일: main.c 프로젝트: carriercomm/legacy
void
threadmain(int argc, char *argv[])
{
	int i, got, scr;
	Text *t;
	Rectangle r;
	Flayer *nwhich;

	getscreen(argc, argv);
	iconinit();
	initio();
	scratch = alloc(100*RUNESIZE);
	nscralloc = 100;
	r = screen->r;
	r.max.y = r.min.y+Dy(r)/5;
	flstart(screen->clipr);
	rinit(&cmd.rasp);
	flnew(&cmd.l[0], gettext, 1, &cmd);
	flinit(&cmd.l[0], r, font, cmdcols);
	cmd.nwin = 1;
	which = &cmd.l[0];
	cmd.tag = Untagged;
	outTs(Tversion, VERSION);
	startnewfile(Tstartcmdfile, &cmd);

	got = 0;
	for(;;got = waitforio()){
		if(hasunlocked && RESIZED())
			resize();
		if(got&(1<<RHost))
			rcv();
		if(got&(1<<RPlumb)){
			for(i=0; cmd.l[i].textfn==0; i++)
				;
			current(&cmd.l[i]);
			flsetselect(which, cmd.rasp.nrunes, cmd.rasp.nrunes);
			type(which, RPlumb);
		}
		if(got&(1<<RKeyboard))
			if(which)
				type(which, RKeyboard);
			else
				kbdblock();
		if(got&(1<<RMouse)){
			if(hostlock==2 || !ptinrect(mousep->xy, screen->r)){
				mouseunblock();
				continue;
			}
			nwhich = flwhich(mousep->xy);
			scr = which && ptinrect(mousep->xy, which->scroll);
			if(mousep->buttons)
				flushtyping(1);
			if(mousep->buttons&1){
				if(nwhich){
					if(nwhich!=which)
						current(nwhich);
					else if(scr)
						scroll(which, 1);
					else{
						t=(Text *)which->user1;
						if(flselect(which)){
							outTsl(Tdclick, t->tag, which->p0);
							t->lock++;
						}else if(t!=&cmd)
							outcmd();
					}
				}
			}else if((mousep->buttons&2) && which){
				if(scr)
					scroll(which, 2);
				else
					menu2hit();
			}else if((mousep->buttons&4)){
				if(scr)
					scroll(which, 3);
				else
					menu3hit();
			}
			mouseunblock();
		}
	}
}
예제 #2
0
파일: main.c 프로젝트: siebenmann/sam
void
main(int argc, char *argv[])
{
	int i, got, scr;
	Text *t;
	Rectangle r;
	Flayer *nwhich;

	int fwdbut;

	if (argc >= 3 && strcmp(argv[1], "-r") == 0)
	{
		machine = argv[2];
	}

	getscreen(argc, argv);
	fwdbut = scrollfwdbut();
	iconinit();
	initio();
	scratch = alloc(100*RUNESIZE);
	nscralloc = 100;
	r = screen.r;
	r.max.y = r.min.y+Dy(r)/5;
	flstart(screen.clipr);
	rinit(&cmd.rasp);
	flnew(&cmd.l[0], stgettext, 1, &cmd);
	flinit(&cmd.l[0], r, font);
	cmd.nwin = 1;
	which = &cmd.l[0];
	cmd.tag = Untagged;
	outTs(Tversion, VERSION);
	startnewfile(Tstartcmdfile, &cmd);

	got = 0;
	for(;;got = waitforio()){
		if(hasunlocked && RESHAPED())
			reshape();
		if(got&RHost)
			rcv();
		if(got&RExtern){
			for(i=0; cmd.l[i].textfn==0; i++)
				;
			current(&cmd.l[i]);
			flsetselect(which, cmd.rasp.nrunes, cmd.rasp.nrunes);
			type(which, RExtern);
		}
		if(got&RKeyboard)
			if(which)
				type(which, RKeyboard);
			else
				kbdblock();
		if(got&RMouse){
			if(lock==2 || !ptinrect(mouse.xy, screen.r)){
				mouseunblock();
				continue;
			}
			nwhich = flwhich(mouse.xy);
			scr = which && ptinrect(mouse.xy, which->scroll);
			if(mouse.buttons)
				flushtyping(1);
			if (chord == 1 && !mouse.buttons)
				chord = 0;
			if (chord)
				chord |= mouse.buttons;
			else if(mouse.buttons&1){
				if(nwhich){
					if(nwhich!=which)
						current(nwhich);
					else if(scr)
						scroll(which, 1, fwdbut == 3 ? 1 : 3);
					else{
						t=(Text *)which->user1;
						if(flselect(which)){
							outTsl(Tdclick, t->tag, which->p0);
							t->lock++;
						}else if(t!=&cmd)
							outcmd();
						if(mouse.buttons&1)
							chord = mouse.buttons;
					}
				}
			}else if((mouse.buttons&2) && which){
				if(scr)
					scroll(which, 2, 2);
				else
					menu2hit();
			}else if((mouse.buttons&4)){
				if(scr)
					scroll(which, 3, fwdbut == 3 ? 3 : 1);
				else
					menu3hit();
			}else if((mouse.buttons&8)){
				scrollone(which, 1);
			}else if((mouse.buttons&16)){
				scrollone(which, 3);
			}
			mouseunblock();
		}
		if(chord) {
			t = (Text *)which->user1;
			if(!t->lock){
				int w = which-t->l;
				if(chord&2){
					cut(t, w, 1, 1);
					chord &= ~2;
				}
				if(chord&4){
					paste(t, w);
					chord &= ~4;
				}
			}
		}
	}
}
예제 #3
0
파일: main.c 프로젝트: rennis250/sam
void
threadmain(int argc, char *argv[])
{
	int i, got, scr, chord;
	Text *t;
	Rectangle r;
	Flayer *nwhich;

	/*
	 * sam is talking to us on fd 0 and 1.
	 * move these elsewhere so that if we accidentally
	 * use 0 and 1 in other code, nothing bad happens.
	 */
	dup(0, 3);
	dup(1, 4);
	hostfd[0] = 3;
	hostfd[1] = 4;
	close(0);
	close(1);
	open("/dev/null", OREAD);
	if(open("/dev/tty", OWRITE) < 0)
		open("/dev/null", OWRITE);

	notify(notifyf);

	if(protodebug) print("getscreen\n");
	getscreen(argc, argv);
	if(protodebug) print("iconinit\n");
	iconinit();
	if(protodebug) print("initio\n");
	initio();
	if(protodebug) print("scratch\n");
	scratch = alloc(100*RUNESIZE);
	nscralloc = 100;
	r = screen->r;
	r.max.y = r.min.y+Dy(r)/5;
	if(protodebug) print("flstart\n");
	flstart(screen->clipr);
	rinit(&cmd.rasp);
	flnew(&cmd.l[0], gettext, 1, &cmd);
	flinit(&cmd.l[0], r, font, cmdcols);
	cmd.nwin = 1;
	which = &cmd.l[0];
	cmd.tag = Untagged;
	outTs(Tversion, VERSION);
	startnewfile(Tstartcmdfile, &cmd);

	got = 0;
	chord = 0;
	if(protodebug) print("loop\n");
	for(;;got = waitforio()){
		if(hasunlocked && RESIZED())
			resize();
		if(got&(1<<RHost))
			rcv();
		if(got&(1<<RPlumb)){
			for(i=0; cmd.l[i].textfn==0; i++)
				;
			current(&cmd.l[i]);
			flsetselect(which, cmd.rasp.nrunes, cmd.rasp.nrunes);
			type(which, RPlumb);
		}
		if(got&(1<<RKeyboard))
			if(which)
				type(which, RKeyboard);
			else
				kbdblock();
		if(got&(1<<RMouse)){
			if(hostlock==2 || !ptinrect(mousep->xy, screen->r)){
				mouseunblock();
				continue;
			}
			nwhich = flwhich(mousep->xy);
			//scr = which && ptinrect(mousep->xy, which->scroll);
			scr = which && (ptinrect(mousep->xy, which->scroll) || mousep->buttons&(8|16));
			if(mousep->buttons)
				flushtyping(1);
			//if(chording && chord==1 && !mousep->buttons)
			if((mousep->buttons&1)==0)
				chord = 0;
			//if(chording && chord)
 				//chord |= mousep->buttons;
			//else if(mousep->buttons&1){
			if(chord && which && which==nwhich){
				chord |= mousep->buttons;
				t = (Text *)which->user1;
				if(!t->lock){
					int w = which-t->l;
					if(chord&2){
						cut(t, w, 1, 1);
						chord &= ~2;
					}
					if(chord&4){
						paste(t, w);
						chord &= ~4;
					}
				}
			}else if(mousep->buttons&(1|8)){
			//}else if(mousep->buttons&1){
				if(nwhich){
					if(nwhich!=which)
						current(nwhich);
					else if(scr)
						//scroll(which, 1);
						scroll(which, (mousep->buttons&8) ? 4 : 1);
					else{
						t=(Text *)which->user1;
						if(flselect(which)){
							outTsl(Tdclick, t->tag, which->p0);
							t->lock++;
						}else if(t!=&cmd)
							outcmd();
						if(mousep->buttons&1)
							chord = mousep->buttons;
					}
				}
			}else if((mousep->buttons&2) && which){
				if(scr)
					scroll(which, 2);
				else
					menu2hit();
            }else if(mousep->buttons&(4|16)){
			//}else if(mousep->buttons&4){
				if(nwhich!=which)
					current(nwhich);
				else if(scr)
				//if(scr)
					//scroll(which, 3);
					scroll(which, (mousep->buttons&16) ? 5 : 3);
				else
					menu3hit();
			}
			mouseunblock();
		}
	}
}