Esempio n. 1
0
File: demo.c Progetto: OpenMORDM/rgl
static void
EventLoop(WindowData *winData)
{
   while (1) {
      static long mask = StructureNotifyMask | ExposureMask | KeyPressMask;
      XEvent event;
      while (XCheckWindowEvent(winData->display, winData->window,
                               mask, &event)) {
         if (event.xany.window == winData->window) {
            switch (event.type) {
            case Expose:
               DrawScene(winData);
               break;
            case ConfigureNotify:
               glViewport(0, 0,
                          event.xconfigure.width, event.xconfigure.height);
               break;
            case KeyPress:
               {
                  char buffer[10];
                  int r;
                  r = XLookupString(&event.xkey, buffer, sizeof(buffer),
                                    NULL, NULL);
                  if (buffer[0] == 27) {
                     /* escape */
                        return;
                  }
               }
            }
         }
      }
      DrawScene(winData);
   }
}
Esempio n. 2
0
static void
resize(Widget w, XtPointer client_data, XEvent *call_data, Boolean *continue_dispatch)
{
    GRAPH *graph = (GRAPH *) client_data;
    XEvent ev;

    NG_IGNORE(call_data);
    NG_IGNORE(continue_dispatch);

    /* pull out all other exposure events
       Also, get rid of other StructureNotify events on this window. */

    while (XCheckWindowEvent(display, DEVDEP(graph).window,
                             /* ExposureMask | */ StructureNotifyMask, &ev))
        ;

    XClearWindow(display, DEVDEP(graph).window);
    graph->absolute.width = w->core.width;
    graph->absolute.height = w->core.height;
    {
        GRAPH *tmp = currentgraph;
        currentgraph = graph;
        gr_resize(graph);
        currentgraph = tmp;
    }
}
/*--------------------------------------
 * Function: UpdateDisplayImpl()
 * Parameters:
 *
 * Description:
 *   Uppdaterar ritytan.
 *------------------------------------*/
