Skip to content

Commit

Permalink
implement FLTK GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ivop committed May 24, 2010
1 parent bbd1253 commit df5e4d5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ChangeLog

* source code cleaned up
* added Qt 4 GUI
* added FLTK GUI

v0.20
* various documentation and typo fixes
Expand Down
66 changes: 63 additions & 3 deletions guifltk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*
*/

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Spinner.H>
#include <FL/Fl_Button.H>

extern "C" {
#include "main.h"
#include "osdep.h"
Expand All @@ -28,26 +33,63 @@ extern "C" {
#include <X11/extensions/XTest.h>

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);
XTestFakeButtonEvent(display, 1, False, CurrentTime);
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) {
Expand All @@ -56,11 +98,29 @@ 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;
}

void close_gui(void) {
}

void main_loop(void) {
w->show();
Fl::run();
}

0 comments on commit df5e4d5

Please sign in to comment.