void folder_changed_callback(GFileMonitor *mon, GFile *first_file, GFile *second_file, GFileMonitorEvent event, gpointer user_data) { gchar *our_filename = (gchar*)(user_data); // If a file is created or deleted, we need to check the file lists again if ((event == G_FILE_MONITOR_EVENT_CREATED) || (event == G_FILE_MONITOR_EVENT_DELETED)) { clear_file_lists(); set_current_window(NULL); load_config(our_filename); if (debug) printf("Files in folder updated!\n - new lists:\n\n"); print_script_lists(); if (debug) printf("-----------\n"); } // Also monitor if our devilspie2.lua file is changed - since it handles // which files are window close or window open scripts. if (event == G_FILE_MONITOR_EVENT_CHANGED) { if (first_file) { gchar *short_filename = g_file_get_basename(first_file); if (g_strcmp0(short_filename, "devilspie2.lua")==0) { clear_file_lists(); set_current_window(NULL); load_config(our_filename); print_script_lists(); if (debug) printf("----------"); } } } }
/** * Program main entry */ int main(int argc, char *argv[]) { static const GOptionEntry options[]={ { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, N_("Print debug info to stdout")}, { "emulate", 'e', 0, G_OPTION_ARG_NONE, &emulate, N_("Don't apply any rules, only emulate execution")}, { "folder", 'f', 0, G_OPTION_ARG_STRING, &script_folder, N_("Search for scripts in this folder"),N_("FOLDER")}, { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("Show Devilspie2 version and quit")}, #ifdef HAVE_GTK3 // libwnck Version Information is only availible if you have // libwnck 3.0 or later { "wnck-version", 'w', 0, G_OPTION_ARG_NONE, &show_wnck_version, N_("Show libwnck version and quit")}, #endif { NULL } }; GError *error = NULL; GOptionContext *context; // Init gettext stuff setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, ""); textdomain(PACKAGE); gdk_init(&argc, &argv); gchar *devilspie2_description = g_strdup_printf(_("apply rules on windows")); gchar *full_desc_string = g_strdup_printf("- %s", devilspie2_description); context=g_option_context_new(full_desc_string); g_option_context_add_main_entries(context,options,NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_print(_("option parsing failed: %s"), error->message); printf("\n"); exit(EXIT_FAILURE); } g_free(full_desc_string); g_free(devilspie2_description); // if the folder is NULL, default to ~/.config/devilspie2/ if (script_folder == NULL) { temp_folder = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), "devilspie2", NULL); // check if the folder does exist if (!g_file_test(temp_folder, G_FILE_TEST_IS_DIR)) { // - and if it doesn't, create it. if (g_mkdir(temp_folder, 0700) != 0) { printf("%s", _("Couldn't create the default folder for devilspie2 scripts.")); printf("\n"); exit(EXIT_FAILURE); } } script_folder = temp_folder; } if (show_version) { printf("Devilspie2 v%s\n\n", DEVILSPIE2_VERSION); exit(EXIT_SUCCESS); } #ifdef HAVE_GTK3 // libwnck Version Information is only availible if you have // libwnck 3.0 or later if (show_wnck_version) { printf("libwnck v%d.%d.%d\n\n", WNCK_MAJOR_VERSION, WNCK_MINOR_VERSION, WNCK_MICRO_VERSION); exit(EXIT_SUCCESS); } #endif #if (GTK_MAJOR_VERSION >= 3) if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { printf("%s", _("An X11 display is required for devilspie2.")); printf("\n\n"); return EXIT_FAILURE; } #endif if (init_script_error_messages()!=0) { printf("%s", _("Couldn't init script error messages!")); printf("\n"); exit(EXIT_FAILURE); } config_filename = g_build_filename(script_folder, "devilspie2.lua", NULL); if (load_config(config_filename)!=0) { devilspie_exit(); return EXIT_FAILURE; } if (debug) { if (emulate) { printf("%s", _("Running devilspie2 in debug and emulate mode.")); } else { printf("%s", _("Running devilspie2 in debug mode.")); } printf("\n\n"); printf(_("Using scripts from folder: %s"), script_folder); printf("\n"); devilspie2_debug = TRUE; } // Should we only run an emulation (don't modify any windows) if (emulate) devilspie2_emulate = emulate; GFile *directory_file; directory_file = g_file_new_for_path(script_folder); // mon = g_file_monitor_directory(directory_file, G_FILE_MONITOR_WATCH_MOUNTS, mon = g_file_monitor_directory(directory_file, G_FILE_MONITOR_NONE, NULL, NULL); if (!mon) { printf("%s", _("Couldn't create directory monitor!")); printf("\n"); return EXIT_FAILURE; } g_signal_connect(mon, "changed", G_CALLBACK(folder_changed_callback), (gpointer)(config_filename)); global_lua_state = init_script(); print_script_lists(); if (debug) printf("------------\n"); // remove stuff cleanly atexit(devilspie_exit); struct sigaction signal_action; sigemptyset(&signal_action.sa_mask); signal_action.sa_flags = 0; signal_action.sa_handler = signal_handler; if (sigaction(SIGINT, &signal_action, NULL) == -1) { exit(EXIT_FAILURE); } init_screens(); loop=g_main_loop_new(NULL, TRUE); g_main_loop_run(loop); return EXIT_SUCCESS; }