示例#1
0
/**
 * 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);
	}

	// set the current window to NULL, we don't need to be able to modify
	// the windows when reading the config
	set_current_window(NULL);

	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;
}
示例#2
0
void runlogic()
{
    NSDL2_RUNLOGIC(NULL, NULL, "Executing init_script()");

    init_script();

    NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Parent");
    {

        NSDL2_RUNLOGIC(NULL, NULL, "Executing dowhile block - DoWhileBlock. NS Variable = var_dowhile");
        {

            NSDL2_RUNLOGIC(NULL, NULL, "NS Variable value for block - DoWhileBlock = %d", ns_get_int_val("var_dowhile"));
            do
            {

                NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq1");
                {

                    NSDL2_RUNLOGIC(NULL, NULL, "Executing weight block - Weight");
                    {
                        //int Weightweight = ns_get_random_number_int(1, 100);
                        int Weightweight = ns_get_random_number_int(1, weight);

                        NSDL2_RUNLOGIC(NULL, NULL, "Percentage random number for block - Weight = %d", Weightweight);

                        //if(Weightweight <= 100)
                        if(Weightweight <= weight)
                        {

                            NSDL2_RUNLOGIC(NULL, NULL, "Executing percent block - Percentage (wt value = 100)");
                            {
                                //int Percentagepercent = ns_get_random_number_int(1, 100);
                                int Percentagepercent = ns_get_random_number_int(1, per1+per2);

                                NSDL2_RUNLOGIC(NULL, NULL, "Percentage random number for block - Percentage = %d", Percentagepercent);

                                //if(Percentagepercent <= 50)
                                if(Percentagepercent <= per1)
                                {
                                    NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - LoginLogout (pct value = 50%)");
                                    LoginLogout();
                                }
                                //else if(Percentagepercent <= 100)
                                else if(Percentagepercent <= per1+per2)
                                {

                                    NSDL2_RUNLOGIC(NULL, NULL, "Executing count block - Count. Min = 1, Max = 1 (pct value = 50%)");
                                    {
                                        //int CountCount = ns_get_random_number_int(1, 1);
                                        int CountCount = ns_get_random_number_int(min, max);
                                        int CountLoop;
                                         for(CountLoop = 1; CountLoop <= CountCount; CountLoop++)
                                        {

                                            NSDL2_RUNLOGIC(NULL, NULL, "Executing while block - while. NS Variable = var_while (pct value = 50%), SelectedCount = %d, Iteration = %d",CountCount, CountLoop);
                                            {

                                                NSDL2_RUNLOGIC(NULL, NULL, "NS Variable value for block - while = %d", ns_get_int_val("var_while"));
                                                while(ns_get_int_val("var_while"))
                                                {

                                                    NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - SeqW (pct value = 50%), SelectedCount = %d, Iteration = %d",CountCount, CountLoop);
                                                    {

                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing switch block - Switch. NS Variable = var_switch (pct value = 50%), SelectedCount = %d, Iteration = %d",CountCount, CountLoop);
                                                        {

                                                            NSDL2_RUNLOGIC(NULL, NULL, "NS Variable value for block - Switch = %d", ns_get_int_val("var_switch"));
                                                            switch(ns_get_int_val("var_switch"))
                                                            {
                                                                case 0:

                                                                    NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq2 (case value = 0), SelectedCount = %d, Iteration = %d",CountCount, CountLoop);
                                                                    {
                                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - Passenger");
                                                                        Passenger();
                                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowSwitch");
                                                                        FlowSwitch();
                                                                    }
                                                                    break;
                                                                case 1:

                                                                    NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq3 (case value = 1)");
                                                                    {
                                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - Reservation");
                                                                        Reservation();
                                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowSwitch");
                                                                        FlowSwitch();
                                                                    }
                                                                    break;
                                                                case 2:

                                                                    NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq4 (case value = 2)");
                                                                    {
                                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - LoginLogout");
                                                                        LoginLogout();
                                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowSwitch");
                                                                        FlowSwitch();
                                                                    }
                                                                    break;
                                                                default:

                                                                    NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq5 (case value = -1)");
                                                                    {
                                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - Tours");
                                                                        Tours();
                                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowSwitch");
                                                                        FlowSwitch();
                                                                    }
                                                                    break;
                                                            }
                                                        }
                                                        NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowWhile");
                                                        FlowWhile();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowDoWhile");
                    FlowDoWhile();
                }
            } while(ns_get_int_val("var_dowhile"));
        }
    }

    NSDL2_RUNLOGIC(NULL, NULL, "Executing ns_exit_session()");
    ns_exit_session();
}