in reply to gtk window sizes
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.
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'; # 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; }
#!/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.
Setting a MINIMUM size#!/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 DEFAULT size and doing a size request#!/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; }
#!/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; }
|
|---|