Beispiel #1
0
static int32_t init_kb(void)
{
    if (!ppb_input_event_interface) {
        ppb_input_event_interface =
                (PPB_InputEvent *) NaCl_GetInterface(PPB_INPUT_EVENT_INTERFACE);
    }
    ppb_keyboard_event_interface =
            (PPB_KeyboardInputEvent *) NaCl_GetInterface(
                    PPB_KEYBOARD_INPUT_EVENT_INTERFACE);

    if (!ppb_input_event_interface) {
        DEBUG_LOG("Could not acquire PPB_InputEvent interface.\n");
        return 0;
    }
    if (!ppb_keyboard_event_interface) {
        DEBUG_LOG("Could not acquire PPB_KeyboardInputEvent interface.\n");
        return 0;
    }

    inputdevice_release_all_keys ();
    reset_hotkeys ();

    return 1;
}
Beispiel #2
0
static void graphics_subinit (void)
{
    XSetWindowAttributes wattr;
    XClassHint classhint;
    XWMHints *hints;
    unsigned long valuemask;

    dgamode = screen_is_picasso ? currprefs.gfx_pfullscreen : currprefs.gfx_afullscreen;
    dgamode = dgamode && dgaavail;

    wattr.background_pixel = /*black.pixel*/0;
    wattr.backing_store = Always;
    wattr.backing_planes = bitdepth;
    wattr.border_pixmap = None;
    wattr.border_pixel = /*black.pixel*/0;
    wattr.colormap = cmap;
    valuemask = (CWEventMask | CWBackPixel | CWBorderPixel
		 | CWBackingStore | CWBackingPlanes | CWColormap);

    if (dgamode) {
	wattr.event_mask = DGA_EVENTMASK;
	wattr.override_redirect = 1;
	valuemask |= CWOverrideRedirect;
    } else
	wattr.event_mask = EVENTMASK;

    XSync (display, 0);

    delete_win = XInternAtom(display, "WM_DELETE_WINDOW", False);
    mywin = XCreateWindow (display, rootwin, 0, 0, current_width, current_height,
			   0, bitdepth, InputOutput, vis, valuemask, &wattr);
    XSetWMProtocols (display, mywin, &delete_win, 1);
    XSync (display, 0);
    XStoreName (display, mywin, PACKAGE_NAME);
    XSetIconName (display, mywin, PACKAGE_NAME);

    /* set class hint */
    classhint.res_name  = (char *)"UAE";
    classhint.res_class = (char *)"UAEScreen";
    XSetClassHint(display, mywin, &classhint);

    hints = XAllocWMHints();
    /* Set window group leader to self to become an application
     * that can be hidden by e.g. WindowMaker.
     * Would be more useful if we could find out what the
     * (optional) GTK+ window ID is :-/ */
    hints->window_group = mywin;
    hints->flags = WindowGroupHint;
    XSetWMHints(display, mywin, hints);

    XMapRaised (display, mywin);
    XSync (display, 0);
    mygc = XCreateGC (display, mywin, 0, 0);

    if (dgamode) {
#ifdef USE_DGA_EXTENSION
	enter_dga_mode ();
	/*setuid(getuid());*/
	picasso_vidinfo.rowbytes = fb_width * picasso_vidinfo.pixbytes;
#endif
    } else {
	get_image (current_width, current_height, &ami_dinfo);
	if (screen_is_picasso) {
	    get_image (current_width, current_height, &pic_dinfo);
	    picasso_vidinfo.rowbytes = pic_dinfo.ximg->bytes_per_line;
	}
    }

    picasso_vidinfo.extra_mem = 1;

    gfxvidinfo.flush_screen = x11_flush_screen;
    gfxvidinfo.lockscr      = x11_lock;
    gfxvidinfo.unlockscr    = x11_unlock;
    

    if (need_dither) {
	gfxvidinfo.maxblocklines = 0;
	gfxvidinfo.rowbytes = gfxvidinfo.pixbytes * currprefs.gfx_width_win;
	gfxvidinfo.linemem = malloc (gfxvidinfo.rowbytes);
        gfxvidinfo.flush_line  = x11_flush_line_dither;
    } else if (! dgamode) {
	gfxvidinfo.emergmem = 0;
	gfxvidinfo.linemem = 0;
	gfxvidinfo.bufmem = (uae_u8 *)ami_dinfo.image_mem;
	gfxvidinfo.rowbytes = ami_dinfo.ximg->bytes_per_line;
	if (currprefs.x11_use_low_bandwidth) {
	    write_log ("Doing low-bandwidth output.\n");
	    gfxvidinfo.maxblocklines = 0;
	    gfxvidinfo.rowbytes = ami_dinfo.ximg->bytes_per_line;
	    gfxvidinfo.linemem = malloc (gfxvidinfo.rowbytes);

	    if (shmavail && currprefs.x11_use_mitshm) {
		switch (gfxvidinfo.pixbytes) {
		    case 4  : gfxvidinfo.flush_line = x11_flush_line_lbw_32bit_mitshm; break;
		    case 2  : gfxvidinfo.flush_line = x11_flush_line_lbw_16bit_mitshm; break;
		    default : gfxvidinfo.flush_line = x11_flush_line_lbw_8bit_mitshm;  break;
		}
	    } else {
		switch (gfxvidinfo.pixbytes) {
		    case 4  : gfxvidinfo.flush_line = x11_flush_line_lbw_32bit; break;
		    case 2  : gfxvidinfo.flush_line = x11_flush_line_lbw_16bit; break;
		    default : gfxvidinfo.flush_line = x11_flush_line_lbw_8bit;	break;
		}
	    }
	} else {
	    gfxvidinfo.maxblocklines = MAXBLOCKLINES_MAX;

	    if (shmavail && currprefs.x11_use_mitshm)
		gfxvidinfo.flush_block  = x11_flush_block_mitshm;
	    else
		gfxvidinfo.flush_block  = x11_flush_block;
	}
    }

    if (visualInfo.VI_CLASS != TrueColor && ! screen_is_picasso) {
	int i;
	for (i = 0; i < 256; i++)
	    XStoreColor (display, cmap, parsed_xcolors + i);
    }

#ifdef USE_DGA_EXTENSION
    if (dgamode) {
	dga_colormap_installed = 0;
	XF86DGAInstallColormap (display, screen, cmap2);
	XF86DGAInstallColormap (display, screen, cmap);
    }
#endif

    if (! dgamode) {
	if (!currprefs.hide_cursor)
	    XDefineCursor (display, mywin, xhairCursor);
	else
	    XDefineCursor (display, mywin, blankCursor);
	cursorOn = 1;
    }

    mousehack = !dgamode;

    if (screen_is_picasso) {
	picasso_has_invalid_lines = 0;
	picasso_invalid_start = picasso_vidinfo.height + 1;
	picasso_invalid_stop = -1;
	memset (picasso_invalid_lines, 0, sizeof picasso_invalid_lines);
    } else
	reset_drawing ();

    inwindow = 0;
    inputdevice_release_all_keys ();
    reset_hotkeys ();
}
Beispiel #3
0
void handle_events (void)
{
    for (;;) {
	XEvent event;
#if 0
	if (! XCheckMaskEvent (display, eventmask, &event))
	    break;
#endif
	if (! XPending (display))
	    break;

	XNextEvent (display, &event);

	switch (event.type) {
	 case KeyPress:
	 case KeyRelease: {
	    int state = (event.type == KeyPress);

	    if (currprefs.map_raw_keys) {
		unsigned int keycode = ((XKeyEvent *)&event)->keycode;
		unsigned int ievent;

		if ((ievent = match_hotkey_sequence (keycode, state)))
		    handle_hotkey_event (ievent, state);
		else
		    inputdevice_translatekeycode (0, keycode, state);
	    } else {
		KeySym keysym;
		int index = 0;
		int ievent, amiga_keycode;
		do {
		    keysym = XLookupKeysym ((XKeyEvent *)&event, index);
		    if ((ievent = match_hotkey_sequence (keysym, state))) {
			handle_hotkey_event (ievent, state);
			break;
		    } else
			if ((amiga_keycode = xkeysym2amiga (keysym)) >= 0) {
			    inputdevice_do_keyboard (amiga_keycode, state);
			    break;
			}
		    index++;
		} while (keysym != NoSymbol);
	    }
	    break;
	 }
	 case ButtonPress:
	 case ButtonRelease: {
	    int state = (event.type == ButtonPress);
	    int buttonno = -1;
	    switch ((int)((XButtonEvent *)&event)->button) {
		case 1:  buttonno = 0; break;
		case 2:  buttonno = 2; break;
		case 3:  buttonno = 1; break;
		/* buttons 4 and 5 report mousewheel events */
		case 4:  if (state) record_key (0x7a << 1); break;
		case 5:  if (state) record_key (0x7b << 1); break;
	    }
            if (buttonno >=0)
		setmousebuttonstate(0, buttonno, state);
	    break;
	 }
	 case MotionNotify:
	    if (dgamode) {
		int tx = ((XMotionEvent *)&event)->x_root;
		int ty = ((XMotionEvent *)&event)->y_root;
		setmousestate (0, 0, tx, 0);
		setmousestate (0, 1, ty, 0);
	    } else if (grabbed) {
		int realmove = 0;
		int tx, ty,ttx,tty;

		tx = ((XMotionEvent *)&event)->x;
		ty = ((XMotionEvent *)&event)->y;

		if (! event.xmotion.send_event) {
		    setmousestate( 0,0,tx-oldx,0);
		    setmousestate( 0,1,ty-oldy,0);
		    realmove = 1;
#undef ABS
#define ABS(a) (((a)<0) ? -(a) : (a) )
		    if (ABS(current_width / 2 - tx) > 3 * current_width / 8
			|| ABS(current_height / 2 - ty) > 3 * current_height / 8)
		    {
#undef ABS
			XEvent event;
			ttx = current_width / 2;
			tty = current_height / 2;
			event.type = MotionNotify;
			event.xmotion.display = display;
			event.xmotion.window = mywin;
			event.xmotion.x = ttx;
			event.xmotion.y = tty;
			XSendEvent (display, mywin, False,
				    PointerMotionMask, &event);
			XWarpPointer (display, None, mywin, 0, 0, 0, 0, ttx, tty);
		    }
		} else {
		    tx=event.xmotion.x;
		    ty=event.xmotion.y;
		}
		oldx = tx;
		oldy = ty;
	    } else if (inwindow) {
		int tx = ((XMotionEvent *)&event)->x;
		int ty = ((XMotionEvent *)&event)->y;
		setmousestate(0,0,tx,1);
		setmousestate(0,1,ty,1);
		if (! cursorOn && !currprefs.hide_cursor) {
		    XDefineCursor(display, mywin, xhairCursor);
		    cursorOn = 1;
		}
		gettimeofday(&lastMotionTime, NULL);
	    }
	    break;
	 case EnterNotify:
	    {
		int tx = ((XCrossingEvent *)&event)->x;
		int ty = ((XCrossingEvent *)&event)->y;
		setmousestate(0,0,tx,1);
		setmousestate(0,1,ty,1);
	    }
	    inwindow = 1;
	    break;
	 case LeaveNotify:
	    inwindow = 0;
	    break;
	 case FocusIn:
	    if (! autorepeatoff)
		XAutoRepeatOff (display);
	    autorepeatoff = 1;
	    break;
	 case FocusOut:
	    if (autorepeatoff)
		XAutoRepeatOn (display);
	    autorepeatoff = 0;
	    inputdevice_release_all_keys ();
	    break;
	 case Expose:
	    refresh_necessary = 1;
	    break;
         case ClientMessage:
            if (((Atom)event.xclient.data.l[0]) == delete_win) {
		uae_stop ();
            }
            break;
	}
    }

#if defined PICASSO96
    if (! dgamode) {
	if (screen_is_picasso && refresh_necessary) {
	    DO_PUTIMAGE (pic_dinfo.ximg, 0, 0, 0, 0,
			 picasso_vidinfo.width, picasso_vidinfo.height);
	    XFlush (display);
	    refresh_necessary = 0;
	    memset (picasso_invalid_lines, 0, sizeof picasso_invalid_lines);
	} else if (screen_is_picasso && picasso_has_invalid_lines) {
	    int i;
	    int strt = -1;

	    picasso_invalid_lines[picasso_vidinfo.height] = 0;
	    for (i = picasso_invalid_start; i < picasso_invalid_stop + 2; i++) {
		if (picasso_invalid_lines[i]) {
		    picasso_invalid_lines[i] = 0;
		    if (strt != -1)
			continue;
		    strt = i;
		} else {
		    if (strt == -1)
			continue;
		    DO_PUTIMAGE (pic_dinfo.ximg, 0, strt, 0, strt,
				 picasso_vidinfo.width, i - strt);
		    strt = -1;
		}
	    }
	    XFlush (display);
	    if (strt != -1)
		abort ();
	}
    }
    picasso_has_invalid_lines = 0;
    picasso_invalid_start = picasso_vidinfo.height + 1;
    picasso_invalid_stop = -1;
#endif

    if (! dgamode) {
	if (! screen_is_picasso && refresh_necessary) {
	    DO_PUTIMAGE (ami_dinfo.ximg, 0, 0, 0, 0, current_width, current_height);
	    refresh_necessary = 0;
	}
	if (cursorOn && !currprefs.hide_cursor) {
	    struct timeval now;
	    int diff;
	    gettimeofday(&now, NULL);
	    diff = (now.tv_sec - lastMotionTime.tv_sec) * 1000000 +
		(now.tv_usec - lastMotionTime.tv_usec);
	    if (diff > 1000000) {
		XDefineCursor (display, mywin, blankCursor);
		cursorOn = 0;
	    }
	}
    }
}
Beispiel #4
0
static int viewport_setup(void) {
  intptr_t width, height, format, rowbytes, pixbytes;
  intptr_t rb = 0, gb = 0, bb = 0, ab = 0;
  intptr_t rs = 0, gs = 0, bs = 0, as = 0;

  printf("creating bitmap\n");

  bitmap = glgfx_bitmap_create(glgfx_bitmap_attr_width,  bm_width,
			       glgfx_bitmap_attr_height, bm_height,
			       glgfx_bitmap_attr_format, bm_format,
			       glgfx_tag_end);

  if (bitmap == NULL) {
    return 0;
  }

  printf("created bitmap %d %d format %08lx\n", bm_width, bm_height, bm_format);

  uint32_t* buffer;
  
  if ((buffer = glgfx_bitmap_lock(bitmap, false, true, glgfx_tag_end)) != NULL) {
    int x, y;

    for (y = 0; y < bm_height; y += 1) {
      for (x = 0; x < bm_width; x += 1) {
	buffer[x+y*bm_width] = glgfx_pixel_create_a8b8g8r8(y*255/bm_height, 0, x*255/bm_width, 128);
      }
    }

    if (glgfx_bitmap_unlock(bitmap, glgfx_tag_end)) {
      printf("updated bitmap\n");
    }
  }


  glgfx_bitmap_getattr(bitmap, glgfx_bitmap_attr_width,       &width);
  glgfx_bitmap_getattr(bitmap, glgfx_bitmap_attr_height,      &height);
  glgfx_bitmap_getattr(bitmap, glgfx_bitmap_attr_format,      &format);
  glgfx_bitmap_getattr(bitmap, glgfx_bitmap_attr_bytesperrow, &rowbytes);

  glgfx_pixel_getattr(format, glgfx_pixel_attr_bytesperpixel, &pixbytes);
  
  glgfx_pixel_getattr(format, glgfx_pixel_attr_redbits,       &rb);
  glgfx_pixel_getattr(format, glgfx_pixel_attr_greenbits,     &gb);
  glgfx_pixel_getattr(format, glgfx_pixel_attr_bluebits,      &bb);
  glgfx_pixel_getattr(format, glgfx_pixel_attr_alphabits,     &ab);
  glgfx_pixel_getattr(format, glgfx_pixel_attr_redshift,      &rs);
  glgfx_pixel_getattr(format, glgfx_pixel_attr_greenshift,    &gs);
  glgfx_pixel_getattr(format, glgfx_pixel_attr_blueshift,     &bs);
  glgfx_pixel_getattr(format, glgfx_pixel_attr_alphashift,    &as);
  
  alloc_colors64k(rb, gb, bb, rs, gs, bs, ab, as, ((1 << ab) - 1), 0 /* byte swap? */ );

  // Set up callback functions
  gfxvidinfo.flush_line         = _flush_line;
  gfxvidinfo.flush_block        = _flush_block;
  gfxvidinfo.flush_screen       = _flush_screen;
  gfxvidinfo.flush_clear_screen = _flush_clear_screen;
  gfxvidinfo.lockscr            = _lockscr;
  gfxvidinfo.unlockscr          = _unlockscr;

#ifdef PICASSO96
  if (!screen_is_picasso) {
#endif
    gfxvidinfo.width         = width;
    gfxvidinfo.height        = height;
    gfxvidinfo.pixbytes      = pixbytes;
    gfxvidinfo.rowbytes      = rowbytes;

    gfxvidinfo.bufmem        = NULL;
    gfxvidinfo.emergmem      = malloc(rowbytes);
    gfxvidinfo.maxblocklines = height;
//    gfxvidinfo.maxblocklines = 0;
    gfxvidinfo.linemem       = NULL;

    reset_drawing ();
    
#ifdef PICASSO96
  }
  else {
    picasso_has_invalid_lines	= 0;
    picasso_invalid_start	= height + 1;
    picasso_invalid_stop	= -1;
    
    picasso_vidinfo.width       = width;
    picasso_vidinfo.height      = height;
    picasso_vidinfo.depth       = rb + gb + bb + ab;
    picasso_vidinfo.pixbytes    = pixbytes;
    picasso_vidinfo.rowbytes    = rowbytes;
    picasso_vidinfo.extra_mem	= 1;

    p96_buffer = malloc(width*height*pixbytes);
    p96_bytes_per_row = width*pixbytes;
    
    memset (picasso_invalid_lines, 0, sizeof picasso_invalid_lines);
  }
#endif

  if (fullscreen) {
    rasinfo = glgfx_viewport_addbitmap(viewport, bitmap, 
				       glgfx_rasinfo_attr_x,      0,
				       glgfx_rasinfo_attr_y,      0,
				       glgfx_rasinfo_attr_width,  real_width, 
				       glgfx_rasinfo_attr_height, real_height, 
				       glgfx_tag_end);
  }
  else {
    rasinfo = glgfx_viewport_addbitmap(viewport, bitmap, 
				       glgfx_rasinfo_attr_x,      (real_width - bm_width) / 2,
				       glgfx_rasinfo_attr_y,      (real_height - bm_height) / 2,
				       glgfx_rasinfo_attr_width,  width,
				       glgfx_rasinfo_attr_height, height,
				       glgfx_tag_end);
  }

  if (rasinfo == NULL) {
    return 0;
  }
  
  inputdevice_release_all_keys();
  reset_hotkeys();

  printf("viewport_setup -> 1\n");
  return 1;
}