11

ARGB色を使用できるように、ビット深度32のX11ウィンドウを作成しようとしています。これが私がすることです:

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

何が起こるかです:

X失敗したリクエストのエラー:BadMatch(無効なパラメーター属性)
  失敗したリクエストのメジャーオペコード:1(X_CreateWindow)
  失敗したリクエストのシリアル番号:7
  出力ストリームの現在のシリアル番号:7

BadMatchエラーが発生する理由についてのポインタはありますか?

4

1 に答える 1

16

問題は、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;
}
于 2010-09-05T14:50:47.067 に答える