sysprof: start on greeter window

This commit is contained in:
Christian Hergert
2023-07-07 15:08:46 -07:00
parent 24145578d3
commit 5c65ddf0b2
6 changed files with 445 additions and 4 deletions

View File

@ -1,6 +1,7 @@
sysprof_sources = [
'main.c',
'sysprof-application.c',
'sysprof-greeter.c',
'sysprof-window.c',
]

View File

@ -23,6 +23,7 @@
#include "sysprof-application.h"
#include "sysprof-credits.h"
#include "sysprof-greeter.h"
#include "sysprof-window.h"
struct _SysprofApplication
@ -35,6 +36,8 @@ G_DEFINE_TYPE (SysprofApplication, sysprof_application, ADW_TYPE_APPLICATION)
static void
sysprof_application_activate (GApplication *app)
{
GtkWidget *greeter;
g_assert (GTK_IS_APPLICATION (app));
for (const GList *iter = gtk_application_get_windows (GTK_APPLICATION (app));
@ -48,7 +51,9 @@ sysprof_application_activate (GApplication *app)
}
}
g_warning ("TODO: show greeter window");
greeter = sysprof_greeter_new ();
gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (greeter));
gtk_window_present (GTK_WINDOW (greeter));
}
static void

View File

@ -0,0 +1,120 @@
/* sysprof-greeter.c
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "config.h"
#include "sysprof-greeter.h"
struct _SysprofGreeter
{
AdwWindow parent_instance;
GtkBox *toolbar;
AdwPreferencesPage *record_page;
};
enum {
PROP_0,
N_PROPS
};
G_DEFINE_FINAL_TYPE (SysprofGreeter, sysprof_greeter, ADW_TYPE_WINDOW)
static GParamSpec *properties [N_PROPS];
static void
sysprof_greeter_view_stack_notify_visible_child (SysprofGreeter *self,
GParamSpec *pspec,
AdwViewStack *stack)
{
g_assert (SYSPROF_IS_GREETER (self));
g_assert (ADW_IS_VIEW_STACK (stack));
gtk_widget_set_visible (GTK_WIDGET (self->toolbar),
GTK_WIDGET (self->record_page) == adw_view_stack_get_visible_child (stack));
}
static void
sysprof_greeter_dispose (GObject *object)
{
SysprofGreeter *self = (SysprofGreeter *)object;
gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_GREETER);
G_OBJECT_CLASS (sysprof_greeter_parent_class)->dispose (object);
}
static void
sysprof_greeter_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SysprofGreeter *self = SYSPROF_GREETER (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_greeter_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SysprofGreeter *self = SYSPROF_GREETER (object);
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_greeter_class_init (SysprofGreeterClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = sysprof_greeter_dispose;
object_class->get_property = sysprof_greeter_get_property;
object_class->set_property = sysprof_greeter_set_property;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-greeter.ui");
gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, toolbar);
gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, record_page);
gtk_widget_class_bind_template_callback (widget_class, sysprof_greeter_view_stack_notify_visible_child);
}
static void
sysprof_greeter_init (SysprofGreeter *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
GtkWidget *
sysprof_greeter_new (void)
{
return g_object_new (SYSPROF_TYPE_GREETER, NULL);
}

View File

@ -0,0 +1,33 @@
/* sysprof-greeter.h
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <adwaita.h>
G_BEGIN_DECLS
#define SYSPROF_TYPE_GREETER (sysprof_greeter_get_type())
G_DECLARE_FINAL_TYPE (SysprofGreeter, sysprof_greeter, SYSPROF, GREETER, AdwWindow)
GtkWidget *sysprof_greeter_new (void);
G_END_DECLS

View File

@ -0,0 +1,284 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="Adw" version="1.0"/>
<template class="SysprofGreeter" parent="AdwWindow">
<property name="default-width">800</property>
<property name="default-height">800</property>
<property name="content">
<object class="AdwToolbarView">
<property name="bottom-bar-style">raised</property>
<child type="top">
<object class="AdwHeaderBar">
<property name="centering-policy">strict</property>
<property name="title-widget">
<object class="AdwViewSwitcherTitle">
<property name="stack">view_stack</property>
</object>
</property>
</object>
</child>
<property name="content">
<object class="AdwViewStack" id="view_stack">
<signal name="notify::visible-child" handler="sysprof_greeter_view_stack_notify_visible_child" swapped="true"/>
<child>
<object class="AdwViewStackPage">
<property name="icon-name">org.gnome.Sysprof-symbolic</property>
<property name="title" translatable="yes">Record</property>
<property name="child">
<object class="AdwPreferencesPage" id="record_page">
<property name="vexpand">true</property>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Time Profiler</property>
<child>
<object class="AdwActionRow" id="first_row">
<property name="activatable-widget">sample_native_stacks</property>
<property name="title" translatable="yes">Sample Native Stacks</property>
<property name="subtitle" translatable="yes">Record native stack traces using a sampling profiler</property>
<child type="suffix">
<object class="GtkSwitch" id="sample_native_stacks">
<property name="active">true</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwComboRow">
<property name="title" translatable="yes">Performance Profile</property>
<property name="subtitle" translatable="yes">Hold the performance profile for the duration of the recording</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwActionRow">
<property name="activatable-widget">sample_javascript_stacks</property>
<property name="title" translatable="yes">Sample JavaScript Stacks</property>
<property name="subtitle" translatable="yes">Record JavaScript stack traces using a sampling profiler</property>
<child type="suffix">
<object class="GtkSwitch" id="sample_javascript_stacks">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">This feature is only supported when launching a GJS-based application.</property>
<property name="xalign">0</property>
<property name="margin-top">8</property>
<style>
<class name="caption"/>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Memory</property>
<child>
<object class="AdwActionRow">
<property name="activatable-widget">record_memory_counters</property>
<property name="title" translatable="yes">System Memory Usage</property>
<property name="subtitle" translatable="yes">Record coarse-grained counters about system memory usage</property>
<child type="suffix">
<object class="GtkSwitch" id="record_memory_counters">
<property name="active">true</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwActionRow">
<property name="activatable-widget">trace_malloc</property>
<property name="title" translatable="yes">Trace Memory Allocations</property>
<property name="subtitle" translatable="yes">Record a strack trace when &lt;tt&gt;malloc&lt;/tt&gt; or similar functions are used</property>
<child type="suffix">
<object class="GtkSwitch" id="trace_malloc">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Memory tracing is only supported when launching an application.</property>
<property name="xalign">0</property>
<property name="margin-top">8</property>
<style>
<class name="caption"/>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Display &amp;amp; Graphics</property>
<child>
<object class="AdwActionRow">
<property name="activatable-widget">record_compositor</property>
<property name="title" translatable="yes">Compositor Frame Timings</property>
<property name="subtitle" translatable="yes">Record frame-timing information from the GNOME Shell compositor</property>
<child type="suffix">
<object class="GtkSwitch" id="record_compositor">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwActionRow">
<property name="activatable-widget">detect_hangs</property>
<property name="title" translatable="yes">Detect Application Hangs</property>
<property name="subtitle" translatable="yes">Detect hangs in the application main loop</property>
<child type="suffix">
<object class="GtkSwitch" id="detect_hangs">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Hang detection is only supported when launching a GTK-based application.</property>
<property name="xalign">0</property>
<property name="margin-top">8</property>
<style>
<class name="caption"/>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Counters</property>
<child>
<object class="AdwActionRow">
<property name="activatable-widget">record_disk_usage</property>
<property name="title" translatable="yes">Disk Usage</property>
<property name="subtitle" translatable="yes">Record coarse-grained counters about storage throughput</property>
<child type="suffix">
<object class="GtkSwitch" id="record_disk_usage">
<property name="active">true</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="activatable-widget">record_network_usage</property>
<property name="title" translatable="yes">Network Usage</property>
<property name="subtitle" translatable="yes">Record coarse-grained counters about network traffic</property>
<child type="suffix">
<object class="GtkSwitch" id="record_network_usage">
<property name="active">true</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="activatable-widget">record_energy_usage</property>
<property name="title" translatable="yes">Energy Usage</property>
<property name="subtitle" translatable="yes">Record coarse-grained counters about energy usage in Watts</property>
<child type="suffix">
<object class="GtkSwitch" id="record_energy_usage">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="activatable-widget">record_battery_charge</property>
<property name="title" translatable="yes">Battery Charge</property>
<property name="subtitle" translatable="yes">Record coarse-grained counters about battery charge or discharge rates</property>
<child type="suffix">
<object class="GtkSwitch" id="record_battery_charge">
<property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</child>
<child>
<object class="AdwViewStackPage">
<property name="icon-name">document-open-recent-symbolic</property>
<property name="title" translatable="yes">Recent</property>
<property name="child">
<object class="GtkLabel"/>
</property>
</object>
</child>
<child>
<object class="AdwViewStackPage">
<property name="icon-name">document-open-symbolic</property>
<property name="title" translatable="yes">Open</property>
<property name="child">
<object class="GtkLabel"/>
</property>
</object>
</child>
</object>
</property>
<child type="bottom">
<object class="GtkBox" id="toolbar">
<child>
<object class="GtkBox" id="record_buttons">
<style>
<class name="toolbar"/>
</style>
<property name="homogeneous">true</property>
<property name="halign">center</property>
<property name="width-request">500</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Record to _File…</property>
<property name="use-underline">true</property>
<property name="hexpand">true</property>
</object>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">_Record to Memory</property>
<property name="use-underline">true</property>
<property name="hexpand">true</property>
<style>
<class name="suggested-action"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
</template>
</interface>

View File

@ -3,9 +3,7 @@
<gresource prefix="/org/gnome/sysprof">
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file preprocess="xml-stripblanks">gtk/menus.ui</file>
</gresource>
<gresource prefix="/org/gnome/sysprof">
<file preprocess="xml-stripblanks">sysprof-greeter.ui</file>
<file preprocess="xml-stripblanks">sysprof-window.ui</file>
</gresource>
</gresources>