int GIIdl_filter_keytrans(gii_input *inp, const char *args, void *argptr) { fkey_priv *priv; DPRINT_MISC("filter-keymap init(%p, \"%s\") called\n", inp, args ? args : ""); priv = malloc(sizeof(fkey_priv)); if (priv == NULL) return GGI_ENOMEM; if(_giiRegisterDevice(inp,&devinfo,NULL)==0) { free(priv); return GGI_ENOMEM; } priv->table = NULL; priv->numentries = 0; fkey_loadmap(args,priv); inp->priv = priv; inp->GIIhandler = GII_fkey_handler; inp->GIIclose = GII_fkey_close; DPRINT_MISC("filter-keymap fully up\n"); return 0; }
int GIIdl_filter_mouse(gii_input *inp, const char *args, void *argptr) { fmouse_priv *priv; DPRINT_MISC("filter-mouse init(%p, \"%s\") called\n", inp, args ? args : ""); priv = malloc(sizeof(fmouse_priv)); if (priv == NULL) return GGI_ENOMEM; if(_giiRegisterDevice(inp,&devinfo,NULL)==0) { free(priv); return GGI_ENOMEM; } priv->entry = NULL; priv->modifiers = 0; fmouse_loadmap(args,priv); inp->priv = priv; inp->GIIhandler = GII_fmouse_handler; inp->GIIclose = GII_fmouse_close; DPRINT_MISC("filter-mouse fully up\n"); return 0; }
static ggi_event_mask GII_ipc_poll(gii_input_t inp, void *arg) { ggi_ipc_priv *priv=inp->priv; ggi_event ev; int rc=0; while(priv->inputoffset!=priv->inputbuffer->writeoffset) { if (priv->inputbuffer->buffer[priv->inputoffset++] != MEMINPMAGIC) { DPRINT_MISC("OUT OF SYNC in shm input !\n"); priv->inputoffset=0; /* Try to resync */ return 0; } /* if */ memcpy(&ev, &(priv->inputbuffer->buffer[priv->inputoffset]), (size_t)(priv->inputbuffer->buffer[priv->inputoffset])); _giiEvQueueAdd(inp, &ev); priv->inputoffset += ev.any.size; rc |= 1 << ev.any.type; if (priv->inputoffset >= (signed)(INPBUFSIZE - sizeof(ggi_event) - sizeof(priv->inputbuffer->writeoffset) - 10)) { priv->inputoffset=0; } /* if */ } /* while */ return rc; } /* GII_ipc_poll */
static void zip(ggi_vnc_client *client, uint8_t *src, int len) { struct zlib_ctx_t *ctx = client->zlib_ctx; int start = client->wbuf.size; int avail; uint32_t done = 0; ctx->zstr.next_in = src; ctx->zstr.avail_in = len; client->wbuf.size += 4; avail = client->wbuf.limit - client->wbuf.size; for (;;) { ctx->zstr.next_out = &client->wbuf.buf[client->wbuf.size + done]; ctx->zstr.avail_out = avail - done; deflate(&ctx->zstr, Z_SYNC_FLUSH); done = avail - ctx->zstr.avail_out; if (ctx->zstr.avail_out) break; avail += 1000; GGI_vnc_buf_reserve(&client->wbuf, client->wbuf.size + avail); } insert_hilo_32(&client->wbuf.buf[start], done); client->wbuf.size += done; DPRINT_MISC("raw %d z %d %d%%\n", len, done, done * 100 / len); }
static int GII_fkey_close(gii_input *inp) { fkey_priv *priv = inp->priv; DPRINT_MISC("GII_fkey_close(%p) called\n", inp); free(priv->table); free(inp->priv); return 0; }
static int GII_xdga_close(gii_input *inp) { xdga_priv *priv = XDGA_PRIV(inp); free(priv); DPRINT_MISC("GII_xdga_close(%p) called\n", inp); return 0; }
static int do_cleanup(ggi_visual *vis) { ggi_fbdev_priv *fbdevpriv = FBDEV_PRIV(vis); struct m2164w_priv *priv = NULL; int i; DPRINT_MISC("mga-2164w: Starting cleanup\n"); if (fbdevpriv != NULL) { priv = M2164W_PRIV(vis); } /* We may be called more than once due to the LibGG cleanup stuff */ if (priv == NULL) return 0; /* Restore OPMODE and terminate any pending DMA operations Manual says we should write to byte 0 to terminate DMA sequence, but it doesn't say whether a 8 bit access is required, or if any access will do. We play it safe here... */ mga_out8(fbdevpriv->mmioaddr, priv->origopmode & 0xff, OPMODE); mga_out16(fbdevpriv->mmioaddr, priv->origopmode, OPMODE); mga_waitidle(fbdevpriv->mmioaddr); munmap((void*)fbdevpriv->mmioaddr, fbdevpriv->orig_fix.mmio_len); DPRINT_MISC("mga-2164w: Unmapped MMIO\n"); /* Free DB resource structures */ for (i = LIBGGI_APPLIST(vis)->num-1; i >= 0; i--) { if (LIBGGI_APPBUFS(vis)[i]->resource) { free(LIBGGI_APPBUFS(vis)[i]->resource); LIBGGI_APPBUFS(vis)[i]->resource = NULL; } } free(priv); FBDEV_PRIV(vis)->accelpriv = NULL; ggUnregisterCleanup((ggcleanup_func *)do_cleanup, vis); return 0; }
static int GII_fkey_handler(gii_input *inp, gii_event *event) { fkey_priv *priv = inp->priv; mapping_entry *entry; int x; static int di_sent=0; if (di_sent==0) { di_sent=1;send_devinfo(inp); } DPRINT_MISC("filter-keymap: Filt check.\n"); if (event->any.origin==inp->origin) return 0; /* avoid recursion ! */ DPRINT_MISC("filter-keymap: Real check.\n"); if (event->any.type!=evKeyPress && event->any.type!=evKeyRelease && event->any.type!=evKeyRepeat) return 0; /* No keyboard event - ignore it */ DPRINT_MISC("filter-keymap: Key event - looking.\n"); for(x=priv->numentries,entry=priv->table;x--;entry++) { DPRINT_MISC("filter-keymap: Table.\n"); if ( (event->key.modifiers&entry->modifier_mask) == entry->modifier_value && (entry->symin ==GIIK_NIL || entry->symin ==event->key.sym) && (entry->labelin ==GIIK_NIL || entry->labelin ==event->key.label) && (entry->buttonin==GIIK_NIL || entry->buttonin==event->key.button) ) { DPRINT_MISC("filter-keymap: Key event - got it - sending.\n"); fkey_send_key(inp, event->key.type, (event->key.modifiers&~entry->modifier_changemask)|entry->modifier_ormask, (entry->buttonout==GIIK_NIL) ? event->key.button : entry->buttonout, (entry->labelout ==GIIK_NIL) ? event->key.label : entry->labelout, (entry->symout ==GIIK_NIL) ? event->key.sym : entry->symout ); return 1; } } return 0; }
int GIIdl_linux_kbd(gii_input *inp, const char *args, void *argptr) { const char *filename = "/dev/tty"; DPRINT_MISC("linux_kbd starting.(args=\"%s\",argptr=%p)\n", args, argptr); /* Initialize */ if (args && *args) { filename = args; } if(_giiRegisterDevice(inp,&devinfo,NULL)==0) { return GGI_ENOMEM; } if (GII_keyboard_init(inp, filename) < 0) { return GGI_ENODEVICE; } /* Make sure the keyboard is reset when the app terminates */ ggRegisterCleanup((ggcleanup_func *)GII_lin_kbd_close, inp); inp->GIIsendevent = GIIsendevent; inp->GIIeventpoll = GII_keyboard_poll; inp->GIIclose = GII_lin_kbd_close; inp->targetcan = emKey; inp->GIIseteventmask(inp, inp->targetcan); inp->maxfd = LINKBD_PRIV(inp)->fd + 1; FD_SET(LINKBD_PRIV(inp)->fd, &inp->fdset); /* Send initial cmdDevInfo event */ send_devinfo(inp); DPRINT_MISC("linux_kbd fully up\n"); return 0; }
static int fkey_doload(const char *filename,fkey_priv *priv) { FILE *infile; mapping_entry *newmap,mapbuf; char buffer[2048]; DPRINT_MISC("filter-keymap opening config \"%s\" called\n", filename ? filename : "(nil)"); if ( NULL==(infile=fopen(filename,"r")) ) { return GGI_ENOFILE; } while(fgets(buffer,2048,infile)) { if ( 10 != sscanf(buffer,"%u %u %u %u %u %u %u %u %u %u", &mapbuf.modifier_mask, &mapbuf.modifier_value, &mapbuf.buttonin, &mapbuf.labelin, &mapbuf.symin, &mapbuf.modifier_changemask, &mapbuf.modifier_ormask, &mapbuf.buttonout, &mapbuf.labelout, &mapbuf.symout ) ) continue; /* Seems not a legal entry */ DPRINT_MISC("filter-keymap have entry #%d\n",priv->numentries); newmap=realloc(priv->table,(priv->numentries+1)*sizeof(mapping_entry)); if (newmap) { priv->table=newmap; priv->table[priv->numentries]=mapbuf; priv->numentries++; } else { free(priv->table); fclose(infile); return GGI_ENOMEM; } } fclose(infile); return 0; }
static int GII_fmouse_close(gii_input *inp) { fmouse_priv *priv = inp->priv; mapping_entry *entry,*next; DPRINT_MISC("GII_fmouse_close(%p) called\n", inp); entry=priv->entry; while(entry) { next=entry->next; free(entry); entry=next; } free(priv); return 0; }
static void handle_telecmd_event(ggi_tele_priv *priv, TeleEvent *ev) { /* handle TELE_CMD_CLOSE ??? */ if ((priv->wait_event == NULL) || (priv->wait_type != ev->type) || (priv->wait_sequence != ev->sequence)) { DPRINT_MISC("display-tele: UNEXPECTED CMD EVENT " "(type=0x%08x seq=0x%08x)\n", ev->type, ev->sequence); return; } DPRINT_EVENTS("display-tele: GOT REPLY (type=0x%08lx " "seq=0x%08lx)\n", ev->type, ev->sequence); memcpy(priv->wait_event, ev, ev->size * sizeof(long)); }
static int GII_lin_kbd_close(gii_input *inp) { linkbd_priv *priv = LINKBD_PRIV(inp); DPRINT_MISC("Linux-kbd cleanup\n"); if (priv == NULL) { /* Make sure we're only called once */ return 0; } if (priv->old_kbled != 0x7f) { ioctl(priv->fd, KDSKBLED, priv->old_kbled); } if (ioctl(priv->fd, KDSKBMODE, priv->old_mode) < 0) { perror("Linux-kbd: couldn't restore mode"); } if (tcsetattr(priv->fd, TCSANOW, &priv->old_termios) < 0) { perror("Linux-kbd: tcsetattr failed"); } close(priv->fd); free(priv); inp->priv = NULL; ggUnregisterCleanup((ggcleanup_func *)GII_lin_kbd_close, inp); fputc('\n', stderr); fflush(stderr); DPRINT("Linux-kbd: exit OK.\n"); return 0; }
static int GII_fmouse_handler(gii_input *inp, gii_event *event) { fmouse_priv *priv = inp->priv; mapping_entry *entry; int ret = 0; int has = 0; int invalue=0; static int di_sent=0; gii_pmove_event pmrel,pmabs; /* Did we already send the device info record ? Do so, if we didn't. */ if (di_sent==0) { di_sent=1; send_devinfo(inp); } DPRINT_MISC("filter-mouse: Filt check.\n"); if (event->any.origin==inp->origin) return 0; /* avoid recursion ! */ DPRINT_MISC("filter-mouse: Real check.\n"); /* Track modifiers. This allows to use stuff like shift-clicking */ if (event->any.type==evKeyPress || event->any.type==evKeyRepeat || event->any.type==evKeyRelease) { priv->modifiers=event->key.modifiers; } /* Clear the eventual relative and absolute events that will * get sent after evaluating all rules. We should probably keep the * absolute events between calls. */ _giiEventBlank((gii_event *)&pmrel, sizeof(gii_pmove_event)); pmrel.type = evPtrRelative; pmrel.size = sizeof(gii_pmove_event); pmrel.origin = inp->origin; pmrel.target = GII_EV_TARGET_ALL; pmrel.x = pmrel.y = pmrel.z = pmrel.wheel = 0; _giiEventBlank((gii_event *)&pmabs, sizeof(gii_pmove_event)); pmabs.type = evPtrAbsolute; pmabs.size = sizeof(gii_pmove_event); pmabs.origin = inp->origin; pmabs.target = GII_EV_TARGET_ALL; pmabs.x = pmabs.y = pmabs.z = pmabs.wheel = 0; /* Now go through the entries and convert as appropriate. */ for(entry = priv->entry;entry;entry = entry->next) { DPRINT_MISC("filter-mouse: Checking entry %p.\n",entry); if ((priv->modifiers&entry->modifier_mask)!= entry->modifier_value) continue; /* Modifiers are wrong. Forget it. */ switch(entry->from) { case MAP_KEY: if (event->any.type==evKeyPress|| event->any.type==evKeyRepeat) invalue=1; /* Key press */ else if (event->any.type==evKeyRelease) invalue=0; /* Key release*/ else continue; /* Something else - forget it. */ /* Continue, if the button/label/symbol doesn't match */ if (entry->fromdata.key.button!=GIIK_NIL&& entry->fromdata.key.button!=event->key.button) continue; if (entry->fromdata.key.label!=GIIK_NIL&& entry->fromdata.key.label!=event->key.label) continue; if (entry->fromdata.key.symbol!=GIIK_NIL&& entry->fromdata.key.symbol!=event->key.sym) continue; break; case MAP_REL: if (event->any.type==evPtrRelative) invalue=getaxis(&event->pmove,entry->fromdata.axis); else continue; break; case MAP_ABS: if (event->any.type==evPtrAbsolute) invalue=getaxis(&event->pmove,entry->fromdata.axis); else continue; break; case MAP_BUTTON: if (event->any.type==evPtrButtonPress && event->pbutton.button==entry->fromdata.button) invalue=1; else if (event->any.type==evPtrButtonRelease && event->pbutton.button==entry->fromdata.button) invalue=0; else continue; break; default:continue; /* Something is wrong */ } switch(entry->to) { case MAP_REL: setaxis(&pmrel, entry->todata.trans.axis, gettrans(&entry->todata.trans, (double)invalue)); ret=1;has|=HASREL; break; case MAP_ABS: setaxis(&pmabs, entry->todata.trans.axis, gettrans(&entry->todata.trans, (double)invalue)); ret = 1; has |= HASABS; break; case MAP_BUTTON: fmouse_send_pbutton(inp, invalue ? evPtrButtonPress : evPtrButtonRelease, entry->todata.button); ret = 1; break; default: continue; /* Something is WRONG here. */ } } DPRINT_MISC("filter-mouse: Checking entry %p.\n",entry); if (has&HASABS) { _giiEvQueueAdd(inp, (gii_event *) &pmabs); } if (has&HASREL) { _giiEvQueueAdd(inp, (gii_event *) &pmrel); } if (ret) DPRINT_MISC("filter-mouse: Eating event.\n"); return ret; }
static int fmouse_doload(const char *filename,fmouse_priv *priv) { FILE *infile; char buffer[2048],*parsepoint,*pp2; const char *expect = "nothing"; int line=0; mapping_entry entry; mapping_entry **ptr; ptr=&priv->entry; while(*ptr) ptr=&((*ptr)->next); DPRINT_MISC("filter-keymap opening config \"%s\" called\n", filename ? filename : "(nil)"); if ( NULL==(infile=fopen(filename,"r")) ) { return GGI_ENOFILE; } while(fgets(buffer,2048,infile)) { line++; /* DPRINT_MISC("filter-mouse should parse %s\n",buffer); - Shouldn't be needed anymore. */ entry.next=NULL; parsepoint=pp2=buffer; switch(entry.from=checkkeyword(parsepoint=pp2,&pp2,maptypelist,MAP_TO)) { case MAP_KEY: entry.modifier_mask=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="modmask";goto error;} entry.modifier_value=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="modval";goto error;} entry.fromdata.key.button=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="key-button";goto error;} entry.fromdata.key.label=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="key-label";goto error;} entry.fromdata.key.symbol=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="key-symbol";goto error;} break; case MAP_REL: case MAP_ABS: entry.modifier_mask=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="modmask";goto error;} entry.modifier_value=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="modval";goto error;} entry.fromdata.axis=checkkeyword(parsepoint=pp2,&pp2,axislist,AX_END); if (pp2==parsepoint) {expect="axis";goto error;} break; case MAP_BUTTON: entry.modifier_mask=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="modmask";goto error;} entry.modifier_value=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="modval";goto error;} entry.fromdata.button=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="butnum";goto error;} break; default: continue; /* silently ignore all unparseables */ } if (MAP_TO!=checkkeyword(parsepoint=pp2,&pp2,maptypelist,MAP_END)) { expect="TO"; error: DPRINT_MISC("filter-mouse Parse error at %d:%s (expecting %s)\n",line,parsepoint,expect); continue; } switch(entry.to=checkkeyword(parsepoint=pp2,&pp2,maptypelist,MAP_TO)) { case MAP_KEY: expect="no KEY output allowed"; goto error; /* Maybe we should add that for mouse->key ? */ case MAP_REL: case MAP_ABS: entry.todata.trans.axis=checkkeyword(parsepoint=pp2,&pp2,axislist,AX_END); if (pp2==parsepoint) {expect="axis";goto error;} entry.todata.trans.factor=strtod(parsepoint=pp2, &pp2); if (pp2==parsepoint) entry.todata.trans.factor=1.0; /* O.k. - the rest will fail as well. So all defaults. */ entry.todata.trans.treshold=strtod(parsepoint=pp2, &pp2); if (pp2==parsepoint) entry.todata.trans.treshold=9999.0; entry.todata.trans.higher=strtod(parsepoint=pp2, &pp2); if (pp2==parsepoint) entry.todata.trans.higher=entry.todata.trans.factor; break; case MAP_BUTTON: entry.todata.button=strtol(parsepoint=pp2, &pp2, 0); if (pp2==parsepoint) {expect="button";goto error;} break; default: goto error; } *ptr=malloc(sizeof(mapping_entry)); if (*ptr) { memcpy(*ptr,&entry,sizeof(mapping_entry)); ptr=&((*ptr)->next); } else { fclose(infile); return GGI_ENOMEM; } } fclose(infile); return 0; }
static int GGIopen(struct ggi_visual *vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32_t *dlret) { ggi_memory_priv *priv; gg_option options[NUM_OPTS]; int err = 0; DPRINT_MISC("GGIopen: coming up.\n"); memcpy(options, optlist, sizeof(options)); LIBGGI_GC(vis) = malloc(sizeof(ggi_gc)); if (!LIBGGI_GC(vis)) return GGI_ENOMEM; /* Allocate descriptor for screen memory */ priv = calloc(1, sizeof(ggi_memory_priv)); if (!priv) { err = GGI_ENOMEM; goto err0; } LIBGGI_PRIVATE(vis) = priv; priv->inp = NULL; priv->memtype = MT_MALLOC; /* Default to mallocing. */ priv->inputbuffer = NULL; /* Default to no input */ if (args) { args = ggParseOptions(args, options, NUM_OPTS); if (args == NULL) { fprintf(stderr, "display-memory: error in " "arguments.\n"); } } if (_ggi_physz_parse_option(options[OPT_PHYSZ].result, &(priv->physzflags), &(priv->physz))) { err = GGI_EARGINVAL; goto err1; } if (args && *args) { /* We have parameters. Analyze them. */ DPRINT("has args: \"%s\"\n", args); #ifdef _GG_HAVE_SHM if (strncmp(args, "shmid:", 6) == 0) { sscanf(args + 6, "%i", &(priv->shmid)); DPRINT("has shmid-arg: %d.\n", priv->shmid); priv->memptr = shmat(priv->shmid, NULL, 0); DPRINT("shmat at %p.\n", priv->memptr); if (priv->memptr != (void *)-1) { priv->memtype = MT_SHMID; if (options[OPT_INPUT].result[0]) { priv->inputbuffer = priv->memptr; priv->memptr = (char *)priv->memptr + INPBUFSIZE; DPRINT("moved mem to %p for input-buffer.\n", priv->memptr); } } } else if (strncmp(args, "keyfile:", 8) == 0) { unsigned int size; char id; char filename[1024]; sscanf(args + 8, "%u:%c:%s", &size, &id, filename); DPRINT("has keyfile-arg:%d:%c:%s.\n", size, id, filename); priv->shmid = shmget(ftok(filename,id), size, IPC_CREAT|0666); DPRINT("has shmid:%d.\n", priv->shmid); priv->memptr = shmat(priv->shmid,NULL,0); DPRINT("shmat at %p.\n", priv->memptr); if (priv->memptr != (void *)-1) { priv->memtype = MT_SHMID; if (options[OPT_INPUT].result[0]) { priv->inputbuffer = priv->memptr; priv->memptr = (char *)priv->memptr + INPBUFSIZE; DPRINT("moved mem to %p for input-buffer.\n", priv->memptr); } } } else #endif /* _GG_HAVE_SHM */ if (strncmp(args, "pointer", 7) == 0) { priv->memptr = argptr; if (priv->memptr) { priv->memtype = MT_EXTERN; } } } /* Explicit pixelformat. */ if (options[OPT_PIXFMT].result[0]) { _ggi_parse_pixfmtstr(options[OPT_PIXFMT].result, '\0', NULL, strlen(options[OPT_PIXFMT].result)+1, &priv->r_mask, &priv->g_mask, &priv->b_mask, &priv->a_mask, &priv->pixfmt_flags); } /* Explicit layout for preallocated buffers with nontrivial layouts. */ if (options[OPT_LAYOUT].result[0] != 'n') { char *idx; priv->fstride = strtoul(options[OPT_LAYOUT].result, &idx, 10); if (strncmp(idx, "plb", 3) == 0) { priv->layout = blPixelLinearBuffer; idx += 3; priv->buffer.plb.stride = strtoul(idx, NULL, 10); } else if (strncmp(idx, "plan", 4) == 0) { priv->layout = blPixelPlanarBuffer; idx += 4; priv->buffer.plan.next_plane = strtoul(idx, &idx, 10); if (*idx != ',') { priv->buffer.plan.next_line = 0; } else { idx++; priv->buffer.plan.next_line = strtoul(idx, &idx, 10); } } else { if (*idx != '\0') fprintf(stderr, "bad layout params\n"); priv->layout = blPixelLinearBuffer; priv->buffer.plb.stride = 0; } } /* Do not blank the framebuffer on SetMode. * (Preserves data in prealloced memory area.) */ priv->noblank = (options[OPT_NOBLANK].result[0] != 'n'); vis->opdisplay->flush = GGI_memory_flush; vis->opdisplay->getmode = GGI_memory_getmode; vis->opdisplay->setmode = GGI_memory_setmode; vis->opdisplay->getapi = GGI_memory_getapi; vis->opdisplay->checkmode = GGI_memory_checkmode; vis->opdisplay->setflags = GGI_memory_setflags; if (priv->inputbuffer) { struct gg_api *gii; #if 0 priv->inputbuffer->visx = priv->inputbuffer->visy = priv->inputbuffer->virtx = priv->inputbuffer->virty = priv->inputbuffer->frames = priv->inputbuffer->visframe = 0; #endif DPRINT_MISC("Adding gii to shmem-memtarget\n"); gii = ggGetAPIByName("gii"); if (gii != NULL && STEM_HAS_API(vis->instance.stem, gii)) { char inputstr[1024]; snprintf(inputstr, sizeof(inputstr), "-size=%i:-pointer", INPBUFSIZE); DPRINT("\"input-memory\" inputstr \"%s\" at %p\n", inputstr, priv->inputbuffer->buffer); priv->inp = ggPlugModule(gii, vis->instance.stem, "input-memory", inputstr, priv->inputbuffer->buffer); DPRINT("ggPlugModule for input-memory returned %p\n", priv->inp); if (priv->inp == NULL) { fprintf(stderr, "display-memory: unable to open input-memory\n"); err = GGI_ENODEVICE; goto err1; } } } *dlret = GGI_DL_OPDISPLAY; return 0; err1: free(priv); err0: free(LIBGGI_GC(vis)); *dlret = GGI_DL_OPDISPLAY; return err; }
static int GGIopen(ggi_visual *vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32_t *dlret) { ggi_fbdev_priv *fbdevpriv = FBDEV_PRIV(vis); struct m2164w_priv *priv; unsigned long usedmemend; size_t fontlen; int pixbytes; int fd = LIBGGI_FD(vis); int i; if (GT_SIZE(LIBGGI_GT(vis)) % 8 != 0 || GT_SIZE(LIBGGI_GT(vis)) > 32 || GT_SIZE(LIBGGI_GT(vis)) < 8) { /* Unsupported mode */ return GGI_ENOFUNC; } pixbytes = GT_ByPP(LIBGGI_GT(vis)); priv = malloc(sizeof(struct m2164w_priv)); if (priv == NULL) { return GGI_ENOMEM; } fbdevpriv->mmioaddr = mmap(NULL, fbdevpriv->orig_fix.mmio_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (signed)fbdevpriv->orig_fix.smem_len); if (fbdevpriv->mmioaddr == MAP_FAILED) { /* Can't mmap() MMIO region - bail out */ DPRINT_LIBS("mga-2164w: Unable to map MMIO region: %s\n" " fd: %d, len: %ld, offset: %ld\n", strerror(errno), fd, fbdevpriv->orig_fix.mmio_len, fbdevpriv->orig_fix.smem_len); fbdevpriv->mmioaddr = NULL; free(priv); return GGI_ENODEVICE; } DPRINT_MISC("mga-2164w: Mapped MMIO region at %p\n", fbdevpriv->mmioaddr); /* Set up DirectBuffers */ for (i=0; i < LIBGGI_MODE(vis)->frames; i++) { ggi_directbuffer *buf = LIBGGI_APPBUFS(vis)[i]; ggi_resource *res; res = malloc(sizeof(ggi_resource)); if (res == NULL) { do_cleanup(vis); return GGI_ENOMEM; } buf->resource = res; buf->resource->acquire = m2164w_acquire; buf->resource->release = m2164w_release; buf->resource->self = buf; buf->resource->priv = vis; buf->resource->count = 0; buf->resource->curactype = 0; } priv->drawboxcmd = BOP_COPY | SHFTZERO | SGNZERO | ARZERO | SOLID | OP_TRAP; if (pixbytes != 3) { switch (fbdevpriv->orig_fix.accel) { case FB_ACCEL_MATROX_MGA2064W: case FB_ACCEL_MATROX_MGA1064SG: case FB_ACCEL_MATROX_MGA2164W: case FB_ACCEL_MATROX_MGA2164W_AGP: /* Use block mode */ priv->drawboxcmd |= ATYPE_BLK; break; default: /* For now - assume SDRAM for other cards */ break; } } priv->dwgctl = 0; priv->oldfgcol = LIBGGI_GC(vis)->fg_color - 1; priv->oldbgcol = LIBGGI_GC(vis)->bg_color - 1; priv->oldtl.x = -1; priv->oldtl.y = -1; priv->oldbr.x = -1; priv->oldbr.y = -1; priv->oldyadd = -1; priv->curopmode = priv->origopmode = mga_in16(fbdevpriv->mmioaddr, OPMODE); /* Use the 7k Pseudo-DMA window */ priv->dmaaddr = (void*)fbdevpriv->mmioaddr; priv->dma_len = 0x1c00; vis->needidleaccel = 1; fbdevpriv->idleaccel = m2164w_idleaccel; /* Accelerate fonts if possible */ priv->font = (uint8_t *)(font); usedmemend = LIBGGI_MODE(vis)->frames * fbdevpriv->fix.line_length * LIBGGI_VIRTY(vis); fontlen = 256*8; priv->fontoffset = fbdevpriv->orig_fix.smem_len - fontlen; priv->fontoffset &= ~127; /* Align */ DPRINT_MISC("mga-2164w: usedmemend: %ld, fontoffset: %ld\n", usedmemend, priv->fontoffset); if (usedmemend <= priv->fontoffset) { memcpy((uint8_t*)fbdevpriv->fb_ptr + priv->fontoffset, font, fontlen); priv->fontoffset *= 8; /* In bits */ priv->charadd = FWIDTH*FHEIGHT; vis->opdraw->putc = GGI_m2164w_fastputc; vis->opdraw->puts = GGI_m2164w_fastputs; DPRINT_MISC("mga-2164w: Using fast chars\n"); } else { priv->fontoffset = 0; vis->opdraw->putc = GGI_m2164w_putc; vis->opdraw->puts = GGI_m2164w_puts; DPRINT_MISC("mga-2164w: Using slow chars\n"); } /* Save previous function pointers */ priv->crossblit = vis->opdraw->crossblit; /* Initialize function pointers */ vis->opdraw->getcharsize= GGI_m2164w_getcharsize; vis->opdraw->drawhline = GGI_m2164w_drawhline; vis->opdraw->drawvline = GGI_m2164w_drawvline; vis->opdraw->drawline = GGI_m2164w_drawline; vis->opdraw->drawbox = GGI_m2164w_drawbox; vis->opdraw->copybox = GGI_m2164w_copybox; vis->opdraw->fillscreen = GGI_m2164w_fillscreen; /* The crossblit in linear-* is faster on truecolor modes! */ if (GT_SCHEME(LIBGGI_GT(vis)) == GT_PALETTE || GT_SCHEME(LIBGGI_GT(vis)) == GT_STATIC_PALETTE) { vis->opdraw->crossblit = GGI_m2164w_crossblit; } FBDEV_PRIV(vis)->accelpriv = priv; /* Register cleanup handler */ ggRegisterCleanup((ggcleanup_func *)do_cleanup, vis); *dlret = GGI_DL_OPDRAW; return 0; }
int GIIdl_xf86dga(gii_input *inp, const char *args, void *argptr) { gii_inputxf86dga_arg *xdgaarg = argptr; xdga_priv *priv; int minkey, maxkey; DPRINT_MISC("GIIdlinit(%p) called for input-dga\n", inp); /* TODO: use XOpenDisplay to get a display if one wasnt * provided? */ if (xdgaarg == NULL || xdgaarg->disp == NULL) { return GGI_EARGREQ; } if ((priv = malloc(sizeof(xdga_priv))) == NULL) { return GGI_ENOMEM; } priv->disp = xdgaarg->disp; priv->screen = xdgaarg->screen; memset(priv->key_vector,0,sizeof(priv->key_vector)); inp->priv = priv; inp->GIIsendevent = GIIsendevent; inp->GIIeventpoll = GII_xdga_eventpoll; inp->GIIclose = GII_xdga_close; if (0 == (priv->origin[XDGA_DEV_KEY] = _giiRegisterDevice(inp,&key_devinfo,NULL))) { GII_xdga_close(inp); return GGI_ENOMEM; } /* if (0 == (priv->origin[XDGA_DEV_MOUSE] = _giiRegisterDevice(inp,&mouse_devinfo,NULL))) { GII_xdga_close(inp); return GGI_ENOMEM; } */ inp->targetcan = emKey; /* | emPointer; */ inp->curreventmask = emKey; /* | emPointer;*/ inp->maxfd = ConnectionNumber(priv->disp) + 1; FD_SET(ConnectionNumber(priv->disp), &inp->fdset); /* mouse_devinfo.num_buttons = XGetPointerMapping(priv->disp, NULL, 0); */ XDisplayKeycodes(priv->disp, &minkey, &maxkey); key_devinfo.num_buttons = (maxkey - minkey) + 1; send_devinfo(inp, XDGA_DEV_KEY); /* send_devinfo(inp, XDGA_DEV_MOUSE); */ XDGAQueryExtension( priv->disp, &priv->event_base, &priv->error_base); XSync( priv->disp, True ); XDGASelectInput( priv->disp, priv->screen, KeyPressMask|KeyReleaseMask); return 0; }
static int GGIopen(ggi_visual *vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32_t *dlret) { ggi_ipc_priv *priv; gg_option options[NUM_OPTS]; struct sockaddr_un address; DPRINT_MISC("display-ipc coming up.\n"); memcpy(options, optlist, sizeof(options)); LIBGGI_GC(vis) = malloc(sizeof(ggi_gc)); if (!LIBGGI_GC(vis)) return GGI_ENOMEM; /* Allocate descriptor for screen memory */ priv = malloc(sizeof(ggi_ipc_priv)); if (!priv) { free(LIBGGI_GC(vis)); return GGI_ENOMEM; } /* if */ LIBGGI_PRIVATE(vis) = priv; priv->inputbuffer = NULL; /* Default to no input */ priv->inputoffset = 0; /* Setup offset. */ if (!args) { DPRINT("display-ipc: required arguments missing\n"); return GGI_EARGREQ; } /* if */ args = ggParseOptions(args, options, NUM_OPTS); if (args == NULL) { DPRINT("display-ipc: error in arguments.\n"); return GGI_EARGREQ; } /* if */ if (_ggi_physz_parse_option(options[OPT_PHYSZ].result, &(priv->physzflags), &(priv->physz))) { free(priv); free(LIBGGI_GC(vis)); return GGI_EARGINVAL; } /* if */ if (!options[OPT_SOCKET].result[0] && !options[OPT_SEMID].result[0] && !options[OPT_SHMID].result[0]) { DPRINT("display-ipc: required arguments missing\n"); return GGI_EARGREQ; } /* if */ if (!(sscanf(options[OPT_SOCKET].result,"%s", address.sun_path) && sscanf(options[OPT_SEMID].result,"%d", &(priv->semid)) && sscanf(options[OPT_SHMID].result,"%d", &(priv->shmid)))) { DPRINT("display-ipc: argument format error\n"); return GGI_EARGREQ; } /* if */ DPRINT("display-ipc parsed args: socket: %s semid: %d shmid: %d\n", address.sun_path, priv->semid, priv->shmid); address.sun_family = AF_UNIX; if ((priv->sockfd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1 || connect(priv->sockfd, (const struct sockaddr *)(&address), sizeof(struct sockaddr_un)) == -1 || (priv->memptr = (char *)shmat(priv->shmid, 0, 0)) == (char *)-1) { DPRINT("display-ipc initialization failed : %s\n", strerror(errno)); return GGI_ENODEVICE; } /* if */ if (options[OPT_INPUT].result[0]) { priv->inputbuffer=priv->memptr; priv->memptr=(char *)priv->memptr+INPBUFSIZE; DPRINT("display-ipc: moved mem to %p for input-buffer.\n", priv->memptr); } /* if */ vis->opdisplay->flush = GGI_ipc_flush; vis->opdisplay->getmode = GGI_ipc_getmode; vis->opdisplay->setmode = GGI_ipc_setmode; vis->opdisplay->getapi = GGI_ipc_getapi; vis->opdisplay->checkmode = GGI_ipc_checkmode; vis->opdisplay->setflags = GGI_ipc_setflags; if (priv->inputbuffer) { gii_input *inp; priv->inputbuffer->visx = priv->inputbuffer->visy = priv->inputbuffer->virtx = priv->inputbuffer->virty = priv->inputbuffer->frames = priv->inputbuffer->visframe = 0; DPRINT_MISC("Adding gii to shmem-memtarget\n"); /* First allocate a new gii_input descriptor. */ if (NULL==(inp=_giiInputAlloc())) { DPRINT_MISC("giiInputAlloc failure.\n"); goto out; } /* if */ DPRINT_MISC("gii inp=%p\n",inp); /* Now fill in the blanks. */ inp->priv = priv; /* We need that in poll() */ priv->inputbuffer->writeoffset = 0; /* Not too good, but ... */ inp->targetcan= emAll; inp->GIIseteventmask(inp,inp->targetcan); inp->maxfd = 0; /* This is polled. */ inp->flags |= GII_FLAGS_HASPOLLED; inp->GIIeventpoll = GII_ipc_poll; inp->GIIsendevent = GII_ipc_send; /* Now join the new event source in. */ vis->input=giiJoinInputs(vis->input,inp); out: while(0){}; } /* if */ *dlret = GGI_DL_OPDISPLAY; return 0; } /* GGIopen */
static inline gii_event_mask GII_keyboard_handle_data(gii_input *inp, int code) { linkbd_priv *priv = LINKBD_PRIV(inp); gii_event ev; struct kbentry entry; int symval, labelval; gii_event_mask mask; _giiEventBlank(&ev, sizeof(gii_key_event)); if (code & 0x80) { code &= 0x7f; ev.key.type = evKeyRelease; priv->keydown_buf[code] = 0; } else if (priv->keydown_buf[code] == 0) { ev.key.type = evKeyPress; priv->keydown_buf[code] = 1; } else { ev.key.type = evKeyRepeat; } ev.key.button = code; /* First update modifiers here so linkey.c can use the value */ ev.key.modifiers = priv->modifiers; if (ev.key.type == evKeyRelease && GII_KTYP(priv->keydown_sym[code]) != GII_KT_MOD && priv->keydown_sym[code] != GIIK_VOID) { /* We can use the cached values */ ev.key.sym = priv->keydown_sym[code]; ev.key.label = priv->keydown_label[code]; } else { /* Temporarily switch back to the old mode because unicodes aren't available through table lookup in MEDIUMRAW */ if (ioctl(priv->fd, KDSKBMODE, priv->old_mode) < 0) { DPRINT_MISC("Linux-kbd: ioctl(KDSKBMODE) failed.\n"); return 0; } /* Look up the keysym without modifiers, which will give us * the key label (more or less). */ entry.kb_table = 0; entry.kb_index = code; if (ioctl(priv->fd, KDGKBENT, &entry) < 0) { DPRINT_MISC("Linux-kbd: ioctl(KDGKBENT) failed.\n"); return 0; } labelval = entry.kb_value; if (priv->old_mode == K_UNICODE) labelval &= 0x0fff; /* Now look up the full keysym in the kernel's table */ /* calculate kernel-like shift value */ entry.kb_table = ((priv->modifiers & GII_MOD_SHIFT) ? (1<<KG_SHIFT) : 0) | ((priv->modifiers & GII_MOD_CTRL) ? (1<<KG_CTRL) : 0) | ((priv->modifiers & GII_MOD_ALT) ? (1<<KG_ALT) : 0) | ((priv->modifiers & GII_MOD_ALTGR) ? (1<<KG_ALTGR) : 0) | ((priv->modifiers & GII_MOD_META) ? (1<<KG_ALT) : 0) | ((priv->modifiers & GII_MOD_CAPS) ? (1<<KG_CAPSSHIFT) : 0); entry.kb_index = code; if (ioctl(priv->fd, KDGKBENT, &entry) < 0) { DPRINT_MISC("Linux-kbd: ioctl(KDGKBENT) failed.\n"); return 0; } /* Switch back to MEDIUMRAW */ if (ioctl(priv->fd, KDSKBMODE, K_MEDIUMRAW) < 0) { DPRINT_MISC("Linux-kbd: ioctl(KDSKBMODE) failed.\n"); return 0; } switch (entry.kb_value) { case K_HOLE: DPRINT_EVENTS("Linux-kbd: NOSUCHKEY\n"); break; case K_NOSUCHMAP: DPRINT_EVENTS("Linux-kbd: NOSUCHMAP\n"); entry.kb_value = K_HOLE; break; } symval = entry.kb_value; if (priv->old_mode == K_UNICODE) symval &= 0x0fff; _gii_linkey_trans(code, labelval, symval, &ev.key); if (ev.key.type == evKeyPress) { if (priv->accent) { if (GII_KTYP(ev.key.sym) != GII_KT_MOD) { handle_accent(priv, symval, &ev); } } else if (KTYP(symval) == KT_DEAD) { priv->accent = GII_KVAL(ev.key.sym); } } if (GII_KTYP(ev.key.sym) == GII_KT_DEAD) { ev.key.sym = GIIK_VOID; } } /* Keep track of modifier state */ if (GII_KTYP(ev.key.label) == GII_KT_MOD) { /* Modifers don't repeat */ if (ev.key.type == evKeyRepeat) return 0; handle_modifier(priv, &ev); } /* Now update modifiers again to get the value _after_ the current event */ ev.key.modifiers = priv->modifiers; if (ev.any.type == evKeyPress) { priv->keydown_sym[code] = ev.key.sym; priv->keydown_label[code] = ev.key.label; } DPRINT_EVENTS("KEY-%s button=0x%02x modifiers=0x%02x " "sym=0x%04x label=0x%04x\n", (ev.key.type == evKeyRelease) ? "UP" : ((ev.key.type == evKeyPress) ? "DN" : "RP"), ev.key.button, ev.key.modifiers, ev.key.sym, ev.key.label); if (priv->call_vtswitch) { if (ev.key.label == GIIK_CtrlL && priv->needctrl2switch) { if (ev.key.type == evKeyRelease) { priv->ctrlstate = 0; } else if (ev.key.type == evKeyPress) { priv->ctrlstate = 1; } } /* Check for console switch. Unfortunately, the kernel doesn't * recognize KT_CONS when the keyboard is in RAW or MEDIUMRAW * mode, so _we_ have to. Sigh. */ if ((ev.key.type == evKeyPress) && (KTYP(entry.kb_value) == KT_CONS) && priv->ctrlstate) { int rc; int new_cons = 1+KVAL(entry.kb_value); /* Clear the keydown buffer, since we'll never know what keys the user pressed (or released) while they were away. */ DPRINT_MISC("Flushing all keys.\n"); rc = GII_keyboard_flush_keys(inp); DPRINT_MISC("Switching to console %d.\n", new_cons); if (ioctl(priv->fd, VT_ACTIVATE, new_cons) < 0) { perror("ioctl(VT_ACTIVATE)"); } return rc; } } mask = (1 << ev.any.type); if (! (inp->curreventmask & mask)) return 0; /* finally queue the key event */ ev.any.size = sizeof(gii_key_event); ev.any.origin = inp->origin; _giiEvQueueAdd(inp, &ev); return (1 << ev.any.type); }
static inline int GII_keyboard_init(gii_input *inp, const char *filename) { int fd; struct termios tio; linkbd_priv *priv; void (*oldinhandler)(int); void (*oldouthandler)(int); DPRINT_MISC("Linux-kbd: opening tty\n"); /* open the tty */ fd = open(filename, O_RDWR); if (fd < 0) { perror("Linux-kbd: Couldn't open TTY"); return GGI_ENODEVICE; } /* allocate keyboard hook */ if ((priv = malloc(sizeof(linkbd_priv))) == NULL) { close(fd); return GGI_ENOMEM; } DPRINT_MISC("Linux-kbd: calling tcgetattr()\n"); /* put tty into "straight through" mode. */ if (tcgetattr(fd, &priv->old_termios) < 0) { perror("Linux-kbd: tcgetattr failed"); } tio = priv->old_termios; tio.c_lflag &= ~(ICANON | ECHO | ISIG); tio.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); tio.c_iflag |= IGNBRK; tio.c_cc[VMIN] = 0; tio.c_cc[VTIME] = 0; DPRINT_MISC("Linux-kbd: calling tcsetattr()\n"); got_stopped = 0; oldinhandler = signal(SIGTTIN, sighandler); oldouthandler = signal(SIGTTOU, sighandler); if (tcsetattr(fd, TCSANOW, &tio) < 0) { perror("Linux-kbd: tcsetattr failed"); } signal(SIGTTIN, oldinhandler); signal(SIGTTOU, oldouthandler); if (got_stopped) { /* We're a background process on this tty... */ fprintf(stderr, "Linux-kbd: can't be run in the background!\n"); free(priv); close(fd); return GGI_EUNKNOWN; } /* Put the keyboard into MEDIUMRAW mode. Despite the name, this * is really "mostly raw", with the kernel just folding long * scancode sequences (e.g. E0 XX) onto single keycodes. */ DPRINT_MISC("Linux-kbd: going to MEDIUMRAW mode\n"); if (ioctl(fd, KDGKBMODE, &priv->old_mode) < 0) { perror("Linux-kbd: couldn't get mode"); priv->old_mode = K_XLATE; } if (ioctl(fd, KDSKBMODE, K_MEDIUMRAW) < 0) { perror("Linux-kbd: couldn't set raw mode"); tcsetattr(fd, TCSANOW, &(priv->old_termios)); close(fd); free(priv); return GGI_ENODEVICE; } priv->fd = fd; priv->eof = 0; priv->call_vtswitch = 1; memset(priv->keydown_buf, 0, sizeof(priv->keydown_buf)); if (ioctl(fd, KDGKBLED, &priv->old_kbled) != 0) { perror("Linux-kbd: unable to get keylock status"); priv->old_kbled = 0x7f; priv->lockedmod = 0; } else { priv->lockedmod = LED2MASK(priv->old_kbled); } /* Make sure LEDs match the flags */ ioctl(priv->fd, KDSETLED, 0x80); priv->normalmod = 0; priv->modifiers = priv->lockedmod | priv->normalmod; priv->lockedmod2 = priv->lockedmod; if (ioctl(fd, KDGKBDIACR, &priv->accent_table) != 0) { priv->accent_table.kb_cnt = 0; } else { unsigned int i; for (i = 0; i < priv->accent_table.kb_cnt; i++) { switch (priv->accent_table.kbdiacr[i].diacr) { case '"': priv->accent_table.kbdiacr[i].diacr = GIIUC_Diaeresis; break; case '\'': priv->accent_table.kbdiacr[i].diacr = GIIUC_Acute; break; } } } priv->accent = 0; if (getenv("GII_CTRLALT_VTSWITCH")) { priv->needctrl2switch = 1; priv->ctrlstate = 0; } else { priv->needctrl2switch = 0; priv->ctrlstate = 1; } inp->priv = priv; DPRINT_MISC("Linux-kbd: init OK.\n"); return 0; }
static int GGIopen(ggi_visual * vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32_t * dlret) { int err = GGI_OK; directx_priv *priv; GGIGII ggigii; gg_option options[NUM_OPTS]; DPRINT("DirectX-target starting\n"); memcpy(options, optlist, sizeof(options)); priv = malloc(sizeof(directx_priv)); if (priv == NULL) { err = GGI_ENOMEM; goto err0; } if ((LIBGGI_GC(vis) = malloc(sizeof(ggi_gc))) == NULL) { err = GGI_ENOMEM; goto err1; } memset(priv, 0, sizeof(directx_priv)); LIBGGI_PRIVATE(vis) = priv; priv->cs = GGI_directx_LockCreate(); if (priv->cs == NULL) { err = GGI_ENOMEM; goto err2; } priv->spincs = GGI_directx_LockCreate(); if (priv->spincs == NULL) { err = GGI_ENOMEM; goto err3; } priv->redraw = 1; priv->setpalette = 1; priv->sizingcs = GGI_directx_LockCreate(); if (priv->sizingcs == NULL) { err = GGI_ENOMEM; goto err4; } priv->xmin = 0; priv->ymin = 0; priv->xmax = 0; priv->ymax = 0; priv->xstep = -1; priv->ystep = -1; if (args) { args = ggParseOptions(args, options, NUM_OPTS); if (args == NULL) { fprintf(stderr, "display-directx: error in " "arguments.\n"); } } if (_ggi_physz_parse_option(options[OPT_PHYSZ].result, &(priv->physzflags), &(priv->physz))) { err = GGI_EARGINVAL; goto err5; } if (options[OPT_KEEPCURSOR].result[0] == 'n') { priv->cursortype = (options[OPT_NOCURSOR].result[0] == 'n') ? 1 : 0; } else { priv->cursortype = 2; } if (options[OPT_INWIN].result[0] != 'n') { if (strcmp(options[OPT_INWIN].result, "root")) { priv->hParent = (HANDLE) strtoul(options[OPT_INWIN].result, NULL, 0); if (!IsWindow(priv->hParent)) { fprintf(stderr, "0x%08x " "is not a valid window handle.\n", (unsigned) priv->hParent); priv->hParent = NULL; } } else priv->hParent = GetDesktopWindow(); } if (options[OPT_FULLSCREEN].result[0] == 'n') { priv->fullscreen = 0; } else { priv->fullscreen = 1; } if (!DDInit(vis)) { err = GGI_ENODEVICE; goto err3; } ggigii.hWnd = priv->hWnd; ggigii.hInstance = priv->hInstance; if (tolower((uint8_t) options[OPT_NOINPUT].result[0]) == 'n' && /* FIXME: dxinput doesn't work with -inwin yet; the following condition disables the default input target if -inwin has been specified */ (!priv->hParent || getenv("GGI_INPUT") || getenv("GGI_INPUT_directx"))) { gii_input *inp; inp = giiOpen("directx", &ggigii, NULL); if (inp == NULL) { DPRINT_MISC("Unable to open directx inputlib\n"); GGIclose(vis, dlh); err = GGI_ENODEVICE; goto err3; } priv->inp = inp; /* Now join the new event source in. */ vis->input = giiJoinInputs(vis->input, inp); } else { priv->inp = NULL; } vis->opdisplay->setmode = GGI_directx_setmode; vis->opdisplay->getmode = GGI_directx_getmode; vis->opdisplay->setflags = GGI_directx_setflags; vis->opdisplay->checkmode = GGI_directx_checkmode; vis->opdisplay->flush = GGI_directx_flush; vis->opdisplay->getapi = GGI_directx_getapi; *dlret = GGI_DL_OPDISPLAY | GGI_DL_OPDRAW; return GGI_OK; err5: GGI_directx_LockDestroy(priv->cs); err4: GGI_directx_LockDestroy(priv->spincs); err3: GGI_directx_LockDestroy(priv->sizingcs); err2: free(LIBGGI_GC(vis)); err1: free(priv); err0: return err; }
int GIIdl_quartz(gii_input *inp, const char *args, void *argptr) { int rc = 0; gii_inputquartz_arg *quartzarg = argptr; quartz_priv *priv; DPRINT_MISC("quartz input starting. (args=%s,argptr=%p)\n", args, argptr); priv = calloc(1, sizeof(quartz_priv)); if (priv == NULL) { rc = GGI_ENOMEM; goto err0; } /* Attention: quartzarg->theWindow is invalid at this point. * It becomes valid once a mode has been set up. */ priv->theWindow = quartzarg->theWindow; #if 0 LIB_ASSERT(priv->theWindow != NULL, "quartzarg->theWindow is NULL\n"); #endif if (0 == (priv->origin[QZ_DEV_KEY] = _giiRegisterDevice(inp, &key_devinfo, NULL))) { rc = GGI_ENODEVICE; goto err1; } /* if */ if (0 == (priv->origin[QZ_DEV_MOUSE] = _giiRegisterDevice(inp, &mouse_devinfo, NULL))) { rc = GGI_ENODEVICE; goto err1; } /* if */ if (GGI_OK != QuartzInit(priv)) { rc = GGI_ENODEVICE; goto err2; } inp->GIIsendevent = GII_quartz_send_event; inp->GIIeventpoll = GII_quartz_eventpoll; #if 0 inp->GIIseteventmask = GII_quartz_seteventmask; inp->GIIgeteventmask = GII_quartz_geteventmaks; #endif inp->GIIclose = GII_quartz_close; inp->targetcan = emKey | emPointer; inp->curreventmask = emKey | emPointer; inp->maxfd = 0; /* We poll from an event queue - ouch! */ inp->flags |= GII_FLAGS_HASPOLLED; inp->priv = priv; inp->GIIseteventmask(inp, inp->targetcan); if (GGI_OK != QuartzFinishLaunch(inp)) { rc = GGI_ENODEVICE; goto err2; } send_devinfo(inp, QZ_DEV_KEY); send_devinfo(inp, QZ_DEV_MOUSE); DPRINT_MISC("quartz input fully up\n"); return GGI_OK; err2: err1: GII_quartz_close(inp); err0: return rc; } /* GIIdlinit */
static int translate_to_ggi(gii_input *inp, gii_event *ev, TeleEvent *tv) { ggi_tele_priv *priv = (ggi_tele_priv *) inp->priv; if ((tv->type & TELE_EVENT_TYPE_MASK) != TELE_INP_BASE) { DPRINT_MISC("display-tele: unrecognised event from " "server (0x%08x).\n", tv->type); return GGI_EEVUNKNOWN; } _giiEventBlank(ev, sizeof(gii_event)); ev->any.time.tv_sec = tv->time.sec; ev->any.time.tv_usec = tv->time.nsec / 1000; ev->any.origin = tv->device; switch (tv->type) { case TELE_INP_KEY: case TELE_INP_KEYUP: { TeleInpKeyData *d = (void *) tv->data; ev->any.size = sizeof(gii_key_event); ev->any.type = (tv->type == TELE_INP_KEY) ? evKeyPress : evKeyRelease; ev->key.modifiers = d->modifiers; ev->key.sym = d->key; ev->key.label = d->label; ev->key.button = d->button; return 0; } case TELE_INP_BUTTON: case TELE_INP_BUTTONUP: { TeleInpButtonData *d = (void *) tv->data; ev->any.size = sizeof(gii_pbutton_event); ev->any.type = (tv->type == TELE_INP_BUTTON) ? evPtrButtonPress : evPtrButtonRelease; ev->pbutton.button = d->button; return 0; } case TELE_INP_MOUSE: case TELE_INP_TABLET: { TeleInpAxisData *d = (void *) tv->data; ev->any.size = sizeof(gii_pmove_event); ev->any.type = (tv->type == TELE_INP_MOUSE) ? evPtrRelative : evPtrAbsolute; ev->pmove.x = (d->count >= 1) ? d->axes[0] : 0; ev->pmove.y = (d->count >= 2) ? d->axes[1] : 0; ev->pmove.z = (d->count >= 3) ? d->axes[2] : 0; ev->pmove.wheel = (d->count >= 4) ? d->axes[3] : 0; return 0; } case TELE_INP_JOYSTICK: { TeleInpAxisData *d = (void *) tv->data; int i; if (d->count > 32) { return GGI_ENOSPACE; } ev->any.size = sizeof(gii_val_event); ev->any.type = evValAbsolute; ev->val.first = 0; ev->val.count = d->count; for (i=0; i < d->count; i++) { ev->val.value[i] = d->axes[i]; } return 0; } case TELE_INP_EXPOSE: { ev->any.size = sizeof(gii_expose_event); ev->any.type = evExpose; /* the whole screen */ ev->expose.x = 0; ev->expose.y = 0; ev->expose.w = priv->width; ev->expose.h = priv->height; return 0; } } DPRINT_MISC("display-tele: unknown input event (0x%08x).\n", tv->type); return GGI_EEVUNKNOWN; }
static int DDCreateSurface(directx_priv *priv, ggi_mode *mode) { HRESULT hr; LPDIRECTDRAWCLIPPER pClipper; DDSURFACEDESC pddsd, bddsd; int i; if (!priv->fullscreen) IDirectDraw2_SetCooperativeLevel(priv->lpddext, priv->hWnd, DDSCL_NORMAL); else { /* Only the thread that has excluse access (Cooperative level) * may restore the surfaces when they are lost. Therefore * let the helper thread get exclusive access so that it can * later do restores. */ directx_fullscreen dxfull; dxfull.priv = priv; dxfull.mode = mode; dxfull.event = CreateEvent(NULL, FALSE, FALSE, NULL); PostThreadMessage(priv->nThreadID, WM_DDFULLSCREEN, 0, (long)&dxfull); WaitForSingleObject(dxfull.event, INFINITE); CloseHandle(dxfull.event); } /* create the primary surface */ memset(&pddsd, 0, sizeof(pddsd)); pddsd.dwSize = sizeof(pddsd); pddsd.dwFlags = DDSD_CAPS; pddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if (priv->fullscreen) pddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY; hr = IDirectDraw2_CreateSurface(priv->lpddext, &pddsd, &priv->lppdds, NULL); if (hr != 0) { fprintf(stderr, "Init Primary Surface Failed RC = %lx. Exiting\n", hr); exit(-1); } IDirectDraw2_CreateClipper(priv->lpddext, 0, &pClipper, NULL); IDirectDrawClipper_SetHWnd(pClipper, 0, priv->hWnd); IDirectDrawSurface_SetClipper(priv->lppdds, pClipper); IDirectDrawClipper_Release(pClipper); pddsd.dwSize = sizeof(pddsd); IDirectDrawSurface_GetSurfaceDesc(priv->lppdds, &pddsd); DPRINT_MISC("DDraw pixel format:\n"); DPRINT_MISC(" Size %u\n", pddsd.ddpfPixelFormat.dwSize); DPRINT_MISC(" Flags %08x\n", pddsd.ddpfPixelFormat.dwFlags); DPRINT_MISC(" FourCC %08x\n", pddsd.ddpfPixelFormat.dwFourCC); DPRINT_MISC(" Count %u\n", pddsd.ddpfPixelFormat.dwRGBBitCount); DPRINT_MISC(" R-Mask(etc) %08x\n", pddsd.ddpfPixelFormat.dwRBitMask); DPRINT_MISC(" G-Mask(etc) %08x\n", pddsd.ddpfPixelFormat.dwGBitMask); DPRINT_MISC(" B-Mask(etc) %08x\n", pddsd.ddpfPixelFormat.dwBBitMask); DPRINT_MISC(" Z-Mask(etc) %08x\n", pddsd.ddpfPixelFormat.dwRGBZBitMask); /* create the back storages */ for (i = 0; i < mode->frames; ++i) { memset(&bddsd, 0, sizeof(bddsd)); bddsd.dwSize = sizeof(bddsd); bddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; bddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; bddsd.dwWidth = mode->virt.x; bddsd.dwHeight = mode->virt.y; /* set up the pixel format */ ZeroMemory(&bddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT)); bddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); bddsd.ddpfPixelFormat.dwFlags = pddsd.ddpfPixelFormat.dwFlags; bddsd.ddpfPixelFormat.dwFourCC = pddsd.ddpfPixelFormat.dwFourCC; bddsd.ddpfPixelFormat.dwRGBBitCount = pddsd.ddpfPixelFormat.dwRGBBitCount; bddsd.ddpfPixelFormat.dwRBitMask = pddsd.ddpfPixelFormat.dwRBitMask; bddsd.ddpfPixelFormat.dwGBitMask = pddsd.ddpfPixelFormat.dwGBitMask; bddsd.ddpfPixelFormat.dwBBitMask = pddsd.ddpfPixelFormat.dwBBitMask; bddsd.ddpfPixelFormat.dwRGBAlphaBitMask = pddsd.ddpfPixelFormat.dwRGBAlphaBitMask; hr = IDirectDraw2_CreateSurface(priv->lpddext, &bddsd, &priv->lpbdds[i], NULL); if (hr) { fprintf(stderr, "Init Backup Failed RC = %lx. Exiting\n", hr); exit(-1); } IDirectDrawSurface2_Lock(priv->lpbdds[i], NULL, &bddsd, DDLOCK_SURFACEMEMORYPTR, NULL); priv->lpSurfaceAdd[i] = (char *) bddsd.lpSurface; IDirectDrawSurface2_Unlock(priv->lpbdds[i], bddsd.lpSurface); } /* set private mode parameters */ priv->maxX = mode->virt.x; priv->maxY = mode->virt.y; priv->ColorDepth = pddsd.ddpfPixelFormat.dwRGBBitCount; priv->pitch = bddsd.lPitch; if (pddsd.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) { static PALETTEENTRY pal[256]; /* todo fill in pal */ hr = IDirectDraw_CreatePalette(priv->lpddext, DDPCAPS_8BIT|DDPCAPS_ALLOW256, pal, &priv->lpddp, NULL); if (hr) { fprintf(stderr, "Init Palette failed RC = %lx. Exiting\n", hr); exit(-1); } hr = IDirectDrawSurface_SetPalette(priv->lppdds, priv->lpddp); if (hr) { fprintf(stderr, "Install Palette failed RC = %lx. Exiting\n", hr); exit(-1); } } return 1; }