//although bool view_created(tw_handle view) { //routine: //0): create a view: which is most likely insert a node to a list tw_handle output = wlc_view_get_output(view); Layout *layout = tw_output_get_current_layout(output);//it shouldn't be //Null, one output //should at least //has one layout struct wl_resource *surface = wlc_surface_get_wl_resource(wlc_view_get_surface(view)); if (TMP_DATA[0] == surface) debug_log("BG_VIEW created\n"); else if (TMP_DATA[1] == surface) debug_log("PANEL_VIEW created\n"); else if (TMP_DATA[2] == surface) debug_log("LOCK_VIEW created\n"); if (!layout->createView(view)) return false; //call update view layout->update_views(); //1): setting up the view visibility attributes, focus attributes, etc. wlc_view_set_mask(view, wlc_output_get_mask(output)); wlc_view_bring_to_front(view); //you have to call it at floating layout wlc_view_focus(view); //2): relayout relayout(wlc_view_get_output(view)); return true; }
/** * * @brief the simple floating windows relayout strategy, which is actually * doing nothing. * * Tested */ static void relayout_float(const tw_handle *views, const size_t nviews, const wlc_geometry *geo) { //this method has to be called in safe env. if(!views || !geo) return; const wlc_size *r = &geo->size; //this method is not safe, how do you ensure you will not access //unallocated memory? c++ vector? for (size_t i = 0; i < nviews; i++) { debug_log("relayout_float\n"); //the only thing we are doing here is ensure the the window //does not go out or border, but is may not be good, since //windows can have border struct wlc_geometry g = *wlc_view_get_geometry(views[i]); g.size.h = (g.size.h > 0) ? g.size.h : 100;//give a initial height if not avaliable g.size.w = (g.size.w > 0) ? g.size.w : 100;//give a initial wpidth if not avaliable int32_t view_botton = g.origin.y+g.size.h; int32_t view_right = g.origin.x+g.size.w; g.size.h = MIN(view_botton, r->h) - g.origin.y; g.size.w = MIN(view_right, r->w) - g.origin.x; wlc_view_set_geometry(views[i], 0, &g); wlc_view_bring_to_front(views[i]); } }
static bool view_created(wlc_handle view) { printf("created\n"); wlc_view_bring_to_front(view); wlc_view_focus(view); return true; }
static bool view_created(wlc_handle view) { printf("created view (%zu)\n", view); wlc_view_bring_to_front(view); wlc_view_focus(view); relayout(wlc_view_get_output(view)); return true; }
void set_view_visibility(swayc_t *view, void *data) { uint32_t *p = data; if (view->type == C_VIEW) { wlc_view_set_mask(view->handle, *p); if (*p == 2) { wlc_view_bring_to_front(view->handle); } else { wlc_view_send_to_back(view->handle); } } view->visible = (*p == 2); }
static bool handle_view_created(wlc_handle handle) { swayc_t *focused = get_focused_container(&root_container); swayc_t *newview = NULL; 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; // takes keyboard focus case WLC_BIT_OVERRIDE_REDIRECT: sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT", handle); locked_view_focus = true; wlc_view_focus(handle); wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true); wlc_view_bring_to_front(handle); break; // Takes container focus case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED: sway_log(L_DEBUG, "view %ld with OVERRIDE_REDIRECT|WLC_BIT_MANAGED", handle); wlc_view_bring_to_front(handle); locked_container_focus = true; break; // set modals as floating containers case WLC_BIT_MODAL: wlc_view_bring_to_front(handle); newview = new_floating_view(handle); case WLC_BIT_POPUP: break; } if (newview) { set_focused_container(newview); arrange_windows(newview->parent, -1, -1); } return true; }
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 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; }
void arrange_windows(swayc_t *container, int width, int height) { int i; if (width == -1 || height == -1) { sway_log(L_DEBUG, "Arranging layout for %p", container); width = container->width; height = container->height; } int x = 0, y = 0; switch (container->type) { case C_ROOT: for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; sway_log(L_DEBUG, "Arranging output at %d", x); child->x = x; child->y = y; arrange_windows(child, -1, -1); // Removed for now because wlc works with relative positions // Addition can be reconsidered once wlc positions are changed // x += child->width; } return; case C_OUTPUT: container->width = width; container->height = height; // These lines make x/y negative and result in stuff glitching out // Their addition can be reconsidered once wlc positions are changed // x -= container->x; // y -= container->y; for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; child->x = x + container->gaps; child->y = y + container->gaps; child->width = width - container->gaps * 2; child->height = height - container->gaps * 2; sway_log(L_DEBUG, "Arranging workspace #%d at %d, %d", i, child->x, child->y); arrange_windows(child, -1, -1); } return; case C_VIEW: { struct wlc_geometry geometry = { .origin = { .x = container->x + container->gaps, .y = container->y + container->gaps }, .size = { .w = width - container->gaps * 2, .h = height - container->gaps * 2 } }; if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) { swayc_t *parent = container; while (parent->type != C_OUTPUT) { parent = parent->parent; } geometry.origin.x = 0; geometry.origin.y = 0; geometry.size.w = parent->width; geometry.size.h = parent->height; wlc_view_set_geometry(container->handle, 0, &geometry); wlc_view_bring_to_front(container->handle); } else { wlc_view_set_geometry(container->handle, 0, &geometry); container->width = width; container->height = height; } sway_log(L_DEBUG, "Set view to %d x %d @ %d, %d", geometry.size.w, geometry.size.h, geometry.origin.x, geometry.origin.y); } return; default: container->width = width; container->height = height; break; }
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; }