Beispiel #1
0
int main(void)
{
    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
        die("could not init SDL");

    SDL_JoystickEventState(SDL_ENABLE);

    if(!open_joysticks())
        die("could not initialize any joysticks");

    Display * dpy = XOpenDisplay(NULL);
    if(!dpy)
        die("could not connect to X display");

    int _;
    if(!XQueryExtension(dpy, "XTEST", &_, &_, &_))
        die("XTEST extension is not supported by X server");

    SDL_Event ev;
    int horz = 0;
    int vert = 0;
    for(;;)
    {
        for(int i = 0; i < 10; ++i)
        {
            while(SDL_PollEvent(&ev))
            {
                if(ev.type == SDL_QUIT)
                    quit(0);
                if(ev.type != SDL_JOYAXISMOTION)
                    continue;

                int val = ev.jaxis.value;
                if(abs(val) < THRESHOLD)
                    val = 0;

                if(ev.jaxis.axis % 2 == 0)
                    horz = val;
                else
                    vert = val;
            }
            usleep(1000);
        }
        // abs() the value passed to pow() since it can't handle a negative
        // with a non-int exponent, and then turn the result back into a
        // negative if needed
        int horz_px = (int)pow(abs(horz) * 0.0001, 2.7) * (horz >= 0 ? 1 : -1);
        int vert_px = (int)pow(abs(vert) * 0.0001, 2.7) * (vert >= 0 ? 1 : -1);
        if(horz_px != 0 || vert_px != 0)
        {
            //fprintf(stderr, "ev %d %d -> %d %d\n", horz, vert, horz_px, vert_px);
            XTestFakeRelativeMotionEvent(dpy, horz_px, vert_px, CurrentTime);
            XSync(dpy, False);
        }
    }
    quit(0);
}
Beispiel #2
0
/* function: queryextensions_x11display
 * Initializes extension variables of <x11display_t>.
 * It is expected that memory of all extension variables is set to zero
 * before you call this function. */
