gpt4 book ai didi

Transparent Full Screen Window with GTK4(带GTK4的透明全屏窗口)

转载 作者:bug小助手 更新时间:2023-10-25 21:41:10 24 4
gpt4 key购买 nike



I am using gtk4 on Ubuntu, Wayland. I want to create a full screen transparent window.

我在Wayland的Ubuntu上使用gtk4。我想创建一个全屏透明窗口。


With this code, I can create a full screen window, but I don't know how to make it transparent.

使用这段代码,我可以创建一个全屏窗口,但我不知道如何使其透明。



  1. My draw_callback does not get called. Why?

  2. How do I make this window transparent?



#include <gtk/gtk.h>
#include <cairo.h>

static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_print ("Hello World\n");
}

gboolean
draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
{
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
int width = gtk_widget_get_allocated_width(widget);
int height = gtk_widget_get_allocated_height(widget);
// cairo_set_source_rgb(cr, 1, 0, 0);
// cairo_move_to(cr, 0, 0);
// cairo_line_to(cr, 200, 200);
// cairo_stroke(cr);

return FALSE;
}

static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

GtkWidget *button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
gtk_window_set_child (GTK_WINDOW (window), button);

GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing_area, 200, 200);
g_signal_connect (G_OBJECT (drawing_area), "draw", G_CALLBACK (draw_callback), NULL);

gtk_window_present (GTK_WINDOW (window));
gtk_window_fullscreen(GTK_WINDOW(window));

// cairo_t *cr = gdk_cairo_create(GTK_WINDOW (window));
// cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
// cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
// cairo_paint (cr);
// cairo_destroy(cr);

}

int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;

app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);

return status;
}

更多回答
优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com