Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade muda to gtk4-rs #270

Open
5 tasks
tweidinger opened this issue Jan 28, 2025 · 1 comment · May be fixed by #272
Open
5 tasks

Upgrade muda to gtk4-rs #270

tweidinger opened this issue Jan 28, 2025 · 1 comment · May be fixed by #272
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@tweidinger
Copy link

We need to upgrade from gtk to gtk4-rs to migrate a unsoundness issue found in glib < 0.2.
Please claim this issue if you want to support or work on this and keep in mind this is a prioritized issue and we try to migrate as soon as possible. If the issue is already assigned to someone you can either reach out with comments or questions reach out for collaboration to the assigned person.

This transition includes:

  • Upgrading gtk to gtk4-rs and handling all errors caused by the dependency change
  • Handle all changes in a backwards compatible way if possible
    • Raise awareness to the working group if breaking changes are required
  • Document migration errors that may be issues in the future or which were complicated to handle
  • Reach out to the working group (alternatively @tweidinger first) if blockers or upstream issues are hit
@tweidinger tweidinger converted this from a draft issue Jan 28, 2025
@amrbashir
Copy link
Member

amrbashir commented Jan 31, 2025

I did a bit of testing and research and this is not going to be an easy task at all, a lot of the APIs has changed and it may require a full rewrite of the gtk backend from scratch.

Here is a dump of what I discovered in case anyone wants to help:

  • menu bar:
    • gtk::PopoverMenuBar::from_model and gio::Menu -> create menu bar
    • can only have submenus (unlike gtk3 which can have items)
  • submenu:
    • gio::MenuItem::new_submenu and gio::Menu -> create submenu item
  • menu item:
    • gio::MenuItem -> create menu item
    • gio::SimpleAction -> define an action for menu item
    • gio::SimpleAction::connect_activate -> listen to menu item activation
    • gio::SimpleAction::set_enabled -> disable or enable item
    • gio::SimpleActionGroup -> define an action group
    • gtk::Window::insert_action_group -> add action group to window, pass None to remove
  • check menu item:
    • gio::SimpleAction::new_stateful -> create action for check menu item, must have a boolean as the state
    • gio::SimpleAction::connect_state_notify -> listen for activation on check menu item state without interrupting gtk4 internal state management
  • icon menu item
    • gio::MenuItem::set_icon -> set icon for menu item
    • gio::BytesIcon -> Load Png icon from bytes
  • accelerators:
    • Application::set_accels -> set accelerator for action, this is global for applicaiton, unlike gtk3 which was per Window. However this should be fine, since the SimpleActionGroup will be added to a specific window resulting in the same behavior of gtk3 (ensuring that each group and its actions are unique to the window)
  • separator menu item
    • This concept is no longer valid and replaced by section submenus (gio::MenuItem::new_section)

And another dump of code that I was testing with (not fully working, adapted from https://github.com/gtk-rs/gtk4-rs/blob/main/examples/menubar/main.rs)

fn main() {
   let window = gtk4::ApplicationWindow::builder()
        .application(application)
        .title("Menubar Example")
        .default_width(350)
        .default_height(350)
        .show_menubar(true)
        .build();


   let menubar = {
        let file_menu = {
            let about_menu_item = gtk4::gio::MenuItem::new(Some("About"), Some(&"muda.about"));
            let quit_menu_item = gtk4::gio::MenuItem::new(Some("Quit"), Some(&"muda.quit"));

            let file_menu = gtk4::gio::Menu::new();
            file_menu.append_item(&about_menu_item);
            file_menu.append_item(&quit_menu_item);
            file_menu
        };

        let menu_bar_m = gtk4::gio::Menu::new();
        menu_bar_m.append_item(&gtk4::gio::MenuItem::new_submenu(Some("File"), &file_menu));

        let menubar = gtk4::PopoverMenuBar::from_model(Some(&menu_bar_m));

        menubar
    };

    let action = gio::SimpleAction::new_stateful("about", None, &glib::Variant::from(true));
    action.connect_activate(move |_, _| {
        println!("about");
    });
    application.set_accels_for_action("muda.about", &["<Control>C"]);


    let action_group = gio::SimpleActionGroup::new();
    action_group.add_action(&action);
    window.insert_action_group("muda", Some(&g));

    let vbox = gtk4::Box::new(gtk4::Orientation::Vertical, 0);
    vbox.append(&menubar);

    window.set_child(Some(&vbox));
}

@tweidinger tweidinger added enhancement New feature or request help wanted Extra attention is needed labels Jan 31, 2025
amrbashir added a commit that referenced this issue Feb 1, 2025
closes #270

kicking off work on gtk4 migration

help is appreciated
@amrbashir amrbashir linked a pull request Feb 1, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Development

Successfully merging a pull request may close this issue.

2 participants