Gtk2::Menu(3)

πŸ“¦
version 1.24993 Β· 2 versions
, in fedora 43

πŸ’– Gtk2::Menu β€” the manual, but make it slay πŸ’–

okay bestie, so this is Gtk2::Menu, which is the Perl wrapper for GtkMenu. It's the lil pop-up list-of-things widget you already know and love, and ngl it is iconic. The manual is Gtk2::Menu(3), filed under User Contributed Perl Documentation, and we're gonna go through the whole thing together, no skips, no cap. πŸŽ€


🌸 HIERARCHY 🌸

here's the family tree, and yes it's giving royal lineage:

Glib::Object
+----Glib::InitiallyUnowned
     +----Gtk2::Object
          +----Gtk2::Widget
               +----Gtk2::Container
                    +----Gtk2::MenuShell
                         +----Gtk2::Menu

πŸ¦‹ INTERFACES πŸ¦‹

these are the interfaces it implements, i.e. the extra vibes it carries:

Glib::Object::_Unregistered::AtkImplementorIface
Gtk2::Buildable

✨ METHODS ✨

  • widget = Gtk2::Menu->new β€” you make a whole new menu, fresh out the box πŸ’…
  • accelgroup = $menu->get_accel_group β€” grab the accel group, the thing holding your keyboard shortcuts.
  • $menu->set_accel_group ($accel_group) β€” set it instead:
    • $accel_group (Gtk2::AccelGroup)
  • string = $menu->get_accel_path β€” get the accel path. Since: gtk+ 2.14
  • $menu->set_accel_path ($accel_path) β€” set that path:
    • $accel_path (string)
  • widget = $menu->get_active β€” which item is currently the active one.
  • $menu->set_active ($index) β€” pick the active one yourself:
    • $index (integer)
  • $menu->attach ($child, $left_attach, $right_attach, $top_attach, $bottom_attach) β€” glue a child into a grid cell of the menu. Since: gtk+ 2.4
    • $child (Gtk2::Widget)
    • $left_attach (integer)
    • $right_attach (integer)
    • $top_attach (integer)
    • $bottom_attach (integer)
  • $menu->attach_to_widget ($attach_widget, $detach_func) β€” attaches $menu to $attach_widget.
    • $attach_widget (Gtk2::Widget)
    • $detach_func (scalar)
⚠️ okay important: $menu must not be currently attached to any other widget β€” and that includes not being a submenu of a Gtk2::MenuItem. Read it again. Internalize it. πŸ™ˆ

If $menu is later detached from the widget with $menu->detach, then the $detach_func gets called like this:

&$detach_func ($attach_widget, $menu)
  • widget = $menu->get_attach_widget β€” the widget the menu is attached to.
  • $menu->detach β€” un-attach it, bye bestie πŸ‘‹
  • list = Gtk2::Menu->get_for_attach_widget ($widget) β€” get the menus attached to a given widget. Since: gtk+ 2.6
    • $widget (Gtk2::Widget)
  • integer = $menu->get_monitor β€” which monitor it's on. Since: gtk+ 2.14
  • $menu->set_monitor ($monitor_num) β€” set the monitor. Since: gtk+ 2.4
    • $monitor_num (integer)
  • $menu->popdown β€” make it go away. poof. 🌈
  • $menu->popup ($parent_menu_shell, $parent_menu_item, $menu_pos_func, $data, $button, $activate_time) β€” the big one, pop that menu up:
    • $parent_menu_shell (Gtk2::Widget or undef)
    • $parent_menu_item (Gtk2::Widget or undef)
    • $menu_pos_func (scalar)
    • $data (scalar)
    • $button (integer)
    • $activate_time (integer)

If $menu_pos_func is not undef, it gets called as:

($x, $y, $push_in) = &$menu_pos_func ($menu, $x, $y, $data)

The $x,$y inputs are a proposed position based on the mouse pointer (and ngl, this isn't actually documented in the Gtk manuals, that's just how it is 😭). What you return should be a desired $x,$y, plus an optional $push_in flag. If $push_in is true then Gtk will adjust $x,$y if necessary so that the menu is fully visible within the screen width and height. thoughtful king behavior ✨

$menu_pos_func and $data are stored inside $menu and may get called again later for a $menu->reposition, or for some obscure things like a changed set_screen while torn-off. And heads up: a further $menu->popup call replaces $menu_pos_func and $data.

  • $menu->reorder_child ($child, $position) β€” move a child to a new spot:
    • $child (Gtk2::Widget)
    • $position (integer)
  • $menu->reposition β€” re-run the positioning situation.
  • boolean = $menu->get_reserve_toggle_size β€” Since: gtk+ 2.18
  • $menu->set_reserve_toggle_size ($reserve_toggle_size) β€” Since: gtk+ 2.18
    • $reserve_toggle_size (boolean)
  • $menu->set_screen ($screen) β€” Since: gtk+ 2.2
    • $screen (Gtk2::Gdk::Screen or undef)
  • boolean = $menu->get_tearoff_state β€” is it torn off or not.
  • $menu->set_tearoff_state ($torn_off)
    • $torn_off (boolean)
  • string = $menu->get_title β€” get the title.
  • $menu->set_title ($title) β€” set the title:
    • $title (string)

πŸŽ€ PROPERTIES πŸŽ€

every property, every flag, in all its glory:

  • 'accel-group' (Gtk2::AccelGroup : default undef : readable / writable / private / static-nick / static-blurb) β€” the accel group holding accelerators for the menu.
  • 'accel-path' (string : default undef : readable / writable / private / static-nick / static-blurb) β€” an accel path used to conveniently construct accel paths of child items.
  • 'active' (integer : default -1 : readable / writable / private / static-nick / static-blurb) β€” the currently selected menu item.
  • 'attach-widget' (Gtk2::Widget : default undef : readable / writable / private / static-nick / static-blurb) β€” the widget the menu is attached to.
  • 'monitor' (integer : default -1 : readable / writable / private / static-nick / static-blurb) β€” the monitor the menu will be popped up on.
  • 'reserve-toggle-size' (boolean : default true : readable / writable / private / static-nick / static-blurb) β€” a boolean that indicates whether the menu reserves space for toggles and icons.
  • 'tearoff-state' (boolean : default false : readable / writable / private / static-nick / static-blurb) β€” a boolean that indicates whether the menu is torn-off.
  • 'tearoff-title' (string : default undef : readable / writable / private / static-nick / static-blurb) β€” a title that may be displayed by the window manager when this menu is torn-off.

🧚 CHILD PROPERTIES 🧚

the properties that belong to the children, not the menu itself:

  • 'bottom-attach' (integer : default -1 : readable / writable / private / static-nick / static-blurb) β€” the row number to attach the bottom of the child to.
  • 'left-attach' (integer : default -1 : readable / writable / private / static-nick / static-blurb) β€” the column number to attach the left side of the child to.
  • 'right-attach' (integer : default -1 : readable / writable / private / static-nick / static-blurb) β€” the column number to attach the right side of the child to.
  • 'top-attach' (integer : default -1 : readable / writable / private / static-nick / static-blurb) β€” the row number to attach the top of the child to.

πŸ’… STYLE PROPERTIES πŸ’…

the glow-up settings:

  • 'arrow-placement' (Gtk2::ArrowPlacement : default "both" : readable / private / static-nick / static-blurb) β€” indicates where scroll arrows should be placed.
  • 'arrow-scaling' (float : default 0.7 : readable / private / static-nick / static-blurb) β€” arbitrary constant to scale down the size of the scroll arrow.
  • 'double-arrows' (boolean : default true : readable / private / static-nick / static-blurb) β€” when scrolling, always show both arrows.
  • 'horizontal-offset' (integer : default -2 : readable / private / static-nick / static-blurb) β€” when the menu is a submenu, position it this number of pixels offset horizontally.
  • 'horizontal-padding' (integer : default 0 : readable / private / static-nick / static-blurb) β€” extra space at the left and right edges of the menu.
  • 'vertical-offset' (integer : default 0 : readable / private / static-nick / static-blurb) β€” when the menu is a submenu, position it this number of pixels offset vertically.
  • 'vertical-padding' (integer : default 1 : readable / private / static-nick / static-blurb) β€” extra space at the top and bottom of the menu.

πŸ”₯ SIGNALS πŸ”₯

just the one, and she's lowkey underrated:

  • move-scroll (Gtk2::Menu, Gtk2::ScrollType)

🌈 ENUMS AND FLAGS 🌈

enum Gtk2::ScrollType

all sixteen of them, in order, exactly as written:

  • 'none' / GTK_SCROLL_NONE
  • 'jump' / GTK_SCROLL_JUMP
  • 'step-backward' / GTK_SCROLL_STEP_BACKWARD
  • 'step-forward' / GTK_SCROLL_STEP_FORWARD
  • 'page-backward' / GTK_SCROLL_PAGE_BACKWARD
  • 'page-forward' / GTK_SCROLL_PAGE_FORWARD
  • 'step-up' / GTK_SCROLL_STEP_UP
  • 'step-down' / GTK_SCROLL_STEP_DOWN
  • 'page-up' / GTK_SCROLL_PAGE_UP
  • 'page-down' / GTK_SCROLL_PAGE_DOWN
  • 'step-left' / GTK_SCROLL_STEP_LEFT
  • 'step-right' / GTK_SCROLL_STEP_RIGHT
  • 'page-left' / GTK_SCROLL_PAGE_LEFT
  • 'page-right' / GTK_SCROLL_PAGE_RIGHT
  • 'start' / GTK_SCROLL_START
  • 'end' / GTK_SCROLL_END

🫢 SEE ALSO 🫢

go read these too, they're the whole friend group:

Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget, Gtk2::Container, Gtk2::MenuShell


Copyright (C) 2003-2011 by the gtk2-perl team.

This software is licensed under the LGPL. See Gtk2 for a full notice.


and that's the whole page bestie, you ate that πŸ’– this was Gtk2::Menu(3) from the User Contributed Perl Documentation, perl v5.42.0, dated 2025-07-25. go forth and pop up menus responsibly πŸ¦‹βœ¨

πŸ“¦ where this page comes from