Re: Question and possibly bugs about string encoding in gtk-perl
- From: Torsten Schönfeld <kaffeetisch gmx de>
- To: Dominique Dumont <domi dumont free fr>, gtk-perl-list gnome org
- Cc: 847051 bugs debian org, Boyuan Yang <073plan gmail com>
- Subject: Re: Question and possibly bugs about string encoding in gtk-perl
- Date: Fri, 16 Dec 2016 21:34:55 +0100
On 16.12.2016 20:02, Dominique Dumont wrote:
On Wednesday, 14 December 2016 10:54:16 CET Boyuan Yang wrote:
The original messy output, as indicated in screenshot in the Ubuntu bug,
looks like treating a latin-1-encoded binary data as UTF-8-encoded data
and showing them anyway.
In more details, the problematic code boils down to:
my $wnck_screen = Gnome2::Wnck::Screen->get_default;
my $win= $wnck_screen->get_windows_stacked; # Gnome2::Wnck object
my $name = $win->get_name;
my $window_item = Gtk2::ImageMenuItem->new_with_label( $name );
$name contains window name apparently in octet format instead of an utf8
string. As a consequence, the list of windows shown by shutter contains
mojibake.
Yes, Gnome2::Wnck does not do any decoding at all in get_name. This is
probably by accident, not by intention, but if you look at what
wnck_window_get_name boils down to,
<https://git.gnome.org/browse/libwnck/tree/libwnck/xutils.c#n1229>, you
see that it returns UTF8-encoded strings in most cases, but sometimes
also strings in X11's compound text encoding, according to
<http://stackoverflow.com/questions/7706589/is-there-any-difference-with-the-x11-atoms-xa-wm-name-and-net-wm-name>.
So it seems like the safest bet would be to try to decode the window
name from UTF8, and if that fails, try Encode::X11 and its
'x11-compound-text' (Hi Kevin!).
The hacky patch proposed (by me) is using
Encode::_utf8_on() to turn on the internal flag for string and mark it as
UTF-8.
And I'm worried that shutter may crash if used in a non-utf8 environment.
After some experimentation, I've come up with a safer solution:
use 5.12.0;
use Encode::Locale;
use Encode qw/decode/;
# ...
my $name = decode( 'locale' , $win->get_name);
This works in utf8 locale and is safer than turning utf8 flag on.
It seems like this would fail in a non-UTF8 locale, however, as
gnome_wnck_window_get_name seems to always return UTF8 strings,
regardless of locale.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]