简体   繁体   English

在哪里可以找到Linux中触摸屏显示器的最大分辨率?

[英]Where to find the max resolution for a touchscreen monitor in Linux?

The application that I'm writing has a thread that is constantly polling a /dev/input/eventX location for touch events since the Linux kernel I am running has limited support for touchscreens. 我正在编写的应用程序具有一个线程,该线程不断轮询/dev/input/eventX位置的触摸事件,因为我正在运行的Linux内核对触摸屏的支持有限。 Because of this limited support, QT5 does not receive any touch events, and I have to parse the raw event data from the device. 由于这种有限的支持,QT5不会收到任何触摸事件,因此我必须解析来自设备的原始事件数据。

My method works, but I am getting wildly inaccurate X and Y values for the touch points because I need to scale the coordinates according to the resolution of the monitor. 我的方法可行,但是由于接触点的X和Y值越来越不准确,因为我需要根据显示器的分辨率缩放坐标。 For example, if I use the evtest utility, I'm able to see that the current max X and Y values for this monitor are (15360, 8640), and the monitor resolution is 1920x1080. 例如,如果使用evtest实用程序,则可以看到该监视器的当前最大X和Y值为(15360,8640),并且监视器分辨率为1920x1080。 This would imply I need to scale both X and Y values by 0.125 to get the correct coordinates. 这意味着我需要将X和Y值都缩放0.125,以获得正确的坐标。

Since the evtest utility is able to show me these max X and Y values, I'm assuming that information can be read somewhere, but I can't find any information on where to get that info. 由于evtest实用程序能够向我显示这些最大X和Y值,因此我假设可以在某处读取该信息,但是找不到在何处获取该信息的任何信息。 Could someone tell me where I can find the touchscreen's current max coordinate values? 有人可以告诉我在哪里可以找到触摸屏的当前最大坐标值吗? Also, if it is not in the same location, where can I get the monitor resolution as well? 另外,如果它不在同一位置,那么在哪里也可以获得显示器的分辨率?

I managed to find the source code for the evtest utility that I mentioned and was able to find the max X and Y values of the touchscreen by using the following code snippet: 我设法找到了我提到的evtest实用程序的源代码,并且能够通过使用以下代码段找到触摸屏的最大X和Y值:

const char * filename = "/dev/input/event15";
char * absval[6] = { "Value", "Min", "Max", "Fuzz", "Flat", "Resolution" };
int fd = open(filename, O_RDONLY);
if((fd < 0) && (errno == EACCES) && (getuid() != 0)) {
    cout << "Could not open device file. Try running as root." << endl;
}

int absX[6] = {};
int absY[6] = {};

ioctl(fd, EVIOCGABS(ABS_MT_POSITION_X), absX);
ioctl(fd, EVIOCGABS(ABS_MT_POSITION_Y), absY);

cout << "ABS_MT_POSITION_X Properties" << endl;
for(int x = 0; x < 6; x++) {
    if((x < 3) || absX[x]) {
        cout << absval[x] << ": " << absX[x] << endl;
    }
}

cout << "ABS_MT_POSITION_Y Properties" << endl;
for(int y = 0; y < 6; y++) {
    if((y < 3) || absX[y]) {
        cout << absval[y] << ": " << absY[y] << endl;
    }
}

SCALE_X = (1920.0f / absX[2]);
SCALE_Y = (1080.0f / absY[2]);

close(fd);

This got me the correct scaling amount. 这给了我正确的缩放比例。

Is there a way to do this using C++ libraries? 有没有办法使用C ++库来做到这一点? Or is there no C++ equivalent to ioctl()? 还是没有等效于ioctl()的C ++?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM