Fixed restoration of the panel divider position.
[psensor.git] / src / ui_graph.c
1 /*
2  * Copyright (C) 2010-2016 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 #include "graph.h"
20 #include "ui_graph.h"
21
22 static int
23 on_graph_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
24 {
25         if (event->type != GDK_BUTTON_PRESS)
26                 return FALSE;
27
28         gtk_menu_popup(GTK_MENU(((struct ui_psensor *)data)->popup_menu),
29                        NULL, NULL, NULL, NULL,
30                        event->button, event->time);
31
32         return TRUE;
33 }
34
35 static gboolean
36 on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
37 {
38         struct ui_psensor *ui_psensor = (struct ui_psensor *)data;
39
40         graph_update(ui_psensor->sensors,
41                      ui_get_graph(),
42                      ui_psensor->config,
43                      ui_psensor->main_window);
44
45         return FALSE;
46 }
47
48 static void smooth_curves_enabled_changed_cbk(void *data)
49 {
50         is_smooth_curves_enabled = config_is_smooth_curves_enabled();
51 }
52
53 void ui_graph_create(struct ui_psensor *ui)
54 {
55         GtkWidget *w_graph;
56
57         log_debug("ui_graph_create()");
58
59         w_graph = ui_get_graph();
60
61         is_smooth_curves_enabled = config_is_smooth_curves_enabled();
62         g_signal_connect_after(config_get_GSettings(),
63                                "changed::graph-smooth-curves-enabled",
64                                G_CALLBACK(smooth_curves_enabled_changed_cbk),
65                                NULL);
66
67         g_signal_connect(GTK_WIDGET(w_graph),
68                          "draw",
69                          G_CALLBACK(on_expose_event),
70                          ui);
71
72         gtk_widget_add_events(w_graph, GDK_BUTTON_PRESS_MASK);
73
74         g_signal_connect(GTK_WIDGET(w_graph),
75                          "button_press_event",
76                          (GCallback) on_graph_clicked, ui);
77
78         log_debug("ui_graph_create() ends");
79 }