Problem
You want to get the size of the display screen as shown below:
Solution
- First get the GdkScreen of the window with GtkWidget::get_screen().
- With the GdkScreen, get the screen width with GdkScreen::get_width() and screen height with GdkScreen::get_height()
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 23 24 25 26 27 | <?php $window = new GtkWindow(); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox()); // display title $title = new GtkLabel("Set the window size to\n". "2/3 of screen width and 2/3 of screen height\n\n"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0.5, 0, 0); $alignment->add($title); $vbox->pack_start($alignment); $screen = $window->get_screen(); // note 1 $screen_width = $screen->get_width(); // note 2 $screen_height = $screen->get_height(); // note 3 $window->set_size_request($screen_width*2/3, $screen_height*2/3); echo "screen size = $screen_width * $screen_height\n"; $window->show_all(); Gtk::main(); ?> |
Output
As shown above.
Read more...