void UpdateDisplayImpl() {
    glXSwapBuffers(display, window);

    XEvent xe;
    //XNextEvent(display, &xe);
    if (XCheckWindowEvent(display, window, KeyPressMask, &xe)) {
        if (xe.type == ClientMessage) {
            if (xe.xclient.data.l[0] == wm_delete_msg) {
                // Easy h4x, lol.
                window = NULL;
            }
        }
        else if (xe.type == MappingNotify) {
            printf("broder dang\n");
            XRefreshKeyboardMapping((XMappingEvent*)&xe);
        }
        else {
            char buf[16] = {0};
            KeySym keysym;
            XLookupString((XKeyEvent*)&xe, buf, sizeof(buf), &keysym, NULL);
            char c = buf[0];
            actionT fn = keyPressCB[c];
            if (fn) fn(keyPressArg[c]);
        }
    }
}
Esempio n. 4
0
int event_x () {

  XEvent XEv;

  return ( ! XCheckWindowEvent ( dis , win , KeyPressMask , &XEv ) ); 

}
Esempio n. 5
0
static int check_window_event(void *win_display, void *drawable, int *width, int *height, int *quit)
{
    int is_event = 0;
    XEvent event;
    Window win = (Window)drawable;
    Display *x11_display = (Display *)win_display;
    
    
    if (check_event == 0)
        return 0;

    pthread_mutex_lock(&gmutex);
    is_event = XCheckWindowEvent(x11_display, win, StructureNotifyMask|KeyPressMask,&event);
    pthread_mutex_unlock(&gmutex);
    
    if (is_event == 0)
        return 0;

    /* bail on any focused key press */
    if(event.type == KeyPress) {  
        *quit = 1;
        return 0;
    }
    
#if 0
    /* rescale the video to fit the window */
    if(event.type == ConfigureNotify) { 
        *width = event.xconfigure.width;
        *height = event.xconfigure.height;
        printf("Scale window to %dx%d\n", width, height);
    }
#endif

    return 0;
}
Esempio n. 6
0
void
x_window_rep::translate (SI x1, SI y1, SI x2, SI y2, SI dx, SI dy) {
  ren->set_origin(0,0);
  begin_draw ();
  ren->clip (x1, y1, x2, y2);

  SI X1= x1+ dx;
  SI Y2= y2+ dy;
  ren->decode (x1, y1);
  ren->decode (x2, y2);
  ren->decode (X1, Y2);
  dx= X1- x1;
  dy= Y2- y2;

  XEvent report;
  while (XCheckWindowEvent (dpy, win, ExposureMask, &report))
    gui->process_event (this, &report);

  rectangles region (rectangle (x1, y2, x2, y1));
  rectangles invalid_intern= invalid_regions & region;
  rectangles invalid_extern= invalid_regions - invalid_intern;
  invalid_intern = ::translate (invalid_intern, dx, dy) & region;
  invalid_regions= invalid_extern | invalid_intern;

  rectangles extra= thicken (region - ::translate (region, dx, dy), 1, 1);
  invalid_regions= invalid_regions | extra;

  if (x1<x2 && y2<y1)
    XCopyArea (dpy, win, win, gc, x1, y2, x2-x1, y1-y2, X1, Y2);
  
  
  ren->unclip ();
  end_draw ();
}
Esempio n. 7
0
static void handle_expose(const XExposeEvent *ev)
{
	WWindow *wwin;
	WScreen *scr;
	XEvent tmp;
	
	while(XCheckWindowEvent(wglobal.dpy, ev->window, ExposureMask, &tmp))
		/* nothing */;

	wwin=FIND_WINDOW_T(ev->window, WWindow);

	if(wwin!=NULL){
		redraw_wwin(wwin);
		return;
	}
	
	if(wglobal.grab_holder==NULL || !WTHING_IS(wglobal.grab_holder, WClient))
		return;
	
	FOR_ALL_SCREENS(scr){
		if(scr->grdata.tabdrag_win==ev->window){
			draw_tabdrag((WClient*)wglobal.grab_holder);
			break;
		}
	}
}
Esempio n. 8
0
void GuiCalibratorX11::give_timer_signal()
{
    if (instance != NULL) {
        // timer signal
        //check timeout
        instance->on_timer_signal();

        // process events
        XEvent event;
        int x, y;
        if (instance->calib_input)
                if (instance->calibrator->check_press_event(&x, &y))
                        instance->on_button_press_event(x, y);
        while (XCheckWindowEvent(instance->display, instance->win, -1, &event) == True) {
            switch (event.type) {
                case Expose:
                    // only draw the last contiguous expose
                    if (event.xexpose.count != 0)
                        break;
                    instance->on_expose_event();
                    break;
                case ButtonPress:
                    if (!instance->calib_input)
                        instance->on_button_press_event(event.xbutton.x, event.xbutton.y);
                    break;
                case KeyPress:
                    exit(0);
                    break;
            }
        }
    }
}
Esempio n. 9
0
int getch()
{
  if (dpy)
  {
    char buffer[100];
    XEvent xev;
    KeySym keysym;
    XComposeStatus compose;

    XFlush(dpy);
    // Wait for the next event
    // XWindowEvent(dpy, win, KeyPressMask, &xev);
    while(!XCheckWindowEvent(dpy, win, KeyPressMask, &xev))
    {
      gi.CheckWindowEvents();
    }
    // This can only be KeyPress because of the mask
    XLookupString((XKeyEvent *)&xev, buffer, sizeof(buffer), &keysym, &compose);
    switch (keysym)
    {
      case XK_Escape:
        return(ESC);
      case XK_Up:
        return(UP);
      case XK_Down:
        return(DOWN);
      default:
        return(keysym);
    }
  }
  else
  {
    return 0;
  }
}
Esempio n. 10
0
int MostrarVideo(struct XVideoContext *xvc,union RGB24Pixel *data,DrawFrameFunc *fc,void *param){
	char *dptr=xvc->img->data,*sptr=(char*)data;
    uint i;
	XEvent event;

    if(XCheckWindowEvent(xvc->display,xvc->window,!NoEventMask,&event)){
        //XNextEvent(xvc->display,&event);

		if (event.type == KeyPress)
			xvc->key=XLookupKeysym(&event.xkey,0);
		else if(event.type == ClientMessage){
            if (event.xclient.data.l[0] == (uint)xvc->wmDeleteMessage)
				return -1;
		}

	}

	for(i=0;i<xvc->width*xvc->height;i++){

		*(dptr+2)=*(sptr++);
		*(dptr+1)=*(sptr++);
		*(dptr+0)=*(sptr++);
		*(dptr+4)=0;
		dptr+=4;
	}

    XPutImage(xvc->display, xvc->pixmap, xvc->gc, xvc->img, 0, 0, 0, 0, xvc->width, xvc->height);
	//XDrawString(xvc->display, xvc->window, DefaultGC(xvc->display, xvc->defscreen), 20, 20, text, strlen(text));
	if(fc)
	    fc(xvc,param);

    XCopyArea(xvc->display,xvc->pixmap,xvc->window,xvc->gc,0,0,xvc->width,xvc->height,0,0);
	XFlush(xvc->display);
	return 0;
}
Esempio n. 11
0
void
processKeys(Window window)
{
    XEvent event;
    while (XCheckWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event)) {
        processEvent(event);
    }
}
Esempio n. 12
0
void MSWidget::expose(const XEvent *pEvent_)
{
  if (pEvent_->xexpose.count==0)
   {
     XEvent aEvent;
     while (XCheckWindowEvent(display(),_window,ExposureMask,&aEvent)==True);
     redraw();
   }
}
int AbstractXApplication::exec() {
    /* Show window */
    XMapWindow(_display, _window);

    while(!(_flags & Flag::Exit)) {
        XEvent event;

        /* Closed window */
        if(XCheckTypedWindowEvent(_display, _window, ClientMessage, &event) &&
                Atom(event.xclient.data.l[0]) == _deleteWindow) {
            return 0;
        }

        while(XCheckWindowEvent(_display, _window, INPUT_MASK, &event)) {
            switch(event.type) {
            /* Window resizing */
            case ConfigureNotify: {
                Vector2i size(event.xconfigure.width, event.xconfigure.height);
                if(size != _viewportSize) {
                    _viewportSize = size;
                    viewportEvent(size);
                    _flags |= Flag::Redraw;
                }
            }
            break;

            /* Key/mouse events */
            case KeyPress:
            case KeyRelease: {
                KeyEvent e(static_cast<KeyEvent::Key>(XLookupKeysym(&event.xkey, 0)), static_cast<InputEvent::Modifier>(event.xkey.state), {event.xkey.x, event.xkey.y});
                event.type == KeyPress ? keyPressEvent(e) : keyReleaseEvent(e);
            }
            break;
            case ButtonPress:
            case ButtonRelease: {
                MouseEvent e(static_cast<MouseEvent::Button>(event.xbutton.button), static_cast<InputEvent::Modifier>(event.xkey.state), {event.xbutton.x, event.xbutton.y});
                event.type == ButtonPress ? mousePressEvent(e) : mouseReleaseEvent(e);
            }
            break;

            /* Mouse move events */
            case MotionNotify: {
                MouseMoveEvent e(static_cast<InputEvent::Modifier>(event.xmotion.state), {event.xmotion.x, event.xmotion.y});
                mouseMoveEvent(e);
            }
            break;
            }
        }

        if(_flags & Flag::Redraw) {
            _flags &= ~Flag::Redraw;
            drawEvent();
        } else Utility::sleep(5);
    }

    return 0;
}
//--------------------------------------------------------------------------------//
void WindowEventUtilities::messagePump()
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
	// Windows Message Loop (NULL means check all HWNDs belonging to this context)
	MSG  msg;
	while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
	{
		TranslateMessage( &msg );
		DispatchMessage( &msg );
	}
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
	//GLX Message Pump
	RenderWindowList::iterator win = _msWindows.begin();
	RenderWindowList::iterator end = _msWindows.end();

	Display* xDisplay = 0; // same for all windows
	
	for (; win != end; win++)
	{
	    XID xid;
	    XEvent event;

	    if (!xDisplay)
		(*win)->getCustomAttribute("XDISPLAY", &xDisplay);

	    (*win)->getCustomAttribute("WINDOW", &xid);

	    while (XCheckWindowEvent (xDisplay, xid, StructureNotifyMask | VisibilityChangeMask | FocusChangeMask, &event))
	    {
		GLXProc(*win, event);
	    }

	    // The ClientMessage event does not appear under any Event Mask
	    while (XCheckTypedWindowEvent (xDisplay, xid, ClientMessage, &event))
	    {
		GLXProc(*win, event);
	    }
	}
#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE && !defined __OBJC__ && !defined __LP64__
	// OSX Message Pump
	EventRef event = NULL;
	EventTargetRef targetWindow;
	targetWindow = GetEventDispatcherTarget();
    
    // If we are unable to get the target then we no longer care about events.
    if( !targetWindow ) return;
    
    // Grab the next event, process it if it is a window event
	while( ReceiveNextEvent( 0, NULL, kEventDurationNoWait, true, &event ) == noErr )
	{
        // Dispatch the event
		SendEventToEventTarget( event, targetWindow );
   		ReleaseEvent( event );
	}
#endif
}
Esempio n. 15
0
Bool
check_event_windowed (Window w, long event_mask,
											register XEvent * event_return)
{
	register int res;

	res = XCheckWindowEvent (dpy, w, event_mask, event_return);
	if (res)
		stash_event_time (event_return);
	return res;
}
Esempio n. 16
0
int gfx_event_waiting()
{
	XEvent event;

	if(XCheckWindowEvent(gfx_display,gfx_window,KeyPressMask|ButtonPressMask,&event)) {
		XPutBackEvent(gfx_display,&event);
		return 1;
	} else {
		return 0;
	}	
}
Esempio n. 17
0
int kbhit()
{
  XEvent xev;

  if (XCheckWindowEvent(dpy, win, KeyPressMask, &xev))
  {
    XPutBackEvent(dpy, &xev);
    return(1);
  }
  return(0);
}
bool GLWindow::GetEvent(Event &event)
{

  if (XPending(dpy)) {
    int keysyms_per_keycode_return;
    XEvent xev;

    // Keyboard Key Press (Keysym code available in /usr/include/X11/keysymdef.h)
    if (XCheckWindowEvent(dpy, glWin, KeyPressMask, &xev)) {
      event.type = TMGL_Press;
      KeySym ks = *XGetKeyboardMapping(dpy,xev.xkey.keycode,1,&keysyms_per_keycode_return);
      MapKey(ks, event.input);
    }
    // Keyboard Key Release (Keysym code available in /usr/include/X11/keysymdef.h)
    else if (XCheckWindowEvent(dpy, glWin, KeyReleaseMask, &xev)) {
      event.type = TMGL_Release;
      KeySym ks = *XGetKeyboardMapping(dpy,xev.xkey.keycode,1,&keysyms_per_keycode_return);
      MapKey(ks, event.input);
    }
    // Mouse Button Press
    else if (XCheckWindowEvent(dpy, glWin, ButtonPressMask, &xev)) {
      event.type = TMGL_Press;
      MapMouse(xev.xbutton.button, event.input);
      event.motion.x = xev.xmotion.x;
      event.motion.y = xev.xmotion.y;
    }
    // Mouse Button Release
    else if (XCheckWindowEvent(dpy, glWin, ButtonReleaseMask, &xev)) {
      event.type = TMGL_Release;
      MapMouse(xev.xbutton.button, event.input);
      event.motion.x = xev.xmotion.x;
      event.motion.y = xev.xmotion.y;
    }
    // Mouse Motion
    else if (XCheckWindowEvent(dpy, glWin, PointerMotionMask, &xev)) {
      event.type = TMGL_Motion;
      event.motion.x = xev.xmotion.x;
      event.motion.y = xev.xmotion.y;
    }
    // Window Exposure
    else if (XCheckWindowEvent(dpy, glWin, ExposureMask, &xev)) {
      XWindowAttributes gwa;
      event.type = TMGL_Expose;
      XGetWindowAttributes(dpy, glWin, &gwa);
      event.expose.width = gwa.width;
      event.expose.height = gwa.height;
    }
    // Quit button pressed
    else if (XCheckTypedEvent(dpy, ClientMessage, &xev)) {
      event.type = TMGL_Quit;
    }
    // Other Events
    else {
      return false;
    }

    return true;
  }
  return false;
}
Esempio n. 19
0
x_window_rep::~x_window_rep () {
  set_identifier (w, 0);

  XEvent report;
  while (XCheckWindowEvent (dpy, win, 0xffffffff, &report));

  tm_delete (ren);
  if (ic_ok) XDestroyIC (ic);
  Window_to_window->reset (win);
  nr_windows--;
  XDestroyWindow (dpy, win);
  gui->deleted_window (win);
}
Esempio n. 20
0
static se_key se_delayed_wait_key(se_text_xviewer* viewer)
{
    se_debug( "waiting for a key..." );    
    XEvent ev;
    while ( XCheckWindowEvent( viewer->env->display, viewer->view,
                               KeyPressMask, &ev ) == False ) {
        usleep( 100 );
    }

    /* g_assert( ev.type == KeyPress ); */
    se_debug( "wait for a key done" );
    return se_key_event_process( viewer->env->display, ev.xkey );
}
Esempio n. 21
0
void
awt_util_consumeAllXEvents(Widget widget)
{
    /* Remove all queued X Events for the window of the widget. */

#define ALL_EVENTS_MASK 0xFFFF

    XEvent xev;

    XFlush(awt_display);
    while (XCheckWindowEvent(awt_display, XtWindow(widget),
               ALL_EVENTS_MASK, &xev)) ;
}
Esempio n. 22
0
Bool wait_event (XEvent * event, Window w, int mask, int max_wait)
{
	int tick_count;

	start_ticker (1);
	/* now we have to wait for our window to become mapped - waiting for PropertyNotify */
	for (tick_count = 0;
			 !XCheckWindowEvent (dpy, w, mask, event) && tick_count < max_wait;
			 tick_count++) {
		XSync (dpy, False);
		wait_tick ();
	}
	return (tick_count < max_wait);
}
Esempio n. 23
0
static void eatExpose(void)
{
	XEvent event, foo;

	/* compress all expose events into a single one */

	if (XCheckMaskEvent(dpy, ExposureMask, &event)) {
		/* ignore other exposure events for this window */
		while (XCheckWindowEvent(dpy, event.xexpose.window, ExposureMask, &foo)) ;
		/* eat exposes for other windows */
		eatExpose();

		event.xexpose.count = 0;
		XPutBackEvent(dpy, &event);
	}
}
Esempio n. 24
0
/* call higher gr_redraw routine */
static void
redraw(Widget w, XtPointer client_data, XEvent *event, Boolean *continue_dispatch)
{
    GRAPH *graph = (GRAPH *) client_data;
    XExposeEvent *pev = & event->xexpose;
    XEvent ev;
    XRectangle rects[30];
    int n = 1;

    NG_IGNORE(w);
    NG_IGNORE(continue_dispatch);

    DEVDEP(graph).isopen = 1;

    rects[0].x = (Position) pev->x;
    rects[0].y = (Position) pev->y;
    rects[0].width  = (Dimension) pev->width;
    rects[0].height = (Dimension) pev->height;

    /* XXX */
    /* pull out all other expose regions that need to be redrawn */
    while (n < 30 && XCheckWindowEvent(display, DEVDEP(graph).window,
                                       ExposureMask, &ev)) {
        pev = (XExposeEvent *) &ev;
        rects[n].x = (Position) pev->x;
        rects[n].y = (Position) pev->y;
        rects[n].width  = (Dimension) pev->width;
        rects[n].height = (Dimension) pev->height;
        n++;
    }
    XSetClipRectangles(display, DEVDEP(graph).gc, 0, 0, rects, n, Unsorted);

    noclear = True;
    {
        GRAPH *tmp = currentgraph;
        currentgraph = graph;
        gr_redraw(graph);
        currentgraph = tmp;
    }
    noclear = False;

    XSetClipMask(display, DEVDEP(graph).gc, None);
}
Esempio n. 25
0
void placate_x()
{
  XEvent           event;
  XConfigureEvent *xce;
  XMotionEvent    *xme;
  XButtonEvent    *xbe;
    checkX;

  while(XCheckWindowEvent(dpy, win, EVENT_MASK, (XEvent *)&event))

    switch(event.type) {

    case ConfigureNotify:

      xce = (XConfigureEvent *)&event;
      screen_height = xce->height;
      screen_width  = xce->width;

      XClearWindow(dpy, win);
      /* if (!clearing_screen) */ redraw_graphics();

      break;

    case MotionNotify:

      xme = (XMotionEvent *)&event;
      x_mouse_x = xme->x;
      x_mouse_y = xme->y;
      break;

    case ButtonPress:
	xbe = (XButtonEvent *)&event;
#undef button
	x_buttondown = xbe->button;
	mouse_click;
	break;

    case ButtonRelease:
	x_buttondown = 0;
	break;
    }
}
Esempio n. 26
0
void GuiCalibratorX11::give_timer_signal()
{
    if (instance != NULL) {
        // timer signal

#ifdef HAVE_TIMERFD
        uint64_t missed;
        ssize_t ret;

        /* Wait for the next timer event. If we have missed any the
         * number is written to "missed" */
        ret = read(instance->timer_fd, &missed, sizeof (missed));
        if (ret == -1) {
        	fprintf(stderr, "failed reading timer");
        }
#endif

        //check timeout
        instance->on_timer_signal();

        // process events
        XEvent event;
        while (XCheckWindowEvent(instance->display, instance->win, -1, &event) == True) {
            switch (event.type) {
                case Expose:
                    // only draw the last contiguous expose
                    if (event.xexpose.count != 0)
                        break;
                    instance->on_expose_event();
                    break;

                case ButtonPress:
                    instance->on_button_press_event(event);
                    break;

                case KeyPress:
                    exit(0);
                    break;
            }
        }
    }
}
Esempio n. 27
0
void
resize(Widget w, caddr_t client_data, caddr_t call_data)
{

    GRAPH *graph = (GRAPH *) client_data;
    XEvent ev;

    /* pull out all other exposure events
       Also, get rid of other StructureNotify events on this window. */

    while (XCheckWindowEvent(display, DEVDEP(graph).window,
	    (long) /* ExposureMask | */ StructureNotifyMask, &ev))
	    ;

    XClearWindow(display, DEVDEP(graph).window);
    graph->absolute.width = w->core.width;
    graph->absolute.height = w->core.height;
    gr_resize(graph);

}
Esempio n. 28
0
void os_DoEvents()
{
  #if defined(SUPPORT_X11)
    if (x11_win)
    {
      //Handle X11
      XEvent e;

      if(XCheckWindowEvent((Display*)x11_disp, (Window)x11_win, KeyPressMask | KeyReleaseMask, &e))
      {
        switch(e.type)
        {
          case KeyPress:
          case KeyRelease:
          {
            int dc_key = x11_keymap[e.xkey.keycode];

            if (e.type == KeyPress)
            {
              x11_dc_buttons &= ~dc_key;
            }
            else
            {
              x11_dc_buttons |= dc_key;
            }

            //printf("KEY: %d -> %d: %d\n",e.xkey.keycode, dc_key, x11_dc_buttons );
          }
          break;


          {
            printf("KEYRELEASE\n");
          }
          break;

        }
      }
    }
  #endif
}
Esempio n. 29
0
/**
 * Check if new X11 event are arrived
 */
void Gi::CheckWindowEvents()
{
  int i;
  XEvent xev;
  // extern STAGE stage;
  //  extern int* order;
  int redrawn=0;
 
  while (XCheckWindowEvent(dpy, win, ExposureMask, &xev))
  {
    switch (xev.type)
    {
     case Expose:
       if (xev.xexpose.count > 0 || redrawn) // More exposures coming up:)
       {
         continue;
       }
 
       // We have requested backingstore, but if none such, and we have a
       // copy of the track, use that.
       // Redraw the whole she-bang :(
       XCopyArea(dpy, pixmap, win, gc, 0, 0, maxx, maxy, 0, 0); 
       draw.ScoreBoard(race_data.stage,0);
       draw.PrintLeaderboardHeader();
       for( i=0; i<args.m_iNumCar; i++ ) // Would like to know how many really...
       {
         draw.Leaders(i, race_data.m_aCarInPos);
       }
       // The cars will arrive shortly:)
       redrawn = 1;
       break;
     case KeyPress:
     case ButtonPress:
     default:
       // cout << "Unknown event " << xev.type << ".\n";
       break;
    }
  }
}
Esempio n. 30
0
File: xlib.c Progetto: jacereda/glcv
int cvrun(int argc, char ** argv) {
        int attr[] = {
                GLX_RGBA,
                GLX_DOUBLEBUFFER,
                GLX_RED_SIZE, 1,
                GLX_GREEN_SIZE, 1,
                GLX_BLUE_SIZE, 1,
                GLX_DEPTH_SIZE, 1,
                None};
        XVisualInfo * vi;
        g_dpy = XOpenDisplay(0);
        g_xim = XOpenIM(g_dpy, 0, 0, 0);
        cvInject(CVE_INIT, 0, 0);
        openwin(cvInject(CVQ_XPOS, 0, 0),
                cvInject(CVQ_YPOS, 0, 0),
                cvInject(CVQ_WIDTH, 0, 0),
                cvInject(CVQ_HEIGHT, 0, 0), 1);
        vi = glXChooseVisual(g_dpy, scr(), attr);
        g_ctx = glXCreateContext(g_dpy, vi, 0, True);
        XFree(vi);

        map();
        ((int(*)(int))glXGetProcAddress((GLubyte*)"glXSwapIntervalSGI"))(1);
        cvInject(CVE_GLINIT, 0, 0);
        while (!g_done) {
                XEvent e;
                if (XCheckWindowEvent(g_dpy, g_win, EVMASK, &e)
                    || XCheckTypedWindowEvent(g_dpy, g_win, ClientMessage, &e))
                        handle(g_dpy, g_win, g_xic, &e);
                glXSwapBuffers(g_dpy, g_win);
                cvInject(CVE_UPDATE, 0, 0);
        }
        cvInject(CVE_GLTERM, 0, 0);
                closewin();
                glXDestroyContext(g_dpy, g_ctx);
        XCloseIM(g_xim);
        XCloseDisplay(g_dpy);
        return cvInject(CVE_TERM, 0, 0);
}