[PATCH] Popover menu position fix on bottom bar
Export this patch
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>
---
inc/gui/widgets/bot_bar.h | 2 --
inc/gui/widgets/digital_meter.h | 12 ++++++++++++
src/gui/widgets/bot_bar.c | 18 +++++-------------
src/gui/widgets/digital_meter.c | 33 +++++++++++++++++++++++++++++++++
4 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/inc/gui/widgets/bot_bar.h b/inc/gui/widgets/bot_bar.h
index 070e52910..713bd76af 100644
--- a/inc/gui/widgets/bot_bar.h
+++ b/inc/gui/widgets/bot_bar.h
@@ -110,8 +110,6 @@ typedef struct _BotBarWidget
char green_hex[8];
char red_hex[8];
- /** Popover to be reused for context menus. */
- GtkPopoverMenu * popover_menu;
} BotBarWidget;
void
diff --git a/inc/gui/widgets/digital_meter.h b/inc/gui/widgets/digital_meter.h
index d745d1355..cf31600cf 100644
--- a/inc/gui/widgets/digital_meter.h
+++ b/inc/gui/widgets/digital_meter.h
@@ -180,6 +180,8 @@ typedef struct _DigitalMeterWidget
PangoLayout * normal_layout;
bool initialized;
+
+ GtkPopoverMenu * popover_menu;
} DigitalMeterWidget;
/**
@@ -231,6 +233,16 @@ digital_meter_set_draw_line (
DigitalMeterWidget * self,
int draw_line);
+/**
+ * Shows the widgets popover menu with the provided content
+ *
+ * @param menu content of the popover menu
+ */
+void
+digital_meter_show_context_menu (
+ DigitalMeterWidget * self,
+ GMenu * menu);
+
/**
* @}
*/
diff --git a/src/gui/widgets/bot_bar.c b/src/gui/widgets/bot_bar.c
index dc3cec839..b65a5a242 100644
--- a/src/gui/widgets/bot_bar.c
+++ b/src/gui/widgets/bot_bar.c
@@ -147,8 +147,8 @@ on_bpm_right_click (
_ ("Tap"), NULL, "app.tap-bpm");
g_menu_append_item (menu, menuitem);
- z_gtk_show_context_menu_from_g_menu (
- self->popover_menu, x, y, menu);
+ digital_meter_show_context_menu (
+ self->digital_bpm, menu);
}
static void
@@ -214,11 +214,11 @@ on_transport_playhead_right_click (
#endif
gtk_widget_insert_action_group (
- GTK_WIDGET (self), "bot-bar",
+ GTK_WIDGET (self->digital_transport), "bot-bar",
G_ACTION_GROUP (action_group));
- z_gtk_show_context_menu_from_g_menu (
- self->popover_menu, x, y, menu);
+ digital_meter_show_context_menu (
+ self->digital_transport, menu);
}
void
@@ -598,8 +598,6 @@ bot_bar_widget_setup (BotBarWidget * self)
static void
dispose (BotBarWidget * self)
{
- gtk_widget_unparent (
- GTK_WIDGET (self->popover_menu));
gtk_widget_unparent (
GTK_WIDGET (self->center_box));
@@ -617,12 +615,6 @@ bot_bar_widget_init (BotBarWidget * self)
gtk_widget_init_template (GTK_WIDGET (self));
- self->popover_menu = GTK_POPOVER_MENU (
- gtk_popover_menu_new_from_model (NULL));
- gtk_widget_set_parent (
- GTK_WIDGET (self->popover_menu),
- GTK_WIDGET (self));
-
ui_gdk_rgba_to_hex (
&UI_COLORS->bright_orange, self->hex_color);
ui_gdk_rgba_to_hex (
diff --git a/src/gui/widgets/digital_meter.c b/src/gui/widgets/digital_meter.c
index c3622d05f..5a0df4cea 100644
--- a/src/gui/widgets/digital_meter.c
+++ b/src/gui/widgets/digital_meter.c
@@ -884,6 +884,19 @@ digital_meter_set_draw_line (
gtk_widget_queue_draw (GTK_WIDGET (self));
}
+void
+digital_meter_show_context_menu (
+ DigitalMeterWidget * self,
+ GMenu * menu)
+{
+ z_gtk_show_context_menu_from_g_menu (
+ self->popover_menu,
+ gtk_widget_get_allocated_width (
+ GTK_WIDGET (self))
+ / 2.0,
+ 0.0, menu);
+}
+
/**
* Motion callback.
*/
@@ -1392,6 +1405,16 @@ _digital_meter_widget_new_for_position (
return self;
}
+static void
+dispose (DigitalMeterWidget * self)
+{
+ gtk_widget_unparent (
+ GTK_WIDGET (self->popover_menu));
+
+ G_OBJECT_CLASS (digital_meter_widget_parent_class)
+ ->dispose (G_OBJECT (self));
+}
+
static void
finalize (DigitalMeterWidget * self)
{
@@ -1418,8 +1441,12 @@ digital_meter_widget_class_init (
gtk_widget_class_set_css_name (
wklass, "digital-meter");
+ gtk_widget_class_set_layout_manager_type (
+ wklass, GTK_TYPE_BIN_LAYOUT);
+
GObjectClass * oklass = G_OBJECT_CLASS (klass);
oklass->finalize = (GObjectFinalizeFunc) finalize;
+ oklass->dispose = (GObjectFinalizeFunc) dispose;
}
static void
@@ -1473,4 +1500,10 @@ digital_meter_widget_init (
gtk_widget_add_controller (
GTK_WIDGET (self),
GTK_EVENT_CONTROLLER (click_gesture));
+
+ self->popover_menu = GTK_POPOVER_MENU (
+ gtk_popover_menu_new_from_model (NULL));
+ gtk_widget_set_parent (
+ GTK_WIDGET (self->popover_menu),
+ GTK_WIDGET (self));
}
--
2.35.1
Applied, thanks!