diff --git a/include/ctl-server.h b/include/ctl-server.h index 5cba6d0..70d3b65 100644 --- a/include/ctl-server.h +++ b/include/ctl-server.h @@ -30,8 +30,6 @@ struct ctl_server_actions { const char* output_name); }; -const char* default_ctl_socket_path(); - struct ctl* ctl_server_new(const char* socket_path, const struct ctl_server_actions* actions); void ctl_server_destroy(struct ctl*); diff --git a/include/util.h b/include/util.h index f9b52b1..fb71ed6 100644 --- a/include/util.h +++ b/include/util.h @@ -17,3 +17,7 @@ #pragma once #define UDIV_UP(a, b) (((a) + (b) - 1) / (b)) + +extern const char* wayvnc_version; + +const char* default_ctl_socket_path(); diff --git a/meson.build b/meson.build index bfe611e..d8849c3 100644 --- a/meson.build +++ b/meson.build @@ -90,6 +90,7 @@ sources = [ 'src/buffer.c', 'src/pixels.c', 'src/transform-util.c', + 'src/util.c', 'src/json-ipc.c', 'src/ctl-server.c', ] diff --git a/src/ctl-server.c b/src/ctl-server.c index 87d7245..08b771c 100644 --- a/src/ctl-server.c +++ b/src/ctl-server.c @@ -499,19 +499,6 @@ accept_failure: free(client); } -const char* default_ctl_socket_path() -{ - static char buffer[128]; - char* xdg_runtime = getenv("XDG_RUNTIME_DIR"); - if (xdg_runtime) - snprintf(buffer, sizeof(buffer), - "%s/wayvncctl", xdg_runtime); - else - snprintf(buffer, sizeof(buffer), - "/tmp/wayvncctl-%d", getuid()); - return buffer; -} - int ctl_server_init(struct ctl* self, const char* socket_path) { if (!socket_path) { diff --git a/src/main.c b/src/main.c index 23f4b93..44abef0 100644 --- a/src/main.c +++ b/src/main.c @@ -51,6 +51,7 @@ #include "transform-util.h" #include "usdt.h" #include "ctl-server.h" +#include "util.h" #ifdef ENABLE_PAM #include "pam_auth.h" @@ -114,14 +115,6 @@ void switch_to_output(struct wayvnc*, struct output*); void switch_to_next_output(struct wayvnc*); void switch_to_prev_output(struct wayvnc*); -#if defined(GIT_VERSION) -static const char wayvnc_version[] = GIT_VERSION; -#elif defined(PROJECT_VERSION) -static const char wayvnc_version[] = PROJECT_VERSION; -#else -static const char wayvnc_version[] = "UNKNOWN"; -#endif - struct wl_shm* wl_shm = NULL; struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf = NULL; struct gbm_device* gbm_device = NULL; diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..ac3dbe1 --- /dev/null +++ b/src/util.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2019 - 2022 Andri Yngvason + * Copyright (c) 2022 Jim Ramsay + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +#include "util.h" + +const char* wayvnc_version = +#if defined(GIT_VERSION) + GIT_VERSION; +#elif defined(PROJECT_VERSION) + PROJECT_VERSION; +#else + "UNKNOWN"; +#endif + +const char* default_ctl_socket_path() +{ + static char buffer[128]; + char* xdg_runtime = getenv("XDG_RUNTIME_DIR"); + if (xdg_runtime) + snprintf(buffer, sizeof(buffer), + "%s/wayvncctl", xdg_runtime); + else + snprintf(buffer, sizeof(buffer), + "/tmp/wayvncctl-%d", getuid()); + return buffer; +}