Example #1
0
/*
 * Check mouse coordinates and possibly set indicated portrait
 * mode from mouse position.
 */
void
GsSetPortraitModeFromXY(GR_COORD rootx, GR_COORD rooty)
{
	int newmode;

	if (rootx == 0) {
		/* rotate left*/
		switch (scrdev.portrait) {
		case MWPORTRAIT_NONE:
		default:
			newmode = MWPORTRAIT_LEFT;
			break;
		case MWPORTRAIT_LEFT:
			newmode = MWPORTRAIT_DOWN;
			break;
		case MWPORTRAIT_DOWN:
			newmode = MWPORTRAIT_RIGHT;
			break;
		case MWPORTRAIT_RIGHT:
			newmode = MWPORTRAIT_NONE;
			break;
		}
		GsSetPortraitMode(newmode);
		GrMoveCursor(5, rooty);
		GdMoveMouse(5, rooty);
	} else if (rootx == scrdev.xvirtres-1) {
		/* rotate right*/
		switch (scrdev.portrait) {
		case MWPORTRAIT_NONE:
		default:
			newmode = MWPORTRAIT_RIGHT;
			break;
		case MWPORTRAIT_LEFT:
			newmode = MWPORTRAIT_NONE;
			break;
		case MWPORTRAIT_DOWN:
			newmode = MWPORTRAIT_LEFT;
			break;
		case MWPORTRAIT_RIGHT:
			newmode = MWPORTRAIT_DOWN;
			break;
		}
		GsSetPortraitMode(newmode);
		GrMoveCursor(scrdev.xvirtres-5, rooty);
		GdMoveMouse(scrdev.xvirtres-5, rooty);
	}
}
Example #2
0
/*
 * Restrict the coordinates of the mouse to the specified coordinates.
 */
void
GdRestrictMouse(MWCOORD newminx, MWCOORD newminy, MWCOORD newmaxx,
	MWCOORD newmaxy)
{
	minx = newminx;
	miny = newminy;
	maxx = newmaxx;
	maxy = newmaxy;
	GdMoveMouse(xpos, ypos);
}
Example #3
0
/*
 * Initialize the graphics and mouse devices at startup.
 * Returns nonzero with a message printed if the initialization failed.
 */
int
GsInitialize(void)
{
	GR_WINDOW	*wp;		/* root window */
	static IMAGEBITS cursorbits[16] = {
	      0xe000, 0x9800, 0x8600, 0x4180,
	      0x4060, 0x2018, 0x2004, 0x107c,
	      0x1020, 0x0910, 0x0988, 0x0544,
	      0x0522, 0x0211, 0x000a, 0x0004
	};
	static IMAGEBITS cursormask[16] = {
	      0xe000, 0xf800, 0xfe00, 0x7f80,
	      0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc,
	      0x1fe0, 0x0ff0, 0x0ff8, 0x077c,
	      0x073e, 0x021f, 0x000e, 0x0004
	};

	wp = (GR_WINDOW *) malloc(sizeof(GR_WINDOW));
	if (wp == NULL) {
		fprintf(stderr, "Cannot allocate root window\n");
		return -1;
	}

#if !NONETWORK
	if (GsOpenSocket() < 0) {
		perror("Cannot bind to named socket");
		free(wp);
		return -1;
	}
#endif

	if ((keyb_fd = GdOpenKeyboard()) < 0) {
		perror("Cannot initialise keyboard");
		/*GsCloseSocket();*/
		free(wp);
		return -1;
	}

	if (GdOpenScreen() < 0) {
		perror("Cannot initialise screen");
		/*GsCloseSocket();*/
		GdCloseKeyboard();
		free(wp);
		return -1;
	}

	if ((mouse_fd = GdOpenMouse()) == -1) { /* -2 == mou_nul.c */
		perror("Cannot initialise mouse");
		/*GsCloseSocket();*/
		GdCloseScreen();
		GdCloseKeyboard();
		free(wp);
		return -1;
	}

	/*
	 * Get screen dimensions for our own and the client's use,
	 * and the information about the default font.
	 */
	GdGetScreenInfo(&scrdev, &sinfo);
	GdGetFontInfo(&scrdev, FONT_OEM_FIXED, &curfont);
	GdGetModifierInfo(&sinfo.modifiers);
	GdGetButtonInfo(&sinfo.buttons);

	/*
	 * Initialize the root window.
	 */
	wp->id = GR_ROOT_WINDOW_ID;
	wp->parent = wp;
	wp->children = NULL;
	wp->siblings = NULL;
	wp->next = NULL;
	wp->x = 0;
	wp->y = 0;
	wp->width = sinfo.cols;
	wp->height = sinfo.rows;
	wp->bordersize = 0;
	wp->background = BLACK;
	wp->bordercolor = BLACK;
	wp->nopropmask = 0;
	wp->eventclients = NULL;
	wp->cursor = NULL;
	wp->mapped = GR_TRUE;
	wp->unmapcount = 0;
	wp->output = GR_TRUE;

	listwp = wp;
	rootwp = wp;
	focuswp = wp;
	mousewp = wp;
	focusfixed = GR_FALSE;

	/*
	 * Initialize and position the default cursor.
	 */
	curcursor = NULL;
	cursorx = -1;
	cursory = -1;
	GsMoveCursor(sinfo.cols / 2, sinfo.rows / 2);
	GsSetCursor(GR_ROOT_WINDOW_ID, 16, 16, 0, 0, WHITE, BLACK,
		cursorbits, cursormask);

#if FRAMEBUFFER | BOGL
	fb_InitVt();
#endif
	scrdev.FillRect(&scrdev, 0, 0, sinfo.cols-1, sinfo.rows-1,
		GdFindColor(BLACK));

	/*
	 * Finally tell the mouse driver some things.
	 */
	curbuttons = 0;
	/*GdSetAccelMouse(5, 3);*/
	GdRestrictMouse(0, 0, sinfo.cols - 1, sinfo.rows - 1);
	GdMoveMouse(sinfo.cols / 2, sinfo.rows / 2);
	GsFlush();

	/*
	 * All done.
	 */
	connectcount = 0;
	return 0;
}
Example #4
0
/**
 * Read the current location and button states of the mouse.
 * Returns -1 on read error.
 * Returns 0 if no new data is available from the mouse driver,
 * or if the new data shows no change in button state or position.
 * Returns 1 if the mouse driver tells us a changed button state
 * or position. Button state and position are always both returned,
 * even if only one or the other changes.
 * Do not block.
 *
 * @param px On return, holds the mouse X co-ordinate.
 * @param py On return, holds the mouse Y co-ordinate.
 * @param pb On return, holds the buttons status.
 * @return -1 on error, 0 if mouse has not moved, 1 if mouse has moved.
 */
int
GdReadMouse(MWCOORD *px, MWCOORD *py, int *pb)
{
	MWCOORD	x, y, z;
	int	newbuttons;	/* new button state */
	int	status;		/* status of reading mouse */
	MWCOORD dx, dy;

	*px = xpos;
	*py = ypos;
	*pb = buttons;

	if (changed) {
		changed = FALSE;
		return 1;
	}

	/* read the mouse position */
	status = mousedev.Read(&x, &y, &z, &newbuttons);
	if (status < 0)
		return -1;

	/* no new info from the mouse driver? */
	if (status == 0)
		return 0;

	/* Relative mice have their own process */
	if (status == 1) {
		int rx, ry;
		filter_relative(status, thresh, scale, &rx, &ry, x, y);
#if FLIP_MOUSE_IN_PORTRAIT_MODE
		dx = xpos;
		dy = ypos;
		filter_relrotate(status, &dx, &dy, x, y);
#else
		dx = xpos + rx;
		dy = ypos + ry;
#endif
	} else {
		dx = x;
		dy = y;

		/* Transformed coords should already have their rotation handled */
		if (mousedev.flags & MOUSE_TRANSFORM)  {
			if (!filter_transform(status, &dx, &dy))
				return 0;
		}
#if FLIP_MOUSE_IN_PORTRAIT_MODE
		if (!(mousedev.flags & MOUSE_RAW))
			filter_absrotate(status, &dx, &dy);
#endif	
	}

	/* 
	 * At this point, we should have a valid mouse point. Check the button
	 * state and set the flags accordingly.  We do this *after* the filters,
	 * because some of the filters (like the transform) need to be called
	 * several times before we get valid data.
	 */
	if (buttons != newbuttons) {
		changed = TRUE;
		buttons = newbuttons;
	}

	/* Finally, move the mouse */
	if (status != 3)
		GdMoveMouse(dx, dy);

	/* anything change? */
	if (!changed)
		return 0;

	/* report new mouse data */
	changed = FALSE;
	*px = xpos;
	*py = ypos;
	*pb = buttons;

	return 1;
}
Example #5
0
/*
 * Initialize the graphics and mouse devices at startup.
 * Returns nonzero with a message printed if the initialization failed.
 */
int
MwInitialize(void)
{
	HWND		wp;		/* root window */
	PSD		psd;
	WNDCLASS	wc;
	int		fd;
	static MWCURSOR arrow = {	/* default arrow cursor*/
		16, 16,
		0,  0,
		RGB(255, 255, 255), RGB(0, 0, 0),
		{ 0xe000, 0x9800, 0x8600, 0x4180,
		  0x4060, 0x2018, 0x2004, 0x107c,
		  0x1020, 0x0910, 0x0988, 0x0544,
		  0x0522, 0x0211, 0x000a, 0x0004 },
		{ 0xe000, 0xf800, 0xfe00, 0x7f80,
		  0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc,
		  0x1fe0, 0x0ff0, 0x0ff8, 0x077c,
		  0x073e, 0x021f, 0x000e, 0x0004 }
	};

	extern MWLISTHEAD mwClassHead;

#if (UNIX | DOS_DJGPP) && !_MINIX
	for (fd = 0; fd < FD_SETSIZE; fd++) {
		userregfd[fd].read = NULL;
		userregfd[fd].write = NULL;
		userregfd[fd].except = NULL;
		userregfd[fd].next = -1;
  	}
	userregfd_head = -1;
#endif
	/* catch terminate signal to restore tty state*/
	signal(SIGTERM, (void *)MwTerminate);

	startTicks = GetTickCount();

	if ((keyb_fd = GdOpenKeyboard()) == -1) {
		EPRINTF("Cannot initialise keyboard\n");
		return -1;
	}

	if ((psd = GdOpenScreen()) == NULL) {
		EPRINTF("Cannot initialise screen\n");
		GdCloseKeyboard();
		return -1;
	}

	if ((mouse_fd = GdOpenMouse()) == -1) {
		EPRINTF("Cannot initialise mouse\n");
		GdCloseScreen(psd);
		GdCloseKeyboard();
		return -1;
	}

#if ANIMATEPALETTE
	setfadelevel(psd, 0);
#endif
	/*
	 * Initialize the root window.
	 */
	wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
	wc.lpfnWndProc = (WNDPROC)DefWindowProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = 0;
	wc.hIcon = 0; /*LoadIcon(GetHInstance(), MAKEINTRESOURCE( 1));*/
	wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/
	wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));
	wc.lpszMenuName = NULL;
	wc.lpszClassName =  "DeskTop";
	RegisterClass( &wc);
	
	wp = GdItemNew(struct hwnd);
	if (!wp) {
		EPRINTF("No memory for root window\n");
		GdCloseMouse();
		GdCloseScreen(psd);
		GdCloseKeyboard();
		return -1;
	}
	/* remove the WS_CAPTION to have bare desktop window*/
	/*wp->style = WS_CLIPCHILDREN | WS_CAPTION | WS_VISIBLE;*/
	wp->style = WS_CLIPCHILDREN | WS_VISIBLE;
	wp->exstyle = 0;
	wp->pClass = (PWNDCLASS)mwClassHead.head;
	wp->parent = NULL;
	wp->children = NULL;
	wp->siblings = NULL;
	wp->next = NULL;
	SetRect(&wp->winrect, 0, 0, psd->xvirtres, psd->yvirtres);
	MwCalcClientRect(wp);
	wp->cursor = NULL;
	wp->unmapcount = 0;
	wp->id = 0;
	strcpy(wp->szTitle, "Microwindows");
	wp->gotPaintMsg = PAINT_PAINTED;
#if UPDATEREGIONS
	wp->update = GdAllocRegion();
#endif

	listwp = wp;
	rootwp = wp;
	focuswp = wp;
	mousewp = wp;

	/* schedule desktop window paint*/
	InvalidateRect(rootwp, NULL, TRUE);

#if VTSWITCH
	MwInitVt();
	/* Check for VT change every 50 ms: */
	GdAddTimer(50, CheckVtChange, NULL);
#endif

	/*
	 * Initialize and position the default cursor.
	 */
	curcursor = NULL;
	cursorx = -1;
	cursory = -1;
	GdShowCursor(psd);
	MwMoveCursor(psd->xvirtres / 2, psd->yvirtres / 2);
	MwSetCursor(rootwp, &arrow);

	/*
	 * Finally tell the mouse driver some things.
	 */
	GdRestrictMouse(0, 0, psd->xvirtres - 1, psd->yvirtres - 1);
	GdMoveMouse(psd->xvirtres / 2, psd->yvirtres / 2);

	return 0;
}
Example #6
0
/*
 * Initialize the graphics and mouse devices at startup.
 * Returns nonzero with a message printed if the initialization failed.
 */
