mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 18:01:29 +00:00
update visibility + container info functions
This commit is contained in:
parent
dfe0dda8d0
commit
5678d824e4
|
@ -103,6 +103,10 @@ swayc_t *swayc_active_workspace_for(swayc_t *view);
|
||||||
|
|
||||||
bool swayc_is_fullscreen(swayc_t *view);
|
bool swayc_is_fullscreen(swayc_t *view);
|
||||||
bool swayc_is_active(swayc_t *view);
|
bool swayc_is_active(swayc_t *view);
|
||||||
|
// Is `parent` the parent of `child`
|
||||||
|
bool swayc_is_parent_of(swayc_t *parent, swayc_t *child);
|
||||||
|
// Is `child` a child of `parent`
|
||||||
|
bool swayc_is_child_of(swayc_t *child, swayc_t *parent);
|
||||||
|
|
||||||
// Mapping functions
|
// Mapping functions
|
||||||
|
|
||||||
|
|
104
sway/container.c
104
sway/container.c
|
@ -547,6 +547,20 @@ bool swayc_is_active(swayc_t *view) {
|
||||||
return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_ACTIVATED);
|
return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_ACTIVATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool swayc_is_parent_of(swayc_t *parent, swayc_t *child) {
|
||||||
|
while (child != &root_container) {
|
||||||
|
child = child->parent;
|
||||||
|
if (child == parent) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool swayc_is_child_of(swayc_t *child, swayc_t *parent) {
|
||||||
|
return swayc_is_parent_of(parent, child);
|
||||||
|
}
|
||||||
|
|
||||||
// Mapping
|
// Mapping
|
||||||
|
|
||||||
void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
|
void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
|
||||||
|
@ -568,58 +582,64 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_view_visibility(swayc_t *view, void *data) {
|
void update_visibility_output(swayc_t *container, wlc_handle output) {
|
||||||
if (!ASSERT_NONNULL(view)) {
|
// Inherit visibility
|
||||||
return;
|
swayc_t *parent = container->parent;
|
||||||
|
container->visible = parent->visible;
|
||||||
|
// special cases where visibility depends on focus
|
||||||
|
if (parent->type == C_OUTPUT
|
||||||
|
|| parent->layout == L_TABBED
|
||||||
|
|| parent->layout == L_STACKED) {
|
||||||
|
container->visible = parent->focused == container;
|
||||||
}
|
}
|
||||||
// TODO add something like this.
|
// Set visibility and output for view
|
||||||
// if (container->type == C_ROOT) {
|
if (container->type == C_VIEW) {
|
||||||
// container->visible = true;
|
wlc_view_set_output(container->handle, output);
|
||||||
// } else {
|
wlc_view_set_mask(container->handle, container->visible ? VISIBLE : 0);
|
||||||
// // Inherit visibility
|
if (container->visible) {
|
||||||
// swayc_t *parent = container->parent;
|
wlc_view_bring_to_front(container->handle);
|
||||||
// container->visible = parent->visible;
|
|
||||||
// // special cases where visibility depends on focus
|
|
||||||
// if (parent->type == C_OUTPUT || parent->layout == L_TABBED ||
|
|
||||||
// parent->layout == L_STACKED) {
|
|
||||||
// container->visible = parent->focused == container;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
bool visible = *(bool *)data;
|
|
||||||
if (view->type == C_VIEW) {
|
|
||||||
wlc_view_set_output(view->handle, swayc_parent_by_type(view, C_OUTPUT)->handle);
|
|
||||||
wlc_view_set_mask(view->handle, visible ? VISIBLE : 0);
|
|
||||||
if (visible) {
|
|
||||||
wlc_view_bring_to_front(view->handle);
|
|
||||||
} else {
|
} else {
|
||||||
wlc_view_send_to_back(view->handle);
|
wlc_view_send_to_back(container->handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Update visibility for children
|
||||||
|
else if (container->children) {
|
||||||
|
int i, len = container->children->length;
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
update_visibility_output(container->children->items[i], output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view->visible = visible;
|
|
||||||
sway_log(L_DEBUG, "Container %p is now %s", view, visible ? "visible" : "invisible");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_visibility(swayc_t *container) {
|
void update_visibility(swayc_t *container) {
|
||||||
if (!container) {
|
if (!container) return;
|
||||||
return;
|
switch (container->type) {
|
||||||
}
|
case C_ROOT:
|
||||||
swayc_t *ws;
|
container->visible = true;
|
||||||
if (container->type == C_ROOT || container->type == C_OUTPUT) {
|
if (container->children) {
|
||||||
int i, len = container->children->length;
|
int i, len = container->children->length;
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
update_visibility(container->children->items[i]);
|
update_visibility(container->children->items[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (container->type == C_WORKSPACE) {
|
|
||||||
container->visible = container->parent->focused == container;
|
case C_OUTPUT:
|
||||||
ws = container;
|
container->visible = true;
|
||||||
} else {
|
if (container->children) {
|
||||||
ws = swayc_active_workspace_for(container);
|
int i, len = container->children->length;
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
update_visibility_output(container->children->items[i], container->handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
swayc_t *op = swayc_parent_by_type(container, C_OUTPUT);
|
||||||
|
update_visibility_output(container, op->handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO better visibility setting
|
|
||||||
bool visible = (ws->parent->focused == ws);
|
|
||||||
sway_log(L_DEBUG, "Setting visibility of container %p to %s", container, visible ? "visible" : "invisible");
|
|
||||||
container_map(ws, set_view_visibility, &visible);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_gaps(swayc_t *view, void *data) {
|
void reset_gaps(swayc_t *view, void *data) {
|
||||||
|
|
20
sway/focus.c
20
sway/focus.c
|
@ -14,6 +14,10 @@ static void update_focus(swayc_t *c) {
|
||||||
// Handle if focus switches
|
// Handle if focus switches
|
||||||
swayc_t *parent = c->parent;
|
swayc_t *parent = c->parent;
|
||||||
if (parent->focused != c) {
|
if (parent->focused != c) {
|
||||||
|
// Get previous focus
|
||||||
|
swayc_t *prev = parent->focused;
|
||||||
|
// Set new focus
|
||||||
|
parent->focused = c;
|
||||||
switch (c->type) {
|
switch (c->type) {
|
||||||
// Shouldnt happen
|
// Shouldnt happen
|
||||||
case C_ROOT: return;
|
case C_ROOT: return;
|
||||||
|
@ -25,16 +29,13 @@ static void update_focus(swayc_t *c) {
|
||||||
|
|
||||||
// Case where workspace changes
|
// Case where workspace changes
|
||||||
case C_WORKSPACE:
|
case C_WORKSPACE:
|
||||||
if (parent->focused) {
|
if (prev) {
|
||||||
swayc_t *ws = parent->focused;
|
// update visibility of old workspace
|
||||||
// hide visibility of old workspace
|
update_visibility(prev);
|
||||||
bool visible = false;
|
destroy_workspace(prev);
|
||||||
container_map(ws, set_view_visibility, &visible);
|
|
||||||
// set visibility of new workspace
|
|
||||||
visible = true;
|
|
||||||
container_map(c, set_view_visibility, &visible);
|
|
||||||
destroy_workspace(ws);
|
|
||||||
}
|
}
|
||||||
|
// Update visibility of newly focused workspace
|
||||||
|
update_visibility(c);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -44,7 +45,6 @@ static void update_focus(swayc_t *c) {
|
||||||
// for example, stacked and tabbing change stuff.
|
// for example, stacked and tabbing change stuff.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
c->parent->focused = c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,7 @@ void move_container(swayc_t *container,swayc_t* root,enum movement_direction dir
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_container_to(swayc_t* container, swayc_t* destination) {
|
void move_container_to(swayc_t* container, swayc_t* destination) {
|
||||||
if (container == destination) {
|
if (container == destination && swayc_is_parent_of(container, destination)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
swayc_t *parent = remove_child(container);
|
swayc_t *parent = remove_child(container);
|
||||||
|
|
Loading…
Reference in a new issue