Gtk2::Ex::WidgetBits - miscellaneous Gtk widget helpers
use Gtk2::Ex::WidgetBits;
($x,$y) = Gtk2::Ex::WidgetBits::get_root_position ($widget)
Return the position of the top left corner of $widget in root window coordinates. If $widget is unrealized the return is an empty list ().
$widget
()
This uses Gtk2::Ex::GdkBits::window_get_root_position so takes the most recently recorded window positions rather than making an X server round-trip.
Gtk2::Ex::GdkBits::window_get_root_position
Gtk2::Ex::WidgetBits::warp_pointer ($widget, $x, $y)
Warp, ie. forcibly move, the mouse pointer to $x,$y in $widget coordinates (ie. relative to the widget's top-left corner). $widget must be realized, since otherwise it doesn't have a screen position.
$x
$y
See Gtk2::Gdk::Display for the basic warp_pointer in root window coordinates. The code here converts using get_root_position above, so there's no server round-trip. Warping is available in Gtk 2.2 up.
warp_pointer
get_root_position
The underlying XWarpPointer operates relative to any window, not just the root, but Gdk doesn't make that feature available.
XWarpPointer
($x,$y) = Gtk2::Ex::WidgetBits::xy_root_to_widget ($widget, $root_x,$root_y)
Convert a root window X,Y position to widget coordinates. If $widget is not realized then it doesn't have a screen position and the return is an empty list.
if (my ($x,$y) = Gtk2::Ex::WidgetBits::xy_root_to_widget ($widget, $x_root, $y_root)) { # widget $x,$y } else { # $widget is not realized, no values }
In the following functions, sizes in millimetres come from the screen (Gtk2::Gdk::Screen). A widget has a screen when it's been added as a child somewhere under a toplevel Gtk2::Window etc. Or in Gtk 2.0.x there's only ever one screen and its size is always used (Gtk2->init required).
Gtk2::Window
Gtk2->init
($width_mm, $height_mm) = Gtk2::Ex::WidgetBits::pixel_size_mm ($widget)
Return the width and height in millimetres of a pixel in $widget. If $widget doesn't have a screen then return no values.
my ($xmm, $ymm) = Gtk2::Ex::WidgetBits::pixel_size_mm ($widget) or print "no screen yet";
$ratio = Gtk2::Ex::WidgetBits::pixel_aspect_ratio ($widget)
Return the ratio width/height of pixel size in millimetres in $widget. For example if a pixel is 3mm wide by 2mm high then the ratio would be 1.5. If $widget doesn't have a screen then return undef.
undef
This ratio is the same way around as Gtk2::AspectFrame. Setting the ratio property to this pixel ratio makes the child square on the monitor.
Gtk2::AspectFrame
ratio
$mm = Gtk2::Ex::WidgetBits::xy_distance_mm ($widget, $x1,$y1, $x2,$y2)
Return the distance in millimetres between pixel points $x1,$y1 and $x2,$y2 in $widget. If $widget doesn't have a screen then return undef.
$x1
$y1
$x2
$y2
Gtk2::Ex::AdjustmentBits, Gtk2::Ex::EntryBits, Gtk2::Ex::GdkBits, Gtk2::Ex::MenuBits, Gtk2::Ex::TextBufferBits, Gtk2::Ex::TreeModelBits, Gtk2::Ex::TreeModel::ImplBits, Gtk2::Ex::TreeViewBits, Gtk2::Ex::Units
Gtk2::Ex::ActionTooltips, Gtk2::Ex::KeySnooper, Gtk2::Ex::SyncCall, Gtk2::Ex::Statusbar::MessageUntilKey, Gtk2::Ex::TreeModelFilter::Change, Test::Weaken::Gtk2
Gtk2::Widget, Gtk2::Ex::WidgetCursor.
http://user42.tuxfamily.org/gtk2-ex-widgetbits/index.html
Copyright 2008, 2009, 2010, 2011, 2012 Kevin Ryde
Gtk2-Ex-WidgetBits is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Gtk2-Ex-WidgetBits is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Gtk2-Ex-WidgetBits. If not, see http://www.gnu.org/licenses/.
To install Gtk2::Ex::WidgetBits, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gtk2::Ex::WidgetBits
CPAN shell
perl -MCPAN -e shell install Gtk2::Ex::WidgetBits
For more information on module installation, please visit the detailed CPAN module installation guide.