如何创建位深度为 32 的窗口 [英] How to create a window with a bit depth of 32

查看:35
本文介绍了如何创建位深度为 32 的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to create a X11 window with a bit depth of 32 so that I can use ARGB colors. Here's what I do:

XVisualInfo vinfo;
int depth = 32;
XMatchVisualInfo(dpy, XDefaultScreen(dpy), depth, TrueColor, &vinfo);
XCreateWindow(dpy, XDefaultRootWindow(dpy), 0, 0, 150, 100, 0, depth, InputOutput,
    vinfo.visual, 0, NULL);

这是发生了什么:

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  1 (X_CreateWindow)
  Serial number of failed request:  7
  Current serial number in output stream:  7

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

Any pointers on why there is a BadMatch error?

推荐答案

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

The problem is this code in the X server 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;
    }

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

i.e. "if depth isn't same as parent depth you have to set the border pixel or pixmap"

这是一个完整的例子

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

这篇关于如何创建位深度为 32 的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