summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2017-01-29 10:35:19 +0100
committerDave Andreoli <dave@gurumeditation.it>2017-01-29 10:35:19 +0100
commitabd60cca9aa3d411eb5f99972317d964256a3665 (patch)
tree93ca7e747ff961b7311a9d198856f3bd98d2f8ad
parentb0271f3a2b8f26cf7d7165d2e4c8fabec1a0584b (diff)
mem gadget: implemented a new info popup
It now show lots more usefull information. The actual values still need to be adjusted, the goal is to show the exact same values of the "free" command
-rw-r--r--src/modules/sysinfo/memusage/memusage.c181
-rw-r--r--src/modules/sysinfo/sysinfo.h1
2 files changed, 149 insertions, 33 deletions
diff --git a/src/modules/sysinfo/memusage/memusage.c b/src/modules/sysinfo/memusage/memusage.c
index 1cc8b645d..9576f4262 100644
--- a/src/modules/sysinfo/memusage/memusage.c
+++ b/src/modules/sysinfo/memusage/memusage.c
@@ -17,6 +17,55 @@ struct _Thread_Config
17}; 17};
18 18
19static void 19static void
20_memusage_popup_update(Instance *inst)
21{
22 Evas_Object *pbar;
23 int val_mb, val_perc;
24 char buf[128];
25
26 if (!inst->cfg->memusage.popup)
27 return;
28
29 if (inst->cfg->memusage.mem_total)
30 {
31 pbar = evas_object_data_get(inst->cfg->memusage.popup, "mem_active_pbar");
32 val_mb = inst->cfg->memusage.mem_active / 1024;
33 val_perc = 100 * ((float)inst->cfg->memusage.mem_active /
34 (float)inst->cfg->memusage.mem_total);
35 snprintf(buf, sizeof(buf), "%d MB (%d %%)", val_mb, val_perc);
36 elm_progressbar_value_set(pbar, (float)val_perc / 100);
37 elm_progressbar_unit_format_set(pbar, buf);
38
39 pbar = evas_object_data_get(inst->cfg->memusage.popup, "mem_buffers_pbar");
40 val_mb = inst->cfg->memusage.mem_buffers / 1024;
41 val_perc = 100 * ((float)inst->cfg->memusage.mem_buffers /
42 (float)inst->cfg->memusage.mem_total);
43 snprintf(buf, sizeof(buf), "%d MB (%d %%)", val_mb, val_perc);
44 elm_progressbar_value_set(pbar, (float)val_perc / 100);
45 elm_progressbar_unit_format_set(pbar, buf);
46
47 pbar = evas_object_data_get(inst->cfg->memusage.popup, "mem_cached_pbar");
48 val_mb = inst->cfg->memusage.mem_cached / 1024;
49 val_perc = 100 * ((float)inst->cfg->memusage.mem_cached /
50 (float)inst->cfg->memusage.mem_total);
51 snprintf(buf, sizeof(buf), "%d MB (%d %%)", val_mb, val_perc);
52 elm_progressbar_value_set(pbar, (float)val_perc / 100);
53 elm_progressbar_unit_format_set(pbar, buf);
54 }
55
56 if (inst->cfg->memusage.swp_total)
57 {
58 pbar = evas_object_data_get(inst->cfg->memusage.popup, "swap_pbar");
59 val_mb = inst->cfg->memusage.swp_active / 1024;
60 val_perc = 100 * ((float)inst->cfg->memusage.swp_active /
61 (float)inst->cfg->memusage.swp_total);
62 snprintf(buf, sizeof(buf), "%d MB (%d %%)", val_mb, val_perc);
63 elm_progressbar_value_set(pbar, (float)val_perc / 100);
64 elm_progressbar_unit_format_set(pbar, buf);
65 }
66}
67
68static void
20_memusage_face_update(Instance *inst) 69_memusage_face_update(Instance *inst)
21{ 70{
22 Edje_Message_Int_Set *msg; 71 Edje_Message_Int_Set *msg;
@@ -37,13 +86,7 @@ _memusage_face_update(Instance *inst)
37 free(msg); 86 free(msg);
38 87
39 if (inst->cfg->memusage.popup) 88 if (inst->cfg->memusage.popup)
40 { 89 _memusage_popup_update(inst);
41 char text[4096];
42 snprintf(text, sizeof(text), "%s: %d%%<br>%s: %d%%",
43 _("Total Memory Usage"), inst->cfg->memusage.mem_percent,
44 _("Total Swap Usage"), inst->cfg->memusage.swp_percent);
45 elm_object_text_set(inst->cfg->memusage.popup_label, text);
46 }
47} 90}
48 91
49static Evas_Object * 92static Evas_Object *
@@ -71,13 +114,105 @@ _memusage_popup_deleted(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_U
71 inst->cfg->memusage.popup = NULL; 114 inst->cfg->memusage.popup = NULL;
72} 115}
73 116
117static Evas_Object *
118_memusage_popup_create(Instance *inst)
119{
120 Evas_Object *popup, *box, *table, *frame, *label, *pbar;
121 char buf[128];
122
123 // popup + vert box
124 popup = elm_ctxpopup_add(e_comp->elm);
125 elm_object_style_set(popup, "noblock");
126 evas_object_smart_callback_add(popup, "dismissed",
127 _memusage_popup_dismissed, inst);
128 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL,
129 _memusage_popup_deleted, inst);
130
131 box = elm_box_add(popup);
132 elm_box_horizontal_set(box, EINA_FALSE);
133 E_EXPAND(box); E_FILL(box);
134 elm_object_content_set(popup, box);
135 evas_object_show(box);
136
137 // mem frame + table
138 frame = elm_frame_add(popup);
139 E_EXPAND(frame); E_FILL(frame);
140 snprintf(buf, sizeof(buf), _("Memory usage (available %ld MB)"),
141 inst->cfg->memusage.mem_total / 1024);
142 elm_object_text_set(frame, buf);
143 elm_box_pack_end(box, frame);
144 evas_object_show(frame);
145
146 table = elm_table_add(frame);
147 E_EXPAND(table); E_FILL(table);
148 elm_object_content_set(frame, table);
149 evas_object_show(table);
150
151 label = elm_label_add(table);
152 E_EXPAND(label); E_ALIGN(label, 0.0, 0.5);
153 elm_object_text_set(label, _("Active"));
154 elm_table_pack(table, label, 0, 1, 1, 1);
155 evas_object_show(label);
156 pbar = elm_progressbar_add(table);
157 E_EXPAND(pbar); E_FILL(pbar);
158 elm_progressbar_span_size_set(pbar, 200 * e_scale);
159 elm_table_pack(table, pbar, 1, 1, 1, 1);
160 evas_object_show(pbar);
161 evas_object_data_set(popup, "mem_active_pbar", pbar);
162
163 label = elm_label_add(table);
164 E_EXPAND(label); E_ALIGN(label, 0.0, 0.5);
165 elm_object_text_set(label, _("Buffers"));
166 elm_table_pack(table, label, 0, 2, 1, 1);
167 evas_object_show(label);
168 pbar = elm_progressbar_add(table);
169 E_EXPAND(pbar); E_FILL(pbar);
170 elm_progressbar_span_size_set(pbar, 200 * e_scale);
171 elm_table_pack(table, pbar, 1, 2, 1, 1);
172 evas_object_show(pbar);
173 evas_object_data_set(popup, "mem_buffers_pbar", pbar);
174
175 label = elm_label_add(table);
176 E_EXPAND(label); E_ALIGN(label, 0.0, 0.5);
177 elm_object_text_set(label, _("Cached"));
178 elm_table_pack(table, label, 0, 3, 1, 1);
179 evas_object_show(label);
180 pbar = elm_progressbar_add(table);
181 E_EXPAND(pbar); E_FILL(pbar);
182 elm_progressbar_span_size_set(pbar, 200 * e_scale);
183 elm_table_pack(table, pbar, 1, 3, 1, 1);
184 evas_object_show(pbar);
185 evas_object_data_set(popup, "mem_cached_pbar", pbar);
186
187 // swp frame
188 frame = elm_frame_add(popup);
189 E_EXPAND(frame); E_FILL(frame);
190 snprintf(buf, sizeof(buf), _("Swap usage (available %ld MB)"),
191 inst->cfg->memusage.swp_total / 1024);
192 elm_object_text_set(frame, buf);
193 elm_box_pack_end(box, frame);
194 evas_object_show(frame);
195
196 pbar = elm_progressbar_add(frame);
197 E_EXPAND(pbar); E_FILL(pbar);
198 elm_object_content_set(frame, pbar);
199 evas_object_show(pbar);
200 evas_object_data_set(popup, "swap_pbar", pbar);
201
202 // show and place the popup
203 e_comp_object_util_autoclose(popup, NULL, NULL, NULL);
204 evas_object_show(popup);
205 e_gadget_util_ctxpopup_place(inst->o_main, popup,
206 inst->cfg->memusage.o_gadget);
207
208 return popup;
209}
210
74static void 211static void
75_memusage_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_data) 212_memusage_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_data)
76{ 213{
77 Evas_Object *label, *popup;
78 Evas_Event_Mouse_Down *ev = event_data; 214 Evas_Event_Mouse_Down *ev = event_data;
79 Instance *inst = data; 215 Instance *inst = data;
80 char text[4096];
81 216
82 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; 217 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
83 if (ev->button != 3) 218 if (ev->button != 3)
@@ -86,30 +221,12 @@ _memusage_mouse_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_U
86 { 221 {
87 elm_ctxpopup_dismiss(inst->cfg->memusage.popup); 222 elm_ctxpopup_dismiss(inst->cfg->memusage.popup);
88 inst->cfg->memusage.popup = NULL; 223 inst->cfg->memusage.popup = NULL;
89 return;
90 } 224 }
91 popup = elm_ctxpopup_add(e_comp->elm); 225 else
92 elm_object_style_set(popup, "noblock"); 226 {
93 evas_object_smart_callback_add(popup, "dismissed", 227 inst->cfg->memusage.popup = _memusage_popup_create(inst);
94 _memusage_popup_dismissed, inst); 228 _memusage_popup_update(inst);
95 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, 229 }
96 _memusage_popup_deleted, inst);
97
98 snprintf(text, sizeof(text), "%s: %d%%<br>%s: %d%%",
99 _("Total Memory Usage"), inst->cfg->memusage.mem_percent,
100 _("Total Swap Usage"), inst->cfg->memusage.swp_percent);
101 label = elm_label_add(popup);
102 elm_object_style_set(label, "marker");
103 elm_object_text_set(label, text);
104 elm_object_content_set(popup, label);
105 evas_object_show(label);
106 inst->cfg->memusage.popup_label = label;
107
108 e_comp_object_util_autoclose(popup, NULL, NULL, NULL);
109 evas_object_show(popup);
110 e_gadget_util_ctxpopup_place(inst->o_main, popup,
111 inst->cfg->memusage.o_gadget);
112 inst->cfg->memusage.popup = popup;
113 } 230 }
114 else 231 else
115 { 232 {
diff --git a/src/modules/sysinfo/sysinfo.h b/src/modules/sysinfo/sysinfo.h
index 41d672e98..e91ca673a 100644
--- a/src/modules/sysinfo/sysinfo.h
+++ b/src/modules/sysinfo/sysinfo.h
@@ -203,7 +203,6 @@ struct _Config_Item
203 { 203 {
204 Evas_Object *o_gadget; 204 Evas_Object *o_gadget;
205 Evas_Object *popup; 205 Evas_Object *popup;
206 Evas_Object *popup_label;
207 Evas_Object *configure; 206 Evas_Object *configure;
208 int poll_interval; 207 int poll_interval;
209 int mem_percent; 208 int mem_percent;