From 02b1d9603b83d99cb1abdb4b6cf04cb6c604cdb6 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 25 Mar 2025 16:56:18 -0300 Subject: [PATCH] sysprof: Add stub context menu to SysprofMarkChartRow This will expose the action to set this row's mark catalog as a session filter. --- src/sysprof/sysprof-mark-chart-row.c | 48 +++++++++++++++++++++++++++ src/sysprof/sysprof-mark-chart-row.ui | 18 ++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/sysprof/sysprof-mark-chart-row.c b/src/sysprof/sysprof-mark-chart-row.c index 5d41ad81..e91f3c96 100644 --- a/src/sysprof/sysprof-mark-chart-row.c +++ b/src/sysprof/sysprof-mark-chart-row.c @@ -31,6 +31,9 @@ struct _SysprofMarkChartRow { GtkWidget parent_instance; + GMenuModel *context_menu; + GtkWidget *context_menu_popover; + SysprofMarkChartItem *item; SysprofChart *chart; @@ -79,6 +82,49 @@ sysprof_mark_chart_row_activate_layer_item_cb (SysprofMarkChartRow *self, return FALSE; } +static void +sysprof_mark_chart_row_button_pressed_cb (SysprofMarkChartRow *self, + int n_press, + double x, + double y, + GtkGestureClick *gesture) +{ + GdkEventSequence *current; + GdkEvent *event; + + g_assert (SYSPROF_IS_MARK_CHART_ROW (self)); + g_assert (GTK_IS_GESTURE_CLICK (gesture)); + + current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)); + event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), current); + + if (!gdk_event_triggers_context_menu (event)) + return; + + if (!self->context_menu_popover) + { + self->context_menu_popover = gtk_popover_menu_new_from_model (self->context_menu); + gtk_popover_set_position (GTK_POPOVER (self->context_menu_popover), GTK_POS_BOTTOM); + gtk_popover_set_has_arrow (GTK_POPOVER (self->context_menu_popover), FALSE); + gtk_widget_set_halign (self->context_menu_popover, GTK_ALIGN_START); + gtk_widget_set_parent (GTK_WIDGET (self->context_menu_popover), GTK_WIDGET (self)); + } + + if (x != -1 && y != -1) + { + GdkRectangle rect = { x, y, 1, 1 }; + gtk_popover_set_pointing_to (GTK_POPOVER (self->context_menu_popover), &rect); + } + else + { + gtk_popover_set_pointing_to (GTK_POPOVER (self->context_menu_popover), NULL); + } + + gtk_popover_popup (GTK_POPOVER (self->context_menu_popover)); + + gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED); +} + static void sysprof_mark_chart_row_dispose (GObject *object) { @@ -154,8 +200,10 @@ sysprof_mark_chart_row_class_init (SysprofMarkChartRowClass *klass) gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-mark-chart-row.ui"); gtk_widget_class_bind_template_child (widget_class, SysprofMarkChartRow, chart); + gtk_widget_class_bind_template_child (widget_class, SysprofMarkChartRow, context_menu); gtk_widget_class_bind_template_child (widget_class, SysprofMarkChartRow, layer); gtk_widget_class_bind_template_callback (widget_class, sysprof_mark_chart_row_activate_layer_item_cb); + gtk_widget_class_bind_template_callback (widget_class, sysprof_mark_chart_row_button_pressed_cb); g_type_ensure (SYSPROF_TYPE_CHART); g_type_ensure (SYSPROF_TYPE_TIME_SERIES_ITEM); diff --git a/src/sysprof/sysprof-mark-chart-row.ui b/src/sysprof/sysprof-mark-chart-row.ui index b5683569..3bd54d45 100644 --- a/src/sysprof/sysprof-mark-chart-row.ui +++ b/src/sysprof/sysprof-mark-chart-row.ui @@ -1,6 +1,24 @@