In a purely GDK 3.10 (no GTK) project how do I refresh/clear/redraw a transparent background of a GdkWindow?
This test.c
sets the background correctly on initialization (gdk_window_show()) and when I iconify+deiconify the window but not on resizing or moving it around per mouse:
#include <gdk/gdk.h>
// #include <gdk/gdkx.h> // GDK X11
// #include <X11/Xlib.h> // Xlib
// #include <X11/Xutil.h>
void eventHandler(GdkEvent *evt, gpointer data) {
GdkWindow *win = (GdkWindow *)data;
switch(evt->type)
{
case GDK_CONFIGURE: {
// refresh window background here
printf("refresh background here\n");
break;
}
case GDK_DELETE: {
gdk_window_destroy(win);
_exit(0);
break;
}
default:
break;
}
}
int main(int argc, char *argv[]) {
gdk_init(NULL, NULL);
GdkDisplay *disp=gdk_display_get_default();
GdkScreen *scr = gdk_display_get_default_screen (disp);
GdkWindow *root = gdk_screen_get_root_window(scr);
GdkWindowAttr attr;
attr.width=200;
attr.height=200;
attr.x=0;
attr.y=0;
attr.window_type = GDK_WINDOW_TOPLEVEL;
attr.wclass=GDK_INPUT_OUTPUT;
GdkVisual *vis = gdk_screen_get_rgba_visual (scr);
attr.visual = vis;
GdkWindow *newWin=gdk_window_new(root,&attr, GDK_WA_X | GDK_WA_Y);
GdkRGBA color = { .red=1.0, .green=0.0, .blue=1.0, .alpha=0.0};
gdk_window_set_background_rgba(newWin, &color);
gdk_event_handler_set (eventHandler, newWin, NULL);
gdk_window_show(newWin);
GMainLoop *mainloop = g_main_new (TRUE);
g_main_loop_run (mainloop);
gdk_display_close(disp);
return 0;
}
gcc build command:
gcc -o test test.c `pkg-config gdk-3.0 --libs --cflags`
Outcome:
Note: I'm targeting X11 so I'm also allowed to include Xlib or GDK X11 backend functions.
Thank you for any help or pointers.
The solution to this is a fix of a rather silly mistake I made passing an incomplete attribute mask to gdk_window_new()
.
To make it work the line in question has to be changed to:
GdkWindow *newWin=gdk_window_new(root,&attr, GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_WMCLASS);