我有一个应用程序,可以在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)
我创建了一个简单的测试用例来重现这个问题:
- 启动第二个显示器(例如另一台计算机,
Xvnc:1
等) - 启动第二个显示器的查看器(如
vncviewer :1
) - 运行以下代码
- 右击按钮,查看弹出菜单是否正确工作
- 左击按钮,使窗口移动到另一个显示器上
- 在另一个显示器上,右击按钮并观察崩溃情况
样本代码:
#!/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;
版本信息:
- 操作系统:CentOS 7.1(Linux 3.10.0-229.el7.x86_64)
- Perl:5.16.3
- Gtk3:3.8.8
- X11:xorg 1.15.0