First up, do I need to create an (initialised) GC before copying into it?
Or does XCopyGC actually initialise the structure with defaults for me?
Then, I'm getting segfaults on the Copy.
/* Create 2 GCs, copy the values of the first into the second */
GC gc1, gc2;
Display *display = XOpenDisplay(NULL);
Window win = XCreateSimpleWindow(etc...);
// those above both worked.
gc1 = XCreateGC(display, win, 0, NULL);
// ... some stuff done here to initialise gc1 with my defaults.
gc2= XCreateGC(display, win, 0, NULL); // is this needed??
// ok so far
XCopyGC(display, gc1, gc2, 0UL);
// ** Wham! seg fault **
Perhaps I am misusing the XCopyGC call, since gcc warns that "parameter 3
makes integer from pointer without cast." Huh? What pointer?
Also, using a 0UL for the valuemask: does that copy everything, or copy
nothing?
If I instead specify some bitmask values for valuemask instead of 0UL:
XCopyGC(display, gc1, gc2, GCForeground | GCBackground | GCFont);
I get another (new) compiler warning that parameter 4 "makes integer from
pointer without cast." Again, what pointer?
Here's the Syntax from the man page for XCreateGC and XCopyGC:
GC XCreateGC(Display *display, Drawable d, unsigned long valuemask,
XGCValues *values);
int XCopyGC(Display *display, GC src, GC dest, unsigned long valuemask);
Not a pointer in sight (except for *display). So why is gcc complaining?
Did XCreateGC actually return a pointer to a GC instead of an actual GC?
in which case, everything I did with gc1 & gc2 should be &gc1 & &gc2?
I'm clearly misreading the man page or not understanding the GC process.
If someone could help me out, much appreciate it.
Thanks,
--
NickC
GC gc1, gc2 :
gc1 = XtAllocateGC (w, 0, 0, &xgc , 0, 0);
XCopyGC (dpy, gc1, 1L, gc2);
--
oops...
Shoudl read gc2 = XtAlloccate..
--
> NickC wrote:
>
>> Here's the Syntax from the man page for XCreateGC and XCopyGC:
>> GC int XCopyGC(Display *display, GC src, GC dest, unsigned long
>> valuemask);
>>
>>
> GC gc1, gc2 :
>
> gc1 = XtAllocateGC (w, 0, 0, &xgc , 0, 0);
> XCopyGC (dpy, gc1, 1L, gc2);
Thank you. I see you've reversed XCopyGC's 3rd & 4th params, and grepping
Xlib.h shows me why. I take it the man page is wrong. Are there errors in
other man pages I need to be aware of?
Thanks again,
--
NickC
> Here's the Syntax from the man page for XCreateGC and XCopyGC:
> GC XCreateGC(Display *display, Drawable d, unsigned long valuemask,
> XGCValues *values);
> int XCopyGC(Display *display, GC src, GC dest, unsigned long valuemask);
The man page listed the parameters of XCopyGC in the wrong order.
It has already been fixed, so there's no need to report it again:
http://cgit.freedesktop.org/xorg/lib/libX11/commit/?id=54c64267cc8bc98641cc39a22cb7bd71673e89e0
https://bugs.launchpad.net/bugs/408337
(It's crazy though that Ubuntu wanted the lspci output and
Xorg.0.log before considering this bug.)
--
NickC
>
> The man page listed the parameters of XCopyGC in the wrong order.
Thanks.
My god, it actually builds and runs now! (Forgive my enthusiasm, but
after days of beating my head against a brick wall, it's easy to get
excited.)
--
NickC
Mixing Xt and Xlib calls is probably not a good idea,
either, if (when) a widget fails an event it doesn't expect,
and if (when) the app runs under a window manager that
generates or propagates X protocol events in a manner it
doesn't expect. It's more reliable to use XCreateGC () if
the app is going to also use XCopyGC () and XFreeGC ().
Btw, a value mask of 0L means that
XCopyGC (dpy, gc1, 0L, gc2) == XCreateGC (dpy, w, 0L, &xgc_values)
HTH again
--
Ctalk Home Page: http://www.ctalklang.org
Ok, I'm using Xlib exclusively now.
> Btw, a value
> mask of 0L means that
>
> XCopyGC (dpy, gc1, 0L, gc2) == XCreateGC (dpy, w, 0L, &xgc_values)
>
Thanks, good to know.
--
NickC