错误:“坏设备”未在此范围内声明

error: ‘BadDevice’ was not declared in this scope

本文关键字:范围内 声明 坏设备 错误      更新时间:2023-10-16

知道为什么我会得到这个错误吗?

error: ‘BadDevice’ was not declared in this scope

我包括:

#include <X11/Xlib.h>

#include <X11/extensions/XInput2.h>

在我的类头文件中。

我是这样使用它的:

 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;
        }

干杯

加里特

这就是你使用它的方式

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

或尝试(也尝试使用您的函数)

int rc;
if (!(rc = XIGrabDevice(dpy, 2,  win, CurrentTime, None, GrabModeAsync,
                       GrabModeAsync, False, &mask)))
{
    fprintf(stderr, "Grab failed with %dn", rc);
    return;
}
似乎要么是BadValue,要么是

BadDevice,要么是BadMatch...将是一个 int 值,它们可能不会在头文件中定义,所以我会检查以确保它们在某个地方。因此,请尝试使用 ret 变量。您的错误代码可能是 1、2、3、4,也可能是 1 或 0。您必须自己定义错误代码。

以下是其他人如何使用XIGrabDevice的示例程序:http://people.freedesktop.org/~whot/xi2-recipes/part5.c