[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using Xlib in gdk




On Mon, 5 Nov 2001, Efraim Yawitz wrote:

> What do I have to do to draw in a window with Xlib functions inside a gtk
> program. Here is the code I have, which compiles and runs but doesn't draw
> anything:

you're trying to do something that's almost) impossible. if you draw on a
window, without invalidating the drawing, you won't necessarily see the
new drawing. drawing _should_ be done from a 'repaint' event. in X
applications, this is usually done by invalidating a region of the window,
and then doing the actuall painting in the repaint event handling.

also, see more below:

> void xdraw(GtkWidget *window)
> {
> 	Window xwindow;
> 	Display *xdisplay;
> 	GdkGC* gc = gdk_gc_new(window->window);
> 	GC xgc = GDK_GC_XGC(gc);
> 	xwindow = GDK_WINDOW_XWINDOW(window->window);
> 	xdisplay = GDK_WINDOW_XDISPLAY(window->window);
> 	XClearWindow(xdisplay, xwindow);
> 	XSetForeground(xdisplay, xgc, BlackPixel(xdisplay, DefaultScreen(xdisplay)));
> 	XSetBackground(xdisplay, xgc, WhitePixel(xdisplay, DefaultScreen(xdisplay)));
> 	XSetFillStyle(xdisplay, xgc, FillSolid);
> 	XFillRectangle(xdisplay, xwindow, xgc, 0, 0, 3, 3);
> }

basically, what you do here is try to draw over a window thet gtk draws
over. its a racy situation, since gtk will redraw the window again,
according to how _it_ thinks the window should look, on the next repaint
event. if you want to paint in the window, you'll have to do that through
gtk's drawing methods. i don't see an easy way around this. you have

another, very odd, option, thought i'm not sure if xlib supports it.
create a new window (using xlib's functions) as a child of gtk's window,
with the exact same size. when you draw into it - draw using a transparent
background. then your drawing will seem to be done on top of the original
window. ofcourse, when you do that - do the drawing the proper way. i.e.
you'll have to somehow (don't ask me how) make sure _you_ get the repaint
event for the window, not gtk (not sure how it can be done, since gtk runs
its main loop, nd catches all events coming from the X server, to dispatch
them to its own handler functions - perhaps you'll need to create a second
connection to the X server, have the new child window controled by that
thread, with a new X connection, and _maybe_ the events will get
dispatched in the way you wish them to.

in any case, you're walking on shaky ground here...
perhaps if you explain _why_ you need to use xlib's functions, and not
gtk's functions, it'll give us a different direction.

--
guy

"For world domination - press 1,
 or dial 0, and please hold, for the creator." -- nob o. dy


=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il