I have a DND window (a window that follows the cursor during a drag). The problem is that the window is stopping the drag destination from getting drag events, because it’s under the cursor.
The window creation looks like this:
widget = gtk_window_new(GTK_WINDOW_POPUP);
gtk_window_set_type_hint(GTK_WINDOW(widget), GDK_WINDOW_TYPE_HINT_DND);
gtk_widget_set_events(widget, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
gtk_widget_realize(widget);
gtk_widget_set_app_paintable(widget, TRUE);
g_signal_connect(G_OBJECT(widget), "draw", G_CALLBACK(on_draw), this);
g_signal_connect(G_OBJECT(widget), "screen-changed", G_CALLBACK(on_screen_changed), this);
gtk_widget_set_size_request(widget, width, height);
gtk_window_set_decorated(GTK_WINDOW(widget), FALSE);
gtk_window_set_opacity(GTK_WINDOW(widget), .7);
Draw event is this:
void DragView::View::expose(cairo_t *context) {
cairo_surface_t* cairo_surface;
guchar* pixels = is_raw_image
? (guchar*) convert_BGRA_to_RGBA((const int*) gdk_pixbuf_get_pixels(pixbuf),
gdk_pixbuf_get_rowstride(pixbuf),
height)
: gdk_pixbuf_get_pixels(pixbuf);
cairo_surface = cairo_image_surface_create_for_data(
pixels,
CAIRO_FORMAT_ARGB32,
width, height, width * 4);
cairo_set_source_surface(context, cairo_surface, 0, 0);
cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);
cairo_paint(context);
if (is_raw_image) {
g_free(pixels);
}
cairo_surface_destroy(cairo_surface);
}
The question is: How do I make the window “transparent” to events? So the events goes to drag dest and not to the drag window.
The code works for gtk2 (with minor changes - draw becomes expose event). Does not work for gtk3.
Full source here:
Thanks.