mirror of
https://github.com/bdnugget/xautoclick.git
synced 2026-11-07 09:17:31 +00:00
Get/set values in main
This commit is contained in:
1 parent
7e104623e5
commit
4247e99429
9 files changed
+46
-50
No files matched your search
@@ -9,6 +9,8 @@ gui_t* gui_init(int argc, char **argv) {
|
||||
if (!gui)
|
||||
return NULL;
|
||||
|
||||
gui->is_save_values = true;
|
||||
|
||||
init_gui(gui, argc, argv);
|
||||
if (!gui->ctx) {
|
||||
free(gui);
|
||||
@@ -23,7 +25,7 @@ void gui_set_button_sensitive(gui_t* gui, button_t button, bool state) {
|
||||
gui->set_button_sensitive(gui->ctx, button, state);
|
||||
}
|
||||
|
||||
int gui_get_spin_value(gui_t* gui, spin_t spin) {
|
||||
int gui_get_spin_value(const gui_t* gui, spin_t spin) {
|
||||
if (gui && gui->get_spin_value)
|
||||
return gui->get_spin_value(gui->ctx, spin);
|
||||
return -1;
|
||||
|
||||
@@ -26,6 +26,7 @@ typedef void (*gui_close_t)(void* ctx);
|
||||
|
||||
typedef struct gui_ctx {
|
||||
void* ctx;
|
||||
bool is_save_values;
|
||||
|
||||
gui_set_button_sensitive_t set_button_sensitive;
|
||||
gui_get_spin_value_t get_spin_value;
|
||||
@@ -35,9 +36,8 @@ typedef struct gui_ctx {
|
||||
} gui_t;
|
||||
|
||||
gui_t* gui_init(int argc, char **argv);
|
||||
|
||||
void gui_set_button_sensitive(gui_t* gui, button_t button, bool state);
|
||||
int gui_get_spin_value(gui_t* gui, spin_t spin);
|
||||
int gui_get_spin_value(const gui_t* gui, spin_t spin);
|
||||
void gui_set_spin_value(gui_t* gui, spin_t spin, int value);
|
||||
void gui_main_loop(gui_t* gui);
|
||||
void gui_close(gui_t* gui);
|
||||
|
||||
@@ -45,7 +45,6 @@ static void ascii_gui_set_spin_value(ascii_gui_t* ctx, spin_t spin, int value) {
|
||||
}
|
||||
|
||||
static void ascii_gui_close(ascii_gui_t* ctx) {
|
||||
set_options();
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
@@ -73,8 +72,6 @@ void init_gui(gui_t* gui, int argc, char **argv) {
|
||||
gui->set_spin_value = (gui_set_spin_value_t)ascii_gui_set_spin_value;
|
||||
gui->main_loop = (gui_main_loop_t)ascii_gui_main_loop;
|
||||
gui->close = (gui_close_t)ascii_gui_close;
|
||||
|
||||
get_options(gui);
|
||||
}
|
||||
|
||||
void set_alarm(int ms) {
|
||||
|
||||
+24
-24
@@ -29,6 +29,8 @@
|
||||
#include "osdep.h"
|
||||
|
||||
typedef struct cli_gui_ctx {
|
||||
int argc;
|
||||
char **argv;
|
||||
int spins[SPINS_COUNT];
|
||||
} cli_gui_t;
|
||||
|
||||
@@ -42,7 +44,6 @@ static void cli_gui_close(cli_gui_t* ctx);
|
||||
|
||||
void init_gui(gui_t* gui, int argc, char **argv) {
|
||||
cli_gui_t* ctx;
|
||||
int c;
|
||||
|
||||
ctx = calloc(1, sizeof(cli_gui_t));
|
||||
if (!ctx) {
|
||||
@@ -50,34 +51,15 @@ void init_gui(gui_t* gui, int argc, char **argv) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->argc = argc;
|
||||
ctx->argv = argv;
|
||||
|
||||
gui->ctx = ctx;
|
||||
gui->is_save_values = false; /* don't set options from command line */
|
||||
gui->get_spin_value = (gui_get_spin_value_t)cli_gui_get_spin_value;
|
||||
gui->set_spin_value = (gui_set_spin_value_t)cli_gui_set_spin_value;
|
||||
gui->main_loop = (gui_main_loop_t)cli_gui_main_loop;
|
||||
gui->close = (gui_close_t)cli_gui_close;
|
||||
/* don't set options from command line */
|
||||
|
||||
get_options(gui);
|
||||
|
||||
/* parse command line */
|
||||
while ((c = getopt(argc, argv, "hi:n:p:r:")) != - 1) {
|
||||
switch (c) {
|
||||
case 'h': printhelp(argv[0]); break;
|
||||
case 'i': ctx->spins[SPIN_INTERVAL] = atoi(optarg); break;
|
||||
case 'n': ctx->spins[SPIN_NUMBER] = atoi(optarg); break;
|
||||
case 'p': ctx->spins[SPIN_PREDELAY] = atoi(optarg); break;
|
||||
case 'r': ctx->spins[SPIN_RANDOM] = atoi(optarg); break;
|
||||
case '?':
|
||||
free(ctx);
|
||||
gui->ctx = NULL;
|
||||
return;
|
||||
default:
|
||||
fprintf(stderr, "unknown command line option: %s\n", argv[optind]);
|
||||
free(ctx);
|
||||
gui->ctx = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_alarm(int ms) {
|
||||
@@ -98,6 +80,24 @@ static void cli_gui_set_spin_value(cli_gui_t* ctx, spin_t spin, int value) {
|
||||
}
|
||||
|
||||
static void cli_gui_main_loop(cli_gui_t* ctx) {
|
||||
int c;
|
||||
|
||||
/* parse command line */
|
||||
while ((c = getopt(ctx->argc, ctx->argv, "hi:n:p:r:")) != - 1) {
|
||||
switch (c) {
|
||||
case 'h': printhelp(ctx->argv[0]); break;
|
||||
case 'i': ctx->spins[SPIN_INTERVAL] = atoi(optarg); break;
|
||||
case 'n': ctx->spins[SPIN_NUMBER] = atoi(optarg); break;
|
||||
case 'p': ctx->spins[SPIN_PREDELAY] = atoi(optarg); break;
|
||||
case 'r': ctx->spins[SPIN_RANDOM] = atoi(optarg); break;
|
||||
case '?':
|
||||
return;
|
||||
default:
|
||||
fprintf(stderr, "unknown command line option: %s\n", ctx->argv[optind]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
common_start_button();
|
||||
|
||||
while (sleeptime) {
|
||||
|
||||
@@ -101,8 +101,6 @@ void fltk_gui_main_loop(fltk_gui_t* ctx) {
|
||||
}
|
||||
|
||||
void fltk_gui_close(fltk_gui_t* ctx) {
|
||||
set_options();
|
||||
|
||||
delete ctx->win;
|
||||
delete ctx;
|
||||
}
|
||||
@@ -134,8 +132,6 @@ void init_gui(gui_t* gui, int, char**) {
|
||||
gui->set_spin_value = (gui_set_spin_value_t)fltk_gui_set_spin_value;
|
||||
gui->main_loop = (gui_main_loop_t)fltk_gui_main_loop;
|
||||
gui->close = (gui_close_t)fltk_gui_close;
|
||||
|
||||
get_options(gui);
|
||||
}
|
||||
|
||||
void set_alarm(int ms) {
|
||||
|
||||
@@ -28,6 +28,7 @@ typedef struct gtk_gui_ctx {
|
||||
GtkWidget *gAutoClick;
|
||||
GtkWidget *spins[SPINS_COUNT];
|
||||
GtkWidget *buttons[BUTTONS_COUNT];
|
||||
int values[SPINS_COUNT];
|
||||
} gtk_gui_t;
|
||||
|
||||
static gboolean myalarm(G_GNUC_UNUSED gpointer data) {
|
||||
@@ -40,6 +41,8 @@ void set_alarm(int ms) {
|
||||
}
|
||||
|
||||
static int gtk_gui_get_spin_value(gtk_gui_t* ctx, spin_t spin) {
|
||||
if (!ctx->spins[spin])
|
||||
return ctx->values[spin];
|
||||
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ctx->spins[spin]));
|
||||
}
|
||||
|
||||
@@ -161,9 +164,12 @@ static void create_buttons(gtk_gui_t* ctx, GObject *root, GtkWidget *box) {
|
||||
ctx->buttons[c] = create_labeled_button(root, box, btn_params[c].text, btn_params[c].callback);
|
||||
}
|
||||
|
||||
static void gautoclick_exit(void) {
|
||||
set_options();
|
||||
static gboolean gautoclick_exit(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, gtk_gui_t* ctx) {
|
||||
for (int i = 0; i < SPINS_COUNT; ++i)
|
||||
ctx->values[i] = gtk_gui_get_spin_value(ctx, i);
|
||||
|
||||
gtk_main_quit();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void create_gAutoClick(gtk_gui_t* ctx) {
|
||||
@@ -194,8 +200,8 @@ static void create_gAutoClick(gtk_gui_t* ctx) {
|
||||
|
||||
create_buttons(ctx, gAutoClick_obj, hbox);
|
||||
|
||||
g_signal_connect (gAutoClick_obj, "delete_event",
|
||||
G_CALLBACK (gautoclick_exit), NULL);
|
||||
g_signal_connect (gAutoClick_obj, "delete-event",
|
||||
G_CALLBACK (gautoclick_exit), ctx);
|
||||
|
||||
ctx->gAutoClick = gAutoClick_win;
|
||||
}
|
||||
@@ -219,6 +225,4 @@ void init_gui(gui_t* gui, int argc, char **argv) {
|
||||
gui->set_spin_value = (gui_set_spin_value_t)gtk_gui_set_spin_value;
|
||||
gui->main_loop = (gui_main_loop_t)gtk_gui_main_loop;
|
||||
gui->close = (gui_close_t)gtk_gui_close;
|
||||
|
||||
get_options(gui);
|
||||
}
|
||||
@@ -51,7 +51,6 @@ void qt_gui_main_loop(ClickWidget *clickWidget) {
|
||||
}
|
||||
|
||||
void qt_gui_close(ClickWidget *clickWidget) {
|
||||
set_options();
|
||||
delete clickTimer;
|
||||
delete clickWidget;
|
||||
}
|
||||
@@ -76,6 +75,4 @@ void init_gui(gui_t* gui, int argc, char **argv) {
|
||||
gui->set_spin_value = (gui_set_spin_value_t)qt_gui_set_spin_value;
|
||||
gui->main_loop = (gui_main_loop_t)qt_gui_main_loop;
|
||||
gui->close = (gui_close_t)qt_gui_close;
|
||||
|
||||
get_options(gui);
|
||||
}
|
||||
@@ -178,14 +178,14 @@ void common_tap_button(void) {
|
||||
prevtime = curtime;
|
||||
}
|
||||
|
||||
void get_options(gui_t *gui) {
|
||||
static void get_options(gui_t *gui) {
|
||||
gui_set_spin_value(gui, SPIN_PREDELAY, options.predelay);
|
||||
gui_set_spin_value(gui, SPIN_INTERVAL, options.interval);
|
||||
gui_set_spin_value(gui, SPIN_RANDOM, options.random_factor);
|
||||
gui_set_spin_value(gui, SPIN_NUMBER, options.clicks_number);
|
||||
}
|
||||
|
||||
void set_options(void) {
|
||||
static void set_options(const gui_t *gui) {
|
||||
options.predelay = gui_get_spin_value(gui, SPIN_PREDELAY);
|
||||
options.interval = gui_get_spin_value(gui, SPIN_INTERVAL);
|
||||
options.random_factor = gui_get_spin_value(gui, SPIN_RANDOM);
|
||||
@@ -320,12 +320,17 @@ int main(int argc, char **argv) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
get_options(gui);
|
||||
|
||||
gui_set_button_sensitive(gui, BUTTON_TAP, true);
|
||||
gui_set_button_sensitive(gui, BUTTON_STOP, false);
|
||||
gui_set_button_sensitive(gui, BUTTON_START, true);
|
||||
|
||||
gui_main_loop(gui);
|
||||
|
||||
if (gui->is_save_values)
|
||||
set_options(gui);
|
||||
|
||||
gui_close(gui);
|
||||
clicker_close(clicker);
|
||||
save_config(config_file, &options);
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
#ifndef __MAIN_H__
|
||||
#define __MAIN_H__
|
||||
|
||||
typedef struct gui_ctx gui_t;
|
||||
|
||||
/* Common functions. GUI's should call back to these */
|
||||
|
||||
void get_options(gui_t *gui);
|
||||
void set_options(void);
|
||||
|
||||
void common_tap_button(void);
|
||||
void common_stop_button(void);
|
||||
void common_start_button(void);
|
||||
|
||||
Reference in new issue
Block a user