diff --git a/src/mainwin.c b/src/mainwin.c index 9693fb9..e153a4c 100644 --- a/src/mainwin.c +++ b/src/mainwin.c @@ -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; } /** @@ -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); } /** @@ -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)) @@ -205,6 +206,8 @@ void set_coords(gpointer *data) gtk_entry_set_text(mainappwindow.y_entry, args->coordy); g_free(args); + + return FALSE; } /** @@ -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) { @@ -245,6 +248,7 @@ void toggle_get_active() gtk_widget_set_sensitive(mainappwindow.get_button, TRUE); break; } + return FALSE; } /** @@ -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); } /** @@ -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; } /** @@ -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; } diff --git a/src/settings.c b/src/settings.c index c4996a8..ca51c0c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -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; } /** @@ -65,11 +69,7 @@ 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; @@ -77,17 +77,16 @@ void get_hotkeys_handler() 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) { @@ -96,7 +95,7 @@ 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)); @@ -104,13 +103,13 @@ void get_hotkeys_handler() 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); @@ -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); @@ -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(); } @@ -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