static char *
config_get_theme (gboolean *is_writable)
{
	GSettings *settings;
	char        *name;
	int          mode;

	settings = g_settings_new (GSETTINGS_SCHEMA);

	if (is_writable)
	{
		gboolean can_write_theme;
		gboolean can_write_mode;

		can_write_theme = g_settings_is_writable (settings,
		                                          KEY_THEMES);
		can_write_mode = g_settings_is_writable (settings,
		                                         KEY_MODE);
		*is_writable = can_write_theme && can_write_mode;
	}

	mode = config_get_mode (NULL);

	name = NULL;
	if (mode == GS_MODE_BLANK_ONLY)
	{
		name = g_strdup ("__blank-only");
	}
	else if (mode == GS_MODE_RANDOM)
	{
		name = g_strdup ("__random");
	}
	else
	{
		 gchar **strv;
                 strv = g_settings_get_strv (settings,
                                             KEY_THEMES);
                 if (strv != NULL) {
                          name = g_strdup (strv[0]);
		}
		else
		{
			/* TODO: handle error */
			/* default to blank */
			name = g_strdup ("__blank-only");
		}

		g_strfreev (strv);
	}

	g_object_unref (settings);

	return name;
}
Beispiel #2
0
/* Mode initialization.  Reads configuration, checks if the kernel has
 * support for mouse pointer and opens required files. */
int
selection_startup(struct mouse *m)
{
	int i;
	struct wsdisplay_char ch;
	struct block *conf;

	if (Initialized) {
		log_warnx("selection mode already initialized");
		return 1;
	}

	(void)memset(&Selmouse, 0, sizeof(struct selmouse));
	Selmouse.sm_mouse = m;

	conf = config_get_mode("selection");
	Selmouse.sm_slowdown_x = block_get_propval_int(conf, "slowdown_x", 0);
	Selmouse.sm_slowdown_y = block_get_propval_int(conf, "slowdown_y", 3);
	if (block_get_propval_int(conf, "lefthanded", 0)) {
		Selmouse.sm_but_select = 2;
		Selmouse.sm_but_paste = 0;
	} else {
		Selmouse.sm_but_select = 0;
		Selmouse.sm_but_paste = 2;
	}

	/* Open current tty */
	(void)ioctl(Selmouse.sm_mouse->m_statfd, WSDISPLAYIO_GETACTIVESCREEN,
	    &i);
	Selmouse.sm_ttyfd = -1;
	open_tty(i);

	/* Check if the kernel has character functions */
	ch.row = ch.col = 0;
	if (ioctl(Selmouse.sm_ttyfd, WSDISPLAYIO_GETWSCHAR, &ch) < 0) {
		(void)close(Selmouse.sm_ttyfd);
		log_warn("ioctl(WSDISPLAYIO_GETWSCHAR) failed");
		return 0;
	}

	assert(Selmouse.sm_max_y != 0); /* Initialized by open_tty above. */
	assert(Selmouse.sm_max_x != 0); /* Initialized by open_tty above. */
	Selmouse.sm_y = Selmouse.sm_max_y / 2;
	Selmouse.sm_x = Selmouse.sm_max_x / 2;
	Selmouse.sm_count_y = 0;
	Selmouse.sm_count_x = 0;
	Selmouse.sm_visible = 0;
	Selmouse.sm_selecting = 0;
	Initialized = 1;

	return 1;
}
Beispiel #3
0
/* Executes a command.  `button' specifies the number of the button that
 * was pressed or released.  `ud' contains the word `up' or `down', which
 * specify the type of event received. */
static void
run_action(int button, const char *ud)
{
	char buf[20];
	const char *cmd;
	struct block *conf;

	(void)snprintf(buf, sizeof(buf), "button_%d_%s", button, ud);

	conf = config_get_mode("action");
	cmd = block_get_propval(conf, buf, NULL);
	if (cmd != NULL) {
		log_info("running command `%s'", cmd);
		system(cmd);
	}
}
Beispiel #4
0
/* Main program.  Parses command line options, reads the configuration
 * file, initializes the mouse and associated files and launches the main
 * event loop. */
int
main(int argc, char **argv)
{
	char *conffile, *modelist, *tstat;
	int needconf, nodaemon, opt;
	struct block *conf;

	setprogname(argv[0]);

	(void)memset(&Mouse, 0, sizeof(struct mouse));
	conffile = _PATH_CONF;
	modelist = NULL;
	needconf = 0;
	nodaemon = -1;

	/* Parse command line options */
	while ((opt = getopt(argc, argv, "Dd:f:m:n")) != -1) {
		switch (opt) {
		case 'D':
			debug++;
			break;
		case 'd': /* Mouse device name */
			Mouse.m_devname = optarg;
			break;
		case 'f': /* Configuration file name */
			needconf = 1;
			conffile = optarg;
			break;
		case 'm': /* List of modes to activate */
			modelist = optarg;
			break;
		case 'n': /* No daemon */
			nodaemon = 1;
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	}

	/* Read the configuration file and get some basic properties */
	config_read(conffile, needconf);
	conf = config_get_mode("Global");
	if (nodaemon == -1)
		nodaemon = block_get_propval_int(conf, "nodaemon", 0);
	X_Console = block_get_propval_int(conf, "xconsole", -1);
	X_Console_Delay = block_get_propval_int(conf, "xconsole_delay",
	    X_Console_Delay);

	/* Open wsdisplay status device */
	tstat = block_get_propval(conf, "ttystat", _PATH_TTYSTAT);
	Mouse.m_statfd = open(tstat, O_RDONLY | O_NONBLOCK, 0);
	if (Mouse.m_statfd == -1)
		log_err(EXIT_FAILURE, "cannot open %s", tstat);

	/* Initialize mouse information and attach modes */
	if (Mouse.m_devname == NULL)
		Mouse.m_devname = block_get_propval(conf, "device",
		    _PATH_DEFAULT_MOUSE);
	Mouse.m_fifoname = block_get_propval(conf, "fifo", NULL);
	init_mouse();
	if (modelist != NULL)
		attach_modes(modelist);
	else
		attach_modes(block_get_propval(conf, "modes", "selection"));

	/* Setup signal handlers */
	(void)signal(SIGINT,  signal_terminate);
	(void)signal(SIGKILL, signal_terminate);
	(void)signal(SIGQUIT, signal_terminate);
	(void)signal(SIGTERM, signal_terminate);

	if (!nodaemon) {
		/* Become a daemon */
		if (daemon(0, 0) == -1)
			log_err(EXIT_FAILURE, "failed to become a daemon");

		/* Create the pidfile, if wanted */
		Pid_File = block_get_propval(conf, "pidfile", NULL);
		if (pidfile(Pid_File) == -1)
			log_warn("pidfile %s", Pid_File);

		Foreground = 0;
	}

	event_loop();

	/* NOTREACHED */
	return EXIT_SUCCESS;
}