Thanks! I think this needs changes/refactoring.
2022-04-13 (水) の 21:00 +0200 に Robert Panovics さんは書きました:
> Reparenting of popover menu for transport playhead and> BPM for positioning> > Fixes https://todo.sr.ht/~alextee/zrythm-bug/860> > Signed-off-by: Robert Panovics <robert.panovics@gmail.com>> ---> src/gui/widgets/bot_bar.c | 32 ++++++++++++++++++++++++++++++--> 1 file changed, 30 insertions(+), 2 deletions(-)> > diff --git a/src/gui/widgets/bot_bar.c b/src/gui/widgets/bot_bar.c> index dc3cec839..fd41fd89b 100644> --- a/src/gui/widgets/bot_bar.c> +++ b/src/gui/widgets/bot_bar.c> @@ -125,6 +125,18 @@ activate_jack_mode (> }> #endif> > +static void> +popover_menu_set_parent (> + GtkWidget * parent,> + GtkPopoverMenu * self)
As a convention, the "subject" of a function (usually something called
"self") should be the first argument.
> +{> + GtkWidget * ref => + g_object_ref (GTK_WIDGET (self));> + gtk_widget_unparent (ref);> + gtk_widget_set_parent (GTK_WIDGET (ref), parent);> + g_object_unref (ref);> +}> +> static void> on_bpm_right_click (> GtkGestureClick * gesture,> @@ -147,8 +159,16 @@ on_bpm_right_click (> _ ("Tap"), NULL, "app.tap-bpm");> g_menu_append_item (menu, menuitem);> > + popover_menu_set_parent (> + GTK_WIDGET (self->digital_bpm),> + self->popover_menu);
I don't think it's a good idea to keep reusing a single popover in many
different widgets. Each right-clickable widget should have its own
popover in its own code, so this should go to DigitalMeterWidget. I
would add a Bin layout on DigitalMeterWidget's widget class (see gtk
docs for GtkBinLayout or grep the code for `BIN_LAYOUT` for examples)
and add a popover in there instead of in this file (note you need to
unparent it during `dispose()`). BotBarWidget should have no popover at
all.
> +> z_gtk_show_context_menu_from_g_menu (> - self->popover_menu, x, y, menu);> + self->popover_menu,> + gtk_widget_get_allocated_width (> + GTK_WIDGET (self->digital_bpm))> + / 2.0,> + 0.0, menu);> }> > static void> @@ -217,8 +237,16 @@ on_transport_playhead_right_click (> GTK_WIDGET (self), "bot-bar",> G_ACTION_GROUP (action_group));
Same as above, this should be handled inside DigitalMeterWidget and all
popover logic should be removed from this file.
> > + popover_menu_set_parent (> + GTK_WIDGET (self->digital_transport),> + self->popover_menu);> +> z_gtk_show_context_menu_from_g_menu (> - self->popover_menu, x, y, menu);> + self->popover_menu,> + gtk_widget_get_allocated_width (> + GTK_WIDGET (self->digital_transport))> + / 2.0,> + 0.0, menu);> }> > void