int
GsInitialize(void)
{
	GR_WINDOW	*wp;		/* root window */
	PSD		psd;
	GR_CURSOR_ID	cid;
	static MWIMAGEBITS cursorbits[16] = {
	      0xe000, 0x9800, 0x8600, 0x4180,
	      0x4060, 0x2018, 0x2004, 0x107c,
	      0x1020, 0x0910, 0x0988, 0x0544,
	      0x0522, 0x0211, 0x000a, 0x0004
	};
	static MWIMAGEBITS cursormask[16] = {
	      0xe000, 0xf800, 0xfe00, 0x7f80,
	      0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc,
	      0x1fe0, 0x0ff0, 0x0ff8, 0x077c,
	      0x073e, 0x021f, 0x000e, 0x0004
	};

	/* If needed, initialize the server mutex. */
	SERVER_LOCK_INIT();

	setbuf(stdout, NULL);
	setbuf(stderr, NULL);

	wp = (GR_WINDOW *) malloc(sizeof(GR_WINDOW));
	if (wp == NULL) {
		EPRINTF("Cannot allocate root window\n");
		return -1;
	}

	startTicks = GsGetTickCount();

#ifndef MW_NOSIGNALS
	/* catch terminate signal to restore tty state*/
	signal(SIGTERM, (void *)GsTerminate);
#endif

#if MW_FEATURE_TIMERS
	screensaver_delay = 0;
#endif
	screensaver_active = GR_FALSE;

	selection_owner.wid = 0;
	selection_owner.typelist = NULL;

#if !NONETWORK
#ifndef MW_NOSIGNALS
	/* ignore pipe signal, sent when clients exit*/
	signal(SIGPIPE, SIG_IGN);
	signal(SIGHUP, SIG_IGN);
#endif

	if (GsOpenSocket() < 0) {
		EPRINTF("Cannot bind to named socket\n");
		free(wp);
		return -1;
	}
#endif

	if ((keyb_fd = GdOpenKeyboard()) == -1) {
		EPRINTF("Cannot initialise keyboard\n");
		/*GsCloseSocket();*/
		free(wp);
		return -1;
	}

#ifdef MW_FEATURE_TWO_KEYBOARDS
	if ((keyb2_fd = GdOpenKeyboard2()) == -1) {
		EPRINTF("Cannot initialise second keyboard\n");
		/*GsCloseSocket();*/
		free(wp);
		return -1;
	}
#endif

	if ((psd = GdOpenScreen()) == NULL) {
		EPRINTF("Cannot initialise screen\n");
		/*GsCloseSocket();*/
		GdCloseKeyboard();
		free(wp);
		return -1;
	}
	GdSetPortraitMode(psd, portraitmode);

	if ((mouse_fd = GdOpenMouse()) == -1) {
		EPRINTF("Cannot initialise mouse\n");
		/*GsCloseSocket();*/
		GdCloseScreen(psd);
		GdCloseKeyboard();
		free(wp);
		return -1;
	}

	/*
	 * Create std font.
	 */
#if (HAVE_BIG5_SUPPORT | HAVE_GB2312_SUPPORT | HAVE_JISX0213_SUPPORT | HAVE_KSC5601_SUPPORT)
	/* system fixed font looks better when mixed with builtin fixed fonts*/
	stdfont = GdCreateFont(psd, MWFONT_SYSTEM_FIXED, 0, NULL);
#else
	stdfont = GdCreateFont(psd, MWFONT_SYSTEM_VAR, 0, NULL);
#endif

	/*
	 * Initialize the root window.
	 */
	wp->psd = psd;
	wp->id = GR_ROOT_WINDOW_ID;
	wp->parent = NULL;		/* changed: was = NULL*/
	wp->owner = NULL;
	wp->children = NULL;
	wp->siblings = NULL;
	wp->next = NULL;
	wp->x = 0;
	wp->y = 0;
	wp->width = psd->xvirtres;
	wp->height = psd->yvirtres;
	wp->bordersize = 0;
	wp->background = BLACK;
	wp->bordercolor = wp->background;
	wp->nopropmask = 0;
	wp->bgpixmap = NULL;
	wp->bgpixmapflags = GR_BACKGROUND_TILE;
	wp->eventclients = NULL;
	wp->cursorid = 0;
	wp->mapped = GR_TRUE;
	wp->realized = GR_TRUE;
	wp->output = GR_TRUE;
	wp->props = 0;
	wp->title = NULL;
	wp->clipregion = NULL;

        listpp = NULL;
	listwp = wp;
	rootwp = wp;
	focuswp = wp;
	mousewp = wp;
	focusfixed = GR_FALSE;

	/*
	 * Initialize and position the default cursor.
	 */
	curcursor = NULL;
	cursorx = -1;
	cursory = -1;
	GdShowCursor(psd);
	GsMoveCursor(psd->xvirtres / 2, psd->yvirtres / 2);

	SERVER_UNLOCK();
	cid = GrNewCursor(16, 16, 0, 0, WHITE, BLACK, cursorbits, cursormask);
	GrSetWindowCursor(GR_ROOT_WINDOW_ID, cid);
	SERVER_LOCK();

	stdcursor = GsFindCursor(cid);

#if VTSWITCH
	MwInitVt();
	/* Check for VT change every 50 ms: */
	GdAddTimer(50, CheckVtChange, NULL);
#endif
	psd->FillRect(psd, 0, 0, psd->xvirtres-1, psd->yvirtres-1,
		GdFindColor(psd, wp->background));

	/*
	 * Tell the mouse driver some things.
	 */
	curbuttons = 0;
	GdRestrictMouse(0, 0, psd->xvirtres - 1, psd->yvirtres - 1);
	GdMoveMouse(psd->xvirtres / 2, psd->yvirtres / 2);

	/* Force root window screen paint*/
	GsRedrawScreen();

	/*
	 * Force the cursor to appear on the screen at startup.
	 * (not required with above GsRedrawScreen)
	GdHideCursor(psd);
	GdShowCursor(psd);
	 */

	/*
	 * All done.
	 */
	connectcount = 0;
	return 0;
}
Example #7
0
/*
 * Read the current location and button states of the mouse.
 * Returns -1 on read error.
 * Returns 0 if no new data is available from the mouse driver,
 * or if the new data shows no change in button state or position.
 * Returns 1 if the mouse driver tells us a changed button state
 * or position. Button state and position are always both returned,
 * even if only one or the other changes.
 * Do not block.
 */
