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

📄 ui_dga.c

📁 另一个分形程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	  x_fatalerror ("XGrabKeyboard failed\n");	}      xf86ctx.grabbed_keybd = 1;    }  if (!xf86ctx.grabbed_mouse)    {      if (XGrabPointer (display, window, True,			PointerMotionMask | ButtonPressMask |			ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None,			None, CurrentTime))	{	  DGA_uninitialise ();	  x_fatalerror ("XGrabPointer failed\n");	}      xf86ctx.grabbed_mouse = 1;    }  if (first_time)    {      if (XF86DGAForkApp (xf86ctx.screen))	{	  perror ("fork");	  DGA_uninitialise ();	  exit (1);	}      first_time = 0;    }  if (!XF86DGADirectVideo (display, xf86ctx.screen,			   XF86DGADirectGraphics | XF86DGADirectMouse |			   XF86DGADirectKeyb))    {      DGA_uninitialise ();      x_fatalerror ("XF86DGADirectVideo failed\n");    }  if (!XF86DGASetViewPort (display, xf86ctx.screen, 0, 0))    {      DGA_uninitialise ();      x_fatalerror ("XF86DGASetViewPort failed\n");    }  /*memset (xf86ctx.base_addr, 0, xf86ctx.bank_size); */}static intDGA_init (void){  int major, minor, event_base, error_base, flags;  int i, count;  XPixmapFormatValues *pixmaps;  mousebuttons = 0;  if (!(display = XOpenDisplay (defdisplay)))    {      return 0;    }  xf86ctx.screen = DefaultScreen (display);  if (geteuid ())    {      x_error ("DGA requires root rights\n");      XCloseDisplay (display);      return 0;    }  if (!XF86DGAQueryVersion (display, &major, &minor))    {      x_error ("XF86DGAQueryVersion failed \n");      XCloseDisplay (display);      return 0;    }  if (!XF86DGAQueryExtension (display, &event_base, &error_base))    {      x_error ("XF86DGAQueryExtension failed\n");      XCloseDisplay (display);      return 0;    }  if (!XF86DGAQueryDirectVideo (display, xf86ctx.screen, &flags))    {      x_error ("XF86DGAQueryDirectVideo failed\n");      XCloseDisplay (display);      return 0;    }  if (!(flags & XF86DGADirectPresent))    {      x_error ("XF86DGADirectVideo support is not present\n");      XCloseDisplay (display);      return 0;    }  if (!XF86DGAGetVideo (display, xf86ctx.screen,			&xf86ctx.base_addr, &xf86ctx.linewidth,			&xf86ctx.bank_size, &xf86ctx.ram_size))    {      x_error ("XF86DGAGetVideo failed\n");      XCloseDisplay (display);      return 0;    }  xf86ctx.visual = DefaultVisual (display, xf86ctx.screen);  if (xf86ctx.bank_size != (xf86ctx.ram_size * 1024))    {      x_error ("Banked graphics modes not supported\n");      XCloseDisplay (display);      return 0;    }  if (!XF86VidModeQueryVersion (display, &major, &minor))    {      x_error ("XF86VidModeQueryVersion failed\n");      XCloseDisplay (display);      return 0;    }  if (!XF86VidModeQueryExtension (display, &event_base, &error_base))    {      x_error ("XF86VidModeQueryExtension failed\n");      XCloseDisplay (display);      return 0;    }  /* dirty hack 24bpp can be either 24bpp packed or 32 bpp sparse */  pixmaps = XListPixmapFormats (display, &count);  if (!pixmaps)    {      x_error ("X11-Error: Couldn't list pixmap formats.\n"	       "Probably out of memory.\n");      XCloseDisplay (display);      return 0;    }  for (i = 0; i < count; i++)    {      if (pixmaps[i].depth == DefaultDepth (display, xf86ctx.screen))	{	  xf86ctx.depth = pixmaps[i].bits_per_pixel;	  break;	}    }  free (pixmaps);  if (i == count)    {      x_error	("Couldn't find a zpixmap with the defaultcolordepth\nThis should not happen!\n");      XCloseDisplay (display);      return 0;    }  DGA_getmodeinfo (&xf86ctx.orig_mode);  if (!XF86VidModeGetAllModeLines (display, xf86ctx.screen,				   &xf86ctx.modecount, &xf86ctx.modes))    {      x_error ("XF86VidModeGetAllModeLines failed\n");      XCloseDisplay (display);      return 0;    }  names = calloc (sizeof (*names), xf86ctx.modecount + 1);  for (i = 0; i < xf86ctx.modecount; i++)    {      char c[256];      sprintf (c, "%ix%i", xf86ctx.modes[i]->hdisplay,	       xf86ctx.modes[i]->vdisplay);      names[i] = mystrdup (c);    }  menu_add (menuitems, NITEMS (menuitems));  DGA_driver.width = (XDisplayWidthMM (display, xf86ctx.screen)) / 10.0;  DGA_driver.height = (XDisplayHeightMM (display, xf86ctx.screen)) / 10.0;  return ( /*1 for sucess 0 for fail */ 1);}static voidDGA_uninitialise (){  int i;  if (xf86ctx.cmap)    {      XFreeColormap (display, xf86ctx.cmap);      xf86ctx.cmap = 0;    }  if (xf86ctx.pixels)    {      free (xf86ctx.pixels);      xf86ctx.pixels = NULL;    }  if (xf86ctx.grabbed_mouse)    {      XUngrabPointer (display, CurrentTime);      xf86ctx.grabbed_mouse = 0;    }  if (xf86ctx.grabbed_keybd)    {      XUngrabKeyboard (display, CurrentTime);      xf86ctx.grabbed_keybd = 0;    }  XF86DGADirectVideo (display, xf86ctx.screen, 0);  if (xf86ctx.vidmode_changed)    {      DGA_vidmode_restoremode (display);      xf86ctx.vidmode_changed = 0;    }  menu_delete (menuitems, NITEMS (menuitems));  for (i = 0; i < xf86ctx.modecount; i++)    free (names[i]);  free (names);}static voidDGA_updatemouse (int x, int y){  mouseX = x;  mouseY = y;  if (storeddata)    {      restore (xf86ctx.base_addr, storeddata, xf86ctx.depth,	       xf86ctx.depth / 8 * xf86ctx.linewidth, xf86ctx.width,	       xf86ctx.height, oldmouseX, oldmouseY);      free (storeddata);    }  storeddata =    store (xf86ctx.base_addr, xf86ctx.depth,	   xf86ctx.depth / 8 * xf86ctx.linewidth, xf86ctx.width,	   xf86ctx.height, mouseX, mouseY);  drawmouse (xf86ctx.base_addr, mousepointer, xf86ctx.depth,	     xf86ctx.depth / 8 * xf86ctx.linewidth, xf86ctx.width,	     xf86ctx.height, mouseX, mouseY);  oldmouseX = mouseX;  oldmouseY = mouseY;}static voidDGA_processevents (int wait, int *mx, int *my, int *mb, int *k){  static int iflag = 0;  XEvent ev;  if (XPending (display) || wait)    {      do	{	  int mousex = 0, mousey = 0;	  XNextEvent (display, &ev);	  switch (ev.type)	    {	    case ButtonRelease:	      switch (ev.xbutton.button)		{		case 1:		  mousebuttons &= ~BUTTON1;		  break;		case 2:		  mousebuttons &= ~BUTTON2;		  break;		case 3:		  mousebuttons &= ~BUTTON3;		  break;		}	      break;	    case ButtonPress:	      switch (ev.xbutton.button)		{		case 1:		  mousebuttons |= BUTTON1;		  break;		case 2:		  mousebuttons |= BUTTON2;		  break;		case 3:		  mousebuttons |= BUTTON3;		  break;		}	      break;	    case MotionNotify:	      mousex = ev.xmotion.x_root;	      mousey = ev.xmotion.y_root;	      break;	    case KeyRelease:	      {		switch (XLookupKeysym (&ev.xkey, 0))		  {		  case XK_Left:		    iflag &= ~1;		    break;		  case XK_Right:		    iflag &= ~2;		    break;		  case XK_Up:		    iflag &= ~4;		    break;		  case XK_Down:		    iflag &= ~8;		    break;		  }	      }	      break;	    case KeyPress:	      {		KeySym ksym;		switch (ksym = XLookupKeysym (&ev.xkey, 0))		  {		  case XK_Left:		    iflag |= 1;		    ui_key (UIKEY_LEFT);		    break;		  case XK_Right:		    iflag |= 2;		    ui_key (UIKEY_RIGHT);		    break;		  case XK_Up:		    iflag |= 4;		    ui_key (UIKEY_UP);		    break;		  case XK_Down:		    iflag |= 8;		    ui_key (UIKEY_DOWN);		    break;#ifdef XK_Page_Up		  case XK_Page_Up:		    iflag |= 4;		    ui_key (UIKEY_PGUP);		    break;		  case XK_Page_Down:		    iflag |= 8;		    ui_key (UIKEY_PGDOWN);		    break;#endif		  case XK_Escape:		    ui_key (UIKEY_ESC);		  case XK_BackSpace:		    ui_key (UIKEY_BACKSPACE);		  default:		    {		      CONST char *name;		      char buff[256];		      if (ksym == XK_F1)			name = "h";		      else			{			  name = buff;			  buff[XLookupString			       (&ev.xkey, buff, 256, &ksym, NULL)] = 0;			}		      if (strlen (name) == 1)			{			  if (ui_key (*name) == 2)			    {			      return;			    }			}		    }		  }	      }	      break;	    }	  if (mousex || mousey)	    {	      mousex += mouseX;	      mousey += mouseY;	      if (mousex < 0)		mousex = 0;	      if (mousey < 0)		mousey = 0;	      if (mousex > xf86ctx.width)		mousex = xf86ctx.width;	      if (mousey > xf86ctx.height)		mousey = xf86ctx.height;	      DGA_updatemouse (mousex, mousey);	    }	}      while (XPending (display));    }  *mx = mouseX;  *my = mouseY;  *mb = mousebuttons;  *k = iflag;}static voidDGA_getmouse (int *x, int *y, int *b){  *x = mouseX;  *y = mouseY;  *b = mousebuttons;}static voidDGA_mousetype (int type){  switch (type)    {    default:    case 0:      mousepointer = mouse_pointer_data;      break;    case 1:      mousepointer = wait_pointer_data;      break;    case 2:      mousepointer = replay_pointer_data;      break;    }  DGA_updatemouse (mouseX, mouseY);}static CONST struct params params[] = {  {"", P_HELP, NULL, "DGA driver options:"},  {"-display", P_STRING, &defdisplay, "Select display"},  {"-defmode", P_STRING, &mode, "Select videomode nearest to specified mode"},  {NULL, 0, NULL, NULL}};struct ui_driver DGA_driver = {  "DGA",  DGA_init,  DGA_getsize,  DGA_processevents,  DGA_getmouse,  DGA_uninitialise,  NULL,  DGA_setpalette,  DGA_print,  DGA_display,  DGA_alloc_buffers,  DGA_free_buffers,  DGA_flip_buffers,  DGA_mousetype,		/*This should be NULL */  NULL,				/*flush */  8,				/*text width */  8,				/*text height */  params,  FULLSCREEN | UPDATE_AFTER_RESIZE,	/*flags...see ui.h */  0.0, 0.0,			/*width/height of screen in centimeters */  0, 0,				/*resolution of screen for windowed systems */  UI_C256,			/*Image type */  0, 255, 255			/*start, end of palette and maximum allocatable */    /*entries */};/* DONT FORGET TO ADD DOCUMENTATION ABOUT YOUR DRIVER INTO xaos.hlp FILE!*/#endif

⌨️ 快捷键说明

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