Skip to content

Commit

Permalink
Return false from every g_idle_add (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
robiot authored Sep 29, 2023
1 parent e21fafb commit e37c609
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
21 changes: 13 additions & 8 deletions src/mainwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ int get_text_to_int(GtkWidget *entry)
/**
* Toggle the start and stop buttons
*/
void toggle_buttons()
gboolean toggle_buttons()
{
gtk_widget_set_sensitive(GTK_WIDGET(mainappwindow.start_button), !isClicking);
gtk_widget_set_sensitive(GTK_WIDGET(mainappwindow.stop_button), isClicking);
return FALSE;
}

/**
Expand Down Expand Up @@ -175,7 +176,7 @@ void click_handler(gpointer *data)

g_free(data);
XCloseDisplay(display);
g_idle_add_once(toggle_buttons, NULL);
g_idle_add(toggle_buttons, NULL);
}

/**
Expand All @@ -196,7 +197,7 @@ struct set_coord_args
/**
* Updates the x and y textboxes with the current cursor location.
*/
void set_coords(gpointer *data)
gboolean set_coords(gpointer *data)
{
struct set_coord_args *args = data;
if (GTK_IS_ENTRY(mainappwindow.x_entry))
Expand All @@ -205,6 +206,8 @@ void set_coords(gpointer *data)
gtk_entry_set_text(mainappwindow.y_entry, args->coordy);

g_free(args);

return FALSE;
}

/**
Expand All @@ -230,7 +233,7 @@ void get_cursor_pos_click_handler()
/**
* Toggle "Get button sensitive" and window topmost.
*/
void toggle_get_active()
gboolean toggle_get_active()
{
switch (isChoosingLocation)
{
Expand All @@ -245,6 +248,7 @@ void toggle_get_active()
gtk_widget_set_sensitive(mainappwindow.get_button, TRUE);
break;
}
return FALSE;
}

/**
Expand All @@ -267,14 +271,14 @@ void get_cursor_pos_handler()
struct set_coord_args *data = g_malloc0(sizeof(struct set_coord_args));
data->coordx = cur_x;
data->coordy = cur_y;
g_idle_add_once(set_coords, data);
g_idle_add(set_coords, data);

usleep(50000);
free(cur_x);
free(cur_y);
}
XCloseDisplay(display);
g_idle_add_once(toggle_get_active, NULL);
g_idle_add(toggle_get_active, NULL);
}

/**
Expand Down Expand Up @@ -359,12 +363,13 @@ void input_changed_save_handler(GtkEditable *editable, struct _MainAppWindow *ma
save_and_populate_config();
}

void open_safe_mode_dialog()
gboolean open_safe_mode_dialog()
{
GtkDialog *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Warning");
gtk_message_dialog_format_secondary_text(dialog, "Intervals under 100 milliseconds is restricted because of safe mode.");
gtk_dialog_run(dialog);
gtk_widget_destroy(dialog);
return FALSE;
}

/**
Expand All @@ -377,7 +382,7 @@ void start_clicked()

if (sleep < 100 && is_safemode())
{
g_idle_add_once(open_safe_mode_dialog, NULL);
g_idle_add(open_safe_mode_dialog, NULL);
return;
}

Expand Down
43 changes: 20 additions & 23 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,29 @@ struct _items

struct set_buttons_entry_struct
{
char *text;
char *text;
};

void set_buttons_entry_text(gpointer *data)
gboolean set_buttons_entry_text(gpointer *data)
{
struct set_buttons_entry_struct *args = data;
struct set_buttons_entry_struct *args = data;
gtk_entry_set_text(GTK_ENTRY(items.buttons_entry), args->text);
free(args->text);
g_free(args);

return FALSE;
}

void enable_start_button()
gboolean enable_start_button()
{
gtk_widget_set_sensitive(items.start_button, TRUE);
return FALSE;
}

void hotkey_finished()
gboolean hotkey_finished()
{
set_start_stop_button_hotkey_text();
return FALSE;
}

/**
Expand All @@ -65,29 +69,24 @@ void get_hotkeys_handler()
continue;

// If prekey, ex shift, ctrl
if (state == XKeysymToKeycode(display, XK_Shift_L) || state == XKeysymToKeycode(display, XK_Shift_R)
|| state == XKeysymToKeycode(display, XK_Alt_L) || state == XKeysymToKeycode(display, XK_Alt_R)
|| state == XKeysymToKeycode(display, XK_Escape) || state == XKeysymToKeycode(display, XK_Control_L)
|| state == XKeysymToKeycode(display, XK_Control_R) || state == XKeysymToKeycode(display, XK_ISO_Level3_Shift)
|| state == XKeysymToKeycode(display, XK_Super_L) || state == XKeysymToKeycode(display, XK_Super_R))
if (state == XKeysymToKeycode(display, XK_Shift_L) || state == XKeysymToKeycode(display, XK_Shift_R) || state == XKeysymToKeycode(display, XK_Alt_L) || state == XKeysymToKeycode(display, XK_Alt_R) || state == XKeysymToKeycode(display, XK_Escape) || state == XKeysymToKeycode(display, XK_Control_L) || state == XKeysymToKeycode(display, XK_Control_R) || state == XKeysymToKeycode(display, XK_ISO_Level3_Shift) || state == XKeysymToKeycode(display, XK_Super_L) || state == XKeysymToKeycode(display, XK_Super_R))
{
hasPreKey = TRUE;
config->button1 = state;
const char *key_str = keycode_to_string(display, state);
const char *plus = " + ";
char *text = malloc(strlen(key_str) + strlen(plus));
sprintf(text, "%s%s", key_str, plus);

struct set_buttons_entry_struct *user_data = g_malloc0(sizeof(struct set_buttons_entry_struct));
user_data->text = text;
g_idle_add_once(set_buttons_entry_text, user_data);
user_data->text = text;
g_idle_add(set_buttons_entry_text, user_data);
}
else
else
{
config->button2 = state;
const char *key_str = keycode_to_string(display, state);
struct set_buttons_entry_struct *user_data = g_malloc0(sizeof(struct set_buttons_entry_struct));


if (hasPreKey == TRUE)
{
Expand All @@ -96,21 +95,21 @@ void get_hotkeys_handler()
sprintf(text, "%s%s", buttons_entry_text, key_str);
user_data->text = text;
}
else
else
{
config->button1 = -1;
char *text = (char *)malloc(1 + strlen(key_str));
strcpy(text, key_str);
user_data->text = text;
}
// Text is freed in the set_buttons_entry_text function
g_idle_add_once(set_buttons_entry_text, user_data);
g_idle_add(set_buttons_entry_text, user_data);
break;
}
}
XCloseDisplay(display);
g_idle_add_once(enable_start_button, NULL);
g_idle_add_once(hotkey_finished, NULL);
g_idle_add(enable_start_button, NULL);
g_idle_add(hotkey_finished, NULL);

g_key_file_set_integer(config_gfile, CFGK_BUTTON_1, config->button1);
g_key_file_set_integer(config_gfile, CFGK_BUTTON_2, config->button2);
Expand All @@ -119,7 +118,6 @@ void get_hotkeys_handler()
isChoosingHotkey = FALSE;
}


void safe_mode_changed(GtkSwitch *self, gboolean state)
{
g_key_file_set_boolean(config_gfile, CFGK_SAFEMODE, state);
Expand Down Expand Up @@ -152,7 +150,6 @@ void reset_preset_button_pressed()
g_key_file_remove_group(config_gfile, PRESET_CATEGORY_OPTIONS, NULL);
g_key_file_remove_group(config_gfile, PRESET_CATEGORY_MORE_OPTIONS, NULL);


save_and_populate_config();
mainappwindow_import_config();
}
Expand All @@ -163,14 +160,14 @@ void settings_dialog_new()
GtkDialog *dialog = GTK_DIALOG(gtk_builder_get_object(builder, "dialog"));

config_read_from_file();

set_window_icon(dialog);

gtk_builder_add_callback_symbol(builder, "safe_mode_changed", safe_mode_changed);
gtk_builder_add_callback_symbol(builder, "xevent_switch_changed", xevent_switch_changed);
gtk_builder_add_callback_symbol(builder, "start_button_pressed", start_button_pressed);
gtk_builder_add_callback_symbol(builder, "reset_preset_button_pressed", reset_preset_button_pressed);

gtk_builder_connect_signals(builder, NULL);

// Load version
Expand Down

1 comment on commit e37c609

@Abasrasoli915
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

****bitcoin bitcoincash eteruom usdt usdc

Please sign in to comment.