eclipse.platform.swt icon indicating copy to clipboard operation
eclipse.platform.swt copied to clipboard

GTK4: Test_org_eclipse_swt_widgets_MenuItem.test_setImageLorg_eclipse_swt_graphics_Image test fail

Open raghucssit opened this issue 4 months ago • 19 comments

2025-09-11T13:49:48.9253664Z [ERROR] Tests run: 24, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.888 s <<< FAILURE! -- in org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_MenuItem
2025-09-11T13:49:48.9256045Z [ERROR] org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_MenuItem.test_setImageLorg_eclipse_swt_graphics_Image -- Time elapsed: 0.478 s <<< FAILURE!
2025-09-11T13:49:48.9262556Z java.lang.AssertionError: expected:<Image {140445329297696}> but was:<null>
2025-09-11T13:49:48.9263253Z 	at org.junit.Assert.fail(Assert.java:89)
2025-09-11T13:49:48.9263771Z 	at org.junit.Assert.failNotEquals(Assert.java:835)
2025-09-11T13:49:48.9264342Z 	at org.junit.Assert.assertEquals(Assert.java:120)
2025-09-11T13:49:48.9264901Z 	at org.junit.Assert.assertEquals(Assert.java:146)
2025-09-11T13:49:48.9266064Z 	at org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_MenuItem.test_setImageLorg_eclipse_swt_graphics_Image(Test_org_eclipse_swt_widgets_MenuItem.java:208)

raghucssit avatar Sep 15 '25 12:09 raghucssit

GTK4 does not support both image and text in Menu Item.

@Override
public void setImage (Image image) {
	//TODO: GTK4 Menu images with text are no longer supported
	if (GTK.GTK4) return;

Possible fixes:

  1. Fix the test case for GTK4 tat we know we can't set both text and image.
  2. Just override the previous one whatever was set before.

raghucssit avatar Sep 15 '25 12:09 raghucssit

What about option 3: Add GtkBox child and allow having both text and image in it?

akurtakov avatar Sep 15 '25 12:09 akurtakov

What about option 3: Add GtkBox child and allow having both text and image in it?

Yeah.. That is a good idea.. I will try it.

raghucssit avatar Sep 15 '25 12:09 raghucssit

What about option 3: Add GtkBox child and allow having both text and image in it?

Initially i tried GtkBox approach like GTK3.. but later after checking GIO API i thought of using MenuItem.set_icon. But I am stuck in this approach because I did not find any direct way to convert Image to GIcon.. And GIcon itself don't have any concrete implementation. I can fallback to GtkBox approach or try more to implement a way to support GIcon in native code. @akurtakov wdyt is it good idea to support GIcon or GtkBox approach is enough ?

raghucssit avatar Sep 21 '25 16:09 raghucssit

I have tried adding a child widget to popover menu using gtk_popover_menu_add_child. For now I have tried insert a custom widget GtkBox only for PUSH item. However it does not display the custom child.. I am not sure what I am missing here.. But steps seems to be right.. I have introduced new native API and build it.. when I run the client code there is no error also.. call to gtk_popover_menu_add_child is successful..

Below is my patch:

diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c
index 3ebcddc..94b5c7c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c
@@ -1755,6 +1755,27 @@
 }
 #endif
 
+#ifndef NO_gtk_1popover_1menu_1add_1child
+JNIEXPORT jboolean JNICALL GTK4_NATIVE(gtk_1popover_1menu_1add_1child)
+  (JNIEnv *env, jclass that, jlong arg0, jlong arg1, jbyteArray arg2)
+{
+    jbyte *lparg2 = NULL;
+    jboolean rc = JNI_FALSE;
+    GTK4_NATIVE_ENTER(env, that, gtk_1popover_1menu_1add_1child_FUNC);
+    if (arg2) {
+        if ((lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL)) == NULL) goto fail;
+    }
+    rc = (jboolean) gtk_popover_menu_add_child(
+            (GtkPopoverMenu *) (intptr_t) arg0,
+            (GtkWidget *) (intptr_t) arg1,
+            (const gchar *) lparg2);
+fail:
+    if (arg2 && lparg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, 0);
+    GTK4_NATIVE_EXIT(env, that, gtk_1popover_1menu_1add_1child_FUNC);
+    return rc;
+}
+#endif
+
 #ifndef NO_gtk_1rgb_1to_1hsv
 JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1rgb_1to_1hsv)
 	(JNIEnv *env, jclass that, jfloat arg0, jfloat arg1, jfloat arg2, jfloatArray arg3, jfloatArray arg4, jfloatArray arg5)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java
index 48ceb12..7dfd9d7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java
@@ -539,6 +539,16 @@
 	/** @param model cast=(GMenuModel *) */
 	public static final native long gtk_popover_menu_bar_new_from_model(long model);
 
+	/**
+	 * gboolean gtk_popover_menu_add_child (GtkPopoverMenu* popover, GtkWidget* child, const char* id)
+	 *
+	 * @param popover cast=(GtkPopoverMenu *)
+	 * @param child cast=(GtkWidget *)
+	 * @param id cast=(const char *)
+	 * @return boolean - true if added, false otherwise
+	 */
+	public static final native boolean gtk_popover_menu_add_child(long popover, long child, byte[] id);
+
 	/* GtkIconTheme */
 	/** @param display cast=(GdkDisplay *) */
 	public static final native long gtk_icon_theme_get_for_display(long display);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
index edc9eb5..34133c9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
@@ -70,6 +70,11 @@
 	Section section;
 	String actionName;
 
+	/* GTK4 custom child support */
+	String customId;        // the id string we use in the menu model custom attribute
+	private byte[] idBytes;
+
+
 /**
  * Constructs a new instance of this class given its parent
  * (which must be a <code>Menu</code>) and a style value
@@ -297,6 +302,43 @@
 				OS.g_action_map_add_action(parent.actionGroup, actionHandle);
 				actionName = String.valueOf(parent.hashCode()) + "." + String.valueOf(this.hashCode());
 				handle = OS.g_menu_item_new(null, Converter.javaStringToCString(actionName));
+
+				//new fix
+			    // 3) Define custom id (same string used for both model + popover child)
+			    customId = "swt-item-" + this.hashCode();
+			    byte[] attr = Converter.javaStringToCString("custom");
+			    byte[] fmt  = Converter.javaStringToCString("s");
+			    idBytes = Converter.javaStringToCString(customId);
+
+			    // Allocate native buffer for string
+			    long idPtr = OS.g_malloc(idBytes.length);
+			    C.memmove(idPtr, idBytes, idBytes.length);
+			    OS.g_menu_item_set_attribute(handle, attr, fmt, idPtr);
+			    OS.g_free(idPtr);
+
+			    // 4) Build widget (GtkBox + Image + Label)
+			    boxHandle = GTK.gtk_box_new(GTK.GTK_ORIENTATION_HORIZONTAL, 6);
+			    if (boxHandle == 0) error(SWT.ERROR_NO_HANDLES);
+
+//			    imageHandle = GTK.gtk_image_new();
+//			    if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
+
+			    labelHandle = GTK.gtk_label_new_with_mnemonic(null);
+			    if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES);
+
+			    //place holder in case of some location allocation.
+			    byte[] buffer = Converter.wcsToMbcs("dummy Label", true);
+			    GTK.gtk_label_set_text_with_mnemonic(labelHandle, buffer);
+
+//			    GTK4.gtk_box_append(boxHandle, imageHandle);
+			    GTK4.gtk_box_append(boxHandle, labelHandle);
+
+//			    GTK.gtk_widget_set_visible(imageHandle, true);
+			    GTK.gtk_widget_set_visible(labelHandle, true);
+
+			    // 5) Register custom widget with parent PopoverMenu
+			    GTK4.gtk_popover_menu_add_child(parent.handle, boxHandle, idBytes);
+
 				break;
 		}
 
@@ -334,7 +376,6 @@
 			selectedSection.sectionItems.add(sectionRelativeIndex, this);
 			OS.g_menu_insert_item(selectedSection.getSectionHandle(), sectionRelativeIndex, handle);
 		}
-
 		parent.items.add(index, this);
 	} else {
 		byte[] buffer = new byte[1];
@@ -1031,6 +1072,14 @@
 	//TODO: GTK4 Menu images with text are no longer supported
 	if (GTK.GTK4) return;
 
+//    long gicon = 0;
+//    if (image != null) {
+//        gicon = image.getGIcon(); // native GIcon pointer from SWT Image
+//    }
+//
+//    // Call native method to set the icon
+//    OS.g_menu_item_set_icon(handle, gicon);
+
 	checkWidget();
 	if (this.image == image) return;
 	if ((style & SWT.SEPARATOR) != 0) return;
@@ -1278,6 +1327,13 @@
 		}
 		OS.g_menu_remove(section.getSectionHandle(), section.getItemPosition(this));
 		OS.g_menu_insert_item(section.getSectionHandle(), section.getItemPosition(this), handle);
+
+		// When setText() is called
+		if (labelHandle != 0 && GTK.GTK_IS_LABEL(labelHandle)) {
+		    GTK.gtk_label_set_text_with_mnemonic(labelHandle, buffer);
+		    GTK.gtk_widget_set_visible(labelHandle, true);
+		}
+
 	} else {
 		if (labelHandle != 0 && GTK.GTK_IS_LABEL (labelHandle)) {
 			GTK.gtk_label_set_text_with_mnemonic (labelHandle, buffer);

@akurtakov @tmssngr Please give it a try and see what I am missing here ? I also commented out previous approach i explained about using GIcon..

raghucssit avatar Sep 23 '25 07:09 raghucssit

For the record this and https://github.com/eclipse-platform/eclipse.platform.swt/issues/2299 are duplicates.

akurtakov avatar Sep 23 '25 07:09 akurtakov

My client code:

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class PopupMenuExample {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("SWT Popup Menu Example");
        shell.setSize(300, 200);

        // Create a POP_UP menu
        Menu popupMenu = new Menu(shell, SWT.POP_UP);
        shell.setMenu(popupMenu);

        // PUSH menu item
        MenuItem pushItem1 = new MenuItem(popupMenu, SWT.PUSH);
        pushItem1.setText("Click Me1");

        // PUSH menu item
        MenuItem pushItem2 = new MenuItem(popupMenu, SWT.PUSH);
        pushItem2.setText("Click Me2");

        // Action for menu item
        pushItem1.addListener(SWT.Selection, e -> System.out.println("Push item clicked"));

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}

raghucssit avatar Sep 23 '25 07:09 raghucssit

Hi @raghucssit, I'm working on #2299. I think changes will also need to be made to ImageList.java in order to fix images for GTK4. I don't know if you have already had a look at this, but if you have an approach in mind I would like to hear it as I am finding it quite difficult.

Hi @raghucssit, I'm working on #2299. I think changes will also need to be made to ImageList.java in order to fix images for GTK4. I don't know if you have already had a look at this, but if you have an approach in mind I would like to hear it as I am finding it quite difficult.

I have not looked into ImageList.. My primary focus is to support custom widget inside PopoverMenu. SWT has implemented Menu using this GTK API. My approach is to add a custom GtkWidget using PopoverMenu.add_child API. But this is not working as I have added my patch above...

According to GIO API doc, Other option available is we can support it using MenuItem.set_icon. But I did not proceed with this because currently SWT does not have GIcon support. Currently even for GTK4 everywhere existing GTK Image is used with GtkBox. Like ToolItem here.. This is the motivation to use custom widget in my case.

Which approach are you using to support image in MenuItem ? Is there any other approach ?

raghucssit avatar Sep 23 '25 10:09 raghucssit

The main issue is the depreciation of Cairo surfaces from GTK3 to GTK4. ImageList uses these extensively and an alternative is required, I am currently attempting to substitute with paintables but it is not a perfect match.

The main issue is the depreciation of Cairo surfaces from GTK3 to GTK4. ImageList uses these extensively and an alternative is required, I am currently attempting to substitute with paintables but it is not a perfect match.

If I have understood it right.. I think something similar is already there.. For example ToolItem#_setImage uses same ImageList and uses paintable to display images.. We can fix MenuItem#_setImage similarly.. But before that we have to support custom widget to PopoverMenu that holds GtkBox and image can added on it.

raghucssit avatar Sep 23 '25 14:09 raghucssit

I've had a look at ToolItem and that seems like a great approach. Thank you for pointing it out.

I figured out what was the issue when I tried adding custom widget to popover. I wanted to add custom widget to MenuItem itself. That is what we need anyway. But It is not possible with GTK. What is possible is we can add a custom item to popover menu. It appears like a Menu Item itself. See the below example I have tried with Button and Box [image+lable].

https://github.com/user-attachments/assets/b591d6d9-0401-4061-979c-1de562ea210a

However Custom Button look different than default Menu Item. So using a Button looks bad. May be we can customize the look of Button in GTK. If that is possible. Then we need to rework a lot in Menu Item because currently Menu is populated using default Menu Model and Action is attached to each menu item.

To me it seems much better to support Icon itself instead of custom approach.. However on plain GTK itself I have not been able to set icon yet... I will continue on that..

Below is the GTK code that i have tried.. Note I have attached an icon to menu item but it does not show any icon.. I have tried some other approached still they did not show icon.

#include <gtk/gtk.h>

// Action callback
static void on_item1_action(GSimpleAction *action, GVariant *parameter, gpointer user_data) {
    g_print("Item 1 activated!\n");
}

static void on_button_clicked(GtkWidget *button, gpointer user_data) {
    GtkApplication *app = GTK_APPLICATION(user_data);

    // Define the popover menu model.
    GMenu *menu = g_menu_new();

    // Create real popover from model
    GtkWidget *popover = gtk_popover_menu_new_from_model(G_MENU_MODEL(menu));
    gtk_widget_set_parent(popover, button);

    // Custom Item 1
    GMenuItem *custom_item1 = g_menu_item_new("Custom Area", NULL);
    g_menu_item_set_attribute(custom_item1, "custom", "s", "custom-1");
    g_menu_insert_item(menu, 0, custom_item1);
    g_object_unref(custom_item1);

    // Custom Button
    GMenuItem *custom_item_button = g_menu_item_new("Custom Button", NULL);
    g_menu_item_set_attribute(custom_item_button, "custom", "s", "custom-button");
    g_menu_insert_item(menu, 0, custom_item_button);
    g_object_unref(custom_item_button);


    // Normal menu item
    GMenuItem *item1 = g_menu_item_new("Item 1", "app.item1");  // <-- attach action name
    GIcon *icon1 = g_themed_icon_new("document-open-symbolic");
    g_menu_item_set_icon(item1, icon1);
    g_menu_append_item(menu, item1);
    g_object_unref(item1);
    g_object_unref(icon1);

    // Add custom widget for placeholder
    GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
    GtkWidget *image = gtk_image_new_from_icon_name("document-save-symbolic");
    GtkWidget *label = gtk_label_new("Custom Image");
    gtk_box_append(GTK_BOX(box), image);
    gtk_box_append(GTK_BOX(box), label);
    gtk_popover_menu_add_child(GTK_POPOVER_MENU(popover), box, "custom-1");

    // --- Custom widget 2: button styled like a menu item
      GtkWidget *custom_button = gtk_button_new_with_label("Custom Button");
      gtk_widget_add_css_class(custom_button, "model");  // makes it look like a menu row
      g_signal_connect(custom_button, "clicked", G_CALLBACK(on_item1_action), NULL);
      gtk_popover_menu_add_child(GTK_POPOVER_MENU(popover), custom_button, "custom-button");

    // Register the action with the application
    GSimpleAction *action = g_simple_action_new("item1", NULL);
    g_signal_connect(action, "activate", G_CALLBACK(on_item1_action), NULL);
    g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(action));
    g_object_unref(action);

    // Show the popover
    gtk_widget_set_visible(popover, TRUE);
}

static void activate(GtkApplication *app, gpointer user_data) {
    GtkWidget *window = gtk_application_window_new(app);
    gtk_window_set_title(GTK_WINDOW(window), "GTK4 Popover with Actions");
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);

    GtkWidget *button = gtk_button_new_with_label("Click me");
    g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), app);
    gtk_window_set_child(GTK_WINDOW(window), button);

    gtk_window_present(GTK_WINDOW(window));
}

int main(int argc, char *argv[]) {
    GtkApplication *app = gtk_application_new("org.example.popover", G_APPLICATION_DEFAULT_FLAGS);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    int status = g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);
    return status;
}

How to compile and run:

gcc popover.c -o popover `pkg-config --cflags --libs gtk4`
./popover

raghucssit avatar Sep 25 '25 10:09 raghucssit

@raghucssit Maybe you want to give https://developer.gnome.org/documentation/tools/inspector.html a try and see the exact css and whatever other properties are needed to make it look the same.

akurtakov avatar Sep 25 '25 10:09 akurtakov

GTK has decided to not to show icons in popover. https://gitlab.gnome.org/GNOME/gtk/-/issues/7219 There is no where it is mentioned in documentation.. I tried every possible approach to set an icon they never shown because they just ignore them.. Only way possible to support this is custom widget.. Box[image+button]. So by default every item in the menu should be custom only because image are set later and we don't know if client sets image or not so we have to keep the placeholder..

raghucssit avatar Sep 26 '25 10:09 raghucssit

Native C code that works:

/* custom placeholder at position 0 */
	GMenuItem *custom_btn_flat = g_menu_item_new(NULL, NULL); /* label not required */
	g_menu_item_set_attribute(custom_btn_flat, "custom", "s", "custom-btn-flat");
	g_menu_insert_item(menu, 0, custom_btn_flat);
	g_object_unref(custom_btn_flat);

	/* 3) Create custom widget: a button styled as a menu-item */
	GtkWidget *btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
	GtkWidget *img = gtk_image_new_from_icon_name("document-open-symbolic");
	GtkWidget *lbl = gtk_label_new("Button with Image");
	gtk_box_append(GTK_BOX(btn_box), img);
	gtk_box_append(GTK_BOX(btn_box), lbl);

	GtkWidget *menu_button = gtk_button_new();
	/* put box (image+label) into the button */
	gtk_button_set_child(GTK_BUTTON(menu_button), btn_box);

	/* style the button so it looks like a menu item */
	gtk_widget_add_css_class(menu_button, "model"); /* matches menu item style */
	gtk_widget_add_css_class(menu_button, "flat"); /* remove button chrome */

	/* register custom child with the same ID as model */
	gtk_popover_menu_add_child(GTK_POPOVER_MENU(popover), menu_button, "custom-btn-flat");

SWT Native call that does not work:

case SWT.PUSH:
			default:
				actionHandle = OS.g_simple_action_new(Converter.javaStringToCString(String.valueOf(this.hashCode())), 0);
				OS.g_action_map_add_action(parent.actionGroup, actionHandle);
				actionName = String.valueOf(parent.hashCode()) + "." + String.valueOf(this.hashCode());
				handle = OS.g_menu_item_new(null, null);

				//new fix
				// Define a custom id and set it as a custom attribute to Menu Item model.
				customId = "swt-item-" + this.hashCode();
				byte[] attr = Converter.javaStringToCString("custom");
				byte[] fmt  = Converter.javaStringToCString("s");
				idBytes = Converter.javaStringToCString(customId + "\0"); // Ensure null-terminated
				// Allocate native buffer for string value
				long idPtr = OS.g_malloc(idBytes.length);
				C.memmove(idPtr, idBytes, idBytes.length);
				OS.g_menu_item_set_attribute(handle, attr, fmt, idPtr);
				OS.g_free(idPtr);

				// Create a actual custom widget to replace the menu item.
				boxHandle = GTK.gtk_box_new(GTK.GTK_ORIENTATION_HORIZONTAL, 6);
				if (boxHandle == 0) error(SWT.ERROR_NO_HANDLES);
//			    imageHandle = GTK.gtk_image_new();
//			    if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
			    labelHandle = GTK.gtk_label_new_with_mnemonic(null);
			    if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES);
			    //place holder in case of some location allocation.
			    byte[] buffer = Converter.wcsToMbcs("dummy Label", true);
			    GTK.gtk_label_set_text_with_mnemonic(labelHandle, buffer);
//			    GTK4.gtk_box_append(boxHandle, imageHandle);
			    GTK4.gtk_box_append(boxHandle, labelHandle);

				 menu_button = GTK.gtk_button_new();
				/* put box (image+label) into the button */
				GTK4.gtk_button_set_child(menu_button, boxHandle);

//				/* style the button so it looks like a menu item. We can add them to native API later. */
//				gtk_widget_add_css_class(menu_button, "model"); /* IMPORTANT: matches menu item style */
//				gtk_widget_add_css_class(menu_button, "flat"); /* optional: remove button chrome */

				/* 4) register custom child with the same ID as model */
				GTK4.gtk_popover_menu_add_child(parent.handle, menu_button, idBytes);

				break;

Native Definition of add child:

#ifndef NO_gtk_1popover_1menu_1add_1child
JNIEXPORT jboolean JNICALL GTK4_NATIVE(gtk_1popover_1menu_1add_1child)
  (JNIEnv *env, jclass that, jlong arg0, jlong arg1, jbyteArray arg2)
{
    jbyte *lparg2 = NULL;
    jboolean rc = JNI_FALSE;
    GTK4_NATIVE_ENTER(env, that, gtk_1popover_1menu_1add_1child_FUNC);
    if (arg2) {
        if ((lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL)) == NULL) goto fail;
    }
    rc = (jboolean) gtk_popover_menu_add_child(
            (GtkPopoverMenu *) (intptr_t) arg0,
            (GtkWidget *) (intptr_t) arg1,
            (const gchar *) lparg2);
fail:
    if (arg2 && lparg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, 0);
    GTK4_NATIVE_EXIT(env, that, gtk_1popover_1menu_1add_1child_FUNC);
    return rc;
}
#endif

Result is not expected: Pure C result:

https://github.com/user-attachments/assets/03cf028f-719f-445e-8559-b86162d29321

SWT patch result:

https://github.com/user-attachments/assets/b679a16a-ebff-4ddd-815d-334b9d4601d5

raghucssit avatar Sep 29 '25 09:09 raghucssit

FYI https://github.com/eclipse-platform/eclipse.platform.swt/pull/2552 claims to made progress too. Maybe you should cooperate more guys although the learning experience here is totally worth it.

akurtakov avatar Sep 29 '25 09:09 akurtakov

public class PopupMenuExample {

I was working with @Theo-Dann-Muirhead-Renesas on this today. On his Ubuntu 24.04 (which has GTK 4.14) he sees the same broken menu as @raghucssit's screencast shows. But on my Ubuntu 25.04 machine (which has GTK 4.18) the pop-up menu works with your code:

https://github.com/user-attachments/assets/0d0755af-b2b6-4224-ad10-c49d70d80610

@raghucssit which version of GTK are you using? Could we be exposed to bugs in GTK that have since been fixed here?

jonahgraham avatar Oct 06 '25 16:10 jonahgraham

@jonahgraham My gtk version is gtk4-4.16.7-1.el10.x86_64. I am using RHEL 10 with Wayland windowing system. Yes possibly i might have exposed to bugs i am slightly behind your gtk version.

raghucssit avatar Nov 18 '25 08:11 raghucssit