Replace Menu with Popover
This is an initial work on replacing Gtk.Menu with a Gtk.Popover because Gtk.Menu is dropped in GTK4.
This aims to solve https://github.com/elementary/camera/issues/205
Thanks @Marukesu
@Marukesu I have tried it but it resulted in Segmentation Fault. There is no better documentation on valadoc about the difference of display_name or name just that display_name is for user-friendly name while there is no definition for name
@Marukesu I have tried it but it resulted in Segmentation Fault.
Try it now, i made some changes on the action, it's now an PropertyAction, so we don't need to provide an fallback, or default value, also it's calling change_camera direct as before when finding a new camera.
There is no better documentation on valadoc about the difference of
display_nameornamejust thatdisplay_nameis for user-friendly name while there is no definition forname
Gst.Object.name is guaranteed to be unique, while display_name isn't. The old code already used this to find the right device when removing it from the menu.
also, it seems that Gtk.MenuButton can use an GLib.MenuModel directly, so we don't need to create the Gtk.Popover.
Okay. I will try it now, Thanks!
also, it seems that Gtk.MenuButton can use an GLib.MenuModel directly, so we don't need to create the Gtk.Popover.
I have replaced Gtk.Menu with a GLib.Menu (which is a subclass of GLib.MenuModel we can add items in) and added the bits and pieces you suggested before to easily add and remove a device to the menu. However, I have not yet managed to create a radiobutton-like behavior where we can select which camera device to use, instead, it shows only as a string. I will continue to research from here. Thanks!
@Marukesu Is there a way we can pass a Gst.Device as a detailed_action?
Because in add_camera_option, we do
camera_options.append (camera.display_name, GLib.Action.print_detailed_name (
MainWindow.ACTION_PREFIX + MainWindow.ACTION_CHANGE_CAMERA,
new GLib.Variant.string (camera.name)
));
while the change_camera functions look like this:
public void change_camera (Gst.Device camera)
Basically, we cannot pass the camera.name by itself because the function uses a Gst.Device as parameter. I also tried changing the function to public void change_camera (string camera_name), but there are other parts of the function that uses other parts of the Gst.Device aside from the name itself
there a way we can pass a Gst.Device as a
detailed_action?
Not that i can think of, action parameters need to be a GLib.Variant and we can't store arbitrary objects in thoses.
Basically, we cannot pass the camera.name by itself because the function uses a Gst.Device as parameter. I also tried changing the function to
public void change_camera (string camera_name), but there are other parts of the function that uses other parts of the Gst.Device aside from the name itself
Yeah, that's why in the camera_name setter we search the for the camera device in the monitor and then call change_camera.
When a new camera is added, we already have the device in hands, so make more sense to use change_camera directly and notify about the change (the notify_property line) than setting the property and having it to search the device again.
Sorry for the late reply @Marukesu , I will look into it. Thanks!
A more updated fix is in the works