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); }
bool set_focused_container_for(swayc_t *a, swayc_t *c) { if (locked_container_focus || !c) { return false; } swayc_t *find = c; // Ensure that a is an ancestor of c while (find != a && (find = find->parent)) { if (find == &root_container) { return false; } } // Get workspace for c, get that workspaces current focused container. swayc_t *workspace = swayc_active_workspace_for(c); swayc_t *focused = get_focused_view(workspace); // if the workspace we are changing focus to has a fullscreen view return if (swayc_is_fullscreen(focused) && c != focused) { return false; } // Check if we changing a parent container that will see chnage bool effective = true; while (find != &root_container) { if (find->parent->focused != find) { effective = false; } find = find->parent; } if (effective) { // Go to set_focused_container return set_focused_container(c); } sway_log(L_DEBUG, "Setting focus for %p:%ld to %p:%ld", a, a->handle, c, c->handle); c->is_focused = true; swayc_t *p = c; while (p != a) { update_focus(p); p = p->parent; p->is_focused = false; } return true; }
bool set_focused_container(swayc_t *c) { if (locked_container_focus || !c) { return false; } swayc_log(L_DEBUG, c, "Setting focus to %p:%ld", c, c->handle); // Get workspace for c, get that workspaces current focused container. swayc_t *workspace = swayc_active_workspace_for(c); swayc_t *focused = get_focused_view(workspace); // if the workspace we are changing focus to has a fullscreen view return if (swayc_is_fullscreen(focused) && focused != c) { return false; } // update container focus from here to root, making necessary changes along // the way swayc_t *p = c; if (p->type != C_OUTPUT && p->type != C_ROOT) { p->is_focused = true; } while (p != &root_container) { update_focus(p); p = p->parent; p->is_focused = false; } // get new focused view and set focus to it. p = get_focused_view(c); if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { // unactivate previous focus if (focused->type == C_VIEW) { wlc_view_set_state(focused->handle, WLC_BIT_ACTIVATED, false); } // activate current focus if (p->type == C_VIEW) { wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); // set focus if view_focus is unlocked if (!locked_view_focus) { wlc_view_focus(p->handle); } } } return true; }
struct cmd_results *cmd_fullscreen(int argc, char **argv) { struct cmd_results *error = NULL; if (config->reading) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can't be used in config file."); if (!config->active) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can only be used when sway is running."); if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0))) { return error; } swayc_t *container = get_focused_view(&root_container); if(container->type != C_VIEW){ return cmd_results_new(CMD_INVALID, "fullscreen", "Only views can fullscreen"); } swayc_t *workspace = swayc_parent_by_type(container, C_WORKSPACE); bool current = swayc_is_fullscreen(container); wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); if (container->is_floating) { if (current) { // set dimensions back to what they were before we fullscreened this container->x = container->cached_geometry.origin.x; container->y = container->cached_geometry.origin.y; container->width = container->cached_geometry.size.w; container->height = container->cached_geometry.size.h; } else { // cache dimensions so we can reset them after we "unfullscreen" this struct wlc_geometry geo = { .origin = { .x = container->x, .y = container->y }, .size = { .w = container->width, .h = container->height } }; container->cached_geometry = geo; } }
bool set_focused_container(swayc_t *c) { if (locked_container_focus || !c || !c->parent) { return false; } swayc_t *active_ws = swayc_active_workspace(); int active_ws_child_count = 0; if (active_ws) { active_ws_child_count = active_ws->children->length + active_ws->floating->length; } swayc_log(L_DEBUG, c, "Setting focus to %p:%" PRIuPTR, c, c->handle); // Get workspace for c, get that workspaces current focused container. swayc_t *workspace = swayc_active_workspace_for(c); swayc_t *focused = get_focused_view(workspace); if (swayc_is_fullscreen(focused) && focused != c) { // if switching to a workspace with a fullscreen view, // focus on the fullscreen view c = focused; } if (c->type == C_VIEW) { // dispatch a window event ipc_event_window(c, "focus"); } // update container focus from here to root, making necessary changes along // the way swayc_t *p = c; if (p->type != C_OUTPUT && p->type != C_ROOT) { p->is_focused = true; } while (p != &root_container) { update_focus(p); p = p->parent; p->is_focused = false; } // get new focused view and set focus to it. p = get_focused_view(c); if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { // unactivate previous focus if (focused->type == C_VIEW) { wlc_view_set_state(focused->handle, WLC_BIT_ACTIVATED, false); update_view_border(focused); } // activate current focus if (p->type == C_VIEW) { wlc_view_set_state(p->handle, WLC_BIT_ACTIVATED, true); // set focus if view_focus is unlocked if (!locked_view_focus) { wlc_view_focus(p->handle); if (p->parent->layout != L_TABBED && p->parent->layout != L_STACKED) { update_view_border(p); } } } // rearrange if parent container is tabbed/stacked swayc_t *parent = swayc_tabbed_stacked_ancestor(p); if (parent != NULL) { arrange_backgrounds(); arrange_windows(parent, -1, -1); } } else if (p->type == C_WORKSPACE) { // remove previous focus if view_focus is unlocked if (!locked_view_focus) { wlc_view_focus(0); } } if (active_ws != workspace) { // active_ws might have been destroyed by now // (focus swap away from empty ws = destroy ws) if (active_ws_child_count == 0) { active_ws = NULL; } ipc_event_workspace(active_ws, workspace, "focus"); } return true; }
static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { // Update view pointer is on pointer_state.view = container_under_pointer(); // Update pointer origin pointer_state.origin.x = origin->x; pointer_state.origin.y = origin->y; // Update pointer_state switch (button) { case M_LEFT_CLICK: if (state == WLC_BUTTON_STATE_PRESSED) { pointer_state.left.held = true; pointer_state.left.x = origin->x; pointer_state.left.y = origin->y; pointer_state.left.view = pointer_state.view; } else { pointer_state.left.held = false; } break; case M_RIGHT_CLICK: if (state == WLC_BUTTON_STATE_PRESSED) { pointer_state.right.held = true; pointer_state.right.x = origin->x; pointer_state.right.y = origin->y; pointer_state.right.view = pointer_state.view; } else { pointer_state.right.held = false; } break; case M_SCROLL_CLICK: if (state == WLC_BUTTON_STATE_PRESSED) { pointer_state.scroll.held = true; pointer_state.scroll.x = origin->x; pointer_state.scroll.y = origin->y; pointer_state.scroll.view = pointer_state.view; } else { pointer_state.scroll.held = false; } break; //TODO scrolling behavior case M_SCROLL_UP: case M_SCROLL_DOWN: break; } // get focused window and check if to change focus on mouse click swayc_t *focused = get_focused_container(&root_container); // dont change focus or mode if fullscreen if (swayc_is_fullscreen(focused)) { return EVENT_PASSTHROUGH; } // set pointer mode only if floating mod has been set if (config->floating_mod) { pointer_mode_set(button, !(modifiers->mods ^ config->floating_mod)); } // Check whether to change focus swayc_t *pointer = pointer_state.view; if (pointer) { if (focused != pointer) { set_focused_container(pointer_state.view); } // Send to front if floating if (pointer->is_floating) { int i; for (i = 0; i < pointer->parent->floating->length; i++) { if (pointer->parent->floating->items[i] == pointer) { list_del(pointer->parent->floating, i); list_add(pointer->parent->floating, pointer); break; } } wlc_view_bring_to_front(pointer->handle); } } // Return if mode has been set if (pointer_state.mode) { return EVENT_HANDLED; } // Always send mouse release if (state == WLC_BUTTON_STATE_RELEASED) { return EVENT_PASSTHROUGH; } // Finally send click return EVENT_PASSTHROUGH; }