int
GdReadMouse(MWCOORD *px, MWCOORD *py, int *pb)
{
	MWCOORD	x, y, z;
	int	newbuttons;	/* new button state */
	int	sign;		/* sign of change */
	int	status;		/* status of reading mouse */

	*px = xpos;
	*py = ypos;
	*pb = buttons;

	if (changed) {
		changed = FALSE;
		return 1;
	}

	/* read the mouse position */
	status = mousedev.Read(&x, &y, &z, &newbuttons);
	if (status < 0)
		return -1;

	/* no new info from the mouse driver? */
	if (status == 0)
		return 0;

	/* has the button state changed? */
	if (buttons != newbuttons) {
		changed = TRUE;
		buttons = newbuttons;
	}

	/* depending on the kind of data that we have */
	switch(status) {
	case 1:	/* relative position change reported, figure new position */
		sign = 1;
		if (x < 0) {
			sign = -1;
			x = -x;
		}
		if (x > thresh)
			x = thresh + (x - thresh) * scale;
		x *= sign;

		sign = 1;
		if (y < 0) {
			sign = -1;
			y = -y;
		}
		if (y > thresh)
			y = thresh + (y - thresh) * scale;
		y *= sign;

#if FLIP_MOUSE_IN_PORTRAIT_MODE
		if (scrdev.portrait == MWPORTRAIT_RIGHT)
			GdMoveMouse(xpos + y, ypos - x);	/* right*/
		else if (scrdev.portrait == MWPORTRAIT_LEFT)
			GdMoveMouse(xpos - y, ypos + x);	/* left*/
		else if (scrdev.portrait == MWPORTRAIT_DOWN)
			GdMoveMouse(xpos + x, ypos - y);	/* down*/
		else 
#endif
			GdMoveMouse(xpos + x, ypos + y);
		break;

	case 2:	/* absolute position reported */
#if FLIP_MOUSE_IN_PORTRAIT_MODE
		if (scrdev.portrait == MWPORTRAIT_RIGHT)
			GdMoveMouse(y, scrdev.xres - x - 1);	/* right*/
		else if (scrdev.portrait == MWPORTRAIT_LEFT)
			GdMoveMouse(scrdev.yres - y - 1, x);	/* left*/
		else if (scrdev.portrait == MWPORTRAIT_DOWN)
			GdMoveMouse(x, scrdev.yres - y - 1);	/* down?*/
		else 
#endif
			GdMoveMouse(x, y);
		break;

	case 3:	/* only button data is available */
		break;
	}
 
	/* didn't anything change? */
	if (!changed)
		return 0;

	/* report new mouse data */
	changed = FALSE;
	*px = xpos;
	*py = ypos;
	*pb = buttons;
	return 1;
}