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; }
int main() { trace_puts(">>> VfdClock main() init"); initGpio(); initRtc(); initTimer(); initUart(); SysTick_Config(72000); // 1kHz trace_puts("<<< VfdClock main() init"); GPIO_WriteBit(LED_PORT, LED_PIN, RESET); // Disable buzzer. GPIO_WriteBit(BUZ_PORT, BUZ_PIN, RESET); TIM_Cmd(TIM3, DISABLE); backupLoad(); uint8_t digits[6] = { DIGIT_BLANK, DIGIT_DASH, DIGIT_DASH, DIGIT_DASH, DIGIT_DASH, DIGIT_BLANK}; setDisplay(digits); gSeconds = RTC_GetCounter(); time_t localtime; struct tm *t = gmtime(&gSeconds); // Logic loop. while (1) { // Read GPS data, if it exists. if (strlen(gGpsLine) > 0) { handleGpsLine(); } else if (gGpsNextPoll < gSeconds) { gpsSetPushFreq("ZDA", 2); } handleDigits(digits, t); handleButtonPress(); if (gSecondFlag) { gSecondFlag = 0; localtime = gSeconds + gUtcOffset; t = gmtime(&localtime); handleDigits(digits, t); setDisplay(digits); // Blink decimal point. GPIO_WriteBit(DP_PORT, DP_PIN, SET); gDpTick = 500; } } }
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; }
void EventsHandler::Run() { XSelectInput(mShared.display, mShared.RootWindow, SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask |EnterWindowMask|LeaveWindowMask|StructureNotifyMask|PropertyChangeMask|KeyPressMask); while (isRunning) { XNextEvent(mShared.display, &event); RunHandlers(); std::cout << event.type << std::endl; //std::cout << "ConfigureRequest is " << ConfigureRequest << std::endl; //std::cout << "RootWindow:" << mShared.RootWindow << std::endl; switch (event.type) { case Expose: break; case ConfigureRequest: break; case KeyPress: handleKeyPress(&event); break; case ButtonPress: handleButtonPress(&event); break; case MotionNotify: handleMotion(&event); break; default: //std::cout << event.type << std::endl; break; } } XCloseDisplay(mShared.display); }
int main(int argc, char **argv) { AppInfo app; XEvent event; memset(&app, 0, sizeof(app)); progclass = "SshAskpass"; app.toplevelShell = XtAppInitialize(&(app.appContext), progclass, NULL, 0, &argc, argv, defaults, NULL, 0); app.argc = argc; app.argv = argv; app.dpy = XtDisplay(app.toplevelShell); app.screen = DefaultScreenOfDisplay(app.dpy); app.rootWindow = RootWindowOfScreen(app.screen); app.black = BlackPixel(app.dpy, DefaultScreen(app.dpy)); app.white = WhitePixel(app.dpy, DefaultScreen(app.dpy)); app.colormap = DefaultColormapOfScreen(app.screen); app.resourceDb = XtDatabase(app.dpy); XtGetApplicationNameAndClass(app.dpy, &progname, &progclass); app.appName = progname; app.appClass = progclass; /* For resources.c. */ db = app.resourceDb; /* Seconds after which keyboard/pointer grab fail. */ app.grabFailTimeout = 5; /* Number of seconds to wait between grab attempts. */ app.grabRetryInterval = 1; app.pid = getpid(); { struct rlimit resourceLimit; int status; status = getrlimit(RLIMIT_CORE, &resourceLimit); if (-1 == status) { fprintf(stderr, "%s[%ld]: getrlimit failed (%s)\n", app.appName, (long) app.pid, strerror(errno)); exit(EXIT_STATUS_ERROR); } resourceLimit.rlim_cur = 0; status = setrlimit(RLIMIT_CORE, &resourceLimit); if (-1 == status) { fprintf(stderr, "%s[%ld]: setrlimit failed (%s)\n", app.appName, (long) app.pid, strerror(errno)); exit(EXIT_STATUS_ERROR); } } app.xResolution = WidthOfScreen(app.screen) * 1000 / WidthMMOfScreen(app.screen); app.yResolution = HeightOfScreen(app.screen) * 1000 / HeightMMOfScreen(app.screen); createDialog(&app); createGCs(&app); app.eventMask = 0; app.eventMask |= ExposureMask; app.eventMask |= ButtonPressMask; app.eventMask |= ButtonReleaseMask; app.eventMask |= Button1MotionMask; app.eventMask |= KeyPressMask; createDialogWindow(&app); XMapWindow(app.dpy, app.dialog->dialogWindow); if (app.inputTimeout > 0) { app.inputTimeoutActive = True; app.inputTimeoutTimerId = XtAppAddTimeOut(app.appContext, app.inputTimeout, handleInputTimeout, (XtPointer) &app); } while(True) { XtAppNextEvent(app.appContext, &event); switch (event.type) { case Expose: grabServer(&app); grabKeyboard(&app); grabPointer(&app); if (event.xexpose.count) { break; } paintDialog(&app); break; case ButtonPress: case ButtonRelease: handleButtonPress(&app, &event); break; case MotionNotify: handlePointerMotion(&app, &event); case KeyPress: handleKeyPress(&app, &event); break; case ClientMessage: if ((32 == event.xclient.format) && ((unsigned long) event.xclient.data.l[0] == app.wmDeleteWindowAtom)) { cancelAction(&app); } break; default: break; } } fprintf(stderr, "%s[%ld]: This should not happen.\n", app.appName, (long) app.pid); return(EXIT_STATUS_ANOMALY); }
void GUI::createEffectBox() { // ------------------------------------------------- // | Position | PosX | PosY | PosZ | Random | row 0 // | Value | Slider-Slider-Slider | Value | row 1 // | EffectGravity | | EffectWind | row 2 // ------------------------------------------------- // col0 col1 col2 col 3 col4 // A Groupbox that will group all of the Source-related widgets in one box QGroupBox* effectBox = new QGroupBox("Effect"); QGridLayout* boxLayout = new QGridLayout; // Setting the position of the new Source QLabel* positionText = new QLabel("Position"); boxLayout->addWidget(positionText, 0, 0, 1, 1); // A validator that allows only floating point numbers in [-1,1] to be entered QValidator* validator = new QDoubleValidator(-1.0, 1.0, 6); // The textbox that holds the x component of the position _effectPositionXText = new QLineEdit; _effectPositionXText->setValidator(validator); _effectPositionXText->setFixedWidth(65); boxLayout->addWidget(_effectPositionXText, 0, 1, 1, 1); // The textbox that holds the y component of the position _effectPositionYText = new QLineEdit; _effectPositionYText->setValidator(validator); _effectPositionYText->setFixedWidth(65); boxLayout->addWidget(_effectPositionYText, 0, 2, 1, 1); // The textbox that holds the z component of the position _effectPositionZText = new QLineEdit; _effectPositionZText->setValidator(validator); _effectPositionZText->setFixedWidth(65); boxLayout->addWidget(_effectPositionZText, 0, 3, 1, 1); // A checkbox that will disable the manual entries and generate random positions _effectPositionRandomize = new QCheckBox("Randomize"); _effectPositionRandomize->setChecked(true); connect(_effectPositionRandomize, SIGNAL(toggled(bool)), this, SLOT(handleEffectRandomize())); boxLayout->addWidget(_effectPositionRandomize, 0, 4, 1, 1); // A slider that is used to choose a value in [0,1] that can be used for whatever effect QLabel* valueText = new QLabel("Value"); boxLayout->addWidget(valueText, 1, 0, 1, 1); // A slider that is used to choose a value in [0,1] that can be used for whatever effect _effectValueSlider = new QSlider; _effectValueSlider->setOrientation(Qt::Horizontal); _effectValueSlider->setMaximum(2000); _effectValueSlider->setValue(2000/2); connect(_effectValueSlider, SIGNAL(valueChanged(int)), this, SLOT(handleEffectSlider())); boxLayout->addWidget(_effectValueSlider, 1, 1, 1, 3); // This label will display the value that was chosen with the slider _effectLabel = new QLabel; _effectLabel->setFixedWidth(65); _effectLabel->setAlignment(Qt::AlignHCenter); boxLayout->addWidget(_effectLabel, 1, 4, 1, 1); // The button that will call the callback '_effectAddedCallback' with Effect::Gravity when pressed _effectGravityButton = new QPushButton("Effects Gravity"); connect(_effectGravityButton, SIGNAL(pressed()), this, SLOT(handleButtonPress())); boxLayout->addWidget(_effectGravityButton, 2, 0, 1, 2); // The button that will call the callback '_effectAddedCallback' with Effect::Wind when pressed _effectWindButton = new QPushButton("Effects Wind"); connect(_effectWindButton, SIGNAL(pressed()), this, SLOT(handleButtonPress())); boxLayout->addWidget(_effectWindButton, 2, 3, 1, 2); effectBox->setLayout(boxLayout); _layout->addWidget(effectBox, 1, 1, 1, 1); // Update the text fields according to the randomize default value handleEffectRandomize(); // Update the label value to the default slider value handleEffectSlider(); }
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; } }