1. How can I get the actual available size of the desktop? The following code gives the maximum resolution, but the size of the desktop actually available to my GTK windows is somewhat less (it is reduced by one taskbar in Windows; by two in Ubuntu.)

I'm afraid to say from my experience, that you have to figure out where the taskbars are, get their window placements, and account for them. When you say take me to (0,0) on the screen, it will go to (0,0). If another app, like a taskbar is there, it's up to you to avoid the taskbar area, or layer your app over the taskbar.

There is a tool for this, called Gnome2::Wnck, and here is a very crude usage. The while(1)hack I used to repeat this is awful, but it shows what is happening.

#!/usr/bin/perl use warnings; use strict; use Gtk2; use Gnome2::Wnck; Gtk2->init(); while (1) { sleep 1; Gtk2->main_iteration while Gtk2->events_pending; my $screen = Gnome2::Wnck::Screen->get(0); $screen->force_update(); my @windows_list = $screen->get_windows(); foreach my $window (@windows_list) { my $name = $window->get_name(); print "name = $name\n"; } print "\n\n"; sleep 10; }

2. The following code creates a window and resizes it. However, the specified size seems to be applied only to the window's client area, not the whole window. (Example: ff the client area is 300x200, the actual size of the window is likely to be something like 300x215.)

The extra pixels are added by the window manager, to give you window manager controls. If you want your window to be exactly what you specify, use no decorations.

#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; # works on any ICCWM compliant window manager my $window = Gtk2::Window->new(); $window->set_decorated(0); Gtk2::Window::set_decorated($window, 0); print $window->get_decorated(),"\n"; $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_size_request(300,200); my $vbox = Gtk2::VBox->new( FALSE, 6 ); $window->add($vbox); $vbox->set_border_width(2); my $hbox= Gtk2::HBox->new( FALSE, 6 ); $vbox->pack_end($hbox,FALSE,FALSE,0); $hbox->set_border_width(2); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $hbox->pack_end( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); $window->set_position('center'); $window->show_all(); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; }
Also remember, (-1,-1) will bring you to the lower right hand bottom corner. But when going from that direction, you must be aware of setting the gravity.
#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; my $window = Gtk2::Window->new('toplevel'); $window->set_title('Z'); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); my $width = 300; my $height = 200; $window->set_size_request($width,$height); $window->set_gravity('GDK_GRAVITY_SOUTH_EAST'); #this avoids the offset due to window decorations my $vbox = Gtk2::VBox->new( FALSE, 6 ); $window->add($vbox); $vbox->set_border_width(2); my $hbox= Gtk2::HBox->new( FALSE, 6 ); $vbox->pack_end($hbox,FALSE,FALSE,0); $hbox->set_border_width(2); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $hbox->pack_end( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); #$window->set_position('center'); my ($xscr, $yscr) = (Gtk2::Gdk->screen_width, Gtk2::Gdk->screen_height +); print "$xscr $yscr\n"; $window->move($xscr - $width, $yscr - $height); $window->show_all(); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; }

Hope that gets you going. :-)

As far as widgets resizing themselves, it is probably a matter of improper packing, and whether you have the homogeneous, spacing, expand, fill, padding settings correct for what behavior you want. Also see gtk2 widgets positions Here are a few more scripts which may be of interest to you.

A window position test
#!/usr/bin/perl -w use strict; use Glib qw/TRUE FALSE/; use Gtk2 -init; my ($xscr, $yscr) = (Gtk2::Gdk->screen_width, Gtk2::Gdk->screen_height +); print "$xscr $yscr\n"; my $window = Gtk2::Window->new; $window->set_border_width(10); $window->set_title('Window 0'); my $width = 300; my $height = 100; $window->set_size_request($width,$height); $window->set_gravity('GDK_GRAVITY_SOUTH_EAST'); $window->signal_connect( delete_event => sub { Gtk2->main_quit; 1 } ); $window->move($xscr,$yscr); my $window1 = Gtk2::Window->new; $window1->set_border_width(10); $window1->set_title('Window 1'); $window1->set_size_request($width,$height); $window1->set_gravity('GDK_GRAVITY_SOUTH_WEST'); $window1->move(0,$yscr); my $window2 = Gtk2::Window->new; $window2->set_border_width(10); $window2->set_title('Window 2'); $window2->set_size_request($width,$height); $window2->set_gravity('GDK_GRAVITY_NORTH_WEST'); $window2->move(0,0); my $vbox = Gtk2::VBox->new; my $b = Gtk2::Button->new_from_stock( "gtk-close" ); $b->signal_connect('button_press_event' => sub { exit }); $vbox->pack_start( $b, TRUE, TRUE, 0 ); $window->add( $vbox ); $vbox->show_all; $window->show_all(); $window1->show_all(); $window2->show_all(); Gtk2->main;
Setting a MINIMUM size
#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; #this way sets a minimum size my $window = Gtk2::Window->new('toplevel'); $window->set_title('Z'); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_size_request(300,200); my $vbox = Gtk2::VBox->new( FALSE, 6 ); $window->add($vbox); $vbox->set_border_width(2); my $hbox= Gtk2::HBox->new( FALSE, 6 ); $vbox->pack_end($hbox,FALSE,FALSE,0); $hbox->set_border_width(2); my $frame0 = Gtk2::Frame->new('Controls'); $vbox->pack_end( $frame0, FALSE, FALSE, 0 ); $frame0->set_border_width(3); $vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0); my $hbox0 = Gtk2::HBox->new( FALSE, 6 ); $frame0->add($hbox0); $hbox0->set_border_width(3); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $hbox0->pack_end( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); $window->show_all(); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; }
Setting a DEFAULT size and doing a size request
#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; # sets a default size my $window = Gtk2::Window->new('toplevel'); $window->set_title('Z'); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_default_size(300,200); my $vbox = Gtk2::VBox->new( FALSE, 6 ); #tells $vbox to take size from parent window #not from children expanding $vbox->set_size_request(0,0); $window->add($vbox); $vbox->set_border_width(2); my $hbox= Gtk2::HBox->new( FALSE, 6 ); $vbox->pack_end($hbox,FALSE,FALSE,0); $hbox->set_border_width(2); my $frame0 = Gtk2::Frame->new('Controls'); $vbox->pack_end( $frame0, FALSE, FALSE, 0 ); $frame0->set_border_width(3); $vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0); my $hbox0 = Gtk2::HBox->new( FALSE, 6 ); $frame0->add($hbox0); $hbox0->set_border_width(3); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $hbox0->pack_end( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); $window->show_all(); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: gtk window sizes by zentara
in thread gtk window sizes by ronlewis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.