16 unsigned int opt_index;
17 unsigned int opt_type;
28 unsigned int in_change;
34 unsigned int in_change;
43 #define GOPT_RANGE_SPIN 4
47 GtkWidget *spins[GOPT_RANGE_SPIN];
50 struct gopt_str_multi {
52 GtkWidget *checks[PARSE_MAX_VP];
55 static GtkWidget *gopt_widgets[FIO_MAX_OPTS];
57 struct gopt_frame_widget {
61 static struct gopt_frame_widget gopt_g_widgets[__FIO_OPT_G_NR];
63 static GtkWidget *gopt_get_group_frame(GtkWidget *box, unsigned int groupmask)
65 unsigned int mask, group;
67 GtkWidget *frame, *hbox;
68 struct gopt_frame_widget *gfw;
74 og = opt_group_cat_from_mask(&mask);
78 group = ffz(~groupmask);
79 gfw = &gopt_g_widgets[group];
81 frame = gtk_frame_new(og->name);
82 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3);
83 hbox = gtk_hbox_new(FALSE, 0);
84 gtk_container_add(GTK_CONTAINER(frame), hbox);
85 gfw->vbox[0] = gtk_vbox_new(TRUE, 5);
86 gfw->vbox[1] = gtk_vbox_new(TRUE, 5);
87 gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[0], TRUE, TRUE, 5);
88 gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[1], TRUE, TRUE, 5);
91 hbox = gtk_hbox_new(FALSE, 3);
92 gtk_box_pack_start(GTK_BOX(gfw->vbox[gfw->nr++ & 1]), hbox, FALSE, FALSE, 5);
97 * Mark children as invisible, if needed.
99 static void gopt_set_children_visible(struct fio_option *parent, gboolean visible)
101 struct fio_option *o;
105 * This isn't super fast, but it should not be an issue. If it is, we
106 * can speed it up by caching the lookup at least. Or we can do it
107 * once, at init time.
109 for (i = 0; fio_options[i].name; i++) {
111 if (!o->parent || !o->hide)
114 if (strcmp(parent->name, o->parent))
118 gtk_widget_set_sensitive(gopt_widgets[i], visible);
122 static void gopt_str_changed(GtkEntry *entry, gpointer data)
124 struct gopt_str *s = (struct gopt_str *) data;
125 struct fio_option *o = &fio_options[s->gopt.opt_index];
129 text = gtk_entry_get_text(GTK_ENTRY(s->entry));
130 set = strcmp(text, "") != 0;
131 gopt_set_children_visible(o, set);
134 static void gopt_mark_index(struct gopt *gopt, unsigned int idx)
136 assert(!gopt_widgets[idx]);
137 gopt->opt_index = idx;
138 gopt_widgets[idx] = gopt->box;
141 static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text, unsigned int idx)
146 s = malloc(sizeof(*s));
147 memset(s, 0, sizeof(*s));
149 s->gopt.box = gtk_hbox_new(FALSE, 3);
151 label = gtk_label_new(o->name);
153 label = gtk_label_new(o->lname);
155 s->entry = gtk_entry_new();
156 gopt_mark_index(&s->gopt, idx);
158 gtk_entry_set_text(GTK_ENTRY(s->entry), text);
159 gtk_entry_set_editable(GTK_ENTRY(s->entry), 1);
160 g_signal_connect(GTK_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
163 gtk_entry_set_text(GTK_ENTRY(s->entry), o->def);
165 gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0);
166 gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0);
171 static void gopt_combo_changed(GtkComboBox *box, gpointer data)
173 struct gopt_combo *c = (struct gopt_combo *) data;
174 struct fio_option *o = &fio_options[c->gopt.opt_index];
176 printf("combo %s changed\n", o->name);
179 static struct gopt_combo *__gopt_new_combo(struct fio_option *o, unsigned int idx)
181 struct gopt_combo *c;
184 c = malloc(sizeof(*c));
185 memset(c, 0, sizeof(*c));
187 c->gopt.box = gtk_hbox_new(FALSE, 3);
189 label = gtk_label_new(o->name);
191 label = gtk_label_new(o->lname);
193 c->combo = gtk_combo_box_new_text();
194 gopt_mark_index(&c->gopt, idx);
195 g_signal_connect(GTK_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
197 gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0);
198 gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0);
204 static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text, unsigned int idx)
206 struct gopt_combo *combo;
207 struct value_pair *vp;
210 combo = __gopt_new_combo(o, idx);
215 gtk_combo_box_append_text(GTK_COMBO_BOX(combo->combo), vp->ival);
216 if (o->def && !strcmp(vp->ival, o->def))
218 if (text && !strcmp(vp->ival, text))
224 gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo), active);
228 static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip, unsigned int idx)
230 struct gopt_combo *combo;
231 struct value_pair *vp;
234 combo = __gopt_new_combo(o, idx);
239 gtk_combo_box_append_text(GTK_COMBO_BOX(combo->combo), vp->ival);
240 if (ip && vp->oval == *ip)
246 gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo), active);
250 static struct gopt *gopt_new_str_multi(struct fio_option *o, unsigned int idx)
252 struct gopt_str_multi *m;
253 struct value_pair *vp;
254 GtkWidget *frame, *hbox;
257 m = malloc(sizeof(*m));
258 memset(m, 0, sizeof(*m));
259 m->gopt.box = gtk_hbox_new(FALSE, 3);
260 gopt_mark_index(&m->gopt, idx);
263 frame = gtk_frame_new(o->name);
265 frame = gtk_frame_new(o->lname);
266 gtk_box_pack_start(GTK_BOX(m->gopt.box), frame, FALSE, FALSE, 3);
268 hbox = gtk_hbox_new(FALSE, 3);
269 gtk_container_add(GTK_CONTAINER(frame), hbox);
274 m->checks[i] = gtk_check_button_new_with_label(vp->ival);
275 gtk_widget_set_tooltip_text(m->checks[i], vp->help);
276 gtk_box_pack_start(GTK_BOX(hbox), m->checks[i], FALSE, FALSE, 3);
283 static void gopt_int_changed(GtkSpinButton *spin, gpointer data)
285 struct gopt_int *i = (struct gopt_int *) data;
286 struct fio_option *o = &fio_options[i->gopt.opt_index];
290 adj = gtk_spin_button_get_adjustment(spin);
291 value = gtk_adjustment_get_value(adj);
292 delta = value - i->lastval;
296 struct gopt_int *i_inv = o->inv_opt->gui_data;
299 assert(o->type == o->inv_opt->type);
302 * Don't recourse into notify changes. Is there a better
303 * way than this? We essentially want to block the update
304 * signal while we perform the below set_value().
306 if (i_inv->in_change)
310 cur_val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(i_inv->spin));
312 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i_inv->spin), cur_val);
317 static struct gopt_int *__gopt_new_int(struct fio_option *o, unsigned long long *p,
320 unsigned long long defval;
322 guint maxval, interval;
325 i = malloc(sizeof(*i));
326 memset(i, 0, sizeof(*i));
327 i->gopt.box = gtk_hbox_new(FALSE, 3);
329 label = gtk_label_new(o->name);
331 label = gtk_label_new(o->lname);
343 check_str_bytes(o->def, &val, NULL);
349 interval = o->interval;
351 i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval);
352 gopt_mark_index(&i->gopt, idx);
353 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(i->spin), GTK_UPDATE_IF_VALID);
354 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), defval);
356 g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i);
358 gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0);
359 gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
365 static struct gopt *gopt_new_int(struct fio_option *o, unsigned int *ip, unsigned int idx)
367 unsigned long long ullp;
372 i = __gopt_new_int(o, &ullp, idx);
374 i = __gopt_new_int(o, NULL, idx);
379 static struct gopt *gopt_new_ullong(struct fio_option *o, unsigned long long *p,
384 i = __gopt_new_int(o, p, idx);
388 static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
390 struct gopt_bool *b = (struct gopt_bool *) data;
391 struct fio_option *o = &fio_options[b->gopt.opt_index];
394 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
397 struct gopt_bool *b_inv = o->inv_opt->gui_data;
399 assert(o->type == o->inv_opt->type);
402 * Don't recourse into notify changes. Is there a better
403 * way than this? We essentially want to block the update
404 * signal while we perform the below set_value().
406 if (b_inv->in_change)
410 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b_inv->check), !set);
414 gopt_set_children_visible(o, set);
417 static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val, unsigned int idx)
423 b = malloc(sizeof(*b));
424 memset(b, 0, sizeof(*b));
425 b->gopt.box = gtk_hbox_new(FALSE, 3);
427 label = gtk_label_new(o->name);
429 label = gtk_label_new(o->lname);
431 b->check = gtk_check_button_new();
432 gopt_mark_index(&b->gopt, idx);
435 else if (o->def && !strcmp(o->def, "1"))
439 defstate = !defstate;
441 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate);
442 g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b);
444 gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0);
445 gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0);
451 * These are paired 0/1 and 2/3. 0/2 are min values, 1/3 are max values.
452 * If the max is made smaller than min, adjust min down.
453 * If the min is made larger than max, adjust the max.
455 static void range_value_changed(GtkSpinButton *spin, gpointer data)
457 struct gopt_range *r = (struct gopt_range *) data;
461 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
462 if (GTK_SPIN_BUTTON(r->spins[i]) == spin) {
468 assert(changed != -1);
473 if (changed == 0 || changed == 2) {
474 GtkWidget *mspin = r->spins[changed + 1];
476 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
477 mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
479 gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
481 GtkWidget *mspin = r->spins[changed - 1];
483 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
484 mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
486 gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
490 static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip,
493 struct gopt_range *r;
499 r = malloc(sizeof(*r));
500 memset(r, 0, sizeof(*r));
501 r->gopt.box = gtk_hbox_new(FALSE, 3);
502 gopt_mark_index(&r->gopt, idx);
504 label = gtk_label_new(o->name);
506 label = gtk_label_new(o->lname);
516 check_str_bytes(o->def, &val, NULL);
522 interval = o->interval;
524 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
525 r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval);
526 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID);
528 gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), *ip[i]);
530 gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), defval);
532 gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0);
533 g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r);
536 gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0);
541 static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
542 unsigned int opt_index, struct thread_options *to)
544 struct gopt *go = NULL;
547 case FIO_OPT_STR_VAL:
548 case FIO_OPT_STR_VAL_TIME: {
549 unsigned long long *ullp = NULL;
552 ullp = td_var(to, o->off1);
554 go = gopt_new_ullong(o, ullp, opt_index);
558 unsigned int *ip = NULL;
561 ip = td_var(to, o->off1);
563 go = gopt_new_int(o, ip, opt_index);
566 case FIO_OPT_STR_SET:
568 unsigned int *ip = NULL;
571 ip = td_var(to, o->off1);
573 go = gopt_new_bool(o, ip, opt_index);
577 if (o->posval[0].ival) {
578 unsigned int *ip = NULL;
581 ip = td_var(to, o->off1);
583 go = gopt_new_combo_int(o, ip, opt_index);
585 /* TODO: usually ->cb, or unsigned int pointer */
586 go = gopt_new_str_store(o, NULL, opt_index);
591 case FIO_OPT_STR_STORE: {
595 char **p = td_var(to, o->off1);
599 if (!o->posval[0].ival) {
600 go = gopt_new_str_store(o, text, opt_index);
604 go = gopt_new_combo_str(o, text, opt_index);
607 case FIO_OPT_STR_MULTI:
608 go = gopt_new_str_multi(o, opt_index);
610 case FIO_OPT_RANGE: {
611 unsigned int *ip[4] = { td_var(to, o->off1),
614 td_var(to, o->off4) };
616 go = gopt_new_int_range(o, ip, opt_index);
619 /* still need to handle this one */
620 case FIO_OPT_FLOAT_LIST:
622 case FIO_OPT_DEPRECATED:
625 printf("ignore type %u\n", o->type);
633 gtk_widget_set_tooltip_text(go->box, o->help);
635 go->opt_type = o->type;
637 dest = gopt_get_group_frame(hbox, o->group);
639 gtk_box_pack_start(GTK_BOX(hbox), go->box, FALSE, FALSE, 5);
641 gtk_box_pack_start(GTK_BOX(dest), go->box, FALSE, FALSE, 5);
645 static void gopt_add_options(GtkWidget **vboxes, struct thread_options *to)
647 GtkWidget *hbox = NULL;
651 * First add all options
653 for (i = 0; fio_options[i].name; i++) {
654 struct fio_option *o = &fio_options[i];
655 unsigned int mask = o->category;
656 struct opt_group *og;
658 while ((og = opt_group_from_mask(&mask)) != NULL) {
659 GtkWidget *vbox = vboxes[ffz(~og->mask)];
661 hbox = gtk_hbox_new(FALSE, 3);
662 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
663 gopt_add_option(hbox, o, i, to);
668 static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
670 GtkWidget *box, *vbox, *scroll;
672 scroll = gtk_scrolled_window_new(NULL, NULL);
673 gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
674 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
676 vbox = gtk_vbox_new(FALSE, 3);
677 box = gtk_hbox_new(FALSE, 0);
678 gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
679 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
680 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new(og->name));
685 static void gopt_add_group_tabs(GtkWidget *notebook, GtkWidget **vbox)
687 struct opt_group *og;
692 unsigned int mask = (1U << i);
694 og = opt_group_from_mask(&mask);
697 vbox[i] = gopt_add_group_tab(notebook, og);
702 void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
704 GtkWidget *dialog, *notebook;
705 GtkWidget *vboxes[__FIO_OPT_C_NR];
707 dialog = gtk_dialog_new_with_buttons("Fio options",
708 GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT,
709 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
710 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
712 gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768);
714 notebook = gtk_notebook_new();
715 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1);
716 gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
717 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook, TRUE, TRUE, 5);
719 gopt_add_group_tabs(notebook, vboxes);
721 gopt_add_options(vboxes, o);
723 gtk_widget_show_all(dialog);
725 gtk_dialog_run(GTK_DIALOG(dialog));
727 gtk_widget_destroy(dialog);