コード例 #1
0
ファイル: x11-srv.c プロジェクト: carriercomm/plan9tweaks
/*
 * Handle an incoming X event.
 */
void
runxevent(XEvent *xev)
{
	int c;
	KeySym k;
	static Mouse m;
	XButtonEvent *be;
	XKeyEvent *ke;

#ifdef SHOWEVENT
	static int first = 1;
	if(first){
		dup(create("/tmp/devdraw.out", OWRITE, 0666), 1);
		setbuf(stdout, 0);
		first = 0;
	}
#endif

	if(xev == 0)
		return;

#ifdef SHOWEVENT
	print("\n");
	ShowEvent(xev);
#endif

	switch(xev->type){
	case Expose:
		_xexpose(xev);
		break;
	
	case DestroyNotify:
		if(_xdestroy(xev))
			exits(0);
		break;

	case ConfigureNotify:
		if(_xconfigure(xev)){
			mouse.resized = 1;
			_xreplacescreenimage();
			sendmouse(m);
		}
		break;

	case ButtonPress:
		be = (XButtonEvent*)xev;
		if(be->button == 1) {
			if(kstate & ControlMask)
				be->button = 2;
			else if(kstate & Mod1Mask)
				be->button = 3;
		}
		// fall through
	case ButtonRelease:
		altdown = 0;
		// fall through
	case MotionNotify:
		if(mouse.stall)
			return;
		if(_xtoplan9mouse(xev, &m) < 0)
			return;
		sendmouse(m);
		break;
	
	case KeyRelease:
	case KeyPress:
		ke = (XKeyEvent*)xev;
		XLookupString(ke, NULL, 0, &k, NULL);
		c = ke->state;
		switch(k) {
		case XK_Alt_L:
		case XK_Meta_L:	/* Shift Alt on PCs */
		case XK_Alt_R:
		case XK_Meta_R:	/* Shift Alt on PCs */
		case XK_Multi_key:
			if(xev->type == KeyPress)
				altdown = 1;
			else if(altdown) {
				altdown = 0;
				sendalt();
			}
			break;
		}

		switch(k) {
		case XK_Control_L:
			if(xev->type == KeyPress)
				c |= ControlMask;
			else
				c &= ~ControlMask;
			goto kbutton;
		case XK_Alt_L:
		case XK_Shift_L:
			if(xev->type == KeyPress)
				c |= Mod1Mask;
			else
				c &= ~Mod1Mask;
		kbutton:
			kstate = c;
			if(m.buttons || kbuttons) {
				altdown = 0; // used alt
				kbuttons = 0;
				if(c & ControlMask)
					kbuttons |= 2;
				if(c & Mod1Mask)
					kbuttons |= 4;
				sendmouse(m);
				break;
			}
		}

		if(xev->type != KeyPress)
			break;
		if(k == XK_F11){
			fullscreen = !fullscreen;
			_xmovewindow(fullscreen ? screenrect : windowrect);
			return;
		}
		if(kbd.stall)
			return;
		if((c = _xtoplan9kbd(xev)) < 0)
			return;
		kbd.r[kbd.wi++] = c;
		if(kbd.wi == nelem(kbd.r))
			kbd.wi = 0;
		if(kbd.ri == kbd.wi)
			kbd.stall = 1;
		matchkbd();
		break;
	
	case FocusOut:
		abortcompose();
		break;
	
	case SelectionRequest:
		_xselect(xev);
		break;
	}
}
コード例 #2
0
ファイル: ui.cpp プロジェクト: dreamsxin/journey_client
	void ui::sendmouse(vector2d pos)
	{
		sendmouse(mouse.getstate(), pos);
	}