Esempio n. 1
0
void freqhndlr(unsigned char signo) {

	unsigned char ovrflow;
	unsigned char dig1, dig2, dig3;

	if (signo == _SIG_KEYB) {
		ovrflow = OCR0;

		if (KEYPRESS[getscreen()].row == 0 && KEYPRESS[getscreen()].col == 1) {
			ovrflow--;
			if (ovrflow < 8) ovrflow = 255;
			OCR0 = ovrflow;
		} else if (KEYPRESS[getscreen()].row == 0 && KEYPRESS[getscreen()].col == 2) {

			if (ovrflow == 255) ovrflow = 7;
			ovrflow++;
			OCR0 = ovrflow;
		}

		dig2 = idiv10(ovrflow);
		dig3 = idiv10(dig2);
		dig1 = ovrflow - 10*dig2; // remainders
		dig2 = dig2 - 10*dig3;

		dispWrite((unsigned char) 0, display_xlate(dig3));
		dispWrite((unsigned char) 1, display_xlate(dig2));
		dispWrite((unsigned char) 2, display_xlate(dig1));

	}

}
Esempio n. 2
0
tgui_Window *newwindow(int x1, int y1, int x2, int y2, int color, unsigned parent, char* title) {

tgui_Window *tgw = malloc(sizeof (tgui_Window));

//unsigned bufsize = (y2 -y1+1) * (x2 - x1 + 1);



	tgw->scrnchar = NULL;
    //tgw->scrncolr = malloc(sizeof (char)*bufsize);

	tgw->x1=x1;
	tgw->y1=y1;
	tgw->x2=x2;
	tgw->y2=y2;
	tgw->color=color;
    tgw->title = title;
	tgw->parent = parent;
	tgw->quitflag = 0;
	tgw->firstobj = NULL;
	tgw->lastobj=NULL;
	tgw->firstmenu=NULL;
	tgw->lastmenu=NULL;

	if (tgw->parent==0) tgw->scrnchar = getscreen(tgw->x1, tgw->y1, tgw->x2, tgw->y2);

	box(tgw);

	return tgw;
} // end of newwindow()
Esempio n. 3
0
File: menu.c Progetto: graue/spray
void displaytext(const char *text)
{
	TTF_Font *font = NULL;
	SDL_Color textcolor;
	SDL_Surface *textsurface;
	SDL_Rect dest;
	int textwidth, textheight;

	/* happy orange */
	textcolor.r = 255;
	textcolor.g = 192;
	textcolor.b = 0;

	if (TTF_Init() < 0)
		error("Font error: %s", TTF_GetError());

	font = TTF_OpenFont("font.ttf", 48);

	if (font == NULL)
		error("Font error: %s", TTF_GetError());

	if (TTF_SizeText(font, text, &textwidth, &textheight) < 0)
		error("Font error: %s", TTF_GetError());

	if (textwidth >= WIDTH || textheight >= HEIGHT)
		error("Font is too big (%dx%d)", textwidth, textheight);

	dest.x = WIDTH/2  - textwidth/2;
	dest.y = HEIGHT/2 - textheight/2;
	dest.w = textwidth;
	dest.h = textheight;

	textsurface = TTF_RenderText_Blended(font, text, textcolor);

	if (!textsurface)
		error("Font error: %s", TTF_GetError());

	SDL_BlitSurface(textsurface, NULL, getscreen(), &dest);
	SDL_FreeSurface(textsurface);
	SDL_UpdateRect(getscreen(), 0, 0, 0, 0);

	TTF_CloseFont(font);
	font = NULL;
	TTF_Quit();
}
Esempio n. 4
0
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;
				}
			}
		}
	}
}
Esempio n. 5
0
File: menu.c Progetto: nealey/9wm
void
button(XButtonEvent * e)
{
	int n, shift;
	Client *c;
	Window dw;
	ScreenInfo *s;

	curtime = e->time;
	s = getscreen(e->root);
	if (s == 0)
		return;
	c = getclient(e->window, 0);
	if (c) {
		e->x += c->x - BORDER + 1;
		e->y += c->y - BORDER + 1;
	} else if (e->window != e->root)
		XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y, &e->x, &e->y, &dw);
	switch (e->button) {
	case Button1:
		if (c) {
			XMapRaised(dpy, c->parent);
			top(c);
			active(c);
		}
		return;
	case Button2:
		if ((e->state & (ShiftMask | ControlMask)) == (ShiftMask | ControlMask)) {
			menuhit(e, &egg);
		} else {
			spawn(s, "9wm-mm");
		}
		return;
	default:
		return;
	case Button3:
		break;
	}

	if (current && current->screen == s)
		cmapnofocus(s);
	switch (n = menuhit(e, &b3menu)) {
	case 0:		/* New */
		spawn(s, termprog);
		break;
	case 1:		/* Reshape */
		reshape(selectwin(1, 0, s));
		break;
	case 2:		/* Move */
		move(selectwin(0, 0, s));
		break;
	case 3:		/* Delete */
		shift = 0;
		c = selectwin(1, &shift, s);
		delete(c, shift);
		break;
	case 4:		/* Hide */
		hide(selectwin(1, 0, s));
		break;
	default:		/* unhide window */
		unhide(n - B3FIXED, 1);
		break;
	case -1:		/* nothing */
		break;
	}
	if (current && current->screen == s)
		cmapfocus(current);
}
Esempio n. 6
0
int
menuhit(XButtonEvent *e, Menu *m)
{
	XEvent ev;
	int i, n, cur, old, wide, high, status, drawn, warp;
	int x, y, dx, dy, xmax, ymax;
	ScreenInfo *s;

	if(font == 0)
		return -1;
	s = getscreen(e->root);
	if(s == 0 || e->window == s->menuwin)	   /* ugly event mangling */
		return -1;

	dx = 0;
	for(n = 0; m->item[n]; n++){
		wide = XTextWidth(font, m->item[n], strlen(m->item[n])) + 4;
		if(wide > dx)
			dx = wide;
	}
	wide = dx;
	cur = m->lasthit;
	if(cur >= n)
		cur = n - 1;

	high = font->ascent + font->descent + 1;
	dy = n*high;
	x = e->x - wide/2;
	y = e->y - cur*high - high/2;
	warp = 0;
	xmax = DisplayWidth(dpy, s->num);
	ymax = DisplayHeight(dpy, s->num);
	if(x < 0){
		e->x -= x;
		x = 0;
		warp++;
	}
	if(x+wide >= xmax){
		e->x -= x+wide-xmax;
		x = xmax-wide;
		warp++;
	}
	if(y < 0){
		e->y -= y;
		y = 0;
		warp++;
	}
	if(y+dy >= ymax){
		e->y -= y+dy-ymax;
		y = ymax-dy;
		warp++;
	}
	if(warp)
		setmouse(e->x, e->y, s);
	XMoveResizeWindow(dpy, s->menuwin, x, y, dx, dy);
	XSelectInput(dpy, s->menuwin, MenuMask);
	XMapRaised(dpy, s->menuwin);
	status = grab(s->menuwin, None, MenuGrabMask, None, e->time);
	if(status != GrabSuccess){
		/* graberror("menuhit", status); */
		XUnmapWindow(dpy, s->menuwin);
		return -1;
	}
	drawn = 0;
	for(;;){
		XMaskEvent(dpy, MenuMask, &ev);
		switch (ev.type){
		default:
			fprintf(stderr, "rio: menuhit: unknown ev.type %d\n", ev.type);
			break;
		case ButtonPress:
			break;
		case ButtonRelease:
			if(ev.xbutton.button != e->button)
				break;
			x = ev.xbutton.x;
			y = ev.xbutton.y;
			i = y/high;
			if(cur >= 0 && y >= cur*high-3 && y < (cur+1)*high+3)
				i = cur;
			if(x < 0 || x > wide || y < -3)
				i = -1;
			else if(i < 0 || i >= n)
				i = -1;
			else
				m->lasthit = i;
			if(!nobuttons(&ev.xbutton))
				i = -1;
			ungrab(&ev.xbutton);
			XUnmapWindow(dpy, s->menuwin);
			return i;
		case MotionNotify:
			if(!drawn)
				break;
			x = ev.xbutton.x;
			y = ev.xbutton.y;
			old = cur;
			cur = y/high;
			if(old >= 0 && y >= old*high-3 && y < (old+1)*high+3)
				cur = old;
			if(x < 0 || x > wide || y < -3)
				cur = -1;
			else if(cur < 0 || cur >= n)
				cur = -1;
			if(cur == old)
				break;
			if(old >= 0 && old < n)
				drawstring(dpy, s, m, wide, high, old, 0);
			if(cur >= 0 && cur < n)
				drawstring(dpy, s, m, wide, high, cur, 1);
			break;
		case Expose:
			XClearWindow(dpy, s->menuwin);
			for(i = 0; i < n; i++)
				drawstring(dpy, s, m, wide, high, i, cur==i);
			drawn = 1;
		}
	}
}
Esempio n. 7
0
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();
		}
	}
}
Esempio n. 8
0
void
button(XButtonEvent *e)
{
    int n, shift;
    Client *c;
    Window dw;
    ScreenInfo *s;

    curtime = e->time;
    s = getscreen(e->root);
    if(s == 0)
        return;
    c = getclient(e->window, 0);
    if(c) {
        if(debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n",
                              e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER);
        if(borderorient(c, e->x, e->y) != BorderUnknown) {
            switch (e->button) {
            case Button1:
            case Button2:
                reshape(c, e->button, pull, e);
                return;
            case Button3:
                move(c, Button3);
                return;
            default:
                return;
            }
        }
        e->x += c->x - BORDER;
        e->y += c->y - BORDER;
    } else if(e->window != e->root) {
        if(debug) fprintf(stderr, "but no client: e x=%d y=%d\n",
                              e->x, e->y);
        XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y,
                              &e->x, &e->y, &dw);
    }
    switch (e->button) {
    case Button1:
        if(c) {
            XMapRaised(dpy, c->parent);
            top(c);
            active(c);
        }
        return;
    case Button2:
        if(c) {
            XMapRaised(dpy, c->parent);
            active(c);
            XAllowEvents (dpy, ReplayPointer, curtime);
        } else if((e->state&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)) {
            menuhit(e, &egg);
        } else if(numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1)
            button2(n);
        return;
    case Button3:
        break;
    case Button4:
        /* scroll up changes to previous virtual screen */
        if(!c && e->type == ButtonPress)
            if(numvirtuals > 1 && virt > 0)
                switch_to(virt - 1);
        return;
    case Button5:
        /* scroll down changes to next virtual screen */
        if(!c && e->type == ButtonPress)
            if(numvirtuals > 1 && virt < numvirtuals - 1)
                switch_to(virt + 1);
        return;
    default:
        return;
    }

    if(current && current->screen == s)
        cmapnofocus(s);
    switch (n = menuhit(e, &b3menu)) {
    case New:
        spawn(s, termFn);
        break;
    case Acme:
        spawn(s, editorFn);
        break;
    case Launcher:
        spawn(s, launcherFn);
        break;
    case Reshape:
        reshape(selectwin(1, 0, s), Button3, sweep, 0);
        break;
    case Move:
        move(selectwin(0, 0, s), Button3);
        break;
    case Delete:
        shift = 0;
        c = selectwin(1, &shift, s);
        delete(c, shift);
        break;
    case Hide:
        hide(selectwin(1, 0, s));
        break;
    default:	/* unhide window */
        unhide(n - B3FIXED, 1);
        break;
    case -1:	/* nothing */
        break;
    }
    if(current && current->screen == s)
        cmapfocus(current);
}
Esempio n. 9
0
File: main.c Progetto: 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();
		}
	}
}