static bool should_focus_on_create(struct wlc_view *view) { // Do not allow unmanaged views to steal focus (tooltips, dnds, etc..) // Do not allow parented windows to steal focus, if current window wasn't parent. uint32_t type = wlc_view_get_type(view); struct wlc_view *parent = wlc_view_get_parent(view); return (!(type & WLC_BIT_UNMANAGED) && (!loliwm.active || !parent || parent == loliwm.active)); }
static void raise_all(struct wlc_view *view) { assert(view); // Raise view and all related views to top honoring the stacking order. struct wlc_view *parent; if ((parent = wlc_view_get_parent(view))) { raise_all(parent); struct wlc_view *v, *vn; struct wl_list *views = wlc_space_get_views(wlc_view_get_space(view)); wlc_view_for_each_safe(v, vn, views) { if (v == view || wlc_view_get_parent(v) != parent) continue; wlc_view_bring_to_front(v); } }
static void layout_parent(struct wlc_view *view, struct wlc_view *parent, uint32_t w, uint32_t h) { assert(view && parent); // Size to fit the undermost parent // TODO: Use surface height as base instead of current struct wlc_view *under; for (under = parent; under && wlc_view_get_parent(under); under = wlc_view_get_parent(under)); uint32_t uw = wlc_view_get_width(under); uint32_t uh = wlc_view_get_height(under); uint32_t tw = (w > uw * 0.8 ? uw * 0.8 : w); uint32_t th = (h > uh * 0.8 ? uh * 0.8 : h); // Center the parent uint32_t pw = wlc_view_get_width(parent); uint32_t ph = wlc_view_get_height(parent); wlc_view_position(view, pw * 0.5 - tw * 0.5, ph * 0.5 - th * 0.5); wlc_view_resize(view, tw, th); }
static void ipc_json_describe_view(swayc_t *c, json_object *object) { json_object *props = json_object_new_object(); float percent = ipc_json_child_percentage(c); const char *layout = (c->parent->type == C_CONTAINER) ? ipc_json_layout_description(c->parent->layout) : "none"; const char *last_layout = (c->parent->type == C_CONTAINER) ? ipc_json_layout_description(c->parent->prev_layout) : "none"; wlc_handle parent = wlc_view_get_parent(c->handle); json_object_object_add(object, "type", json_object_new_string((c->is_floating) ? "floating_con" : "con")); json_object_object_add(object, "scratchpad_state", json_object_new_string(ipc_json_get_scratchpad_state(c))); json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL); // TODO: make urgency actually work once Sway supports it json_object_object_add(object, "urgent", json_object_new_boolean(false)); json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); json_object_object_add(object, "last_split_layout", (strcmp(last_layout, "null") == 0) ? NULL : json_object_new_string(last_layout)); json_object_object_add(object, "workspace_layout", json_object_new_string(ipc_json_layout_description(swayc_parent_by_type(c, C_WORKSPACE)->workspace_layout))); json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(c))); json_object_object_add(object, "current_border_width", json_object_new_int(c->border_thickness)); json_object_object_add(object, "rect", ipc_json_create_rect(c)); json_object_object_add(object, "deco_rect", ipc_json_create_rect_from_geometry(c->title_bar_geometry)); json_object_object_add(object, "geometry", ipc_json_create_rect_from_geometry(c->cached_geometry)); json_object_object_add(object, "window_rect", ipc_json_create_rect_from_geometry(c->actual_geometry)); json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); json_object_object_add(object, "window", json_object_new_int(c->handle)); // for the sake of i3 compat json_object_object_add(props, "class", c->class ? json_object_new_string(c->class) : c->app_id ? json_object_new_string(c->app_id) : NULL); json_object_object_add(props, "instance", c->instance ? json_object_new_string(c->instance) : c->app_id ? json_object_new_string(c->app_id) : NULL); json_object_object_add(props, "title", (c->name) ? json_object_new_string(c->name) : NULL); json_object_object_add(props, "transient_for", parent ? json_object_new_int(parent) : NULL); json_object_object_add(object, "window_properties", props); json_object_object_add(object, "fullscreen_mode", json_object_new_int(swayc_is_fullscreen(c) ? 1 : 0)); json_object_object_add(object, "sticky", json_object_new_boolean(c->sticky)); json_object_object_add(object, "floating", json_object_new_string( c->is_floating ? "auto_on" : "auto_off")); // we can't state the cause json_object_object_add(object, "app_id", c->app_id ? json_object_new_string(c->app_id) : NULL); }
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; } }
static bool handle_view_created(wlc_handle handle) { // if view is child of another view, the use that as focused container wlc_handle parent = wlc_view_get_parent(handle); swayc_t *focused = NULL; swayc_t *newview = NULL; // Get parent container, to add view in if (parent) { focused = get_swayc_for_handle(parent, &root_container); } if (!focused || focused->type == C_OUTPUT) { focused = get_focused_container(&root_container); } sway_log(L_DEBUG, "handle:%ld type:%x state:%x parent:%ld " "mask:%d (x:%d y:%d w:%d h:%d) title:%s " "class:%s appid:%s", handle, wlc_view_get_type(handle), wlc_view_get_state(handle), parent, wlc_view_get_mask(handle), wlc_view_get_geometry(handle)->origin.x, wlc_view_get_geometry(handle)->origin.y,wlc_view_get_geometry(handle)->size.w, wlc_view_get_geometry(handle)->size.h, wlc_view_get_title(handle), wlc_view_get_class(handle), wlc_view_get_app_id(handle)); // TODO properly figure out how each window should be handled. switch (wlc_view_get_type(handle)) { // regular view created regularly case 0: newview = new_view(focused, handle); wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true); break; // Dmenu keeps viewfocus, but others with this flag dont, for now simulate // dmenu case WLC_BIT_OVERRIDE_REDIRECT: // locked_view_focus = true; wlc_view_focus(handle); wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); wlc_view_bring_to_front(handle); break; // Firefox popups have this flag set. case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: wlc_view_bring_to_front(handle); locked_container_focus = true; break; // Modals, get focus, popups do not case WLC_BIT_MODAL: wlc_view_focus(handle); wlc_view_bring_to_front(handle); newview = new_floating_view(handle); case WLC_BIT_POPUP: wlc_view_bring_to_front(handle); break; } if (newview) { set_focused_container(newview); swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT); arrange_windows(output, -1, -1); } return true; }
static bool is_tiled(struct wlc_view *view) { uint32_t state = wlc_view_get_state(view); return !(state & WLC_BIT_FULLSCREEN) && !wlc_view_get_parent(view) && is_managed(view) && !is_or(view) && !is_modal(view); }