1

any idea why I would be getting this error?:

error: ‘BadDevice’ was not declared in this scope

I have included:

#include <X11/Xlib.h>

and

#include <X11/extensions/XInput2.h>

in my class header file.

I am using it like this:

 int ret = XIGrabDevice(display_, 2,  LinuxInputManager::getWindow(),
                            CurrentTime, None, GrabModeAsync,
                            GrabModeAsync, False, &eventMask_);
        if (ret == BadValue)
            std::cout << "bad value" << std::endl;
        else if (ret == BadDevice)
            std::cout << "BadDevice" << std::endl;
        if (ret == BadMatch)
            std::cout << "BadMatch" << std::endl;
        if (ret == BadWindow)
            std::cout << "BadWindow" << std::endl;

        if (ret) {
            std::cout << "not available 3" << std::endl;
        }

Cheers

Jarrett

Jarrett
  • 1,767
  • 25
  • 47
  • Show us the declaration for `BadDevice`, presumably an `enum` – John Dibling Dec 06 '12 at 16:42
  • well, it's a return value from the function `XIGrabDevice`, which is defined in `X11/extensions/XInput2.h` (ala http://linux.die.net/man/3/xigrabdevice). Do I need to define these by myself?? If so, what values to I assign to them? – Jarrett Dec 06 '12 at 17:14
  • OK, looks like BadDevice isn't defined in the X header files anywhere. However, it is listed on the man page as a possible return value. Maybe the man pages are stale? Not sure... – Jarrett Dec 07 '12 at 16:28
  • Looking at the source code for libxi, it appears you need to do something like `int BadDeviceErrCode; BadDevice(display_, BadDeviceErrCode); if (ret == BadDeviceErrCode) {}` after including X11/extensions/Xinput.h (though the error isn't actually generated by any function in libxi as far as I can tell). – user786653 Dec 08 '12 at 12:13
  • hmmm...wierd...I guess the man page is a little outdated. Oh well. I'll just ignore the error for now :) Thanks @user786653 – Jarrett Dec 10 '12 at 20:15
  • Could it be something to do with the fact that XIGrabDevice returns a stucture and you are setting it equal to an int? – crh225 Dec 11 '12 at 16:56
  • @crh225 No - `XIGrabDevice` returns an int. Status is defined in Xlib.h as `#define Status int`. – Jarrett Dec 13 '12 at 15:49

1 Answers1

0

This is how you use it

int rc;
if ((rc = XIGrabDevice(dpy, 2,  win, CurrentTime, None, GrabModeAsync,
                       GrabModeAsync, False, &mask)) != GrabSuccess)
{
    fprintf(stderr, "Grab failed with %d\n", rc);
    return;
}

or try (also try with your functions)

int rc;
if (!(rc = XIGrabDevice(dpy, 2,  win, CurrentTime, None, GrabModeAsync,
                       GrabModeAsync, False, &mask)))
{
    fprintf(stderr, "Grab failed with %d\n", rc);
    return;
}

It appears that either BadValue, BadDevice, BadMatch... will be an int value, and they might not be defined in the header files so I would check to make sure they are there somewhere. So, try to cout the ret variable. Your error codes might be something like 1, 2, 3, 4 or they could be 1 or 0. You make have to define the error codes yourself.

Here is an example program of how someone else used XIGrabDevice: http://people.freedesktop.org/~whot/xi2-recipes/part5.c

crh225
  • 821
  • 18
  • 34