diff --git a/ChangeLog b/ChangeLog index 0600319..5a31258 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ ChangeLog * source code cleaned up * added Qt 4 GUI + * added FLTK GUI v0.20 * various documentation and typo fixes diff --git a/guifltk.cpp b/guifltk.cpp index 6edf05a..12ed29b 100644 --- a/guifltk.cpp +++ b/guifltk.cpp @@ -18,6 +18,11 @@ * */ +#include +#include +#include +#include + extern "C" { #include "main.h" #include "osdep.h" @@ -28,6 +33,19 @@ extern "C" { #include static Display *display; +static Fl_Double_Window *w; +static Fl_Button *buttons[3]; +static Fl_Spinner *spins[4]; +static int repeated = 0; + +static const struct foo { + const char * const label; + const int min, max, val; +} bar[4] = { + { "Pre-delay", 1, 1<<30, 2000 }, { "Interval", 1, 1<<30, 1000 }, + { "Random +/-", 1, 10240, 64 }, { "# of clicks", 1, 10240, 32 } +}; +static const char * const butnames[3] = { "Tap", "Stop", "Start" }; void click_mouse_button(void) { XTestFakeButtonEvent(display, 1, True, CurrentTime); @@ -35,19 +53,43 @@ void click_mouse_button(void) { XFlush(display); } +static void alarm_callback(void *v) { + common_alarm_callback(); +} + void set_alarm(int ms) { + if (!repeated) { + Fl::add_timeout(0.001*ms, alarm_callback); + repeated = 1; + } else { + Fl::repeat_timeout(0.001*ms, alarm_callback); + } } int get_spin_value(spin_t spin) { -// return mywidget->spins[spin]->value(); + return spins[spin]->value(); } void set_spin_value(spin_t spin, int value) { -// mywidget->spins[spin]->setValue(value); + spins[spin]->value(value); } void set_button_sensitive(button_t button, int state) { -// mywidget->buttons[button]->setEnabled(state); + if (state) buttons[button]->activate(); + else buttons[button]->deactivate(); +} + +static void tap_callback(Fl_Widget *w, void *v) { + common_tap_button(); +} + +static void stop_callback(Fl_Widget *w, void *v) { + repeated = 0; + common_stop_button(); +} + +static void start_callback(Fl_Widget *w, void *v) { + common_start_button(); } int init_gui(int argc, char **argv) { @@ -56,6 +98,22 @@ int init_gui(int argc, char **argv) { return 0; } + w = new Fl_Double_Window(175, 155, "fltkAutoClick"); + w->begin(); + w->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE); + for (int c=0; c<3; c++) + buttons[c] = new Fl_Button(5+55*c, 125, 55, 25, butnames[c]); + for (int c=0; c<4; c++) { + spins[c] = new Fl_Spinner(95, 5+c*30, 75, 25, bar[c].label); + spins[c]->minimum(bar[c].min); + spins[c]->maximum(bar[c].max); + spins[c]->value (bar[c].val); + } + buttons[0]->callback(tap_callback); + buttons[1]->callback(stop_callback); + buttons[2]->callback(start_callback); + w->end(); + return 1; } @@ -63,4 +121,6 @@ void close_gui(void) { } void main_loop(void) { + w->show(); + Fl::run(); }