mirror of
https://github.com/swaywm/sway.git
synced 2026-05-03 06:46:26 -04:00
add headless outputs option
This commit is contained in:
parent
447dcd3cb3
commit
fe29ebc2a2
3 changed files with 60 additions and 6 deletions
|
|
@ -43,7 +43,7 @@ struct sway_server {
|
||||||
|
|
||||||
struct sway_server server;
|
struct sway_server server;
|
||||||
|
|
||||||
bool server_init(struct sway_server *server);
|
bool server_init(struct sway_server *server, bool headless);
|
||||||
void server_fini(struct sway_server *server);
|
void server_fini(struct sway_server *server);
|
||||||
void server_run(struct sway_server *server);
|
void server_run(struct sway_server *server);
|
||||||
|
|
||||||
|
|
|
||||||
11
sway/main.c
11
sway/main.c
|
|
@ -250,13 +250,14 @@ static void drop_permissions(bool keep_caps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
static int verbose = 0, debug = 0, validate = 0;
|
static int verbose = 0, debug = 0, validate = 0, headless = 0;
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"config", required_argument, NULL, 'c'},
|
{"config", required_argument, NULL, 'c'},
|
||||||
{"validate", no_argument, NULL, 'C'},
|
{"validate", no_argument, NULL, 'C'},
|
||||||
{"debug", no_argument, NULL, 'd'},
|
{"debug", no_argument, NULL, 'd'},
|
||||||
|
{"headless", no_argument, NULL, 'H'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"verbose", no_argument, NULL, 'V'},
|
{"verbose", no_argument, NULL, 'V'},
|
||||||
{"get-socketpath", no_argument, NULL, 'p'},
|
{"get-socketpath", no_argument, NULL, 'p'},
|
||||||
|
|
@ -272,6 +273,7 @@ int main(int argc, char **argv) {
|
||||||
" -c, --config <config> Specify a config file.\n"
|
" -c, --config <config> Specify a config file.\n"
|
||||||
" -C, --validate Check the validity of the config file, then exit.\n"
|
" -C, --validate Check the validity of the config file, then exit.\n"
|
||||||
" -d, --debug Enables full logging, including debug information.\n"
|
" -d, --debug Enables full logging, including debug information.\n"
|
||||||
|
" -H, --headless Starts sway with the headless backend.\n"
|
||||||
" -v, --version Show the version number and quit.\n"
|
" -v, --version Show the version number and quit.\n"
|
||||||
" -V, --verbose Enables more verbose logging.\n"
|
" -V, --verbose Enables more verbose logging.\n"
|
||||||
" --get-socketpath Gets the IPC socket path and prints it, then exits.\n"
|
" --get-socketpath Gets the IPC socket path and prints it, then exits.\n"
|
||||||
|
|
@ -288,7 +290,7 @@ int main(int argc, char **argv) {
|
||||||
int c;
|
int c;
|
||||||
while (1) {
|
while (1) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
c = getopt_long(argc, argv, "hCdvVc:", long_options, &option_index);
|
c = getopt_long(argc, argv, "hCHdvVc:", long_options, &option_index);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -306,6 +308,9 @@ int main(int argc, char **argv) {
|
||||||
case 'd': // debug
|
case 'd': // debug
|
||||||
debug = 1;
|
debug = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'H':
|
||||||
|
headless = 1;
|
||||||
|
break;
|
||||||
case 'v': // version
|
case 'v': // version
|
||||||
fprintf(stdout, "sway version " SWAY_VERSION "\n");
|
fprintf(stdout, "sway version " SWAY_VERSION "\n");
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
|
@ -384,7 +389,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
layout_init();
|
layout_init();
|
||||||
|
|
||||||
if (!server_init(&server)) {
|
if (!server_init(&server, headless)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/backend.h>
|
#include <wlr/backend.h>
|
||||||
#include <wlr/backend/session.h>
|
#include <wlr/backend/session.h>
|
||||||
|
#include <wlr/backend/headless.h>
|
||||||
#include <wlr/render/wlr_renderer.h>
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/types/wlr_compositor.h>
|
#include <wlr/types/wlr_compositor.h>
|
||||||
#include <wlr/types/wlr_gamma_control.h>
|
#include <wlr/types/wlr_gamma_control.h>
|
||||||
|
|
@ -38,12 +39,60 @@ static void server_ready(struct wl_listener *listener, void *data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool server_init(struct sway_server *server) {
|
static size_t parse_outputs_env(const char *name) {
|
||||||
|
const char *outputs_str = getenv(name);
|
||||||
|
if (outputs_str == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *end;
|
||||||
|
int outputs = (int)strtol(outputs_str, &end, 10);
|
||||||
|
if (*end || outputs < 0) {
|
||||||
|
wlr_log(L_ERROR, "%s specified with invalid integer, ignoring", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct wlr_backend *create_headless_backend(struct wl_display *display) {
|
||||||
|
const char *outputs_env = "SWAY_HEADLESS_OUTPUTS";
|
||||||
|
const char *outputs_str = getenv(outputs_env);
|
||||||
|
int outputs = 1;
|
||||||
|
|
||||||
|
if (outputs_str != NULL) {
|
||||||
|
char *end;
|
||||||
|
outputs = (int)strtol(outputs_str, &end, 10);
|
||||||
|
if (*end || outputs < 0) {
|
||||||
|
outputs = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_backend *backend = wlr_headless_backend_create(display);
|
||||||
|
|
||||||
|
if (backend == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < outputs; ++i) {
|
||||||
|
wlr_headless_add_output(backend, 1280, 720);
|
||||||
|
}
|
||||||
|
|
||||||
|
return backend;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool server_init(struct sway_server *server, bool headless) {
|
||||||
wlr_log(L_DEBUG, "Initializing Wayland server");
|
wlr_log(L_DEBUG, "Initializing Wayland server");
|
||||||
|
|
||||||
server->wl_display = wl_display_create();
|
server->wl_display = wl_display_create();
|
||||||
server->wl_event_loop = wl_display_get_event_loop(server->wl_display);
|
server->wl_event_loop = wl_display_get_event_loop(server->wl_display);
|
||||||
server->backend = wlr_backend_autocreate(server->wl_display);
|
|
||||||
|
if (headless) {
|
||||||
|
server->backend = create_headless_backend(server->wl_display);
|
||||||
|
} else {
|
||||||
|
server->backend = wlr_backend_autocreate(server->wl_display);
|
||||||
|
}
|
||||||
|
assert(server->backend);
|
||||||
|
|
||||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
|
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
|
||||||
assert(renderer);
|
assert(renderer);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue