16 unsigned int opt_index;
17 unsigned int opt_type;
40 #define GOPT_RANGE_SPIN 4
44 GtkWidget *spins[GOPT_RANGE_SPIN];
48 struct flist_head list;
52 static struct flist_head gopt_list[FIO_MAX_OPTS];
54 static void __gopt_set_children_visible(unsigned int idx, gboolean visible)
56 struct flist_head *entry;
57 struct gopt_widget *gw;
59 flist_for_each(entry, &gopt_list[idx]) {
60 gw = flist_entry(entry, struct gopt_widget, list);
61 gtk_widget_set_sensitive(gw->widget, visible);
66 * Mark children as invisible, if needed.
68 static void gopt_set_children_visible(struct fio_option *parent, gboolean visible)
74 * This isn't super fast, but it should not be an issue. If it is, we
75 * can speed it up by caching the lookup at least. Or we can do it
78 for (i = 0; fio_options[i].name; i++) {
80 if (!o->parent || !o->hide)
83 if (strcmp(parent->name, o->parent))
86 __gopt_set_children_visible(i, visible);
90 static void gopt_str_changed(GtkEntry *entry, gpointer data)
92 struct gopt_str *s = (struct gopt_str *) data;
93 struct fio_option *o = &fio_options[s->gopt.opt_index];
97 text = gtk_entry_get_text(GTK_ENTRY(s->entry));
98 set = strcmp(text, "") != 0;
99 gopt_set_children_visible(o, set);
102 static void gopt_mark_index(struct gopt *gopt, unsigned int idx)
104 struct gopt_widget *gw;
106 gopt->opt_index = idx;
108 gw = malloc(sizeof(*gw));
109 gw->widget = gopt->box;
110 flist_add_tail(&gw->list, &gopt_list[idx]);
113 static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text, unsigned int idx)
118 s = malloc(sizeof(*s));
120 s->gopt.box = gtk_hbox_new(FALSE, 3);
121 label = gtk_label_new(o->name);
122 gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0);
124 s->entry = gtk_entry_new();
125 gopt_mark_index(&s->gopt, idx);
127 gtk_entry_set_text(GTK_ENTRY(s->entry), text);
128 gtk_entry_set_editable(GTK_ENTRY(s->entry), 1);
129 g_signal_connect(GTK_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
132 gtk_entry_set_text(GTK_ENTRY(s->entry), o->def);
134 gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0);
138 static void gopt_combo_changed(GtkComboBox *box, gpointer data)
140 struct gopt_combo *c = (struct gopt_combo *) data;
141 struct fio_option *o = &fio_options[c->gopt.opt_index];
143 printf("combo %s changed\n", o->name);
146 static struct gopt_combo *__gopt_new_combo(struct fio_option *o, unsigned int idx)
148 struct gopt_combo *c;
151 c = malloc(sizeof(*c));
153 c->gopt.box = gtk_hbox_new(FALSE, 3);
154 label = gtk_label_new(o->name);
155 gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0);
157 c->combo = gtk_combo_box_new_text();
158 gopt_mark_index(&c->gopt, idx);
159 gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0);
161 g_signal_connect(GTK_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
166 static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text, unsigned int idx)
168 struct gopt_combo *combo;
169 struct value_pair *vp;
172 combo = __gopt_new_combo(o, idx);
177 gtk_combo_box_append_text(GTK_COMBO_BOX(combo->combo), vp->ival);
178 if (o->def && !strcmp(vp->ival, o->def))
180 if (text && !strcmp(vp->ival, text))
186 gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo), active);
190 static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip, unsigned int idx)
192 struct gopt_combo *combo;
193 struct value_pair *vp;
196 combo = __gopt_new_combo(o, idx);
201 gtk_combo_box_append_text(GTK_COMBO_BOX(combo->combo), vp->ival);
202 if (ip && vp->oval == *ip)
208 gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo), active);
212 static void gopt_int_changed(GtkSpinButton *spin, gpointer data)
214 struct gopt_int *i = (struct gopt_int *) data;
215 struct fio_option *o = &fio_options[i->gopt.opt_index];
217 printf("int %s changed\n", o->name);
220 static struct gopt_int *__gopt_new_int(struct fio_option *o, unsigned long long *p,
223 unsigned long long defval;
225 guint maxval, interval;
228 i = malloc(sizeof(*i));
229 i->gopt.box = gtk_hbox_new(FALSE, 3);
230 label = gtk_label_new(o->name);
231 gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
243 check_str_bytes(o->def, &val, NULL);
249 interval = o->interval;
251 i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval);
252 gopt_mark_index(&i->gopt, idx);
253 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(i->spin), GTK_UPDATE_IF_VALID);
254 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), defval);
256 gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0);
258 g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i);
263 static struct gopt *gopt_new_int(struct fio_option *o, unsigned int *ip, unsigned int idx)
265 unsigned long long ullp;
270 i = __gopt_new_int(o, &ullp, idx);
272 i = __gopt_new_int(o, NULL, idx);
277 static struct gopt *gopt_new_ullong(struct fio_option *o, unsigned long long *p,
282 i = __gopt_new_int(o, p, idx);
286 static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
288 struct gopt_bool *b = (struct gopt_bool *) data;
289 struct fio_option *o = &fio_options[b->gopt.opt_index];
292 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
293 gopt_set_children_visible(o, set);
296 static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val, unsigned int idx)
302 b = malloc(sizeof(*b));
303 b->gopt.box = gtk_hbox_new(FALSE, 3);
304 label = gtk_label_new(o->name);
305 gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0);
307 b->check = gtk_check_button_new();
308 gopt_mark_index(&b->gopt, idx);
311 else if (o->def && !strcmp(o->def, "1"))
314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate);
315 g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b);
317 gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0);
322 * These are paired 0/1 and 2/3. 0/2 are min values, 1/3 are max values.
323 * If the max is made smaller than min, adjust min down.
324 * If the min is made larger than max, adjust the max.
326 static void range_value_changed(GtkSpinButton *spin, gpointer data)
328 struct gopt_range *r = (struct gopt_range *) data;
332 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
333 if (GTK_SPIN_BUTTON(r->spins[i]) == spin) {
339 assert(changed != -1);
344 if (changed == 0 || changed == 2) {
345 GtkWidget *mspin = r->spins[changed + 1];
347 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
348 mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
350 gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
352 GtkWidget *mspin = r->spins[changed - 1];
354 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
355 mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
357 gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
361 static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip,
364 struct gopt_range *r;
370 r = malloc(sizeof(*r));
371 r->gopt.box = gtk_hbox_new(FALSE, 3);
372 gopt_mark_index(&r->gopt, idx);
373 label = gtk_label_new(o->name);
374 gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0);
384 check_str_bytes(o->def, &val, NULL);
390 interval = o->interval;
392 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
393 r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval);
394 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID);
396 gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), *ip[i]);
398 gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), defval);
400 gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0);
401 g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r);
407 static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
408 unsigned int opt_index, struct thread_options *to)
410 struct gopt *go = NULL;
413 case FIO_OPT_STR_VAL:
414 case FIO_OPT_STR_VAL_TIME: {
415 unsigned long long *ullp = NULL;
418 ullp = td_var(to, o->off1);
420 go = gopt_new_ullong(o, ullp, opt_index);
424 unsigned int *ip = NULL;
427 ip = td_var(to, o->off1);
429 go = gopt_new_int(o, ip, opt_index);
432 case FIO_OPT_STR_SET:
434 unsigned int *ip = NULL;
437 ip = td_var(to, o->off1);
439 go = gopt_new_bool(o, ip, opt_index);
443 unsigned int *ip = NULL;
446 ip = td_var(to, o->off1);
448 go = gopt_new_combo_int(o, ip, opt_index);
451 case FIO_OPT_STR_STORE: {
455 char **p = td_var(to, o->off1);
459 if (!o->posval[0].ival) {
460 go = gopt_new_str_store(o, text, opt_index);
464 go = gopt_new_combo_str(o, text, opt_index);
467 case FIO_OPT_STR_MULTI:
468 go = gopt_new_combo_str(o, NULL, opt_index);
470 case FIO_OPT_RANGE: {
471 unsigned int *ip[4] = { td_var(to, o->off1),
474 td_var(to, o->off4) };
476 go = gopt_new_int_range(o, ip, opt_index);
479 /* still need to handle this one */
480 case FIO_OPT_FLOAT_LIST:
482 case FIO_OPT_DEPRECATED:
485 printf("ignore type %u\n", o->type);
491 gtk_widget_set_tooltip_text(go->box, o->help);
493 gtk_box_pack_start(GTK_BOX(hbox), go->box, FALSE, FALSE, 5);
494 go->opt_type = o->type;
498 static void gopt_add_options(GtkWidget **vboxes, struct thread_options *to)
500 GtkWidget *hbox = NULL;
503 for (i = 0; fio_options[i].name; i++) {
504 struct fio_option *o = &fio_options[i];
505 unsigned int mask = o->category;
506 struct opt_group *og;
508 while ((og = opt_group_from_mask(&mask)) != NULL) {
509 GtkWidget *vbox = vboxes[ffz(~og->mask)];
511 hbox = gtk_hbox_new(FALSE, 3);
512 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
513 gopt_add_option(hbox, o, i, to);
518 static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
520 GtkWidget *box, *vbox, *scroll;
522 scroll = gtk_scrolled_window_new(NULL, NULL);
523 gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
524 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
526 vbox = gtk_vbox_new(FALSE, 3);
527 box = gtk_hbox_new(FALSE, 0);
528 gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
529 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
530 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new(og->name));
535 static void gopt_add_group_tabs(GtkWidget *notebook, GtkWidget **vbox)
537 struct opt_group *og;
540 for (i = 0; i < FIO_MAX_OPTS; i++)
541 INIT_FLIST_HEAD(&gopt_list[i]);
545 unsigned int mask = (1U << i);
547 og = opt_group_from_mask(&mask);
550 vbox[i] = gopt_add_group_tab(notebook, og);
555 void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
557 GtkWidget *dialog, *notebook;
558 GtkWidget *vboxes[__FIO_OPT_G_NR];
560 dialog = gtk_dialog_new_with_buttons("Fio options",
561 GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT,
562 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
563 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
565 gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768);
567 notebook = gtk_notebook_new();
568 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1);
569 gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
570 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook, TRUE, TRUE, 5);
572 gopt_add_group_tabs(notebook, vboxes);
574 gopt_add_options(vboxes, o);
576 gtk_widget_show_all(dialog);
578 gtk_dialog_run(GTK_DIALOG(dialog));
580 gtk_widget_destroy(dialog);