/* Metacity X managed windows */ /* * Copyright (C) 2001 Havoc Pennington * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include "window.h" #include "util.h" #include "frame.h" #include "errors.h" #include "workspace.h" #include "stack.h" #include "keybindings.h" #include "ui.h" #include static void constrain_size (MetaWindow *window, MetaFrameGeometry *fgeom, int width, int height, int *new_width, int *new_height); static void constrain_position (MetaWindow *window, MetaFrameGeometry *fgeom, int x, int y, int *new_x, int *new_y); static int update_size_hints (MetaWindow *window); static int update_title (MetaWindow *window); static int update_protocols (MetaWindow *window); static int update_wm_hints (MetaWindow *window); static int update_net_wm_state (MetaWindow *window); static int update_mwm_hints (MetaWindow *window); static int update_wm_class (MetaWindow *window); static int update_transient_for (MetaWindow *window); static void update_sm_hints (MetaWindow *window); static int update_role (MetaWindow *window); static int update_net_wm_type (MetaWindow *window); static int update_initial_workspace (MetaWindow *window); static void recalc_window_type (MetaWindow *window); static void recalc_window_features (MetaWindow *window); static int set_wm_state (MetaWindow *window, int state); static int set_net_wm_state (MetaWindow *window); static void send_configure_notify (MetaWindow *window); static gboolean process_configure_request (MetaWindow *window, int x, int y, int width, int height, int border_width); static gboolean process_property_notify (MetaWindow *window, XPropertyEvent *event); static void meta_window_show (MetaWindow *window); static void meta_window_hide (MetaWindow *window); static void meta_window_move_resize_internal (MetaWindow *window, gboolean is_configure_request, int root_x_nw, int root_y_nw, int w, int h); static gboolean get_cardinal (MetaDisplay *display, Window xwindow, Atom atom, gulong *val); void meta_window_unqueue_calc_showing (MetaWindow *window); MetaWindow* meta_window_new (MetaDisplay *display, Window xwindow, gboolean must_be_viewable) { MetaWindow *window; XWindowAttributes attrs; GSList *tmp; MetaWorkspace *space; meta_verbose ("Attempting to manage 0x%lx\n", xwindow); /* Grab server */ meta_display_grab (display); meta_error_trap_push (display); XGetWindowAttributes (display->xdisplay, xwindow, &attrs); if (meta_error_trap_pop (display)) { meta_verbose ("Failed to get attributes for window 0x%lx\n", xwindow); meta_display_ungrab (display); return NULL; } if (attrs.override_redirect) { meta_verbose ("Deciding not to manage override_redirect window 0x%lx\n", xwindow); meta_display_ungrab (display); return NULL; } if (must_be_viewable && attrs.map_state != IsViewable) { /* Only manage if WM_STATE is IconicState or NormalState */ gulong state; if (!(get_cardinal (display, xwindow, display->atom_wm_state, &state) && (state == IconicState || state == NormalState))) { meta_verbose ("Deciding not to manage unmapped or unviewable window 0x%lx\n", xwindow); meta_display_ungrab (display); return NULL; } /* FIXME should honor WM_STATE probably */ } meta_error_trap_push (display); XAddToSaveSet (display->xdisplay, xwindow); XSelectInput (display->xdisplay, xwindow, PropertyChangeMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask); /* Get rid of any borders */ if (attrs.border_width != 0) XSetWindowBorderWidth (display->xdisplay, xwindow, 0); if (meta_error_trap_pop (display) != Success) { meta_verbose ("Window 0x%lx disappeared just as we tried to manage it\n", xwindow); meta_display_ungrab (display); return NULL; } g_assert (!attrs.override_redirect); window = g_new (MetaWindow, 1); window->xwindow = xwindow; /* this is in window->screen->display, but that's too annoying to * type */ window->display = display; window->workspaces = NULL; window->screen = NULL; tmp = display->screens; while (tmp != NULL) { if (((MetaScreen *)tmp->data)->xscreen == attrs.screen) { window->screen = tmp->data; break; } tmp = tmp->next; } g_assert (window->screen); /* avoid tons of stack updates */ meta_stack_freeze (window->screen->stack); /* Remember this rect is the actual window size */ window->rect.x = attrs.x; window->rect.y = attrs.y; window->rect.width = attrs.width; window->rect.height = attrs.height; /* And border width, size_hints are the "request" */ window->border_width = attrs.border_width; window->size_hints.x = attrs.x; window->size_hints.y = attrs.y; window->size_hints.width = attrs.width; window->size_hints.height = attrs.height; /* And this is our unmaximized size */ window->saved_rect = window->rect; window->depth = attrs.depth; window->xvisual = attrs.visual; window->title = NULL; window->desc = g_strdup_printf ("0x%lx", window->xwindow); window->frame = NULL; window->has_focus = FALSE; window->user_has_resized = FALSE; window->user_has_moved = FALSE; window->maximized = FALSE; window->on_all_workspaces = FALSE; window->shaded = FALSE; window->initially_iconic = FALSE; window->minimized = FALSE; window->iconic = FALSE; window->mapped = attrs.map_state != IsUnmapped; /* if already mapped we don't want to do the placement thing */ window->placed = window->mapped; window->unmanaging = FALSE; window->calc_showing_queued = FALSE; window->keys_grabbed = FALSE; window->grab_on_frame = FALSE; window->withdrawn = FALSE; window->unmaps_pending = 0; window->mwm_decorated = TRUE; window->mwm_has_close_func = TRUE; window->mwm_has_minimize_func = TRUE; window->mwm_has_maximize_func = TRUE; window->mwm_has_move_func = TRUE; window->mwm_has_resize_func = TRUE; window->decorated = TRUE; window->has_close_func = TRUE; window->has_minimize_func = TRUE; window->has_maximize_func = TRUE; window->has_move_func = TRUE; window->has_resize_func = TRUE; window->has_shade_func = TRUE; window->wm_state_modal = FALSE; window->wm_state_skip_taskbar = FALSE; window->wm_state_skip_pager = FALSE; window->res_class = NULL; window->res_name = NULL; window->role = NULL; window->sm_client_id = NULL; window->xtransient_for = None; window->xgroup_leader = None; window->xclient_leader = None; window->type = META_WINDOW_NORMAL; window->type_atom = None; window->layer = META_LAYER_NORMAL; window->stack_op = NULL; window->initial_workspace = meta_workspace_screen_index (window->screen->active_workspace); meta_display_register_x_window (display, &window->xwindow, window); update_size_hints (window); update_title (window); update_protocols (window); update_wm_hints (window); update_net_wm_state (window); update_mwm_hints (window); update_wm_class (window); update_transient_for (window); update_sm_hints (window); /* must come after transient_for */ update_role (window); update_net_wm_type (window); update_initial_workspace (window); if (window->initially_iconic) { /* WM_HINTS said minimized */ window->minimized = TRUE; meta_verbose ("Window %s asked to start out minimized\n", window->desc); } /* FIXME we have a tendency to set this then immediately * change it again. */ set_wm_state (window, window->iconic ? IconicState : NormalState); set_net_wm_state (window); if (window->decorated) meta_window_ensure_frame (window); meta_window_grab_keys (window); space = meta_display_get_workspace_by_screen_index (window->display, window->screen, window->initial_workspace); if (space == NULL) space = window->screen->active_workspace; meta_workspace_add_window (space, window); /* Only accept USPosition on normal windows because the app is full * of shit claiming the user set -geometry for a dialog or dock */ if (window->type == META_WINDOW_NORMAL && (window->size_hints.flags & USPosition)) { /* don't constrain with placement algorithm */ window->placed = TRUE; meta_verbose ("Honoring USPosition for %s instead of using placement algorithm\n", window->desc); } if (window->type != META_WINDOW_NORMAL) { window->placed = TRUE; meta_verbose ("Not placing non-normal-type window\n"); } if (window->type == META_WINDOW_DESKTOP || window->type == META_WINDOW_DOCK) { /* Change the default */ window->on_all_workspaces = TRUE; } /* Put our state back where it should be, * passing TRUE for is_configure_request, ICCCM says * initial map is handled same as configure request */ meta_window_move_resize_internal (window, TRUE, window->size_hints.x, window->size_hints.y, window->size_hints.width, window->size_hints.height); meta_stack_add (window->screen->stack, window); /* Sync stack changes */ meta_stack_thaw (window->screen->stack); meta_window_queue_calc_showing (window); meta_display_ungrab (display); return window; } void meta_window_free (MetaWindow *window) { GList *tmp; meta_verbose ("Unmanaging 0x%lx\n", window->xwindow); window->unmanaging = TRUE; if (window->display->focus_window == window) window->display->focus_window = NULL; meta_window_unqueue_calc_showing (window); tmp = window->workspaces; while (tmp != NULL) { GList *next; next = tmp->next; /* pops front of list */ meta_workspace_remove_window (tmp->data, window); tmp = next; } g_assert (window->workspaces == NULL); meta_stack_remove (window->screen->stack, window); /* FIXME restore original size if window has maximized */ if (window->withdrawn) set_wm_state (window, WithdrawnState); if (window->frame) meta_window_destroy_frame (window); meta_window_ungrab_keys (window); meta_display_unregister_x_window (window->display, window->xwindow); /* Put back anything we messed up */ meta_error_trap_push (window->display); if (window->border_width != 0) XSetWindowBorderWidth (window->display->xdisplay, window->xwindow, window->border_width); meta_error_trap_pop (window->display); g_free (window->sm_client_id); g_free (window->role); g_free (window->res_class); g_free (window->res_name); g_free (window->title); g_free (window->desc); g_free (window); } static int set_wm_state (MetaWindow *window, int state) { unsigned long data[2]; /* twm sets the icon window as data[1], I couldn't find that in * ICCCM. */ data[0] = state; data[1] = None; meta_error_trap_push (window->display); XChangeProperty (window->display->xdisplay, window->xwindow, window->display->atom_wm_state, window->display->atom_wm_state, 32, PropModeReplace, (guchar*) data, 2); return meta_error_trap_pop (window->display); } static int set_net_wm_state (MetaWindow *window) { int i; unsigned long data[10]; gboolean skip_pager; gboolean skip_taskbar; if (window->type == META_WINDOW_DESKTOP || window->type == META_WINDOW_DOCK || window->type == META_WINDOW_TOOLBAR || window->type == META_WINDOW_MENU) skip_pager = TRUE; else skip_pager = FALSE; if (window->type == META_WINDOW_DESKTOP || window->type == META_WINDOW_DOCK || window->type == META_WINDOW_MENU) skip_taskbar = TRUE; else skip_taskbar = FALSE; i = 0; if (window->shaded) { data[i] = window->display->atom_net_wm_state_shaded; ++i; } if (window->wm_state_modal) { data[i] = window->display->atom_net_wm_state_modal; ++i; } if (window->wm_state_skip_pager || skip_pager) { data[i] = window->display->atom_net_wm_state_skip_pager; ++i; } if (window->wm_state_skip_taskbar || skip_pager) { data[i] = window->display->atom_net_wm_state_skip_taskbar; ++i; } if (window->maximized) { data[i] = window->display->atom_net_wm_state_maximized_horz; ++i; data[i] = window->display->atom_net_wm_state_maximized_vert; ++i; } meta_verbose ("Setting _NET_WM_STATE with %d atoms\n", i); meta_error_trap_push (window->display); XChangeProperty (window->display->xdisplay, window->xwindow, window->display->atom_net_wm_state, XA_ATOM, 32, PropModeReplace, (guchar*) data, i); return meta_error_trap_pop (window->display); } void meta_window_calc_showing (MetaWindow *window) { gboolean on_workspace; on_workspace = g_list_find (window->workspaces, window->screen->active_workspace) != NULL; if (!on_workspace) meta_verbose ("Window %s is not on workspace %d\n", window->desc, meta_workspace_index (window->screen->active_workspace)); else meta_verbose ("Window %s is on the active workspace %d\n", window->desc, meta_workspace_index (window->screen->active_workspace)); if (window->on_all_workspaces) { on_workspace = TRUE; meta_verbose ("Window %s is on all workspaces\n", window->desc); } if (window->minimized || !on_workspace) { meta_window_hide (window); } else { meta_window_show (window); } } static guint calc_showing_idle = 0; static GSList *calc_showing_pending = NULL; static gboolean idle_calc_showing (gpointer data) { GSList *tmp; tmp = calc_showing_pending; while (tmp != NULL) { MetaWindow *window; window = tmp->data; meta_window_calc_showing (window); window->calc_showing_queued = FALSE; tmp = tmp->next; } g_slist_free (calc_showing_pending); calc_showing_pending = NULL; calc_showing_idle = 0; return FALSE; } void meta_window_unqueue_calc_showing (MetaWindow *window) { if (!window->calc_showing_queued) return; meta_verbose ("Removing %s from the calc_showing queue\n", window->desc); calc_showing_pending = g_slist_remove (calc_showing_pending, window); window->calc_showing_queued = FALSE; if (calc_showing_pending == NULL && calc_showing_idle != 0) { g_source_remove (calc_showing_idle); calc_showing_idle = 0; } } void meta_window_queue_calc_showing (MetaWindow *window) { if (window->unmanaging) return; if (window->calc_showing_queued) return; meta_verbose ("Putting %s in the calc_showing queue\n", window->desc); window->calc_showing_queued = TRUE; if (calc_showing_idle == 0) calc_showing_idle = g_idle_add (idle_calc_showing, NULL); calc_showing_pending = g_slist_prepend (calc_showing_pending, window); } void meta_window_show (MetaWindow *window) { meta_verbose ("Showing window %s, shaded: %d iconic: %d\n", window->desc, window->shaded, window->iconic); /* don't ever do the initial position constraint thing again */ window->placed = TRUE; /* Shaded means the frame is mapped but the window is not */ if (window->frame && !window->frame->mapped) { meta_verbose ("Frame actually needs map\n"); window->frame->mapped = TRUE; meta_ui_map_frame (window->screen->ui, window->frame->xwindow); } if (window->shaded) { if (window->mapped) { meta_verbose ("%s actually needs unmap\n", window->desc); window->mapped = FALSE; window->unmaps_pending += 1; meta_error_trap_push (window->display); XUnmapWindow (window->display->xdisplay, window->xwindow); meta_error_trap_pop (window->display); } if (!window->iconic) { window->iconic = TRUE; set_wm_state (window, IconicState); } } else { if (!window->mapped) { meta_verbose ("%s actually needs map\n", window->desc); window->mapped = TRUE; meta_error_trap_push (window->display); XMapWindow (window->display->xdisplay, window->xwindow); meta_error_trap_pop (window->display); } if (window->iconic) { window->iconic = FALSE; set_wm_state (window, NormalState); } } } void meta_window_hide (MetaWindow *window) { meta_verbose ("Hiding window %s\n", window->desc); if (window->frame && window->frame->mapped) { meta_verbose ("Frame actually needs unmap\n"); window->frame->mapped = FALSE; meta_ui_unmap_frame (window->screen->ui, window->frame->xwindow); } if (window->mapped) { meta_verbose ("%s actually needs unmap\n", window->desc); window->mapped = FALSE; window->unmaps_pending += 1; meta_error_trap_push (window->display); XUnmapWindow (window->display->xdisplay, window->xwindow); meta_error_trap_pop (window->display); } if (!window->iconic) { window->iconic = TRUE; set_wm_state (window, IconicState); } } void meta_window_minimize (MetaWindow *window) { if (!window->minimized) { window->minimized = TRUE; meta_window_queue_calc_showing (window); } } void meta_window_unminimize (MetaWindow *window) { if (window->minimized) { window->minimized = FALSE; meta_window_queue_calc_showing (window); } } void meta_window_maximize (MetaWindow *window) { if (!window->maximized) { window->maximized = TRUE; /* save size/pos as appropriate args for move_resize */ window->saved_rect = window->rect; if (window->frame) { window->saved_rect.x += window->frame->rect.x; window->saved_rect.y += window->frame->rect.y; } /* move_resize with new maximization constraints */ meta_window_queue_move_resize (window); set_net_wm_state (window); } } void meta_window_unmaximize (MetaWindow *window) { if (window->maximized) { window->maximized = FALSE; meta_window_move_resize (window, window->saved_rect.x, window->saved_rect.y, window->saved_rect.width, window->saved_rect.height); set_net_wm_state (window); } } void meta_window_shade (MetaWindow *window) { meta_verbose ("Shading %s\n", window->desc); if (!window->shaded) { window->shaded = TRUE; meta_window_focus (window, CurrentTime); meta_window_queue_move_resize (window); meta_window_queue_calc_showing (window); set_net_wm_state (window); } } void meta_window_unshade (MetaWindow *window) { meta_verbose ("Unshading %s\n", window->desc); if (window->shaded) { window->shaded = FALSE; meta_window_queue_move_resize (window); meta_window_queue_calc_showing (window); /* focus the window */ /* FIXME CurrentTime is bogus */ meta_window_focus (window, CurrentTime); set_net_wm_state (window); } } /* returns values suitable for meta_window_move */ void adjust_for_gravity (MetaWindow *window, MetaFrameGeometry *fgeom, gboolean coords_assume_border, int x, int y, int *xp, int *yp) { int ref_x, ref_y; int bw; int child_x, child_y; int frame_width, frame_height; if (coords_assume_border) bw = window->border_width; else bw = 0; if (fgeom) { child_x = fgeom->left_width; child_y = fgeom->top_height; frame_width = child_x + window->rect.width + fgeom->right_width; frame_height = child_y + window->rect.height + fgeom->bottom_height; } else { child_x = 0; child_y = 0; frame_width = window->rect.width; frame_height = window->rect.height; } /* We're computing position to pass to window_move, which is * the position of the client window (StaticGravity basically) * * (see WM spec description of gravity computation, but note that * their formulas assume we're honoring the border width, rather * than compensating for having turned it off) */ switch (window->size_hints.win_gravity) { case NorthWestGravity: ref_x = x; ref_y = y; break; case NorthGravity: ref_x = x + window->rect.width / 2 + bw; ref_y = y; break; case NorthEastGravity: ref_x = x + window->rect.width + bw * 2; ref_y = y; break; case WestGravity: ref_x = x; ref_y = y + window->rect.height / 2 + bw; break; case CenterGravity: ref_x = x + window->rect.width / 2 + bw; ref_y = y + window->rect.height / 2 + bw; break; case EastGravity: ref_x = x + window->rect.width + bw * 2; ref_y = y + window->rect.height / 2 + bw; break; case SouthWestGravity: ref_x = x; ref_y = y + window->rect.height + bw * 2; break; case SouthGravity: ref_x = x + window->rect.width / 2 + bw; ref_y = y + window->rect.height + bw * 2; break; case SouthEastGravity: ref_x = x + window->rect.width + bw * 2; ref_y = y + window->rect.height + bw * 2; break; case StaticGravity: default: ref_x = x; ref_y = y; break; } switch (window->size_hints.win_gravity) { case NorthWestGravity: *xp = ref_x + child_x; *yp = ref_y + child_y; break; case NorthGravity: *xp = ref_x - frame_width / 2 + child_x; *yp = ref_y + child_y; break; case NorthEastGravity: *xp = ref_x - frame_width + child_x; *yp = ref_y + child_y; break; case WestGravity: *xp = ref_x + child_x; *yp = ref_y - frame_height / 2 + child_y; break; case CenterGravity: *xp = ref_x - frame_width / 2 + child_x; *yp = ref_y - frame_height / 2 + child_y; break; case EastGravity: *xp = ref_x - frame_width + child_x; *yp = ref_y - frame_height / 2 + child_y; break; case SouthWestGravity: *xp = ref_x + child_x; *yp = ref_y - frame_height + child_y; break; case SouthGravity: *xp = ref_x - frame_width / 2 + child_x; *yp = ref_y - frame_height + child_y; break; case SouthEastGravity: *xp = ref_x - frame_width + child_x; *yp = ref_y - frame_height + child_y; break; case StaticGravity: default: *xp = ref_x; *yp = ref_y; break; } } static void meta_window_move_resize_internal (MetaWindow *window, gboolean is_configure_request, int root_x_nw, int root_y_nw, int w, int h) { XWindowChanges values; unsigned int mask; gboolean need_configure_notify; MetaFrameGeometry fgeom; gboolean need_move_client = FALSE; gboolean need_move_frame = FALSE; gboolean need_resize_client = FALSE; gboolean need_resize_frame = FALSE; { int oldx, oldy; meta_window_get_position (window, &oldx, &oldy); meta_verbose ("Move/resize %s to %d,%d %dx%d%s from %d,%d %dx%d\n", window->desc, root_x_nw, root_y_nw, w, h, is_configure_request ? " (configure request)" : "", oldx, oldy, window->rect.width, window->rect.height); } if (window->frame) meta_frame_calc_geometry (window->frame, &fgeom); constrain_size (window, &fgeom, w, h, &w, &h); meta_verbose ("Constrained resize of %s to %d x %d\n", window->desc, w, h); if (w != window->rect.width || h != window->rect.height) need_resize_client = TRUE; window->rect.width = w; window->rect.height = h; if (window->frame) { int new_w, new_h; new_w = window->rect.width + fgeom.left_width + fgeom.right_width; if (window->shaded) new_h = fgeom.top_height; else new_h = window->rect.height + fgeom.top_height + fgeom.bottom_height; if (new_w != window->frame->rect.width || new_h != window->frame->rect.height) need_resize_frame = TRUE; window->frame->rect.width = new_w; window->frame->rect.height = new_h; meta_verbose ("Calculated frame size %dx%d\n", window->frame->rect.width, window->frame->rect.height); } if (is_configure_request) { adjust_for_gravity (window, window->frame ? &fgeom : NULL, /* configure request coords assume * the border width existed */ is_configure_request, root_x_nw, root_y_nw, &root_x_nw, &root_y_nw); meta_verbose ("Compensated position for gravity, new pos %d,%d\n", root_x_nw, root_y_nw); } constrain_position (window, window->frame ? &fgeom : NULL, root_x_nw, root_y_nw, &root_x_nw, &root_y_nw); meta_verbose ("Constrained position to %d,%d\n", root_x_nw, root_y_nw); if (window->frame) { int new_x, new_y; new_x = root_x_nw - fgeom.left_width; new_y = root_y_nw - fgeom.top_height; if (new_x != window->frame->rect.x || new_y != window->frame->rect.y) need_move_frame = TRUE; if (window->rect.x != fgeom.left_width || window->rect.y != fgeom.top_height) need_move_client = TRUE; window->frame->rect.x = new_x; window->frame->rect.y = new_y; /* window->rect.x, window->rect.y are relative to frame, * remember they are the server coords */ window->rect.x = fgeom.left_width; window->rect.y = fgeom.top_height; } else { if (root_x_nw != window->rect.x || root_y_nw != window->rect.y) need_move_client = TRUE; window->rect.x = root_x_nw; window->rect.y = root_y_nw; } /* Fill in other frame member variables */ if (window->frame) { window->frame->child_x = fgeom.left_width; window->frame->child_y = fgeom.top_height; window->frame->right_width = fgeom.right_width; window->frame->bottom_height = fgeom.bottom_height; } /* See ICCCM 4.1.5 for when to send ConfigureNotify */ need_configure_notify = FALSE; /* If this is a configure request and we change nothing, then we * must send configure notify. */ if (is_configure_request && !(need_move_client || need_move_frame || need_resize_client || need_resize_frame || window->border_width != 0)) need_configure_notify = TRUE; /* We must send configure notify if we move but don't resize, since * the client window may not get a real event */ if ((need_move_client || need_move_frame) && !(need_resize_client || need_resize_frame)) need_configure_notify = TRUE; /* Sync our new size/pos with X as efficiently as possible */ values.border_width = 0; values.x = window->rect.x; values.y = window->rect.y; values.width = window->rect.width; values.height = window->rect.height; mask = 0; if (is_configure_request && window->border_width != 0) mask |= CWBorderWidth; /* must force to 0 */ if (need_move_client) mask |= (CWX | CWY); if (need_resize_client) mask |= (CWWidth | CWHeight); if (mask != 0) { { int newx, newy; meta_window_get_position (window, &newx, &newy); meta_verbose ("Syncing new client geometry %d,%d %dx%d, border: %s pos: %s size: %s\n", newx, newy, window->rect.width, window->rect.height, mask & CWBorderWidth ? "true" : "false", need_move_client ? "true" : "false", need_resize_client ? "true" : "false"); } meta_error_trap_push (window->display); XConfigureWindow (window->display->xdisplay, window->xwindow, mask, &values); meta_error_trap_pop (window->display); } /* Now do the frame */ if (window->frame) meta_frame_sync_to_window (window->frame, need_move_frame, need_resize_frame); if (need_configure_notify) send_configure_notify (window); /* Invariants leaving this function are: * a) window->rect and frame->rect reflect the actual * server-side size/pos of window->xwindow and frame->xwindow * b) all constraints are obeyed by window->rect and frame->rect */ } void meta_window_resize (MetaWindow *window, int w, int h) { int x, y; meta_window_get_position (window, &x, &y); meta_window_move_resize_internal (window, FALSE, x, y, w, h); } void meta_window_move (MetaWindow *window, int root_x_nw, int root_y_nw) { meta_window_move_resize_internal (window, FALSE, root_x_nw, root_y_nw, window->rect.width, window->rect.height); } void meta_window_move_resize (MetaWindow *window, int root_x_nw, int root_y_nw, int w, int h) { meta_window_move_resize_internal (window, FALSE, root_x_nw, root_y_nw, w, h); } void meta_window_queue_move_resize (MetaWindow *window) { /* FIXME actually queue, don't do it immediately */ int x, y; meta_window_get_position (window, &x, &y); meta_window_move_resize (window, x, y, window->rect.width, window->rect.height); } void meta_window_get_position (MetaWindow *window, int *x, int *y) { if (window->frame) { *x = window->frame->rect.x + window->frame->child_x; *y = window->frame->rect.y + window->frame->child_y; } else { *x = window->rect.x; *y = window->rect.y; } } void meta_window_delete (MetaWindow *window, Time timestamp) { meta_error_trap_push (window->display); if (window->delete_window) { meta_verbose ("Deleting %s with delete_window request\n", window->desc); meta_window_send_icccm_message (window, window->display->atom_wm_delete_window, timestamp); } else { meta_verbose ("Deleting %s with explicit kill\n", window->desc); XKillClient (window->display->xdisplay, window->xwindow); } meta_error_trap_pop (window->display); } void meta_window_focus (MetaWindow *window, Time timestamp) { meta_verbose ("Setting input focus to window %s, input: %d take_focus: %d\n", window->desc, window->input, window->take_focus); if (window->shaded && window->frame) { /* This is so we can still use keyboard shortcuts * and still draw the window as focused. */ if (window->frame) { meta_verbose ("Focusing frame of %s\n", window->desc); XSetInputFocus (window->display->xdisplay, window->frame->xwindow, RevertToPointerRoot, CurrentTime); } } else { meta_error_trap_push (window->display); if (window->input) { XSetInputFocus (window->display->xdisplay, window->xwindow, RevertToPointerRoot, timestamp); } if (window->take_focus) { meta_window_send_icccm_message (window, window->display->atom_wm_take_focus, timestamp); } meta_error_trap_pop (window->display); } } void meta_window_change_workspace (MetaWindow *window, MetaWorkspace *workspace) { meta_verbose ("Changing window %s to workspace %d\n", window->desc, meta_workspace_index (workspace)); /* See if we're already on this space */ if (g_list_find (window->workspaces, workspace) != NULL) { meta_verbose ("Already on this workspace\n"); return; } /* Add first, to maintain invariant that we're always * on some workspace. */ meta_workspace_add_window (workspace, window); /* unstick if stuck */ if (window->on_all_workspaces) window->on_all_workspaces = FALSE; /* Lamely rely on prepend */ g_assert (window->workspaces->data == workspace); /* Remove from all other spaces */ while (window->workspaces->next) /* while list size > 1 */ meta_workspace_remove_window (window->workspaces->next->data, window); } void meta_window_stick (MetaWindow *window) { if (window->on_all_workspaces) return; /* We don't change window->workspaces, because we revert * to that original workspace list if on_all_workspaces is * toggled back off. */ window->on_all_workspaces = TRUE; meta_window_set_current_workspace_hint (window); meta_window_queue_calc_showing (window); } void meta_window_unstick (MetaWindow *window) { if (!window->on_all_workspaces) return; /* Revert to window->workspaces */ window->on_all_workspaces = FALSE; /* We change ourselves to the active workspace, since otherwise you'd get * a weird window-vaporization effect. Once we have UI for being * on more than one workspace this should probably be add_workspace * not change_workspace. */ if (!meta_workspace_contains_window (window->screen->active_workspace, window)) meta_window_change_workspace (window, window->screen->active_workspace); meta_window_set_current_workspace_hint (window); meta_window_queue_calc_showing (window); } unsigned long meta_window_get_net_wm_desktop (MetaWindow *window) { if (window->on_all_workspaces || g_list_length (window->workspaces) > 1) return 0xFFFFFFFF; else return meta_workspace_screen_index (window->workspaces->data); } int meta_window_set_current_workspace_hint (MetaWindow *window) { /* FIXME if on more than one workspace, we claim to be "sticky", * the WM spec doesn't say what to do here. */ unsigned long data[1]; if (window->workspaces == NULL) return Success; /* this happens when destroying windows */ data[0] = meta_window_get_net_wm_desktop (window); meta_verbose ("Setting _NET_WM_DESKTOP of %s to %ld\n", window->desc, data[0]); meta_error_trap_push (window->display); XChangeProperty (window->display->xdisplay, window->xwindow, window->display->atom_net_wm_desktop, XA_CARDINAL, 32, PropModeReplace, (guchar*) data, 1); return meta_error_trap_pop (window->display); } void meta_window_raise (MetaWindow *window) { meta_verbose ("Raising window %s\n", window->desc); meta_stack_raise (window->screen->stack, window); } void meta_window_send_icccm_message (MetaWindow *window, Atom atom, Time timestamp) { /* This comment and code are from twm, copyright * Open Group, Evans & Sutherland, etc. */ /* * ICCCM Client Messages - Section 4.2.8 of the ICCCM dictates that all * client messages will have the following form: * * event type ClientMessage * message type _XA_WM_PROTOCOLS * window tmp->w * format 32 * data[0] message atom * data[1] time stamp */ XClientMessageEvent ev; ev.type = ClientMessage; ev.window = window->xwindow; ev.message_type = window->display->atom_wm_protocols; ev.format = 32; ev.data.l[0] = atom; ev.data.l[1] = timestamp; XSendEvent (window->display->xdisplay, window->xwindow, False, 0, (XEvent*) &ev); } gboolean meta_window_configure_request (MetaWindow *window, XEvent *event) { return process_configure_request (window, event->xconfigurerequest.x, event->xconfigurerequest.y, event->xconfigurerequest.width, event->xconfigurerequest.height, event->xconfigurerequest.border_width); } gboolean meta_window_property_notify (MetaWindow *window, XEvent *event) { return process_property_notify (window, &event->xproperty); } gboolean meta_window_client_message (MetaWindow *window, XEvent *event) { MetaDisplay *display; display = window->display; if (event->xclient.message_type == display->atom_net_close_window) { /* I think the wm spec should maybe put a time * in this message, CurrentTime here is sort of * bogus. But it rarely matters most likely. */ meta_window_delete (window, CurrentTime); return TRUE; } else if (event->xclient.message_type == display->atom_net_wm_desktop) { int space; MetaWorkspace *workspace; space = event->xclient.data.l[0]; meta_verbose ("Request to move %s to screen workspace %d\n", window->desc, space); workspace = meta_display_get_workspace_by_screen_index (display, window->screen, space); if (workspace) { if (window->on_all_workspaces) meta_window_unstick (window); meta_window_change_workspace (window, workspace); } else if (space == 0xFFFFFFFF) { meta_window_stick (window); } else { meta_verbose ("No such workspace %d for screen\n", space); } return TRUE; } else if (event->xclient.message_type == display->atom_net_wm_state) { gulong action; Atom first; Atom second; action = event->xclient.data.l[0]; first = event->xclient.data.l[1]; second = event->xclient.data.l[2]; if (meta_is_verbose ()) { char *str1; char *str2; meta_error_trap_push (display); str1 = XGetAtomName (display->xdisplay, first); if (meta_error_trap_pop (display)) str1 = NULL; meta_error_trap_push (display); str2 = XGetAtomName (display->xdisplay, second); if (meta_error_trap_pop (display)) str2 = NULL; meta_verbose ("Request to change _NET_WM_STATE action %ld atom1: %s atom2: %s\n", action, str1 ? str1 : "(unknown)", str2 ? str2 : "(unknown)");