What my code (below) does:
- Creates a XLIB window with a background color
- Draws a string on the window
- Draws a line on the window
- Creates a GTK+ window
- Makes the GTK+ window realise the XLIB window exsists via a GDK window
- Display the output of the XLIB window inside the GTK+ window
It works and creates a window of the correct colour but it doesn't draw the string or the line on the screen. Any ideas of how to make it appear or where im going wrong?
The reason I am not using the GTK+ drawing functions is because this a test program in reality all the drawing needs to come from the xlib window.
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void destroy(GtkWidget *widget, gpointer data ) {
gtk_main_quit ();
}
int main(int argc, char** argv) {
GtkWidget *xwindow;
//Open the display
Display *display = XOpenDisplay(NULL);
int screen = DefaultScreen(display);
//Create the window
Window w = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0,
200, 100, 20, black, 10201020);
XSelectInput(display, w, StructureNotifyMask);
XMapWindow(display, w);
GC gc = XCreateGC(display, w, 0, NULL);
for(;;) {
XEvent e;
XNextEvent(display, &e);
if (e.type == MapNotify)
break;
}
XDrawString(display, w, gc, 10, 10, "HelloWorld!", 12);
XDrawLine(display, w, gc, 10, 60, 180, 20);
XFlush(display);
//SET UP
gtk_init (&argc, &argv);
//xwindow
xwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect (xwindow, "destroy",
G_CALLBACK (destroy), NULL);
g_signal_connect (xwindow, "destroy",
G_CALLBACK (print), NULL);
gtk_widget_realize(xwindow);
xwindow->window = gdk_window_foreign_new((guint32)w);
//SET UP
gtk_widget_show(xwindow);
gtk_main ();
return 0;
}