GtkMenu::set_tearoff_state

void set_tearoff_state(bool torn_off);

set_tearoff_state() when set to true creates a non-resizeable, decorated, top-level window, sized to fit the menu contents and iconized in the task bar. The torn-off menu does not need a further parent window, and can act as a standalone widget in its own right.

Where the same menu has also been set as a submenu on an existing GtkMenuItem or as a popup, the menu data is displayed in the currently-visible menu shell.

Note that the GtkMenu in this form is not and cannot be made modal. It could be described as a persistent popup.

It is not possible to connect directly to the tearoff window housing the menu, because it has not been exposed as a property in PHP-GTK - with good reason, as the reference counting has been juggled in GTK+ to make the widget possible in the first place. In order to connect the window's delete event to something meaningful, you will need to do something like this:

<?php

dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));

function exit_activated($menu) {
$menu->destroy();
}

$menu = &new GtkMenu();
$window = $filemenu->parent;
$window->ref();
$window->set_flags(GTK_HAS_GRAB);
$menu->connect_object('destroy', array('gtk', 'main_quit'));

/*  Append and connect your menu items here, but note that any exit item
 must call $menu->destroy() rather than the usual gtk::main_quit(), in
 order to avoid the main loop being quitted twice over  */

$exit = &new GtkMenuItem("Exit");
$exit->connect_object('activate', 'exit_activated', $menu);

$menu->set_title("Tested!");
$menu->set_tearoff_state(true);
$menu->show_all();

gtk::main();

?>
Notice that the "destroy" signal must be connected in this instance, and not the window's "delete-event" signal. This is because the parent window accessed is not the same window as has the window decorations, but is capable of accessing the internal destroy signal triggered by that window if it is given grab beforehand, and can propagate the event to all its children.

You will also spot that this means the menu needs to be rebuilt any time it is called.