Am 09.09.2014 22:28, schrieb Torsten Schoenfeld:
> On 08.09.2014 22:20, Torsten Schoenfeld wrote:
>> In principle, GtkSettings' "notify::gtk-font-name" can be used for this,
>> but it's not available in perl-Gtk2, only perl-Gtk3:
>>
>> perl -MGtk3=-init -E'my $s = Gtk3::Settings::get_default (); say $s->get
>> ("gtk-font-name"); $s->signal_connect ("notify::gtk-font-name", sub {
>> say $s->get ("gtk-font-name") }); Gtk3::main ();'
> 
> That was not entirely correct, it turns out.  While
> gtk_settings_get_default is not bound in perl-Gtk2 (patches welcome),
> gtk_widget_get_settings is.  So try this:
> 
> perl -MGtk2=-init -E'my $w = Gtk2::Window->new; my $s =
> $w->get_settings; say $s->get ("gtk-font-name"); $s->signal_connect
> ("notify::gtk-font-name", sub { say $s->get ("gtk-font-name"); });
> Gtk2->main ();'
> 
> To parse the font name, you can use Pango::FontDescription->from_string.

Thanks Thorsten! 
Unfortunately your code doesn't work on my system (Perl 5.20. gtk2-perl 2.24).

But after some searches I found a signal which works for me \O/ 
Here's my test code:

#!/usr/bin/perl -w

use strict;

use Gtk2 '-init';
our $last_fsize;

sub changed {
    my $window = shift;
    my $fontsize = get_fontsize($window);
    
    if ($last_fsize != $fontsize) {
        print "changed!\n";
        # update it
        $last_fsize = $fontsize;
    }
}


sub get_fontsize {
    my $window = shift;
    my $context = $window->get_pango_context();
    my $fontDesc = $context->get_font_description();
    my $fontsize = $fontDesc->get_size();
        my $pango_scale = Gtk2::Pango->scale();
    if ($fontsize > 200) {
        $fontsize = $fontsize/$pango_scale ;
    }
    
    return $fontsize;
}

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
$window->signal_connect('style-set' => \&changed, $window);

$last_fsize = get_fontsize($window);

$window->show();

Gtk2->main;

I found the hint about 'style-set' in a chrome bug report
where're problems with wrong font size in menus against
the set font size in Gtk2.

If anybody interested to read:
https://code.google.com/p/chromium/issues/detail?id=375824

The interesting part is the function void Gtk2UI::Initialize() in a git commit:
https://chromium.googlesource.com/chromium/src.git/+/9816ff759cec9ef4b8774b649c695cd9d51ade80/chrome/browser/ui/libgtk2ui/gtk2_ui.cc

Thanks again for your help :-)

Best,
Thomas

-- 
--
"Two things are infinite: the universe and human stupidity; and I'm not sure 
about the the universe."   --   Albert Einstein
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to