From 441dae4a44f60665c9f669a80304b688285c9c22 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Thu, 27 May 2010 02:20:29 +0200 Subject: Split init function of methods and providers into init and start. The set_option function can be called to set options between init and start. --- src/gamma-vidmode.c | 60 +++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'src/gamma-vidmode.c') diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c index e8f6d63..970c45d 100644 --- a/src/gamma-vidmode.c +++ b/src/gamma-vidmode.c @@ -37,36 +37,10 @@ int -vidmode_init(vidmode_state_t *state, char *args) +vidmode_init(vidmode_state_t *state) { - int screen_num = -1; - - /* Parse arguments. */ - while (args != NULL) { - char *next_arg = strchr(args, ':'); - if (next_arg != NULL) *(next_arg++) = '\0'; - - char *value = strchr(args, '='); - if (value != NULL) *(value++) = '\0'; - - if (strcasecmp(args, "screen") == 0) { - if (value == NULL) { - fprintf(stderr, _("Missing value for" - " parameter: `%s'.\n"), - args); - return -1; - } - screen_num = atoi(value); - } else { - fprintf(stderr, _("Unknown method parameter: `%s'.\n"), - args); - return -1; - } - - args = next_arg; - } - - int r; + state->screen_num = -1; + state->saved_ramps = NULL; /* Open display */ state->display = XOpenDisplay(NULL); @@ -76,6 +50,15 @@ vidmode_init(vidmode_state_t *state, char *args) return -1; } + return 0; +} + +int +vidmode_start(vidmode_state_t *state) +{ + int r; + int screen_num = state->screen_num; + if (screen_num < 0) screen_num = DefaultScreen(state->display); state->screen_num = screen_num; @@ -152,6 +135,25 @@ vidmode_print_help(FILE *f) fputs("\n", f); } +int +vidmode_set_option(vidmode_state_t *state, const char *key, const char *value) +{ + if (key == NULL) { + fprintf(stderr, _("Missing value for parameter: `%s'.\n"), + key); + return -1; + } + + if (strcasecmp(key, "screen") == 0) { + state->screen_num = atoi(value); + } else { + fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); + return -1; + } + + return 0; +} + void vidmode_restore(vidmode_state_t *state) { -- cgit v1.2.3-70-g09d2