【问题标题】:Grab the color of a pixel with Xcb instead of Xlib使用 Xcb 而不是 Xlib 获取像素的颜色
【发布时间】:2017-06-15 05:49:41
【问题描述】:

我使用了几个窗口管理器,如果我理解正确,他们使用 xlib。 (真棒,openbox,fluxbox...)

我使用以下代码检测像素中“RED”的数量:

#include <iostream>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
using namespace std;
int main(int argc, char *argv[]){
    XColor c;
    Display *d = XOpenDisplay((char *) NULL);
    int RED;
    int x=atoi(argv[1]);
    int y=atoi(argv[2]);
    XImage *image;
    image = XGetImage (d, RootWindow (d, DefaultScreen (d)), x, y, 1, 1, AllPlanes, XYPixmap);
    c.pixel = XGetPixel (image, 0, 0);
    XFree (image);
    XQueryColor (d, DefaultColormap(d, DefaultScreen (d)), &c);
    RED=c.red/256;
    cout << RED;
}

但它总是用我的i3-gaps 窗口管理器返回 0。 (与其他 wm 合作)

我猜这是因为i3 不使用Xlib 而是使用Xcb

如果是这样,我如何使用 Xcb 实现相同的目标? (从 Xlib 语法向后兼容的东西?)

【问题讨论】:

  • 窗口管理器与此无关。

标签: c++ xlib xcb


【解决方案1】:

我刚刚将#include &lt;X11/Xlib.h&gt; 替换为#include &lt;xcb/xcb.h&gt;

太棒了……

【讨论】:

  • 这毫无意义。它与窗口管理器是使用 Xlib 还是 XCB 无关,也与替换包含工作无关。那应该无法使用您显示的代码进行编译。
猜你喜欢
  • 1970-01-01
  • 2018-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-30
  • 2017-01-23
  • 1970-01-01
相关资源
最近更新 更多