Example #1
0
int DrawWindow (void (*DrawWindowContent) (), int (*KeyPressFunction) (int))
{
    XEvent Event;
    XWindowAttributes Attr;
    KeySym nKeySym;
    int nDepth;
    
    if ((prDisplay = XOpenDisplay(0)) == 0) return 1;
    
    nScreenNum = DefaultScreen(prDisplay);
    nWnd = XCreateSimpleWindow(prDisplay,
    RootWindow(prDisplay,nScreenNum),XPos,YPos,WDef,HDef,WBorder,BlackPixel(prDisplay,nScreenNum),WhitePixel(prDisplay,nScreenNum));
    if (SetWindowManagerHints(prDisplay,PClass,nWnd,WMin,HMin,WTitle,WITitle,0)) return 2;
    XSelectInput(prDisplay, nWnd, ExposureMask | KeyPressMask);
    XMapWindow(prDisplay, nWnd);
    
    prGC = XCreateGC(prDisplay, nWnd, 0, 0);
    if (AllocColors(prDisplay, DefaultColormap(prDisplay, nScreenNum), &rColors)) return 3; 
    if (CreateBitmaps(prDisplay, nWnd, prPixmap)) return 4; 
    if (XGetWindowAttributes(prDisplay, nWnd, &Attr))
    {
	nWWidth = Attr.width;
	nWHeight = Attr.height;
	nDepth = Attr.depth;
    }
    else return 5;
    
    draw = XCreatePixmap(prDisplay, nWnd, nWWidth, nWHeight, nDepth);
    if (!draw) return 4;
    
    // message cycle
    while (true)
    {
	XNextEvent (prDisplay, &Event);
	switch (Event.type)
	{
	case Expose:
//	if (!
	HandleExpose(DrawWindowContent, Event, Attr, nDepth);
//	) return 5; break;
break;
	case KeyPress: if (HandleKeyPress(KeyPressFunction, Event, nKeySym)) return 0; break;
	}
	while (XCheckMaskEvent(prDisplay, KeyPressMask | KeyReleaseMask, &Event));
    }
    return 0;
}
Example #2
0
void MenuExpose(XEvent *event)
{
  Menu *mc;
  MenuItem *mi;

  if(event->xexpose.count) return;
  if(!XFindContext(disp, event->xexpose.window, TheScreen.MenuContext,
                   (XPointer *)&mi)) {
    DrawItem(mi, 0);
    return;
  }
  if(!XFindContext(disp, event->xexpose.window, TheScreen.MenuFrameContext,
                   (XPointer *)&mc)) {
    DrawMenuFrame(mc, 0);
    return;
  }
  HandleExpose(event);
}
Example #3
0
void Widget::Expose( CullingTarget& target ) const {
	if( m_invalidated ) {
		m_invalidated = false;

		m_drawable.reset( InvalidateImpl() );

		if( m_drawable ) {
			m_drawable->SetPosition( GetAbsolutePosition() );
		}
	}

	if( IsVisible() ) {
		if( m_drawable ) {
			target.Draw( *m_drawable );
		}

		HandleExpose( target );
		OnExpose();
	}
}
Example #4
0
/*
 * entry point for the background thread
 */
wxThread::ExitCode WorkerThread::Entry()
{
    bool bDone = TestDestroy();

    Debug.AddLine("WorkerThread::Entry() begins");

#if defined(__WINDOWS__)
    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    Debug.AddLine("worker thread CoInitializeEx returns %x", hr);
#endif

    while (!bDone)
    {
        WORKER_THREAD_REQUEST message;
        bool dummy;
        wxMessageQueueError queueError = m_wakeupQueue.Receive(dummy);

        Debug.AddLine("Worker thread wakes up");

        assert(queueError == wxMSGQUEUE_NO_ERROR);

        queueError = m_highPriorityQueue.ReceiveTimeout(0, message);

        if (queueError == wxMSGQUEUE_TIMEOUT)
        {
            queueError = m_lowPriorityQueue.ReceiveTimeout(0, message);
            assert(queueError != wxMSGQUEUE_TIMEOUT);
        }

        assert(queueError == wxMSGQUEUE_NO_ERROR);

        switch(message.request)
        {
            bool bError;

            case REQUEST_NONE:
                Debug.AddLine("worker thread servicing REQUEST_NONE");
                break;
            case REQUEST_TERMINATE:
                Debug.AddLine("worker thread servicing REQUEST_TERMINATE");
                bDone = true;
                break;
            case REQUEST_EXPOSE:
                Debug.AddLine("worker thread servicing REQUEST_EXPOSE %d",
                    message.args.expose.exposureDuration);
                bError = HandleExpose(&message.args.expose);
                SendWorkerThreadExposeComplete(message.args.expose.pImage, bError);
                break;
            case REQUEST_MOVE: {
                Debug.AddLine(wxString::Format("worker thread servicing REQUEST_MOVE %s dir %d (%.2f, %.2f)",
                    message.args.move.pMount->GetMountClassName(), message.args.move.direction,
                    message.args.move.vectorEndpoint.X, message.args.move.vectorEndpoint.Y));
                Mount::MOVE_RESULT moveResult = HandleMove(&message.args.move);
                SendWorkerThreadMoveComplete(message.args.move.pMount, moveResult);
                break;
            }
            default:
                Debug.AddLine("worker thread servicing unknown request %d", message.request);
                break;
        }

        Debug.AddLine("worker thread done servicing request");
        bDone |= TestDestroy();
    }

    Debug.AddLine("WorkerThread::Entry() ends");
    Debug.Flush();

    return (wxThread::ExitCode)0;
}
Example #5
0
/** Wait for an event and process it. */
char WaitForEvent(XEvent *event)
{
   struct timeval timeout;
   CallbackNode *cp;
   fd_set fds;
   long sleepTime;
   int fd;
   char handled;

#ifdef ConnectionNumber
   fd = ConnectionNumber(display);
#else
   fd = JXConnectionNumber(display);
#endif

   /* Compute how long we should sleep. */
   sleepTime = 10 * 1000;  /* 10 seconds. */
   for(cp = callbacks; cp; cp = cp->next) {
      if(cp->freq > 0 && cp->freq < sleepTime) {
         sleepTime = cp->freq;
      }
   }

   do {

      if(restack_pending) {
         RestackClients();
         restack_pending = 0;
      }
      if(task_update_pending) {
         UpdateTaskBar();
         task_update_pending = 0;
      }
      if(pager_update_pending) {
         UpdatePager();
         pager_update_pending = 0;
      }

      while(JXPending(display) == 0) {
         FD_ZERO(&fds);
         FD_SET(fd, &fds);
         timeout.tv_sec = sleepTime / 1000;
         timeout.tv_usec = (sleepTime % 1000) * 1000;
         if(select(fd + 1, &fds, NULL, NULL, &timeout) <= 0) {
            Signal();
         }
         if(JUNLIKELY(shouldExit)) {
            return 0;
         }
      }

      Signal();

      JXNextEvent(display, event);
      UpdateTime(event);

      switch(event->type) {
      case ConfigureRequest:
         HandleConfigureRequest(&event->xconfigurerequest);
         handled = 1;
         break;
      case MapRequest:
         HandleMapRequest(&event->xmap);
         handled = 1;
         break;
      case PropertyNotify:
         handled = HandlePropertyNotify(&event->xproperty);
         break;
      case ClientMessage:
         HandleClientMessage(&event->xclient);
         handled = 1;
         break;
      case UnmapNotify:
         HandleUnmapNotify(&event->xunmap);
         handled = 1;
         break;
      case Expose:
         handled = HandleExpose(&event->xexpose);
         break;
      case ColormapNotify:
         HandleColormapChange(&event->xcolormap);
         handled = 1;
         break;
      case DestroyNotify:
         handled = HandleDestroyNotify(&event->xdestroywindow);
         break;
      case SelectionClear:
         handled = HandleSelectionClear(&event->xselectionclear);
         break;
      case ResizeRequest:
         handled = HandleDockResizeRequest(&event->xresizerequest);
         break;
      case MotionNotify:
         SetMousePosition(event->xmotion.x_root, event->xmotion.y_root,
                          event->xmotion.window);
         handled = 0;
         break;
      case ButtonPress:
      case ButtonRelease:
         SetMousePosition(event->xbutton.x_root, event->xbutton.y_root,
                          event->xbutton.window);
         handled = 0;
         break;
      case EnterNotify:
         SetMousePosition(event->xcrossing.x_root, event->xcrossing.y_root,
                          event->xcrossing.window);
         handled = 0;
         break;
      case LeaveNotify:
         SetMousePosition(event->xcrossing.x_root, event->xcrossing.y_root,
                          None);
         handled = 0;
         break;
      case ReparentNotify:
         HandleDockReparentNotify(&event->xreparent);
         handled = 1;
         break;
      case ConfigureNotify:
         handled = HandleConfigureNotify(&event->xconfigure);
         break;
      case CreateNotify:
      case MapNotify:
      case GraphicsExpose:
      case NoExpose:
         handled = 1;
         break;
      default:
         if(0) {
#ifdef USE_SHAPE
         } else if(haveShape && event->type == shapeEvent) {
            HandleShapeEvent((XShapeEvent*)event);
            handled = 1;
#endif
         } else {
            handled = 0;
         }
         break;
      }

      if(!handled) {
         handled = ProcessTrayEvent(event);
      }
      if(!handled) {
         handled = ProcessDialogEvent(event);
      }
      if(!handled) {
         handled = ProcessSwallowEvent(event);
      }
      if(!handled) {
         handled = ProcessPopupEvent(event);
      }

   } while(handled && JLIKELY(!shouldExit));

   return !handled;

}
Example #6
0
/** Wait for an event and process it. */
void WaitForEvent(XEvent *event) {

   struct timeval timeout;
   fd_set fds;
   int fd;
   int handled;

   fd = JXConnectionNumber(display);

   do {

      while(JXPending(display) == 0) {
         FD_ZERO(&fds);
         FD_SET(fd, &fds);
         timeout.tv_usec = 0;
         timeout.tv_sec = 1;
         if(select(fd + 1, &fds, NULL, NULL, &timeout) <= 0) {
            Signal();
         }
      }

      Signal();

      JXNextEvent(display, event);

      switch(event->type) {
      case ConfigureRequest:
         HandleConfigureRequest(&event->xconfigurerequest);
         handled = 1;
         break;
      case MapRequest:
         HandleMapRequest(&event->xmap);
         handled = 1;
         break;
      case PropertyNotify:
         handled = HandlePropertyNotify(&event->xproperty);
         break;
      case ClientMessage:
         HandleClientMessage(&event->xclient);
         handled = 1;
         break;
      case UnmapNotify:
         HandleUnmapNotify(&event->xunmap);
         handled = 1;
         break;
      case Expose:
         handled = HandleExpose(&event->xexpose);
         break;
      case ColormapNotify:
         HandleColormapChange(&event->xcolormap);
         handled = 1;
         break;
      case DestroyNotify:
         handled = HandleDestroyNotify(&event->xdestroywindow);
         break;
      case SelectionClear:
         handled = HandleSelectionClear(&event->xselectionclear);
         break;
      case ResizeRequest:
         handled = HandleDockResizeRequest(&event->xresizerequest);
         break;
      case MotionNotify:
         SetMousePosition(event->xmotion.x_root, event->xmotion.y_root);
         handled = 0;
         break;
      case ReparentNotify:
         HandleDockReparentNotify(&event->xreparent);
         handled = 1;
         break;
      case ConfigureNotify:
         handled = 0;
         break;
      case CreateNotify:
      case MapNotify:
      case GraphicsExpose:
      case NoExpose:
         handled = 1;
         break;
      default:
#ifdef USE_SHAPE
         if(haveShape && event->type == shapeEvent) {
            HandleShapeEvent((XShapeEvent*)event);
            handled = 1;
         } else {
            handled = 0;
         }
#else
         handled = 0;
#endif
         break;
      }

      if(!handled) {
         handled = ProcessTrayEvent(event);
      }
      if(!handled) {
         handled = ProcessDialogEvent(event);
      }
      if(!handled) {
         handled = ProcessSwallowEvent(event);
      }
      if(!handled) {
         handled = ProcessPopupEvent(event);
      }

   } while(handled && !shouldExit);

}