mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 16:36:26 +01:00
Merge branch 'master' into xwayland-wants-float
This commit is contained in:
commit
bf38081382
10 changed files with 93 additions and 48 deletions
|
@ -32,6 +32,10 @@ struct sway_output {
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
|
|
||||||
pid_t bg_pid;
|
pid_t bg_pid;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
struct wl_signal destroy;
|
||||||
|
} events;
|
||||||
};
|
};
|
||||||
|
|
||||||
void output_damage_whole(struct sway_output *output);
|
void output_damage_whole(struct sway_output *output);
|
||||||
|
|
|
@ -44,6 +44,8 @@ struct sway_server {
|
||||||
|
|
||||||
struct sway_server server;
|
struct sway_server server;
|
||||||
|
|
||||||
|
/* Prepares an unprivileged server_init by performing all privileged operations in advance */
|
||||||
|
bool server_privileged_prepare(struct sway_server *server);
|
||||||
bool server_init(struct sway_server *server);
|
bool server_init(struct sway_server *server);
|
||||||
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);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -61,40 +62,56 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
|
||||||
wordexp_t p;
|
wordexp_t p;
|
||||||
char *src = join_args(argv, j);
|
char *src = join_args(argv, j);
|
||||||
if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
|
if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
|
||||||
return cmd_results_new(CMD_INVALID, "output",
|
struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID, "output",
|
||||||
"Invalid syntax (%s).", src);
|
"Invalid syntax (%s)", src);
|
||||||
|
free(src);
|
||||||
|
wordfree(&p);
|
||||||
|
return cmd_res;
|
||||||
}
|
}
|
||||||
free(src);
|
free(src);
|
||||||
src = p.we_wordv[0];
|
src = strdup(p.we_wordv[0]);
|
||||||
if (config->reading && *src != '/') {
|
|
||||||
char *conf = strdup(config->current_config);
|
|
||||||
if (conf) {
|
|
||||||
char *conf_path = dirname(conf);
|
|
||||||
src = malloc(strlen(conf_path) + strlen(src) + 2);
|
|
||||||
if (src) {
|
|
||||||
sprintf(src, "%s/%s", conf_path, p.we_wordv[0]);
|
|
||||||
} else {
|
|
||||||
wlr_log(L_ERROR,
|
|
||||||
"Unable to allocate background source");
|
|
||||||
}
|
|
||||||
free(conf);
|
|
||||||
} else {
|
|
||||||
wlr_log(L_ERROR, "Unable to allocate background source");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!src || access(src, F_OK) == -1) {
|
|
||||||
wordfree(&p);
|
|
||||||
return cmd_results_new(CMD_INVALID, "output",
|
|
||||||
"Background file unreadable (%s).", src);
|
|
||||||
}
|
|
||||||
|
|
||||||
output->background = strdup(src);
|
|
||||||
output->background_option = strdup(mode);
|
|
||||||
if (src != p.we_wordv[0]) {
|
|
||||||
free(src);
|
|
||||||
}
|
|
||||||
wordfree(&p);
|
wordfree(&p);
|
||||||
|
if (!src) {
|
||||||
|
wlr_log(L_ERROR, "Failed to duplicate string");
|
||||||
|
return cmd_results_new(CMD_FAILURE, "output",
|
||||||
|
"Unable to allocate resource");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config->reading && *src != '/') {
|
||||||
|
// src file is inside configuration dir
|
||||||
|
|
||||||
|
char *conf = strdup(config->current_config);
|
||||||
|
if(!conf) {
|
||||||
|
wlr_log(L_ERROR, "Failed to duplicate string");
|
||||||
|
return cmd_results_new(CMD_FAILURE, "output",
|
||||||
|
"Unable to allocate resources");
|
||||||
|
}
|
||||||
|
|
||||||
|
char *conf_path = dirname(conf);
|
||||||
|
char *rel_path = src;
|
||||||
|
src = malloc(strlen(conf_path) + strlen(src) + 2);
|
||||||
|
if (!src) {
|
||||||
|
free(rel_path);
|
||||||
|
free(conf);
|
||||||
|
wlr_log(L_ERROR, "Unable to allocate memory");
|
||||||
|
return cmd_results_new(CMD_FAILURE, "output",
|
||||||
|
"Unable to allocate resources");
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(src, "%s/%s", conf_path, rel_path);
|
||||||
|
free(rel_path);
|
||||||
|
free(conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (access(src, F_OK) == -1) {
|
||||||
|
struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output",
|
||||||
|
"Unable to access background file '%s': %s", src, strerror(errno));
|
||||||
|
free(src);
|
||||||
|
return cmd_res;
|
||||||
|
}
|
||||||
|
|
||||||
|
output->background = src;
|
||||||
|
output->background_option = strdup(mode);
|
||||||
argc -= j + 1; argv += j + 1;
|
argc -= j + 1; argv += j + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,6 +219,8 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct sway_layer_surface *sway_layer =
|
struct sway_layer_surface *sway_layer =
|
||||||
wl_container_of(listener, sway_layer, output_destroy);
|
wl_container_of(listener, sway_layer, output_destroy);
|
||||||
wl_list_remove(&sway_layer->output_destroy.link);
|
wl_list_remove(&sway_layer->output_destroy.link);
|
||||||
|
wl_list_remove(&sway_layer->link);
|
||||||
|
wl_list_init(&sway_layer->link);
|
||||||
sway_layer->layer_surface->output = NULL;
|
sway_layer->layer_surface->output = NULL;
|
||||||
wlr_layer_surface_close(sway_layer->layer_surface);
|
wlr_layer_surface_close(sway_layer->layer_surface);
|
||||||
}
|
}
|
||||||
|
@ -350,10 +352,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
|
||||||
wl_signal_add(&layer_surface->surface->events.commit,
|
wl_signal_add(&layer_surface->surface->events.commit,
|
||||||
&sway_layer->surface_commit);
|
&sway_layer->surface_commit);
|
||||||
|
|
||||||
sway_layer->output_destroy.notify = handle_output_destroy;
|
|
||||||
wl_signal_add(&layer_surface->output->events.destroy,
|
|
||||||
&sway_layer->output_destroy);
|
|
||||||
|
|
||||||
sway_layer->destroy.notify = handle_destroy;
|
sway_layer->destroy.notify = handle_destroy;
|
||||||
wl_signal_add(&layer_surface->events.destroy, &sway_layer->destroy);
|
wl_signal_add(&layer_surface->events.destroy, &sway_layer->destroy);
|
||||||
sway_layer->map.notify = handle_map;
|
sway_layer->map.notify = handle_map;
|
||||||
|
@ -366,6 +364,9 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
|
||||||
layer_surface->data = sway_layer;
|
layer_surface->data = sway_layer;
|
||||||
|
|
||||||
struct sway_output *output = layer_surface->output->data;
|
struct sway_output *output = layer_surface->output->data;
|
||||||
|
sway_layer->output_destroy.notify = handle_output_destroy;
|
||||||
|
wl_signal_add(&output->events.destroy, &sway_layer->output_destroy);
|
||||||
|
|
||||||
wl_list_insert(&output->layers[layer_surface->layer], &sway_layer->link);
|
wl_list_insert(&output->layers[layer_surface->layer], &sway_layer->link);
|
||||||
|
|
||||||
// Temporarily set the layer's current state to client_pending
|
// Temporarily set the layer's current state to client_pending
|
||||||
|
|
|
@ -1199,6 +1199,8 @@ static void damage_handle_destroy(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct sway_output *output = wl_container_of(listener, output, destroy);
|
struct sway_output *output = wl_container_of(listener, output, destroy);
|
||||||
|
wl_signal_emit(&output->events.destroy, output);
|
||||||
|
|
||||||
if (output->swayc) {
|
if (output->swayc) {
|
||||||
container_destroy(output->swayc);
|
container_destroy(output->swayc);
|
||||||
}
|
}
|
||||||
|
@ -1277,6 +1279,7 @@ void output_enable(struct sway_output *output) {
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
wl_list_init(&output->layers[i]);
|
wl_list_init(&output->layers[i]);
|
||||||
}
|
}
|
||||||
|
wl_signal_init(&output->events.destroy);
|
||||||
|
|
||||||
input_manager_configure_xcursor(input_manager);
|
input_manager_configure_xcursor(input_manager);
|
||||||
|
|
||||||
|
|
|
@ -120,11 +120,12 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wants_floating(struct sway_view *view) {
|
static bool wants_floating(struct sway_view *view) {
|
||||||
struct wlr_xdg_toplevel_state *state =
|
struct wlr_xdg_toplevel *toplevel = view->wlr_xdg_surface->toplevel;
|
||||||
&view->wlr_xdg_surface->toplevel->current;
|
struct wlr_xdg_toplevel_state *state = &toplevel->current;
|
||||||
return state->min_width != 0 && state->min_height != 0
|
return (state->min_width != 0 && state->min_height != 0
|
||||||
&& state->min_width == state->max_width
|
&& state->min_width == state->max_width
|
||||||
&& state->min_height == state->max_height;
|
&& state->min_height == state->max_height)
|
||||||
|
|| toplevel->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void for_each_surface(struct sway_view *view,
|
static void for_each_surface(struct sway_view *view,
|
||||||
|
|
|
@ -119,11 +119,13 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wants_floating(struct sway_view *view) {
|
static bool wants_floating(struct sway_view *view) {
|
||||||
struct wlr_xdg_toplevel_v6_state *state =
|
struct wlr_xdg_toplevel_v6 *toplevel =
|
||||||
&view->wlr_xdg_surface_v6->toplevel->current;
|
view->wlr_xdg_surface_v6->toplevel;
|
||||||
return state->min_width != 0 && state->min_height != 0
|
struct wlr_xdg_toplevel_v6_state *state = &toplevel->current;
|
||||||
|
return (state->min_width != 0 && state->min_height != 0
|
||||||
&& state->min_width == state->max_width
|
&& state->min_width == state->max_width
|
||||||
&& state->min_height == state->max_height;
|
&& state->min_height == state->max_height)
|
||||||
|
|| toplevel->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void for_each_surface(struct sway_view *view,
|
static void for_each_surface(struct sway_view *view,
|
||||||
|
|
|
@ -174,10 +174,13 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
|
||||||
seat_set_focus_warp(seat, c, false);
|
seat_set_focus_warp(seat, c, false);
|
||||||
}
|
}
|
||||||
} else if (c->type == C_VIEW) {
|
} else if (c->type == C_VIEW) {
|
||||||
// Focus c if both of the following are true:
|
// Focus c if the following are true:
|
||||||
// - cursor is over a new view, i.e. entered a new window; and
|
// - cursor is over a new view, i.e. entered a new window; and
|
||||||
// - the new view is visible, i.e. not hidden in a stack or tab.
|
// - the new view is visible, i.e. not hidden in a stack or tab; and
|
||||||
if (c != prev_c && view_is_visible(c->sway_view)) {
|
// - the seat does not have a keyboard grab
|
||||||
|
if (!wlr_seat_keyboard_has_grab(cursor->seat->wlr_seat) &&
|
||||||
|
c != prev_c &&
|
||||||
|
view_is_visible(c->sway_view)) {
|
||||||
seat_set_focus_warp(seat, c, false);
|
seat_set_focus_warp(seat, c, false);
|
||||||
} else {
|
} else {
|
||||||
struct sway_container *next_focus =
|
struct sway_container *next_focus =
|
||||||
|
|
|
@ -359,6 +359,11 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
executable_sanity_check();
|
executable_sanity_check();
|
||||||
bool suid = false;
|
bool suid = false;
|
||||||
|
|
||||||
|
if (!server_privileged_prepare(&server)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (getuid() != geteuid() || getgid() != getegid()) {
|
if (getuid() != geteuid() || getgid() != getegid()) {
|
||||||
// Retain capabilities after setuid()
|
// Retain capabilities after setuid()
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <wlr/types/wlr_idle.h>
|
#include <wlr/types/wlr_idle.h>
|
||||||
#include <wlr/types/wlr_layer_shell.h>
|
#include <wlr/types/wlr_layer_shell.h>
|
||||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||||
|
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
||||||
#include <wlr/types/wlr_primary_selection.h>
|
#include <wlr/types/wlr_primary_selection.h>
|
||||||
#include <wlr/types/wlr_screenshooter.h>
|
#include <wlr/types/wlr_screenshooter.h>
|
||||||
#include <wlr/types/wlr_server_decoration.h>
|
#include <wlr/types/wlr_server_decoration.h>
|
||||||
|
@ -24,9 +25,8 @@
|
||||||
#include "sway/tree/layout.h"
|
#include "sway/tree/layout.h"
|
||||||
#include "sway/xwayland.h"
|
#include "sway/xwayland.h"
|
||||||
|
|
||||||
bool server_init(struct sway_server *server) {
|
bool server_privileged_prepare(struct sway_server *server) {
|
||||||
wlr_log(L_DEBUG, "Initializing Wayland server");
|
wlr_log(L_DEBUG, "Preparing Wayland server initialization");
|
||||||
|
|
||||||
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, NULL);
|
server->backend = wlr_backend_autocreate(server->wl_display, NULL);
|
||||||
|
@ -35,6 +35,12 @@ bool server_init(struct sway_server *server) {
|
||||||
wlr_log(L_ERROR, "Unable to create backend");
|
wlr_log(L_ERROR, "Unable to create backend");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool server_init(struct sway_server *server) {
|
||||||
|
wlr_log(L_DEBUG, "Initializing Wayland server");
|
||||||
|
|
||||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
|
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
|
||||||
assert(renderer);
|
assert(renderer);
|
||||||
|
|
||||||
|
@ -99,6 +105,7 @@ bool server_init(struct sway_server *server) {
|
||||||
deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
|
deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
|
||||||
|
|
||||||
wlr_linux_dmabuf_create(server->wl_display, renderer);
|
wlr_linux_dmabuf_create(server->wl_display, renderer);
|
||||||
|
wlr_export_dmabuf_manager_v1_create(server->wl_display);
|
||||||
|
|
||||||
server->socket = wl_display_add_socket_auto(server->wl_display);
|
server->socket = wl_display_add_socket_auto(server->wl_display);
|
||||||
if (!server->socket) {
|
if (!server->socket) {
|
||||||
|
|
Loading…
Reference in a new issue