mirror of
https://github.com/swaywm/sway.git
synced 2026-03-27 07:58:40 -04:00
Merge 2d335bac57 into 40aabb80c6
This commit is contained in:
commit
dc6060c4b2
1 changed files with 29 additions and 11 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <strings.h>
|
||||||
#include <wlr/config.h>
|
#include <wlr/config.h>
|
||||||
#include <wlr/backend/headless.h>
|
#include <wlr/backend/headless.h>
|
||||||
#include <wlr/backend/multi.h>
|
#include <wlr/backend/multi.h>
|
||||||
|
|
@ -9,23 +10,28 @@
|
||||||
#include "sway/server.h"
|
#include "sway/server.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
struct create_result {
|
||||||
|
bool done;
|
||||||
|
struct wlr_output *new_output;
|
||||||
|
};
|
||||||
|
|
||||||
static void create_output(struct wlr_backend *backend, void *data) {
|
static void create_output(struct wlr_backend *backend, void *data) {
|
||||||
bool *done = data;
|
struct create_result *result = data;
|
||||||
if (*done) {
|
if (result->done) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wlr_backend_is_wl(backend)) {
|
if (wlr_backend_is_wl(backend)) {
|
||||||
wlr_wl_output_create(backend);
|
result->new_output = wlr_wl_output_create(backend);
|
||||||
*done = true;
|
result->done = true;
|
||||||
} else if (wlr_backend_is_headless(backend)) {
|
} else if (wlr_backend_is_headless(backend)) {
|
||||||
wlr_headless_add_output(backend, 1920, 1080);
|
result->new_output = wlr_headless_add_output(backend, 1920, 1080);
|
||||||
*done = true;
|
result->done = true;
|
||||||
}
|
}
|
||||||
#if WLR_HAS_X11_BACKEND
|
#if WLR_HAS_X11_BACKEND
|
||||||
else if (wlr_backend_is_x11(backend)) {
|
else if (wlr_backend_is_x11(backend)) {
|
||||||
wlr_x11_output_create(backend);
|
result->new_output = wlr_x11_output_create(backend);
|
||||||
*done = true;
|
result->done = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -37,13 +43,25 @@ struct cmd_results *cmd_create_output(int argc, char **argv) {
|
||||||
sway_assert(wlr_backend_is_multi(server.backend),
|
sway_assert(wlr_backend_is_multi(server.backend),
|
||||||
"Expected a multi backend");
|
"Expected a multi backend");
|
||||||
|
|
||||||
bool done = false;
|
struct create_result result = { false, NULL };
|
||||||
wlr_multi_for_each_backend(server.backend, create_output, &done);
|
wlr_multi_for_each_backend(server.backend, create_output, &result);
|
||||||
|
|
||||||
if (!done) {
|
if (!result.done) {
|
||||||
return cmd_results_new(CMD_INVALID,
|
return cmd_results_new(CMD_INVALID,
|
||||||
"Can only create outputs for Wayland, X11 or headless backends");
|
"Can only create outputs for Wayland, X11 or headless backends");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool should_set_name = argc >= 2 && strcasecmp(argv[0], "name") == 0;
|
||||||
|
|
||||||
|
if (should_set_name) {
|
||||||
|
if (NULL == result.new_output) {
|
||||||
|
return cmd_results_new(CMD_FAILURE,
|
||||||
|
"Cannot assign name to new output");
|
||||||
|
}
|
||||||
|
|
||||||
|
sway_log(SWAY_DEBUG, "Set new output name to %s", argv[1]);
|
||||||
|
wlr_output_set_name(result.new_output, argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue