Load a config file
parent
c1210f1426
commit
20cd7725f6
|
@ -51,6 +51,7 @@ sources = [
|
||||||
'src/keyboard.c',
|
'src/keyboard.c',
|
||||||
'src/seat.c',
|
'src/seat.c',
|
||||||
'src/smooth.c',
|
'src/smooth.c',
|
||||||
|
'src/cfg.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|
35
src/main.c
35
src/main.c
|
@ -45,6 +45,7 @@
|
||||||
#include "pointer.h"
|
#include "pointer.h"
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "seat.h"
|
#include "seat.h"
|
||||||
|
#include "cfg.h"
|
||||||
|
|
||||||
#define DEFAULT_ADDRESS "127.0.0.1"
|
#define DEFAULT_ADDRESS "127.0.0.1"
|
||||||
#define DEFAULT_PORT 5900
|
#define DEFAULT_PORT 5900
|
||||||
|
@ -60,6 +61,7 @@ struct wayvnc {
|
||||||
struct wl_registry* registry;
|
struct wl_registry* registry;
|
||||||
struct wl_list outputs;
|
struct wl_list outputs;
|
||||||
struct wl_list seats;
|
struct wl_list seats;
|
||||||
|
struct cfg cfg;
|
||||||
|
|
||||||
struct zwp_virtual_keyboard_manager_v1* keyboard_manager;
|
struct zwp_virtual_keyboard_manager_v1* keyboard_manager;
|
||||||
|
|
||||||
|
@ -503,6 +505,7 @@ int wayvnc_usage(FILE* stream, int rc)
|
||||||
static const char* usage =
|
static const char* usage =
|
||||||
"Usage: wayvnc [options] [address [port]]\n"
|
"Usage: wayvnc [options] [address [port]]\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
" -C,--config=<path> Select a config file.\n"
|
||||||
" -c,--frame-capturing=screencopy|dmabuf Select frame capturing backend.\n"
|
" -c,--frame-capturing=screencopy|dmabuf Select frame capturing backend.\n"
|
||||||
" -o,--output=<id> Select output to capture.\n"
|
" -o,--output=<id> Select output to capture.\n"
|
||||||
" -k,--keyboard=<layout> Select keyboard layout.\n"
|
" -k,--keyboard=<layout> Select keyboard layout.\n"
|
||||||
|
@ -519,16 +522,19 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
struct wayvnc self = { 0 };
|
struct wayvnc self = { 0 };
|
||||||
|
|
||||||
const char* address = DEFAULT_ADDRESS;
|
const char* cfg_file = NULL;
|
||||||
int port = DEFAULT_PORT;
|
|
||||||
|
const char* address = NULL;
|
||||||
|
int port = 0;
|
||||||
|
|
||||||
int output_id = -1;
|
int output_id = -1;
|
||||||
enum frame_capture_backend_type fcbackend = FRAME_CAPTURE_BACKEND_NONE;
|
enum frame_capture_backend_type fcbackend = FRAME_CAPTURE_BACKEND_NONE;
|
||||||
const char* seat_name = NULL;
|
const char* seat_name = NULL;
|
||||||
|
|
||||||
static const char* shortopts = "c:o:k:s:h";
|
static const char* shortopts = "Cc:o:k:s:h";
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
|
{ "config", required_argument, NULL, 'C' },
|
||||||
{ "frame-capturing", required_argument, NULL, 'c' },
|
{ "frame-capturing", required_argument, NULL, 'c' },
|
||||||
{ "output", required_argument, NULL, 'o' },
|
{ "output", required_argument, NULL, 'o' },
|
||||||
{ "keyboard", required_argument, NULL, 'k' },
|
{ "keyboard", required_argument, NULL, 'k' },
|
||||||
|
@ -543,6 +549,9 @@ int main(int argc, char* argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case 'C':
|
||||||
|
cfg_file = optarg;
|
||||||
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
fcbackend = frame_capture_backend_from_string(optarg);
|
fcbackend = frame_capture_backend_from_string(optarg);
|
||||||
if (fcbackend == FRAME_CAPTURE_BACKEND_NONE) {
|
if (fcbackend == FRAME_CAPTURE_BACKEND_NONE) {
|
||||||
|
@ -576,6 +585,26 @@ int main(int argc, char* argv[])
|
||||||
if (n_args >= 2)
|
if (n_args >= 2)
|
||||||
port = atoi(argv[optind + 1]);
|
port = atoi(argv[optind + 1]);
|
||||||
|
|
||||||
|
int cfg_rc = cfg_load(&self.cfg, cfg_file);
|
||||||
|
if (cfg_file && cfg_rc != 0) {
|
||||||
|
if (cfg_rc > 0) {
|
||||||
|
log_error("Failed to load config. Error on line %d\n",
|
||||||
|
cfg_rc);
|
||||||
|
} else {
|
||||||
|
log_error("Failed to load config. %m\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cfg_rc == 0) {
|
||||||
|
if (!address) address = self.cfg.address;
|
||||||
|
if (!port) port = self.cfg.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!address) address = DEFAULT_ADDRESS;
|
||||||
|
if (!port) port = DEFAULT_PORT;
|
||||||
|
|
||||||
if (init_wayland(&self) < 0) {
|
if (init_wayland(&self) < 0) {
|
||||||
log_error("Failed to initialise wayland\n");
|
log_error("Failed to initialise wayland\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue