mirror of
https://github.com/swaywm/sway.git
synced 2025-11-18 06:59:48 -05:00
Merge branch 'master' into master
This commit is contained in:
commit
3c26536267
29 changed files with 697 additions and 281 deletions
|
|
@ -533,11 +533,10 @@ struct sway_container *container_parent(struct sway_container *container,
|
|||
return container;
|
||||
}
|
||||
|
||||
static struct sway_container *container_at_view(struct sway_container *swayc,
|
||||
double lx, double ly,
|
||||
static void surface_at_view(struct sway_container *swayc, double lx, double ly,
|
||||
struct wlr_surface **surface, double *sx, double *sy) {
|
||||
if (!sway_assert(swayc->type == C_VIEW, "Expected a view")) {
|
||||
return NULL;
|
||||
return;
|
||||
}
|
||||
struct sway_view *sview = swayc->sway_view;
|
||||
double view_sx = lx - sview->x;
|
||||
|
|
@ -567,9 +566,7 @@ static struct sway_container *container_at_view(struct sway_container *swayc,
|
|||
*sx = _sx;
|
||||
*sy = _sy;
|
||||
*surface = _surface;
|
||||
return swayc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -682,7 +679,8 @@ struct sway_container *tiling_container_at(
|
|||
struct sway_container *con, double lx, double ly,
|
||||
struct wlr_surface **surface, double *sx, double *sy) {
|
||||
if (con->type == C_VIEW) {
|
||||
return container_at_view(con, lx, ly, surface, sx, sy);
|
||||
surface_at_view(con, lx, ly, surface, sx, sy);
|
||||
return con;
|
||||
}
|
||||
if (!con->children->length) {
|
||||
return NULL;
|
||||
|
|
@ -745,7 +743,7 @@ struct sway_container *container_at(struct sway_container *workspace,
|
|||
struct sway_container *focus =
|
||||
seat_get_focus_inactive(seat, &root_container);
|
||||
if (focus && focus->type == C_VIEW) {
|
||||
container_at_view(focus, lx, ly, surface, sx, sy);
|
||||
surface_at_view(focus, lx, ly, surface, sx, sy);
|
||||
if (*surface && surface_is_popup(*surface)) {
|
||||
return focus;
|
||||
}
|
||||
|
|
@ -1163,19 +1161,16 @@ void container_floating_translate(struct sway_container *con,
|
|||
double x_amount, double y_amount) {
|
||||
con->x += x_amount;
|
||||
con->y += y_amount;
|
||||
con->current.swayc_x += x_amount;
|
||||
con->current.swayc_y += y_amount;
|
||||
if (con->type == C_VIEW) {
|
||||
con->sway_view->x += x_amount;
|
||||
con->sway_view->y += y_amount;
|
||||
con->current.view_x += x_amount;
|
||||
con->current.view_y += y_amount;
|
||||
} else {
|
||||
for (int i = 0; i < con->children->length; ++i) {
|
||||
struct sway_container *child = con->children->items[i];
|
||||
container_floating_translate(child, x_amount, y_amount);
|
||||
}
|
||||
}
|
||||
container_set_dirty(con);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1185,7 +1180,7 @@ void container_floating_translate(struct sway_container *con,
|
|||
* one, otherwise we'll choose whichever output is closest to the container's
|
||||
* center.
|
||||
*/
|
||||
static struct sway_container *container_floating_find_output(
|
||||
struct sway_container *container_floating_find_output(
|
||||
struct sway_container *con) {
|
||||
double center_x = con->x + con->width / 2;
|
||||
double center_y = con->y + con->height / 2;
|
||||
|
|
@ -1219,9 +1214,7 @@ void container_floating_move_to(struct sway_container *con,
|
|||
"Expected a floating container")) {
|
||||
return;
|
||||
}
|
||||
desktop_damage_whole_container(con);
|
||||
container_floating_translate(con, lx - con->x, ly - con->y);
|
||||
desktop_damage_whole_container(con);
|
||||
struct sway_container *old_workspace = container_parent(con, C_WORKSPACE);
|
||||
struct sway_container *new_output = container_floating_find_output(con);
|
||||
if (!sway_assert(new_output, "Unable to find any output")) {
|
||||
|
|
@ -1239,6 +1232,17 @@ void container_floating_move_to(struct sway_container *con,
|
|||
}
|
||||
}
|
||||
|
||||
void container_floating_move_to_center(struct sway_container *con) {
|
||||
if (!sway_assert(container_is_floating(con),
|
||||
"Expected a floating container")) {
|
||||
return;
|
||||
}
|
||||
struct sway_container *ws = container_parent(con, C_WORKSPACE);
|
||||
double new_lx = ws->x + (ws->width - con->width) / 2;
|
||||
double new_ly = ws->y + (ws->height - con->height) / 2;
|
||||
container_floating_translate(con, new_lx - con->x, new_ly - con->y);
|
||||
}
|
||||
|
||||
void container_set_dirty(struct sway_container *container) {
|
||||
if (container->dirty) {
|
||||
return;
|
||||
|
|
@ -1318,6 +1322,11 @@ void container_set_fullscreen(struct sway_container *container, bool enable) {
|
|||
container->y = container->saved_y;
|
||||
container->width = container->saved_width;
|
||||
container->height = container->saved_height;
|
||||
struct sway_container *output =
|
||||
container_floating_find_output(container);
|
||||
if (!container_has_ancestor(container, output)) {
|
||||
container_floating_move_to_center(container);
|
||||
}
|
||||
} else {
|
||||
container->width = container->saved_width;
|
||||
container->height = container->saved_height;
|
||||
|
|
|
|||
|
|
@ -142,49 +142,55 @@ struct sway_container *container_remove_child(struct sway_container *child) {
|
|||
|
||||
void container_move_to(struct sway_container *container,
|
||||
struct sway_container *destination) {
|
||||
if (!sway_assert(container->type == C_CONTAINER ||
|
||||
container->type == C_VIEW, "Expected a container or view")) {
|
||||
return;
|
||||
}
|
||||
if (container == destination
|
||||
|| container_has_ancestor(container, destination)) {
|
||||
return;
|
||||
}
|
||||
struct sway_container *old_parent = NULL;
|
||||
struct sway_container *new_parent = NULL;
|
||||
if (container_is_floating(container)) {
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
struct sway_container *old_parent = container_remove_child(container);
|
||||
container->width = container->height = 0;
|
||||
container->saved_width = container->saved_height = 0;
|
||||
|
||||
struct sway_container *new_parent, *new_parent_focus;
|
||||
struct sway_seat *seat = input_manager_get_default_seat(input_manager);
|
||||
|
||||
// Get the focus of the destination before we change it.
|
||||
new_parent_focus = seat_get_focus_inactive(seat, destination);
|
||||
if (destination->type == C_VIEW) {
|
||||
new_parent = container_add_sibling(destination, container);
|
||||
// Resolve destination into a workspace
|
||||
struct sway_container *new_ws = NULL;
|
||||
if (destination->type == C_OUTPUT) {
|
||||
new_ws = output_get_active_workspace(destination->sway_output);
|
||||
} else if (destination->type == C_WORKSPACE) {
|
||||
new_ws = destination;
|
||||
} else {
|
||||
new_ws = container_parent(destination, C_WORKSPACE);
|
||||
}
|
||||
if (!new_ws) {
|
||||
// This can happen if the user has run "move container to mark foo",
|
||||
// where mark foo is on a hidden scratchpad container.
|
||||
return;
|
||||
}
|
||||
struct sway_container *old_output =
|
||||
container_parent(container, C_OUTPUT);
|
||||
old_parent = container_remove_child(container);
|
||||
container_add_child(new_ws->sway_workspace->floating, container);
|
||||
// If changing output, center it within the workspace
|
||||
if (old_output != new_ws->parent && !container->is_fullscreen) {
|
||||
container_floating_move_to_center(container);
|
||||
}
|
||||
} else {
|
||||
new_parent = destination;
|
||||
container_add_child(destination, container);
|
||||
old_parent = container_remove_child(container);
|
||||
container->width = container->height = 0;
|
||||
container->saved_width = container->saved_height = 0;
|
||||
|
||||
if (destination->type == C_VIEW) {
|
||||
new_parent = container_add_sibling(destination, container);
|
||||
} else {
|
||||
new_parent = destination;
|
||||
container_add_child(destination, container);
|
||||
}
|
||||
}
|
||||
|
||||
wl_signal_emit(&container->events.reparent, old_parent);
|
||||
|
||||
if (container->type == C_WORKSPACE) {
|
||||
// If moving a workspace to a new output, maybe create a new workspace
|
||||
// on the previous output
|
||||
if (old_parent->children->length == 0) {
|
||||
char *ws_name = workspace_next_name(old_parent->name);
|
||||
struct sway_container *ws = workspace_create(old_parent, ws_name);
|
||||
free(ws_name);
|
||||
seat_set_focus(seat, ws);
|
||||
}
|
||||
|
||||
// Try to remove an empty workspace from the destination output.
|
||||
container_reap_empty_recursive(new_parent_focus);
|
||||
|
||||
container_sort_workspaces(new_parent);
|
||||
seat_set_focus(seat, new_parent);
|
||||
workspace_output_raise_priority(container, old_parent, new_parent);
|
||||
ipc_event_workspace(NULL, container, "move");
|
||||
} else if (container->type == C_VIEW) {
|
||||
if (container->type == C_VIEW) {
|
||||
ipc_event_window(container, "move");
|
||||
}
|
||||
container_notify_subtree_changed(old_parent);
|
||||
|
|
@ -859,7 +865,7 @@ struct sway_container *container_split(struct sway_container *child,
|
|||
}
|
||||
if (child->type == C_WORKSPACE && child->children->length == 0) {
|
||||
// Special case: this just behaves like splitt
|
||||
child->prev_layout = child->layout;
|
||||
child->prev_split_layout = child->layout;
|
||||
child->layout = layout;
|
||||
return child;
|
||||
}
|
||||
|
|
@ -870,7 +876,7 @@ struct sway_container *container_split(struct sway_container *child,
|
|||
|
||||
remove_gaps(child);
|
||||
|
||||
cont->prev_layout = L_NONE;
|
||||
cont->prev_split_layout = L_NONE;
|
||||
cont->width = child->width;
|
||||
cont->height = child->height;
|
||||
cont->x = child->x;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
|
|
@ -456,7 +457,13 @@ static struct sway_container *select_workspace(struct sway_view *view) {
|
|||
if (criteria->type == CT_ASSIGN_WORKSPACE) {
|
||||
ws = workspace_by_name(criteria->target);
|
||||
if (!ws) {
|
||||
ws = workspace_create(NULL, criteria->target);
|
||||
if (strcasecmp(criteria->target, "back_and_forth") == 0) {
|
||||
if (prev_workspace_name) {
|
||||
ws = workspace_create(NULL, prev_workspace_name);
|
||||
}
|
||||
} else {
|
||||
ws = workspace_create(NULL, criteria->target);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
|
|
@ -891,6 +898,15 @@ static bool find_by_mark_iterator(struct sway_container *con,
|
|||
return con->type == C_VIEW && view_has_mark(con->sway_view, mark);
|
||||
}
|
||||
|
||||
struct sway_view *view_find_mark(char *mark) {
|
||||
struct sway_container *container = container_find(&root_container,
|
||||
find_by_mark_iterator, mark);
|
||||
if (!container) {
|
||||
return NULL;
|
||||
}
|
||||
return container->sway_view;
|
||||
}
|
||||
|
||||
bool view_find_and_unmark(char *mark) {
|
||||
struct sway_container *container = container_find(&root_container,
|
||||
find_by_mark_iterator, mark);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
static struct sway_container *get_workspace_initial_output(const char *name) {
|
||||
struct sway_container *workspace_get_initial_output(const char *name) {
|
||||
struct sway_container *parent;
|
||||
// Search for workspace<->output pair
|
||||
int e = config->workspace_outputs->length;
|
||||
|
|
@ -48,7 +48,7 @@ static struct sway_container *get_workspace_initial_output(const char *name) {
|
|||
struct sway_container *workspace_create(struct sway_container *output,
|
||||
const char *name) {
|
||||
if (output == NULL) {
|
||||
output = get_workspace_initial_output(name);
|
||||
output = workspace_get_initial_output(name);
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "Added workspace %s for output %s", name, output->name);
|
||||
|
|
@ -59,7 +59,7 @@ struct sway_container *workspace_create(struct sway_container *output,
|
|||
workspace->width = output->width;
|
||||
workspace->height = output->height;
|
||||
workspace->name = !name ? NULL : strdup(name);
|
||||
workspace->prev_layout = L_NONE;
|
||||
workspace->prev_split_layout = L_NONE;
|
||||
workspace->layout = container_get_default_layout(output);
|
||||
|
||||
struct sway_workspace *swayws = calloc(1, sizeof(struct sway_workspace));
|
||||
|
|
@ -250,6 +250,7 @@ struct sway_container *workspace_by_name(const char *name) {
|
|||
current_workspace = container_parent(focus, C_WORKSPACE);
|
||||
current_output = container_parent(focus, C_OUTPUT);
|
||||
}
|
||||
|
||||
if (strcmp(name, "prev") == 0) {
|
||||
return workspace_prev(current_workspace);
|
||||
} else if (strcmp(name, "prev_on_output") == 0) {
|
||||
|
|
@ -260,6 +261,9 @@ struct sway_container *workspace_by_name(const char *name) {
|
|||
return workspace_output_next(current_output);
|
||||
} else if (strcmp(name, "current") == 0) {
|
||||
return current_workspace;
|
||||
} else if (strcasecmp(name, "back_and_forth") == 0) {
|
||||
return prev_workspace_name ? container_find(&root_container,
|
||||
_workspace_by_name, (void *)prev_workspace_name) : NULL;
|
||||
} else {
|
||||
return container_find(&root_container, _workspace_by_name,
|
||||
(void *)name);
|
||||
|
|
@ -364,7 +368,8 @@ struct sway_container *workspace_prev(struct sway_container *current) {
|
|||
return workspace_prev_next_impl(current, false);
|
||||
}
|
||||
|
||||
bool workspace_switch(struct sway_container *workspace) {
|
||||
bool workspace_switch(struct sway_container *workspace,
|
||||
bool no_auto_back_and_forth) {
|
||||
if (!workspace) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -379,7 +384,7 @@ bool workspace_switch(struct sway_container *workspace) {
|
|||
active_ws = container_parent(focus, C_WORKSPACE);
|
||||
}
|
||||
|
||||
if (config->auto_back_and_forth
|
||||
if (!no_auto_back_and_forth && config->auto_back_and_forth
|
||||
&& active_ws == workspace
|
||||
&& prev_workspace_name) {
|
||||
struct sway_container *new_ws = workspace_by_name(prev_workspace_name);
|
||||
|
|
@ -406,17 +411,20 @@ bool workspace_switch(struct sway_container *workspace) {
|
|||
struct sway_container *floating =
|
||||
next_output_prev_ws->sway_workspace->floating;
|
||||
bool has_sticky = false;
|
||||
for (int i = 0; i < floating->children->length; ++i) {
|
||||
struct sway_container *floater = floating->children->items[i];
|
||||
if (floater->is_sticky) {
|
||||
has_sticky = true;
|
||||
container_remove_child(floater);
|
||||
container_add_child(workspace->sway_workspace->floating, floater);
|
||||
if (floater == focus) {
|
||||
seat_set_focus(seat, NULL);
|
||||
seat_set_focus(seat, floater);
|
||||
if (workspace != next_output_prev_ws) {
|
||||
for (int i = 0; i < floating->children->length; ++i) {
|
||||
struct sway_container *floater = floating->children->items[i];
|
||||
if (floater->is_sticky) {
|
||||
has_sticky = true;
|
||||
container_remove_child(floater);
|
||||
container_add_child(workspace->sway_workspace->floating,
|
||||
floater);
|
||||
if (floater == focus) {
|
||||
seat_set_focus(seat, NULL);
|
||||
seat_set_focus(seat, floater);
|
||||
}
|
||||
--i;
|
||||
}
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue