static void handle_event() { XEvent event; KeySym key; /* a dealie-bob to handle KeyPress Events */ char text[255]; /* a char buffer for KeyPress Events */ while (1) { while (!XPending(display)) { if (update) { update = 0; //XClearArea(display, win, 0, 0, emu_window_width, emu_window_height, 1); generateKrtImage(); redraw(); usleep(0x20000); } } XNextEvent(display, &event); #if DEBUG_MSG dbg_print_event(&event); #endif if (event.type == Expose && event.xexpose.count == 0) { redraw(); } if (event.type == KeyRelease) { lastKeyStroke = 0; } if (event.type == KeyPress) { int len = XLookupString(&event.xkey, text, 255, &key, 0); if (len > 0) { lastKeyStroke = text[0]; } else { /*TODO use mapping table*/ switch (key) { case XK_Left: lastKeyStroke = 0x08; break; case XK_Right: lastKeyStroke = 0x09; break; case XK_Up: lastKeyStroke = 0x0b; break; case XK_Down: lastKeyStroke = 0x0a; break; default: printf("umpapped key %lx->0x%x\n", key, lastKeyStroke); lastKeyStroke = 0; break; } } /*if (text[0] == 'q' || text[0] == 0x3) { break;*/ } if (event.type == ConfigureNotify) { int scaleX = event.xconfigurerequest.width / selected_model->pixel_width; int scaleY = event.xconfigurerequest.height / selected_model->pixel_height; int tmpScale = scaleX > scaleY ? scaleY : scaleX; scale = tmpScale ? tmpScale : 1; scale = scale > ZOOM_MAX ? ZOOM_MAX : scale; emu_window_width = selected_model->pixel_width * scale; emu_window_height = selected_model->pixel_height * scale; start_x = (event.xconfigurerequest.width - emu_window_width) / 2; start_y = (event.xconfigurerequest.height - emu_window_height) / 2; } if (event.type == ClientMessage) { /* TODO erledigen wir später, test ob auch wirklich das Fester geschlossen werden soll * if (event.xclient.data.l[0] == wmDeleteWindow) { global.done = 1; } */ break; } if (event.type == ButtonPress) { cursorFromX = (event.xbutton.x - start_x) / getCharacterWidth(); cursorFromY = (event.xbutton.y - start_y) / getCharacterHeight(); selectText = 1; } if (event.type == ButtonRelease) { selectText = 0; XSetSelectionOwner(display, XA_PRIMARY, win, CurrentTime); redraw(); } if (event.type == MotionNotify) { cursorToX = (event.xmotion.x - start_x) / getCharacterWidth(); cursorToY = (event.xmotion.y - start_y) / getCharacterHeight(); cursorToX = cursorToX < 0 ? 0 : cursorToX; cursorToY = cursorToY < 0 ? 0 : cursorToY; cursorToX = cursorToX >= selected_model->text_width ? selected_model->text_width : cursorToX; cursorToY = cursorToY >= selected_model->text_height ? selected_model->text_height - 1 : cursorToY; printf("mark (%d,%d) (%d,%d)\n", cursorFromX, cursorFromY, cursorToX, cursorToY); redraw(); } if (event.type == SelectionRequest) { handleSelectionRequest(event.xselectionrequest); } } }
bool QXlibScreen::handleEvent(XEvent *xe) { int quit = false; QXlibWindow *platformWindow = 0; QWidget *widget = QWidget::find(xe->xany.window); if (widget) { platformWindow = static_cast<QXlibWindow *>(widget->platformWindow()); } Atom wmProtocolsAtom = QXlibStatic::atom(QXlibStatic::WM_PROTOCOLS); Atom wmDeleteWindowAtom = QXlibStatic::atom(QXlibStatic::WM_DELETE_WINDOW); switch (xe->type) { case ClientMessage: if (xe->xclient.format == 32 && xe->xclient.message_type == wmProtocolsAtom) { Atom a = xe->xclient.data.l[0]; if (a == wmDeleteWindowAtom) platformWindow->handleCloseEvent(); } break; case Expose: if (platformWindow) if (xe->xexpose.count == 0) platformWindow->paintEvent(); break; case ConfigureNotify: if (platformWindow) platformWindow->resizeEvent(&xe->xconfigure); break; case ButtonPress: if (platformWindow) platformWindow->mousePressEvent(&xe->xbutton); break; case ButtonRelease: if (platformWindow) platformWindow->handleMouseEvent(QEvent::MouseButtonRelease, &xe->xbutton); break; case MotionNotify: if (platformWindow) platformWindow->handleMouseEvent(QEvent::MouseMove, &xe->xbutton); break; case XKeyPress: mKeyboard->handleKeyEvent(widget,QEvent::KeyPress, &xe->xkey); break; case XKeyRelease: mKeyboard->handleKeyEvent(widget,QEvent::KeyRelease, &xe->xkey); break; case EnterNotify: if (platformWindow) platformWindow->handleEnterEvent(); break; case LeaveNotify: if (platformWindow) platformWindow->handleLeaveEvent(); break; case XFocusIn: if (platformWindow) platformWindow->handleFocusInEvent(); break; case XFocusOut: if (platformWindow) platformWindow->handleFocusOutEvent(); break; case PropertyNotify: break; case SelectionClear: qDebug() << "Selection Clear!!!"; break; case SelectionRequest: handleSelectionRequest(xe); break; case SelectionNotify: qDebug() << "Selection Notify!!!!"; break; default: #ifdef MYX11_DEBUG qDebug() << hex << xe->xany.window << "Other X event" << xe->type; #endif break; } return quit; }