bool AppFrontend::Process() { if(!IsRunning()) return false; #if CE_FRONTEND_USEXLIB #if CE_FRONTEND_USEXCB xcb_generic_event_t *xcbEvent; xcb_window_t xcbWindow; while((xcbEvent = xcb_poll_for_event((xcb_connection_t *)m_xcbConnection))) { Event event; event.base.timeMS = GetRunTimeMS(); event.base.canvas = 0; switch(xcbEvent->response_type & ~0x80) { case XCB_CLIENT_MESSAGE: if((*(xcb_client_message_event_t*)xcbEvent).data.data32[0] == m_wmDeleteMessage) return Stop(); break; case XCB_DESTROY_NOTIFY: case XCB_UNMAP_NOTIFY: return Stop(true); case XCB_KEY_PRESS: { xcb_button_press_event_t *cast = (xcb_button_press_event_t *)xcbEvent; event.type = event::KeyDown; xcbWindow = cast->event; if(m_canvasMap.count(xcbWindow)) event.base.canvas = m_canvasMap[xcbWindow]; event.key.scanCode = NativeScanCodeToScanCode(cast->detail); event.key.keyCode = ScanCodeToKeyCode(event.key.scanCode); event.key.state = cast->state; OnEvent(event); break; } case XCB_KEY_RELEASE: { xcb_key_release_event_t *cast = (xcb_key_release_event_t *)xcbEvent; event.type = event::KeyUp; xcbWindow = cast->event; if(m_canvasMap.count(xcbWindow)) event.base.canvas = m_canvasMap[xcbWindow]; event.key.scanCode = NativeScanCodeToScanCode(cast->detail); event.key.keyCode = ScanCodeToKeyCode(event.key.scanCode); event.key.state = cast->state; OnEvent(event); break; } case XCB_BUTTON_PRESS: { xcb_button_release_event_t *cast = (xcb_button_release_event_t *)xcbEvent; event.type = event::MouseButtonDown; xcbWindow = cast->event; if(m_canvasMap.count(xcbWindow)) event.base.canvas = m_canvasMap[xcbWindow]; switch(cast->detail) { case 1: event.mouseButton.button = event::MouseButtonLeft; break; case 2: event.mouseButton.button = event::MouseButtonMiddle; break; case 3: event.mouseButton.button = event::MouseButtonRight; break; default: event.mouseButton.button = event::Unknown; } event.mouseButton.state = cast->state; event.mouseButton.x = cast->event_x; event.mouseButton.y = cast->event_y; OnEvent(event); break; } case XCB_BUTTON_RELEASE: { xcb_button_release_event_t *cast = (xcb_button_release_event_t *)xcbEvent; event.type = event::MouseButtonUp; xcbWindow = cast->event; if(m_canvasMap.count(xcbWindow)) event.base.canvas = m_canvasMap[xcbWindow]; switch(cast->detail) { case 1: event.mouseButton.button = event::MouseButtonLeft; break; case 2: event.mouseButton.button = event::MouseButtonMiddle; break; case 3: event.mouseButton.button = event::MouseButtonRight; break; default: event.mouseButton.button = event::Unknown; } event.mouseButton.state = cast->state; event.mouseButton.x = cast->event_x; event.mouseButton.y = cast->event_y; OnEvent(event); break; } case XCB_MOTION_NOTIFY: { xcb_motion_notify_event_t *cast = (xcb_motion_notify_event_t *)xcbEvent; event.type = event::MouseMotion; xcbWindow = cast->event; if(m_canvasMap.count(xcbWindow)) event.base.canvas = m_canvasMap[xcbWindow]; event.mouseMotion.x = cast->event_x; event.mouseMotion.y = cast->event_y; OnEvent(event); break; } case XCB_CONFIGURE_NOTIFY: { xcb_configure_notify_event_t *cast = (xcb_configure_notify_event_t *)xcbEvent; xcbWindow = cast->event; if(m_canvasMap.count(xcbWindow)) event.base.canvas = m_canvasMap[xcbWindow]; if(cast->width != event.base.canvas->GetWidth() || cast->height != event.base.canvas->GetHeight()) { event.base.canvas->UpdateViewport(cast->width, cast->height); event.type = event::WindowResize; event.windowResize.width = cast->width; event.windowResize.height = cast->height; OnEvent(event); } break; } default: break; } free(xcbEvent); } #else while(XPending((Display *)m_xDisplay)) { XEvent xEvent; XNextEvent((Display *)m_xDisplay, &xEvent); Window xWindow = xEvent.xany.window; Event event; event.base.timeMS = GetRunTimeMS(); event.base.canvas = 0; if(m_canvasMap.count(xWindow)) event.base.canvas = m_canvasMap[xWindow]; switch(xEvent.type) { case ClientMessage: if(xEvent.xclient.data.l[0] == m_wmDeleteMessage) return Stop(); break; case DestroyNotify: case UnmapNotify: return Stop(true); case KeyPress: event.type = event::KeyDown; event.key.scanCode = NativeScanCodeToScanCode(xEvent.xkey.keycode); event.key.keyCode = ScanCodeToKeyCode(event.key.scanCode); event.key.state = xEvent.xkey.state; OnEvent(event); break; case KeyRelease: event.type = event::KeyUp; event.key.scanCode = NativeScanCodeToScanCode(xEvent.xkey.keycode); event.key.keyCode = ScanCodeToKeyCode(event.key.scanCode); event.key.state = xEvent.xkey.state; OnEvent(event); break;; case ButtonPress: event.mouseButton.type = event::MouseButtonDown; switch(xEvent.xbutton.button) { case 1: event.mouseButton.button = event::MouseButtonLeft; break; case 2: event.mouseButton.button = event::MouseButtonMiddle; break; case 3: event.mouseButton.button = event::MouseButtonRight; break; default: event.mouseButton.button = event::Unknown; } event.mouseButton.state = xEvent.xbutton.state; event.mouseButton.x = xEvent.xbutton.x; event.mouseButton.y = xEvent.xbutton.y; OnEvent(event); break; case ButtonRelease: event.mouseButton.type = event::MouseButtonUp; switch(xEvent.xbutton.button) { case 1: event.mouseButton.button = event::MouseButtonLeft; break; case 2: event.mouseButton.button = event::MouseButtonMiddle; break; case 3: event.mouseButton.button = event::MouseButtonRight; break; default: event.mouseButton.button = event::Unknown; } event.mouseButton.state = xEvent.xbutton.state; event.mouseButton.x = xEvent.xbutton.x; event.mouseButton.y = xEvent.xbutton.y; OnEvent(event); break; case MotionNotify: event.type = event::MouseMotion; event.mouseMotion.x = xEvent.xmotion.x; event.mouseMotion.y = xEvent.xmotion.y; OnEvent(event); break; case ConfigureNotify: if(xEvent.xconfigure.width != event.base.canvas->GetWidth() || xEvent.xconfigure.height != event.base.canvas->GetHeight()) { event.base.canvas->UpdateViewport(xEvent.xconfigure.width, xEvent.xconfigure.height); event.type = event::WindowResize; event.windowResize.width = xEvent.xconfigure.width; event.windowResize.height = xEvent.xconfigure.height; OnEvent(event); } break; } } #endif #endif #if CE_FRONTEND_USEWIN MSG wMsg; while(PeekMessage(&wMsg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&wMsg); DispatchMessage(&wMsg); } #endif #if CE_FRONTEND_USEXLIB map<int, Canvas *>::iterator it; #endif #if CE_FRONTEND_USEWIN map<void *, Canvas *>::iterator it; #endif for(it = m_canvasMap.begin(); it != m_canvasMap.end(); it++) it->second->Render(); return App::Process(); }
PuglStatus puglProcessEvents(PuglView* view) { XEvent event; while (XPending(view->impl->display) > 0) { XNextEvent(view->impl->display, &event); switch (event.type) { case MapNotify: puglReshape(view, view->width, view->height); break; case ConfigureNotify: if ((event.xconfigure.width != view->width) || (event.xconfigure.height != view->height)) { puglReshape(view, event.xconfigure.width, event.xconfigure.height); } break; case Expose: if (event.xexpose.count != 0) { break; } puglDisplay(view); break; case MotionNotify: setModifiers(view, event.xmotion.state, event.xmotion.time); if (view->motionFunc) { view->motionFunc(view, event.xmotion.x, event.xmotion.y); } break; case ButtonPress: setModifiers(view, event.xbutton.state, event.xbutton.time); if (event.xbutton.button >= 4 && event.xbutton.button <= 7) { if (view->scrollFunc) { float dx = 0, dy = 0; switch (event.xbutton.button) { case 4: dy = 1.0f; break; case 5: dy = -1.0f; break; case 6: dx = -1.0f; break; case 7: dx = 1.0f; break; } view->scrollFunc(view, dx, dy); } break; } // nobreak case ButtonRelease: setModifiers(view, event.xbutton.state, event.xbutton.time); if (view->mouseFunc && (event.xbutton.button < 4 || event.xbutton.button > 7)) { view->mouseFunc(view, event.xbutton.button, event.type == ButtonPress, event.xbutton.x, event.xbutton.y); } break; case KeyPress: { setModifiers(view, event.xkey.state, event.xkey.time); KeySym sym; char str[5]; int n = XLookupString(&event.xkey, str, 4, &sym, NULL); PuglKey key = keySymToSpecial(sym); if (!key && view->keyboardFunc) { if (n == 1) { view->keyboardFunc(view, true, str[0]); } else { fprintf(stderr, "warning: Unknown key %X\n", (int)sym); } } else if (view->specialFunc) { view->specialFunc(view, true, key); } } break; case KeyRelease: { setModifiers(view, event.xkey.state, event.xkey.time); bool repeated = false; if (view->ignoreKeyRepeat && XEventsQueued(view->impl->display, QueuedAfterReading)) { XEvent next; XPeekEvent(view->impl->display, &next); if (next.type == KeyPress && next.xkey.time == event.xkey.time && next.xkey.keycode == event.xkey.keycode) { XNextEvent(view->impl->display, &event); repeated = true; } } if (!repeated && view->keyboardFunc) { KeySym sym = XKeycodeToKeysym( view->impl->display, event.xkey.keycode, 0); PuglKey special = keySymToSpecial(sym); if (!special) { view->keyboardFunc(view, false, sym); } else if (view->specialFunc) { view->specialFunc(view, false, special); } } } break; case ClientMessage: if (!strcmp(XGetAtomName(view->impl->display, event.xclient.message_type), "WM_PROTOCOLS")) { if (view->closeFunc) { view->closeFunc(view); } } break; default: break; } } if (view->redisplay) { puglDisplay(view); } return PUGL_SUCCESS; }
bool x11_alive(void *data) { while (XPending(g_x11_dpy)) { XEvent event; bool filter = false; /* Can get events from older windows. Check this. */ XNextEvent(g_x11_dpy, &event); filter = XFilterEvent(&event, g_x11_win); switch (event.type) { case ClientMessage: if (event.xclient.window == g_x11_win && (Atom)event.xclient.data.l[0] == g_x11_quit_atom) frontend_driver_set_signal_handler_state(1); break; case DestroyNotify: if (event.xdestroywindow.window == g_x11_win) frontend_driver_set_signal_handler_state(1); break; case MapNotify: if (event.xmap.window == g_x11_win) g_x11_has_focus = true; break; case UnmapNotify: if (event.xunmap.window == g_x11_win) g_x11_has_focus = false; break; case ButtonPress: switch (event.xbutton.button) { case 1: /* Left click */ #if 0 RARCH_LOG("Click occurred : [%d, %d]\n", event.xbutton.x_root, event.xbutton.y_root); #endif break; case 2: /* Grabbed */ /* Middle click */ break; case 3: /* Right click */ break; case 4: /* Grabbed */ /* Scroll up */ case 5: /* Scroll down */ x_input_poll_wheel(&event.xbutton, true); break; } break; case EnterNotify: g_x11_entered = true; break; case LeaveNotify: g_x11_entered = false; break; case ButtonRelease: break; case KeyPress: case KeyRelease: if (event.xkey.window == g_x11_win) x11_handle_key_event(&event, g_x11_xic, filter); break; } } return !((bool)frontend_driver_get_signal_handler_state()); }
/* This function handles XEvents that might be in the queue. It generates GstEvent that will be sent upstream in the pipeline to handle interactivity and navigation.*/ static void gst_vdp_sink_handle_xevents (VdpSink * vdp_sink) { XEvent e; guint pointer_x = 0, pointer_y = 0; gboolean pointer_moved = FALSE; gboolean exposed = FALSE, configured = FALSE; g_return_if_fail (GST_IS_VDP_SINK (vdp_sink)); /* Then we get all pointer motion events, only the last position is interesting. */ g_mutex_lock (vdp_sink->flow_lock); g_mutex_lock (vdp_sink->x_lock); while (XCheckWindowEvent (vdp_sink->device->display, vdp_sink->window->win, PointerMotionMask, &e)) { g_mutex_unlock (vdp_sink->x_lock); g_mutex_unlock (vdp_sink->flow_lock); switch (e.type) { case MotionNotify: pointer_x = e.xmotion.x; pointer_y = e.xmotion.y; pointer_moved = TRUE; break; default: break; } g_mutex_lock (vdp_sink->flow_lock); g_mutex_lock (vdp_sink->x_lock); } if (pointer_moved) { g_mutex_unlock (vdp_sink->x_lock); g_mutex_unlock (vdp_sink->flow_lock); GST_DEBUG ("vdp_sink pointer moved over window at %d,%d", pointer_x, pointer_y); gst_navigation_send_mouse_event (GST_NAVIGATION (vdp_sink), "mouse-move", 0, pointer_x, pointer_y); g_mutex_lock (vdp_sink->flow_lock); g_mutex_lock (vdp_sink->x_lock); } /* We get all remaining events on our window to throw them upstream */ while (XCheckWindowEvent (vdp_sink->device->display, vdp_sink->window->win, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask, &e)) { KeySym keysym; /* We lock only for the X function call */ g_mutex_unlock (vdp_sink->x_lock); g_mutex_unlock (vdp_sink->flow_lock); switch (e.type) { case ButtonPress: /* Mouse button pressed/released over our window. We send upstream events for interactivity/navigation */ GST_DEBUG ("vdp_sink button %d pressed over window at %d,%d", e.xbutton.button, e.xbutton.x, e.xbutton.x); gst_navigation_send_mouse_event (GST_NAVIGATION (vdp_sink), "mouse-button-press", e.xbutton.button, e.xbutton.x, e.xbutton.y); break; case ButtonRelease: GST_DEBUG ("vdp_sink button %d release over window at %d,%d", e.xbutton.button, e.xbutton.x, e.xbutton.x); gst_navigation_send_mouse_event (GST_NAVIGATION (vdp_sink), "mouse-button-release", e.xbutton.button, e.xbutton.x, e.xbutton.y); break; case KeyPress: case KeyRelease: /* Key pressed/released over our window. We send upstream events for interactivity/navigation */ GST_DEBUG ("vdp_sink key %d pressed over window at %d,%d", e.xkey.keycode, e.xkey.x, e.xkey.x); g_mutex_lock (vdp_sink->x_lock); keysym = XKeycodeToKeysym (vdp_sink->device->display, e.xkey.keycode, 0); g_mutex_unlock (vdp_sink->x_lock); if (keysym != NoSymbol) { char *key_str = NULL; g_mutex_lock (vdp_sink->x_lock); key_str = XKeysymToString (keysym); g_mutex_unlock (vdp_sink->x_lock); gst_navigation_send_key_event (GST_NAVIGATION (vdp_sink), e.type == KeyPress ? "key-press" : "key-release", key_str); } else { gst_navigation_send_key_event (GST_NAVIGATION (vdp_sink), e.type == KeyPress ? "key-press" : "key-release", "unknown"); } break; default: GST_DEBUG_OBJECT (vdp_sink, "vdp_sink unhandled X event (%d)", e.type); } g_mutex_lock (vdp_sink->flow_lock); g_mutex_lock (vdp_sink->x_lock); } while (XCheckWindowEvent (vdp_sink->device->display, vdp_sink->window->win, ExposureMask | StructureNotifyMask, &e)) { switch (e.type) { case Expose: exposed = TRUE; break; case ConfigureNotify: configured = TRUE; break; default: break; } } if (vdp_sink->handle_expose && (exposed || configured)) { g_mutex_unlock (vdp_sink->x_lock); g_mutex_unlock (vdp_sink->flow_lock); gst_vdp_sink_expose (GST_X_OVERLAY (vdp_sink)); g_mutex_lock (vdp_sink->flow_lock); g_mutex_lock (vdp_sink->x_lock); } /* Handle Display events */ while (XPending (vdp_sink->device->display)) { XNextEvent (vdp_sink->device->display, &e); switch (e.type) { case ClientMessage:{ Atom wm_delete; wm_delete = XInternAtom (vdp_sink->device->display, "WM_DELETE_WINDOW", False); if (wm_delete == (Atom) e.xclient.data.l[0]) { /* Handle window deletion by posting an error on the bus */ GST_ELEMENT_ERROR (vdp_sink, RESOURCE, NOT_FOUND, ("Output window was closed"), (NULL)); g_mutex_unlock (vdp_sink->x_lock); gst_vdp_sink_window_destroy (vdp_sink, vdp_sink->window); vdp_sink->window = NULL; g_mutex_lock (vdp_sink->x_lock); } break; } default: break; } } g_mutex_unlock (vdp_sink->x_lock); g_mutex_unlock (vdp_sink->flow_lock); }
/* This function handles XEvents that might be in the queue. It generates GstEvent that will be sent upstream in the pipeline to handle interactivity and navigation. It will also listen for configure events on the window to trigger caps renegotiation so on the fly software scaling can work. */ static void gst_pvrvideosink_handle_xevents (GstPVRVideoSink * pvrvideosink) { XEvent e; gboolean exposed = FALSE; gboolean configured = FALSE; g_mutex_lock (pvrvideosink->flow_lock); g_mutex_lock (pvrvideosink->dcontext->x_lock); /* Handle Expose */ while (XCheckWindowEvent (pvrvideosink->dcontext->x_display, pvrvideosink->xwindow->window, ExposureMask | StructureNotifyMask, &e)) { switch (e.type) { case Expose: exposed = TRUE; break; case ConfigureNotify: g_mutex_unlock (pvrvideosink->dcontext->x_lock); gst_pvrvideosink_xwindow_update_geometry (pvrvideosink); g_mutex_lock (pvrvideosink->dcontext->x_lock); configured = TRUE; break; default: break; } } if (exposed || configured) { g_mutex_unlock (pvrvideosink->dcontext->x_lock); g_mutex_unlock (pvrvideosink->flow_lock); gst_pvrvideosink_expose (GST_VIDEO_OVERLAY (pvrvideosink)); g_mutex_lock (pvrvideosink->flow_lock); g_mutex_lock (pvrvideosink->dcontext->x_lock); } /* Handle Display events */ while (XPending (pvrvideosink->dcontext->x_display)) { XNextEvent (pvrvideosink->dcontext->x_display, &e); switch (e.type) { case ClientMessage:{ Atom wm_delete; wm_delete = XInternAtom (pvrvideosink->dcontext->x_display, "WM_DELETE_WINDOW", True); if (wm_delete != None && wm_delete == (Atom) e.xclient.data.l[0]) { /* Handle window deletion by posting an error on the bus */ GST_ELEMENT_ERROR (pvrvideosink, RESOURCE, NOT_FOUND, ("Output window was closed"), (NULL)); g_mutex_unlock (pvrvideosink->dcontext->x_lock); gst_pvrvideosink_xwindow_destroy (pvrvideosink, pvrvideosink->xwindow); pvrvideosink->xwindow = NULL; g_mutex_lock (pvrvideosink->dcontext->x_lock); } break; } default: break; } } g_mutex_unlock (pvrvideosink->dcontext->x_lock); g_mutex_unlock (pvrvideosink->flow_lock); }
bool QEventDispatcherX11::hasPendingEvents() { extern uint qGlobalPostedEventsCount(); // from qapplication.cpp return (qGlobalPostedEventsCount() || XPending(X11->display)); }
int main(int argc, char **argv) { opt_data opts; optproc(argc, argv, &opts); if(audio_init(&opts) < 0) exit(1); int x = 0, y = 0, w, h; if(opts.w < 0 && opts.h < 0) opts.w = opts.h = 512; else if(opts.w < 0) opts.w = opts.h; else if(opts.h < 0) opts.h = opts.w; w = opts.w; h = opts.h; XEvent event; dpy = XOpenDisplay( NULL ); if(dpy == NULL) { printf("Error: couldn't open display %s\n", getenv("DISPLAY")); exit(EXIT_FAILURE); } int glx_major, glx_minor; if(!glXQueryVersion(dpy, &glx_major, &glx_minor)) { printf("GLX extension missing!\n"); XCloseDisplay(dpy); exit(EXIT_FAILURE); } printf("GLX version %i.%i\n", glx_major, glx_minor); int glxErrBase, glxEventBase; glXQueryExtension(dpy, &glxErrBase, &glxEventBase); printf("GLX: errorBase = %i, eventBase = %i\n", glxErrBase, glxEventBase); Window xwin, root; int numReturned; GLXFBConfig *fbConfigs; fbConfigs = glXChooseFBConfig( dpy, DefaultScreen(dpy), fbattrib, &numReturned ); if(fbConfigs == NULL) { //TODO: handle this? printf("No suitable fbconfigs!\n"); exit(EXIT_FAILURE); } XVisualInfo *vinfo = glXGetVisualFromFBConfig( dpy, fbConfigs[0] ); root = DefaultRootWindow(dpy); /* window attributes */ XSetWindowAttributes attrs; attrs.background_pixel = 0; attrs.border_pixel = 0; attrs.colormap = XCreateColormap(dpy, root, vinfo->visual, AllocNone); //attrs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; attrs.event_mask = StructureNotifyMask | KeyPressMask; unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; xwin = XCreateWindow(dpy, root, x, y, w, h, 0, vinfo->depth, InputOutput, vinfo->visual, mask, &attrs); XFree(vinfo); // Set hints and properties: { XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = w; sizehints.height = h; sizehints.flags = USSize | USPosition; XSetNormalHints(dpy, xwin, &sizehints); XSetStandardProperties(dpy, xwin, "Julia-vis", "Julia-vis", None, (char **)NULL, 0, &sizehints); } /* Create a GLX context for OpenGL rendering */ GLXContext context = glXCreateNewContext(dpy, fbConfigs[0], GLX_RGBA_TYPE, NULL, True ); #if 0 GLXContext context = 0; glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); if(strstr(glXQueryExtensionsString(dpy, 0), "GLX_ARB_create_context") || !glXCreateContextAttribsARB) { printf("glXCreateContextAttribsARB() not found ... using old-style GLX context\n"); context = glXCreateNewContext(dpy, fbConfigs[0], GLX_RGBA_TYPE, 0, True); } else { const int context_attribs[] = { GLX_RENDER_TYPE, GLX_RGBA_TYPE, GLX_CONTEXT_MAJOR_VERSION_ARB, 2, GLX_CONTEXT_MINOR_VERSION_ARB, 1, None }; context = glXCreateContextAttribsARB(dpy, fbConfigs[0], NULL, True, context_attribs); } if(context == NULL) { printf("Failed to create context!\n"); return EXIT_FAILURE; } #endif glxWin = glXCreateWindow(dpy, fbConfigs[0], xwin, NULL ); XMapWindow(dpy, xwin); XIfEvent(dpy, &event, WaitForNotify, (XPointer) xwin); glXMakeContextCurrent(dpy, glxWin, glxWin, context); init_gl(&opts, w, h); if(strstr(glXQueryExtensionsString(dpy, 0), "GLX_MESA_swap_control")) { PFNGLXSWAPINTERVALMESAPROC swap_interval = glXGetProcAddressARB("glXSwapIntervalMESA"); swap_interval(1); opts.draw_rate = 600; } if(strstr(glXQueryExtensionsString(dpy, 0), "GLX_INTEL_swap_event")) { glXSelectEvent(dpy, glxWin, GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK); have_intel_swap_event = GL_TRUE; } int debug_maxsrc = 0, debug_pal = 0, show_mandel = 0, show_fps_hist = 0; if(have_intel_swap_event) render_frame(debug_maxsrc, debug_pal, show_mandel, show_fps_hist); while(1) { if(!have_intel_swap_event) render_frame(debug_maxsrc, debug_pal, show_mandel, show_fps_hist); //int clear_key = 1; while (XPending(dpy) > 0) { XNextEvent(dpy, &event); if(event.type == glxEventBase + GLX_BufferSwapComplete) { render_frame(debug_maxsrc, debug_pal, show_mandel, show_fps_hist); continue; } switch (event.type) { case Expose: /* we'll redraw below */ break; /*case ConfigureNotify: window_w = event.xconfigure.width; window_h = event.xconfigure.height; if (surface_type == EGL_WINDOW_BIT) reshape(window_w, window_h); break;*/ case KeyPress: { //clear_key = 0; //char buffer[10]; int code; code = XLookupKeysym(&event.xkey, 0); if (code == XK_F1) { debug_maxsrc = !debug_maxsrc; } else if (code == XK_F2) { debug_pal = !debug_pal; } else if (code == XK_F3) { show_mandel = !show_mandel; } else if (code == XK_F4) { show_fps_hist = !show_fps_hist; } else { code = XLookupKeysym(&event.xkey, 1); if(code == XK_Escape) { goto glx_main_loop_quit; } } } break; default: //printf("Bar %i!\n", event.type); break; } } } glx_main_loop_quit: audio_shutdown(); XDestroyWindow(dpy, xwin); XCloseDisplay(dpy); return 0; }
static void HandleEvents( void ) { XEvent event; qboolean dowarp = qfalse, was_focused = focus; int mwx = x11display.win_width / 2; int mwy = x11display.win_height / 2; char *p; int key = 0; int time = 0; assert( x11display.dpy && x11display.win ); #ifdef WSW_EVDEV if( mouse_active && m_evdev_num ) { evdev_read(); } else #endif if( mouse_active && !dgamouse ) { int root_x, root_y, win_x, win_y; unsigned int mask; Window root, child; if( XQueryPointer( x11display.dpy, x11display.win, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask ) ) { mx += ( (int)win_x - mwx ); my += ( (int)win_y - mwy ); mwx = win_x; mwy = win_y; if( mx || my ) dowarp = qtrue; if( ignore_one ) { mx = my = 0; ignore_one = qfalse; } } } while( XPending( x11display.dpy ) ) { XNextEvent( x11display.dpy, &event ); switch( event.type ) { case KeyPress: time = Sys_XTimeToSysTime(event.xkey.time); p = XLateKey( &event.xkey, &key ); if( key ) Key_Event( key, qtrue, time ); while ( p && *p ) { qwchar wc = Q_GrabWCharFromUtf8String( (const char **)&p ); Key_CharEvent( key, wc ); } break; case KeyRelease: if( repeated_press( &event ) ) break; // don't send release events when repeating time = Sys_XTimeToSysTime(event.xkey.time); XLateKey( &event.xkey, &key ); Key_Event( key, event.type == KeyPress, time ); break; case MotionNotify: #ifdef WSW_EVDEV if( mouse_active && dgamouse && !m_evdev_num ) #else if( mouse_active && dgamouse ) #endif { mx += event.xmotion.x_root; my += event.xmotion.y_root; if( ignore_one ) { mx = my = 0; ignore_one = qfalse; } } break; case ButtonPress: if( ( cls.key_dest == key_console ) && !in_grabinconsole->integer ) break; #ifdef WSW_EVDEV if( m_evdev_num ) break; #endif time = Sys_XTimeToSysTime(event.xkey.time); if( event.xbutton.button == 1 ) Key_MouseEvent( K_MOUSE1, 1, time ); else if( event.xbutton.button == 2 ) Key_MouseEvent( K_MOUSE3, 1, time ); else if( event.xbutton.button == 3 ) Key_MouseEvent( K_MOUSE2, 1, time ); else if( event.xbutton.button == 4 ) Key_Event( K_MWHEELUP, 1, time ); else if( event.xbutton.button == 5 ) Key_Event( K_MWHEELDOWN, 1, time ); else if( event.xbutton.button >= 6 && event.xbutton.button <= 10 ) Key_MouseEvent( K_MOUSE4+event.xbutton.button-6, 1, time ); break; case ButtonRelease: if( ( cls.key_dest == key_console ) && !in_grabinconsole->integer ) break; #ifdef WSW_EVDEV if( m_evdev_num ) break; #endif time = Sys_XTimeToSysTime(event.xkey.time); if( event.xbutton.button == 1 ) Key_MouseEvent( K_MOUSE1, 0, time ); else if( event.xbutton.button == 2 ) Key_MouseEvent( K_MOUSE3, 0, time ); else if( event.xbutton.button == 3 ) Key_MouseEvent( K_MOUSE2, 0, time ); else if( event.xbutton.button == 4 ) Key_Event( K_MWHEELUP, 0, time ); else if( event.xbutton.button == 5 ) Key_Event( K_MWHEELDOWN, 0, time ); else if( event.xbutton.button >= 6 && event.xbutton.button <= 10 ) Key_MouseEvent( K_MOUSE4+event.xbutton.button-6, 0, time ); break; case FocusIn: if( x11display.ic ) XSetICFocus(x11display.ic); if( !focus ) { focus = qtrue; } break; case FocusOut: if( x11display.ic ) XUnsetICFocus(x11display.ic); if( focus ) { Key_ClearStates(); focus = qfalse; } break; case ClientMessage: if( event.xclient.data.l[0] == x11display.wmDeleteWindow ) Cbuf_ExecuteText( EXEC_NOW, "quit" ); break; case MapNotify: mapped = qtrue; if( x11display.modeset ) { if ( x11display.dpy && x11display.win ) { XSetInputFocus( x11display.dpy, x11display.win, RevertToPointerRoot, CurrentTime ); x11display.modeset = qfalse; } } if( input_active ) { uninstall_grabs(); install_grabs(); } break; case ConfigureNotify: VID_AppActivate( qtrue, qfalse ); break; case PropertyNotify: if( event.xproperty.window == x11display.win ) { if ( event.xproperty.atom == x11display.wmState ) { qboolean was_minimized = minimized; _X11_CheckWMSTATE(); if( minimized != was_minimized ) { // FIXME: find a better place for this?.. CL_SoundModule_Activate( !minimized ); } } } break; } } if( dowarp ) { XWarpPointer( x11display.dpy, None, x11display.win, 0, 0, 0, 0, x11display.win_width/2, x11display.win_height/2 ); } // set fullscreen or windowed mode upon focus in/out events if: // a) lost focus in fullscreen -> windowed // b) received focus -> fullscreen if a) if( ( focus != was_focused ) ) { if( x11display.features.wmStateFullscreen ) { if( !focus && Cvar_Value( "vid_fullscreen" ) ) { go_fullscreen_on_focus = qtrue; Cbuf_ExecuteText( EXEC_APPEND, "vid_fullscreen 0\n" ); } else if( focus && go_fullscreen_on_focus ) { go_fullscreen_on_focus = qfalse; Cbuf_ExecuteText( EXEC_APPEND, "vid_fullscreen 1\n" ); } } } }
int get_bits( int x, int y, int w, int h, pixel_t *dest) { int result = 0; if (!dest) return -1; #ifdef _WIN32 HWND hwnd; #if 0 POINT p; p.x = x; p.y = y; hwnd = WindowFromPoint( p); #else hwnd = GetDesktopWindow(); #endif if (hwnd == NULL) { printf( "%s: Failed to get HWND at (%d;%d)\n", __func__, x, y); } else { char title[1024] = ""; GetWindowText( hwnd, title, sizeof( title)); // printf( "%s: got HWND=%p at (%d;%d) [%s]\n", __func__, hwnd, x, y, title); RECT rect; if (!GetClientRect( hwnd, &rect)) { printf( "%s: Failed to get rect of HWND=%p\n", __func__, hwnd); } else { // printf( "%s: got rect=(%ld;%ld;%ld;%ld)\n", __func__, rect.left, rect.right, rect.top, rect.bottom); HDC hdc; // hdc = GetDC( hwnd); hdc = GetWindowDC( hwnd); if (hdc == NULL) { printf( "%s: Failed to get HDC of HWND=%p\n", __func__, hwnd); } else { // printf( "%s: got HDC=%p\n", __func__, hdc); // x = 0; y = 0; COLORREF cref; int i, j; for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { cref = GetPixel( hdc, x + i, y + j); dest->r = GetRValue( cref); dest->g = GetGValue( cref); dest->b = GetBValue( cref); dest++; // printf( " %08lx", cref); } // printf( "\n"); } } } } #elif 1 char* display = getenv( "DISPLAY"); Display* pDisplay = XOpenDisplay( display); do { XSync( pDisplay, False); } while (XPending( pDisplay)); Drawable hWindow; hWindow = XDefaultRootWindow( pDisplay); XImage* pImage; unsigned long planes = (typeof(planes))-1; int format = ZPixmap; pImage = XGetImage( pDisplay, hWindow, x, y, w, h, planes, format); int i, j; for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { unsigned long pixel; pixel = XGetPixel( pImage, i, j); #if 0 dest->b = pixel & 0xFF; dest->g = (pixel & 0xFF00) >> 8; dest->r = (pixel & 0xFF0000) >> 16; #else dest->r = pixel & 0xFF; dest->g = (pixel & 0xFF00) >> 8; dest->b = (pixel & 0xFF0000) >> 16; #endif dest++; } } XDestroyImage( pImage); XCloseDisplay( pDisplay); #else int i, j; static int f = 0; for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { dest->r = f+1*j+2*i; dest->g = f+3*j+4*(i+1); dest->b = f+5*j+6*(i+2); dest++; } } f+=10; #endif return result; }
int main(void) { Display *xdisplay; XkbEvent xevent; int opcode, xkbEventBase, xkbErrorBase, major, minor; int currentLayout = 0; time_t timestamp; char datetime[DATETIME_BUFFER + 1]; int status; snd_mixer_t *amixer; snd_mixer_elem_t *amixer_elem; snd_mixer_selem_id_t *amixer_selem; long int volume, volumeMin, volumeMax, volumePercent; struct udev *udev; struct udev_monitor *udev_monitor; struct udev_device *udev_device; int udev_fd; int ps_current = 0, ps_total = 0; openlog(NULL, LOG_CONS|LOG_PERROR|LOG_PID, LOG_DAEMON); if (!(xdisplay = XOpenDisplay(NULL))) { syslog(LOG_ERR, "Can't open display: %s!\n", strerror(errno)); return EXIT_FAILURE; } if (!XkbQueryExtension(xdisplay, &opcode, &xkbEventBase, &xkbErrorBase, &major, &minor)) { syslog(LOG_ERR, "X doesn't support a compatible Xkb!\n"); return EXIT_FAILURE; } if (!XkbSelectEvents(xdisplay, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask)) { syslog(LOG_ERR, "Could not set Xkb event mask!\n"); return EXIT_FAILURE; } if ((status = snd_mixer_open(&amixer, 0)) < 0 || (status = snd_mixer_selem_register(amixer, NULL, NULL)) < 0 || (status = snd_mixer_attach(amixer, "default")) < 0) { syslog(LOG_ERR, "Alsa failed: %s!\n", snd_strerror(status)); return EXIT_FAILURE; } if ((status = snd_mixer_load(amixer)) || (status = snd_mixer_selem_id_malloc(&amixer_selem)) < 0) { syslog(LOG_ERR, "Alsa failed: %s!\n", snd_strerror(status)); return EXIT_FAILURE; } snd_mixer_selem_id_set_index(amixer_selem, 0); snd_mixer_selem_id_set_name(amixer_selem, "Master"); amixer_elem = snd_mixer_find_selem(amixer, amixer_selem); snd_mixer_selem_get_playback_volume_range(amixer_elem, &volumeMin, &volumeMax); if (amixer_elem == NULL) { syslog(LOG_ERR, "Mixer simple element handle not found!\n"); return EXIT_FAILURE; } udev = udev_new(); if (udev == NULL) { syslog(LOG_ERR, "Can't create udev object!\n"); return EXIT_FAILURE; } udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); if (udev_monitor == NULL) { syslog(LOG_ERR, "Can't create udev monitor!\n"); return EXIT_SUCCESS; } if (udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "power_supply", NULL) < 0) { syslog(LOG_ERR, "Could't watch power_supply events!\n"); return EXIT_FAILURE; } if (udev_monitor_enable_receiving(udev_monitor) < 0) { syslog(LOG_ERR, "Could't bind udev monitor event!\n"); return EXIT_FAILURE; } udev_fd = udev_monitor_get_fd(udev_monitor); while(1) { time(×tamp); strftime(datetime, DATETIME_BUFFER, DATETIME_FORMAT, localtime(×tamp)); while(XPending(xdisplay)) { XNextEvent(xdisplay, &xevent.core); if (xevent.type == xkbEventBase && xevent.any.xkb_type == XkbStateNotify) { currentLayout = xevent.state.group; } } if ((status = snd_mixer_handle_events(amixer)) < 0) { syslog(LOG_ERR, "Alsa failed: %s!\n", snd_strerror(status)); return EXIT_FAILURE; } if ((status = snd_mixer_selem_get_playback_volume(amixer_elem, SND_MIXER_SCHN_MONO, &volume)) < 0) { syslog(LOG_ERR, "Alsa failed: %s!\n", snd_strerror(status)); return EXIT_FAILURE; } volumePercent = (volume * 100) / volumeMax; fd_set fds; int ret; struct timeval tv = {.tv_sec = 0, .tv_usec = 0}; FD_ZERO(&fds); FD_SET(udev_fd, &fds); ret = select(udev_fd + 1, &fds, NULL, NULL, &tv); if (ret > 0 && FD_ISSET(udev_fd, &fds)) { udev_device = udev_monitor_receive_device(udev_monitor); if (udev_device == NULL) { syslog(LOG_ERR, "Can't get udev device!\n"); return EXIT_SUCCESS; } printf("Name: %s\n", udev_device_get_sysname(udev_device)); printf("Node: %s\n", udev_device_get_devnode(udev_device)); printf("Subsystem: %s\n", udev_device_get_subsystem(udev_device)); printf("Devtype: %s\n", udev_device_get_devtype(udev_device)); printf("Action: %s\n", udev_device_get_action(udev_device)); /*ps_current = atoi(udev_device_get_property_value(udev_device, "POWER_SUPPLY_CHARGE_NOW"));*/ /*ps_total = atoi(udev_device_get_property_value(udev_device, "POWER_SUPPLY_CHARGE_FULL"));*/ printf("%s\n", udev_device_get_sysattr_value(udev_device, "energy_now")); printf("%s\n", udev_device_get_sysattr_value(udev_device, "energy_full")); udev_device_unref(udev_device); } printf("%s %s\t%s %li\t%s %i\t%s %s\n", GLYPH_KEYBOARD, layouts[currentLayout], GLYPH_VOLUME, volumePercent, GLYPH_BATTERY, ps_current, GLYPH_CLOCK, datetime ); usleep(SLEEP_MSECONDS * 1000); } snd_mixer_selem_id_free(amixer_selem); snd_mixer_close(amixer); XCloseDisplay(xdisplay); closelog(); return EXIT_SUCCESS; }
int main(int argc, char **argv) { EGLDisplay sEGLDisplay; EGLContext sEGLContext; EGLSurface sEGLSurface; /* EGL Configuration */ EGLint aEGLAttributes[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_DEPTH_SIZE, 16, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; EGLint aEGLContextAttributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLConfig aEGLConfigs[1]; EGLint cEGLConfigs; #ifdef _WIN32 MSG sMessage; #else XSetWindowAttributes win_attrs; int attrs[64], idx = 0, num_config = 0; int major, minor; Colormap colormap; XVisualInfo *pVisual; XEvent e; #endif GLint iLocPosition = 0; GLint iLocColour, iLocTexCoord, iLocNormal, iLocMVP; GLint iLocXangle, iLocYangle, iLocZangle; GLint iLocAspect, iLocLightPos, iLocSampler, iLocSampler2; GLuint uiProgram, uiFragShader, uiVertShader; GLenum myTex, myTex2; int bDone = 0; const unsigned int uiWidth = 640; const unsigned int uiHeight = 480; int iXangle = 0, iYangle = 0, iZangle = 0; float aTBNmatrix1[9], aTBNmatrix2[9]; float aLightPos[] = { 0.0f, 0.0f, -1.0f }; // Light is nearest camera. unsigned char *myPixels = calloc(1, 128*128*4); // Holds texture data. unsigned char *myPixels2 = calloc(1, 128*128*4); // Holds texture data. float aRotate[16], aModelView[16], aPerspective[16], aMVP[16]; int i; /* EGL Init */ #ifdef _WIN32 hDisplay = EGL_DEFAULT_DISPLAY; #else hDisplay = XOpenDisplay(NULL); if (!hDisplay) { printf("Could not open display\n"); exit(-1); } #endif sEGLDisplay = EGL_CHECK(eglGetDisplay(hDisplay)); EGL_CHECK(eglInitialize(sEGLDisplay, NULL, NULL)); EGL_CHECK(eglChooseConfig(sEGLDisplay, aEGLAttributes, aEGLConfigs, 1, &cEGLConfigs)); if (cEGLConfigs == 0) { printf("No EGL configurations were returned.\n"); exit(-1); } #ifdef _WIN32 hWindow = create_window(uiWidth, uiHeight); #else hWindow = create_window("OpenGL ES 2.0 Example on a Linux Desktop", uiWidth, uiHeight, hDisplay, sEGLDisplay, aEGLConfigs[0], &colormap, &pVisual); #endif sEGLSurface = EGL_CHECK(eglCreateWindowSurface(sEGLDisplay, aEGLConfigs[0], (EGLNativeWindowType)hWindow, NULL)); if (sEGLSurface == EGL_NO_SURFACE) { printf("Failed to create EGL surface.\n"); exit(-1); } sEGLContext = EGL_CHECK(eglCreateContext(sEGLDisplay, aEGLConfigs[0], EGL_NO_CONTEXT, aEGLContextAttributes)); if (sEGLContext == EGL_NO_CONTEXT) { printf("Failed to create EGL context.\n"); exit(-1); } EGL_CHECK(eglMakeCurrent(sEGLDisplay, sEGLSurface, sEGLSurface, sEGLContext)); /* Shader Initialisation */ process_shader(&uiVertShader, "shader.vert", GL_VERTEX_SHADER); process_shader(&uiFragShader, "shader.frag", GL_FRAGMENT_SHADER); /* Create uiProgram (ready to attach shaders) */ uiProgram = GL_CHECK(glCreateProgram()); /* Attach shaders and link uiProgram */ GL_CHECK(glAttachShader(uiProgram, uiVertShader)); GL_CHECK(glAttachShader(uiProgram, uiFragShader)); GL_CHECK(glLinkProgram(uiProgram)); /* Get attribute locations of non-fixed attributes like colour and texture coordinates. */ iLocPosition = GL_CHECK(glGetAttribLocation(uiProgram, "av4position")); iLocColour = GL_CHECK(glGetAttribLocation(uiProgram, "av3colour")); #ifdef DEBUG printf("iLocPosition = %i\n", iLocPosition); printf("iLocColour = %i\n", iLocColour); #endif /* Get uniform locations */ iLocMVP = GL_CHECK(glGetUniformLocation(uiProgram, "mvp")); #ifdef DEBUG printf("iLocMVP = %i\n", iLocMVP); #endif GL_CHECK(glUseProgram(uiProgram)); /* Enable attributes for position, colour and texture coordinates etc. */ GL_CHECK(glEnableVertexAttribArray(iLocPosition)); GL_CHECK(glEnableVertexAttribArray(iLocColour)); /* Populate attributes for position, colour and texture coordinates etc. */ GL_CHECK(glVertexAttribPointer(iLocPosition, 3, GL_FLOAT, GL_FALSE, 0, aVertices)); GL_CHECK(glVertexAttribPointer(iLocColour, 3, GL_FLOAT, GL_FALSE, 0, aColours)); GL_CHECK(glEnable(GL_CULL_FACE)); GL_CHECK(glEnable(GL_DEPTH_TEST)); #ifndef _WIN32 XSelectInput(hDisplay, hWindow, KeyPressMask | ExposureMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | VisibilityChangeMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask); #endif /* Enter event loop */ while (!bDone) { #ifdef _WIN32 if(PeekMessage(&sMessage, NULL, 0, 0, PM_REMOVE)) { if(sMessage.message == WM_QUIT) { bDone = 1; } else { TranslateMessage(&sMessage); DispatchMessage(&sMessage); } } #else while (XPending(hDisplay) > 0) { XNextEvent(hDisplay, &e); if (e.type == ButtonPress) { bDone = 1; } } #endif /* * Do some rotation with Euler angles. It is not a fixed axis as * quaterions would be, but the effect is cool. */ rotate_matrix(iXangle, 1.0, 0.0, 0.0, aModelView); rotate_matrix(iYangle, 0.0, 1.0, 0.0, aRotate); multiply_matrix(aRotate, aModelView, aModelView); rotate_matrix(iZangle, 0.0, 1.0, 0.0, aRotate); multiply_matrix(aRotate, aModelView, aModelView); /* Pull the camera back from the cube */ aModelView[14] -= 2.5; perspective_matrix(45.0, (double)uiWidth/(double)uiHeight, 0.01, 100.0, aPerspective); multiply_matrix(aPerspective, aModelView, aMVP); GL_CHECK(glUniformMatrix4fv(iLocMVP, 1, GL_FALSE, aMVP)); iXangle += 3; iYangle += 2; iZangle += 1; if(iXangle >= 360) iXangle -= 360; if(iXangle < 0) iXangle += 360; if(iYangle >= 360) iYangle -= 360; if(iYangle < 0) iYangle += 360; if(iZangle >= 360) iZangle -= 360; if(iZangle < 0) iZangle += 360; GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)); GL_CHECK(glDrawArrays(GL_TRIANGLES, 0, 36)); if (!eglSwapBuffers(sEGLDisplay, sEGLSurface)) { printf("Failed to swap buffers.\n"); } #ifdef _WIN32 Sleep(20); #else usleep(20000); #endif } /* Cleanup shaders */ GL_CHECK(glUseProgram(0)); GL_CHECK(glDeleteShader(uiVertShader)); GL_CHECK(glDeleteShader(uiFragShader)); GL_CHECK(glDeleteProgram(uiProgram)); /* EGL clean up */ EGL_CHECK(eglMakeCurrent(sEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); EGL_CHECK(eglDestroySurface(sEGLDisplay, sEGLSurface)); EGL_CHECK(eglDestroyContext(sEGLDisplay, sEGLContext)); EGL_CHECK(eglTerminate(sEGLDisplay)); #ifndef _WIN32 /* X windows clean up */ XDestroyWindow(hDisplay, hWindow); XFreeColormap(hDisplay, colormap); XFree(pVisual); XCloseDisplay(hDisplay); #endif return 0; }
void MainLoop() override { bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen; if (fullscreen) { X11Utils::ToggleFullscreen(dpy, win); #if defined(HAVE_XRANDR) && HAVE_XRANDR XRRConfig->ToggleDisplayMode(True); #endif } // The actual loop while (running) { XEvent event; KeySym key; for (int num_events = XPending(dpy); num_events > 0; num_events--) { XNextEvent(dpy, &event); switch (event.type) { case KeyPress: key = XLookupKeysym((XKeyEvent*)&event, 0); if (key == XK_Escape) { if (Core::GetState() == Core::CORE_RUN) { if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) XUndefineCursor(dpy, win); Core::SetState(Core::CORE_PAUSE); } else { if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) XDefineCursor(dpy, win, blankCursor); Core::SetState(Core::CORE_RUN); } } else if ((key == XK_Return) && (event.xkey.state & Mod1Mask)) { fullscreen = !fullscreen; X11Utils::ToggleFullscreen(dpy, win); #if defined(HAVE_XRANDR) && HAVE_XRANDR XRRConfig->ToggleDisplayMode(fullscreen); #endif } else if (key >= XK_F1 && key <= XK_F8) { int slot_number = key - XK_F1 + 1; if (event.xkey.state & ShiftMask) State::Save(slot_number); else State::Load(slot_number); } else if (key == XK_F9) Core::SaveScreenShot(); else if (key == XK_F11) State::LoadLastSaved(); else if (key == XK_F12) { if (event.xkey.state & ShiftMask) State::UndoLoadState(); else State::UndoSaveState(); } break; case FocusIn: rendererHasFocus = true; if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor && Core::GetState() != Core::CORE_PAUSE) XDefineCursor(dpy, win, blankCursor); break; case FocusOut: rendererHasFocus = false; if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) XUndefineCursor(dpy, win); break; case ClientMessage: if ((unsigned long) event.xclient.data.l[0] == XInternAtom(dpy, "WM_DELETE_WINDOW", False)) running = false; break; } } if (!fullscreen) { Window winDummy; unsigned int borderDummy, depthDummy; XGetGeometry(dpy, win, &winDummy, &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos, &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos, (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth, (unsigned int *)&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight, &borderDummy, &depthDummy); } usleep(100000); } }
void cX11Window::XEventThread() { // Free look variables static bool mouseLookEnabled = false; static bool mouseMoveEnabled = false; static float lastMouse[2]; while (GLWin.win) { XEvent event; KeySym key; for (int num_events = XPending(GLWin.evdpy); num_events > 0; num_events--) { XNextEvent(GLWin.evdpy, &event); switch(event.type) { case KeyPress: key = XLookupKeysym((XKeyEvent*)&event, 0); if (g_Config.bOSDHotKey) { switch (key) { case XK_3: OSDChoice = 1; // Toggle native resolution g_Config.iEFBScale = g_Config.iEFBScale + 1; if (g_Config.iEFBScale > 7) g_Config.iEFBScale = 0; break; case XK_4: OSDChoice = 2; // Toggle aspect ratio g_Config.iAspectRatio = (g_Config.iAspectRatio + 1) & 3; break; case XK_5: OSDChoice = 3; // Toggle EFB copy if (!g_Config.bEFBCopyEnable || g_Config.bCopyEFBToTexture) { g_Config.bEFBCopyEnable ^= true; g_Config.bCopyEFBToTexture = false; } else { g_Config.bCopyEFBToTexture = !g_Config.bCopyEFBToTexture; } break; case XK_6: OSDChoice = 4; g_Config.bDisableFog = !g_Config.bDisableFog; break; default: break; } } if (g_Config.bFreeLook) { static float debugSpeed = 1.0f; switch (key) { case XK_parenleft: debugSpeed /= 2.0f; break; case XK_parenright: debugSpeed *= 2.0f; break; case XK_w: VertexShaderManager::TranslateView(0.0f, debugSpeed); break; case XK_s: VertexShaderManager::TranslateView(0.0f, -debugSpeed); break; case XK_a: VertexShaderManager::TranslateView(debugSpeed, 0.0f); break; case XK_d: VertexShaderManager::TranslateView(-debugSpeed, 0.0f); break; case XK_r: VertexShaderManager::ResetView(); break; } } break; case ButtonPress: if (g_Config.bFreeLook) { switch (event.xbutton.button) { case 2: // Middle button lastMouse[0] = event.xbutton.x; lastMouse[1] = event.xbutton.y; mouseMoveEnabled = true; break; case 3: // Right button lastMouse[0] = event.xbutton.x; lastMouse[1] = event.xbutton.y; mouseLookEnabled = true; break; } } break; case ButtonRelease: if (g_Config.bFreeLook) { switch (event.xbutton.button) { case 2: // Middle button mouseMoveEnabled = false; break; case 3: // Right button mouseLookEnabled = false; break; } } break; case MotionNotify: if (g_Config.bFreeLook) { if (mouseLookEnabled) { VertexShaderManager::RotateView((event.xmotion.x - lastMouse[0]) / 200.0f, (event.xmotion.y - lastMouse[1]) / 200.0f); lastMouse[0] = event.xmotion.x; lastMouse[1] = event.xmotion.y; } if (mouseMoveEnabled) { VertexShaderManager::TranslateView((event.xmotion.x - lastMouse[0]) / 50.0f, (event.xmotion.y - lastMouse[1]) / 50.0f); lastMouse[0] = event.xmotion.x; lastMouse[1] = event.xmotion.y; } } break; case ConfigureNotify: Window winDummy; unsigned int borderDummy, depthDummy; XGetGeometry(GLWin.evdpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y, &GLWin.width, &GLWin.height, &borderDummy, &depthDummy); GLInterface->SetBackBufferDimensions(GLWin.width, GLWin.height); break; case ClientMessage: if ((unsigned long) event.xclient.data.l[0] == XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", False)) Host_Message(WM_USER_STOP); if ((unsigned long) event.xclient.data.l[0] == XInternAtom(GLWin.evdpy, "RESIZE", False)) XMoveResizeWindow(GLWin.evdpy, GLWin.win, event.xclient.data.l[1], event.xclient.data.l[2], event.xclient.data.l[3], event.xclient.data.l[4]); break; default: break; } } Common::SleepCurrentThread(20); } }
void run(Display *display, Screen *screen) { shared_ptr<GLWindow> window(new GLWindow(display, screen)); // create window if (!window->create()) { fprintf(stderr, "ERROR: Cannot create window!\n"); } if (!window->activate()) { fprintf(stderr, "ERROR: Cannot activate window!\n"); } // setup glew glewInit(); // setup renderer window->camera = Camera( PerspectiveProjection<f32>(60.0 / 180.0 * M_PI, window->ratio(), 0.01, 100.0), LookAtTransform<f32>(Vector3<f32>(0, 0.25, 1), Vector3<f32>(0, 0, 0), Vector3<f32>(0, 1, 0)) ); // setup demo scene shared_ptr<ShaderProgram> program( new ShaderProgram( Shader::fromFile(GL_VERTEX_SHADER, "test.vs"), Shader::fromFile(GL_FRAGMENT_SHADER, "test.fs") ) ); shared_ptr<Surface> surface0(new FlatSurface(program)); Scene scene; // program->print(); scene.addSurface("surface0", surface0); scene.startAll(); scene.showAll(); // event loop i64u firstDraw, lastDraw; firstDraw = Clock::tick(); lastDraw = Clock::tick(); while (window->exists()) { bool draw = Clock::elapsed(lastDraw) >= frameTime; bool active = false; if (draw) { window->camera.viewport = Rectangle2<i32>(0, 0, window->width(), window->height()); window->camera = window->camera.withProjectionMatrix( PerspectiveProjection<f32>(60.0 / 180.0 * M_PI, window->ratio(), 0.01, 100.0) ); // .withViewMatrix( // LookAroundYTransform<f32>(Vector3<f32>(0, 0, 0), 10.0, Clock::elapsed(firstDraw) * M_PI * 2, 0) // ); // renderer.animate(); lastDraw = Clock::tick(); window->beginFrame(); scene.animate(); scene.render(window); } while (XPending(display)) { XEvent xev; XNextEvent(display, &xev); window->processEvent(xev); active = true; } if (draw) { window->endFrame(); } else if (!active) { f64 wait = frameTime - Clock::elapsed(lastDraw); if (wait > 0) { Clock::sleep(wait < 0.010 ? wait : 0.010); } } } // destroy window window->deactivate(); window->destroy(); }
void SampleMain() { SfwOpenWindow("Gainput: Gesture sample"); gainput::TrackingAllocator allocator(gainput::GetDefaultAllocator()); gainput::InputManager manager(true, allocator); const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>(); const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>(); gainput::InputDeviceTouch* touchDevice = manager.CreateAndGetDevice<gainput::InputDeviceTouch>(); GAINPUT_ASSERT(touchDevice); gainput::DeviceId touchId = touchDevice->GetDeviceId(); #if defined(GAINPUT_PLATFORM_LINUX) || defined(GAINPUT_PLATFORM_WIN) manager.SetDisplaySize(SfwGetWidth(), SfwGetHeight()); #endif SfwSetInputManager(&manager); gainput::InputMap map(manager, "testmap", allocator); map.MapBool(ButtonConfirm, mouseId, gainput::MouseButtonLeft); gainput::DoubleClickGesture* dcg = manager.CreateAndGetDevice<gainput::DoubleClickGesture>(); GAINPUT_ASSERT(dcg); dcg->Initialize(mouseId, gainput::MouseButtonLeft, mouseId, gainput::MouseAxisX, 0.01f, mouseId, gainput::MouseAxisY, 0.01f, 500); map.MapBool(ButtonConfirmDouble, dcg->GetDeviceId(), gainput::DoubleClickTriggered); gainput::SimultaneouslyDownGesture* sdg = manager.CreateAndGetDevice<gainput::SimultaneouslyDownGesture>(); GAINPUT_ASSERT(sdg); sdg->AddButton(mouseId, gainput::MouseButtonLeft); sdg->AddButton(keyboardId, gainput::KeyShiftL); map.MapBool(ButtonConfirmExtra, sdg->GetDeviceId(), gainput::SimultaneouslyDownTriggered); MultiTouchEmulator* mte = manager.CreateAndGetDevice<MultiTouchEmulator>(); mte->Initialize(sdg->GetDeviceId(), gainput::SimultaneouslyDownTriggered, mouseId, gainput::MouseAxisX, mouseId, gainput::MouseAxisY, mouseId, gainput::MouseButtonLeft, mouseId, gainput::MouseAxisX, mouseId, gainput::MouseAxisY); if (!touchDevice->IsAvailable() || touchDevice->GetVariant() == gainput::InputDevice::DV_NULL) { touchId = mte->GetDeviceId(); } gainput::HoldGesture* hg = manager.CreateAndGetDevice<gainput::HoldGesture>(); GAINPUT_ASSERT(hg); hg->Initialize(touchId, gainput::Touch0Down, touchId, gainput::Touch0X, 0.1f, touchId, gainput::Touch0Y, 0.1f, true, 800); map.MapBool(ButtonHoldGesture, hg->GetDeviceId(), gainput::HoldTriggered); gainput::TapGesture* tg = manager.CreateAndGetDevice<gainput::TapGesture>(); GAINPUT_ASSERT(tg); tg->Initialize(touchId, gainput::Touch0Down, 500); map.MapBool(ButtonTapGesture, tg->GetDeviceId(), gainput::TapTriggered); gainput::PinchGesture* pg = manager.CreateAndGetDevice<gainput::PinchGesture>(); GAINPUT_ASSERT(pg); pg->Initialize(touchId, gainput::Touch0Down, touchId, gainput::Touch0X, touchId, gainput::Touch0Y, touchId, gainput::Touch1Down, touchId, gainput::Touch1X, touchId, gainput::Touch1Y); map.MapBool(ButtonPinching, pg->GetDeviceId(), gainput::PinchTriggered); map.MapFloat(ButtonPinchScale, pg->GetDeviceId(), gainput::PinchScale); gainput::RotateGesture* rg = manager.CreateAndGetDevice<gainput::RotateGesture>(); GAINPUT_ASSERT(rg); rg->Initialize(touchId, gainput::Touch0Down, touchId, gainput::Touch0X, touchId, gainput::Touch0Y, touchId, gainput::Touch1Down, touchId, gainput::Touch1X, touchId, gainput::Touch1Y); map.MapBool(ButtonRotating, rg->GetDeviceId(), gainput::RotateTriggered); map.MapFloat(ButtonRotateAngle, rg->GetDeviceId(), gainput::RotateAngle); bool doExit = false; while (!SfwIsDone() && !doExit) { manager.Update(); #if defined(GAINPUT_PLATFORM_LINUX) XEvent event; while (XPending(SfwGetXDisplay())) { XNextEvent(SfwGetXDisplay(), &event); manager.HandleEvent(event); if (event.type == DestroyNotify || event.type == ClientMessage) { doExit = true; } } #elif defined(GAINPUT_PLATFORM_WIN) MSG msg; while (PeekMessage(&msg, SfwGetHWnd(), 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); manager.HandleMessage(msg); } #endif SfwUpdate(); if (map.GetBoolWasDown(ButtonConfirm)) { SFW_LOG("Confirmed!\n"); SFW_LOG("Memory: %u allocs, %u deallocs, %u used bytes\n", static_cast<unsigned>(allocator.GetAllocateCount()), static_cast<unsigned>(allocator.GetDeallocateCount()), static_cast<unsigned>(allocator.GetAllocatedMemory())); } if (map.GetBoolWasDown(ButtonConfirmDouble)) { SFW_LOG("Confirmed doubly!\n"); } if (map.GetBoolWasDown(ButtonConfirmExtra)) { SFW_LOG("Confirmed alternatively!\n"); } if (map.GetBool(ButtonHoldGesture)) { SFW_LOG("Hold triggered!\n"); } if (map.GetBoolWasDown(ButtonTapGesture)) { SFW_LOG("Tapped!\n"); } if (map.GetBool(ButtonPinching)) { SFW_LOG("Pinching: %f\n", map.GetFloat(ButtonPinchScale)); } if (map.GetBool(ButtonRotating)) { SFW_LOG("Rotation angle: %f\n", map.GetFloat(ButtonRotateAngle)); } } SfwCloseWindow(); }
/* * Function for selecting all interesting events on a given * (tree of) window(s). */ static void selectEvents (Window window, Bool substructureOnly) { Window root; /* root window of the window */ Window parent; /* parent of the window */ Window* children; /* children of the window */ unsigned nofChildren = 0; /* number of children */ unsigned i; /* loop counter */ XWindowAttributes attribs; /* attributes of the window */ if( xautolock_ignoreWindow( window )) return; /* * Start by querying the server about the root and parent windows. */ if (!XQueryTree (queue.display, window, &root, &parent, &children, &nofChildren)) { return; } if (nofChildren) (void) XFree ((char*) children); /* * Build the appropriate event mask. The basic idea is that we don't * want to interfere with the normal event propagation mechanism if * we don't have to. * * On the root window, we need to ask for both substructureNotify * and KeyPress events. On all other windows, we always need * substructureNotify, but only need Keypress if some other client * also asked for them, or if they are not being propagated up the * window tree. */ #if 0 if (substructureOnly) { (void) XSelectInput (queue.display, window, SubstructureNotifyMask); } else { if (parent == None) /* the *real* rootwindow */ { attribs.all_event_masks = attribs.do_not_propagate_mask = KeyPressMask; } else if (!XGetWindowAttributes (queue.display, window, &attribs)) #else { if (!XGetWindowAttributes (queue.display, window, &attribs)) #endif { return; } #if 0 (void) XSelectInput (queue.display, window, SubstructureNotifyMask | ( ( attribs.all_event_masks | attribs.do_not_propagate_mask) & KeyPressMask)); #else { int mask = SubstructureNotifyMask | attribs.your_event_mask; if( !substructureOnly ) { mask |= ( ( attribs.all_event_masks | attribs.do_not_propagate_mask) & KeyPressMask ); } (void) XSelectInput (queue.display, window, mask ); } #endif } /* * Now ask for the list of children again, since it might have changed * in between the last time and us selecting SubstructureNotifyMask. * * There is a (very small) chance that we might process a subtree twice: * child windows that have been created after our XSelectinput() has * been processed but before we get to the XQueryTree() bit will be * in this situation. This is harmless. It could be avoided by using * XGrabServer(), but that'd be an impolite thing to do, and since it * isn't required... */ if (!XQueryTree (queue.display, window, &root, &parent, &children, &nofChildren)) { return; } /* * Now do the same thing for all children. */ for (i = 0; i < nofChildren; ++i) { selectEvents (children[i], substructureOnly); } if (nofChildren) (void) XFree ((char*) children); } #if 0 /* * Function for processing any events that have come in since * last time. It is crucial that this function does not block * in case nothing interesting happened. */ void processEvents (void) { while (XPending (queue.display)) { XEvent event; if (XCheckMaskEvent (queue.display, SubstructureNotifyMask, &event)) { if (event.type == CreateNotify) { addToQueue (event.xcreatewindow.window); } } else { (void) XNextEvent (queue.display, &event); } /* * Reset the triggers if and only if the event is a * KeyPress event *and* was not generated by XSendEvent(). */ if ( event.type == KeyPress && !event.xany.send_event) { resetTriggers (); } } /* * Check the window queue for entries that are older than * CREATION_DELAY seconds. */ processQueue ((time_t) CREATION_DELAY); } #else void xautolock_processEvent( XEvent* event ) { if (event->type == CreateNotify) { addToQueue (event->xcreatewindow.window); } /* * Reset the triggers if and only if the event is a * KeyPress event *and* was not generated by XSendEvent(). */ if ( event->type == KeyPress && !event->xany.send_event) { xautolock_resetTriggers (); } } void xautolock_processQueue() { /* * Check the window queue for entries that are older than * CREATION_DELAY seconds. */ processQueue ((time_t) CREATION_DELAY); }
void wmifs_routine(int argc, char **argv) { rckeys wmifs_keys[] = { { "left", &left_action }, { "middle", &middle_action }, { "right", &right_action }, { NULL, NULL } }; int i, j; XEvent Event; int but_stat = -1; int stat_online; int stat_current; int first_time = 1; unsigned int curtime; unsigned int nexttime; struct timeval tv, tv2; long ipacket, opacket, istat, ostat; char temp[BUFFER_SIZE]; char *p; for (i = 0; i < MAX_STAT_DEVICES; i++) { stat_devices[i].name[0] = 0; for (j = 0; j < 48; j++) { stat_devices[i].his[j][0] = 0; stat_devices[i].his[j][1] = 0; } } stat_online = checknetdevs(); stat_current = 0; if (active_interface) { int isauto = !strcmp(active_interface, "auto"); for (i = 0; i < stat_online; i++) { if ((isauto && stillonline(stat_devices[i].name)) || !strcmp(stat_devices[i].name, active_interface)) { stat_current = i; break; } } } #ifdef LEFT_ACTION left_action = strdup(LEFT_ACTION); #endif #ifdef MIDDLE_ACTION middle_action = strdup(MIDDLE_ACTION); #endif #ifdef RIGHT_ACTION right_action = strdup(RIGHT_ACTION); #endif /* Scan throught the .rc files */ parse_rcfile(CONF"/wmifsrc", wmifs_keys); p = getenv("HOME"); if (p == NULL || *p == 0) { fprintf(stderr, "Unknown $HOME directory, please check your environment\n"); return; } strncpy(temp, p, BUFFER_SIZE - 10); strcat(temp, "/.wmifsrc"); parse_rcfile(temp, wmifs_keys); parse_rcfile(CONF"/wmifsrc.fixed", wmifs_keys); /* set user-defined colors */ if (color[0] != 0) { Window Root; XColor col; XWindowAttributes attributes; int screen; Pixel pixel; #define NUMSYMBOLS 4 XpmColorSymbol user_color[NUMSYMBOLS] = { {NULL, "#2081B2CAAEBA", 0}, /* + */ {NULL, "#28A23CF338E3", 0}, /* O */ {NULL, "#000049244103", 0}, /* @ */ {NULL, "#18618A288617", 0}, /* # */ }; /* code based on GetColor() from wmgeneral.c */ /* we need a temporary display to parse the color */ display = XOpenDisplay(NULL); screen = DefaultScreen(display); Root = RootWindow(display, screen); XGetWindowAttributes(display, Root, &attributes); col.pixel = 0; if (!XParseColor(display, attributes.colormap, color, &col)) { fprintf(stderr, "wmtime: can't parse %s.\n", color); goto draw_window; } else if (!XAllocColor(display, attributes.colormap, &col)) { fprintf(stderr, "wmtime: can't allocate %s.\n", color); goto draw_window; } pixel = col.pixel; /* replace colors from wmtime-master.xpm */ user_color[0].pixel = pixel; user_color[1].pixel = scale_pixel(pixel, .3); user_color[2].pixel = scale_pixel(pixel, .4); user_color[3].pixel = scale_pixel(pixel, .8); wmgen.attributes.valuemask |= XpmColorSymbols; wmgen.attributes.numsymbols = NUMSYMBOLS; wmgen.attributes.colorsymbols = user_color; XCloseDisplay(display); } draw_window: openXwindow(argc, argv, wmifs_master_xpm, (char*)wmifs_mask_bits, wmifs_mask_width, wmifs_mask_height); /* > Button */ AddMouseRegion(0, 5, 5, 35, 15); AddMouseRegion(1, 5, 20, 58, 58); gettimeofday(&tv2, NULL); nexttime = ScrollSpeed; DrawActiveIFS(stat_devices[stat_current].name); while (1) { struct timespec ts; gettimeofday(&tv, NULL); curtime = (tv.tv_sec - tv2.tv_sec) * 1000 + (tv.tv_usec - tv2.tv_usec) / 1000; waitpid(0, NULL, WNOHANG); for (i = 0; i < stat_online; i++) { get_statistics(stat_devices[i].name, &ipacket, &opacket, &istat, &ostat); if (first_time) { first_time = 0; } else { stat_devices[i].his[53][0] += istat - stat_devices[i].istatlast; stat_devices[i].his[53][1] += ostat - stat_devices[i].ostatlast; } if (i == stat_current) { if (!stillonline(stat_devices[i].name)) SetErrLED(LED_NET_POWER); else SetOnLED(LED_NET_POWER); if (stat_devices[i].istatlast == istat) SetOffLED(LED_NET_RX); else SetOnLED(LED_NET_RX); if (stat_devices[i].ostatlast == ostat) SetOffLED(LED_NET_TX); else SetOnLED(LED_NET_TX); } stat_devices[i].istatlast = istat; stat_devices[i].ostatlast = ostat; } RedrawWindow(); if (curtime >= nexttime) { nexttime = curtime + ScrollSpeed; DrawStats(&stat_devices[stat_current].his[0][0], 54, 40, 5, 58); for (i = 0; i < stat_online; i++) { if (stillonline(stat_devices[i].name)) { for (j = 1; j < 54; j++) { stat_devices[i].his[j-1][0] = stat_devices[i].his[j][0]; stat_devices[i].his[j-1][1] = stat_devices[i].his[j][1]; } stat_devices[i].his[53][0] = 0; stat_devices[i].his[53][1] = 0; } } RedrawWindow(); } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { switch (but_stat) { case 0: /* re-read the table */ strcpy(temp, stat_devices[stat_current].name); stat_online = checknetdevs(); stat_current = 0; for (i = 0; i < stat_online; i++) { if (!strcmp(temp, stat_devices[i].name)) stat_current = i; } stat_current++; if (stat_current == stat_online) stat_current = 0; DrawActiveIFS(stat_devices[stat_current].name); DrawStats(&stat_devices[stat_current].his[0][0], 54, 40, 5, 58); break; case 1: switch (Event.xbutton.button) { case 1: if (left_action) execCommand(left_action); break; case 2: if (middle_action) execCommand(middle_action); break; case 3: if (right_action) execCommand(right_action); break; } break; } } but_stat = -1; RedrawWindow(); break; } } ts.tv_sec = 0; ts.tv_nsec = SampleInt * 1000000; nanosleep(&ts, NULL); } }
/*ARGSUSED*/ extern int main(int argc, char *argv[]) { XEvent ev; struct sigaction sa; int dpy_fd, max_fd; argv0 = argv[0]; mode = wm_initialising; setlocale(LC_ALL, ""); /* Open a connection to the X server. */ dpy = XOpenDisplay(NULL); if (dpy == 0) panic("can't open display."); parseResources(); /* Set up an error handler. */ XSetErrorHandler(errorHandler); /* Set up signal handlers. */ signal(SIGTERM, Terminate); signal(SIGINT, Terminate); signal(SIGHUP, Terminate); /* Ignore SIGCHLD. */ sa.sa_handler = SIG_IGN; #ifdef SA_NOCLDWAIT sa.sa_flags = SA_NOCLDWAIT; #else sa.sa_flags = 0; #endif sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, 0); /* Internalize useful atoms. */ wm_state = XInternAtom(dpy, "WM_STATE", False); wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False); wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False); wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False); wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False); wm_colormaps = XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); compound_text = XInternAtom(dpy, "COMPOUND_TEXT", False); _mozilla_url = XInternAtom(dpy, "_MOZILLA_URL", False); motif_wm_hints = XInternAtom(dpy, "_MOTIF_WM_HINTS", False); ewmh_init(); /* * Get fonts for our titlebar and our popup window. We try to * get Lucida, but if we can't we make do with fixed because everyone * has that. */ { /* FIXME: do these need to be freed? */ char **missing; char *def; int missing_count; font_set = XCreateFontSet(dpy, font_name, &missing, &missing_count, &def); if (font_set == NULL) font_set = XCreateFontSet(dpy, "fixed", &missing, &missing_count, &def); if (font_set == NULL) panic("unable to create font set for title font"); if (missing_count > 0) fprintf(stderr,"%s: warning: missing %d charset" "%s for title font\n", argv0, missing_count, (missing_count == 1)?"":"s"); font_set_ext = XExtentsOfFontSet(font_set); popup_font_set = XCreateFontSet(dpy, popup_font_name, &missing, &missing_count, &def); if (popup_font_set == NULL) popup_font_set = XCreateFontSet(dpy, "fixed", &missing, &missing_count, &def); if (popup_font_set == NULL) panic("unable to create font set for popup font"); if (missing_count > 0) fprintf(stderr,"%s: warning: missing %d charset" "%s for popup font\n", argv0, missing_count, (missing_count == 1)?"":"s"); popup_font_set_ext = XExtentsOfFontSet(popup_font_set); } initScreens(); ewmh_init_screens(); session_init(argc, argv); /* See if the server has the Shape Window extension. */ shape = serverSupportsShapes(); /* * Initialisation is finished, but we start off not interacting with the * user. */ mode = wm_idle; /* * The main event loop. */ dpy_fd = ConnectionNumber(dpy); max_fd = dpy_fd + 1; if (ice_fd > dpy_fd) max_fd = ice_fd + 1; for (;;) { fd_set readfds; FD_ZERO(&readfds); FD_SET(dpy_fd, &readfds); if (ice_fd > 0) FD_SET(ice_fd, &readfds); if (select(max_fd, &readfds, NULL, NULL, NULL) > -1) { if (FD_ISSET(dpy_fd, &readfds)) { while (XPending(dpy)) { XNextEvent(dpy, &ev); dispatch(&ev); } } if (ice_fd > 0 && FD_ISSET(ice_fd, &readfds)) { session_process(); } } } }
static int display(struct vidisp_st *st, const char *title, const struct vidframe *frame) { struct vidframe frame_rgb; int err = 0; if (!st->disp) return ENODEV; /* * check for window delete - without blocking */ while (XPending(st->disp)) { XEvent e; XNextEvent(st->disp, &e); if (e.type == ClientMessage) { if ((Atom) e.xclient.data.l[0] == st->XwinDeleted) { info("x11: window deleted\n"); /* * we have to bail as all of the display * pointers are bad. */ close_window(st); return ENODEV; } } } if (!vidsz_cmp(&st->size, &frame->size)) { char capt[256]; if (st->size.w && st->size.h) { info("x11: reset: %u x %u ---> %u x %u\n", st->size.w, st->size.h, frame->size.w, frame->size.h); } if (st->internal && !st->win) err = create_window(st, &frame->size); err |= x11_reset(st, &frame->size); if (err) return err; if (title) { re_snprintf(capt, sizeof(capt), "%s - %u x %u", title, frame->size.w, frame->size.h); } else { re_snprintf(capt, sizeof(capt), "%u x %u", frame->size.w, frame->size.h); } XStoreName(st->disp, st->win, capt); } /* Convert from YUV420P to RGB */ vidframe_init_buf(&frame_rgb, st->pixfmt, &frame->size, (uint8_t *)st->shm.shmaddr); vidconv(&frame_rgb, frame, 0); /* draw */ if (st->xshmat) XShmPutImage(st->disp, st->win, st->gc, st->image, 0, 0, 0, 0, st->size.w, st->size.h, false); else XPutImage(st->disp, st->win, st->gc, st->image, 0, 0, 0, 0, st->size.w, st->size.h); XSync(st->disp, false); return err; }
int main(int argc, char **argv) { XEvent event; KeySym key; done = False; /* default to fullscreen */ GLWin.fs = false; if (!createGLWindow("NeHe's Texture Mapping Tutorial", 640, 480, 24, GLWin.fs)) { done = True; } /* wait for events*/ while (!done) { /* handle the events in the queue */ while (XPending(GLWin.dpy) > 0) { XNextEvent(GLWin.dpy, &event); switch (event.type) { case Expose: if (event.xexpose.count != 0) break; drawGLScene(); break; case ConfigureNotify: /* call resizeGLScene only if our window-size changed */ if ((event.xconfigure.width != GLWin.width) || (event.xconfigure.height != GLWin.height)) { GLWin.width = event.xconfigure.width; GLWin.height = event.xconfigure.height; printf("Resize event\n"); resizeGLScene(event.xconfigure.width, event.xconfigure.height); } break; /* exit in case of a mouse button press */ case ButtonPress: done = True; break; case KeyPress: key = XLookupKeysym(&event.xkey, 0); keyPressed(key); break; case ClientMessage: if (*XGetAtomName(GLWin.dpy, event.xclient.message_type) == *"WM_PROTOCOLS") { printf("Exiting sanely...\n"); done = True; } break; default: break; } } drawGLScene(); } killGLWindow(); return 0; }
/* * main */ int main(int argc, char *argv[]) { struct tm *gTime, *gmt; struct stat fi; XEvent event; Pixmap NewPixmap, NewShapeMask; XpmAttributes Attributes; Colormap cmap; int n, s, m, dt1, dt2, dt3, len; int Year, Month, Day; int Hours, Mins, Secs; int i, j, Width, Height, yoff, fd, Flag; long CurrentLocalTime; double UT, hour24(), jd(), CurrentJD, OldFileUT, FileUT; char command[1040], ImageName[256]; int havePixmap= 0; /* * Parse any command line arguments. */ ParseCMDLine(argc, argv); /* * Figure out what the name of the image xpm file should be... */ len = strlen(ImageURL); for (j = 0, i=0; i<len; ++i){ if (ImageURL[i] == '/') j = i; } strcpy(ImageName, ImageURL+j+1); sprintf(XpmFileName, "%s/.wmGrabImage/%s.xpm", getenv("HOME"), ImageName); sprintf(ImageFileName, "%s/.wmGrabImage/%s", getenv("HOME"), ImageName); openXwindow(argc, argv, wmGrabImage_master, wmGrabImage_mask_bits, wmGrabImage_mask_width, wmGrabImage_mask_height); cmap = DefaultColormap(display, DefaultScreen(display)); /* * Loop until we die */ n = 32000; s = 32000; m = 32000; dt1 = 32000; dt2 = 32000; dt3 = 32000; DblClkDelay = 32000; UpToDate = 0; FileUT = -999.0; Flag = 1; NewShapeMask = 0; Attributes.nalloc_pixels = 0; while(1) { /* * Keep track of # of seconds */ if (m > 100){ m = 0; ++dt1; ++dt2; ++dt3; } else { /* * Increment counter */ ++m; } /* * Double Click Delays * Keep track of click events. If Delay too long, set GotFirstClick's to False. */ if (DblClkDelay > 15) { DblClkDelay = 0; GotFirstClick1 = 0; GotDoubleClick1 = 0; GotFirstClick2 = 0; GotDoubleClick2 = 0; GotFirstClick3 = 0; GotDoubleClick3 = 0; } else { ++DblClkDelay; } /* * Process any pending X events. */ while(XPending(display)){ XNextEvent(display, &event); switch(event.type){ case Expose: RedrawWindow(); break; case ButtonPress: pressEvent(&event.xbutton); break; case ButtonRelease: break; } } /* * Draw window. */ if (ForceUpdate||Flag){ /* * Compute Current Julian Date */ CurrentLocalTime = time(CurrentTime); gTime = gmtime(&CurrentLocalTime); Year = gTime->tm_year+1900; Month = gTime->tm_mon+1; Day = gTime->tm_mday; Hours = gTime->tm_hour; Mins = gTime->tm_min; Secs = gTime->tm_sec; UT = (double)Hours + (double)Mins/60.0 + (double)Secs/3600.0; CurrentJD = jd(Year, Month, Day, UT); /* * Clear window. */ copyXPMArea(5, 69, 54, 54, 5, 5); if (havePixmap) { /* * free up the colors, if we alloc'd some before */ if (Attributes.nalloc_pixels > 0) XFreeColors(display, cmap, Attributes.alloc_pixels, Attributes.nalloc_pixels, 0); /* * Free last pixmap -- we dont need it anymore... * A ShapeMask is returned if the Pixmap had the color None used. * We could probably change Transparent to None to make use of this, but for now, * lets just ignore it... */ if ( NewShapeMask != 0 ) XFreePixmap(display, NewShapeMask); XFreePixmap(display, NewPixmap); XpmFreeAttributes(&Attributes); havePixmap= 0; } /* * Grab new pixmap. Accept a reasonable color match. */ Attributes.valuemask = XpmExactColors | XpmCloseness | XpmReturnAllocPixels; Attributes.exactColors = 0; Attributes.closeness = 40000; if (XpmReadFileToPixmap(display, Root, XpmFileName, &NewPixmap, &NewShapeMask, &Attributes) >= 0){ Height = Attributes.height; Width = Attributes.width; yoff = (CenterImage) ? (54 - Height)/2 : 0; XCopyArea(display, NewPixmap, wmgen.pixmap, NormalGC, 0, 0, Width, Height, 5, 5+yoff); Flag = 0; ForceUpdate = 0; havePixmap= 1; } /* * Make changes visible */ RedrawWindow(); } /* * Check xpm file status */ if (dt2 > 1){ dt2 = 0; if ( (fd = open(XpmFileName, O_RDONLY)) >= 0 ) { fstat(fd, &fi); close(fd); gmt = gmtime(&fi.st_mtime); OldFileUT = FileUT; FileUT = (double)gmt->tm_hour + (double)gmt->tm_min/60.0 + (double)gmt->tm_sec/3600.0; if (FileUT != OldFileUT) ForceUpdate = 1; } } /* * Check every 5 min if the values are not up to date... */ if (ForceUpdate2||(dt3 > UpdateDELAY)){ dt3 = 0; /* * Execute Perl script to grab the Latest METAR Report */ if (ConvertGeometry != NULL) sprintf(command, "GrabImage %s %s &", ImageURL, ConvertGeometry); else sprintf(command, "GrabImage %s &", ImageURL); system(command); ForceUpdate = 1; ForceUpdate2 = 0; } /* * Wait for next update */ usleep(DELAY); } }
void handleTooSmall(XInfo &xinfo, XEvent event) { int x = 0; XEvent event2; unsigned long lastRepaint = 0; int inside = 0; XFillRectangle(xinfo.display, xinfo.window, xinfo.gc[0], 0, 0, 800, 600); std::string text_pause("--Pause--"); XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2, xinfo.current_h/2, text_pause.c_str(), text_pause.length() ); std::string text_resume("The window is too small, please resize the window"); XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2, xinfo.current_h/2 + 20, text_resume.c_str(), text_resume.length() ); while (x == 0) { // stay looping untill window size exceed 800*600 // print to the screen notify user the game window is too small if (XPending(xinfo.display) > 0) { XNextEvent( xinfo.display, &event2 ); switch( event2.type ) { case ConfigureNotify: { XConfigureEvent xce = event2.xconfigure; fprintf(stderr, "Handling resize w=%d h=%d\n", xce.width, xce.height); xinfo.current_w = xce.width; xinfo.current_h = xce.height; if (xce.width >= 800 && xce.height >= 600) { printf("w > 800 and h > 600 resuming the game!!\n"); x = 1; } else { XFillRectangle(xinfo.display, xinfo.window, xinfo.gc[0], 0, 0, 800, 600); std::string text_pause("--Pause--"); XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2, xinfo.current_h/2, text_pause.c_str(), text_pause.length() ); std::string text_resume("The window is too small"); XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2-30, xinfo.current_h/2 + 20, text_resume.c_str(), text_resume.length() ); text_resume="Please resize to continue"; XDrawImageString( xinfo.display, xinfo.window, xinfo.gc[1], xinfo.current_w/2-35, xinfo.current_h/2 + 40, text_resume.c_str(), text_resume.length() ); } break; } case KeyPress: { KeySym key; char text[BufferSize]; int i = XLookupString((XKeyEvent *)&event2,text,BufferSize,&key,NULL); if ( i == 1) { if (text[0] == 'q') { error("Terminating normally."); } } break; } } // switch }// if xpending } // while } // end handleTooSmall
void glutMainLoop() { char buffer[10]; int r; // code; char pressed = 0; int i; XAllowEvents(dpy, AsyncBoth, CurrentTime); while (gRunning) { int op = 0; while (XPending(dpy) > 0) { XEvent event; XNextEvent(dpy, &event); switch (event.type) { case ClientMessage: if (event.xclient.data.l[0] == wmDeleteMessage) // quit! gRunning = 0; break; case Expose: op = 1; break; // Update event! Should do draw here. case ConfigureNotify: if (gReshape) gReshape(event.xconfigure.width, event.xconfigure.height); else { glViewport(0, 0, event.xconfigure.width, event.xconfigure.height); } animate = 1; break; case KeyPress: case KeyRelease: r = XLookupString(&event.xkey, buffer, sizeof(buffer), NULL, NULL); if (event.type == KeyPress) { if (gKey) gKey(buffer[0], 0, 0); gKeymap[(int)buffer[0]] = 1;} else { if (gKeyUp) gKeyUp(buffer[0], 0, 0); gKeymap[(int)buffer[0]] = 0;} break; case ButtonPress: gButtonPressed[event.xbutton.button] = 1; if (gMouseFunc != NULL) gMouseFunc(GLUT_LEFT_BUTTON, GLUT_DOWN, event.xbutton.x, event.xbutton.y); break; case ButtonRelease: gButtonPressed[event.xbutton.button] = 0; if (gMouseFunc != NULL) gMouseFunc(GLUT_LEFT_BUTTON, GLUT_UP, event.xbutton.x, event.xbutton.y); break; case MotionNotify: pressed = 0; for (i = 0; i < 5; i++) if (gButtonPressed[i]) pressed = 1; if (pressed && gMouseDragged) gMouseDragged(event.xbutton.x, event.xbutton.y); else if (gMouseMoved) gMouseMoved(event.xbutton.x, event.xbutton.y); break; default: break; } } if (animate) { animate = 0; if (gDisplay) gDisplay(); else printf("No display function!\n"); op = 0; } else if (gIdle) gIdle(); checktimers(); } glXMakeCurrent(dpy, None, NULL); glXDestroyContext(dpy, ctx); XDestroyWindow(dpy, win); XCloseDisplay(dpy); }
static void HandleEvents(void) { int b; int key; XEvent event; qboolean dowarp = qfalse; char *p; int dx, dy; int t = 0; // default to 0 in case we don't set if (!dpy) return; while (XPending(dpy)) { XNextEvent(dpy, &event); switch (event.type) { case KeyPress: t = Sys_XTimeToSysTime(event.xkey.time); p = XLateKey(&event.xkey, &key); if (key) { Sys_QueEvent( t, SE_KEY, key, qtrue, 0, NULL ); } if (p) { while (*p) { Sys_QueEvent( t, SE_CHAR, *p++, 0, 0, NULL ); } } break; case KeyRelease: t = Sys_XTimeToSysTime(event.xkey.time); // bk001206 - handle key repeat w/o XAutRepatOn/Off // also: not done if console/menu is active. // From Ryan's Fakk2. // see game/q_shared.h, KEYCATCH_* . 0 == in 3d game. if (cls.keyCatchers == 0) { // FIXME: KEYCATCH_NONE if (repeated_press(&event) == qtrue) continue; } // if XLateKey(&event.xkey, &key); Sys_QueEvent( t, SE_KEY, key, qfalse, 0, NULL ); break; case MotionNotify: t = Sys_XTimeToSysTime(event.xkey.time); if (mouse_active) { #ifdef HAVE_XF86DGA if (in_dgamouse->value) { mx += event.xmotion.x_root; my += event.xmotion.y_root; if (t - mouseResetTime > MOUSE_RESET_DELAY ) { Sys_QueEvent( t, SE_MOUSE, mx, my, 0, NULL ); } mx = my = 0; } else #endif /* HAVE_XF86DGA */ { // If it's a center motion, we've just returned from our warp if (event.xmotion.x == glConfig.vidWidth/2 && event.xmotion.y == glConfig.vidHeight/2) { mwx = glConfig.vidWidth/2; mwy = glConfig.vidHeight/2; if (t - mouseResetTime > MOUSE_RESET_DELAY ) { Sys_QueEvent( t, SE_MOUSE, mx, my, 0, NULL ); } mx = my = 0; break; } dx = ((int)event.xmotion.x - mwx); dy = ((int)event.xmotion.y - mwy); mx += dx; my += dy; mwx = event.xmotion.x; mwy = event.xmotion.y; dowarp = qtrue; } } break; case ButtonPress: t = Sys_XTimeToSysTime(event.xkey.time); if (event.xbutton.button == 4) { Sys_QueEvent( t, SE_KEY, K_MWHEELUP, qtrue, 0, NULL ); } else if (event.xbutton.button == 5) { Sys_QueEvent( t, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL ); } else { // NOTE TTimo there seems to be a weird mapping for K_MOUSE1 K_MOUSE2 K_MOUSE3 .. b=-1; if (event.xbutton.button == 1) { b = 0; // K_MOUSE1 } else if (event.xbutton.button == 2) { b = 2; // K_MOUSE3 } else if (event.xbutton.button == 3) { b = 1; // K_MOUSE2 } else if (event.xbutton.button == 6) { b = 3; // K_MOUSE4 } else if (event.xbutton.button == 7) { b = 4; // K_MOUSE5 }; Sys_QueEvent( t, SE_KEY, K_MOUSE1 + b, qtrue, 0, NULL ); } break; case ButtonRelease: t = Sys_XTimeToSysTime(event.xkey.time); if (event.xbutton.button == 4) { Sys_QueEvent( t, SE_KEY, K_MWHEELUP, qfalse, 0, NULL ); } else if (event.xbutton.button == 5) { Sys_QueEvent( t, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL ); } else { b=-1; if (event.xbutton.button == 1) { b = 0; } else if (event.xbutton.button == 2) { b = 2; } else if (event.xbutton.button == 3) { b = 1; } else if (event.xbutton.button == 6) { b = 3; // K_MOUSE4 } else if (event.xbutton.button == 7) { b = 4; // K_MOUSE5 }; Sys_QueEvent( t, SE_KEY, K_MOUSE1 + b, qfalse, 0, NULL ); } break; case CreateNotify : win_x = event.xcreatewindow.x; win_y = event.xcreatewindow.y; break; case ConfigureNotify : win_x = event.xconfigure.x; win_y = event.xconfigure.y; break; } } if (dowarp) { XWarpPointer(dpy,None,win,0,0,0,0, (glConfig.vidWidth/2),(glConfig.vidHeight/2)); } }
bool CXWindowsEventQueueBuffer::isEmpty() const { CLock lock(&m_mutex); return (XPending(m_display) == 0); }
void CL_DisplayWindow_OpenGL::keep_alive() { XEvent event, next_event; CL_Rect *rect; for (int i=XPending(disp); i>0; i--) { XNextEvent(disp, &event); switch(event.type) { //Resize or Move case ConfigureNotify: #ifdef DEBUG CL_Log::log("debug", "ConfigureNotify Event received"); #endif set_size(event.xconfigure.width,event.xconfigure.height); break; case ClientMessage: #ifdef DEBUG CL_Log::log("debug", "Received ClientMessage, sending close signal"); #endif sig_window_close(); break; case Expose: // Repaint notification // Could be more efficient if we checked ahead for other // repaint notifications #ifdef DEBUG CL_Log::log("debug", "Expose Event received"); #endif rect = new CL_Rect(event.xexpose.x, event.xexpose.y, event.xexpose.x + event.xexpose.width, event.xexpose.y + event.xexpose.height); sig_paint(*rect); delete rect; break; case FocusIn: #ifdef DEBUG CL_Log::log("debug", "Focus In"); #endif focus = true; sig_got_focus(); break; case FocusOut: #ifdef DEBUG CL_Log::log("debug", "Focus Out"); #endif focus = false; sig_lost_focus(); break; case KeyRelease: if( XEventsQueued( disp, QueuedAfterReading ) ) { XPeekEvent( disp, &next_event ); if( next_event.type == KeyPress && next_event.xkey.window == event.xkey.window && next_event.xkey.keycode == event.xkey.keycode && next_event.xkey.time == event.xkey.time ) { // Do not report anything for this event break; } } case KeyPress: case KeymapNotify: case ButtonPress: case ButtonRelease: case MotionNotify: sig_xevent(event); break; case PropertyNotify: #ifdef DEBUG // This looks to be mostly useless // I'm getting a lot of WM messages that aren't really useful. // --MSR, April 5, 2003 /* if(event.xproperty.state == PropertyNewValue) { CL_Log::log("debug", "%1 has a new value", XGetAtomName(disp, event.xproperty.atom)); } */ #endif break; #ifdef DEBUG case EnterNotify: case LeaveNotify: CL_Log::log("debug", "The mouse has left or entered the window"); break; // default: // CL_Log::log("debug", "Unhandled event type: %1", event.type); #endif default: sig_unknown_xevent(event); break; } } }
int XMenuActivate( register Display *display, /* Display to put menu on. */ register XMenu *menu, /* Menu to activate. */ int *p_num, /* Pane number selected. */ int *s_num, /* Selection number selected. */ int x_pos, /* X coordinate of menu position. */ int y_pos, /* Y coordinate of menu position. */ unsigned int event_mask, /* Mouse button event mask. */ char **data, /* Pointer to return data value. */ void (*help_callback) (char const *, int, int)) /* Help callback. */ { int status; /* X routine call status. */ int orig_x; /* Upper left menu origin X coord. */ int orig_y; /* Upper left menu origin Y coord. */ int ret_val; /* Return value. */ register XMPane *p_ptr; /* Current XMPane. */ register XMPane *event_xmp; /* Event XMPane pointer. */ register XMPane *cur_p; /* Current pane. */ register XMSelect *cur_s; /* Current selection. */ XMWindow *event_xmw; /* Event XMWindow pointer. */ XEvent event; /* X input event. */ XEvent peek_event; /* X input peek ahead event. */ Bool selection = False; /* Selection has been made. */ Bool forward = True; /* Moving forward in the pane list. */ Window root, child; int root_x, root_y, win_x, win_y; unsigned int mask; KeySym keysym; /* * Define and allocate a foreign event queue to hold events * that don't belong to XMenu. These events are later restored * to the X event queue. */ typedef struct _xmeventque { XEvent event; struct _xmeventque *next; } XMEventQue; XMEventQue *feq = NULL; /* Foreign event queue. */ XMEventQue *feq_tmp; /* Foreign event queue temporary. */ /* * If there are no panes in the menu then return failure * because the menu is not initialized. */ if (menu->p_count == 0) { _XMErrorCode = XME_NOT_INIT; return(XM_FAILURE); } /* * Find the desired current pane. */ cur_p = _XMGetPanePtr(menu, *p_num); if (cur_p == NULL) { return(XM_FAILURE); } cur_p->activated = cur_p->active; /* * Find the desired current selection. * If the current selection index is out of range a null current selection * will be assumed and the cursor will be placed in the current pane * header. */ cur_s = _XMGetSelectionPtr(cur_p, *s_num); /* * Compute origin of menu so that cursor is in * Correct pane and selection. */ _XMTransToOrigin(display, menu, cur_p, cur_s, x_pos, y_pos, &orig_x, &orig_y); menu->x_pos = orig_x; /* Store X and Y coords of menu. */ menu->y_pos = orig_y; if (XMenuRecompute(display, menu) == XM_FAILURE) { return(XM_FAILURE); } /* * Flush the window creation queue. * This batches all window creates since lazy evaluation * is more efficient than individual evaluation. * This routine also does an XFlush(). */ if (_XMWinQueFlush(display, menu, cur_p, cur_s) == _FAILURE) { return(XM_FAILURE); } /* * Make sure windows are in correct order (in case we were passed * an already created menu in incorrect order.) */ for(p_ptr = menu->p_list->next; p_ptr != cur_p; p_ptr = p_ptr->next) XRaiseWindow(display, p_ptr->window); for(p_ptr = menu->p_list->prev; p_ptr != cur_p->prev; p_ptr = p_ptr->prev) XRaiseWindow(display, p_ptr->window); /* * Make sure all selection windows are mapped. */ for ( p_ptr = menu->p_list->next; p_ptr != menu->p_list; p_ptr = p_ptr->next ){ XMapSubwindows(display, p_ptr->window); } /* * Synchronize the X buffers and the event queue. * From here on, all events in the queue that don't belong to * XMenu are sent back to the application via an application * provided event handler or discarded if the application has * not provided an event handler. */ XSync(display, 0); /* * Grab the mouse for menu input. */ status = XGrabPointer( display, menu->parent, True, event_mask, GrabModeAsync, GrabModeAsync, None, menu->mouse_cursor, CurrentTime ); if (status == Success && x_menu_grab_keyboard) { status = XGrabKeyboard (display, menu->parent, False, GrabModeAsync, GrabModeAsync, CurrentTime); if (status != Success) XUngrabPointer(display, CurrentTime); } if (status == _X_FAILURE) { _XMErrorCode = XME_GRAB_MOUSE; return(XM_FAILURE); } /* * Map the menu panes. */ XMapWindow(display, cur_p->window); for (p_ptr = menu->p_list->next; p_ptr != cur_p; p_ptr = p_ptr->next) XMapWindow(display, p_ptr->window); for (p_ptr = cur_p->next; p_ptr != menu->p_list; p_ptr = p_ptr->next) XMapWindow(display, p_ptr->window); XRaiseWindow(display, cur_p->window); /* Make sure current */ /* pane is on top. */ cur_s = NULL; /* Clear current selection. */ /* * Begin event processing loop. */ while (1) { if (wait_func) (*wait_func) (wait_data); XNextEvent(display, &event); /* Get next event. */ switch (event.type) { /* Dispatch on the event type. */ case Expose: event_xmp = (XMPane *)XLookUpAssoc(display, menu->assoc_tab, event.xexpose.window); if (event_xmp == NULL) { /* * If AEQ mode is enabled then queue the event. */ if (menu->aeq) { feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); if (feq_tmp == NULL) { _XMErrorCode = XME_CALLOC; return(XM_FAILURE); } feq_tmp->event = event; feq_tmp->next = feq; feq = feq_tmp; } else if (_XMEventHandler) (*_XMEventHandler)(&event); break; } if (event_xmp->activated) { XSetWindowBackground(display, event_xmp->window, menu->bkgnd_color); } else { XSetWindowBackgroundPixmap(display, event_xmp->window, menu->inact_pixmap); } _XMRefreshPane(display, menu, event_xmp); break; case EnterNotify: /* * First wait a small period of time, and see * if another EnterNotify event follows hard on the * heels of this one. i.e., the user is simply * "passing through". If so, ignore this one. */ event_xmw = (XMWindow *)XLookUpAssoc(display, menu->assoc_tab, event.xcrossing.window); if (event_xmw == NULL) break; if (event_xmw->type == SELECTION) { /* * We have entered a selection. */ /* if (XPending(display) == 0) usleep(150000); */ if (XPending(display) != 0) { XPeekEvent(display, &peek_event); if(peek_event.type == LeaveNotify) { break; } } cur_s = (XMSelect *)event_xmw; help_callback (cur_s->help_string, cur_p->serial, cur_s->serial); /* * If the pane we are in is active and the * selection entered is active then activate * the selection. */ if (cur_p->active && cur_s->active > 0) { cur_s->activated = 1; _XMRefreshSelection(display, menu, cur_s); } } else { /* * We have entered a pane. */ /* if (XPending(display) == 0) usleep(150000); */ if (XPending(display) != 0) { XPeekEvent(display, &peek_event); if (peek_event.type == EnterNotify) break; } XQueryPointer(display, menu->parent, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); event_xmp = (XMPane *)XLookUpAssoc(display, menu->assoc_tab, child); if (event_xmp == NULL) break; if (event_xmp == cur_p) break; if (event_xmp->serial > cur_p->serial) forward = True; else forward = False; p_ptr = cur_p; while (p_ptr != event_xmp) { if (forward) p_ptr = p_ptr->next; else p_ptr = p_ptr->prev; XRaiseWindow(display, p_ptr->window); } if (cur_p->activated) { cur_p->activated = False; XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap); _XMRefreshPane(display, menu, cur_p); } if (event_xmp->active) event_xmp->activated = True; #if 1 /* * i suspect the we don't get an EXPOSE event when backing * store is enabled; the menu windows content is probably * not drawn in when it should be in that case. * in that case, this is probably an ugly fix! * i hope someone more familiar with this code would * take it from here. -- [email protected]. */ XSetWindowBackground(display, event_xmp->window, menu->bkgnd_color); _XMRefreshPane(display, menu, event_xmp); #endif cur_p = event_xmp; } break; case LeaveNotify: event_xmw = (XMWindow *)XLookUpAssoc( display, menu->assoc_tab, event.xcrossing.window ); if (event_xmw == NULL) break; if(cur_s == NULL) break; /* * If the current selection was activated then * deactivate it. */ if (cur_s->activated) { cur_s->activated = False; _XMRefreshSelection(display, menu, cur_s); } cur_s = NULL; break; case ButtonPress: case ButtonRelease: *p_num = cur_p->serial; /* * Check to see if there is a current selection. */ if (cur_s != NULL) { /* * Set the selection number to the current selection. */ *s_num = cur_s->serial; /* * If the current selection was activated then * we have a valid selection otherwise we have * an inactive selection. */ if (cur_s->activated) { *data = cur_s->data; ret_val = XM_SUCCESS; } else { ret_val = XM_IA_SELECT; } } else { /* * No selection was current. */ ret_val = XM_NO_SELECT; } selection = True; break; case KeyPress: case KeyRelease: keysym = XLookupKeysym (&event.xkey, 0); /* Pop down on C-g and Escape. */ if ((keysym == XK_g && (event.xkey.state & ControlMask) != 0) || keysym == XK_Escape) /* Any escape, ignore modifiers. */ { ret_val = XM_NO_SELECT; selection = True; } break; default: /* * If AEQ mode is enabled then queue the event. */ if (menu->aeq) { feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); if (feq_tmp == NULL) { _XMErrorCode = XME_CALLOC; return(XM_FAILURE); } feq_tmp->event = event; feq_tmp->next = feq; feq = feq_tmp; } else if (_XMEventHandler) (*_XMEventHandler)(&event); } /* * If a selection has been made, break out of the event loop. */ if (selection == True) break; } /* * Unmap the menu. */ for ( p_ptr = menu->p_list->next; p_ptr != menu->p_list; p_ptr = p_ptr->next) { XUnmapWindow(display, p_ptr->window); } /* * Ungrab the mouse. */ XUngrabPointer(display, CurrentTime); XUngrabKeyboard(display, CurrentTime); /* * Restore bits under where the menu was if we managed * to save them and free the pixmap. */ /* * If there is a current selection deactivate it. */ if (cur_s != NULL) cur_s->activated = 0; /* * Deactivate the current pane. */ cur_p->activated = 0; XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap); /* * Synchronize the X buffers and the X event queue. */ XSync(display, 0); /* * Dispatch any events remaining on the queue. */ while (QLength(display)) { /* * Fetch the next event. */ XNextEvent(display, &event); /* * Discard any events left on the queue that belong to XMenu. * All others are held and then returned to the event queue. */ switch (event.type) { case Expose: case EnterNotify: case LeaveNotify: case ButtonPress: case ButtonRelease: /* * Does this event belong to one of XMenu's windows? * If so, discard it and process the next event. * If not fall through and treat it as a foreign event. */ event_xmp = (XMPane *)XLookUpAssoc( display, menu->assoc_tab, event.xbutton.window ); if (event_xmp != NULL) continue; default: /* * This is a foreign event. * Queue it for later return to the X event queue. */ feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); if (feq_tmp == NULL) { _XMErrorCode = XME_CALLOC; return(XM_FAILURE); } feq_tmp->event = event; feq_tmp->next = feq; feq = feq_tmp; } } /* * Return any foreign events that were queued to the X event queue. */ while (feq != NULL) { feq_tmp = feq; XPutBackEvent(display, &feq_tmp->event); feq = feq_tmp->next; free((char *)feq_tmp); } wait_func = 0; /* * Return successfully. */ _XMErrorCode = XME_NO_ERROR; return(ret_val); }
int main(int argc,char *argv[]) { int i; unsigned int borderwidth ; char *display_name = NULL; char *wname = "wmload"; XGCValues gcv; unsigned long gcm; XEvent Event; XTextProperty name; XClassHint classHint; Pixmap pixmask; Atom _XA_WM_DELETE_WINDOW = None; Geometry = ""; mywmhints.initial_state = NormalState; /* Parse command line options */ ProgName = argv[0]; for(i=1;i<argc;i++) { char *arg= argv[i]; if (arg[0] == '-') { switch(arg[1]) { case 'u': if(++i >=argc) usage(); sscanf(argv[i], "%d", &updatespeed); continue; case 'e': if(++i >=argc) usage(); strcpy(&Execute[0], argv[i]); strcat(&Execute[0], " &"); continue; case 's': ONLYSHAPE=1; continue; case 'p': if(++i >=argc) usage(); Geometry = argv[i]; continue; case 'i': mywmhints.initial_state = IconicState; continue; case 'w': mywmhints.initial_state = WithdrawnState; continue; case 'l': if(++i >=argc) usage(); LedColor = argv[i]; continue; case 'v': fprintf(stdout, "\nwmload version: %i.%i.%i\n", major_VER, minor_VER, patch_VER); if(argc == 2) exit(0); continue; default: usage(); } } else { fprintf(stderr, "\nInvalid argument: %s\n", arg); usage(); } } /* Open the display */ if (!(dpy = XOpenDisplay(display_name))) { fprintf(stderr,"wmload: can't open display %s\n", XDisplayName(display_name)); exit (1); } screen= DefaultScreen(dpy); Root = RootWindow(dpy, screen); d_depth = DefaultDepth(dpy, screen); x_fd = XConnectionNumber(dpy); _XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False); /* Convert XPM Data to XImage */ GetXPM(); /* Create a window to hold the banner */ mysizehints.flags= USSize|USPosition; mysizehints.x = 0; mysizehints.y = 0; back_pix = GetColor("white"); fore_pix = GetColor("black"); XWMGeometry(dpy, screen, Geometry, NULL, (borderwidth =1), &mysizehints, &mysizehints.x,&mysizehints.y,&mysizehints.width,&mysizehints.height, &i); mysizehints.width = wmload.attributes.width; mysizehints.height= wmload.attributes.height; win = XCreateSimpleWindow(dpy,Root,mysizehints.x,mysizehints.y, mysizehints.width,mysizehints.height, borderwidth,fore_pix,back_pix); iconwin = XCreateSimpleWindow(dpy,win,mysizehints.x,mysizehints.y, mysizehints.width,mysizehints.height, borderwidth,fore_pix,back_pix); /* activate hints */ XSetWMNormalHints(dpy, win, &mysizehints); classHint.res_name = "wmload"; classHint.res_class = "WMLoad"; XSetClassHint(dpy, win, &classHint); XSelectInput(dpy,win,MW_EVENTS); XSelectInput(dpy,iconwin,MW_EVENTS); XSetCommand(dpy,win,argv,argc); if (XStringListToTextProperty(&wname, 1, &name) ==0) { fprintf(stderr, "wmload: can't allocate window name\n"); exit(-1); } XSetWMName(dpy, win, &name); /* Create a GC for drawing */ gcm = GCForeground|GCBackground|GCGraphicsExposures; gcv.foreground = fore_pix; gcv.background = back_pix; gcv.graphics_exposures = FALSE; NormalGC = XCreateGC(dpy, Root, gcm, &gcv); if (ONLYSHAPE) { /* try to make shaped window here */ pixmask = XCreateBitmapFromData(dpy, win, (char *)mask2_bits, mask2_width, mask2_height); XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, pixmask, ShapeSet); XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); } mywmhints.icon_window = iconwin; mywmhints.icon_x = mysizehints.x; mywmhints.icon_y = mysizehints.y; mywmhints.window_group = win; mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint; XSetWMHints(dpy, win, &mywmhints); XSetWMProtocols (dpy, win, &_XA_WM_DELETE_WINDOW, 1); XMapWindow(dpy,win); InitLoad(); InsertLoad(); RedrawWindow(&visible); while(1) { if (actualtime != time(0)) { actualtime = time(0); if(actualtime % updatespeed == 0) InsertLoad(); RedrawWindow(&visible); } /* read a packet */ while (XPending(dpy)) { XNextEvent(dpy,&Event); switch(Event.type) { case Expose: if(Event.xexpose.count == 0 ) RedrawWindow(&visible); break; case ButtonPress: ExecuteExternal(); break; case ClientMessage: if ((Event.xclient.format != 32) || ((Atom)Event.xclient.data.l[0] != _XA_WM_DELETE_WINDOW)) break; case DestroyNotify: XFreeGC(dpy, NormalGC); XDestroyWindow(dpy, iconwin); XDestroyWindow(dpy, win); XCloseDisplay(dpy); exit(0); break ; default: break; } } XFlush(dpy); #ifdef SYSV poll((struct poll *) 0, (size_t) 0, 50); #else { struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 50000000L; /* 5/100 sec */ nanosleep(&ts, NULL); } #endif } return 0; }
int main (int argc, char **argv) { XEvent event; XSizeHints xsh; XSetWindowAttributes xswa; XVisualInfo *vinfo; glitz_drawable_format_t templ; glitz_drawable_format_t *dformat; unsigned long mask = 0; unsigned int width, height, window_width, window_height; int i; program_name = argv[0]; for (i = 1; i < argc; i++) { if (!strcasecmp ("-image", argv[i])) output_type = IMAGE_TYPE; #ifdef CAIRO_HAS_XLIB_SURFACE else if (!strcasecmp ("-xrender", argv[i])) { output_type = XRENDER_TYPE; } #endif else if (!strcasecmp ("-glx", argv[i])) { output_type = GLX_TYPE; } else if (!strcasecmp ("-noaa", argv[i])) { aa = 0; } else if (!strcasecmp ("-swaa", argv[i])) { aa = 1; } else if (!strcasecmp ("-hwaa", argv[i])) { aa = 3; } else { test_type = get_test_type (argv[i]); } } if (!test_type) { usage(); exit(1); } if (output_type != GLX_TYPE && test_type >= OPENGL_TYPE) { printf ("Sorry, this test only works with OpenGL!\n"); usage(); exit(1); } window_width = width = WINDOW_WIDTH; window_height = height = WINDOW_HEIGHT; if (aa == 3) templ.samples = 4; else templ.samples = 1; templ.depth_size = 16; if (test_type == CUBE_TYPE) mask |= GLITZ_FORMAT_DEPTH_SIZE_MASK; mask |= GLITZ_FORMAT_SAMPLES_MASK; if ((dpy = XOpenDisplay (NULL)) == NULL) { fprintf(stderr, "%s: can't open display: %s\n", argv[0], XDisplayName (NULL)); exit(1); } if (output_type != GLX_TYPE) { xsh.flags = PSize; xsh.width = width; xsh.height = height; xsh.x = 0; xsh.y = 0; win = XCreateWindow (dpy, RootWindow (dpy, DefaultScreen (dpy)), xsh.x, xsh.y, xsh.width, xsh.height, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, &xswa); XSetStandardProperties (dpy, win, PACKAGE, PACKAGE, None, argv, argc, &xsh); XSetWMHints (dpy, win, &xwmh); XSelectInput (dpy, win, StructureNotifyMask); } else { xsh.flags = PSize; xsh.width = width; xsh.height = height; xsh.x = 0; xsh.y = 0; mask = 0; templ.doublebuffer = 1; mask |= GLITZ_FORMAT_DOUBLEBUFFER_MASK; dformat = glitz_glx_find_window_format (dpy, DefaultScreen (dpy), mask, &templ, 0); vinfo = glitz_glx_get_visual_info_from_format (dpy, DefaultScreen (dpy), dformat); xswa.colormap = XCreateColormap (dpy, RootWindow (dpy, DefaultScreen (dpy)), vinfo->visual, AllocNone); win = XCreateWindow (dpy, RootWindow (dpy, DefaultScreen (dpy)), xsh.x, xsh.y, xsh.width, xsh.height, 0, vinfo->depth, CopyFromParent, vinfo->visual, CWColormap, &xswa); XSetStandardProperties (dpy, win, PACKAGE, PACKAGE, None, argv, argc, &xsh); XSetWMHints (dpy, win, &xwmh); XSelectInput (dpy, win, StructureNotifyMask); } switch (output_type) { case XRENDER_TYPE: resize_pixmap (width, height); break; case IMAGE_TYPE: resize_image (width, height); break; case GLX_TYPE: drawable = glitz_glx_create_drawable_for_window (dpy, 0, dformat, win, width, height); if (!drawable) { printf ("failed to create glitz drawable\n"); exit (1); } break; } if (aa == 3 && dformat->samples < 2) { fprintf (stderr, "hardware multi-sampling not available\n"); exit (1); } if (drawable) { surface = resize_glitz_drawable (drawable, dformat, width, height); } cr = cairo_create (surface); cairo_set_tolerance (cr, 0.5); setup (test_type); XMapWindow (dpy, win); for (;;) { if (XPending (dpy)) { XNextEvent (dpy, &event); if (event.type == ConfigureNotify) { width = event.xconfigure.width; height = event.xconfigure.height; switch (output_type) { #ifdef CAIRO_HAS_XLIB_SURFACE case XRENDER_TYPE: resize_pixmap (width, height); cairo_destroy (cr); cr = cairo_create (surface); cairo_set_tolerance (cr, 0.5); break; #endif case IMAGE_TYPE: resize_image (width, height); cairo_destroy (cr); cr = cairo_create (surface); cairo_set_tolerance (cr, 0.5); break; case GLX_TYPE: cairo_surface_destroy (surface); surface = resize_glitz_drawable (drawable, dformat, width, height); cairo_destroy (cr); cr = cairo_create (surface); cairo_set_tolerance (cr, 0.5); break; } } } else { render (test_type, output_type == GLX_TYPE); switch (output_type) { #ifdef CAIRO_HAS_XLIB_SURFACE case XRENDER_TYPE: XSetWindowBackgroundPixmap (dpy, win, pixmap); XClearWindow (dpy, win); break; #endif case IMAGE_TYPE: { GC gc; XImage *xim; pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy), width, height, DefaultDepth (dpy, DefaultScreen (dpy))); xim = XCreateImage(dpy, DefaultVisual (dpy, DefaultScreen (dpy)), DefaultDepth(dpy, DefaultScreen (dpy)), ZPixmap, 0, (char *) image, width, height, 32, 0); gc = XCreateGC (dpy, pixmap, 0, NULL); XPutImage (dpy, pixmap, gc, xim, 0, 0, 0, 0, width, height); XFreeGC (dpy, gc); xim->data = NULL; XDestroyImage (xim); XSetWindowBackgroundPixmap (dpy, win, pixmap); XClearWindow (dpy, win); XFreePixmap (dpy, pixmap); } break; } XSync (dpy, 0); } } exit (1); }
int32_t run(int _argc, char** _argv) { XInitThreads(); m_display = XOpenDisplay(0); int32_t screen = DefaultScreen(m_display); int32_t depth = DefaultDepth(m_display, screen); Visual* visual = DefaultVisual(m_display, screen); Window root = RootWindow(m_display, screen); XSetWindowAttributes windowAttrs; memset(&windowAttrs, 0, sizeof(windowAttrs) ); windowAttrs.background_pixmap = 0; windowAttrs.border_pixel = 0; windowAttrs.event_mask = 0 | ButtonPressMask | ButtonReleaseMask | ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | ResizeRedirectMask | StructureNotifyMask ; m_window = XCreateWindow(m_display , root , 0, 0 , ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, 0, depth , InputOutput , visual , CWBorderPixel|CWEventMask , &windowAttrs ); const char *wmDeleteWindowName = "WM_DELETE_WINDOW"; Atom wmDeleteWindow; XInternAtoms(m_display, (char **)&wmDeleteWindowName, 1, False, &wmDeleteWindow); XSetWMProtocols(m_display, m_window, &wmDeleteWindow, 1); XMapWindow(m_display, m_window); XStoreName(m_display, m_window, "BGFX"); bgfx::x11SetDisplayWindow(m_display, m_window); MainThreadEntry mte; mte.m_argc = _argc; mte.m_argv = _argv; bx::Thread thread; thread.init(mte.threadFunc, &mte); while (!m_exit) { if (XPending(m_display) ) { XEvent event; XNextEvent(m_display, &event); switch (event.type) { case Expose: break; case ConfigureNotify: break; case ClientMessage: if((Atom)event.xclient.data.l[0] == wmDeleteWindow) { m_eventQueue.postExitEvent(); } break; case ButtonPress: case ButtonRelease: { const XButtonEvent& xbutton = event.xbutton; MouseButton::Enum mb; switch (xbutton.button) { case Button1: mb = MouseButton::Left; break; case Button2: mb = MouseButton::Middle; break; case Button3: mb = MouseButton::Right; break; default: mb = MouseButton::None; break; } if (MouseButton::None != mb) { m_eventQueue.postMouseEvent(xbutton.x , xbutton.y , 0 , mb , event.type == ButtonPress ); } } break; case MotionNotify: { const XMotionEvent& xmotion = event.xmotion; m_eventQueue.postMouseEvent(xmotion.x , xmotion.y , 0 ); } break; case KeyPress: case KeyRelease: { XKeyEvent& xkey = event.xkey; KeySym keysym = XLookupKeysym(&xkey, 0); switch (keysym) { case XK_Meta_L: setModifier(Modifier::LeftMeta, KeyPress == event.type); break; case XK_Meta_R: setModifier(Modifier::RightMeta, KeyPress == event.type); break; case XK_Control_L: setModifier(Modifier::LeftCtrl, KeyPress == event.type); break; case XK_Control_R: setModifier(Modifier::RightCtrl, KeyPress == event.type); break; case XK_Shift_L: setModifier(Modifier::LeftShift, KeyPress == event.type); break; case XK_Shift_R: setModifier(Modifier::RightShift, KeyPress == event.type); break; case XK_Alt_L: setModifier(Modifier::LeftAlt, KeyPress == event.type); break; case XK_Alt_R: setModifier(Modifier::RightAlt, KeyPress == event.type); break; default: { Key::Enum key = fromXk(keysym); if (Key::None != key) { m_eventQueue.postKeyEvent(key, m_modifiers, KeyPress == event.type); } } break; } } break; case ResizeRequest: { const XResizeRequestEvent& xresize = event.xresizerequest; XResizeWindow(m_display, m_window, xresize.width, xresize.height); } break; } } } thread.shutdown(); XUnmapWindow(m_display, m_window); XDestroyWindow(m_display, m_window); return EXIT_SUCCESS; }