admin管理员组文章数量:1336331
I need to create transparent window and when user clicks inside this window then mouse event to be passed to a window that is behind. For example, if there is a text editor behind my window then mouse event should be passed to that editor window. By other words I need the window to be transparent for mouse events.
This is my code. I create window but its content area is not transparent.
#include <gtk/gtk.h>
#include <cairo.h>
static void on_destroy(GtkWidget *widget, gpointer data) {
gtk_main_quit();
}
static void on_realize(GtkWidget *widget, gpointer data) {
GdkWindow *gdk_window;
cairo_t *cr;
cairo_surface_t *surface;
cairo_region_t *region;
gdk_window = gtk_widget_get_window(widget);
if (gdk_window) {
surface = gdk_window_create_similar_surface(gdk_window, CAIRO_CONTENT_COLOR_ALPHA, 400, 300);
cr = cairo_create(surface);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_rectangle(cr, 0, 0, 400, 300);
cairo_fill(cr);
region = cairo_region_create_rectangle(&((cairo_rectangle_int_t){0, 0, 200, 300}));
gdk_window_input_shape_combine_region(gdk_window, region, 0, 0);
cairo_destroy(cr);
cairo_surface_destroy(surface);
cairo_region_destroy(region);
}
}
int main(int argc, char *argv[]) {
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(on_destroy), NULL);
g_signal_connect(window, "realize", G_CALLBACK(on_realize), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Could anyone say how to do it?
I need to create transparent window and when user clicks inside this window then mouse event to be passed to a window that is behind. For example, if there is a text editor behind my window then mouse event should be passed to that editor window. By other words I need the window to be transparent for mouse events.
This is my code. I create window but its content area is not transparent.
#include <gtk/gtk.h>
#include <cairo.h>
static void on_destroy(GtkWidget *widget, gpointer data) {
gtk_main_quit();
}
static void on_realize(GtkWidget *widget, gpointer data) {
GdkWindow *gdk_window;
cairo_t *cr;
cairo_surface_t *surface;
cairo_region_t *region;
gdk_window = gtk_widget_get_window(widget);
if (gdk_window) {
surface = gdk_window_create_similar_surface(gdk_window, CAIRO_CONTENT_COLOR_ALPHA, 400, 300);
cr = cairo_create(surface);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_rectangle(cr, 0, 0, 400, 300);
cairo_fill(cr);
region = cairo_region_create_rectangle(&((cairo_rectangle_int_t){0, 0, 200, 300}));
gdk_window_input_shape_combine_region(gdk_window, region, 0, 0);
cairo_destroy(cr);
cairo_surface_destroy(surface);
cairo_region_destroy(region);
}
}
int main(int argc, char *argv[]) {
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(on_destroy), NULL);
g_signal_connect(window, "realize", G_CALLBACK(on_realize), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Could anyone say how to do it?
Share Improve this question edited Nov 20, 2024 at 14:11 SilverCube asked Nov 19, 2024 at 18:44 SilverCubeSilverCube 7342 silver badges12 bronze badges 5 |1 Answer
Reset to default 0You may explore about using gtk_overlay_set_overlay_pass_through() which internally uses gdk_window_set_pass_through() which you can also use directly if not wanting to use a GtkOverlay
widget.
Description of GtkOverlay:pass-through
property:
/**
* GtkOverlay:pass-through:
*
* Whether to pass input through the overlay child to the main child.
* (Of course, this has no effect when set on the main child itself.)
*
* Note that this is implemented by calling gdk_window_set_pass_through()
* on the window that the overlay child is placed in. If the descendents
* of the overlay child have their own windows, you need to manually call
* that function on them to achieve the desired effect.
*
* Since: 3.18
*/
本文标签: gtkHow to create a transparent window in GDK 3 that passes mouse events using CStack Overflow
版权声明:本文标题:gtk - How to create a transparent window in GDK 3 that passes mouse events using C? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742405353a2468705.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
gdk_window_input_shape_combine_region
. That is about "click goes to the window behind". Do you know aboutgdk_window_shape_combine_region
? This one seems to about "visibly transparent" or "see through". Alternatively, for "semi-transparent", something like stackoverflow/questions/3908565/… should be helpful. – Uli Schlachter Commented Nov 21, 2024 at 15:16