meta_window_move_resize_internal (MetaWindow * window, MetaMoveResizeFlags flags, int resize_gravity, int root_x_nw, int root_y_nw, int w, int h) { unsigned int mask; MetaFrameGeometry fgeom; gboolean need_resize_client = (0); gboolean is_configure_request; MetaRectangle new_rect; MetaRectangle old_rect; { adjust_for_gravity (window, window->frame ? &fgeom : ((void *) 0), is_configure_request, window->size_hints.win_gravity, &new_rect); } meta_window_constrain (window, window->frame ? &fgeom : ((void *) 0), flags, resize_gravity, &old_rect, &new_rect); if (mask != 0) { { meta_topic_real (META_DEBUG_GEOMETRY, need_resize_client ? "true" : "false"); } } { window->user_has_move_resized = (!(0)); meta_window_get_position (window, &window->user_rect.x, &window->user_rect.y); } }
void meta_core_get (Display *xdisplay, Window xwindow, ...) { va_list args; MetaCoreGetType request; MetaDisplay *display = meta_display_for_x_display (xdisplay); MetaWindow *window = meta_display_lookup_x_window (display, xwindow); va_start (args, xwindow); request = va_arg (args, MetaCoreGetType); /* Now, we special-case the first request slightly. Mostly, requests * for information on windows which have no frame are errors. * But sometimes we may want to know *whether* a window has a frame. * In this case, pass the key META_CORE_WINDOW_HAS_FRAME * as the *first* request, with a pointer to a boolean; if the window * has no frame, this will be set to False and meta_core_get will * exit immediately (so the values of any other requests will be * undefined). Otherwise it will be set to True and meta_core_get will * continue happily on its way. */ if (request != META_CORE_WINDOW_HAS_FRAME && (window == NULL || window->frame == NULL)) { meta_bug ("No such frame window 0x%lx!\n", xwindow); return; } while (request != META_CORE_GET_END) { gpointer answer = va_arg (args, gpointer); switch (request) { case META_CORE_WINDOW_HAS_FRAME: *((gboolean*)answer) = window != NULL && window->frame != NULL; if (!*((gboolean*)answer)) return; /* see above */ break; case META_CORE_GET_CLIENT_WIDTH: *((gint*)answer) = window->rect.width; break; case META_CORE_GET_CLIENT_HEIGHT: *((gint*)answer) = window->rect.height; break; case META_CORE_IS_TITLEBAR_ONSCREEN: *((gboolean*)answer) = meta_window_titlebar_is_onscreen (window); break; case META_CORE_GET_CLIENT_XWINDOW: *((Window*)answer) = window->xwindow; break; case META_CORE_GET_FRAME_FLAGS: *((MetaFrameFlags*)answer) = meta_frame_get_flags (window->frame); break; case META_CORE_GET_FRAME_TYPE: { MetaFrameType base_type = META_FRAME_TYPE_LAST; switch (window->type) { case META_WINDOW_NORMAL: base_type = META_FRAME_TYPE_NORMAL; break; case META_WINDOW_DIALOG: base_type = META_FRAME_TYPE_DIALOG; break; case META_WINDOW_MODAL_DIALOG: base_type = META_FRAME_TYPE_MODAL_DIALOG; break; case META_WINDOW_MENU: base_type = META_FRAME_TYPE_MENU; break; case META_WINDOW_UTILITY: base_type = META_FRAME_TYPE_UTILITY; break; case META_WINDOW_DESKTOP: case META_WINDOW_DOCK: case META_WINDOW_TOOLBAR: case META_WINDOW_SPLASHSCREEN: /* No frame */ base_type = META_FRAME_TYPE_LAST; break; } if (base_type == META_FRAME_TYPE_LAST) { /* can't add border if undecorated */ *((MetaFrameType*)answer) = META_FRAME_TYPE_LAST; } else if (window->border_only) { /* override base frame type */ *((MetaFrameType*)answer) = META_FRAME_TYPE_BORDER; } else { *((MetaFrameType*)answer) = base_type; } break; } case META_CORE_GET_MINI_ICON: *((GdkPixbuf**)answer) = window->mini_icon; break; case META_CORE_GET_ICON: *((GdkPixbuf**)answer) = window->icon; break; case META_CORE_GET_X: meta_window_get_position (window, (int*)answer, NULL); break; case META_CORE_GET_Y: meta_window_get_position (window, NULL, (int*)answer); break; case META_CORE_GET_FRAME_WORKSPACE: *((gint*)answer) = meta_window_get_net_wm_desktop (window); break; case META_CORE_GET_FRAME_X: *((gint*)answer) = window->frame->rect.x; break; case META_CORE_GET_FRAME_Y: *((gint*)answer) = window->frame->rect.y; break; case META_CORE_GET_FRAME_WIDTH: *((gint*)answer) = window->frame->rect.width; break; case META_CORE_GET_FRAME_HEIGHT: *((gint*)answer) = window->frame->rect.height; break; case META_CORE_GET_SCREEN_WIDTH: *((gint*)answer) = window->screen->rect.width; break; case META_CORE_GET_SCREEN_HEIGHT: *((gint*)answer) = window->screen->rect.height; break; default: meta_warning(_("Unknown window information request: %d"), request); } request = va_arg (args, MetaCoreGetType); } va_end (args); }
static void find_next_cascade (MetaWindow *window, MetaFrameGeometry *fgeom, /* visible windows on relevant workspaces */ GList *windows, int x, int y, int *new_x, int *new_y) { GList *tmp; GList *sorted; int cascade_x, cascade_y; int x_threshold, y_threshold; int window_width, window_height; int cascade_stage; MetaRectangle work_area; const MetaXineramaScreenInfo* current; sorted = g_list_copy (windows); sorted = g_list_sort (sorted, northwestcmp); /* This is a "fuzzy" cascade algorithm. * For each window in the list, we find where we'd cascade a * new window after it. If a window is already nearly at that * position, we move on. */ /* arbitrary-ish threshold, honors user attempts to * manually cascade. */ #define CASCADE_FUZZ 15 if (fgeom) { x_threshold = MAX (fgeom->left_width, CASCADE_FUZZ); y_threshold = MAX (fgeom->top_height, CASCADE_FUZZ); } else { x_threshold = CASCADE_FUZZ; y_threshold = CASCADE_FUZZ; } /* Find furthest-SE origin of all workspaces. * cascade_x, cascade_y are the target position * of NW corner of window frame. */ current = meta_screen_get_current_xinerama (window->screen); meta_window_get_work_area_for_xinerama (window, current->number, &work_area); cascade_x = MAX (0, work_area.x); cascade_y = MAX (0, work_area.y); /* Find first cascade position that's not used. */ window_width = window->frame ? window->frame->rect.width : window->rect.width; window_height = window->frame ? window->frame->rect.height : window->rect.height; cascade_stage = 0; tmp = sorted; while (tmp != NULL) { MetaWindow *w; int wx, wy; w = tmp->data; /* we want frame position, not window position */ if (w->frame) { wx = w->frame->rect.x; wy = w->frame->rect.y; } else { wx = w->rect.x; wy = w->rect.y; } if (ABS (wx - cascade_x) < x_threshold && ABS (wy - cascade_y) < y_threshold) { /* This window is "in the way", move to next cascade * point. The new window frame should go at the origin * of the client window we're stacking above. */ meta_window_get_position (w, &wx, &wy); cascade_x = wx; cascade_y = wy; /* If we go off the screen, start over with a new cascade */ if (((cascade_x + window_width) > (work_area.x + work_area.width)) || ((cascade_y + window_height) > (work_area.y + work_area.height))) { cascade_x = MAX (0, work_area.x); cascade_y = MAX (0, work_area.y); #define CASCADE_INTERVAL 50 /* space between top-left corners of cascades */ cascade_stage += 1; cascade_x += CASCADE_INTERVAL * cascade_stage; /* start over with a new cascade translated to the right, unless * we are out of space */ if ((cascade_x + window_width) < (work_area.x + work_area.width)) { tmp = sorted; continue; } else { /* All out of space, this cascade_x won't work */ cascade_x = MAX (0, work_area.x); break; } } } else { /* Keep searching for a further-down-the-diagonal window. */ } tmp = tmp->next; } /* cascade_x and cascade_y will match the last window in the list * that was "in the way" (in the approximate cascade diagonal) */ g_list_free (sorted); /* Convert coords to position of window, not position of frame. */ if (fgeom == NULL) { *new_x = cascade_x; *new_y = cascade_y; } else { *new_x = cascade_x + fgeom->left_width; *new_y = cascade_y + fgeom->top_height; } }
void meta_core_get (Display *xdisplay, Window xwindow, ...) { va_list args; MetaCoreGetType request; MetaDisplay *display = meta_display_for_x_display (xdisplay); MetaWindow *window = meta_display_lookup_x_window (display, xwindow); va_start (args, xwindow); request = va_arg (args, MetaCoreGetType); /* Now, we special-case the first request slightly. Mostly, requests * for information on windows which have no frame are errors. * But sometimes we may want to know *whether* a window has a frame. * In this case, pass the key META_CORE_WINDOW_HAS_FRAME * as the *first* request, with a pointer to a boolean; if the window * has no frame, this will be set to False and meta_core_get will * exit immediately (so the values of any other requests will be * undefined). Otherwise it will be set to True and meta_core_get will * continue happily on its way. */ if (request != META_CORE_WINDOW_HAS_FRAME && (window == NULL || window->frame == NULL)) { meta_bug ("No such frame window 0x%lx!\n", xwindow); return; } while (request != META_CORE_GET_END) { gpointer answer = va_arg (args, gpointer); switch (request) { case META_CORE_WINDOW_HAS_FRAME: *((gboolean*)answer) = window != NULL && window->frame != NULL; if (!*((gboolean*)answer)) return; /* see above */ break; case META_CORE_GET_CLIENT_WIDTH: *((gint*)answer) = window->rect.width; break; case META_CORE_GET_CLIENT_HEIGHT: *((gint*)answer) = window->rect.height; break; case META_CORE_GET_CLIENT_XWINDOW: *((Window*)answer) = window->xwindow; break; case META_CORE_GET_FRAME_FLAGS: *((MetaFrameFlags*)answer) = meta_frame_get_flags (window->frame); break; case META_CORE_GET_FRAME_TYPE: *((MetaFrameType*)answer) = meta_window_get_frame_type (window); break; case META_CORE_GET_MINI_ICON: *((GdkPixbuf**)answer) = window->mini_icon; break; case META_CORE_GET_ICON: *((GdkPixbuf**)answer) = window->icon; break; case META_CORE_GET_X: meta_window_get_position (window, (int*)answer, NULL); break; case META_CORE_GET_Y: meta_window_get_position (window, NULL, (int*)answer); break; case META_CORE_GET_FRAME_WORKSPACE: *((gint*)answer) = meta_window_get_net_wm_desktop (window); break; case META_CORE_GET_FRAME_X: *((gint*)answer) = window->frame->rect.x; break; case META_CORE_GET_FRAME_Y: *((gint*)answer) = window->frame->rect.y; break; case META_CORE_GET_FRAME_WIDTH: *((gint*)answer) = window->frame->rect.width; break; case META_CORE_GET_FRAME_HEIGHT: *((gint*)answer) = window->frame->rect.height; break; case META_CORE_GET_THEME_VARIANT: *((char**)answer) = window->gtk_theme_variant; break; case META_CORE_GET_SCREEN_WIDTH: *((gint*)answer) = window->screen->rect.width; break; case META_CORE_GET_SCREEN_HEIGHT: *((gint*)answer) = window->screen->rect.height; break; default: meta_warning(_("Unknown window information request: %d"), request); } request = va_arg (args, MetaCoreGetType); } va_end (args); }
void meta_window_place (MetaWindow *window, MetaFrameGeometry *fgeom, int x, int y, int *new_x, int *new_y) { GList *windows; const MetaXineramaScreenInfo *xi; /* frame member variables should NEVER be used in here, only * MetaFrameGeometry. But remember fgeom == NULL * for undecorated windows. Also, this function should * NEVER have side effects other than computing the * placement coordinates. */ meta_topic (META_DEBUG_PLACEMENT, "Placing window %s\n", window->desc); windows = NULL; switch (window->type) { /* Run placement algorithm on these. */ case META_WINDOW_NORMAL: case META_WINDOW_DIALOG: case META_WINDOW_MODAL_DIALOG: case META_WINDOW_SPLASHSCREEN: break; /* Assume the app knows best how to place these, no placement * algorithm ever (other than "leave them as-is") */ case META_WINDOW_DESKTOP: case META_WINDOW_DOCK: case META_WINDOW_TOOLBAR: case META_WINDOW_MENU: case META_WINDOW_UTILITY: goto done_no_constraints; } if (meta_prefs_get_disable_workarounds ()) { switch (window->type) { /* Only accept USPosition on normal windows because the app is full * of shit claiming the user set -geometry for a dialog or dock */ case META_WINDOW_NORMAL: if (window->size_hints.flags & USPosition) { /* don't constrain with placement algorithm */ meta_topic (META_DEBUG_PLACEMENT, "Honoring USPosition for %s instead of using placement algorithm\n", window->desc); goto done; } break; /* Ignore even USPosition on dialogs, splashscreen */ case META_WINDOW_DIALOG: case META_WINDOW_MODAL_DIALOG: case META_WINDOW_SPLASHSCREEN: break; /* Assume the app knows best how to place these. */ case META_WINDOW_DESKTOP: case META_WINDOW_DOCK: case META_WINDOW_TOOLBAR: case META_WINDOW_MENU: case META_WINDOW_UTILITY: if (window->size_hints.flags & PPosition) { meta_topic (META_DEBUG_PLACEMENT, "Not placing non-normal non-dialog window with PPosition set\n"); goto done_no_constraints; } break; } } else { /* workarounds enabled */ if ((window->size_hints.flags & PPosition) || (window->size_hints.flags & USPosition)) { meta_topic (META_DEBUG_PLACEMENT, "Not placing window with PPosition or USPosition set\n"); avoid_being_obscured_as_second_modal_dialog (window, fgeom, &x, &y); goto done_no_constraints; } } if ((window->type == META_WINDOW_DIALOG || window->type == META_WINDOW_MODAL_DIALOG) && window->xtransient_for != None) { /* Center horizontally, at top of parent vertically */ MetaWindow *parent; parent = meta_display_lookup_x_window (window->display, window->xtransient_for); if (parent) { int w; meta_window_get_position (parent, &x, &y); w = parent->rect.width; /* center of parent */ x = x + w / 2; /* center of child over center of parent */ x -= window->rect.width / 2; /* "visually" center window over parent, leaving twice as * much space below as on top. */ y += (parent->rect.height - window->rect.height)/3; /* put top of child's frame, not top of child's client */ if (fgeom) y += fgeom->top_height; meta_topic (META_DEBUG_PLACEMENT, "Centered window %s over transient parent\n", window->desc); avoid_being_obscured_as_second_modal_dialog (window, fgeom, &x, &y); goto done; } } /* FIXME UTILITY with transient set should be stacked up * on the sides of the parent window or something. */ if (window->type == META_WINDOW_DIALOG || window->type == META_WINDOW_MODAL_DIALOG || window->type == META_WINDOW_SPLASHSCREEN) { /* Center on current xinerama (i.e. on current monitor) */ int w, h; /* Warning, this function is a round trip! */ xi = meta_screen_get_current_xinerama (window->screen); w = xi->rect.width; h = xi->rect.height; x = (w - window->rect.width) / 2; y = (h - window->rect.height) / 2; x += xi->rect.x; y += xi->rect.y; meta_topic (META_DEBUG_PLACEMENT, "Centered window %s on screen %d xinerama %d\n", window->desc, window->screen->number, xi->number); goto done_check_denied_focus; } /* Find windows that matter (not minimized, on same workspace * as placed window, may be shaded - if shaded we pretend it isn't * for placement purposes) */ { GSList *all_windows; GSList *tmp; all_windows = meta_display_list_windows (window->display); tmp = all_windows; while (tmp != NULL) { MetaWindow *w = tmp->data; if (meta_window_showing_on_its_workspace (w) && w != window && (window->workspace == w->workspace || window->on_all_workspaces || w->on_all_workspaces)) windows = g_list_prepend (windows, w); tmp = tmp->next; } g_slist_free (all_windows); } /* Warning, this is a round trip! */ xi = meta_screen_get_current_xinerama (window->screen); /* "Origin" placement algorithm */ x = xi->rect.x; y = xi->rect.y; if (find_first_fit (window, fgeom, windows, xi->number, x, y, &x, &y)) goto done_check_denied_focus; /* Maximize windows if they are too big for their work area (bit of * a hack here). Assume undecorated windows probably don't intend to * be maximized. */ if (window->has_maximize_func && window->decorated && !window->fullscreen) { MetaRectangle workarea; MetaRectangle outer; meta_window_get_work_area_for_xinerama (window, xi->number, &workarea); meta_window_get_outer_rect (window, &outer); /* If the window is bigger than the screen, then automaximize. Do NOT * auto-maximize the directions independently. See #419810. */ if (outer.width >= workarea.width && outer.height >= workarea.height) { window->maximize_horizontally_after_placement = TRUE; window->maximize_vertically_after_placement = TRUE; } } /* If no placement has been done, revert to cascade to avoid * fully overlapping window (e.g. starting multiple terminals) * */ if (!meta_prefs_get_center_new_windows() && (x == xi->rect.x && y == xi->rect.y)) find_next_cascade (window, fgeom, windows, x, y, &x, &y); done_check_denied_focus: /* If the window is being denied focus and isn't a transient of the * focus window, we do NOT want it to overlap with the focus window * if at all possible. This is guaranteed to only be called if the * focus_window is non-NULL, and we try to avoid that window. */ if (window->denied_focus_and_not_transient) { gboolean found_fit; MetaWindow *focus_window; MetaRectangle overlap; focus_window = window->display->focus_window; g_assert (focus_window != NULL); /* No need to do anything if the window doesn't overlap at all */ found_fit = !meta_rectangle_intersect (&window->rect, &focus_window->rect, &overlap); /* Try to do a first fit again, this time only taking into account the * focus window. */ if (!meta_prefs_get_center_new_windows() && !found_fit) { GList *focus_window_list; focus_window_list = g_list_prepend (NULL, focus_window); /* Reset x and y ("origin" placement algorithm) */ x = xi->rect.x; y = xi->rect.y; found_fit = find_first_fit (window, fgeom, focus_window_list, xi->number, x, y, &x, &y); g_list_free (focus_window_list); } /* If that still didn't work, just place it where we can see as much * as possible. */ if (!found_fit) find_most_freespace (window, fgeom, focus_window, x, y, &x, &y); } done: g_list_free (windows); done_no_constraints: *new_x = x; *new_y = y; }