static void CheckVtChange(void *arg) { if(MwCheckVtChange()) GsRedrawScreen(); GdAddTimer(50, CheckVtChange, NULL); }
/* * Set dynamic portrait mode and redraw screen. */ void GsSetPortraitMode(int mode) { GdSetPortraitMode(&scrdev, mode); GdRestrictMouse(0, 0, scrdev.xvirtres - 1, scrdev.yvirtres - 1); /* reset clip and root window size*/ clipwp = NULL; rootwp->width = scrdev.xvirtres; rootwp->height = scrdev.yvirtres; /* deliver portrait changed event to all windows selecting it*/ GsDeliverPortraitChangedEvent(); /* redraw screen - apps may redraw/resize again causing flicker*/ GsRedrawScreen(); }
/* * Update keyboard status and issue events on it if necessary. * This function doesn't block, but is normally only called when * there is known to be some data waiting to be read from the keyboard. */ GR_BOOL GsCheckKeyboardEvent(void) { MWKEY mwkey; /* latest character */ MWKEYMOD modifiers; /* latest modifiers */ MWSCANCODE scancode; int keystatus; /* latest keyboard status */ /* Read the latest keyboard status: */ keystatus = GdReadKeyboard(&mwkey, &modifiers, &scancode); if(keystatus < 0) { if(keystatus == -2) /* special case return code*/ GsTerminate(); GsError(GR_ERROR_KEYBOARD_ERROR, 0); return FALSE; } else if(keystatus) { /* Deliver events as appropriate: */ switch (mwkey) { case MWKEY_QUIT: GsTerminate(); /* no return*/ case MWKEY_REDRAW: GsRedrawScreen(); break; case MWKEY_PRINT: if (keystatus == 1) GdCaptureScreen("screen.bmp"); break; } GsDeliverKeyboardEvent(0, (keystatus==1? GR_EVENT_TYPE_KEY_DOWN: GR_EVENT_TYPE_KEY_UP), mwkey, modifiers, scancode); return TRUE; } return FALSE; }
void GsSelect(void) { fd_set rfds; int e; int setsize = 0; struct timeval to; /* Set up the FDs for use in the main select(): */ FD_ZERO(&rfds); FD_SET(mouse_fd, &rfds); FD_SET(keyb_fd, &rfds); if (mouse_fd > setsize) setsize = mouse_fd; if (keyb_fd > setsize) setsize = keyb_fd; #if NONETWORK /* handle registered input file descriptors*/ if (regfd != -1) { FD_SET(regfd, &rfds); if (regfd > setsize) setsize = regfd; } #else /* handle client socket connections*/ FD_SET(un_sock, &rfds); if (un_sock > setsize) setsize = un_sock; curclient = root_client; while(curclient) { if(curclient->waiting_for_event && curclient->eventhead) { curclient->waiting_for_event = FALSE; GsGetNextEventWrapperFinish(); return; } FD_SET(curclient->id, &rfds); if(curclient->id > setsize) setsize = curclient->id; curclient = curclient->next; } #endif ++setsize; /* Set up the timeout for the main select(): */ to.tv_sec = 0L; to.tv_usec = 10000L; /* Wait for some input on any of the fds in the set or a timeout: */ if((e = select(setsize, &rfds, NULL, NULL, &to)) > 0) { /* If data is present on the mouse fd, service it: */ if(FD_ISSET(mouse_fd, &rfds)) GsCheckMouseEvent(); /* If data is present on the keyboard fd, service it: */ if(FD_ISSET(keyb_fd, &rfds)) GsCheckKeyboardEvent(); #if NONETWORK /* If registered input descriptor, handle it*/ if(regfd != -1 && FD_ISSET(regfd, &rfds)) { GR_EVENT_FDINPUT * gp; gp = (GR_EVENT_FDINPUT *)GsAllocEvent(curclient); if(gp) { gp->type = GR_EVENT_TYPE_FDINPUT; gp->fd = regfd; } } #else /* If a client is trying to connect, accept it: */ if(FD_ISSET(un_sock, &rfds)) GsAcceptClient(); /* If a client is sending us a command, handle it: */ curclient = root_client; while(curclient) { if(FD_ISSET(curclient->id, &rfds)) GsHandleClient(curclient->id); curclient = curclient->next; } #endif } else if(!e) { #if FRAMEBUFFER | BOGL if(fb_CheckVtChange()) GsRedrawScreen(); #endif } else if(errno != EINTR) perror("Select() call in main failed"); }
/* * 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; }