Example #1
0
int main(int argc, char** argv) {
	const char* config_file = NULL;
	bool test_mode = false;
	bool daemon_mode = false;

	if(argc > 1) {
		const char* a;
		for(int i = 1; i < argc; i++) {
			a = argv[i];
			if(CHECK_ARGV(a, "-h", "--help")) {
				help();
				return 0;
			} else if(CHECK_ARGV(a, "-c", "--config")) {
				config_file = next_param(i, argv, argc);
				if(!config_file) {
					puts("Missing configuration filename");
					return 1;
				}
				i++;
			} else if(CHECK_ARGV(a, "-d", "--daemon")) {
				daemon_mode = true;
			} else if(CHECK_ARGV(a, "-t", "--test")) {
				test_mode = true;
			} else {
				printf("Unknown parameter '%s'. Run 'elma -h' for options\n", a);
				return 1;
			}
		}
	}

	ElmaService* service = ElmaService::instance();

	if(!service->load_config()) {
		puts("Unable to load config file");
		return 1;
	}

	if(!service->load_theme()) {
		puts("Unable to load theme file");
		return 1;
	}

	service->display_window();

	return 0;
}
Example #2
0
int main(int argc, char** argv) {
	const char* config_file = NULL;
	const char* pid_file    = NULL;
	const char* log_file    = NULL;

	bool do_startup     = false;
	bool do_foreground  = false;

	if(argc > 1) {
		const char* a;
		for(int i = 1; i < argc; i++) {
			a = argv[i];
			if(CHECK_ARGV(a, "-h", "--help")) {
				help();
				return 0;
			} else if(CHECK_ARGV(a, "-c", "--config")) {
				config_file = next_param(i, argv, argc);
				if(!config_file) {
					puts("Missing configuration filename");
					return 1;
				}
				i++;
			} else if(CHECK_ARGV(a, "-p", "--pid")) {
				pid_file = next_param(i, argv, argc);
				if(!pid_file) {
					puts("Missing pid filename");
					return 1;
				}
				i++;
			} else if(CHECK_ARGV(a, "-l", "--log")) {
				log_file = next_param(i, argv, argc);
				if(!log_file) {
					puts("Missing log filename");
					return 1;
				}
				i++;
			} 
			else if(CHECK_ARGV(a, "-s", "--startup"))
				do_startup = true;
			else if(CHECK_ARGV(a, "-f", "--foreground"))
				do_foreground = true;
			else {
				printf("Unknown parameter '%s'. Run '"APPNAME" -h' for options\n", a);
				return 1;
			}
		}
	}
	
	// make sure X11 is running before fork
	fl_open_display();

	// start service
	if(!do_foreground) {
		int x;
		if((x = fork()) > 0)
			exit(0);
		else if(x == -1) {
			printf("Fatal: fork failed !\n");
			return 1;
		}
	}

	EvokeService* service = EvokeService::instance();

	if(!service->setup_logging(log_file)) {
		printf("Can't open %s for logging. Please choose some writeable place\n", log_file);
		return 1;
	}

	EVOKE_LOG("= "APPNAME" started =\n");

	if(!pid_file)
		pid_file = DEFAULT_PID;

	if(!service->setup_pid(pid_file)) {
		EVOKE_LOG("Either another "APPNAME" instance is running or can't create pid file. Please correct this\n");
		EVOKE_LOG("= "APPNAME" abrupted shutdown =\n");
		return 1;
	}

	if(!config_file)
		config_file = CONFIG_FILE; // TODO: XDG paths

	if(!service->setup_config(config_file, do_startup)) {
		EVOKE_LOG("Unable to read correctly %s. Please check it is correct config file\n");
		EVOKE_LOG("= "APPNAME" abrupted shutdown =\n");
		return 1;
	}

	service->setup_atoms(fl_display);

	signal(SIGINT, quit_signal);
	signal(SIGTERM, quit_signal);
	signal(SIGKILL, quit_signal);

	running = true;

	XSelectInput(fl_display, RootWindow(fl_display, fl_screen), PropertyChangeMask | StructureNotifyMask | ClientMessage);

	/*
	 * Register event listener and run in infinite loop. Loop will be
	 * interrupted from one of the received signals.
	 *
	 * I choose to use fltk for this since wait() will nicely pool events
	 * and pass expecting ones to xmessage_handler(). Other (non-fltk) solution would
	 * be to manually pool events via select() and that code could be very messy.
	 * So stick with the simplicity :)
	 */
	Fl::add_handler(xmessage_handler);
	while(running)
		Fl::wait(FOREVER);

	EVOKE_LOG("= "APPNAME" nice shutdown =\n");
	return 0;
}
Example #3
0
int main(int argc, char** argv) {
	bool do_startup         = false;
	bool do_dryrun          = false;
	bool show_splash        = true;

	if(argc > 1) {
		const char* a;
		for(int i = 1; i < argc; i++) {
			a = argv[i];
			if(CHECK_ARGV(a, "-h", "--help")) {
				help();
				return 0;
			}
			else if(CHECK_ARGV(a, "-s", "--startup"))
				do_startup = true;
			else if(CHECK_ARGV(a, "-d", "--dry-run"))
				do_dryrun = true;
			else if(CHECK_ARGV(a, "-n", "--no-splash"))
				show_splash = false;
			else {
				printf("Unknown parameter '%s'. Run 'evoke -h' for options\n", a);
				return 1;
			}
		}
	}

	EDE_APPLICATION("evoke");

	/* make sure X11 is running before rest of code is called */
	fl_open_display();

	/* initialize main service object */
	EvokeService* service = EvokeService::instance();

	/*
	 * Main loop is not initialized before startup (and splash) are finished;
	 * this is intentional so we could use 'dryrun' to test a splash theme and startup items
	 * without interfering with already running evoke instance (and getting lock error)
	 *
	 * TODO: dryrun option is pretty dummy; better to use "test-splash" or similar
	 */
	if(do_startup) {
		service->read_startup();
		service->run_startup(show_splash, do_dryrun);
	}

	/* only testing, quit nicely */
	if(do_dryrun)
		return 0;

	if(!service->setup_lock(LOCK_FILE)) {
		printf("*** Either another evoke instance is running or I can't create lock file.\n");
		printf("*** If program abnormaly crashed before, just remove '%s' and start it again.\n", LOCK_FILE);
		return 1;
	}

	signal(SIGINT,  quit_signal);
	signal(SIGTERM, quit_signal);
	signal(SIGKILL, quit_signal);
	signal(SIGQUIT, quit_signal);

#ifdef USE_SIGHUP
	/*
	 * This is mostly used when we get request to shutdown session and close/kill all windows.
	 * If evoke is started from gui console (xterm, rxvt), closing that window we will get 
	 * SIGHUP since terminal will disconnect all controlling processes. On other hand, if evoke
	 * is started as session carrier (eg. run from xinitrc), this is not needed.
	 */
	signal(SIGHUP,  quit_signal);
#endif

	service->start_xsettings_manager();

	/* set stuff so xsettings manager can receive events */
	XSelectInput(fl_display, RootWindow(fl_display, fl_screen), 
			PropertyChangeMask | SubstructureNotifyMask | ClientMessage);
	Fl::add_handler(xmessage_handler);

	/* run applicator for settings; it must be done after manager is fully on */
	if(do_startup)
		run_async("ede-settings-apply");

	service->start();

	while(service->running()) {
		/*
		 * FLTK will not report SelectionClear needed for XSETTINGS manager
		 * so we must catch it first before FLTK discards it (if we can :P)
		 * This can be missed greatly due a large number of XDamage events
		 * and using this method is not quite safe.
		 */
		if(fl_xevent && fl_xevent->type == SelectionClear)
			service->handle(fl_xevent);

		Fl::wait(FOREVER);
	}

	return 0;
}
Example #4
0
int main(int argc, char **argv) {
    const char *title, *txt;
    int         opt = OPT_NONE;
    int         ret = EDE_DIALOG_ERROR_RET;
    int         nbuttons = 0;

    MessageBoxType     mtype = MSGBOX_PLAIN;
    MessageBoxIconType itype = MSGBOX_ICON_TYPE_INFO;

    title = txt = NULL;

    if(argc <= 1) {
        help();
        return EDE_DIALOG_ERROR_RET;
    }

    for(int i = 1; i < argc; i++) {
        if(CHECK_ARGV(argv[i], "-h", "--help")) {
            help();
            return EDE_DIALOG_ERROR_RET;
        }

        /* optional flags */
        if(CHECK_ARGV_LONG(argv[i], "--title")) {
            title = next_param(i, argv, argc);
            if(!title) {
                puts("'title' option requires a parameter");
                return EDE_DIALOG_ERROR_RET;
            }

            i++;
            continue;
        }

        /* mandatory flags */
        if(CHECK_ARGV_LONG(argv[i], "--yesno")) {
            itype = MSGBOX_ICON_TYPE_QUESTION;
            opt = OPT_YESNO;
        } else if(CHECK_ARGV_LONG(argv[i], "--yesnocancel")) {
            itype = MSGBOX_ICON_TYPE_QUESTION;
            opt = OPT_YESNOCANCEL;
        } else if(CHECK_ARGV_LONG(argv[i], "--error")) {
            itype = MSGBOX_ICON_TYPE_ALERT;
            opt = OPT_ERROR;
        } else if(CHECK_ARGV_LONG(argv[i], "--sorry")) {
            itype = MSGBOX_ICON_TYPE_ALERT;
            opt = OPT_SORRY;
        } else if(CHECK_ARGV_LONG(argv[i], "--msgbox")) {
            opt = OPT_MSGBOX;
            /* for else do nothing; use default values */
        } else if(CHECK_ARGV_LONG(argv[i], "--inputbox")) {
            itype = MSGBOX_ICON_TYPE_INPUT;
            mtype = MSGBOX_INPUT;
            opt   = OPT_INPUTBOX;
        } else if(CHECK_ARGV_LONG(argv[i], "--password")) {
            itype = MSGBOX_ICON_TYPE_PASSWORD;
            mtype = MSGBOX_INPUT_SECRET;
            opt   = OPT_PASSWORD;
        } else {
            printf("Unknown '%s' parameter\n", argv[i]);
            return EDE_DIALOG_ERROR_RET;
        }

        /* every above option requres additional parameter */
        txt = next_param(i, argv, argc);
        if(!txt) {
            printf("'%s' option requires a parameter\n", argv[i]);
            return EDE_DIALOG_ERROR_RET;
        }

        /* skip parameter */
        i++;
    }

    if(opt == OPT_NONE) {
        puts("Missing one of the flags that will describe the dialog. Run program with '--help' for the details");
        return EDE_DIALOG_ERROR_RET;
    }

    EDE_APPLICATION("ede-dialog");

    /*
     * Use a trick to load icon theme and colors using xsettings stuff. edelib::Window will load them
     * and fill static FLTK values; every further window will use those values, including our will use them
     *
     * TODO: this hack needs appropriate solution in edelib.
     */
    EdelibWindow *win = new EdelibWindow(-100, -100, 0, 0);
    win->show();
    Fl::wait(0.2);
    win->hide();

    mbox = new MessageBox(mtype);
    mbox->set_icon_from_type(itype);
    mbox->set_text(txt);
    mbox->label(title);

    /* determine buttons */
    switch(opt) {
    case OPT_YESNO:
        mbox->add_button(_("&No"));
        mbox->add_button(_("&Yes"));
        nbuttons = 2;
        break;
    case OPT_YESNOCANCEL:
        mbox->add_button(_("&Cancel"));
        mbox->add_button(_("&No"));
        mbox->add_button(_("&Yes"));
        nbuttons = 3;
        break;
    case OPT_ERROR:
    case OPT_MSGBOX:
    case OPT_SORRY:
        mbox->add_button(_("&Close"));
        nbuttons = 1;
        break;
    case OPT_INPUTBOX:
    case OPT_PASSWORD:
        mbox->add_button(_("&Cancel"));
        mbox->add_button(_("&OK"));
        nbuttons = 2;
        break;
    }

    ret = mbox->run();

    /* check box type and 'Cancel' wasn't present */
    if((opt == OPT_INPUTBOX || opt == OPT_PASSWORD) && ret != 0)
        printf("%s\n", mbox->get_input());

    /*
     * Now emulate kdialog return values; e.g. 'OK' will be 0 and 'Cancel' will be 1 if two buttons
     * are exists. Because MessageBox already do this in reversed way, here value is just re-reversed again if
     * we have more that one button.
     */
    if(nbuttons > 1) {
        /* xor-ing with 2 is different so button number can't be decreased */
        if(nbuttons == 3) {
            ret ^= nbuttons;
            ret -= 1;
        } else {
            ret ^= (nbuttons - 1);
        }
    }

    return ret;
}