mirror of
https://github.com/swaywm/sway.git
synced 2024-11-10 20:44:01 +01:00
Merge pull request #105 from Half-Shot/master
Basic 'move' functionality.
This commit is contained in:
commit
a436fc17ff
@ -15,6 +15,7 @@ enum swayc_types{
|
||||
C_TYPES,
|
||||
};
|
||||
|
||||
|
||||
enum swayc_layouts{
|
||||
L_NONE,
|
||||
L_HORIZ,
|
||||
@ -86,6 +87,7 @@ swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts);
|
||||
swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data);
|
||||
void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
|
||||
|
||||
|
||||
// Mappings
|
||||
void set_view_visibility(swayc_t *view, void *data);
|
||||
void reset_gaps(swayc_t *view, void *data);
|
||||
|
@ -17,6 +17,9 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child);
|
||||
swayc_t *replace_child(swayc_t *child, swayc_t *new_child);
|
||||
swayc_t *remove_child(swayc_t *child);
|
||||
|
||||
void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction);
|
||||
|
||||
|
||||
// Layout
|
||||
void arrange_windows(swayc_t *container, double width, double height);
|
||||
|
||||
|
@ -206,7 +206,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
|
||||
if (!view->is_floating) {
|
||||
// Remove view from its current location
|
||||
destroy_container(remove_child(view));
|
||||
|
||||
|
||||
// and move it into workspace floating
|
||||
add_floating(active_workspace,view);
|
||||
view->x = (active_workspace->width - view->width)/2;
|
||||
@ -341,6 +341,27 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char *
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cmd_move(struct sway_config *config, int argc, char **argv) {
|
||||
if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
swayc_t *view = get_focused_container(&root_container);
|
||||
|
||||
if (strcasecmp(argv[0], "left") == 0) {
|
||||
move_container(view,&root_container,MOVE_LEFT);
|
||||
} else if (strcasecmp(argv[0], "right") == 0) {
|
||||
move_container(view,&root_container,MOVE_RIGHT);
|
||||
} else if (strcasecmp(argv[0], "up") == 0) {
|
||||
move_container(view,&root_container,MOVE_UP);
|
||||
} else if (strcasecmp(argv[0], "down") == 0) {
|
||||
move_container(view,&root_container,MOVE_DOWN);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
|
||||
if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) {
|
||||
return false;
|
||||
@ -736,6 +757,7 @@ static struct cmd_handler handlers[] = {
|
||||
{ "kill", cmd_kill },
|
||||
{ "layout", cmd_layout },
|
||||
{ "log_colors", cmd_log_colors },
|
||||
{ "move", cmd_move},
|
||||
{ "reload", cmd_reload },
|
||||
{ "resize", cmd_resize },
|
||||
{ "set", cmd_set },
|
||||
|
@ -108,6 +108,50 @@ swayc_t *remove_child(swayc_t *child) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
//TODO: Implement horizontal movement.
|
||||
//TODO: Implement move to a different workspace.
|
||||
void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction){
|
||||
sway_log(L_DEBUG, "Moved window");
|
||||
swayc_t *temp;
|
||||
int i;
|
||||
uint clength = root->children->length;
|
||||
//Rearrange
|
||||
for (i = 0; i < clength; ++i) {
|
||||
swayc_t *child = root->children->items[i];
|
||||
if (child->handle == container->handle){
|
||||
if (clength == 1){
|
||||
//Only one container, meh.
|
||||
break;
|
||||
}
|
||||
if (direction == MOVE_LEFT && i > 0){
|
||||
temp = root->children->items[i-1];
|
||||
root->children->items[i] = temp;
|
||||
root->children->items[i-1] = container;
|
||||
arrange_windows(&root_container,-1,-1);
|
||||
}
|
||||
else if (direction == MOVE_RIGHT && i < clength-1){
|
||||
temp = root->children->items[i+1];
|
||||
root->children->items[i] = temp;
|
||||
root->children->items[i+1] = container;
|
||||
arrange_windows(&root_container,-1,-1);
|
||||
|
||||
}
|
||||
else if (direction == MOVE_UP){
|
||||
sway_log(L_INFO, "Moving up not implemented");
|
||||
}
|
||||
else if (direction == MOVE_DOWN){
|
||||
sway_log(L_INFO, "Moving down not implemented");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if (child->children != NULL){
|
||||
move_container(container,child,direction);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void arrange_windows(swayc_t *container, double width, double height) {
|
||||
int i;
|
||||
|
Loading…
Reference in New Issue
Block a user