【问题标题】:How to create a window with a bit depth of 32如何创建位深为 32 的窗口
【发布时间】:2010-09-05 09:41:45
【问题描述】:

我正在尝试创建一个位深度为 32 的 X11 窗口,以便我可以使用 ARGB 颜色。这是我的工作:

XVisualInfo vinfo;
整数深度 = 32;
XMatchVisualInfo(dpy, XDefaultScreen(dpy), 深度, TrueColor, &vinfo);
XCreateWindow(dpy, XDefaultRootWindow(dpy), 0, 0, 150, 100, 0, 深度, InputOutput,
    vinfo.visual, 0, NULL);

会发生什么:

X Error of failed request: BadMatch (invalid parameter attributes)
  失败请求的主要操作码:1(X_CreateWindow)
  失败请求的序列号:7
  输出流中的当前序列号:7

关于为什么会出现 BadMatch 错误的任何指示?

【问题讨论】:

    标签: transparency x11 argb


    【解决方案1】:

    问题是X服务器中的这段代码http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c#n615

      if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) &&
        (class != InputOnly) &&
        (depth != pParent->drawable.depth))
        {
        *error = BadMatch;
        return NullWindow;
        }
    

    即“如果深度与父深度不同,则必须设置边框像素或像素图”

    这是一个完整的例子

    #include <X11/Xlib.h>
    #include <X11/Xutil.h>
    #include <X11/extensions/Xcomposite.h>
    
    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
      Display *dpy;
      XVisualInfo vinfo;
      int depth;
      XVisualInfo *visual_list;
      XVisualInfo visual_template;
      int nxvisuals;
      int i;
      XSetWindowAttributes attrs;
      Window parent;
      Visual *visual;
    
      dpy = XOpenDisplay(NULL);
    
      nxvisuals = 0;
      visual_template.screen = DefaultScreen(dpy);
      visual_list = XGetVisualInfo (dpy, VisualScreenMask, &visual_template, &nxvisuals);
    
      for (i = 0; i < nxvisuals; ++i)
        {
          printf("  %3d: visual 0x%lx class %d (%s) depth %d\n",
                 i,
                 visual_list[i].visualid,
                 visual_list[i].class,
                 visual_list[i].class == TrueColor ? "TrueColor" : "unknown",
                 visual_list[i].depth);
        }
    
      if (!XMatchVisualInfo(dpy, XDefaultScreen(dpy), 32, TrueColor, &vinfo))
        {
          fprintf(stderr, "no such visual\n");
          return 1;
        }
    
      printf("Matched visual 0x%lx class %d (%s) depth %d\n",
             vinfo.visualid,
             vinfo.class,
             vinfo.class == TrueColor ? "TrueColor" : "unknown",
             vinfo.depth);
    
      parent = XDefaultRootWindow(dpy);
    
      XSync(dpy, True);
    
      printf("creating RGBA child\n");
    
      visual = vinfo.visual;
      depth = vinfo.depth;
    
      attrs.colormap = XCreateColormap(dpy, XDefaultRootWindow(dpy), visual, AllocNone);
      attrs.background_pixel = 0;
      attrs.border_pixel = 0;
    
      XCreateWindow(dpy, parent, 10, 10, 150, 100, 0, depth, InputOutput,
                    visual, CWBackPixel | CWColormap | CWBorderPixel, &attrs);
    
      XSync(dpy, True);
    
      printf("No error\n");
    
      return 0;
    }
    

    【讨论】:

    • 当我设置一个边框像素时,我仍然得到一个匹配错误的错误(是的,我在同一个 XCreateWindow() 调用中这样做)。
    • 我猜我的测试程序也设置了颜色图。
    • 谢谢,看来需要一个背景像素、颜色图边框像素。
    • 其实backpixel根本不需要。
    猜你喜欢
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多