Adding shortcut for search bar

I’m rewriting my software in GTK4/5 and, while at it, I wanted to switch to a proper coding methodology.

I now have the following:

struct _OTPClientWindow
    AdwApplicationWindow parent;
    GtkToggleButton *search_button;


static void
otpclient_window_show_searchbar (GSimpleAction *simple,
                                 GVariant      *parameter,
                                 gpointer       user_data)
    OTPClientWindow *self = OTPCLIENT_WINDOW(user_data);
    gtk_toggle_button_set_active (self->search_button, TRUE);

static void
otpclient_window_init (OTPClientWindow *self)
    gtk_widget_init_template (GTK_WIDGET(self));

    const GActionEntry win_entries[] = {
            { .name = "search", .activate = otpclient_window_show_searchbar, NULL, NULL, NULL },
    g_action_map_add_action_entries (G_ACTION_MAP(self), win_entries, G_N_ELEMENTS(win_entries), self);

static void
otpclient_window_class_init (OTPClientWindowClass *class)
    G_OBJECT_CLASS (class)->dispose = otpclient_window_dispose;
    gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS(class), "/com/github/paolostivanin/OTPClient/ui/window.ui");
    gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS(class), OTPClientWindow, search_button);


while in my application_startup routine I have: set_accel_for_action (self, "", "<Control>f");.

In my ui file I have:

              <object class="GtkToggleButton" id="search_button">
                <property name="icon-name">system-search-symbolic</property>

now, when I compile everything and execute ctrl-f, I get:

(otpclient:9253): Gtk-CRITICAL **: 15:08:44.865: gtk_toggle_button_set_active: assertion 'GTK_IS_TOGGLE_BUTTON (toggle_button)' failed

what am I missing here?

What do you mean with this? There is no GTK5 yet :slightly_smiling_face:

There will an alpha next year it seems. If you look at the deprecation branch in GTK repo, you’ll see that quite some stuff will be removed with GTK 5 (e.g. treevivew). More info here: On deprecations – GTK Development Blog

So, since I had to rewrite part of the code for gtk4, I took the opportunity to do a from scratch rewrite and be done for the foreseeable future :slight_smile:

No, it’s still very much up in the air. We don’t have a definite set of requirements for breaking API, at the moment.

Those are just deprecations: it’s how we move the toolkit forward.

1 Like

I know :slight_smile: but since I’m rewriting it from scratch, avoiding deprecations I think it’s the best approach :smiley: