mirror of
https://github.com/swaywm/sway.git
synced 2025-11-11 13:29:51 -05:00
Merge branch 'master' of https://github.com/SirCmpwn/sway
This commit is contained in:
commit
5a9ba261bc
26 changed files with 1493 additions and 570 deletions
186
sway/layout.c
186
sway/layout.c
|
|
@ -4,6 +4,7 @@
|
|||
#include "layout.h"
|
||||
#include "log.h"
|
||||
#include "list.h"
|
||||
#include "config.h"
|
||||
#include "container.h"
|
||||
#include "workspace.h"
|
||||
#include "focus.h"
|
||||
|
|
@ -32,6 +33,21 @@ void add_child(swayc_t *parent, swayc_t *child) {
|
|||
child->width, child->height, parent, parent->type, parent->width, parent->height);
|
||||
list_add(parent->children, child);
|
||||
child->parent = parent;
|
||||
// set focus for this container
|
||||
if (parent->children->length == 1) {
|
||||
set_focused_container_for(parent, child);
|
||||
}
|
||||
}
|
||||
|
||||
void add_floating(swayc_t *ws, swayc_t *child) {
|
||||
sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type,
|
||||
child->width, child->height, ws, ws->type, ws->width, ws->height);
|
||||
list_add(ws->floating, child);
|
||||
child->parent = ws;
|
||||
child->is_floating = true;
|
||||
if (!ws->focused) {
|
||||
set_focused_container_for(ws, child);
|
||||
}
|
||||
}
|
||||
|
||||
swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) {
|
||||
|
|
@ -55,7 +71,7 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
|
|||
new_child->parent = child->parent;
|
||||
|
||||
if (child->parent->focused == child) {
|
||||
child->parent->focused = new_child;
|
||||
set_focused_container_for(child->parent, new_child);
|
||||
}
|
||||
child->parent = NULL;
|
||||
return parent;
|
||||
|
|
@ -72,6 +88,7 @@ swayc_t *remove_child(swayc_t *child) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
} else {
|
||||
for (i = 0; i < parent->children->length; ++i) {
|
||||
if (parent->children->items[i] == child) {
|
||||
|
|
@ -80,7 +97,7 @@ swayc_t *remove_child(swayc_t *child) {
|
|||
}
|
||||
}
|
||||
}
|
||||
//Set focused to new container
|
||||
// Set focused to new container
|
||||
if (parent->focused == child) {
|
||||
if (parent->children->length > 0) {
|
||||
set_focused_container_for(parent, parent->children->items[i?i-1:0]);
|
||||
|
|
@ -104,7 +121,7 @@ void move_container(swayc_t *container,swayc_t* root,int direction){
|
|||
//Only one container, meh.
|
||||
break;
|
||||
}
|
||||
|
||||
//TODO: Implement horizontal movement.
|
||||
//TODO: Implement move to a different workspace.
|
||||
if(direction == MOVE_LEFT && i > 0){
|
||||
temp = root->children->items[i-1];
|
||||
|
|
@ -167,11 +184,11 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
|||
// y -= container->y;
|
||||
for (i = 0; i < container->children->length; ++i) {
|
||||
swayc_t *child = container->children->items[i];
|
||||
sway_log(L_DEBUG, "Arranging workspace #%d", i);
|
||||
child->x = x;
|
||||
child->y = y;
|
||||
child->width = width;
|
||||
child->height = height;
|
||||
child->x = x + container->gaps;
|
||||
child->y = y + container->gaps;
|
||||
child->width = width - container->gaps * 2;
|
||||
child->height = height - container->gaps * 2;
|
||||
sway_log(L_DEBUG, "Arranging workspace #%d at %d, %d", i, child->x, child->y);
|
||||
arrange_windows(child, -1, -1);
|
||||
}
|
||||
return;
|
||||
|
|
@ -179,27 +196,24 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
|||
{
|
||||
struct wlc_geometry geometry = {
|
||||
.origin = {
|
||||
.x = container->x,
|
||||
.y = container->y
|
||||
.x = container->x + container->gaps / 2,
|
||||
.y = container->y + container->gaps / 2
|
||||
},
|
||||
.size = {
|
||||
.w = width,
|
||||
.h = height
|
||||
.w = width - container->gaps,
|
||||
.h = height - container->gaps
|
||||
}
|
||||
};
|
||||
if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) {
|
||||
swayc_t *parent = container;
|
||||
while (parent->type != C_OUTPUT) {
|
||||
parent = parent->parent;
|
||||
}
|
||||
swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT);
|
||||
geometry.origin.x = 0;
|
||||
geometry.origin.y = 0;
|
||||
geometry.size.w = parent->width;
|
||||
geometry.size.h = parent->height;
|
||||
wlc_view_set_geometry(container->handle, &geometry);
|
||||
wlc_view_set_geometry(container->handle, 0, &geometry);
|
||||
wlc_view_bring_to_front(container->handle);
|
||||
} else {
|
||||
wlc_view_set_geometry(container->handle, &geometry);
|
||||
wlc_view_set_geometry(container->handle, 0, &geometry);
|
||||
container->width = width;
|
||||
container->height = height;
|
||||
}
|
||||
|
|
@ -213,40 +227,62 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
|||
break;
|
||||
}
|
||||
|
||||
double total_weight = 0;
|
||||
for (i = 0; i < container->children->length; ++i) {
|
||||
swayc_t *child = container->children->items[i];
|
||||
total_weight += child->weight;
|
||||
}
|
||||
|
||||
x = y = 0;
|
||||
double scale = 0;
|
||||
switch (container->layout) {
|
||||
case L_HORIZ:
|
||||
default:
|
||||
sway_log(L_DEBUG, "Arranging %p horizontally", container);
|
||||
// Calculate total width
|
||||
for (i = 0; i < container->children->length; ++i) {
|
||||
swayc_t *child = container->children->items[i];
|
||||
double percent = child->weight / total_weight;
|
||||
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width);
|
||||
child->x = x + container->x;
|
||||
child->y = y + container->y;
|
||||
int w = width * percent;
|
||||
int h = height;
|
||||
arrange_windows(child, w, h);
|
||||
x += w;
|
||||
int *old_width = &((swayc_t *)container->children->items[i])->width;
|
||||
if (*old_width <= 0) {
|
||||
if (container->children->length > 1) {
|
||||
*old_width = width / (container->children->length - 1);
|
||||
} else {
|
||||
*old_width = width;
|
||||
}
|
||||
}
|
||||
scale += *old_width;
|
||||
}
|
||||
// Resize windows
|
||||
if (scale > 0.1) {
|
||||
scale = width / scale;
|
||||
sway_log(L_DEBUG, "Arranging %p horizontally", container);
|
||||
for (i = 0; i < container->children->length; ++i) {
|
||||
swayc_t *child = container->children->items[i];
|
||||
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale);
|
||||
child->x = x + container->x;
|
||||
child->y = y + container->y;
|
||||
arrange_windows(child, child->width * scale, height);
|
||||
x += child->width;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case L_VERT:
|
||||
sway_log(L_DEBUG, "Arranging %p vertically", container);
|
||||
// Calculate total height
|
||||
for (i = 0; i < container->children->length; ++i) {
|
||||
swayc_t *child = container->children->items[i];
|
||||
double percent = child->weight / total_weight;
|
||||
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will receive %.2f of %d)", child, child->type, percent, width);
|
||||
child->x = x + container->x;
|
||||
child->y = y + container->y;
|
||||
int w = width;
|
||||
int h = height * percent;
|
||||
arrange_windows(child, w, h);
|
||||
y += h;
|
||||
int *old_height = &((swayc_t *)container->children->items[i])->height;
|
||||
if (*old_height <= 0) {
|
||||
if (container->children->length > 1) {
|
||||
*old_height = height / (container->children->length - 1);
|
||||
} else {
|
||||
*old_height = height;
|
||||
}
|
||||
}
|
||||
scale += *old_height;
|
||||
}
|
||||
// Resize
|
||||
if (scale > 0.1) {
|
||||
scale = height / scale;
|
||||
sway_log(L_DEBUG, "Arranging %p vertically", container);
|
||||
for (i = 0; i < container->children->length; ++i) {
|
||||
swayc_t *child = container->children->items[i];
|
||||
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale);
|
||||
child->x = x + container->x;
|
||||
child->y = y + container->y;
|
||||
arrange_windows(child, width, child->height * scale);
|
||||
y += child->height;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -268,20 +304,15 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
|||
}
|
||||
};
|
||||
if (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN) {
|
||||
swayc_t *parent = view;
|
||||
while (parent->type != C_OUTPUT) {
|
||||
parent = parent->parent;
|
||||
}
|
||||
swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT);
|
||||
geometry.origin.x = 0;
|
||||
geometry.origin.y = 0;
|
||||
geometry.size.w = parent->width;
|
||||
geometry.size.h = parent->height;
|
||||
wlc_view_set_geometry(view->handle, &geometry);
|
||||
wlc_view_set_geometry(view->handle, 0, &geometry);
|
||||
wlc_view_bring_to_front(view->handle);
|
||||
} else {
|
||||
wlc_view_set_geometry(view->handle, &geometry);
|
||||
view->width = width;
|
||||
view->height = height;
|
||||
wlc_view_set_geometry(view->handle, 0, &geometry);
|
||||
// Bring the views to the front in order of the list, the list
|
||||
// will be kept up to date so that more recently focused views
|
||||
// have higher indexes
|
||||
|
|
@ -326,3 +357,54 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) {
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) {
|
||||
swayc_t *parent = container->parent;
|
||||
|
||||
if (dir == MOVE_PARENT) {
|
||||
if (parent->type == C_OUTPUT) {
|
||||
return NULL;
|
||||
} else {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
// Test if we can even make a difference here
|
||||
bool can_move = false;
|
||||
int diff = 0;
|
||||
if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
|
||||
if (parent->layout == L_HORIZ || parent->type == C_ROOT) {
|
||||
can_move = true;
|
||||
diff = dir == MOVE_LEFT ? -1 : 1;
|
||||
}
|
||||
} else {
|
||||
if (parent->layout == L_VERT) {
|
||||
can_move = true;
|
||||
diff = dir == MOVE_UP ? -1 : 1;
|
||||
}
|
||||
}
|
||||
if (can_move) {
|
||||
int i;
|
||||
for (i = 0; i < parent->children->length; ++i) {
|
||||
swayc_t *child = parent->children->items[i];
|
||||
if (child == container) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int desired = i + diff;
|
||||
if (desired < 0 || desired >= parent->children->length) {
|
||||
can_move = false;
|
||||
} else {
|
||||
return parent->children->items[desired];
|
||||
}
|
||||
}
|
||||
if (!can_move) {
|
||||
container = parent;
|
||||
parent = parent->parent;
|
||||
if (!parent) {
|
||||
// Nothing we can do
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue