Пример #1
0
void eventloop(void (*expose)(), void (*resize)(), void (*buttonpress)())
/* This is the main event loop */
{
   for(;;){
/* get events, use first to display text and graphics */
      XNextEvent(display, &report);
      switch  (report.type)
      {
         case Expose: handleExpose(expose); break;
         case ConfigureNotify: handleResize(resize);break;
         case ButtonPress: (*buttonpress)(); break;
         case KeyPress:
           /*****************************
           -- user stuff here for key press in window---
           e.g. exit program (note that, typing q in window exits)
           ******************************/
            XUnloadFont(display, font_info->fid);
            XFreeGC(display, drawgc);
            XCloseDisplay(display);
         default:
        /* all events selected by StructureNotifyMask
         * except ConfigureNotify are thrown away here,
         * since nothing is done with them */
            break;
      }
   }
}
Пример #2
0
int Kernel::run() {
    XEvent event;

    LOGDEBUG("main event loop launched");
    ostringstream oss;
    while (runlevel_ == Kernel::RUN) {

        XCORE->nextEvent(&event);
        switch (event.type) {
        case ButtonPress:
            LOGDEBUG("button press event");
            handleButtonPress(&event.xbutton);
            break;
        case ButtonRelease:
            LOGDEBUG("button release event");
            handleButtonRelease(&event.xbutton);
            break;
        case ClientMessage:
            LOGDEBUG("client message event");
            handleClientMessage(&event.xclient);
            break;
        case ConfigureRequest:
            LOGDEBUG("configure request event");
            handleConfigureRequest(&event.xconfigurerequest);
            break;
        case DestroyNotify:
            LOGDEBUG("destroy window event");
            handleDestroyNotify(&event.xdestroywindow);
            break;
        case Expose:
            LOGDEBUG("expose event");
            handleExpose(&event.xexpose);
            break;
        case KeyPress:
            LOGDEBUG("keypress event");
            handleKeyPress(&event.xkey);
            break;
        case MapRequest:
            LOGDEBUG("map request event");
            handleMapRequest(&event.xmaprequest);
            break;
        case MotionNotify:
            LOGDEBUG("motion event");
            handleMotionNotify(&event.xmotion);
            break;
        case PropertyNotify:
            LOGDEBUG("property event");
            handlePropertyNotify(&event.xproperty);
            break;
        case UnmapNotify:
            LOGDEBUG("unmap event");
            handleUnmapNotify(&event.xunmap);
            break;
        }

    }
    return 0;
}
Пример #3
0
void handleEvents(void)
/* This function can be called to handle events instead of entering
   the event loop. The calls must be frequent to ensure proper action.
*/
{
   while (XCheckMaskEvent(display, event_mask, &report))
   switch  (report.type)
   {
      case Expose: handleExpose(NULL);break;
      case ConfigureNotify: handleResize(NULL);break;
      case ButtonPress: buttonState=1;break;
      case ButtonRelease: buttonState=0;break;
      case KeyPress: lastKey=report.xkey.keycode;
      case MotionNotify:;
   }
}
Пример #4
0
Файл: test.c Проект: MayKeoN/ysh
int
main (int argc, char **argv)
{
   int done = 0;
   struct drawing canvas;
   struct window win;
   XEvent myevent;

   initialize (&canvas, &win, argc, argv);
   if (fractal_options.type == MANDELBROT)
      mandelbrot (&canvas, &win);
   else
      julia (&canvas, &win);

   while (!done)
   {
      XNextEvent (win.display, &myevent);
      switch (myevent.type)
      {
         case ButtonPress:
              handleButtonPress (&myevent, &canvas, &win);
              break;
         case Expose:
              handleExpose (&myevent, &canvas, &win);
              break;
         case MappingNotify:
              XRefreshKeyboardMapping ((XMappingEvent *) &myevent);
              break;
         case ReparentNotify:
              handleReparentNotify (&myevent, &win);
              break;
         case KeyPress:
              exit (EXIT_SUCCESS);
              break;
      }
   }
   XFreeGC (win.display, win.gc);
   XDestroyWindow (win.display, win.win);
   XCloseDisplay (win.display);
   return EXIT_SUCCESS;
}
Пример #5
0
void OpenGraphics(int hres, int vres, int bg_col, int fg_col, int ltx, int lty)
/* It opens and displays a graphic window with hres pixels in the horizontal
   direction and vres pixels in the vertical direction with bg_col as the
   background color and fg_col as the foreground color
*/
{
   char nulltxt='\0';
   char *nulltxtPtr=&nulltxt;

   if (isgraphic)
   {
      fontWdth=9;
      fontHght=15;

      opengfxwndw(2,hres,vres,bg_col,fg_col,1,&nulltxtPtr);
      myGraphic=1;

      do{
         XNextEvent(display, &report);
      }while (report.type != Expose);
      handleExpose(NULL);
   }
}
Пример #6
0
void X11WindowedBackend::handleEvent(xcb_generic_event_t *e)
{
    const uint8_t eventType = e->response_type & ~0x80;
    switch (eventType) {
    case XCB_BUTTON_PRESS:
    case XCB_BUTTON_RELEASE:
        handleButtonPress(reinterpret_cast<xcb_button_press_event_t*>(e));
        break;
    case XCB_MOTION_NOTIFY: {
            auto event = reinterpret_cast<xcb_motion_notify_event_t*>(e);
            auto it = std::find_if(m_windows.constBegin(), m_windows.constEnd(), [event] (const Output &o) { return o.window == event->event; });
            if (it == m_windows.constEnd()) {
                break;
            }
            pointerMotion(QPointF(event->root_x - (*it).xPosition.x() + (*it).internalPosition.x(),
                                  event->root_y - (*it).xPosition.y() + (*it).internalPosition.y()),
                          event->time);
        }
        break;
    case XCB_KEY_PRESS:
    case XCB_KEY_RELEASE: {
            auto event = reinterpret_cast<xcb_key_press_event_t*>(e);
            if (eventType == XCB_KEY_PRESS) {
                if (!m_keySymbols) {
                    m_keySymbols = xcb_key_symbols_alloc(m_connection);
                }
                const xcb_keysym_t kc = xcb_key_symbols_get_keysym(m_keySymbols, event->detail, 0);
                if (kc == XK_Control_R) {
                    grabKeyboard(event->time);
                }
                keyboardKeyPressed(event->detail - 8, event->time);
            } else {
                keyboardKeyReleased(event->detail - 8, event->time);
            }
        }
        break;
    case XCB_CONFIGURE_NOTIFY:
        updateSize(reinterpret_cast<xcb_configure_notify_event_t*>(e));
        break;
    case XCB_ENTER_NOTIFY: {
            auto event = reinterpret_cast<xcb_enter_notify_event_t*>(e);
            auto it = std::find_if(m_windows.constBegin(), m_windows.constEnd(), [event] (const Output &o) { return o.window == event->event; });
            if (it == m_windows.constEnd()) {
                break;
            }
            pointerMotion(QPointF(event->root_x - (*it).xPosition.x() + (*it).internalPosition.x(),
                                  event->root_y - (*it).xPosition.y() + (*it).internalPosition.y()),
                          event->time);
        }
        break;
    case XCB_CLIENT_MESSAGE:
        handleClientMessage(reinterpret_cast<xcb_client_message_event_t*>(e));
        break;
    case XCB_EXPOSE:
        handleExpose(reinterpret_cast<xcb_expose_event_t*>(e));
        break;
    case XCB_MAPPING_NOTIFY:
        if (m_keySymbols) {
            xcb_refresh_keyboard_mapping(m_keySymbols, reinterpret_cast<xcb_mapping_notify_event_t*>(e));
        }
        break;
    default:
        break;
    }
}