static int queryextensions_x11display(x11display_t * x11disp)
{
   int   major ;
   int   minor ;
   int   dummy ;
   Bool  isSupported ;

   isSupported = XQueryExtension(x11disp->sys_display, "DOUBLE-BUFFER", &dummy, &x11disp->xdbe.eventbase, &x11disp->xdbe.errorbase) ;
   if (isSupported) {
      isSupported = XdbeQueryExtension(x11disp->sys_display, &major, &minor) ;
      if (isSupported) {
         x11disp->xdbe.isSupported   = true ;
         x11disp->xdbe.version_major = (uint16_t) major ;
         x11disp->xdbe.version_minor = (uint16_t) minor ;
      }
   }

   isSupported = XQueryExtension(x11disp->sys_display, "RANDR", &dummy, &x11disp->xrandr.eventbase, &x11disp->xrandr.errorbase) ;
   if (isSupported) {
      isSupported = XRRQueryVersion(x11disp->sys_display, &major, &minor) ;
      if (isSupported) {
         x11disp->xrandr.isSupported   = true ;
         x11disp->xrandr.version_major = (uint16_t) major ;
         x11disp->xrandr.version_minor = (uint16_t) minor ;

         // prepare receiving events
         for (int i = ScreenCount(x11disp->sys_display); (--i) >= 0 ;) {
            XRRSelectInput(x11disp->sys_display, RootWindow(x11disp->sys_display,i), RRScreenChangeNotifyMask) ;
         }
      }
   }

   isSupported = XQueryExtension(x11disp->sys_display, "RENDER", &dummy, &x11disp->xrender.eventbase, &x11disp->xrender.errorbase) ;
   if (isSupported) {
      isSupported = XRenderQueryVersion(x11disp->sys_display, &major, &minor) ;
      if (isSupported) {
         x11disp->xrender.isSupported   = true ;
         x11disp->xrender.version_major = (uint16_t) major ;
         x11disp->xrender.version_minor = (uint16_t) minor ;
      }
   }

   return 0 ;
}
Beispiel #3
0
void *cursor_motion_thread(void *targs) {

    struct MCursor *this = (struct MCursor *)targs;
 
    Display *dpy;
    int xi_opcode, event, error;
    XEvent ev;

    dpy = XOpenDisplay(NULL);

    if (!dpy) {
    	MLOGE("Failed to open display.\n");
    	return (void *)-1;
    }

    if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &event, &error)) {
       MLOGE("X Input extension not available.\n");
       XCloseDisplay(dpy);
       return (void *)-1;
    }

    if (!has_xi2(dpy)){
        XCloseDisplay(dpy);
        return (void *)-1;
    }
       

    /* select for XI2 events */
    select_events(dpy, DefaultRootWindow(dpy));

    while(1) 
    {
    	XGenericEventCookie *cookie = &ev.xcookie;
    	Window      	root_ret, child_ret;
    	int         	root_x, root_y;
    	int         	win_x, win_y;
    	unsigned int    mask;

    	XNextEvent(dpy, &ev);

    	if (cookie->type == GenericEvent && cookie->extension == xi_opcode && XGetEventData(dpy, cookie)){
            
            if (cookie->evtype == XI_RawMotion) {
                XQueryPointer(dpy, DefaultRootWindow(dpy), &root_ret, &child_ret, &root_x, &root_y, &win_x, &win_y, &mask);
                update_cursor(dpy, this->mMdpy, &this->mBuffer, root_x, root_y);
            }

            XFreeEventData(dpy, cookie);
        }

    	
    }
 
    XCloseDisplay(dpy);
    return NULL;
}
Beispiel #4
0
void Extensions::addData( const char* name )
    {
    assert( data_nextensions < 32 );
    int opcode, event_base, error_base;
    XQueryExtension( display(), name, &opcode, &event_base, &error_base );
    data_extensions[ data_nextensions ] = name;
    data_opcodes[ data_nextensions ] = opcode;
    data_error_bases[ data_nextensions ] = error_base;
    ++data_nextensions;
    }
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, &currentRotation);

                // 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;
}
Beispiel #6
0
static void
meta_backend_x11_post_init (MetaBackend *backend)
{
  MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
  MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
  int major, minor;

  priv->xdisplay = clutter_x11_get_default_display ();

  priv->source = x_event_source_new (backend);

  if (!XSyncQueryExtension (priv->xdisplay, &priv->xsync_event_base, &priv->xsync_error_base) ||
      !XSyncInitialize (priv->xdisplay, &major, &minor))
    meta_fatal ("Could not initialize XSync");

  {
    int major = 2, minor = 3;
    gboolean has_xi = FALSE;

    if (XQueryExtension (priv->xdisplay,
                         "XInputExtension",
                         &priv->xinput_opcode,
                         &priv->xinput_error_base,
                         &priv->xinput_event_base))
      {
        if (XIQueryVersion (priv->xdisplay, &major, &minor) == Success)
          {
            int version = (major * 10) + minor;
            if (version >= 22)
              has_xi = TRUE;
          }
      }

    if (!has_xi)
      meta_fatal ("X server doesn't have the XInput extension, version 2.2 or newer\n");
  }

  take_touch_grab (backend);

  priv->xcb = XGetXCBConnection (priv->xdisplay);
  if (!xkb_x11_setup_xkb_extension (priv->xcb,
                                    XKB_X11_MIN_MAJOR_XKB_VERSION,
                                    XKB_X11_MIN_MINOR_XKB_VERSION,
                                    XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS,
                                    NULL, NULL,
                                    &priv->xkb_event_base,
                                    &priv->xkb_error_base))
    meta_fatal ("X server doesn't have the XKB extension, version %d.%d or newer\n",
                XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION);

  g_signal_connect_object (clutter_device_manager_get_default (), "device-added",
                           G_CALLBACK (on_device_added), backend, 0);

  META_BACKEND_CLASS (meta_backend_x11_parent_class)->post_init (backend);
}
gboolean
supports_xinput_devices (void)
{
        gint op_code, event, error;

        return XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
                                "XInputExtension",
                                &op_code,
                                &event,
                                &error);
}
static void
clutter_backend_x11_create_device_manager (ClutterBackendX11 *backend_x11)
{
  ClutterEventTranslator *translator;
  ClutterBackend *backend;

#ifdef HAVE_XINPUT_2
  if (clutter_enable_xinput)
    {
      int event_base, first_event, first_error;

      if (XQueryExtension (backend_x11->xdpy, "XInputExtension",
                           &event_base,
                           &first_event,
                           &first_error))
        {
          int major = 2;
          int minor = 3;

          if (XIQueryVersion (backend_x11->xdpy, &major, &minor) != BadRequest)
            {
              CLUTTER_NOTE (BACKEND, "Creating XI2 device manager");
              backend_x11->has_xinput = TRUE;
              backend_x11->device_manager =
                g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_XI2,
                              "backend", backend_x11,
                              "opcode", event_base,
                              NULL);

              backend_x11->xi_minor = minor;
            }
        }
    }

  if (backend_x11->device_manager == NULL)
#endif /* HAVE_XINPUT_2 */
    {
      CLUTTER_NOTE (BACKEND, "Creating Core device manager");
      backend_x11->has_xinput = FALSE;
      backend_x11->device_manager =
        g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_X11,
                      "backend", backend_x11,
                      NULL);

      backend_x11->xi_minor = -1;
    }

  backend = CLUTTER_BACKEND (backend_x11);
  backend->device_manager = backend_x11->device_manager;

  translator = CLUTTER_EVENT_TRANSLATOR (backend_x11->device_manager);
  _clutter_backend_add_event_translator (backend, translator);
}
Beispiel #9
0
int
dm_validXType(char *dpy_string, char *name)
{
    if (strcmp(name, "wgl")==0) {
#ifdef DM_WGL
	return 1;
#else
	bu_log("Specified display type [%s] is not available in this compilation.", name);
#endif /* DM_WGL */
	return 0;
    }

    if (strcmp(name, "ogl")==0) {
#ifdef DM_OGL
	Display *dpy;
	int return_val;
	if ((dpy = XOpenDisplay(dpy_string)) != NULL) {
	    if (XQueryExtension(dpy, "GLX", &return_val, &return_val, &return_val)) {
		XCloseDisplay(dpy);
		return 1;
	    }
	    XCloseDisplay(dpy);
	}
#else
	bu_log("Specified display type [%s] is not available in this compilation.", name);
#endif /* DM_OGL */
	return 0;
    }

    if (strcmp(name, "X")==0) {
#ifdef DM_X
	Display *dpy;
	if ((dpy = XOpenDisplay(dpy_string)) != NULL) {
	    XCloseDisplay(dpy);
	    return 1;
	}
#else
	bu_log("Specified display type [%s] is not available in this compilation.", name);
#endif /* DM_X */
	return 0;
    }

    if (strcmp(name, "tk")==0) {
#ifdef DM_TK
	return 1;
#else
	bu_log("Specified display type [%s] is not available in this compilation.", name);
#endif /* DM_TK */
	return 0;
    }

    return 0;
}
int main() {
    /* Connect to the X server */
    Display *display = XOpenDisplay(NULL);
    Window win_root = XDefaultRootWindow(display);

/* XInput Extension available? */
    int opcode, event, error;
    if (!XQueryExtension(display, "XInputExtension", &opcode, &event, &error)) {
        printf("X Input extension not available.\n");
        return -1;
    }

/* Which version of XI2? We support 2.0 */
    int major = 2, minor = 0;
    if (XIQueryVersion(display, &major, &minor) == BadRequest) {
        printf("XI2 not available. Server supports %d.%d\n", major, minor);
        return -1;
    }


    XIDetachSlaveInfo info;
    info.type = XIDetachSlave;
    info.deviceid = 10;

    XIAnyHierarchyChangeInfo any_info;
    any_info.type = XIDetachSlave;
    any_info.detach = info;
    XIChangeHierarchy(display, &any_info, 1);

    printf("Detached slave device 10\n");

    int master_id = get_master_keyboard_id(display);
    if (master_id == -1){
        printf("No master keyboard available.\n");
        return -1;
    }

    std::this_thread::sleep_for(std::chrono::seconds(10));

    XIAttachSlaveInfo attach_info;
    attach_info.type = XIAttachSlave;
    attach_info.deviceid = 10;
    attach_info.new_master = master_id;
    XIAnyHierarchyChangeInfo any_attach_info;
    any_attach_info.type = XIAttachSlave;
    any_attach_info.attach = attach_info;
    XIChangeHierarchy(display, &any_attach_info, 1);

    printf("Attached slave device 10\n");

    XCloseDisplay(display);
}
Beispiel #11
0
int XvGrabber::getgrabber()
{
	Tk_Window tk = Tcl::instance().tkmain();
	Display* dpy = Tk_Display(tk);

	int majop, eventbase, errbase;
	if (XQueryExtension(dpy, "XVideo", &majop,
			    &eventbase, &errbase) == False)
		return (-1);

	Window root = DefaultRootWindow(dpy);
	u_int ngrabbers=0;
	XvAdaptorInfo* grabbers;
	if (XvQueryAdaptors(dpy, root, &ngrabbers, &grabbers) != Success)
	  return (-1);
	if (ngrabbers > 1)
	  fprintf(stderr, "XVgrabber: warning: more than one frame grabber\n");
		
        for (int i=2; i<ngrabbers; i++) {
          //if ((grabbers[i].type)&XvOutputMask) {
          if ((grabbers[i].type)&XvInputMask) {
	    fprintf(stderr, "Xv %d grabber: %s\n",i,grabbers[i].name);
	    strncpy(grabber_name, grabbers[i].name, sizeof(grabber_name));
	    grabID_ = grabbers[i].base_id;
          }
        }
        if (!grabID_) return (-1);

	XvFreeAdaptorInfo(grabbers);

	XvQueryEncodings(dpy, grabID_, &nencodings, &encoding);
#if 1
	printf("Encodings(%d): ", nencodings);
	for (int i=0; i<nencodings; i++)
	  printf("%s %d %d\n", encoding[i].name,
		 encoding[i].width, encoding[i].height);
	printf("\n");
#endif

	XAbrightness = XInternAtom(dpy, "XV_BRIGHTNESS", False);
	XAcontrast = XInternAtom(dpy, "XV_CONTRAST", False);
	XAhue = XInternAtom(dpy, "XV_HUE", False);
	XAsaturation = XInternAtom(dpy, "XV_SATURATION", False);
	XAencoding = XInternAtom(dpy, "XV_ENCODING", False);

	XvGetPortAttribute(dpy, grabID_, XAencoding, (int *)&encodingid_);

	if (!XMatchVisualInfo(dpy, Tk_ScreenNumber(tk), 24, TrueColor, &vinfo_))
		return (-1);

	return (0);
}
int x11_window_init(void)
{ 
  int i;
#ifdef USE_MITSHM
  shm_info.shmaddr = NULL;
  /* get XExtensions to see if mit shared memory is available */
  if (XQueryExtension (display, "MIT-SHM", &i, &i, &i))
    mit_shm_available = 1;
  else
    fprintf (stderr, "X-Server Doesn't support MIT-SHM extension\n");
#endif
  return SYSDEP_DISPLAY_WINDOWED|SYSDEP_DISPLAY_EFFECTS;
}
Beispiel #13
0
Datei: glx.c Projekt: dborca/sage
Bool
glXQueryExtension (Display *dpy, int *errorBase, int *eventBase)
{
    int major_op, erb, evb;
    Bool rv;

    rv = XQueryExtension(dpy, "GLX", &major_op, &evb, &erb);
    if (rv) {
	if (errorBase) *errorBase = erb;
	if (eventBase) *eventBase = evb;
    }
    return rv;
}
int
main (int    argc,
      char **argv)
{
        GError *error = NULL;
        int     op, event, err;

#ifdef ENABLE_NLS
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
# endif
        textdomain (GETTEXT_PACKAGE);
#endif

        if (error) {
                fprintf (stderr, "%s\n", error->message);
                exit (1);
        }

        if (! gtk_init_with_args (&argc, &argv, NULL, NULL, NULL, &error)) {
                fprintf (stderr, "%s", error->message);
                g_error_free (error);
                exit (1);
        }

        if (! XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XF86_VIDMODE_NAME, &op, &event, &err)) {
                g_message ("no " XF86_VIDMODE_NAME " extension");
        } else {
# ifdef HAVE_XF86VMODE_GAMMA
                int major;
                int minor;

                if (! XF86VidModeQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor)) {
                        g_message ("unable to get " XF86_VIDMODE_NAME " version");
                } else {
                        g_message (XF86_VIDMODE_NAME " version %d.%d", major, minor);
                }
# else /* !HAVE_XF86VMODE_GAMMA */
                g_message ("no support for display's " XF86_VIDMODE_NAME " extension");
# endif /* !HAVE_XF86VMODE_GAMMA */
        }

        gs_debug_init (TRUE, FALSE);

        test_fade ();

        gs_debug_shutdown ();

        return 0;
}
Beispiel #15
0
void extensions_init(void) {
    int event, error;
    if (!XQueryExtension(display, "XInputExtension", &xi_ext_opcode, &event, &error))
        bail("XInput extension is not available.");

    int major_op = 2;
    int minor_op = 2;

    int result = XIQueryVersion(display, &major_op, &minor_op);
    if (result == BadRequest)
        bail("XI2 is not supported in a sufficient version (or at all).");
    else if (result != Success)
        bail("Failed to query XI2 extension.");
}
Beispiel #16
0
//////////////////////////////////////////////////////////////////////////
// Factory method for generating the correct type of autotype method, based
// on
//   1. User preference
//   2. XTEST extension availability
//
AutotypeMethodBase* GetAutotypeMethod(Display* disp,
									pws_os::AutotypeMethod method_preference)
{
  int major_opcode, first_event, first_error;
  AutotypeMethodBase *method_ptr = nullptr;
  if (method_preference != pws_os::ATMETHOD_XSENDKEYS &&
			XQueryExtension(disp, "XTEST", &major_opcode, &first_event, &first_error)) {
    method_ptr = new AutotypeMethodXTEST(disp, true); // true => emulate modifiers independently
  }
  else {
	method_ptr = new AutotypeMethodSendKeys(disp, false); // false => no emulation for modifier keys
  }
  return method_ptr;
}
Beispiel #17
0
////////////////////////////////////////////////////////////
/// Switch to fullscreen mode
////////////////////////////////////////////////////////////
void WindowImplX11::SwitchToFullscreen(const VideoMode& Mode)
{
    // Check if the XRandR extension is present
    int Version;
    if (XQueryExtension(ourDisplay, "RANDR", &Version, &Version, &Version))
    {
        // Get the current configuration
        XRRScreenConfiguration* Config = XRRGetScreenInfo(ourDisplay, RootWindow(ourDisplay, ourScreen));
        if (Config)
        {
            // Get the current rotation
            Rotation CurrentRotation;
            myOldVideoMode = XRRConfigCurrentConfiguration(Config, &CurrentRotation);

            // Get the available screen sizes
            int NbSizes;
            XRRScreenSize* Sizes = XRRConfigSizes(Config, &NbSizes);
            if (Sizes && (NbSizes > 0))
            {
                // Search a matching size
                for (int i = 0; i < NbSizes; ++i)
                {
                    if ((Sizes[i].width == static_cast<int>(Mode.Width)) && (Sizes[i].height == static_cast<int>(Mode.Height)))
                    {
                        // Switch to fullscreen mode
                        XRRSetScreenConfig(ourDisplay, Config, RootWindow(ourDisplay, ourScreen), i, CurrentRotation, CurrentTime);

                        // Set "this" as the current fullscreen window
                        ourFullscreenWindow = this;
                        break;
                    }
                }
            }

            // Free the configuration instance
            XRRFreeScreenConfigInfo(Config);
        }
        else
        {
            // Failed to get the screen configuration
            std::cerr << "Failed to get the current screen configuration for fullscreen mode, switching to windiw mode" << std::endl;
        }
    }
    else
    {
        // XRandr extension is not supported : we cannot use fullscreen mode
        std::cerr << "Fullscreen is not supported, switching to window mode" << std::endl;
    }
}
Beispiel #18
0
/*****************************************************************************
 * OpenDisplay: open and initialize OpenGL device
 *****************************************************************************/
static int CheckGLX( vlc_object_t *p_this, vlc_bool_t *b_glx13 )
{
    Display *p_display = NULL;
    int i_opcode, i_evt, i_err = 0;
    int i_maj, i_min = 0;

    /* Open the display */
    p_display = XOpenDisplay( NULL );
    if( p_display == NULL )
    {
        msg_Err( p_this, "Cannot open display" );
        return VLC_EGENERIC;
    }

    /* Check for GLX extension */
    if( !XQueryExtension( p_display, "GLX", &i_opcode, &i_evt, &i_err ) )
    {
        msg_Err( p_this, "GLX extension not supported" );
        XCloseDisplay( p_display );
        return VLC_EGENERIC;
    }
    if( !glXQueryExtension( p_display, &i_err, &i_evt ) )
    {
        msg_Err( p_this, "glXQueryExtension failed" );
        XCloseDisplay( p_display );
        return VLC_EGENERIC;
    }

    /* Check GLX version */
    if (!glXQueryVersion( p_display, &i_maj, &i_min ) )
    {
        msg_Err( p_this, "glXQueryVersion failed" );
        XCloseDisplay( p_display );
        return VLC_EGENERIC;
    }
    if( i_maj <= 0 || ((i_maj == 1) && (i_min < 3)) )
    {
        *b_glx13 = VLC_FALSE;
        msg_Dbg( p_this, "Using GLX 1.2 API" );
    }
    else
    {
        *b_glx13 = VLC_TRUE;
        msg_Dbg( p_this, "Using GLX 1.3 API" );
    }

    XCloseDisplay( p_display );
    return VLC_SUCCESS;
}
Beispiel #19
0
bool AutoTypePlatformX11::isAvailable()
{
    int ignore;

    if (!XQueryExtension(m_dpy, "XInputExtension", &ignore, &ignore, &ignore)) {
        return false;
    }

    if (!XQueryExtension(m_dpy, "XTEST", &ignore, &ignore, &ignore)) {
        return false;
    }

    if (!m_xkb) {
        XkbDescPtr kbd = getKeyboard();

        if (!kbd) {
            return false;
        }

        XkbFreeKeyboard(kbd, XkbAllComponentsMask, True);
    }

    return true;
}
static gboolean
supports_xinput_devices_with_opcode (int *opcode)
{
    gint op_code, event, error;
    gboolean retval;

    retval = XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
                              "XInputExtension",
                              &op_code,
                              &event,
                              &error);
    if (opcode)
        *opcode = op_code;

    return retval;
}
Beispiel #21
0
void MCScreenDC::initatoms()
{
	XSetErrorHandler(xerror);
	XSync( dpy, false ) ;
	
	int ev1, ev2;
	int major, minor;
	Bool pix;
	MCshmpix = False ;
	if (!MCshmoff )
		if ( XQueryExtension(dpy, "MIT-SHM", &shmopcode, &ev1, &ev2))
	        if ( XShmQueryVersion(dpy, &major, &minor, &pix))
	{
		MCshm = True;
		MCshmpix = pix; // For shared memory pixmap's we need this to be true as well...
	}

	create_stipple();

	selectionatom = XInternAtom(dpy, SELECTIONNAME, False);
	
	MCprotocolatom = XInternAtom(dpy, "WM_PROTOCOLS", False);
	MCtakefocusatom = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
	MCdeletewindowatom = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
	MCstateatom = XInternAtom(dpy, "WM_STATE", False);
	MCmwmmessageatom = XInternAtom(dpy, "_MOTIF_WM_MESSAGES", True);
	MCmwmhintsatom = XInternAtom(dpy, "_MOTIF_WM_HINTS", True);
	
#ifdef OLWM
	MColwinatom = XInternAtom(dpy, "_OL_WIN_ATTR" , True);
	MColwtotheratom = XInternAtom(dpy, "_OL_WT_OTHER", True);
	MColwtpropatom = XInternAtom(dpy, "_OL_WT_PROP", True);
	MColadecoratom = XInternAtom(dpy, "_OL_DECOR_ADD", True);
	MColddecoratom = XInternAtom(dpy, "_OL_DECOR_DEL", True);
	MColresizeatom = XInternAtom(dpy, "_OL_DECOR_RESIZE", True);
	MColheaderatom = XInternAtom(dpy, "_OL_DECOR_HEADER", True);
	MColcloseatom = XInternAtom(dpy, "_OL_DECOR_CLOSE", True);
#endif
	
	MClayeratom = XInternAtom(dpy, "_WIN_LAYER", False);
	MCclipboardatom = XInternAtom(dpy, "CLIPBOARD", False);
	
	MCclientlistatom = XInternAtom(dpy, "_NET_CLIENT_LIST", True);
	MCstrutpartialatom = XInternAtom(dpy, "_NET_WM_STRUT_PARTIAL", True);
	MCworkareaatom = XInternAtom(dpy, "_NET_WORKAREA", True);
}
Beispiel #22
0
int main (int argc, char **argv)
{
    Display *dpy;
    int xi_opcode, event, error;
    Window win;
    XEvent ev;

    dpy = XOpenDisplay(NULL);

    if (!dpy) {
        fprintf(stderr, "Failed to open display.\n");
        return -1;
    }

    if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &event, &error)) {
           printf("X Input extension not available.\n");
              return -1;
    }

    if (!has_xi2(dpy))
        return -1;

    /* Create a simple window */
    win = create_win(dpy);

    /* select for XI2 events */
    select_events(dpy, win);

    while(1) {
        XGenericEventCookie *cookie = &ev.xcookie;

        XNextEvent(dpy, &ev);

        if (cookie->type != GenericEvent ||
            cookie->extension != xi_opcode)
            continue;

        if (XGetEventData(dpy, cookie))
        {
            printf("Event type %d received\n", cookie->evtype);
            XFreeEventData(dpy, &ev.xcookie);
        }
    }

    return 0;
}
Beispiel #23
0
static Object P_Query_Extension (Object d, Object name) {
    int opcode, event, error;
    Object ret, t;
    GC_Node2;

    Check_Type (d, T_Display);
    if (!XQueryExtension (DISPLAY(d)->dpy, Get_Strsym (name), &opcode,
            &event, &error))
        return False;
    t = ret = P_Make_List (Make_Integer (3), Null);
    GC_Link2 (ret, t);
    Car (t) = (opcode ? Make_Integer (opcode) : False); t = Cdr (t);
    Car (t) = (event ? Make_Integer (event) : False); t = Cdr (t);
    Car (t) = (error ? Make_Integer (error) : False);
    GC_Unlink;
    return ret;
}
void rmdQueryExtensions(Display *dpy,
                        ProgArgs *args,
                        int *damage_event,
                        int *damage_error,
                        int *shm_opcode) {
    int xf_event_basep,
        xf_error_basep,
        shm_event_base,
        shm_error_base,
        shape_event_base,
        shape_error_base;

    if((!(args->full_shots))&&(!XDamageQueryExtension( dpy, damage_event, damage_error))) {
        fprintf(stderr,"XDamage extension not found!!!\n"
                "Try again using the --full-shots option, though\n"
                "enabling XDamage is highly recommended,\n"
                "for performance reasons.\n");
        exit(4);
    }
    if((!args->noshared)&&(!XQueryExtension(dpy,
                                            "MIT-SHM",
                                            shm_opcode,
                                            &shm_event_base,
                                            &shm_error_base))) {
        args->noshared=1;
        fprintf(stderr,"Shared Memory extension not present!\n"
                "Try again using the --no-shared option\n");
        exit(5);
    }
    if((args->xfixes_cursor)&&
            (XFixesQueryExtension(dpy,&xf_event_basep,&xf_error_basep)==False)) {
        args->xfixes_cursor=0;
        fprintf(stderr,"Xfixes extension not present!\n"
                "Please run with the -dummy-cursor or"
                " --no-cursor option.\n");
        exit(6);
    }
    if((!args->noframe)&&
            (!XShapeQueryExtension(dpy,&shape_event_base,&shape_error_base))) {
        fprintf(stderr,"XShape Not Found!!!\n"
                "Frame won't be available.\n");

        args->noframe=1;
    }

}
Beispiel #25
0
static void FShmInit(Display *dpy)
{
	if (FShmInitialized)
	{
		return;
	}

	FShmInitialized = True;

	if (!XShmSupport)
	{
		return;
	}
	FShmImagesSupported = XQueryExtension(
		dpy, "MIT-SHM", &FShmMajorOpCode, &FShmEventBase,
		&FShmErrorBase);
}
Beispiel #26
0
JNIEXPORT jboolean JNICALL
    Java_com_sun_media_renderer_video_XLibRenderer_xlibSetComponent(JNIEnv *env,
								    jobject blitter,
								    jobject component)
{
    XWindowAttributes xwa;
    int error;
    XlibBlitter *xblitter = (XlibBlitter*) GetIntField(env, blitter, "blitter");
    
    if (xblitter->display) {
	freeDisplay(*xblitter);
    }
    
    if (xblitter->surface) {
	(*env)->DeleteGlobalRef(env, xblitter->surface);
	xblitter->surface = NULL;
    }
    
    if ( jawt == 1 && xblitter->awtObj != 0) {
	freeJAWT(env, xblitter);
	xblitter->awtObj = 0;
	xblitter->drawingSurface = 0;
    }
    
    xblitter->component = component;
    getComponentInfo(env, xblitter);
    
    awtLock(env, xblitter);
    
    xblitter->screen = DefaultScreen(xblitter->display);
    XGetWindowAttributes(xblitter->display, xblitter->xid, &xwa);
    xblitter->visual = xwa.visual;
    xblitter->depth  = xwa.depth;
    xblitter->bitsPerPixel = (xwa.depth == 8)? 8 : ((xwa.depth < 24)? 16 : 32);
    xblitter->gc = XCreateGC(xblitter->display, xblitter->xid, 0, 0);
    
    xblitter->shmAvailable = XQueryExtension(xblitter->display, "MIT-SHM",
					     &(xblitter->shmOpcode),
					     &(xblitter->shmComplete),
					     &error);
    
    awtUnlock(env, xblitter);
    
    return 1;
}
Beispiel #27
0
GdkDeviceManager *
_gdk_x11_device_manager_new (GdkDisplay *display)
{
  if (!g_getenv ("GDK_CORE_DEVICE_EVENTS"))
    {
#ifdef XINPUT_2
      int opcode, firstevent, firsterror;
      Display *xdisplay;

      xdisplay = GDK_DISPLAY_XDISPLAY (display);

      if (XQueryExtension (xdisplay, "XInputExtension",
                           &opcode, &firstevent, &firsterror))
        {
          int major, minor;

          major = 2;
	  minor = 3;

          if (!_gdk_disable_multidevice &&
              XIQueryVersion (xdisplay, &major, &minor) != BadRequest)
            {
              GdkX11DeviceManagerXI2 *device_manager_xi2;

              GDK_NOTE (INPUT, g_message ("Creating XI2 device manager"));

              device_manager_xi2 = g_object_new (GDK_TYPE_X11_DEVICE_MANAGER_XI2,
                                                 "display", display,
                                                 "opcode", opcode,
                                                 "major", major,
                                                 "minor", minor,
                                                 NULL);

              return GDK_DEVICE_MANAGER (device_manager_xi2);
            }
        }
#endif /* XINPUT_2 */
    }

  GDK_NOTE (INPUT, g_message ("Creating core device manager"));

  return g_object_new (GDK_TYPE_X11_DEVICE_MANAGER_CORE,
                       "display", display,
                       NULL);
}
Beispiel #28
0
static void
init_xinerama_indices (GdkX11Screen *x11_screen)
{
  int opcode, firstevent, firsterror;

  x11_screen->xinerama_matches = g_hash_table_new (g_direct_hash, g_direct_equal);
  if (XQueryExtension (x11_screen->xdisplay, "XINERAMA",
		       &opcode, &firstevent, &firsterror))
    {
      x11_screen->xinerama_matches = g_hash_table_new (g_direct_hash, g_direct_equal);

      /* Solaris Xinerama first, then XFree/Xorg Xinerama
       * to match the order in init_multihead()
       */
      if (init_solaris_xinerama_indices (x11_screen) == FALSE)
        init_xfree_xinerama_indices (x11_screen);
    }
}
/* test if the xrecord extension is found */
Bool
check_xrecord(Display * display)
{

    Bool found;
    Status status;
    int major_opcode, minor_opcode, first_error;
    int version[2];

    found = XQueryExtension(display,
                            "RECORD",
                            &major_opcode, &minor_opcode, &first_error);

    status = XRecordQueryVersion(display, version, version + 1);
    if (verbose && status) {
        printf("X RECORD extension version %d.%d\n", version[0], version[1]);
    }
    return found;
}
Beispiel #30
0
XfwmDevices *
xfwm_devices_new (GdkDisplay *display)
{
    XfwmDevices *devices;
#ifdef HAVE_XI2
    GdkSeat *seat;
    GdkDevice *pointer_device;
    GdkDevice *keyboard_device;
    gint firstevent, firsterror;
#endif

    devices = g_new0 (XfwmDevices, 1);
    devices->xi2_available = FALSE;
    devices->xi2_opcode = 0;

    devices->pointer.keyboard = FALSE;
    devices->pointer.xi2_device = None;

    devices->keyboard.keyboard = TRUE;
    devices->keyboard.xi2_device = None;

#ifdef HAVE_XI2
    seat = gdk_display_get_default_seat (display);
    pointer_device = gdk_seat_get_pointer (seat);
    keyboard_device = gdk_seat_get_keyboard (seat);

    if (GDK_IS_X11_DEVICE_XI2 (pointer_device) || GDK_IS_X11_DEVICE_XI2 (keyboard_device))
    {
        /* GDK uses XI2, let's use it too */

        /* Obtain XI2 opcode */
        if (XQueryExtension (gdk_x11_display_get_xdisplay (display), "XInputExtension",
                             &devices->xi2_opcode, &firstevent, &firsterror))
        {
            devices->xi2_available = TRUE;
            devices->pointer.xi2_device = gdk_x11_device_get_id (pointer_device);
            devices->keyboard.xi2_device = gdk_x11_device_get_id (keyboard_device);
        }
    }
#endif

    return devices;
}