在备用 X11 显示器上打开弹出菜单时 Gtk3 崩溃

Gtk3 crash when opening a popup menu on alternate X11 display

我有一个可以在 X11 显示器之间移动的应用程序,但是当我在不是我开始的显示器上时,尝试打开弹出菜单会导致崩溃。菜单栏中的菜单工作正常,只是弹出窗口不行。

(popuptest.pl:17147): Gdk-ERROR **: The program 'popuptest.pl' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadWindow (invalid Window parameter)'.
  (Details: serial 355 error_code 3 request_code 131 minor_code 51)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
Trace/breakpoint trap (core dumped)

我创建了一个重现问题的简单测试用例:

  1. 启动辅助显示器(即另一台机器,Xvnc :1,等等)
  2. 启动第二个显示的查看器(例如 vncviewer :1
  3. 运行下面的代码
  4. 右击按钮,弹出菜单正常工作
  5. 左键单击按钮,window 移动到另一个显示器
  6. 在另一个显示器上,右键单击按钮并观察崩溃

示例代码:

#!/usr/bin/perl -w
use strict;
use Glib qw/TRUE FALSE/;
use Gtk3 -init;
my $win = Gtk3::Window->new;
$win->signal_connect(destroy => sub {Gtk3::main_quit});
my $btn = Gtk3::Button->new_with_label("move to :1");
$btn->signal_connect(clicked => sub {
        $win->set_screen(Gtk3::Gdk::Display::open(":1")->get_screen(0));
});
my $menu;
$btn->signal_connect('button-press-event' => sub {
        my ($widget, $event) = @_;
        return FALSE unless $event->button == 3;
        $menu = Gtk3::Menu->new;
        $menu->attach(Gtk3::MenuItem->new_with_label(''.localtime), 0, 1, 0, 1);
        $menu->show_all;
        $menu->popup(undef, undef, undef, undef, $event->button, $event->time);
        return TRUE;
});
$win->add($btn);
$win->show_all;
Gtk3->main;

版本:

这似乎是那个版本的 Gtk 中的错误。

我能够在装有 Gtk 3.18 的系统上对其进行测试,并且运行良好。至少我知道这不是 Perl 代码中的错误。