如何刷新透明背景?

时间:2023-01-24 14:05:25

In a purely GDK 3.10 (no GTK) project how do I refresh/clear/redraw a transparent background of a GdkWindow?

在纯GDK 3.10(无GTK)项目中,如何刷新/清除/重绘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:

这个测试。c在初始化时正确设置背景(gdk_window_show()),当我iconify+deiconify窗口时,而不是在每个鼠标上调整大小或移动它:

#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命令:

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.

注意:我的目标是X11,所以我也允许包含Xlib或GDK X11后端函数。

Thank you for any help or pointers.

谢谢你的帮助和指点。

1 个解决方案

#1


0  

The solution to this is a fix of a rather silly mistake I made passing an incomplete attribute mask to gdk_window_new().

解决这个问题的方法是修复一个相当愚蠢的错误,我将一个不完整的属性掩码传递给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);

#1


0  

The solution to this is a fix of a rather silly mistake I made passing an incomplete attribute mask to gdk_window_new().

解决这个问题的方法是修复一个相当愚蠢的错误,我将一个不完整的属性掩码传递给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);