mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
visualizer-selection: initial visualizer selection support
This gets started on allowing the user to select a region. Nothing is yet responding to the changes in selection, but that can come later. Ideally, we will truncate (or mark rows invisible/insensitive) if they do not fall within the selected time region.
This commit is contained in:
@ -151,6 +151,7 @@ uiheaders_DATA = \
|
|||||||
sp-profiler-menu-button.h \
|
sp-profiler-menu-button.h \
|
||||||
sp-recording-state-view.h \
|
sp-recording-state-view.h \
|
||||||
sp-visualizer-row.h \
|
sp-visualizer-row.h \
|
||||||
|
sp-visualizer-selection.h \
|
||||||
sp-visualizer-view.h \
|
sp-visualizer-view.h \
|
||||||
sp-zoom-manager.h \
|
sp-zoom-manager.h \
|
||||||
sysprof-ui.h \
|
sysprof-ui.h \
|
||||||
@ -178,6 +179,7 @@ libsysprof_ui_@API_VERSION@_la_SOURCES = \
|
|||||||
sp-visualizer-list.c \
|
sp-visualizer-list.c \
|
||||||
sp-visualizer-list.h \
|
sp-visualizer-list.h \
|
||||||
sp-visualizer-row.c \
|
sp-visualizer-row.c \
|
||||||
|
sp-visualizer-selection.c \
|
||||||
sp-visualizer-ticks.c \
|
sp-visualizer-ticks.c \
|
||||||
sp-visualizer-ticks.h \
|
sp-visualizer-ticks.h \
|
||||||
sp-visualizer-ticks-private.h \
|
sp-visualizer-ticks-private.h \
|
||||||
|
|||||||
10
lib/resources/css/shared.css
Normal file
10
lib/resources/css/shared.css
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
visualizers.selection {
|
||||||
|
background: none;
|
||||||
|
background-color: alpha(@theme_selected_bg_color, 0.35);
|
||||||
|
border: 1px solid @theme_selected_bg_color;
|
||||||
|
}
|
||||||
|
visualizers.selection:backdrop {
|
||||||
|
background: none;
|
||||||
|
background-color: alpha(@theme_selected_bg_color, 0.15);
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
@ -1,6 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<gresources>
|
<gresources>
|
||||||
<gresource prefix="/org/gnome/sysprof">
|
<gresource prefix="/org/gnome/sysprof">
|
||||||
|
<file compressed="true">css/shared.css</file>
|
||||||
|
|
||||||
<file compressed="true">ui/sp-callgraph-view.ui</file>
|
<file compressed="true">ui/sp-callgraph-view.ui</file>
|
||||||
<file compressed="true">ui/sp-empty-state-view.ui</file>
|
<file compressed="true">ui/sp-empty-state-view.ui</file>
|
||||||
<file compressed="true">ui/sp-failed-state-view.ui</file>
|
<file compressed="true">ui/sp-failed-state-view.ui</file>
|
||||||
|
|||||||
@ -10,6 +10,9 @@
|
|||||||
<property name="hexpand">true</property>
|
<property name="hexpand">true</property>
|
||||||
<property name="visible">true</property>
|
<property name="visible">true</property>
|
||||||
</object>
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="pass-through">true</property>
|
||||||
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow" id="scroller">
|
<object class="GtkScrolledWindow" id="scroller">
|
||||||
|
|||||||
@ -159,6 +159,8 @@ sp_visualizer_row_class_init (SpVisualizerRowClass *klass)
|
|||||||
static void
|
static void
|
||||||
sp_visualizer_row_init (SpVisualizerRow *self)
|
sp_visualizer_row_init (SpVisualizerRow *self)
|
||||||
{
|
{
|
||||||
|
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (self), FALSE);
|
||||||
|
gtk_list_box_row_set_selectable (GTK_LIST_BOX_ROW (self), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
214
lib/sp-visualizer-selection.c
Normal file
214
lib/sp-visualizer-selection.c
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
/* sp-visualizer-selection.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define G_LOG_DOMAIN "sp-visualizer-selection"
|
||||||
|
|
||||||
|
#include "sp-visualizer-selection.h"
|
||||||
|
|
||||||
|
struct _SpVisualizerSelection
|
||||||
|
{
|
||||||
|
GObject parent_instance;
|
||||||
|
GArray *ranges;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
gint64 begin;
|
||||||
|
gint64 end;
|
||||||
|
} Range;
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (SpVisualizerSelection, sp_visualizer_selection, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
PROP_0,
|
||||||
|
PROP_HAS_SELECTION,
|
||||||
|
N_PROPS
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CHANGED,
|
||||||
|
N_SIGNALS
|
||||||
|
};
|
||||||
|
|
||||||
|
static GParamSpec *properties [N_PROPS];
|
||||||
|
static guint signals [N_SIGNALS];
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
int64_swap (gint64 *a,
|
||||||
|
gint64 *b)
|
||||||
|
{
|
||||||
|
if (*a > *b)
|
||||||
|
{
|
||||||
|
gint64 tmp = *a;
|
||||||
|
*a = *b;
|
||||||
|
*b = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sp_visualizer_selection_finalize (GObject *object)
|
||||||
|
{
|
||||||
|
SpVisualizerSelection *self = (SpVisualizerSelection *)object;
|
||||||
|
|
||||||
|
g_clear_pointer (&self->ranges, g_array_unref);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (sp_visualizer_selection_parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sp_visualizer_selection_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
SpVisualizerSelection *self = SP_VISUALIZER_SELECTION (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_HAS_SELECTION:
|
||||||
|
g_value_set_boolean (value, sp_visualizer_selection_get_has_selection (self));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sp_visualizer_selection_class_init (SpVisualizerSelectionClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
|
object_class->finalize = sp_visualizer_selection_finalize;
|
||||||
|
object_class->get_property = sp_visualizer_selection_get_property;
|
||||||
|
|
||||||
|
properties [PROP_HAS_SELECTION] =
|
||||||
|
g_param_spec_boolean ("has-selection",
|
||||||
|
"Has Selection",
|
||||||
|
"Has Selection",
|
||||||
|
FALSE,
|
||||||
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpVisualizerSelection::changed:
|
||||||
|
*
|
||||||
|
* This signal is emitted when the selection has changed.
|
||||||
|
*/
|
||||||
|
signals [CHANGED] =
|
||||||
|
g_signal_new ("changed",
|
||||||
|
G_TYPE_FROM_CLASS (klass),
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sp_visualizer_selection_init (SpVisualizerSelection *self)
|
||||||
|
{
|
||||||
|
self->ranges = g_array_new (FALSE, FALSE, sizeof (Range));
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
sp_visualizer_selection_get_has_selection (SpVisualizerSelection *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (SP_IS_VISUALIZER_SELECTION (self), FALSE);
|
||||||
|
|
||||||
|
return self->ranges->len > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sp_visualizer_selection_foreach:
|
||||||
|
* @self: A #SpVisualizerSelection
|
||||||
|
* @foreach_func: (scope call): a callback for each range
|
||||||
|
* @user_data: user data for @foreach_func
|
||||||
|
*
|
||||||
|
* Calls @foreach_func for every selected range.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
sp_visualizer_selection_foreach (SpVisualizerSelection *self,
|
||||||
|
SpVisualizerSelectionForeachFunc foreach_func,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SP_IS_VISUALIZER_SELECTION (self));
|
||||||
|
g_return_if_fail (foreach_func != NULL);
|
||||||
|
|
||||||
|
for (guint i = 0; i < self->ranges->len; i++)
|
||||||
|
{
|
||||||
|
const Range *range = &g_array_index (self->ranges, Range, i);
|
||||||
|
foreach_func (self, range->begin, range->end, user_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sp_visualizer_selection_select_range (SpVisualizerSelection *self,
|
||||||
|
gint64 begin_time,
|
||||||
|
gint64 end_time)
|
||||||
|
{
|
||||||
|
Range range = { 0 };
|
||||||
|
|
||||||
|
g_return_if_fail (SP_IS_VISUALIZER_SELECTION (self));
|
||||||
|
|
||||||
|
int64_swap (&begin_time, &end_time);
|
||||||
|
|
||||||
|
range.begin = begin_time;
|
||||||
|
range.end = end_time;
|
||||||
|
|
||||||
|
g_array_append_val (self->ranges, range);
|
||||||
|
|
||||||
|
if (self->ranges->len == 1)
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAS_SELECTION]);
|
||||||
|
g_signal_emit (self, signals [CHANGED], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sp_visualizer_selection_unselect_range (SpVisualizerSelection *self,
|
||||||
|
gint64 begin,
|
||||||
|
gint64 end)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SP_IS_VISUALIZER_SELECTION (self));
|
||||||
|
|
||||||
|
int64_swap (&begin, &end);
|
||||||
|
|
||||||
|
for (guint i = 0; i < self->ranges->len; i++)
|
||||||
|
{
|
||||||
|
const Range *range = &g_array_index (self->ranges, Range, i);
|
||||||
|
|
||||||
|
if (range->begin == begin && range->end == end)
|
||||||
|
{
|
||||||
|
g_array_remove_index (self->ranges, i);
|
||||||
|
if (self->ranges->len == 0)
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAS_SELECTION]);
|
||||||
|
g_signal_emit (self, signals [CHANGED], 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sp_visualizer_selection_unselect_all (SpVisualizerSelection *self)
|
||||||
|
{
|
||||||
|
g_return_if_fail (SP_IS_VISUALIZER_SELECTION (self));
|
||||||
|
|
||||||
|
if (self->ranges->len > 0)
|
||||||
|
{
|
||||||
|
g_array_remove_range (self->ranges, 0, self->ranges->len);
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAS_SELECTION]);
|
||||||
|
g_signal_emit (self, signals [CHANGED], 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
lib/sp-visualizer-selection.h
Normal file
49
lib/sp-visualizer-selection.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* sp-visualizer-selection.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SP_VISUALIZER_SELECTION_H
|
||||||
|
#define SP_VISUALIZER_SELECTION_H
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define SP_TYPE_VISUALIZER_SELECTION (sp_visualizer_selection_get_type())
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (SpVisualizerSelection, sp_visualizer_selection, SP, VISUALIZER_SELECTION, GtkDrawingArea)
|
||||||
|
|
||||||
|
typedef void (*SpVisualizerSelectionForeachFunc) (SpVisualizerSelection *self,
|
||||||
|
gint64 begin_time,
|
||||||
|
gint64 end_time,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
gboolean sp_visualizer_selection_get_has_selection (SpVisualizerSelection *self);
|
||||||
|
void sp_visualizer_selection_select_range (SpVisualizerSelection *self,
|
||||||
|
gint64 begin_time,
|
||||||
|
gint64 end_time);
|
||||||
|
void sp_visualizer_selection_unselect_range (SpVisualizerSelection *self,
|
||||||
|
gint64 begin,
|
||||||
|
gint64 end);
|
||||||
|
void sp_visualizer_selection_unselect_all (SpVisualizerSelection *self);
|
||||||
|
void sp_visualizer_selection_foreach (SpVisualizerSelection *self,
|
||||||
|
SpVisualizerSelectionForeachFunc foreach_func,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* SP_VISUALIZER_SELECTION_H */
|
||||||
@ -23,6 +23,7 @@
|
|||||||
#include "sp-visualizer-list.h"
|
#include "sp-visualizer-list.h"
|
||||||
#include "sp-visualizer-row.h"
|
#include "sp-visualizer-row.h"
|
||||||
#include "sp-visualizer-row-private.h"
|
#include "sp-visualizer-row-private.h"
|
||||||
|
#include "sp-visualizer-selection.h"
|
||||||
#include "sp-visualizer-ticks.h"
|
#include "sp-visualizer-ticks.h"
|
||||||
#include "sp-visualizer-view.h"
|
#include "sp-visualizer-view.h"
|
||||||
|
|
||||||
@ -31,14 +32,28 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SpCaptureReader *reader;
|
SpCaptureReader *reader;
|
||||||
SpZoomManager *zoom_manager;
|
SpZoomManager *zoom_manager;
|
||||||
|
SpVisualizerSelection *selection;
|
||||||
|
|
||||||
SpVisualizerList *list;
|
SpVisualizerList *list;
|
||||||
GtkScrolledWindow *scroller;
|
GtkScrolledWindow *scroller;
|
||||||
SpVisualizerTicks *ticks;
|
SpVisualizerTicks *ticks;
|
||||||
|
|
||||||
|
gint64 drag_begin_at;
|
||||||
|
gint64 drag_selection_at;
|
||||||
|
|
||||||
|
guint button_pressed : 1;
|
||||||
} SpVisualizerViewPrivate;
|
} SpVisualizerViewPrivate;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
SpVisualizerView *self;
|
||||||
|
GtkStyleContext *style_context;
|
||||||
|
cairo_t *cr;
|
||||||
|
GtkAllocation alloc;
|
||||||
|
} SelectionDraw;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_READER,
|
PROP_READER,
|
||||||
@ -61,6 +76,102 @@ G_DEFINE_TYPE_EXTENDED (SpVisualizerView, sp_visualizer_view, GTK_TYPE_BIN, 0,
|
|||||||
static GParamSpec *properties [N_PROPS];
|
static GParamSpec *properties [N_PROPS];
|
||||||
static guint signals [N_SIGNALS];
|
static guint signals [N_SIGNALS];
|
||||||
static GtkBuildableIface *parent_buildable;
|
static GtkBuildableIface *parent_buildable;
|
||||||
|
static GtkCssProvider *css_provider;
|
||||||
|
|
||||||
|
static void
|
||||||
|
find_row1 (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GtkWidget **row1 = data;
|
||||||
|
|
||||||
|
if (*row1 == NULL && SP_IS_VISUALIZER_ROW (widget))
|
||||||
|
*row1 = widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gint64
|
||||||
|
get_time_from_coordinates (SpVisualizerView *self,
|
||||||
|
gint x,
|
||||||
|
gint y)
|
||||||
|
{
|
||||||
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
|
SpVisualizerRow *row1 = NULL;
|
||||||
|
GtkAdjustment *hadjustment;
|
||||||
|
GtkAllocation alloc;
|
||||||
|
gdouble nsec_per_pixel;
|
||||||
|
gdouble value;
|
||||||
|
gint64 begin_time;
|
||||||
|
gint64 end_time;
|
||||||
|
gint graph_width;
|
||||||
|
|
||||||
|
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||||
|
|
||||||
|
if (priv->reader == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||||
|
|
||||||
|
x -= alloc.x;
|
||||||
|
y -= alloc.y;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the first row so we can get an idea of how wide the graph is
|
||||||
|
* (ignoring spacing caused by the widget being wider than the data points.
|
||||||
|
*/
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (priv->list), find_row1, &row1);
|
||||||
|
if (!SP_IS_VISUALIZER_ROW (row1))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
hadjustment = gtk_scrolled_window_get_hadjustment (priv->scroller);
|
||||||
|
value = gtk_adjustment_get_value (hadjustment);
|
||||||
|
|
||||||
|
begin_time = sp_capture_reader_get_start_time (priv->reader);
|
||||||
|
end_time = sp_capture_reader_get_end_time (priv->reader);
|
||||||
|
|
||||||
|
graph_width = _sp_visualizer_row_get_graph_width (row1);
|
||||||
|
nsec_per_pixel = (end_time - begin_time) / (gdouble)graph_width;
|
||||||
|
begin_time += value * nsec_per_pixel;
|
||||||
|
end_time = begin_time + (alloc.width * nsec_per_pixel);
|
||||||
|
|
||||||
|
return begin_time + ((end_time - begin_time) / (gdouble)alloc.width * x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
get_x_for_time_at (SpVisualizerView *self,
|
||||||
|
const GtkAllocation *alloc,
|
||||||
|
gint64 time_at)
|
||||||
|
{
|
||||||
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
|
SpVisualizerRow *row1 = NULL;
|
||||||
|
GtkAdjustment *hadjustment;
|
||||||
|
gdouble nsec_per_pixel;
|
||||||
|
gdouble value;
|
||||||
|
gint64 begin_time;
|
||||||
|
gint64 end_time;
|
||||||
|
gint graph_width;
|
||||||
|
|
||||||
|
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||||
|
g_assert (alloc != NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the first row so we can get an idea of how wide the graph is
|
||||||
|
* (ignoring spacing caused by the widget being wider than the data points.
|
||||||
|
*/
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (priv->list), find_row1, &row1);
|
||||||
|
if (!SP_IS_VISUALIZER_ROW (row1))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
hadjustment = gtk_scrolled_window_get_hadjustment (priv->scroller);
|
||||||
|
value = gtk_adjustment_get_value (hadjustment);
|
||||||
|
|
||||||
|
begin_time = sp_capture_reader_get_start_time (priv->reader);
|
||||||
|
end_time = sp_capture_reader_get_end_time (priv->reader);
|
||||||
|
|
||||||
|
graph_width = _sp_visualizer_row_get_graph_width (row1);
|
||||||
|
nsec_per_pixel = (end_time - begin_time) / (gdouble)graph_width;
|
||||||
|
begin_time += value * nsec_per_pixel;
|
||||||
|
|
||||||
|
return ((time_at - begin_time) / nsec_per_pixel);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sp_visualizer_view_row_added (SpVisualizerView *self,
|
sp_visualizer_view_row_added (SpVisualizerView *self,
|
||||||
@ -88,52 +199,20 @@ sp_visualizer_view_row_removed (SpVisualizerView *self,
|
|||||||
g_signal_emit (self, signals [VISUALIZER_REMOVED], 0, widget);
|
g_signal_emit (self, signals [VISUALIZER_REMOVED], 0, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
find_row1 (GtkWidget *widget,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GtkWidget **row1 = data;
|
|
||||||
|
|
||||||
if (*row1 == NULL && SP_IS_VISUALIZER_ROW (widget))
|
|
||||||
*row1 = widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sp_visualizer_view_update_ticks (SpVisualizerView *self)
|
sp_visualizer_view_update_ticks (SpVisualizerView *self)
|
||||||
{
|
{
|
||||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
SpVisualizerRow *row1 = NULL;
|
|
||||||
GtkAdjustment *hadjustment;
|
|
||||||
GtkAllocation alloc;
|
GtkAllocation alloc;
|
||||||
gdouble nsec_per_pixel;
|
|
||||||
gdouble value;
|
|
||||||
gint64 begin_time;
|
gint64 begin_time;
|
||||||
gint64 end_time;
|
gint64 end_time;
|
||||||
gint graph_width;
|
|
||||||
|
|
||||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||||
|
|
||||||
if (priv->reader == NULL)
|
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||||
return;
|
|
||||||
|
|
||||||
begin_time = sp_capture_reader_get_start_time (priv->reader);
|
begin_time = get_time_from_coordinates (self, alloc.x, alloc.y);
|
||||||
end_time = sp_capture_reader_get_end_time (priv->reader);
|
end_time = get_time_from_coordinates (self, alloc.x + alloc.width, alloc.y);
|
||||||
|
|
||||||
gtk_container_foreach (GTK_CONTAINER (priv->list), find_row1, &row1);
|
|
||||||
|
|
||||||
if (!SP_IS_VISUALIZER_ROW (row1))
|
|
||||||
return;
|
|
||||||
|
|
||||||
hadjustment = gtk_scrolled_window_get_hadjustment (priv->scroller);
|
|
||||||
value = gtk_adjustment_get_value (hadjustment);
|
|
||||||
|
|
||||||
gtk_widget_get_allocation (GTK_WIDGET (priv->ticks), &alloc);
|
|
||||||
|
|
||||||
/* In practice, the adjustment is 1.0 per pixel. */
|
|
||||||
graph_width = _sp_visualizer_row_get_graph_width (row1);
|
|
||||||
nsec_per_pixel = (end_time - begin_time) / (gdouble)graph_width;
|
|
||||||
begin_time += value * nsec_per_pixel;
|
|
||||||
end_time = begin_time + (alloc.width * nsec_per_pixel);
|
|
||||||
|
|
||||||
sp_visualizer_ticks_set_time_range (priv->ticks, begin_time, end_time);
|
sp_visualizer_ticks_set_time_range (priv->ticks, begin_time, end_time);
|
||||||
}
|
}
|
||||||
@ -162,6 +241,182 @@ sp_visualizer_view_size_allocate (GtkWidget *widget,
|
|||||||
sp_visualizer_view_update_ticks (self);
|
sp_visualizer_view_update_ticks (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
draw_selection_cb (SpVisualizerSelection *selection,
|
||||||
|
gint64 range_begin,
|
||||||
|
gint64 range_end,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
SelectionDraw *draw = user_data;
|
||||||
|
GdkRectangle area;
|
||||||
|
|
||||||
|
g_assert (SP_IS_VISUALIZER_SELECTION (selection));
|
||||||
|
g_assert (draw != NULL);
|
||||||
|
g_assert (draw->cr != NULL);
|
||||||
|
g_assert (SP_IS_VISUALIZER_VIEW (draw->self));
|
||||||
|
|
||||||
|
area.x = get_x_for_time_at (draw->self, &draw->alloc, range_begin);
|
||||||
|
area.width = get_x_for_time_at (draw->self, &draw->alloc, range_end) - area.x;
|
||||||
|
area.y = 0;
|
||||||
|
area.height = draw->alloc.height;
|
||||||
|
|
||||||
|
if (area.width < 0)
|
||||||
|
{
|
||||||
|
area.width = ABS (area.width);
|
||||||
|
area.x -= area.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_render_background (draw->style_context, draw->cr, area.x, area.y, area.width, area.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sp_visualizer_view_draw (GtkWidget *widget,
|
||||||
|
cairo_t *cr)
|
||||||
|
{
|
||||||
|
SpVisualizerView *self = (SpVisualizerView *)widget;
|
||||||
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
|
SelectionDraw draw = { 0 };
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
|
g_assert (GTK_IS_WIDGET (widget));
|
||||||
|
g_assert (cr != NULL);
|
||||||
|
|
||||||
|
draw.style_context = gtk_widget_get_style_context (widget);
|
||||||
|
draw.self = self;
|
||||||
|
draw.cr = cr;
|
||||||
|
|
||||||
|
gtk_widget_get_allocation (widget, &draw.alloc);
|
||||||
|
|
||||||
|
ret = GTK_WIDGET_CLASS (sp_visualizer_view_parent_class)->draw (widget, cr);
|
||||||
|
|
||||||
|
if (sp_visualizer_selection_get_has_selection (priv->selection) || priv->button_pressed)
|
||||||
|
{
|
||||||
|
gtk_style_context_add_class (draw.style_context, "selection");
|
||||||
|
sp_visualizer_selection_foreach (priv->selection, draw_selection_cb, &draw);
|
||||||
|
if (priv->button_pressed)
|
||||||
|
draw_selection_cb (priv->selection, priv->drag_begin_at, priv->drag_selection_at, &draw);
|
||||||
|
gtk_style_context_remove_class (draw.style_context, "selection");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sp_visualizer_view_list_button_press_event (SpVisualizerView *self,
|
||||||
|
GdkEventButton *ev,
|
||||||
|
SpVisualizerList *list)
|
||||||
|
{
|
||||||
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
|
|
||||||
|
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||||
|
g_assert (ev != NULL);
|
||||||
|
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||||
|
|
||||||
|
if (priv->reader == NULL)
|
||||||
|
return GDK_EVENT_PROPAGATE;
|
||||||
|
|
||||||
|
if (ev->button != GDK_BUTTON_PRIMARY)
|
||||||
|
{
|
||||||
|
if (sp_visualizer_selection_get_has_selection (priv->selection))
|
||||||
|
{
|
||||||
|
sp_visualizer_selection_unselect_all (priv->selection);
|
||||||
|
return GDK_EVENT_STOP;
|
||||||
|
}
|
||||||
|
return GDK_EVENT_PROPAGATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ev->state & GDK_SHIFT_MASK) == 0)
|
||||||
|
sp_visualizer_selection_unselect_all (priv->selection);
|
||||||
|
|
||||||
|
priv->button_pressed = TRUE;
|
||||||
|
|
||||||
|
priv->drag_begin_at = get_time_from_coordinates (self, ev->x, ev->y);
|
||||||
|
priv->drag_selection_at = priv->drag_begin_at;
|
||||||
|
|
||||||
|
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||||
|
|
||||||
|
return GDK_EVENT_PROPAGATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sp_visualizer_view_list_button_release_event (SpVisualizerView *self,
|
||||||
|
GdkEventButton *ev,
|
||||||
|
SpVisualizerList *list)
|
||||||
|
{
|
||||||
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
|
|
||||||
|
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||||
|
g_assert (ev != NULL);
|
||||||
|
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||||
|
|
||||||
|
if (!priv->button_pressed || ev->button != GDK_BUTTON_PRIMARY)
|
||||||
|
return GDK_EVENT_PROPAGATE;
|
||||||
|
|
||||||
|
priv->button_pressed = FALSE;
|
||||||
|
|
||||||
|
if (priv->drag_begin_at != priv->drag_selection_at)
|
||||||
|
{
|
||||||
|
sp_visualizer_selection_select_range (priv->selection,
|
||||||
|
priv->drag_begin_at,
|
||||||
|
priv->drag_selection_at);
|
||||||
|
priv->drag_begin_at = -1;
|
||||||
|
priv->drag_selection_at = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||||
|
|
||||||
|
return GDK_EVENT_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
sp_visualizer_view_list_motion_notify_event (SpVisualizerView *self,
|
||||||
|
GdkEventMotion *ev,
|
||||||
|
SpVisualizerList *list)
|
||||||
|
{
|
||||||
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
|
|
||||||
|
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||||
|
g_assert (ev != NULL);
|
||||||
|
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||||
|
|
||||||
|
if (!priv->button_pressed)
|
||||||
|
return GDK_EVENT_PROPAGATE;
|
||||||
|
|
||||||
|
priv->drag_selection_at = get_time_from_coordinates (self, ev->x, ev->y);
|
||||||
|
|
||||||
|
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||||
|
|
||||||
|
return GDK_EVENT_PROPAGATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sp_visualizer_view_list_realize_after (SpVisualizerView *self,
|
||||||
|
SpVisualizerList *list)
|
||||||
|
{
|
||||||
|
GdkDisplay *display;
|
||||||
|
GdkWindow *window;
|
||||||
|
GdkCursor *cursor;
|
||||||
|
|
||||||
|
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||||
|
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||||
|
|
||||||
|
window = gtk_widget_get_window (GTK_WIDGET (list));
|
||||||
|
display = gdk_window_get_display (window);
|
||||||
|
cursor = gdk_cursor_new_from_name (display, "text");
|
||||||
|
gdk_window_set_cursor (window, cursor);
|
||||||
|
g_clear_object (&cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sp_visualizer_view_selection_changed (SpVisualizerView *self,
|
||||||
|
SpVisualizerSelection *selection)
|
||||||
|
{
|
||||||
|
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||||
|
g_assert (SP_IS_VISUALIZER_SELECTION (selection));
|
||||||
|
|
||||||
|
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sp_visualizer_view_finalize (GObject *object)
|
sp_visualizer_view_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
@ -170,6 +425,7 @@ sp_visualizer_view_finalize (GObject *object)
|
|||||||
|
|
||||||
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
||||||
g_clear_object (&priv->zoom_manager);
|
g_clear_object (&priv->zoom_manager);
|
||||||
|
g_clear_object (&priv->selection);
|
||||||
|
|
||||||
G_OBJECT_CLASS (sp_visualizer_view_parent_class)->finalize (object);
|
G_OBJECT_CLASS (sp_visualizer_view_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
@ -230,6 +486,7 @@ sp_visualizer_view_class_init (SpVisualizerViewClass *klass)
|
|||||||
object_class->get_property = sp_visualizer_view_get_property;
|
object_class->get_property = sp_visualizer_view_get_property;
|
||||||
object_class->set_property = sp_visualizer_view_set_property;
|
object_class->set_property = sp_visualizer_view_set_property;
|
||||||
|
|
||||||
|
widget_class->draw = sp_visualizer_view_draw;
|
||||||
widget_class->size_allocate = sp_visualizer_view_size_allocate;
|
widget_class->size_allocate = sp_visualizer_view_size_allocate;
|
||||||
|
|
||||||
properties [PROP_READER] =
|
properties [PROP_READER] =
|
||||||
@ -270,6 +527,12 @@ sp_visualizer_view_class_init (SpVisualizerViewClass *klass)
|
|||||||
gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, ticks);
|
gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, ticks);
|
||||||
|
|
||||||
gtk_widget_class_set_css_name (widget_class, "visualizers");
|
gtk_widget_class_set_css_name (widget_class, "visualizers");
|
||||||
|
|
||||||
|
css_provider = gtk_css_provider_new ();
|
||||||
|
gtk_css_provider_load_from_resource (css_provider, "/org/gnome/sysprof/css/shared.css");
|
||||||
|
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
|
||||||
|
GTK_STYLE_PROVIDER (css_provider),
|
||||||
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -278,8 +541,43 @@ sp_visualizer_view_init (SpVisualizerView *self)
|
|||||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
GtkAdjustment *hadjustment;
|
GtkAdjustment *hadjustment;
|
||||||
|
|
||||||
|
priv->drag_begin_at = -1;
|
||||||
|
priv->drag_selection_at = -1;
|
||||||
|
|
||||||
gtk_widget_init_template (GTK_WIDGET (self));
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
|
|
||||||
|
priv->selection = g_object_new (SP_TYPE_VISUALIZER_SELECTION, NULL);
|
||||||
|
|
||||||
|
g_signal_connect_object (priv->selection,
|
||||||
|
"changed",
|
||||||
|
G_CALLBACK (sp_visualizer_view_selection_changed),
|
||||||
|
self,
|
||||||
|
G_CONNECT_SWAPPED);
|
||||||
|
|
||||||
|
g_signal_connect_object (priv->list,
|
||||||
|
"button-press-event",
|
||||||
|
G_CALLBACK (sp_visualizer_view_list_button_press_event),
|
||||||
|
self,
|
||||||
|
G_CONNECT_SWAPPED);
|
||||||
|
|
||||||
|
g_signal_connect_object (priv->list,
|
||||||
|
"button-release-event",
|
||||||
|
G_CALLBACK (sp_visualizer_view_list_button_release_event),
|
||||||
|
self,
|
||||||
|
G_CONNECT_SWAPPED);
|
||||||
|
|
||||||
|
g_signal_connect_object (priv->list,
|
||||||
|
"motion-notify-event",
|
||||||
|
G_CALLBACK (sp_visualizer_view_list_motion_notify_event),
|
||||||
|
self,
|
||||||
|
G_CONNECT_SWAPPED);
|
||||||
|
|
||||||
|
g_signal_connect_object (priv->list,
|
||||||
|
"realize",
|
||||||
|
G_CALLBACK (sp_visualizer_view_list_realize_after),
|
||||||
|
self,
|
||||||
|
G_CONNECT_SWAPPED | G_CONNECT_AFTER);
|
||||||
|
|
||||||
g_signal_connect_object (priv->list,
|
g_signal_connect_object (priv->list,
|
||||||
"add",
|
"add",
|
||||||
G_CALLBACK (sp_visualizer_view_row_added),
|
G_CALLBACK (sp_visualizer_view_row_added),
|
||||||
@ -338,6 +636,8 @@ sp_visualizer_view_set_reader (SpVisualizerView *self,
|
|||||||
|
|
||||||
sp_visualizer_ticks_set_epoch (priv->ticks, begin_time);
|
sp_visualizer_ticks_set_epoch (priv->ticks, begin_time);
|
||||||
sp_visualizer_ticks_set_time_range (priv->ticks, begin_time, begin_time);
|
sp_visualizer_ticks_set_time_range (priv->ticks, begin_time, begin_time);
|
||||||
|
|
||||||
|
sp_visualizer_selection_unselect_all (priv->selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
sp_visualizer_list_set_reader (priv->list, reader);
|
sp_visualizer_list_set_reader (priv->list, reader);
|
||||||
@ -437,3 +737,21 @@ sp_visualizer_view_set_zoom_manager (SpVisualizerView *self,
|
|||||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_MANAGER]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_MANAGER]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sp_visualizer_view_get_selection:
|
||||||
|
*
|
||||||
|
* Gets the #SpVisualizerSelection instance for the visualizer view.
|
||||||
|
* This can be used to alter the selection or selections of the visualizers.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): An #SpVisualizerSelection.
|
||||||
|
*/
|
||||||
|
SpVisualizerSelection *
|
||||||
|
sp_visualizer_view_get_selection (SpVisualizerView *self)
|
||||||
|
{
|
||||||
|
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||||
|
|
||||||
|
g_return_val_if_fail (SP_IS_VISUALIZER_VIEW (self), NULL);
|
||||||
|
|
||||||
|
return priv->selection;
|
||||||
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "sp-visualizer-row.h"
|
#include "sp-visualizer-row.h"
|
||||||
|
#include "sp-visualizer-selection.h"
|
||||||
#include "sp-zoom-manager.h"
|
#include "sp-zoom-manager.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
@ -57,13 +58,14 @@ struct _SpVisualizerViewClass
|
|||||||
gpointer _reserved16;
|
gpointer _reserved16;
|
||||||
};
|
};
|
||||||
|
|
||||||
GtkWidget *sp_visualizer_view_new (void);
|
GtkWidget *sp_visualizer_view_new (void);
|
||||||
SpCaptureReader *sp_visualizer_view_get_reader (SpVisualizerView *self);
|
SpCaptureReader *sp_visualizer_view_get_reader (SpVisualizerView *self);
|
||||||
void sp_visualizer_view_set_reader (SpVisualizerView *self,
|
void sp_visualizer_view_set_reader (SpVisualizerView *self,
|
||||||
SpCaptureReader *reader);
|
SpCaptureReader *reader);
|
||||||
SpZoomManager *sp_visualizer_view_get_zoom_manager (SpVisualizerView *self);
|
SpZoomManager *sp_visualizer_view_get_zoom_manager (SpVisualizerView *self);
|
||||||
void sp_visualizer_view_set_zoom_manager (SpVisualizerView *self,
|
void sp_visualizer_view_set_zoom_manager (SpVisualizerView *self,
|
||||||
SpZoomManager *zoom_manager);
|
SpZoomManager *zoom_manager);
|
||||||
|
SpVisualizerSelection *sp_visualizer_view_get_selection (SpVisualizerView *self);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,7 @@ G_BEGIN_DECLS
|
|||||||
# include "sp-process-model-row.h"
|
# include "sp-process-model-row.h"
|
||||||
# include "sp-profiler-menu-button.h"
|
# include "sp-profiler-menu-button.h"
|
||||||
# include "sp-visualizer-row.h"
|
# include "sp-visualizer-row.h"
|
||||||
|
# include "sp-visualizer-selection.h"
|
||||||
# include "sp-visualizer-view.h"
|
# include "sp-visualizer-view.h"
|
||||||
# include "sp-zoom-manager.h"
|
# include "sp-zoom-manager.h"
|
||||||
#undef SYSPROF_INSIDE
|
#undef SYSPROF_INSIDE
|
||||||
|
|||||||
Reference in New Issue
Block a user