Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
swayc_t *new_output(wlc_handle handle) {
    const struct wlc_size* size = wlc_output_get_resolution(handle);
    const char *name = wlc_output_get_name(handle);
    sway_log(L_DEBUG, "Added output %u %s", (unsigned int)handle, name);

    swayc_t *output = new_swayc(C_OUTPUT);
    output->width = size->w;
    output->height = size->h;
    output->handle = handle;
    if (name) {
        output->name = strdup(name);
    }

    add_child(&root_container, output);

    //TODO something with this
    int total_width = 0;
    container_map(&root_container, add_output_widths, &total_width);

    //Create workspace
    char *ws_name = workspace_next_name();
    new_workspace(output, ws_name);
    free(ws_name);

    return output;
}
Ejemplo n.º 3
0
swayc_t *new_floating_view(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 %lu:%x:%s as a floating view",
		handle, wlc_view_get_type(handle), title);
	// Setup values
	view->handle = handle;
	view->name = title ? strdup(title) : NULL;
	view->visible = true;

	// Set the geometry of the floating view
	const struct wlc_geometry* geometry = wlc_view_get_geometry(handle);

	// give it requested geometry, but place in center
	view->x = (active_workspace->width - geometry->size.w) / 2;
	view->y = (active_workspace->height- geometry->size.h) / 2;
	view->width = geometry->size.w;
	view->height = geometry->size.h;

	view->desired_width = view->width;
	view->desired_height = view->height;

	view->is_floating = true;

	// Case of focused workspace, just create as child of it
	list_add(active_workspace->floating, view);
	view->parent = active_workspace;
	if (active_workspace->focused == NULL) {
		set_focused_container_for(active_workspace, view);
	}
	return view;
}
Ejemplo n.º 4
0
swayc_t *new_floating_view(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 as a floating view",
		(unsigned int)handle, title);
	//Setup values
	view->handle = handle;
	view->name = title ? strdup(title) : NULL;
	view->visible = true;

	// Set the geometry of the floating view
	const struct wlc_geometry* geometry = wlc_view_get_geometry(handle);

	view->x = geometry->origin.x;
	view->y = geometry->origin.y;
	view->width = geometry->size.w;
	view->height = geometry->size.h;

	view->desired_width = view->width;
	view->desired_height = view->height;

	view->is_floating = true;

	//Case of focused workspace, just create as child of it
	list_add(active_workspace->floating, view);
	view->parent = active_workspace;
	if (active_workspace->focused == NULL) {
		active_workspace->focused = view;
	}
	return view;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
swayc_t *new_workspace(swayc_t * output, const char *name) {
    sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle);
    swayc_t *workspace = new_swayc(C_WORKSPACE);

    workspace->layout = L_HORIZ; // TODO:default layout
    workspace->width = output->width;
    workspace->height = output->height;
    workspace->name = strdup(name);
    workspace->visible = true;

    add_child(output, workspace);
    return workspace;
}
Ejemplo n.º 7
0
swayc_t *new_output(wlc_handle handle) {
	const struct wlc_size* size = wlc_output_get_resolution(handle);
	const char *name = wlc_output_get_name(handle);
	sway_log(L_DEBUG, "Added output %lu:%s", handle, name);

	swayc_t *output = new_swayc(C_OUTPUT);
	output->width = size->w;
	output->height = size->h;
	output->handle = handle;
	output->name = name ? strdup(name) : NULL;
	output->gaps = config->gaps_outer + config->gaps_inner / 2;

	add_child(&root_container, output);

	// Create workspace
	char *ws_name = NULL;
	if (name) {
		int i;
		for (i = 0; i < config->workspace_outputs->length; ++i) {
			struct workspace_output *wso = config->workspace_outputs->items[i];
			if (strcasecmp(wso->output, name) == 0) {
				sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
				// Check if any other workspaces are using this name
				if (find_container(&root_container, workspace_test, wso->workspace)) {
					sway_log(L_DEBUG, "But it's already taken");
					break;
				}
				sway_log(L_DEBUG, "So we're going to use it");
				ws_name = strdup(wso->workspace);
				break;
			}
		}
	}
	if (!ws_name) {
		ws_name = workspace_next_name();
	}

	// create and initilize default workspace
	swayc_t *ws = new_workspace(output, ws_name);
	ws->is_focused = true;

	free(ws_name);
	
	return output;
}
Ejemplo n.º 8
0
swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
	if (!ASSERT_NONNULL(child)) {
		return NULL;
	}
	swayc_t *cont = new_swayc(C_CONTAINER);

	sway_log(L_DEBUG, "creating container %p around %p", cont, child);

	cont->layout = layout;
	cont->width = child->width;
	cont->height = child->height;
	cont->x = child->x;
	cont->y = child->y;
	cont->visible = child->visible;

	/* Container inherits all of workspaces children, layout and whatnot */
	if (child->type == C_WORKSPACE) {
		swayc_t *workspace = child;
		// reorder focus
		cont->focused = workspace->focused;
		workspace->focused = cont;
		// set all children focu to container
		int i;
		for (i = 0; i < workspace->children->length; ++i) {
			((swayc_t *)workspace->children->items[i])->parent = cont;
		}
		// Swap children
		list_t  *tmp_list  = workspace->children;
		workspace->children = cont->children;
		cont->children = tmp_list;
		// add container to workspace chidren
		add_child(workspace, cont);
		// give them proper layouts
		cont->layout = workspace->layout;
		workspace->layout = layout;
		set_focused_container_for(workspace, get_focused_view(workspace));
	} else { // Or is built around container
		swayc_t *parent = replace_child(child, cont);
		if (parent) {
			add_child(cont, child);
		}
	}
	return cont;
}
Ejemplo n.º 9
0
swayc_t *new_workspace(swayc_t *output, const char *name) {
	if (!ASSERT_NONNULL(output)) {
		return NULL;
	}
	sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle);
	swayc_t *workspace = new_swayc(C_WORKSPACE);

	workspace->layout = L_HORIZ; // TODO: default layout
	workspace->x = output->x;
	workspace->y = output->y;
	workspace->width = output->width;
	workspace->height = output->height;
	workspace->name = strdup(name);
	workspace->visible = true;
	workspace->floating = create_list();

	add_child(output, workspace);
	return workspace;
}
Ejemplo n.º 10
0
swayc_t *new_output(wlc_handle handle) {
	const struct wlc_size* size = wlc_output_get_resolution(handle);
	const char *name = wlc_output_get_name(handle);
	sway_log(L_DEBUG, "Added output %u %s", (unsigned int)handle, name);

	swayc_t *output = new_swayc(C_OUTPUT);
	output->width = size->w;
	output->height = size->h;
	output->handle = handle;
	output->name = name ? strdup(name) : NULL;

	add_child(&root_container, output);

	//TODO something with this
	int total_width = 0;
	container_map(&root_container, add_output_widths, &total_width);

	//Create workspace
	char *ws_name = NULL;
	if (name) {
		int i;
		for (i = 0; i < config->workspace_outputs->length; ++i) {
			struct workspace_output *wso = config->workspace_outputs->items[i];
			if (strcasecmp(wso->output, name) == 0) {
				sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
				ws_name = strdup(wso->workspace);
				break;
			}
		}
	}
	if (!ws_name) {
		ws_name = workspace_next_name();
	}
	new_workspace(output, ws_name);
	free(ws_name);
	
	return output;
}
Ejemplo n.º 11
0
swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
    swayc_t *cont = new_swayc(C_CONTAINER);

    sway_log(L_DEBUG, "creating container %p around %p", cont, child);

    cont->layout = layout;
    cont->width = child->width;
    cont->height = child->height;
    cont->x	= child->x;
    cont->y = child->y;
    cont->visible = child->visible;

    /* Container inherits all of workspaces children, layout and whatnot */
    if (child->type == C_WORKSPACE) {
        swayc_t *workspace = child;
        //reorder focus
        cont->focused = workspace->focused;
        workspace->focused = cont;
        //Swap children
        list_t  *tmp_list  = workspace->children;
        workspace->children = cont->children;
        cont->children = tmp_list;
        //add container to workspace chidren
        add_child(workspace, cont);
        //give them proper layouts
        cont->layout = workspace->layout;
        workspace->layout = layout;
    }
    //Or is built around container
    else {
        swayc_t *parent = replace_child(child, cont);
        if (parent) {
            add_child(cont, child);
        }
    }
    return cont;
}