diff options
| -rw-r--r-- | LICENSE | 2 | ||||
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | fake-quartz-cg.c | 2 | ||||
| -rw-r--r-- | info/libgamma.texinfo | 8 | ||||
| -rw-r--r-- | libgamma.7 | 2 | ||||
| -rw-r--r-- | libgamma.h | 16 | ||||
| -rw-r--r-- | libgamma_dummy_get_fd.c | 18 | ||||
| -rw-r--r-- | libgamma_get_fd.c | 24 | ||||
| -rw-r--r-- | libgamma_linux_drm_get_fd.c | 18 | ||||
| -rw-r--r-- | libgamma_quartz_cg_get_fd.c | 18 | ||||
| -rw-r--r-- | libgamma_strerror_r.c | 23 | ||||
| -rw-r--r-- | libgamma_w32_gdi_get_fd.c | 18 | ||||
| -rw-r--r-- | libgamma_x_randr_get_fd.c | 16 | ||||
| -rw-r--r-- | libgamma_x_vidmode_get_fd.c | 16 | ||||
| -rw-r--r-- | method-dummy.h | 10 | ||||
| -rw-r--r-- | method-linux-drm.h | 10 | ||||
| -rw-r--r-- | method-quartz-cg.h | 10 | ||||
| -rw-r--r-- | method-w32-gdi.h | 10 | ||||
| -rw-r--r-- | method-x-randr.h | 10 | ||||
| -rw-r--r-- | method-x-vidmode.h | 10 | ||||
| -rw-r--r-- | mk/method-dummy=yes.mk | 1 | ||||
| -rw-r--r-- | mk/method-linux-drm=yes.mk | 1 | ||||
| -rw-r--r-- | mk/method-quartz-cg=yes.mk | 1 | ||||
| -rw-r--r-- | mk/method-w32-gdi=yes.mk | 1 | ||||
| -rw-r--r-- | mk/method-x-randr=yes.mk | 1 | ||||
| -rw-r--r-- | mk/method-x-vidmode=yes.mk | 1 |
26 files changed, 242 insertions, 8 deletions
@@ -1,6 +1,6 @@ ISC License -© 2014, 2015, 2016, 2017, 2021 Mattias Andrée <m@maandree.se> +© 2014, 2015, 2016, 2017, 2021, 2026 Mattias Andrée <m@maandree.se> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -1,7 +1,7 @@ .POSIX: LIB_MAJOR = 0 -LIB_MINOR = 8 +LIB_MINOR = 9 LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) @@ -109,6 +109,7 @@ OBJ_PUBLIC =\ libgamma_gamma_rampsf_free.o\ libgamma_gamma_rampsf_initialise.o\ libgamma_get_crtc_information.o\ + libgamma_get_fd.o\ libgamma_group_gid.o\ libgamma_group_name.o\ libgamma_is_method_available.o\ diff --git a/fake-quartz-cg.c b/fake-quartz-cg.c index 999609b..b1a6a4b 100644 --- a/fake-quartz-cg.c +++ b/fake-quartz-cg.c @@ -254,7 +254,7 @@ CGGetOnlineDisplayList(uint32_t max_size, CGDirectDisplayID *restrict displays_o } /* Copy over the gamma ramps to the memory area we have allocated */ - memcpy(&original_ramps[(3 * i + 0) * 256], xcb_randr_get_crtc_gamma_red(gamma_reply) + memcpy(&original_ramps[(3 * i + 0) * 256], xcb_randr_get_crtc_gamma_red(gamma_reply), 256 * sizeof(*original_ramps)); memcpy(&original_ramps[(3 * i + 1) * 256], xcb_randr_get_crtc_gamma_green(gamma_reply), 256 * sizeof(*original_ramps)); diff --git a/info/libgamma.texinfo b/info/libgamma.texinfo index 3094e95..eed4cfa 100644 --- a/info/libgamma.texinfo +++ b/info/libgamma.texinfo @@ -250,6 +250,14 @@ to determine the default site for the adjustment method. @end table +The function @code{libgamma_get_fd} takes the site +state as its only argument and returns the file +descriptor used to communicate with the display +server. It returns @code{-1} if the adjustment +method does not use a file descriptor for that +communication. The returned file descriptor is owned +by the site state and must not be closed by the caller. + To release all resources held by a site state, call the function @code{libgamma_site_destroy}, whose only parameter is the site state to @@ -203,6 +203,8 @@ The number of possible values on the encoding axis of a gamma ramp. .br .BR libgamma_get_crtc_information (3), .br +.BR libgamma_get_fd (3), +.br .BR libgamma_group_gid (3), .br .BR libgamma_group_name (3), @@ -1849,7 +1849,7 @@ int libgamma_value_of_error(const char *); * @return The group that the user needs to be a member of * if `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned */ -LIBGAMMA_GCC_ONLY__(__attribute__((__warn_unused_result__))) +LIBGAMMA_GCC_ONLY__(__attribute__((__warn_unused_result__, __pure__))) #ifndef __WIN32__ gid_t libgamma_group_gid_get(void); #else @@ -1878,7 +1878,7 @@ void libgamma_group_gid_set(short); * if the name of the group `libgamma_group_gid` cannot * be determined */ -LIBGAMMA_GCC_ONLY__(__attribute__((__warn_unused_result__))) +LIBGAMMA_GCC_ONLY__(__attribute__((__warn_unused_result__, __pure__))) const char *libgamma_group_name_get(void); /** @@ -2320,6 +2320,18 @@ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__))) void libgamma_site_destroy(struct libgamma_site_state *restrict); /** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor, or -1 if the adjustment method does not + * use a file descriptor to communicate with the display server; + * the file descriptor is owned by the site state and must not be + * closed by the caller + */ +LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__))) +int libgamma_get_fd(struct libgamma_site_state *restrict); + +/** * Release all resources held by a site state * and free the site state pointer * diff --git a/libgamma_dummy_get_fd.c b/libgamma_dummy_get_fd.c new file mode 100644 index 0000000..631967c --- /dev/null +++ b/libgamma_dummy_get_fd.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#define IN_LIBGAMMA_DUMMY +#include "common.h" + + +/** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return -1, as this adjustment method does not use a file descriptor + * to communicate with the display server + */ +int +libgamma_dummy_get_fd(struct libgamma_site_state *restrict this) +{ + (void) this; + return -1; +} diff --git a/libgamma_get_fd.c b/libgamma_get_fd.c new file mode 100644 index 0000000..70c1522 --- /dev/null +++ b/libgamma_get_fd.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +/** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor, or -1 if the adjustment method does not + * use a file descriptor to communicate with the display server + */ +int +libgamma_get_fd(struct libgamma_site_state *restrict this) +{ + switch (this->method) { +#define X(CONST, CNAME, ...)\ + case CONST:\ + return libgamma_##CNAME##_get_fd(this); + LIST_AVAILABLE_METHODS(X) +#undef X + default: + return -1; + } +} diff --git a/libgamma_linux_drm_get_fd.c b/libgamma_linux_drm_get_fd.c new file mode 100644 index 0000000..eece0f1 --- /dev/null +++ b/libgamma_linux_drm_get_fd.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#define IN_LIBGAMMA_LINUX_DRM +#include "common.h" + + +/** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return -1, as this adjustment method does not use a file descriptor + * to communicate with the display server + */ +int +libgamma_linux_drm_get_fd(struct libgamma_site_state *restrict this) +{ + (void) this; + return -1; +} diff --git a/libgamma_quartz_cg_get_fd.c b/libgamma_quartz_cg_get_fd.c new file mode 100644 index 0000000..478a584 --- /dev/null +++ b/libgamma_quartz_cg_get_fd.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#define IN_LIBGAMMA_QUARTZ_CG +#include "common.h" + + +/** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return -1, as this adjustment method does not use a file descriptor + * to communicate with the display server + */ +int +libgamma_quartz_cg_get_fd(struct libgamma_site_state *restrict this) +{ + (void) this; + return -1; +} diff --git a/libgamma_strerror_r.c b/libgamma_strerror_r.c index c95d8a9..1076ed8 100644 --- a/libgamma_strerror_r.c +++ b/libgamma_strerror_r.c @@ -2,6 +2,22 @@ #include "common.h" +static const char * +libgamma_xsi_strerror_r(int (*function)(int, char *, size_t), int error_code, char *buf, size_t bufsize) +{ + int error = function(error_code, buf, bufsize); + errno = error; + return error ? NULL : buf; +} + + +static const char * +libgamma_gnu_strerror_r(char *(*function)(int, char *, size_t), int error_code, char *buf, size_t bufsize) +{ + return function(error_code, buf, bufsize); +} + + /** * Get a description of an error * @@ -36,11 +52,12 @@ libgamma_strerror_r(int error_code, char buf[], size_t bufsize) *buf = '\0'; if (error_code >= 0) { saved_errno = errno; - desc = _Generic(strerror_r(error_code, buf, bufsize), + desc = _Generic(&strerror_r, /* XSI strerror_r */ - int: (errno = (int)(intptr_t)strerror_r(error_code, buf, bufsize)) ? NULL : buf, + int (*)(int, char *, size_t): libgamma_xsi_strerror_r, /* GNU strerror_r */ - char *: (char *)(intptr_t)strerror_r(error_code, buf, bufsize)); + char *(*)(int, char *, size_t): libgamma_gnu_strerror_r) + (&strerror_r, error_code, buf, bufsize); if (desc == buf && (!bufsize || !*buf)) desc = NULL; if (desc) { diff --git a/libgamma_w32_gdi_get_fd.c b/libgamma_w32_gdi_get_fd.c new file mode 100644 index 0000000..ce5de0a --- /dev/null +++ b/libgamma_w32_gdi_get_fd.c @@ -0,0 +1,18 @@ +/* See LICENSE file for copyright and license details. */ +#define IN_LIBGAMMA_W32_GDI +#include "common.h" + + +/** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return -1, as this adjustment method does not use a file descriptor + * to communicate with the display server + */ +int +libgamma_w32_gdi_get_fd(struct libgamma_site_state *restrict this) +{ + (void) this; + return -1; +} diff --git a/libgamma_x_randr_get_fd.c b/libgamma_x_randr_get_fd.c new file mode 100644 index 0000000..3b4f83f --- /dev/null +++ b/libgamma_x_randr_get_fd.c @@ -0,0 +1,16 @@ +/* See LICENSE file for copyright and license details. */ +#define IN_LIBGAMMA_X_RANDR +#include "common.h" + + +/** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor + */ +int +libgamma_x_randr_get_fd(struct libgamma_site_state *restrict this) +{ + return xcb_get_file_descriptor((xcb_connection_t *)this->data); +} diff --git a/libgamma_x_vidmode_get_fd.c b/libgamma_x_vidmode_get_fd.c new file mode 100644 index 0000000..656fcbc --- /dev/null +++ b/libgamma_x_vidmode_get_fd.c @@ -0,0 +1,16 @@ +/* See LICENSE file for copyright and license details. */ +#define IN_LIBGAMMA_X_VIDMODE +#include "common.h" + + +/** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor + */ +int +libgamma_x_vidmode_get_fd(struct libgamma_site_state *restrict this) +{ + return ConnectionNumber((Display *)this->data); +} diff --git a/method-dummy.h b/method-dummy.h index fa50b18..c82f40a 100644 --- a/method-dummy.h +++ b/method-dummy.h @@ -216,6 +216,16 @@ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__))) void libgamma_dummy_site_destroy(struct libgamma_site_state *restrict); /** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor, or -1 if the adjustment method does not + * use a file descriptor to communicate with the display server + */ +LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __const__))) +int libgamma_dummy_get_fd(struct libgamma_site_state *restrict); + +/** * Restore the gamma ramps all CRTC:s with a site to the system settings * * @param this The site state diff --git a/method-linux-drm.h b/method-linux-drm.h index 9e98412..67f775d 100644 --- a/method-linux-drm.h +++ b/method-linux-drm.h @@ -65,6 +65,16 @@ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__))) void libgamma_linux_drm_site_destroy(struct libgamma_site_state *restrict); /** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor, or -1 if the adjustment method does not + * use a file descriptor to communicate with the display server + */ +LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __const__))) +int libgamma_linux_drm_get_fd(struct libgamma_site_state *restrict); + +/** * Restore the gamma ramps all CRTC:s with a site to the system settings * * @param this The site state diff --git a/method-quartz-cg.h b/method-quartz-cg.h index e37e3e4..3619f64 100644 --- a/method-quartz-cg.h +++ b/method-quartz-cg.h @@ -43,6 +43,16 @@ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__))) void libgamma_quartz_cg_site_destroy(struct libgamma_site_state *restrict); /** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor, or -1 if the adjustment method does not + * use a file descriptor to communicate with the display server + */ +LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __const__))) +int libgamma_quartz_cg_get_fd(struct libgamma_site_state *restrict); + +/** * Restore the gamma ramps all CRTC:s with a site to the system settings * * @param this The site state diff --git a/method-w32-gdi.h b/method-w32-gdi.h index 3815bdb..3cf3563 100644 --- a/method-w32-gdi.h +++ b/method-w32-gdi.h @@ -53,6 +53,16 @@ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__))) void libgamma_w32_gdi_site_destroy(struct libgamma_site_state *restrict); /** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor, or -1 if the adjustment method does not + * use a file descriptor to communicate with the display server + */ +LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __const__))) +int libgamma_w32_gdi_get_fd(struct libgamma_site_state *restrict); + +/** * Restore the gamma ramps all CRTC:s with a site to the system settings * * @param this The site state diff --git a/method-x-randr.h b/method-x-randr.h index e331912..12dda92 100644 --- a/method-x-randr.h +++ b/method-x-randr.h @@ -86,6 +86,16 @@ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__))) void libgamma_x_randr_site_destroy(struct libgamma_site_state *restrict); /** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor, or -1 if the adjustment method does not + * use a file descriptor to communicate with the display server + */ +LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__))) +int libgamma_x_randr_get_fd(struct libgamma_site_state *restrict); + +/** * Restore the gamma ramps all CRTC:s with a site to the system settings * * @param this The site state diff --git a/method-x-vidmode.h b/method-x-vidmode.h index 48dec39..118e077 100644 --- a/method-x-vidmode.h +++ b/method-x-vidmode.h @@ -39,6 +39,16 @@ LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__))) void libgamma_x_vidmode_site_destroy(struct libgamma_site_state *restrict); /** + * Get the file descriptor used to communicate with the display server + * + * @param this The site state + * @return The file descriptor, or -1 if the adjustment method does not + * use a file descriptor to communicate with the display server + */ +LIBGAMMA_GCC_ONLY__(__attribute__((__nonnull__, __warn_unused_result__, __pure__))) +int libgamma_x_vidmode_get_fd(struct libgamma_site_state *restrict); + +/** * Restore the gamma ramps all CRTC:s with a site to the system settings * * @param this The site state diff --git a/mk/method-dummy=yes.mk b/mk/method-dummy=yes.mk index 88eb2aa..272b4b9 100644 --- a/mk/method-dummy=yes.mk +++ b/mk/method-dummy=yes.mk @@ -6,6 +6,7 @@ OBJ_DUMMY =\ libgamma_dummy_method_capabilities.o\ libgamma_dummy_site_initialise.o\ libgamma_dummy_site_destroy.o\ + libgamma_dummy_get_fd.o\ libgamma_dummy_site_restore.o\ libgamma_dummy_partition_initialise.o\ libgamma_dummy_partition_destroy.o\ diff --git a/mk/method-linux-drm=yes.mk b/mk/method-linux-drm=yes.mk index 6d8f56f..caf7d77 100644 --- a/mk/method-linux-drm=yes.mk +++ b/mk/method-linux-drm=yes.mk @@ -9,6 +9,7 @@ OBJ_LINUX_DRM =\ libgamma_linux_drm_method_capabilities.o\ libgamma_linux_drm_site_initialise.o\ libgamma_linux_drm_site_destroy.o\ + libgamma_linux_drm_get_fd.o\ libgamma_linux_drm_site_restore.o\ libgamma_linux_drm_partition_initialise.o\ libgamma_linux_drm_partition_destroy.o\ diff --git a/mk/method-quartz-cg=yes.mk b/mk/method-quartz-cg=yes.mk index 540c23e..dff004d 100644 --- a/mk/method-quartz-cg=yes.mk +++ b/mk/method-quartz-cg=yes.mk @@ -11,6 +11,7 @@ OBJ_QUARTZ_GC =\ libgamma_quartz_cg_method_capabilities.o\ libgamma_quartz_cg_site_initialise.o\ libgamma_quartz_cg_site_destroy.o\ + libgamma_quartz_cg_get_fd.o\ libgamma_quartz_cg_site_restore.o\ libgamma_quartz_cg_partition_initialise.o\ libgamma_quartz_cg_partition_destroy.o\ diff --git a/mk/method-w32-gdi=yes.mk b/mk/method-w32-gdi=yes.mk index 1f04c43..d11c3a4 100644 --- a/mk/method-w32-gdi=yes.mk +++ b/mk/method-w32-gdi=yes.mk @@ -6,6 +6,7 @@ OBJ_W32_GDI =\ libgamma_w32_gdi_method_capabilities.o\ libgamma_w32_gdi_site_initialise.o\ libgamma_w32_gdi_site_destroy.o\ + libgamma_w32_gdi_get_fd.o\ libgamma_w32_gdi_site_restore.o\ libgamma_w32_gdi_partition_initialise.o\ libgamma_w32_gdi_partition_destroy.o\ diff --git a/mk/method-x-randr=yes.mk b/mk/method-x-randr=yes.mk index 07a55e9..aa0c259 100644 --- a/mk/method-x-randr=yes.mk +++ b/mk/method-x-randr=yes.mk @@ -9,6 +9,7 @@ OBJ_X_RANDR =\ libgamma_x_randr_method_capabilities.o\ libgamma_x_randr_site_initialise.o\ libgamma_x_randr_site_destroy.o\ + libgamma_x_randr_get_fd.o\ libgamma_x_randr_site_restore.o\ libgamma_x_randr_partition_initialise.o\ libgamma_x_randr_partition_destroy.o\ diff --git a/mk/method-x-vidmode=yes.mk b/mk/method-x-vidmode=yes.mk index c709f20..37d547b 100644 --- a/mk/method-x-vidmode=yes.mk +++ b/mk/method-x-vidmode=yes.mk @@ -9,6 +9,7 @@ OBJ_X_VIDMODE =\ libgamma_x_vidmode_method_capabilities.o\ libgamma_x_vidmode_site_initialise.o\ libgamma_x_vidmode_site_destroy.o\ + libgamma_x_vidmode_get_fd.o\ libgamma_x_vidmode_site_restore.o\ libgamma_x_vidmode_partition_initialise.o\ libgamma_x_vidmode_partition_destroy.o\ |
