diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index 8fc49316..d971be62 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -14,6 +14,7 @@ sysprof_sources = [ 'sysprof-section.c', 'sysprof-sidebar.c', 'sysprof-single-model.c', + 'sysprof-traceables-utility.c', 'sysprof-window.c', ] diff --git a/src/sysprof/sysprof-traceables-utility.c b/src/sysprof/sysprof-traceables-utility.c new file mode 100644 index 00000000..a3cb5f6e --- /dev/null +++ b/src/sysprof/sysprof-traceables-utility.c @@ -0,0 +1,137 @@ +/* sysprof-traceables-utility.c + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include + +#include "sysprof-traceables-utility.h" + +struct _SysprofTraceablesUtility +{ + GtkWidget parent_instance; + SysprofSession *session; + GListModel *traceables; +}; + +enum { + PROP_0, + PROP_SESSION, + PROP_TRACEABLES, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofTraceablesUtility, sysprof_traceables_utility, GTK_TYPE_WIDGET) + +static GParamSpec *properties[N_PROPS]; + +static void +sysprof_traceables_utility_finalize (GObject *object) +{ + SysprofTraceablesUtility *self = (SysprofTraceablesUtility *)object; + GtkWidget *child; + + gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_TRACEABLES_UTILITY); + + while ((child = gtk_widget_get_first_child (GTK_WIDGET (object)))) + gtk_widget_unparent (child); + + g_clear_object (&self->session); + + G_OBJECT_CLASS (sysprof_traceables_utility_parent_class)->finalize (object); +} + +static void +sysprof_traceables_utility_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofTraceablesUtility *self = SYSPROF_TRACEABLES_UTILITY (object); + + switch (prop_id) + { + case PROP_SESSION: + g_value_set_object (value, self->session); + break; + + case PROP_TRACEABLES: + g_value_set_object (value, self->traceables); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_traceables_utility_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofTraceablesUtility *self = SYSPROF_TRACEABLES_UTILITY (object); + + switch (prop_id) + { + case PROP_SESSION: + g_set_object (&self->session, g_value_get_object (value)); + break; + + case PROP_TRACEABLES: + g_set_object (&self->traceables, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_traceables_utility_class_init (SysprofTraceablesUtilityClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->finalize = sysprof_traceables_utility_finalize; + object_class->get_property = sysprof_traceables_utility_get_property; + object_class->set_property = sysprof_traceables_utility_set_property; + + properties[PROP_SESSION] = + g_param_spec_object ("session", NULL, NULL, + SYSPROF_TYPE_SESSION, + (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + + properties[PROP_TRACEABLES] = + g_param_spec_object ("traceables", NULL, NULL, + G_TYPE_LIST_MODEL, + (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-traceables-utility.ui"); + gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); +} + +static void +sysprof_traceables_utility_init (SysprofTraceablesUtility *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} diff --git a/src/sysprof/sysprof-traceables-utility.h b/src/sysprof/sysprof-traceables-utility.h new file mode 100644 index 00000000..f76063b7 --- /dev/null +++ b/src/sysprof/sysprof-traceables-utility.h @@ -0,0 +1,31 @@ +/* sysprof-traceables-utility.h + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_TRACEABLES_UTILITY (sysprof_traceables_utility_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofTraceablesUtility, sysprof_traceables_utility, SYSPROF, TRACEABLES_UTILITY, GtkWidget) + +G_END_DECLS diff --git a/src/sysprof/sysprof-traceables-utility.ui b/src/sysprof/sysprof-traceables-utility.ui new file mode 100644 index 00000000..7aadec01 --- /dev/null +++ b/src/sysprof/sysprof-traceables-utility.ui @@ -0,0 +1,10 @@ + + + + diff --git a/src/sysprof/sysprof-window.c b/src/sysprof/sysprof-window.c index 5f54e8e1..f7313fa0 100644 --- a/src/sysprof/sysprof-window.c +++ b/src/sysprof/sysprof-window.c @@ -33,6 +33,7 @@ #include "sysprof-processes-section.h" #include "sysprof-samples-section.h" #include "sysprof-sidebar.h" +#include "sysprof-traceables-utility.h" #include "sysprof-window.h" struct _SysprofWindow @@ -41,6 +42,9 @@ struct _SysprofWindow SysprofDocument *document; SysprofSession *session; + + AdwViewStack *utility_stack; + AdwWindowTitle *utility_title; }; enum { @@ -193,6 +197,9 @@ sysprof_window_class_init (SysprofWindowClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-window.ui"); + gtk_widget_class_bind_template_child (widget_class, SysprofWindow, utility_stack); + gtk_widget_class_bind_template_child (widget_class, SysprofWindow, utility_title); + gtk_widget_class_install_action (widget_class, "win.open-capture", NULL, sysprof_window_open_capture_action); gtk_widget_class_install_action (widget_class, "win.record-capture", NULL, sysprof_window_record_capture_action); @@ -206,12 +213,39 @@ sysprof_window_class_init (SysprofWindowClass *klass) g_type_ensure (SYSPROF_TYPE_SAMPLES_SECTION); g_type_ensure (SYSPROF_TYPE_SESSION); g_type_ensure (SYSPROF_TYPE_SIDEBAR); + g_type_ensure (SYSPROF_TYPE_TRACEABLES_UTILITY); +} + +static void +utility_stack_notify_visible_child_cb (SysprofWindow *self, + GParamSpec *pspec, + AdwViewStack *utility_stack) +{ + AdwViewStackPage *page; + const char *title = NULL; + GtkWidget *child; + + g_assert (SYSPROF_IS_WINDOW (self)); + g_assert (ADW_IS_VIEW_STACK (utility_stack)); + + if ((child = adw_view_stack_get_visible_child (utility_stack)) && + (page = adw_view_stack_get_page (utility_stack, child))) + title = adw_view_stack_page_get_title (page); + + adw_window_title_set_title (self->utility_title, title); } static void sysprof_window_init (SysprofWindow *self) { gtk_widget_init_template (GTK_WIDGET (self)); + + g_signal_connect_object (self->utility_stack, + "notify::visible-child", + G_CALLBACK (utility_stack_notify_visible_child_cb), + self, + G_CONNECT_SWAPPED); + utility_stack_notify_visible_child_cb (self, NULL, self->utility_stack); } GtkWidget * diff --git a/src/sysprof/sysprof-window.ui b/src/sysprof/sysprof-window.ui index 4ff12701..ae6d3251 100644 --- a/src/sysprof/sysprof-window.ui +++ b/src/sysprof/sysprof-window.ui @@ -169,11 +169,27 @@ - - + + + + true + + + Stack Traces + + + + SysprofWindow + + + + + + + diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index 659d79bc..0e49f338 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -14,6 +14,7 @@ sysprof-recording-pad.ui sysprof-samples-section.ui sysprof-sidebar.ui + sysprof-traceables-utility.ui sysprof-window.ui icons/scalable/actions/address-layout-symbolic.svg icons/scalable/actions/mark-chart-symbolic.svg