⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x11_out.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 3 页
字号:
		    		    /* Have we been requested to quit (or another client message?) */		  case ClientMessage:		    if ( (xevent.xclient.format == 32) && (xevent.xclient.data.l[0] == xWindow->WM_DELETE_WINDOW) ) {		      evt.type = GF_EVENT_QUIT;		      vout->on_event(vout->evt_cbk_hdl, &evt);		    }		    break;		  case KeyPress:		  case KeyRelease:		    x11_translate_key(XKeycodeToKeysym (xWindow->display, xevent.xkey.keycode, 0), &evt.key);			evt.type = (xevent.type ==KeyPress) ? GF_EVENT_KEYDOWN : GF_EVENT_KEYUP;			vout->on_event (vout->evt_cbk_hdl, &evt);		    			if (xevent.type ==KeyPress) {				XLookupString (&xevent.xkey, (char *) keybuf, sizeof(keybuf), NULL, &state);				if (keybuf[0]) {					evt.character.unicode_char = keybuf[0];					evt.type = GF_EVENT_TEXTINPUT;					vout->on_event (vout->evt_cbk_hdl, &evt);				}			}			break;		    		  case ButtonPress:			  if (!xWindow->fullscreen && !xWindow->has_focus) {				  xWindow->has_focus = 1;				  XSetInputFocus(xWindow->display, xWindow->wnd, RevertToParent, CurrentTime);			  }		  case ButtonRelease:		    //				last_mouse_move = xevent.xbutton.time;		    evt.mouse.x = xevent.xbutton.x;		    evt.mouse.y = xevent.xbutton.y;			evt.type = (xevent.type == ButtonRelease) ? GF_EVENT_MOUSEUP : GF_EVENT_MOUSEDOWN;		    		    switch (xevent.xbutton.button) {		    case Button1:		      evt.mouse.button = GF_MOUSE_LEFT;		      vout->on_event (vout->evt_cbk_hdl, &evt);		      break;		    case Button2:		      evt.mouse.button = GF_MOUSE_MIDDLE;		      vout->on_event (vout->evt_cbk_hdl, &evt);		      break;		    case Button3:		      evt.mouse.button = GF_MOUSE_RIGHT;		      vout->on_event (vout->evt_cbk_hdl, &evt);		      break;		    case Button4:		      evt.type = GF_EVENT_MOUSEWHEEL;		      evt.mouse.wheel_pos = FIX_ONE;		      vout->on_event(vout->evt_cbk_hdl, &evt);		      break;		    case Button5:		      evt.type = GF_EVENT_MOUSEWHEEL;		      evt.mouse.wheel_pos = -FIX_ONE;		      vout->on_event(vout->evt_cbk_hdl, &evt);		      break;		    }		    if (!xWindow->fullscreen && (xevent.type==ButtonPress) ) 		      XSetInputFocus(xWindow->display, xWindow->wnd, RevertToNone, CurrentTime);		    break;		    		  case MotionNotify:		    evt.type = GF_EVENT_MOUSEMOVE;		    evt.mouse.x = xevent.xmotion.x;		    evt.mouse.y = xevent.xmotion.y;		    vout->on_event (vout->evt_cbk_hdl, &evt);		    break;		    		  case PropertyNotify:		    break;		  case MapNotify:		    break;		  case CirculateNotify:		    break;		  case UnmapNotify:		    break;		  case ReparentNotify:		    break;		  case FocusOut:			if (!xWindow->fullscreen) xWindow->has_focus = 0;		    break;		  case FocusIn:			if (!xWindow->fullscreen) xWindow->has_focus = 1;		    break;		    		  case DestroyNotify:		      evt.type = GF_EVENT_QUIT;		      vout->on_event(vout->evt_cbk_hdl, &evt);		    break;		    		  default:		    break;		  }	 }}#ifdef GPAC_HAS_OPENGLstatic GF_Err X11_SetupGL(GF_VideoOutput *vout){  GF_Event evt;  XWindow *xWin = (XWindow *)vout->opaque;  XSync(xWin->display, False);  xWin->glx_context = glXCreateContext(xWin->display,xWin->glx_visualinfo, NULL, True);  XSync(xWin->display, False);  if (!xWin->glx_context) return GF_IO_ERR;  if ( ! glXMakeCurrent(xWin->display, xWin->fullscreen ? xWin->full_wnd : xWin->wnd, xWin->glx_context) ) return GF_IO_ERR;  XSync(xWin->display, False);  evt.type = GF_EVENT_VIDEO_SETUP;  vout->on_event (vout->evt_cbk_hdl,&evt);  xWin->is_init = 1;  return GF_OK;}static void X11_ReleaseGL(XWindow *xWin){  XSync(xWin->display, False);  if (xWin->glx_context) {    glXMakeCurrent(xWin->display, None, NULL);    glXDestroyContext(xWin->display, xWin->glx_context);    xWin->glx_context = NULL;  }  xWin->is_init = 0;  XSync(xWin->display, False);}#endifstatic void X11_ReleaseBackBuffer (GF_VideoOutput * vout){	X11VID ();	if (xWindow->is_init == 1) {		switch (xWindow->videoaccesstype) {#ifdef GPAC_HAS_X11_SHM		case VIDEO_XI_SHMSTD:			XShmDetach (xWindow->display, xWindow->shmseginfo);			if (xWindow->surface) XDestroyImage(xWindow->surface);			xWindow->surface = NULL;			if (xWindow->shmseginfo->shmaddr) shmdt(xWindow->shmseginfo->shmaddr);			if (xWindow->shmseginfo->shmid >= 0)				shmctl (xWindow->shmseginfo->shmid, IPC_RMID, NULL);			free (xWindow->shmseginfo);			xWindow->shmseginfo = NULL;			break;		case VIDEO_XI_SHMPIXMAP:			XShmDetach(xWindow->display, xWindow->shmseginfo);			XFreePixmap(xWindow->display, xWindow->pixmap);			if (xWindow->shmseginfo->shmaddr) shmdt (xWindow->shmseginfo->shmaddr);			if (xWindow->shmseginfo->shmid >= 0) shmctl (xWindow->shmseginfo->shmid, IPC_RMID, NULL);			free (xWindow->shmseginfo);			xWindow->shmseginfo = NULL;			break;#endif		case VIDEO_XI_STANDARD:			if (xWindow->back_buffer->buffer) free (xWindow->back_buffer->buffer);			xWindow->back_buffer->buffer = NULL;			if (xWindow->surface) XFree(xWindow->surface);			xWindow->surface = NULL;			break;		}		xWindow->is_init = 0;	}}/* * init backbuffer */GF_Err X11_InitBackBuffer (GF_VideoOutput * vout, u32 VideoWidth, u32 VideoHeight){	Window cur_wnd;	u32 size;	VideoWidth = VideoWidth > 32 ? VideoWidth : 32;	VideoWidth = VideoWidth < 4096 ? VideoWidth : 4096;	VideoHeight = VideoHeight > 32 ? VideoHeight : 32;	VideoHeight = VideoHeight > 4096 ? 4096 : VideoHeight;	X11VID ();	if (!xWindow || !VideoWidth || !VideoHeight)		return GF_BAD_PARAM;	X11_ReleaseBackBuffer(vout);	/*WATCHOUT seems we need even width when using shared memory extensions*/	if ((xWindow->videoaccesstype!=VIDEO_XI_STANDARD) && (VideoWidth%2)) 	  VideoWidth++;	xWindow->back_buffer->BPP = xWindow->bpp;	xWindow->back_buffer->width = VideoWidth;	xWindow->back_buffer->height = VideoHeight;	xWindow->back_buffer->pitch = VideoWidth * xWindow->bpp;	size = VideoWidth * VideoHeight * xWindow->bpp;	cur_wnd = xWindow->fullscreen ? xWindow->full_wnd : xWindow->wnd;	switch (xWindow->videoaccesstype) {#ifdef GPAC_HAS_X11_SHM	case VIDEO_XI_SHMPIXMAP:		GF_SAFEALLOC(xWindow->shmseginfo, XShmSegmentInfo);		xWindow->shmseginfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);		xWindow->shmseginfo->shmaddr = shmat(xWindow->shmseginfo->shmid, 0, 0);		xWindow->back_buffer->buffer = (unsigned char *) xWindow->shmseginfo->shmaddr;		xWindow->shmseginfo->readOnly = False;		XShmAttach (xWindow->display, xWindow->shmseginfo);		xWindow->pixmap = XShmCreatePixmap (xWindow->display, cur_wnd,								xWindow->back_buffer->buffer, xWindow->shmseginfo,								VideoWidth, VideoHeight, xWindow->depth);		XSetWindowBackgroundPixmap (xWindow->display, cur_wnd, xWindow->pixmap);		break;	case VIDEO_XI_SHMSTD:		GF_SAFEALLOC(xWindow->shmseginfo, XShmSegmentInfo);		xWindow->surface = XShmCreateImage (xWindow->display, xWindow->visual,										 xWindow->depth, ZPixmap, NULL, xWindow->shmseginfo, 										 VideoWidth, VideoHeight);		xWindow->shmseginfo->shmid = shmget(IPC_PRIVATE,									 xWindow->surface->bytes_per_line * xWindow->surface->height,									 IPC_CREAT | 0777);		xWindow->surface->data = xWindow->shmseginfo->shmaddr = shmat(xWindow->shmseginfo->shmid, NULL, 0);		xWindow->back_buffer->buffer = (unsigned char *) xWindow->surface->data;		xWindow->shmseginfo->readOnly = False;		XShmAttach (xWindow->display, xWindow->shmseginfo);		break;#endif	case VIDEO_XI_STANDARD:		xWindow->back_buffer->buffer = (char *) malloc(sizeof(char)*size);		xWindow->surface = XCreateImage (xWindow->display, xWindow->visual,				      xWindow->depth, ZPixmap,				      0,				      xWindow->back_buffer->buffer,				      VideoWidth, VideoHeight,				      xWindow->bpp*8, xWindow->back_buffer->pitch);	}	xWindow->is_init = 1;	return GF_OK;}/* * resize buffer: note we don't resize window here */GF_Err X11_ResizeBackBuffer (struct _video_out *vout, u32 newWidth, u32 newHeight){	X11VID ();	if ((newWidth != xWindow->back_buffer->width) || (newHeight != xWindow->back_buffer->height)) {		if ((newWidth >= 32) && (newHeight >= 32))			return X11_InitBackBuffer (vout, newWidth, newHeight);	}	return GF_OK;}GF_Err X11_ProcessEvent (struct _video_out * vout, GF_Event * evt){	X11VID ();	if (!xWindow->setup_done) X11_SetupWindow(vout);	if (evt) {	switch (evt->type) {	case GF_EVENT_SET_CURSOR:		break;	case GF_EVENT_SET_CAPTION:		if (!xWindow->par_wnd) XStoreName (xWindow->display, xWindow->wnd, evt->caption.caption);		break;	case GF_EVENT_SHOWHIDE:		break;	case GF_EVENT_SIZE:		/*if owning the window and not in fullscreen, resize it (initial scene size)*/	xWindow->w_width = evt->size.width;	xWindow->w_height = evt->size.height;	  if (!xWindow->fullscreen) {	    if (xWindow->par_wnd) {	      XWindowAttributes pwa;	      XGetWindowAttributes(xWindow->display, xWindow->par_wnd, &pwa);	      XMoveResizeWindow(xWindow->display, xWindow->wnd, pwa.x, pwa.y, evt->size.width, evt->size.height);	      if (!xWindow->no_select_input) XSetInputFocus(xWindow->display, xWindow->wnd, RevertToNone, CurrentTime);	    } else {		XResizeWindow (xWindow->display, xWindow->wnd, evt->size.width, evt->size.height);	    }	  }	  break;	case GF_EVENT_VIDEO_SETUP:		/*and resetup HW*/#ifdef GPAC_HAS_OPENGL		if (xWindow->is_3D_out) return X11_SetupGL(vout);#endif		return X11_ResizeBackBuffer(vout, evt->size.width, evt->size.height);	}	} else {	  X11_HandleEvents(vout);	}	return GF_OK;}/* switch from/to full screen mode */GF_Err X11_SetFullScreen (struct _video_out * vout, u32 bFullScreenOn, u32 * screen_width, u32 * screen_height){	X11VID ();	xWindow->fullscreen = bFullScreenOn;#ifdef GPAC_HAS_OPENGL	if (xWindow->is_3D_out) X11_ReleaseGL(xWindow);#endif	if (bFullScreenOn) {		xWindow->store_width = *screen_width;		xWindow->store_height = *screen_height;		xWindow->w_width = vout->max_screen_width;		xWindow->w_height = vout->max_screen_height;		XFreeGC (xWindow->display, xWindow->the_gc);		xWindow->the_gc = XCreateGC (xWindow->display, xWindow->full_wnd, 0, NULL);		XMoveResizeWindow (xWindow->display,				   (Window) xWindow->full_wnd, 0, 0,				   vout->max_screen_width,				   vout->max_screen_height);		*screen_width = xWindow->w_width;		*screen_height = xWindow->w_height;		XUnmapWindow (xWindow->display, xWindow->wnd);		XMapWindow (xWindow->display, xWindow->full_wnd);		XSetInputFocus(xWindow->display, xWindow->full_wnd, RevertToNone, CurrentTime);		XRaiseWindow(xWindow->display, xWindow->full_wnd);		XGrabKeyboard(xWindow->display, xWindow->full_wnd, True, GrabModeAsync, GrabModeAsync, CurrentTime);	} else {		*screen_width = xWindow->store_width;		*screen_height = xWindow->store_height;		XFreeGC (xWindow->display, xWindow->the_gc);		xWindow->the_gc = XCreateGC (xWindow->display, xWindow->wnd, 0, NULL);		XUnmapWindow (xWindow->display, xWindow->full_wnd);		XMapWindow (xWindow->display, xWindow->wnd);		XUngrabKeyboard(xWindow->display, CurrentTime);		if (xWindow->par_wnd) XSetInputFocus(xWindow->display, xWindow->wnd, RevertToNone, CurrentTime);		/*backbuffer resize will be done right after this is called */	}#ifdef GPAC_HAS_OPENGL	if (xWindow->is_3D_out) X11_SetupGL(vout);#endif	return GF_OK;}/*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -