diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2017-10-11 20:04:29 -0700 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2017-10-13 17:53:58 -0700 |
commit | 6531b8c73d1eb069e39804167c42948f5f6cd412 (patch) | |
tree | cc23f5d236d03473647233a9971765d3888f8f2d /src | |
parent | Merge pull request #536 from jonls/gtk-help-args (diff) | |
download | redshift-ng-6531b8c73d1eb069e39804167c42948f5f6cd412.tar.gz redshift-ng-6531b8c73d1eb069e39804167c42948f5f6cd412.tar.bz2 redshift-ng-6531b8c73d1eb069e39804167c42948f5f6cd412.tar.xz |
Move module struct definitions to separate files
Diffstat (limited to 'src')
-rw-r--r-- | src/gamma-drm.c | 26 | ||||
-rw-r--r-- | src/gamma-drm.h | 12 | ||||
-rw-r--r-- | src/gamma-dummy.c | 28 | ||||
-rw-r--r-- | src/gamma-dummy.h | 13 | ||||
-rw-r--r-- | src/gamma-quartz.c | 28 | ||||
-rw-r--r-- | src/gamma-quartz.h | 15 | ||||
-rw-r--r-- | src/gamma-randr.c | 28 | ||||
-rw-r--r-- | src/gamma-randr.h | 11 | ||||
-rw-r--r-- | src/gamma-vidmode.c | 28 | ||||
-rw-r--r-- | src/gamma-vidmode.h | 14 | ||||
-rw-r--r-- | src/gamma-w32gdi.c | 28 | ||||
-rw-r--r-- | src/gamma-w32gdi.h | 14 | ||||
-rw-r--r-- | src/location-corelocation.h | 15 | ||||
-rw-r--r-- | src/location-corelocation.m | 27 | ||||
-rw-r--r-- | src/location-geoclue2.c | 28 | ||||
-rw-r--r-- | src/location-geoclue2.h | 12 | ||||
-rw-r--r-- | src/location-manual.c | 26 | ||||
-rw-r--r-- | src/location-manual.h | 12 | ||||
-rw-r--r-- | src/redshift.c | 177 |
19 files changed, 237 insertions, 305 deletions
diff --git a/src/gamma-drm.c b/src/gamma-drm.c index c2ac4bd..19f66fd 100644 --- a/src/gamma-drm.c +++ b/src/gamma-drm.c @@ -41,7 +41,7 @@ #include "colorramp.h" -int +static int drm_init(drm_state_t *state) { /* Initialize state. */ @@ -54,7 +54,7 @@ drm_init(drm_state_t *state) return 0; } -int +static int drm_start(drm_state_t *state) { /* Acquire access to a graphics card. */ @@ -172,7 +172,7 @@ drm_start(drm_state_t *state) return 0; } -void +static void drm_restore(drm_state_t *state) { drm_crtc_state_t *crtcs = state->crtcs; @@ -185,7 +185,7 @@ drm_restore(drm_state_t *state) } } -void +static void drm_free(drm_state_t *state) { if (state->crtcs != NULL) { @@ -208,7 +208,7 @@ drm_free(drm_state_t *state) } } -void +static void drm_print_help(FILE *f) { fputs(_("Adjust gamma ramps with Direct Rendering Manager.\n"), f); @@ -221,7 +221,7 @@ drm_print_help(FILE *f) fputs("\n", f); } -int +static int drm_set_option(drm_state_t *state, const char *key, const char *value) { if (strcasecmp(key, "card") == 0) { @@ -240,7 +240,7 @@ drm_set_option(drm_state_t *state, const char *key, const char *value) return 0; } -int +static int drm_set_temperature(drm_state_t *state, const color_setting_t *setting) { drm_crtc_state_t *crtcs = state->crtcs; @@ -288,3 +288,15 @@ drm_set_temperature(drm_state_t *state, const color_setting_t *setting) return 0; } + + +const gamma_method_t drm_gamma_method = { + "drm", 0, + (gamma_method_init_func *)drm_init, + (gamma_method_start_func *)drm_start, + (gamma_method_free_func *)drm_free, + (gamma_method_print_help_func *)drm_print_help, + (gamma_method_set_option_func *)drm_set_option, + (gamma_method_restore_func *)drm_restore, + (gamma_method_set_temperature_func *)drm_set_temperature +}; diff --git a/src/gamma-drm.h b/src/gamma-drm.h index ae97d00..6f63413 100644 --- a/src/gamma-drm.h +++ b/src/gamma-drm.h @@ -46,16 +46,6 @@ typedef struct { } drm_state_t; -int drm_init(drm_state_t *state); -int drm_start(drm_state_t *state); -void drm_free(drm_state_t *state); - -void drm_print_help(FILE *f); -int drm_set_option(drm_state_t *state, const char *key, const char *value); - -void drm_restore(drm_state_t *state); -int drm_set_temperature(drm_state_t *state, - const color_setting_t *setting); - +extern const gamma_method_t drm_gamma_method; #endif /* ! REDSHIFT_GAMMA_DRM_H */ diff --git a/src/gamma-dummy.c b/src/gamma-dummy.c index ba62d93..dadc014 100644 --- a/src/gamma-dummy.c +++ b/src/gamma-dummy.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2013-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2013-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #include <stdio.h> @@ -30,46 +30,58 @@ #include "redshift.h" -int +static int gamma_dummy_init(void *state) { return 0; } -int +static int gamma_dummy_start(void *state) { fputs(_("WARNING: Using dummy gamma method! Display will not be affected by this gamma method.\n"), stderr); return 0; } -void +static void gamma_dummy_restore(void *state) { } -void +static void gamma_dummy_free(void *state) { } -void +static void gamma_dummy_print_help(FILE *f) { fputs(_("Does not affect the display but prints the color temperature to the terminal.\n"), f); fputs("\n", f); } -int +static int gamma_dummy_set_option(void *state, const char *key, const char *value) { fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); return -1; } -int +static int gamma_dummy_set_temperature(void *state, const color_setting_t *setting) { printf(_("Temperature: %i\n"), setting->temperature); return 0; } + + +const gamma_method_t dummy_gamma_method = { + "dummy", 0, + (gamma_method_init_func *)gamma_dummy_init, + (gamma_method_start_func *)gamma_dummy_start, + (gamma_method_free_func *)gamma_dummy_free, + (gamma_method_print_help_func *)gamma_dummy_print_help, + (gamma_method_set_option_func *)gamma_dummy_set_option, + (gamma_method_restore_func *)gamma_dummy_restore, + (gamma_method_set_temperature_func *)gamma_dummy_set_temperature +}; diff --git a/src/gamma-dummy.h b/src/gamma-dummy.h index 3e58ec1..df4dfe9 100644 --- a/src/gamma-dummy.h +++ b/src/gamma-dummy.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2013-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2013-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #ifndef REDSHIFT_GAMMA_DUMMY_H @@ -23,16 +23,7 @@ #include "redshift.h" -int gamma_dummy_init(void *state); -int gamma_dummy_start(void *state); -void gamma_dummy_free(void *state); - -void gamma_dummy_print_help(FILE *f); -int gamma_dummy_set_option(void *state, const char *key, const char *value); - -void gamma_dummy_restore(void *state); -int gamma_dummy_set_temperature(void *state, - const color_setting_t *setting); +extern const gamma_method_t dummy_gamma_method; #endif /* ! REDSHIFT_GAMMA_DUMMY_H */ diff --git a/src/gamma-quartz.c b/src/gamma-quartz.c index 879da21..6bacff4 100644 --- a/src/gamma-quartz.c +++ b/src/gamma-quartz.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2014-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #ifdef HAVE_CONFIG_H @@ -37,7 +37,7 @@ #include "colorramp.h" -int +static int quartz_init(quartz_state_t *state) { state->preserve = 1; @@ -46,7 +46,7 @@ quartz_init(quartz_state_t *state) return 0; } -int +static int quartz_start(quartz_state_t *state) { int r; @@ -132,13 +132,13 @@ quartz_start(quartz_state_t *state) return 0; } -void +static void quartz_restore(quartz_state_t *state) { CGDisplayRestoreColorSyncSettings(); } -void +static void quartz_free(quartz_state_t *state) { if (state->displays != NULL) { @@ -149,7 +149,7 @@ quartz_free(quartz_state_t *state) free(state->displays); } -void +static void quartz_print_help(FILE *f) { fputs(_("Adjust gamma ramps on OSX using Quartz.\n"), f); @@ -163,7 +163,7 @@ quartz_print_help(FILE *f) fputs("\n", f); } -int +static int quartz_set_option(quartz_state_t *state, const char *key, const char *value) { if (strcasecmp(key, "preserve") == 0) { @@ -222,7 +222,7 @@ quartz_set_temperature_for_display(quartz_state_t *state, int display_index, free(gamma_ramps); } -int +static int quartz_set_temperature(quartz_state_t *state, const color_setting_t *setting) { @@ -232,3 +232,15 @@ quartz_set_temperature(quartz_state_t *state, return 0; } + + +const gamma_method_t quartz_gamma_method = { + "quartz", 1, + (gamma_method_init_func *)quartz_init, + (gamma_method_start_func *)quartz_start, + (gamma_method_free_func *)quartz_free, + (gamma_method_print_help_func *)quartz_print_help, + (gamma_method_set_option_func *)quartz_set_option, + (gamma_method_restore_func *)quartz_restore, + (gamma_method_set_temperature_func *)quartz_set_temperature +}; diff --git a/src/gamma-quartz.h b/src/gamma-quartz.h index cd29d54..3c1a8c1 100644 --- a/src/gamma-quartz.h +++ b/src/gamma-quartz.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2014-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #ifndef REDSHIFT_GAMMA_QUARTZ_H @@ -40,17 +40,6 @@ typedef struct { } quartz_state_t; -int quartz_init(quartz_state_t *state); -int quartz_start(quartz_state_t *state); -void quartz_free(quartz_state_t *state); - -void quartz_print_help(FILE *f); -int quartz_set_option(quartz_state_t *state, const char *key, - const char *value); - -void quartz_restore(quartz_state_t *state); -int quartz_set_temperature(quartz_state_t *state, - const color_setting_t *setting); - +extern const gamma_method_t quartz_gamma_method; #endif /* ! REDSHIFT_GAMMA_QUARTZ_H */ diff --git a/src/gamma-randr.c b/src/gamma-randr.c index 6e0fd00..ef240b2 100644 --- a/src/gamma-randr.c +++ b/src/gamma-randr.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #include <stdio.h> @@ -42,7 +42,7 @@ #define RANDR_VERSION_MINOR 3 -int +static int randr_init(randr_state_t *state) { /* Initialize state. */ @@ -91,7 +91,7 @@ randr_init(randr_state_t *state) return 0; } -int +static int randr_start(randr_state_t *state) { xcb_generic_error_t *error; @@ -228,7 +228,7 @@ randr_start(randr_state_t *state) return 0; } -void +static void randr_restore(randr_state_t *state) { xcb_generic_error_t *error; @@ -257,7 +257,7 @@ randr_restore(randr_state_t *state) } } -void +static void randr_free(randr_state_t *state) { /* Free CRTC state */ @@ -271,7 +271,7 @@ randr_free(randr_state_t *state) xcb_disconnect(state->conn); } -void +static void randr_print_help(FILE *f) { fputs(_("Adjust gamma ramps with the X RANDR extension.\n"), f); @@ -287,7 +287,7 @@ randr_print_help(FILE *f) fputs("\n", f); } -int +static int randr_set_option(randr_state_t *state, const char *key, const char *value) { if (strcasecmp(key, "screen") == 0) { @@ -416,7 +416,7 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, return 0; } -int +static int randr_set_temperature(randr_state_t *state, const color_setting_t *setting) { @@ -440,3 +440,15 @@ randr_set_temperature(randr_state_t *state, return 0; } + + +const gamma_method_t randr_gamma_method = { + "randr", 1, + (gamma_method_init_func *)randr_init, + (gamma_method_start_func *)randr_start, + (gamma_method_free_func *)randr_free, + (gamma_method_print_help_func *)randr_print_help, + (gamma_method_set_option_func *)randr_set_option, + (gamma_method_restore_func *)randr_restore, + (gamma_method_set_temperature_func *)randr_set_temperature +}; diff --git a/src/gamma-randr.h b/src/gamma-randr.h index 1fe7cb3..a44205d 100644 --- a/src/gamma-randr.h +++ b/src/gamma-randr.h @@ -48,16 +48,7 @@ typedef struct { } randr_state_t; -int randr_init(randr_state_t *state); -int randr_start(randr_state_t *state); -void randr_free(randr_state_t *state); - -void randr_print_help(FILE *f); -int randr_set_option(randr_state_t *state, const char *key, const char *value); - -void randr_restore(randr_state_t *state); -int randr_set_temperature(randr_state_t *state, - const color_setting_t *setting); +extern const gamma_method_t randr_gamma_method; #endif /* ! REDSHIFT_GAMMA_RANDR_H */ diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c index e664f80..8d49363 100644 --- a/src/gamma-vidmode.c +++ b/src/gamma-vidmode.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #include <stdlib.h> @@ -37,7 +37,7 @@ #include "colorramp.h" -int +static int vidmode_init(vidmode_state_t *state) { state->screen_num = -1; @@ -56,7 +56,7 @@ vidmode_init(vidmode_state_t *state) return 0; } -int +static int vidmode_start(vidmode_state_t *state) { int r; @@ -113,7 +113,7 @@ vidmode_start(vidmode_state_t *state) return 0; } -void +static void vidmode_free(vidmode_state_t *state) { /* Free saved ramps */ @@ -123,7 +123,7 @@ vidmode_free(vidmode_state_t *state) XCloseDisplay(state->display); } -void +static void vidmode_print_help(FILE *f) { fputs(_("Adjust gamma ramps with the X VidMode extension.\n"), f); @@ -138,7 +138,7 @@ vidmode_print_help(FILE *f) fputs("\n", f); } -int +static int vidmode_set_option(vidmode_state_t *state, const char *key, const char *value) { if (strcasecmp(key, "screen") == 0) { @@ -153,7 +153,7 @@ vidmode_set_option(vidmode_state_t *state, const char *key, const char *value) return 0; } -void +static void vidmode_restore(vidmode_state_t *state) { uint16_t *gamma_r = &state->saved_ramps[0*state->ramp_size]; @@ -170,7 +170,7 @@ vidmode_restore(vidmode_state_t *state) } } -int +static int vidmode_set_temperature(vidmode_state_t *state, const color_setting_t *setting) { @@ -220,3 +220,15 @@ vidmode_set_temperature(vidmode_state_t *state, return 0; } + + +const gamma_method_t vidmode_gamma_method = { + "vidmode", 1, + (gamma_method_init_func *)vidmode_init, + (gamma_method_start_func *)vidmode_start, + (gamma_method_free_func *)vidmode_free, + (gamma_method_print_help_func *)vidmode_print_help, + (gamma_method_set_option_func *)vidmode_set_option, + (gamma_method_restore_func *)vidmode_restore, + (gamma_method_set_temperature_func *)vidmode_set_temperature +}; diff --git a/src/gamma-vidmode.h b/src/gamma-vidmode.h index 4b6cecc..dbd3e5d 100644 --- a/src/gamma-vidmode.h +++ b/src/gamma-vidmode.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #ifndef REDSHIFT_GAMMA_VIDMODE_H @@ -36,17 +36,7 @@ typedef struct { } vidmode_state_t; -int vidmode_init(vidmode_state_t *state); -int vidmode_start(vidmode_state_t *state); -void vidmode_free(vidmode_state_t *state); - -void vidmode_print_help(FILE *f); -int vidmode_set_option(vidmode_state_t *state, const char *key, - const char *value); - -void vidmode_restore(vidmode_state_t *state); -int vidmode_set_temperature(vidmode_state_t *state, - const color_setting_t *setting); +extern const gamma_method_t vidmode_gamma_method; #endif /* ! REDSHIFT_GAMMA_VIDMODE_H */ diff --git a/src/gamma-w32gdi.c b/src/gamma-w32gdi.c index 3d67331..9896dce 100644 --- a/src/gamma-w32gdi.c +++ b/src/gamma-w32gdi.c @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #include <stdio.h> @@ -40,7 +40,7 @@ #define MAX_ATTEMPTS 10 -int +static int w32gdi_init(w32gdi_state_t *state) { state->saved_ramps = NULL; @@ -49,7 +49,7 @@ w32gdi_init(w32gdi_state_t *state) return 0; } -int +static int w32gdi_start(w32gdi_state_t *state) { BOOL r; @@ -91,7 +91,7 @@ w32gdi_start(w32gdi_state_t *state) return 0; } -void +static void w32gdi_free(w32gdi_state_t *state) { /* Free saved ramps */ @@ -99,7 +99,7 @@ w32gdi_free(w32gdi_state_t *state) } -void +static void w32gdi_print_help(FILE *f) { fputs(_("Adjust gamma ramps with the Windows GDI.\n"), f); @@ -113,7 +113,7 @@ w32gdi_print_help(FILE *f) fputs("\n", f); } -int +static int w32gdi_set_option(w32gdi_state_t *state, const char *key, const char *value) { if (strcasecmp(key, "preserve") == 0) { @@ -126,7 +126,7 @@ w32gdi_set_option(w32gdi_state_t *state, const char *key, const char *value) return 0; } -void +static void w32gdi_restore(w32gdi_state_t *state) { /* Open device context */ @@ -150,7 +150,7 @@ w32gdi_restore(w32gdi_state_t *state) ReleaseDC(NULL, hDC); } -int +static int w32gdi_set_temperature(w32gdi_state_t *state, const color_setting_t *setting) { @@ -215,3 +215,15 @@ w32gdi_set_temperature(w32gdi_state_t *state, return 0; } + + +const gamma_method_t w32gdi_gamma_method = { + "wingdi", 1, + (gamma_method_init_func *)w32gdi_init, + (gamma_method_start_func *)w32gdi_start, + (gamma_method_free_func *)w32gdi_free, + (gamma_method_print_help_func *)w32gdi_print_help, + (gamma_method_set_option_func *)w32gdi_set_option, + (gamma_method_restore_func *)w32gdi_restore, + (gamma_method_set_temperature_func *)w32gdi_set_temperature +}; diff --git a/src/gamma-w32gdi.h b/src/gamma-w32gdi.h index 6e73cd1..9094acd 100644 --- a/src/gamma-w32gdi.h +++ b/src/gamma-w32gdi.h @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2010-2017 Jon Lund Steffensen <jonlst@gmail.com> */ #ifndef REDSHIFT_GAMMA_W32GDI_H @@ -32,17 +32,7 @@ typedef struct { } w32gdi_state_t; -int w32gdi_init(w32gdi_state_t *state); -int w32gdi_start(w32gdi_state_t *state); -void w32gdi_free(w32gdi_state_t *state); - -void w32gdi_print_help(FILE *f); -int w32gdi_set_option(w32gdi_state_t *state, const char *key, - const char *value); - -void w32gdi_restore(w32gdi_state_t *state); -int w32gdi_set_temperature(w32gdi_state_t *state, - const color_setting_t *color); +extern const gamma_method_t w32gdi_gamma_method; #endif /* ! REDSHIFT_GAMMA_W32GDI_H */ diff --git a/src/location-corelocation.h b/src/location-corelocation.h index ae1feeb..04ced29 100644 --- a/src/location-corelocation.h +++ b/src/location-corelocation.h @@ -37,20 +37,7 @@ typedef struct { } location_corelocation_state_t; -int location_corelocation_init(location_corelocation_state_t *state); -int location_corelocation_start(location_corelocation_state_t *state); -void location_corelocation_free(location_corelocation_state_t *state); - -void location_corelocation_print_help(FILE *f); -int location_corelocation_set_option( - location_corelocation_state_t *state, - const char *key, const char *value); - -int location_corelocation_get_fd( - location_corelocation_state_t *state); -int location_corelocation_handle( - location_corelocation_state_t *state, - location_t *location, int *available); +extern const location_provider_t corelocation_location_provider; #endif /* ! REDSHIFT_LOCATION_CORELOCATION_H */ diff --git a/src/location-corelocation.m b/src/location-corelocation.m index 5150839..17e0054 100644 --- a/src/location-corelocation.m +++ b/src/location-corelocation.m @@ -172,13 +172,13 @@ pipe_close_callback( @end -int +static int location_corelocation_init(location_corelocation_state_t *state) { return 0; } -int +static int location_corelocation_start(location_corelocation_state_t *state) { state->pipe_fd_read = -1; @@ -215,7 +215,7 @@ location_corelocation_start(location_corelocation_state_t *state) return 0; } -void +static void location_corelocation_free(location_corelocation_state_t *state) { if (state->pipe_fd_read != -1) { @@ -225,14 +225,14 @@ location_corelocation_free(location_corelocation_state_t *state) free(state->private); } -void +static void location_corelocation_print_help(FILE *f) { fputs(_("Use the location as discovered by the Corelocation provider.\n"), f); fputs("\n", f); } -int +static int location_corelocation_set_option( location_corelocation_state_t *state, const char *key, const char *value) { @@ -240,13 +240,14 @@ location_corelocation_set_option( return -1; } -int +static int location_corelocation_get_fd(location_corelocation_state_t *state) { return state->pipe_fd_read; } -int location_corelocation_handle( +static int +location_corelocation_handle( location_corelocation_state_t *state, location_t *location, int *available) { @@ -265,3 +266,15 @@ int location_corelocation_handle( return 0; } + + +const location_provider_t corelocation_location_provider = { + "corelocation", + (location_provider_init_func *)location_corelocation_init, + (location_provider_start_func *)location_corelocation_start, + (location_provider_free_func *)location_corelocation_free, + (location_provider_print_help_func *)location_corelocation_print_help, + (location_provider_set_option_func *)location_corelocation_set_option, + (location_provider_get_fd_func *)location_corelocation_get_fd, + (location_provider_handle_func *)location_corelocation_handle +}; diff --git a/src/location-geoclue2.c b/src/location-geoclue2.c index 6ebedb4..b012da4 100644 --- a/src/location-geoclue2.c +++ b/src/location-geoclue2.c @@ -285,7 +285,7 @@ on_pipe_closed(GIOChannel *channel, GIOCondition condition, gpointer user_data) /* Run loop for location provider thread. */ -void * +static void * run_geoclue2_loop(void *state_) { location_geoclue2_state_t *state = state_; @@ -324,7 +324,7 @@ run_geoclue2_loop(void *state_) return NULL; } -int +static int location_geoclue2_init(location_geoclue2_state_t *state) { #if !GLIB_CHECK_VERSION(2, 35, 0) @@ -333,7 +333,7 @@ location_geoclue2_init(location_geoclue2_state_t *state) return 0; } -int +static int location_geoclue2_start(location_geoclue2_state_t *state) { state->pipe_fd_read = -1; @@ -362,7 +362,7 @@ location_geoclue2_start(location_geoclue2_state_t *state) return 0; } -void +static void location_geoclue2_free(location_geoclue2_state_t *state) { if (state->pipe_fd_read != -1) { @@ -376,7 +376,7 @@ location_geoclue2_free(location_geoclue2_state_t *state) g_mutex_clear(&state->lock); } -void +static void location_geoclue2_print_help(FILE *f) { fputs(_("Use the location as discovered by a GeoClue2 provider.\n"), @@ -384,7 +384,7 @@ location_geoclue2_print_help(FILE *f) fputs("\n", f); } -int +static int location_geoclue2_set_option(location_geoclue2_state_t *state, const char *key, const char *value) { @@ -392,13 +392,13 @@ location_geoclue2_set_option(location_geoclue2_state_t *state, return -1; } -int +static int location_geoclue2_get_fd(location_geoclue2_state_t *state) { return state->pipe_fd_read; } -int +static int location_geoclue2_handle( location_geoclue2_state_t *state, location_t *location, int *available) @@ -418,3 +418,15 @@ location_geoclue2_handle( return 0; } + + +const location_provider_t geoclue2_location_provider = { + "geoclue2", + (location_provider_init_func *)location_geoclue2_init, + (location_provider_start_func *)location_geoclue2_start, + (location_provider_free_func *)location_geoclue2_free, + (location_provider_print_help_func *)location_geoclue2_print_help, + (location_provider_set_option_func *)location_geoclue2_set_option, + (location_provider_get_fd_func *)location_geoclue2_get_fd, + (location_provider_handle_func *)location_geoclue2_handle +}; diff --git a/src/location-geoclue2.h b/src/location-geoclue2.h index 2f04eea..b20d5a9 100644 --- a/src/location-geoclue2.h +++ b/src/location-geoclue2.h @@ -39,17 +39,7 @@ typedef struct { } location_geoclue2_state_t; -int location_geoclue2_init(location_geoclue2_state_t *state); -int location_geoclue2_start(location_geoclue2_state_t *state); -void location_geoclue2_free(location_geoclue2_state_t *state); - -void location_geoclue2_print_help(FILE *f); -int location_geoclue2_set_option(location_geoclue2_state_t *state, - const char *key, const char *value); - -int location_geoclue2_get_fd(location_geoclue2_state_t *state); -int location_geoclue2_handle(location_geoclue2_state_t *state, - location_t *location, int *available); +extern const location_provider_t geoclue2_location_provider; #endif /* ! REDSHIFT_LOCATION_GEOCLUE2_H */ diff --git a/src/location-manual.c b/src/location-manual.c index 8ce324c..d7ba37a 100644 --- a/src/location-manual.c +++ b/src/location-manual.c @@ -33,7 +33,7 @@ #endif -int +static int location_manual_init(location_manual_state_t *state) { state->loc.lat = NAN; @@ -42,7 +42,7 @@ location_manual_init(location_manual_state_t *state) return 0; } -int +static int location_manual_start(location_manual_state_t *state) { /* Latitude and longitude must be set */ @@ -54,12 +54,12 @@ location_manual_start(location_manual_state_t *state) return 0; } -void +static void location_manual_free(location_manual_state_t *state) { } -void +static void location_manual_print_help(FILE *f) { fputs(_("Specify location manually.\n"), f); @@ -75,7 +75,7 @@ location_manual_print_help(FILE *f) fputs("\n", f); } -int +static int location_manual_set_option(location_manual_state_t *state, const char *key, const char *value) { @@ -100,13 +100,13 @@ location_manual_set_option(location_manual_state_t *state, const char *key, return 0; } -int +static int location_manual_get_fd(location_manual_state_t *state) { return -1; } -int +static int location_manual_handle( location_manual_state_t *state, location_t *location, int *available) { @@ -115,3 +115,15 @@ location_manual_handle( return 0; } + + +const location_provider_t manual_location_provider = { + "manual", + (location_provider_init_func *)location_manual_init, + (location_provider_start_func *)location_manual_start, + (location_provider_free_func *)location_manual_free, + (location_provider_print_help_func *)location_manual_print_help, + (location_provider_set_option_func *)location_manual_set_option, + (location_provider_get_fd_func *)location_manual_get_fd, + (location_provider_handle_func *)location_manual_handle +}; diff --git a/src/location-manual.h b/src/location-manual.h index 7094e9a..58a0f4c 100644 --- a/src/location-manual.h +++ b/src/location-manual.h @@ -30,17 +30,7 @@ typedef struct { } location_manual_state_t; -int location_manual_init(location_manual_state_t *state); -int location_manual_start(location_manual_state_t *state); -void location_manual_free(location_manual_state_t *state); - -void location_manual_print_help(FILE *f); -int location_manual_set_option(location_manual_state_t *state, - const char *key, const char *value); - -int location_manual_get_fd(location_manual_state_t *state); -int location_manual_handle( - location_manual_state_t *state, location_t *location, int *available); +extern const location_provider_t manual_location_provider; #endif /* ! REDSHIFT_LOCATION_MANUAL_H */ diff --git a/src/redshift.c b/src/redshift.c index f46853b..3c7dcec 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -127,82 +127,6 @@ typedef union { } gamma_state_t; -/* Gamma adjustment method structs */ -static const gamma_method_t gamma_methods[] = { -#ifdef ENABLE_DRM - { - "drm", 0, - (gamma_method_init_func *)drm_init, - (gamma_method_start_func *)drm_start, - (gamma_method_free_func *)drm_free, - (gamma_method_print_help_func *)drm_print_help, - (gamma_method_set_option_func *)drm_set_option, - (gamma_method_restore_func *)drm_restore, - (gamma_method_set_temperature_func *)drm_set_temperature - }, -#endif -#ifdef ENABLE_RANDR - { - "randr", 1, - (gamma_method_init_func *)randr_init, - (gamma_method_start_func *)randr_start, - (gamma_method_free_func *)randr_free, - (gamma_method_print_help_func *)randr_print_help, - (gamma_method_set_option_func *)randr_set_option, - (gamma_method_restore_func *)randr_restore, - (gamma_method_set_temperature_func *)randr_set_temperature - }, -#endif -#ifdef ENABLE_VIDMODE - { - "vidmode", 1, - (gamma_method_init_func *)vidmode_init, - (gamma_method_start_func *)vidmode_start, - (gamma_method_free_func *)vidmode_free, - (gamma_method_print_help_func *)vidmode_print_help, - (gamma_method_set_option_func *)vidmode_set_option, - (gamma_method_restore_func *)vidmode_restore, - (gamma_method_set_temperature_func *)vidmode_set_temperature - }, -#endif -#ifdef ENABLE_QUARTZ - { - "quartz", 1, - (gamma_method_init_func *)quartz_init, - (gamma_method_start_func *)quartz_start, - (gamma_method_free_func *)quartz_free, - (gamma_method_print_help_func *)quartz_print_help, - (gamma_method_set_option_func *)quartz_set_option, - (gamma_method_restore_func *)quartz_restore, - (gamma_method_set_temperature_func *)quartz_set_temperature - }, -#endif -#ifdef ENABLE_WINGDI - { - "wingdi", 1, - (gamma_method_init_func *)w32gdi_init, - (gamma_method_start_func *)w32gdi_start, - (gamma_method_free_func *)w32gdi_free, - (gamma_method_print_help_func *)w32gdi_print_help, - (gamma_method_set_option_func *)w32gdi_set_option, - (gamma_method_restore_func *)w32gdi_restore, - (gamma_method_set_temperature_func *)w32gdi_set_temperature - }, -#endif - { - "dummy", 0, - (gamma_method_init_func *)gamma_dummy_init, - (gamma_method_start_func *)gamma_dummy_start, - (gamma_method_free_func *)gamma_dummy_free, - (gamma_method_print_help_func *)gamma_dummy_print_help, - (gamma_method_set_option_func *)gamma_dummy_set_option, - (gamma_method_restore_func *)gamma_dummy_restore, - (gamma_method_set_temperature_func *)gamma_dummy_set_temperature - }, - { NULL } -}; - - /* Union of state data for location providers */ typedef union { location_manual_state_t manual; @@ -215,51 +139,6 @@ typedef union { } location_state_t; -/* Location provider method structs */ -static const location_provider_t location_providers[] = { -#ifdef ENABLE_GEOCLUE2 - { - "geoclue2", - (location_provider_init_func *)location_geoclue2_init, - (location_provider_start_func *)location_geoclue2_start, - (location_provider_free_func *)location_geoclue2_free, - (location_provider_print_help_func *) - location_geoclue2_print_help, - (location_provider_set_option_func *) - location_geoclue2_set_option, - (location_provider_get_fd_func *)location_geoclue2_get_fd, - (location_provider_handle_func *)location_geoclue2_handle - }, -#endif -#ifdef ENABLE_CORELOCATION - { - "corelocation", - (location_provider_init_func *)location_corelocation_init, - (location_provider_start_func *)location_corelocation_start, - (location_provider_free_func *)location_corelocation_free, - (location_provider_print_help_func *) - location_corelocation_print_help, - (location_provider_set_option_func *) - location_corelocation_set_option, - (location_provider_get_fd_func *)location_corelocation_get_fd, - (location_provider_handle_func *)location_corelocation_handle - }, -#endif - { - "manual", - (location_provider_init_func *)location_manual_init, - (location_provider_start_func *)location_manual_start, - (location_provider_free_func *)location_manual_free, - (location_provider_print_help_func *) - location_manual_print_help, - (location_provider_set_option_func *) - location_manual_set_option, - (location_provider_get_fd_func *)location_manual_get_fd, - (location_provider_handle_func *)location_manual_handle - }, - { NULL } -}; - /* Bounds for parameters. */ #define MIN_LAT -90.0 #define MAX_LAT 90.0 @@ -566,7 +445,7 @@ print_help(const char *program_name) } static void -print_method_list() +print_method_list(const gamma_method_t *gamma_methods) { fputs(_("Available adjustment methods:\n"), stdout); for (int i = 0; gamma_methods[i].name != NULL; i++) { @@ -581,7 +460,7 @@ print_method_list() } static void -print_provider_list() +print_provider_list(const location_provider_t location_providers[]) { fputs(_("Available location providers:\n"), stdout); for (int i = 0; location_providers[i].name != NULL; i++) { @@ -900,13 +779,13 @@ location_is_valid(const location_t *location) } static const gamma_method_t * -find_gamma_method(const char *name) +find_gamma_method(const gamma_method_t gamma_methods[], const char *name) { const gamma_method_t *method = NULL; for (int i = 0; gamma_methods[i].name != NULL; i++) { const gamma_method_t *m = &gamma_methods[i]; if (strcasecmp(name, m->name) == 0) { - method = m; + method = m; break; } } @@ -915,7 +794,8 @@ find_gamma_method(const char *name) } static const location_provider_t * -find_location_provider(const char *name) +find_location_provider( + const location_provider_t location_providers[], const char *name) { const location_provider_t *provider = NULL; for (int i = 0; location_providers[i].name != NULL; i++) { @@ -1333,9 +1213,42 @@ main(int argc, char *argv[]) /* Temperature for manual mode */ int temp_set = -1; + /* List of gamma methods. */ + const gamma_method_t gamma_methods[] = { +#ifdef ENABLE_DRM + drm_gamma_method, +#endif +#ifdef ENABLE_RANDR + randr_gamma_method, +#endif +#ifdef ENABLE_VIDMODE + vidmode_gamma_method, +#endif +#ifdef ENABLE_QUARTZ + quartz_gamma_method, +#endif +#ifdef ENABLE_WINGDI + w32gdi_gamma_method, +#endif + dummy_gamma_method, + { NULL } + }; + const gamma_method_t *method = NULL; char *method_args = NULL; + /* List of location providers. */ + const location_provider_t location_providers[] = { +#ifdef ENABLE_GEOCLUE2 + geoclue2_location_provider, +#endif +#ifdef ENABLE_CORELOCATION + corelocation_location_provider, +#endif + manual_location_provider, + { NULL } + }; + const location_provider_t *provider = NULL; char *provider_args = NULL; @@ -1386,7 +1299,7 @@ main(int argc, char *argv[]) case 'l': /* Print list of providers if argument is `list' */ if (strcasecmp(optarg, "list") == 0) { - print_provider_list(); + print_provider_list(location_providers); exit(EXIT_SUCCESS); } @@ -1413,7 +1326,8 @@ main(int argc, char *argv[]) } /* Lookup provider from name. */ - provider = find_location_provider(provider_name); + provider = find_location_provider( + location_providers, provider_name); if (provider == NULL) { fprintf(stderr, _("Unknown location provider" " `%s'.\n"), provider_name); @@ -1430,7 +1344,7 @@ main(int argc, char *argv[]) case 'm': /* Print list of methods if argument is `list' */ if (strcasecmp(optarg, "list") == 0) { - print_method_list(); + print_method_list(gamma_methods); exit(EXIT_SUCCESS); } @@ -1442,7 +1356,7 @@ main(int argc, char *argv[]) } /* Find adjustment method by name. */ - method = find_gamma_method(optarg); + method = find_gamma_method(gamma_methods, optarg); if (method == NULL) { /* TRANSLATORS: This refers to the method used to adjust colors e.g VidMode */ @@ -1603,7 +1517,7 @@ main(int argc, char *argv[]) "adjustment-method") == 0) { if (method == NULL) { method = find_gamma_method( - setting->value); + gamma_methods, setting->value); if (method == NULL) { fprintf(stderr, _("Unknown" " adjustment" @@ -1617,6 +1531,7 @@ main(int argc, char *argv[]) "location-provider") == 0) { if (provider == NULL) { provider = find_location_provider( + location_providers, setting->value); if (provider == NULL) { fprintf(stderr, _("Unknown" |