Example #1
0
File: layout.c Project: thuck/sway
static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geometry) {
	struct wlc_geometry g = *geometry;
	c->actual_geometry = g;

	swayc_t *output = swayc_parent_by_type(c, C_OUTPUT);
	const struct wlc_size *res = wlc_output_get_resolution(output->handle);

	switch (c->border_type) {
	case B_NONE:
		break;
	case B_PIXEL:
		adjust_border_geometry(c, &g, res, c->border_thickness,
			c->border_thickness, c->border_thickness, c->border_thickness);
		break;
	case B_NORMAL:
	{
		int title_bar_height = config->font_height + 4; // borders + padding

		adjust_border_geometry(c, &g, res, c->border_thickness,
			c->border_thickness, title_bar_height, c->border_thickness);

		struct wlc_geometry title_bar = {
			.origin = {
				.x = c->actual_geometry.origin.x - c->border_thickness,
				.y = c->actual_geometry.origin.y - title_bar_height
			},
			.size = {
				.w = c->actual_geometry.size.w + (2 * c->border_thickness),
				.h = title_bar_height
			}
		};
		c->title_bar_geometry = title_bar;
		break;
	}
	}
Example #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;
}
Example #3
0
static void handle_output_pre_render(wlc_handle output) {
	struct wlc_size resolution = *wlc_output_get_resolution(output);

	int i;
	for (i = 0; i < desktop_shell.backgrounds->length; ++i) {
		struct background_config *config = desktop_shell.backgrounds->items[i];
		if (config->output == output) {
			wlc_surface_render(config->surface, &(struct wlc_geometry){ wlc_origin_zero, resolution });
			break;
		}
Example #4
0
static void
relayout(struct wlc_space *space)
{
   if (!space)
      return;

   struct wl_list *views;
   if (!(views = wlc_space_get_userdata(space)))
      return;

   uint32_t rwidth, rheight;
   struct wlc_output *output = wlc_space_get_output(space);
   wlc_output_get_resolution(output, &rwidth, &rheight);

   struct wlc_view *v;
   uint32_t count = 0;
   wlc_view_for_each_user(v, views)
      if (is_tiled(v)) ++count;

   bool toggle = false;
   uint32_t y = 0, height = rheight / (count > 1 ? count - 1 : 1);
   uint32_t fheight = (rheight > height * (count - 1) ? height + (rheight - height * (count - 1)) : height);
   wlc_view_for_each_user(v, views) {
      if (wlc_view_get_state(v) & WLC_BIT_FULLSCREEN) {
         wlc_view_resize(v, rwidth, rheight);
         wlc_view_position(v, 0, 0);
      }

      if (wlc_view_get_type(v) & WLC_BIT_SPLASH)
         wlc_view_position(v, rwidth * 0.5 - wlc_view_get_width(v) * 0.5, rheight * 0.5 - wlc_view_get_height(v) * 0.5);

      struct wlc_view *parent;
      if (is_managed(v) && !is_or(v) && (parent = wlc_view_get_parent(v)))
         layout_parent(v, parent, wlc_view_get_width(v), wlc_view_get_height(v));

      if (!is_tiled(v))
         continue;

      uint32_t slave = rwidth * loliwm.cut;
      wlc_view_set_state(v, WLC_BIT_MAXIMIZED, true);
      wlc_view_resize(v, (count > 1 ? (toggle ? slave : rwidth - slave) : rwidth), (toggle ? (y == 0 ? fheight : height) : rheight));
      wlc_view_position(v, (toggle ? rwidth - slave : 0), y);

      if (toggle)
         y += (y == 0 ? fheight : height);

      toggle = true;
   }
}
Example #5
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;
}
Example #6
0
static json_object *ipc_json_create_rect(swayc_t *c) {
	json_object *rect = json_object_new_object();

	json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x));
	json_object_object_add(rect, "y", json_object_new_int((int32_t)c->y));

	struct wlc_size size;
	if (c->type == C_OUTPUT) {
		size = *wlc_output_get_resolution(c->handle);
	} else {
		size.w = c->width;
		size.h = c->height;
	}

	json_object_object_add(rect, "width", json_object_new_int((int32_t)size.w));
	json_object_object_add(rect, "height", json_object_new_int((int32_t)size.h));

	return rect;
}
Example #7
0
File: example.c Project: hsoft/wlc
static void
relayout(wlc_handle output)
{
   const struct wlc_size *r;
   if (!(r = wlc_output_get_resolution(output)))
      return;

   size_t memb;
   const wlc_handle *views = wlc_output_get_views(output, &memb);

   bool toggle = false;
   uint32_t y = 0;
   uint32_t w = r->w / 2, h = r->h / chck_maxu32((1 + memb) / 2, 1);
   for (size_t i = 0; i < memb; ++i) {
      struct wlc_geometry g = { { (toggle ? w : 0), y }, { (!toggle && i == memb - 1 ? r->w : w), h } };
      wlc_view_set_geometry(views[i], &g);
      y = y + (!(toggle = !toggle) ? h : 0);
   }
}
Example #8
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;
}
Example #9
0
void apply_output_config(struct output_config *oc, swayc_t *output) {
	if (oc && oc->enabled == 0) {
		destroy_output(output);
		return;
	}

	if (oc && oc->width > 0 && oc->height > 0) {
		output->width = oc->width;
		output->height = oc->height;

		sway_log(L_DEBUG, "Set %s size to %ix%i (%d)", oc->name, oc->width, oc->height, oc->scale);
		struct wlc_size new_size = { .w = oc->width, .h = oc->height };
		wlc_output_set_resolution(output->handle, &new_size, (uint32_t)oc->scale);
	} else if (oc && oc->scale != 1) {
		const struct wlc_size *new_size = wlc_output_get_resolution(output->handle);
		wlc_output_set_resolution(output->handle, new_size, (uint32_t)oc->scale);
	}

	// Find position for it
	if (oc && oc->x != -1 && oc->y != -1) {
		sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
		output->x = oc->x;
		output->y = oc->y;
	} else {
		int x = 0;
		for (int i = 0; i < root_container.children->length; ++i) {
			swayc_t *c = root_container.children->items[i];
			if (c->type == C_OUTPUT) {
				if (c->width + c->x > x) {
					x = c->width + c->x;