Vector2i InputImpl::getMousePosition(const Window& relativeTo) { WindowHandle handle = relativeTo.getSystemHandle(); if (handle) { // Open a connection with the X server Display* display = OpenDisplay(); // we don't care about these but they are required ::Window root, child; int gx, gy; unsigned int buttons; int x = 0; int y = 0; XQueryPointer(display, handle, &root, &child, &gx, &gy, &x, &y, &buttons); // Close the connection with the X server CloseDisplay(display); return Vector2i(x, y); } else { return Vector2i(); } }
bool InputImpl::isMouseButtonPressed(Mouse::Button button) { // Open a connection with the X server Display* display = OpenDisplay(); // we don't care about these but they are required ::Window root, child; int wx, wy; int gx, gy; unsigned int buttons = 0; XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &wx, &wy, &buttons); // Close the connection with the X server CloseDisplay(display); switch (button) { case Mouse::Left: return buttons & Button1Mask; case Mouse::Right: return buttons & Button3Mask; case Mouse::Middle: return buttons & Button2Mask; case Mouse::XButton1: return false; // not supported by X case Mouse::XButton2: return false; // not supported by X default: return false; } return false; }
int main(int argc, char *argv[]) { Display *dpy; GLXFBConfig pixmapConfig; XVisualInfo *windowVis; GLXPixmap gp; Window win; GLXContext ctx; Pixmap p; dpy = OpenDisplay(); pixmapConfig = ChoosePixmapFBConfig(dpy); windowVis = ChooseWindowVisual(dpy); win = CreateWindow(dpy, windowVis, 500, 500, "Texture From Pixmap"); gp = CreatePixmap(dpy, pixmapConfig, 512, 512, &p); DrawPixmapImage(dpy, p, 512, 512); ctx = glXCreateContext(dpy, windowVis, NULL, True); if (!ctx) { printf("Couldn't create GLX context\n"); exit(1); } glXMakeCurrent(dpy, win, ctx); BindPixmapTexture(dpy, gp); EventLoop(dpy, win); return 0; }
Widget MakeMenuItem(Widget parent, char *name, ButtonCB func, void *arg) { int n = 0; Arg wargs[5]; /* Used to set widget resources */ Widget item, menu; if (lsx_curwin->toplevel == NULL && OpenDisplay(0,NULL) == 0) return NULL; if (parent == NULL) return NULL; /* * We get the "menu" widget child of the parent widget because the * parent is really a reference to the menu button widget, not the * popup-shell widget we really want. See the above comment in * MakeMenu(). */ if ((menu = XtNameToWidget(parent, "menu")) == NULL) return NULL; n = 0; XtSetArg(wargs[n], XtNlabel, name); n++; XtSetArg(wargs[n], XtNleftMargin, check_mark_width); n++; item = XtCreateManagedWidget("menu_item", smeBSBObjectClass, menu, wargs, n); if (item == NULL) return NULL; if (func) XtAddCallback(item, XtNcallback, (XtCallbackProc)func, arg); return item; }
int main(int argc, char *argv[]) { Display *display = NULL; char *host = "localhost"; int port = 9090; display = OpenDisplay("localhost", 9090); if (display == NULL) { fprintf(stderr, "Unable to connect to display %s:%d\n", host, port); exit(1); } /* Register Callbacks */ RegisterCallback(display, ExposeEventType, expose_event, NULL); RegisterCallback(display, SetupEventType, setup, NULL); RegisterCallback(display, MouseMoveEventType, mouse_move, NULL); MainLoop(display); CloseDisplay(display); free(eyes); free(pupils); return 0; }
// Create rendering window. bool cInterfaceEGL::Create(void *window_handle, bool core, bool use565) { EGLint egl_major, egl_minor; egl_dpy = OpenDisplay(); if (!egl_dpy) { EGL_ILOG("Error: eglGetDisplay() failed\n"); return false; } if (!eglInitialize(egl_dpy, &egl_major, &egl_minor)) { EGL_ILOG("Error: eglInitialize() failed\n"); return false; } EGL_ILOG("eglInitialize() succeeded (use565=%d)\n", (int)use565); if (s_opengl_mode == MODE_DETECT || s_opengl_mode == MODE_DETECT_ES) DetectMode(); if (!ChooseAndCreate(window_handle, core, use565) && s_opengl_mode == MODE_OPENGLES3) { // Fallback to ES 2.0 and try again. s_opengl_mode = MODE_OPENGLES2; if (!ChooseAndCreate(window_handle, core, use565)) { eglTerminate(egl_dpy); egl_dpy = nullptr; return false; } } return true; }
/***************************************************************************** * Open: allocate video thread output method *****************************************************************************/ static int Open( vlc_object_t *p_this ) { vout_thread_t * p_vout = (vout_thread_t *)p_this; /* Allocate structure */ p_vout->p_sys = (struct vout_sys_t*) malloc( sizeof( struct vout_sys_t ) ); if( p_vout->p_sys == NULL ) return( 1 ); p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = Manage; p_vout->pf_render = NULL; //Render; p_vout->pf_display = Display; #ifdef NEED_QTE_MAIN p_vout->p_sys->p_qte_main = module_need( p_this, "gui-helper", "qte", true ); if( p_vout->p_sys->p_qte_main == NULL ) { free( p_vout->p_sys ); return VLC_ENOMOD; } #endif if (OpenDisplay(p_vout)) { msg_Err( p_vout, "Cannot set up qte video output" ); Close(p_this); return( -1 ); } return( 0 ); }
/***************************************************************************** * Create: allocates Glide video thread output method ***************************************************************************** * This function allocates and initializes a Glide vout method. *****************************************************************************/ static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) { msg_Err( p_vout, "out of memory" ); return( 1 ); } /* Open and initialize device */ if( OpenDisplay( p_vout ) ) { msg_Err( p_vout, "cannot open display" ); free( p_vout->p_sys ); return( 1 ); } p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = Manage; p_vout->pf_render = NULL; p_vout->pf_display = Display; return( 0 ); }
Widget MakeButton(char *txt, ButtonCB func, void *data) { int n = 0; Arg wargs[5]; /* Used to set widget resources */ Widget button; if (lsx_curwin->toplevel == NULL && OpenDisplay(0, NULL) == 0) return NULL; n = 0; if (txt) { XtSetArg(wargs[n], XtNlabel, txt); n++; } button = XtCreateManagedWidget("button", commandWidgetClass, lsx_curwin->form_widget,wargs,n); if (button == NULL) return NULL; if (func) XtAddCallback(button, XtNcallback, (XtCallbackProc)func, data); return button; } /* end of MakeButton() */
Widget MakeDrawArea(int width, int height, RedisplayCB redisplay, void *data) { int n = 0; Arg wargs[5]; /* Used to set widget resources */ Widget draw_widget; DrawInfo *di; if (lsx_curwin->toplevel == NULL && OpenDisplay(0, NULL) == 0) return NULL; di = (DrawInfo *)calloc(sizeof(DrawInfo), 1); if (di == NULL) return NULL; n = 0; XtSetArg(wargs[n], XtNwidth, width); n++; XtSetArg(wargs[n], XtNheight,height); n++; draw_widget = XtCreateManagedWidget("drawing_area", drawingAreaWidgetClass, lsx_curwin->form_widget,wargs,n); if (draw_widget == NULL) { free(di); return NULL; } di->drawgc = setup_gc(draw_widget); di->foreground = BlackPixel(lsx_curwin->display, lsx_curwin->screen); di->background = WhitePixel(lsx_curwin->display, lsx_curwin->screen); di->mask = 0xffffffff; di->user_data = data; di->redisplay = redisplay; XtAddCallback(draw_widget, XtNexposeCallback, (XtCallbackProc)_redisplay,di); XtAddCallback(draw_widget, XtNresizeCallback, (XtCallbackProc)_resize, di); XtAddCallback(draw_widget, XtNinputCallback, (XtCallbackProc)_do_input, di); XtAddCallback(draw_widget, XtNmotionCallback, (XtCallbackProc)_do_motion,di); lsx_curwin->last_draw_widget = draw_widget; di->widget = draw_widget; di->next = draw_info_head; draw_info_head = di; cur_di = di; /* * Make sure the font is set to something sane. */ if (lsx_curwin->font == NULL) lsx_curwin->font = GetFont("fixed"); SetWidgetFont(draw_widget, lsx_curwin->font); return draw_widget; }
void GlxContext::createSurface(::Window window) { m_display = OpenDisplay(); m_connection = XGetXCBConnection(m_display); // A window already exists, so just use it m_window = window; updateSettingsFromWindow(); }
VideoMode VideoModeImpl::getDesktopMode() { VideoMode desktopMode; // Open a connection with the X server Display* display = OpenDisplay(); if (display) { // Retrieve the default screen number int screen = DefaultScreen(display); // Check if the XRandR extension is present int version; if (XQueryExtension(display, "RANDR", &version, &version, &version)) { // Get the current configuration XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen)); if (config) { // Get the current video mode Rotation currentRotation; int currentMode = XRRConfigCurrentConfiguration(config, ¤tRotation); // Get the available screen sizes int nbSizes; XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes); if (sizes && (nbSizes > 0)) desktopMode = VideoMode(sizes[currentMode].width, sizes[currentMode].height, DefaultDepth(display, screen)); // Free the configuration instance XRRFreeScreenConfigInfo(config); } else { // Failed to get the screen configuration err() << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl; } } else { // XRandr extension is not supported : we cannot get the video modes err() << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl; } // Close the connection with the X server CloseDisplay(display); } else { // We couldn't connect to the X server err() << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl; } return desktopMode; }
void InputImpl::setMousePosition(const Vector2i& position) { // Open a connection with the X server Display* display = OpenDisplay(); XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, position.x, position.y); XFlush(display); // Close the connection with the X server CloseDisplay(display); }
void InputImpl::setMousePosition(const Vector2i& position, const Window& relativeTo) { // Open a connection with the X server Display* display = OpenDisplay(); WindowHandle handle = relativeTo.getSystemHandle(); if (handle) { XWarpPointer(display, None, handle, 0, 0, 0, 0, position.x, position.y); XFlush(display); } // Close the connection with the X server CloseDisplay(display); }
/***************************************************************************** * Create: allocates omapfb video thread output method ***************************************************************************** * This function allocates and initializes a FB vout method. *****************************************************************************/ static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_sys_t *p_sys; if( p_vout->fmt_in.i_chroma != VLC_CODEC_I420 && p_vout->fmt_in.i_chroma != VLC_CODEC_YV12 ) return VLC_EGENERIC; /* Allocate instance and initialize some members */ p_vout->p_sys = p_sys = calloc( 1, sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) return VLC_ENOMEM; p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = Manage; p_vout->pf_render = NULL; p_vout->pf_display = DisplayVideo; p_vout->pf_control = Control; p_sys->b_embed = var_CreateGetInteger( p_vout, "omap-embedded" ); p_sys->b_video_enabled = true; if( OpenDisplay( p_vout ) ) { free( p_vout->p_sys ); return VLC_EGENERIC; } if( InitWindow( p_vout ) ) { free( p_vout->p_sys ); return VLC_EGENERIC; } #ifdef HAVE_OSSO p_vout->p_sys->i_backlight_on_counter = i_backlight_on_interval; p_vout->p_sys->p_octx = osso_initialize( "vlc", VERSION, 0, NULL ); if ( p_vout->p_sys->p_octx == NULL ) { msg_Err( p_vout, "Could not get osso context" ); } else { msg_Dbg( p_vout, "Initialized osso context" ); } #endif return VLC_SUCCESS; }
/***************************************************************************** * Manage: handle Qte events ***************************************************************************** * This function should be called regularly by video output thread. It manages * Qte events and allows window resizing. It returns a non null value on * error. *****************************************************************************/ static int Manage( vout_thread_t *p_vout ) { // msg_Dbg( p_vout, "Manage" ); /* Fullscreen change */ if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE ) { p_vout->b_fullscreen = ! p_vout->b_fullscreen; // p_vout->p_sys->b_cursor_autohidden = 0; // SDL_ShowCursor( p_vout->p_sys->b_cursor && // ! p_vout->p_sys->b_cursor_autohidden ); p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE; p_vout->i_changes |= VOUT_SIZE_CHANGE; } /* * Size change */ if( p_vout->i_changes & VOUT_SIZE_CHANGE ) { msg_Dbg( p_vout, "video display resized (%dx%d)", p_vout->p_sys->i_width, p_vout->p_sys->i_height ); CloseDisplay( p_vout ); OpenDisplay( p_vout ); /* We don't need to signal the vout thread about the size change if * we can handle rescaling ourselves */ p_vout->i_changes &= ~VOUT_SIZE_CHANGE; } /* Pointer change */ // if( ! p_vout->p_sys->b_cursor_autohidden && // ( mdate() - p_vout->p_sys->i_lastmoved > // p_vout->p_sys->i_mouse_hide_timeout ) ) // { // /* Hide the mouse automatically */ // p_vout->p_sys->b_cursor_autohidden = 1; // SDL_ShowCursor( 0 ); // } // // if( !vlc_object_alive (p_vout->p_libvlc) ) // p_vout->p_sys->bRunning = FALSE; return 0; }
GlxContext::GlxContext(GlxContext* shared, const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel) : m_window (0), m_context (NULL), m_ownsWindow(false) { // Open a connection with the X server // (important: must be the same display as the owner window) m_display = OpenDisplay(); // Get the owner window and its device context m_window = static_cast< ::Window>(owner->getSystemHandle()); // Create the context if (m_window) createContext(shared, bitsPerPixel, settings); }
void init_display(int argc, char **argv, MyProgram *me) { Widget w[5]; if (OpenDisplay(argc, argv) == FALSE) return; w[0] = MakeButton("Pattern #1", pattern1, me); w[1] = MakeButton("Pattern #2", pattern2, me); w[2] = MakeButton("Quit!", quit, me); w[3] = MakeLabel("Bitmap demo program"); w[4] = MakeDrawArea(X_SIZE, Y_SIZE, redisplay, me); SetWidgetPos(w[1], PLACE_RIGHT, w[0], NO_CARE, NULL); SetWidgetPos(w[2], PLACE_RIGHT, w[1], NO_CARE, NULL); SetWidgetPos(w[3], PLACE_RIGHT, w[2], NO_CARE, NULL); SetWidgetPos(w[4], PLACE_UNDER, w[0], NO_CARE, NULL); /* This call actually causes the whole thing to be displayed on the * screen. You have to call this function before doing any drawing * into the window. */ ShowDisplay(); /* Get standard (red, blue, green, yellow, black, white) colors for * drawing stuff. Check libsx.h for more info. */ GetStandardColors(); /* If you wanted to get all the colors in the colormap, you'd do the * following : * * GetAllColors(); * SetColorMap(GREY_SCALE_1); * * You can wait to do it till later if you want. There's no need * to do it here if you don't need to (because it wacks out the * colormap). Check libsx.h for other colormap types you can * ask for (like RAINBOW_{1,2} or GREY_SCALE_{1,2}). */ }
Vector2i InputImpl::getMousePosition() { // Open a connection with the X server Display* display = OpenDisplay(); // we don't care about these but they are required ::Window root, child; int x, y; unsigned int buttons; int gx = 0; int gy = 0; XQueryPointer(display, DefaultRootWindow(display), &root, &child, &gx, &gy, &x, &y, &buttons); // Close the connection with the X server CloseDisplay(display); return Vector2i(gx, gy); }
HDISPLAY GetMainDisplay(HDEVICE device) { int index = 0; HDISPLAY display = NULL; while ((index < MAX_DISPLAYS)) { if (!(display = OpenDisplay(device, index))) { index++; continue; } if (IsDisplayConnected(display)) { break; } ReleaseDisplay(display); display = NULL; index++; } return display; }
/* * Menu functions. */ Widget MakeMenu(char *name) { int n = 0; Arg wargs[5]; /* Used to set widget resources */ Widget button, menu=NULL; if (lsx_curwin->toplevel == NULL && OpenDisplay(0,NULL) == 0) return NULL; if (name == NULL) return NULL; n = 0; XtSetArg(wargs[n], XtNlabel, name); n++; /* * We create two widgets, the simpleMenu widget is a child of the menu button * widget. We return the reference to the button widget however so that * way the SetXXColor() and SetWidgetFont() functions work as expect * (that is they change the menu button). * * The MakeMenuItem() function is aware of this, and gets the child of * the menu button for creation of the actual menu items. * */ button = XtCreateManagedWidget("menuButton", menuButtonWidgetClass, lsx_curwin->form_widget, wargs, n); if (button) menu = XtCreatePopupShell("menu", simpleMenuWidgetClass, button, NULL, 0); if (menu == NULL) { XtDestroyWidget(button); button = NULL; } return button; }
static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_sys_t *p_sys = NULL; p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = Manage; p_vout->pf_render = NULL; p_vout->pf_display = Display; /* Allocate structure */ p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) ); if( !p_sys ) { msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; } p_sys->p_directfb = NULL; p_sys->p_primary = NULL; p_sys->p_pixels = NULL; p_sys->i_width = 0; p_sys->i_height = 0; /* Init DirectFB */ if( DirectFBInit(NULL,NULL) != DFB_OK ) { msg_Err(p_vout, "Cannot init DirectFB"); return VLC_EGENERIC; } if( OpenDisplay( p_vout ) ) { msg_Err(p_vout, "Cannot create primary surface"); free( p_sys ); return VLC_EGENERIC; } return VLC_SUCCESS; }
GlxContext::GlxContext(GlxContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height) : m_window (0), m_context (NULL), m_ownsWindow(true) { // Open a connection with the X server m_display = OpenDisplay(); // Create the hidden window int screen = DefaultScreen(m_display); m_window = XCreateWindow(m_display, RootWindow(m_display, screen), 0, 0, width, height, 0, DefaultDepth(m_display, screen), InputOutput, DefaultVisual(m_display, screen), 0, NULL); // Create the context createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, settings); }
GlxContext::GlxContext(GlxContext* shared) : m_window (0), m_context (NULL), m_ownsWindow(true) { // Open a connection with the X server m_display = OpenDisplay(); // Create a dummy window (disabled and hidden) int screen = DefaultScreen(m_display); m_window = XCreateWindow(m_display, RootWindow(m_display, screen), 0, 0, 1, 1, 0, DefaultDepth(m_display, screen), InputOutput, DefaultVisual(m_display, screen), 0, NULL); // Create the context createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings()); }
GlxContext::GlxContext(GlxContext* shared) : m_window (0), m_context (NULL), m_ownsWindow(true) { // Open a connection with the X server m_display = OpenDisplay(); m_connection = XGetXCBConnection(m_display); xcb_screen_t* screen = XCBScreenOfDisplay(m_connection, DefaultScreen(m_display)); // Choose the visual according to the context settings XVisualInfo visualInfo = selectBestVisual(m_display, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings()); // Define the window attributes xcb_colormap_t colormap = xcb_generate_id(m_connection); xcb_create_colormap(m_connection, XCB_COLORMAP_ALLOC_NONE, colormap, screen->root, visualInfo.visualid); const uint32_t value_list[] = {colormap}; // Create a dummy window (disabled and hidden) m_window = xcb_generate_id(m_connection); xcb_create_window( m_connection, static_cast<uint8_t>(visualInfo.depth), m_window, screen->root, 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, visualInfo.visualid, XCB_CW_COLORMAP, value_list ); // Create the context createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings()); }
Widget MakeLabel(char *txt) { int n = 0; int bg_color = -1; Arg wargs[5]; /* Used to set widget resources */ Widget label; if (lsx_curwin->toplevel == NULL && OpenDisplay(0, NULL) == 0) return NULL; n = 0; if (txt) { XtSetArg(wargs[n], XtNlabel, txt); n++; } label = XtCreateManagedWidget("label", labelWidgetClass, lsx_curwin->form_widget,wargs,n); if (label == NULL) return NULL; /* this little contortion here is to make sure there is no * border around the label (else it looks exactly like a command * button, and that's confusing) */ n = 0; XtSetArg(wargs[n], XtNbackground, &bg_color); n++; XtGetValues(label, wargs, n); n = 0; XtSetArg(wargs[n], XtNborder, bg_color); n++; XtSetValues(label, wargs, n); return label; } /* end of MakeLabel() */
bool InputImpl::isKeyPressed(Keyboard::Key key) { // Get the corresponding X11 keysym KeySym keysym = 0; switch (key) { case Keyboard::LShift: keysym = XK_Shift_L; break; case Keyboard::RShift: keysym = XK_Shift_R; break; case Keyboard::LControl: keysym = XK_Control_L; break; case Keyboard::RControl: keysym = XK_Control_R; break; case Keyboard::LAlt: keysym = XK_Alt_L; break; case Keyboard::RAlt: keysym = XK_Alt_R; break; case Keyboard::LSystem: keysym = XK_Super_L; break; case Keyboard::RSystem: keysym = XK_Super_R; break; case Keyboard::Menu: keysym = XK_Menu; break; case Keyboard::Escape: keysym = XK_Escape; break; case Keyboard::SemiColon: keysym = XK_semicolon; break; case Keyboard::Slash: keysym = XK_slash; break; case Keyboard::Equal: keysym = XK_equal; break; case Keyboard::Dash: keysym = XK_minus; break; case Keyboard::LBracket: keysym = XK_bracketleft; break; case Keyboard::RBracket: keysym = XK_bracketright; break; case Keyboard::Comma: keysym = XK_comma; break; case Keyboard::Period: keysym = XK_period; break; case Keyboard::Quote: keysym = XK_apostrophe; break; case Keyboard::BackSlash: keysym = XK_backslash; break; case Keyboard::Tilde: keysym = XK_grave; break; case Keyboard::Space: keysym = XK_space; break; case Keyboard::Return: keysym = XK_Return; break; case Keyboard::BackSpace: keysym = XK_BackSpace; break; case Keyboard::Tab: keysym = XK_Tab; break; case Keyboard::PageUp: keysym = XK_Prior; break; case Keyboard::PageDown: keysym = XK_Next; break; case Keyboard::End: keysym = XK_End; break; case Keyboard::Home: keysym = XK_Home; break; case Keyboard::Insert: keysym = XK_Insert; break; case Keyboard::Delete: keysym = XK_Delete; break; case Keyboard::Add: keysym = XK_KP_Add; break; case Keyboard::Subtract: keysym = XK_KP_Subtract; break; case Keyboard::Multiply: keysym = XK_KP_Multiply; break; case Keyboard::Divide: keysym = XK_KP_Divide; break; case Keyboard::Pause: keysym = XK_Pause; break; case Keyboard::F1: keysym = XK_F1; break; case Keyboard::F2: keysym = XK_F2; break; case Keyboard::F3: keysym = XK_F3; break; case Keyboard::F4: keysym = XK_F4; break; case Keyboard::F5: keysym = XK_F5; break; case Keyboard::F6: keysym = XK_F6; break; case Keyboard::F7: keysym = XK_F7; break; case Keyboard::F8: keysym = XK_F8; break; case Keyboard::F9: keysym = XK_F9; break; case Keyboard::F10: keysym = XK_F10; break; case Keyboard::F11: keysym = XK_F11; break; case Keyboard::F12: keysym = XK_F12; break; case Keyboard::F13: keysym = XK_F13; break; case Keyboard::F14: keysym = XK_F14; break; case Keyboard::F15: keysym = XK_F15; break; case Keyboard::Left: keysym = XK_Left; break; case Keyboard::Right: keysym = XK_Right; break; case Keyboard::Up: keysym = XK_Up; break; case Keyboard::Down: keysym = XK_Down; break; case Keyboard::Numpad0: keysym = XK_KP_Insert; break; case Keyboard::Numpad1: keysym = XK_KP_End; break; case Keyboard::Numpad2: keysym = XK_KP_Down; break; case Keyboard::Numpad3: keysym = XK_KP_Page_Down; break; case Keyboard::Numpad4: keysym = XK_KP_Left; break; case Keyboard::Numpad5: keysym = XK_KP_Begin; break; case Keyboard::Numpad6: keysym = XK_KP_Right; break; case Keyboard::Numpad7: keysym = XK_KP_Home; break; case Keyboard::Numpad8: keysym = XK_KP_Up; break; case Keyboard::Numpad9: keysym = XK_KP_Page_Up; break; case Keyboard::A: keysym = XK_a; break; case Keyboard::B: keysym = XK_b; break; case Keyboard::C: keysym = XK_c; break; case Keyboard::D: keysym = XK_d; break; case Keyboard::E: keysym = XK_e; break; case Keyboard::F: keysym = XK_f; break; case Keyboard::G: keysym = XK_g; break; case Keyboard::H: keysym = XK_h; break; case Keyboard::I: keysym = XK_i; break; case Keyboard::J: keysym = XK_j; break; case Keyboard::K: keysym = XK_k; break; case Keyboard::L: keysym = XK_l; break; case Keyboard::M: keysym = XK_m; break; case Keyboard::N: keysym = XK_n; break; case Keyboard::O: keysym = XK_o; break; case Keyboard::P: keysym = XK_p; break; case Keyboard::Q: keysym = XK_q; break; case Keyboard::R: keysym = XK_r; break; case Keyboard::S: keysym = XK_s; break; case Keyboard::T: keysym = XK_t; break; case Keyboard::U: keysym = XK_u; break; case Keyboard::V: keysym = XK_v; break; case Keyboard::W: keysym = XK_w; break; case Keyboard::X: keysym = XK_x; break; case Keyboard::Y: keysym = XK_y; break; case Keyboard::Z: keysym = XK_z; break; case Keyboard::Num0: keysym = XK_0; break; case Keyboard::Num1: keysym = XK_1; break; case Keyboard::Num2: keysym = XK_2; break; case Keyboard::Num3: keysym = XK_3; break; case Keyboard::Num4: keysym = XK_4; break; case Keyboard::Num5: keysym = XK_5; break; case Keyboard::Num6: keysym = XK_6; break; case Keyboard::Num7: keysym = XK_7; break; case Keyboard::Num8: keysym = XK_8; break; case Keyboard::Num9: keysym = XK_9; break; default: keysym = 0; break; } // Sanity checks if (key < 0 || key >= sf::Keyboard::KeyCount) return false; // Open a connection with the X server Display* display = OpenDisplay(); // Convert to keycode xcb_keycode_t keycode = XKeysymToKeycode(display, keysym); CloseDisplay(display); ScopedXcbPtr<xcb_generic_error_t> error(NULL); // Open a connection with the X server xcb_connection_t* connection = OpenConnection(); // Get the whole keyboard state ScopedXcbPtr<xcb_query_keymap_reply_t> keymap( xcb_query_keymap_reply( connection, xcb_query_keymap(connection), &error ) ); // Close the connection with the X server CloseConnection(connection); if (error) { err() << "Failed to query keymap" << std::endl; return false; } // Check our keycode return (keymap->keys[keycode / 8] & (1 << (keycode % 8))) != 0; }
static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; /* Allocate structure */ vd->sys = sys = malloc(sizeof(*sys)); if (!sys) return VLC_ENOMEM; sys->directfb = NULL; sys->primary = NULL; sys->width = 0; sys->height = 0; sys->pool = NULL; /* Init DirectFB */ if (DirectFBInit(NULL,NULL) != DFB_OK) { msg_Err(vd, "Cannot init DirectFB"); free(sys); return VLC_EGENERIC; } if (OpenDisplay(vd)) { msg_Err(vd, "Cannot create primary surface"); Close(VLC_OBJECT(vd)); return VLC_EGENERIC; } /* */ video_format_t fmt = vd->fmt; switch (sys->pixel_format) { case DSPF_RGB332: /* 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0) */ fmt.i_chroma = VLC_CODEC_RGB8; fmt.i_rmask = 0x7 << 5; fmt.i_gmask = 0x7 << 2; fmt.i_bmask = 0x3 << 0; break; case DSPF_RGB16: /* 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0) */ fmt.i_chroma = VLC_CODEC_RGB16; fmt.i_rmask = 0x1f << 11; fmt.i_gmask = 0x3f << 5; fmt.i_bmask = 0x1f << 0; break; case DSPF_RGB24: /* 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0) */ fmt.i_chroma = VLC_CODEC_RGB24; fmt.i_rmask = 0xff << 16; fmt.i_gmask = 0xff << 8; fmt.i_bmask = 0xff << 0; break; case DSPF_RGB32: /* 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0) */ fmt.i_chroma = VLC_CODEC_RGB32; fmt.i_rmask = 0xff << 16; fmt.i_gmask = 0xff << 8; fmt.i_bmask = 0xff << 0; break; default: msg_Err(vd, "unknown screen depth %i", sys->pixel_format); Close(VLC_OBJECT(vd)); return VLC_EGENERIC; } fmt.i_width = sys->width; fmt.i_height = sys->height; /* */ vout_display_info_t info = vd->info; info.has_hide_mouse = true; /* */ vd->fmt = fmt; vd->info = info; vd->get = Get; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = Manage; /* */ vout_display_SendEventFullscreen(vd, true); vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height, true); return VLC_SUCCESS; }
std::vector<VideoMode> VideoModeImpl::getFullscreenModes() { std::vector<VideoMode> modes; // Open a connection with the X server Display* display = OpenDisplay(); if (display) { // Retrieve the default screen number int screen = DefaultScreen(display); // Check if the XRandR extension is present int version; if (XQueryExtension(display, "RANDR", &version, &version, &version)) { // Get the current configuration XRRScreenConfiguration* config = XRRGetScreenInfo(display, RootWindow(display, screen)); if (config) { // Get the available screen sizes int nbSizes; XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes); if (sizes && (nbSizes > 0)) { // Get the list of supported depths int nbDepths = 0; int* depths = XListDepths(display, screen, &nbDepths); if (depths && (nbDepths > 0)) { // Combine depths and sizes to fill the array of supported modes for (int i = 0; i < nbDepths; ++i) { for (int j = 0; j < nbSizes; ++j) { // Convert to VideoMode VideoMode mode(sizes[j].width, sizes[j].height, depths[i]); // Add it only if it is not already in the array if (std::find(modes.begin(), modes.end(), mode) == modes.end()) modes.push_back(mode); } } // Free the array of depths XFree(depths); } } // Free the configuration instance XRRFreeScreenConfigInfo(config); } else { // Failed to get the screen configuration err() << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl; } } else { // XRandr extension is not supported : we cannot get the video modes err() << "Failed to use the XRandR extension while trying to get the supported video modes" << std::endl; } // Close the connection with the X server CloseDisplay(display); } else { // We couldn't connect to the X server err() << "Failed to connect to the X server while trying to get the supported video modes" << std::endl; } return modes; }
CursorImpl::CursorImpl() : m_display(OpenDisplay()), m_cursor(None) { // That's it. }