void move_container_to(swayc_t* container, swayc_t* destination) { if (container == destination || swayc_is_parent_of(container, destination)) { return; } swayc_t *parent = remove_child(container); // reset container geometry container->width = container->height = 0; // Send to new destination if (container->is_floating) { add_floating(swayc_active_workspace_for(destination), container); } else if (destination->type == C_WORKSPACE) { add_child(destination, container); } else { add_sibling(destination, container); } // Destroy old container if we need to parent = destroy_container(parent); // Refocus swayc_t *op1 = swayc_parent_by_type(destination, C_OUTPUT); swayc_t *op2 = swayc_parent_by_type(parent, C_OUTPUT); set_focused_container(get_focused_view(op1)); arrange_windows(op1, -1, -1); update_visibility(op1); if (op1 != op2) { set_focused_container(get_focused_view(op2)); arrange_windows(op2, -1, -1); update_visibility(op2); } }
swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { if (!ASSERT_NONNULL(sibling)) { return NULL; } const char *title = wlc_view_get_title(handle); swayc_t *view = new_swayc(C_VIEW); sway_log(L_DEBUG, "Adding new view %lu:%s to container %p %d", handle, title, sibling, sibling ? sibling->type : 0); // Setup values view->handle = handle; view->name = title ? strdup(title) : NULL; view->visible = true; view->is_focused = true; // Setup geometry const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); view->width = 0; view->height = 0; view->desired_width = geometry->size.w; view->desired_height = geometry->size.h; view->gaps = config->gaps_inner; view->is_floating = false; if (sibling->type == C_WORKSPACE) { // Case of focused workspace, just create as child of it add_child(sibling, view); } else { // Regular case, create as sibling of current container add_sibling(sibling, view); } return view; }
swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { const char *title = wlc_view_get_title(handle); swayc_t *view = new_swayc(C_VIEW); sway_log(L_DEBUG, "Adding new view %u:%s to container %p %d", (unsigned int)handle, title, sibling, sibling?sibling->type:0); //Setup values view->handle = handle; view->name = title ? strdup(title) : NULL; view->visible = true; view->desired_width = -1; view->desired_height = -1; // TODO: properly set this view->is_floating = false; //Case of focused workspace, just create as child of it if (sibling->type == C_WORKSPACE) { add_child(sibling, view); } //Regular case, create as sibling of current container else { add_sibling(sibling, view); } return view; }
void move_container_to(swayc_t* container, swayc_t* destination) { if (container == destination || swayc_is_parent_of(container, destination)) { return; } swayc_t *parent = remove_child(container); // Send to new destination if (container->is_floating) { swayc_t *ws = swayc_active_workspace_for(destination); add_floating(ws, container); // If the workspace only has one child after adding one, it // means that the workspace was just initialized. if (ws->children->length + ws->floating->length == 1) { ipc_event_workspace(NULL, ws, "init"); } } else if (destination->type == C_WORKSPACE) { // reset container geometry container->width = container->height = 0; add_child(destination, container); // If the workspace only has one child after adding one, it // means that the workspace was just initialized. if (destination->children->length + destination->floating->length == 1) { ipc_event_workspace(NULL, destination, "init"); } } else { // reset container geometry container->width = container->height = 0; add_sibling(destination, container); } // Destroy old container if we need to parent = destroy_container(parent); // Refocus swayc_t *op1 = swayc_parent_by_type(destination, C_OUTPUT); swayc_t *op2 = swayc_parent_by_type(parent, C_OUTPUT); set_focused_container(get_focused_view(op1)); arrange_windows(op1, -1, -1); update_visibility(op1); if (op1 != op2) { set_focused_container(get_focused_view(op2)); arrange_windows(op2, -1, -1); update_visibility(op2); } }
struct cmd_results *cmd_floating(int argc, char **argv) { struct cmd_results *error = NULL; if (config->reading) return cmd_results_new(CMD_FAILURE, "floating", "Can't be used in config file."); if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { return error; } swayc_t *view = current_container; bool wants_floating; if (strcasecmp(argv[0], "enable") == 0) { wants_floating = true; } else if (strcasecmp(argv[0], "disable") == 0) { wants_floating = false; } else if (strcasecmp(argv[0], "toggle") == 0) { wants_floating = !view->is_floating; } else { return cmd_results_new(CMD_FAILURE, "floating", "Expected 'floating <enable|disable|toggle>"); } // Prevent running floating commands on things like workspaces if (view->type != C_VIEW) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } // Change from nonfloating to floating if (!view->is_floating && wants_floating) { // Remove view from its current location destroy_container(remove_child(view)); // and move it into workspace floating add_floating(swayc_active_workspace(), view); view->x = (swayc_active_workspace()->width - view->width)/2; view->y = (swayc_active_workspace()->height - view->height)/2; if (view->desired_width != -1) { view->width = view->desired_width; } if (view->desired_height != -1) { view->height = view->desired_height; } arrange_windows(swayc_active_workspace(), -1, -1); } else if (view->is_floating && !wants_floating) { // Delete the view from the floating list and unset its is_floating flag remove_child(view); view->is_floating = false; // Get the properly focused container, and add in the view there swayc_t *focused = container_under_pointer(); // If focused is null, it's because the currently focused container is a workspace if (focused == NULL || focused->is_floating) { focused = swayc_active_workspace(); } set_focused_container(focused); sway_log(L_DEBUG, "Non-floating focused container is %p", focused); // Case of focused workspace, just create as child of it if (focused->type == C_WORKSPACE) { add_child(focused, view); } // Regular case, create as sibling of current container else { add_sibling(focused, view); } // Refocus on the view once its been put back into the layout view->width = view->height = 0; arrange_windows(swayc_active_workspace(), -1, -1); remove_view_from_scratchpad(view); ipc_event_window(view, "floating"); } set_focused_container(view); return cmd_results_new(CMD_SUCCESS, NULL, NULL); }