2001-05-31 06:42:58 +00:00
|
|
|
/* Metacity X window decorations */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2001 Havoc Pennington
|
2003-12-26 02:42:38 +00:00
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
2001-05-31 06:42:58 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-10-27 03:03:32 +00:00
|
|
|
#include <config.h>
|
2001-05-31 06:42:58 +00:00
|
|
|
#include "frame.h"
|
2003-01-28 15:07:43 +00:00
|
|
|
#include "bell.h"
|
2001-05-31 06:42:58 +00:00
|
|
|
#include "errors.h"
|
2001-06-24 03:18:10 +00:00
|
|
|
#include "keybindings.h"
|
2001-06-03 21:39:57 +00:00
|
|
|
|
2001-06-20 03:01:26 +00:00
|
|
|
#define EVENT_MASK (SubstructureRedirectMask | \
|
|
|
|
StructureNotifyMask | SubstructureNotifyMask | \
|
|
|
|
ExposureMask | \
|
|
|
|
ButtonPressMask | ButtonReleaseMask | \
|
|
|
|
PointerMotionMask | PointerMotionHintMask | \
|
2001-06-23 05:49:35 +00:00
|
|
|
EnterWindowMask | LeaveWindowMask | \
|
2002-05-09 22:34:00 +00:00
|
|
|
FocusChangeMask | \
|
|
|
|
ColormapChangeMask)
|
2001-06-20 03:01:26 +00:00
|
|
|
|
2001-06-03 01:33:27 +00:00
|
|
|
void
|
|
|
|
meta_window_ensure_frame (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaFrame *frame;
|
|
|
|
XSetWindowAttributes attrs;
|
2003-11-16 04:19:18 +00:00
|
|
|
Visual *visual;
|
2001-06-03 01:33:27 +00:00
|
|
|
|
|
|
|
if (window->frame)
|
|
|
|
return;
|
2002-01-02 17:42:14 +00:00
|
|
|
|
|
|
|
/* See comment below for why this is required. */
|
|
|
|
meta_display_grab (window->display);
|
2001-06-03 01:33:27 +00:00
|
|
|
|
|
|
|
frame = g_new (MetaFrame, 1);
|
|
|
|
|
|
|
|
frame->window = window;
|
|
|
|
frame->xwindow = None;
|
|
|
|
|
2001-06-09 21:58:30 +00:00
|
|
|
frame->rect = window->rect;
|
|
|
|
frame->child_x = 0;
|
|
|
|
frame->child_y = 0;
|
|
|
|
frame->bottom_height = 0;
|
|
|
|
frame->right_width = 0;
|
2002-08-23 18:00:40 +00:00
|
|
|
frame->current_cursor = 0;
|
2001-06-09 21:58:30 +00:00
|
|
|
|
2001-06-10 03:17:15 +00:00
|
|
|
frame->mapped = FALSE;
|
2003-01-05 07:51:02 +00:00
|
|
|
frame->need_reapply_frame_shape = TRUE;
|
2003-01-28 15:07:43 +00:00
|
|
|
frame->is_flashing = FALSE;
|
2001-06-10 03:17:15 +00:00
|
|
|
|
2001-09-09 03:44:42 +00:00
|
|
|
meta_verbose ("Framing window %s: visual %s default, depth %d default depth %d\n",
|
|
|
|
window->desc,
|
|
|
|
XVisualIDFromVisual (window->xvisual) ==
|
|
|
|
XVisualIDFromVisual (window->screen->default_xvisual) ?
|
|
|
|
"is" : "is not",
|
|
|
|
window->depth, window->screen->default_depth);
|
2002-04-22 18:18:38 +00:00
|
|
|
meta_verbose ("Frame geometry %d,%d %dx%d\n",
|
|
|
|
frame->rect.x, frame->rect.y,
|
|
|
|
frame->rect.width, frame->rect.height);
|
|
|
|
|
2001-09-09 03:44:42 +00:00
|
|
|
/* Default depth/visual handles clients with weird visuals; they can
|
|
|
|
* always be children of the root depth/visual obviously, but
|
|
|
|
* e.g. DRI games can't be children of a parent that has the same
|
|
|
|
* visual as the client.
|
|
|
|
*/
|
2003-08-16 16:32:10 +00:00
|
|
|
|
2003-11-16 04:19:18 +00:00
|
|
|
visual = 0;
|
|
|
|
/* XXX special case for depth 32 windows (assumed to be ARGB) */
|
|
|
|
if (window->depth == 32)
|
|
|
|
visual = window->xvisual;
|
|
|
|
|
2003-08-16 16:32:10 +00:00
|
|
|
frame->xwindow = meta_ui_create_frame_window (window->screen->ui,
|
2003-11-16 04:19:18 +00:00
|
|
|
window->display->xdisplay,
|
|
|
|
visual,
|
|
|
|
frame->rect.x,
|
|
|
|
frame->rect.y,
|
2003-08-16 16:32:10 +00:00
|
|
|
frame->rect.width,
|
|
|
|
frame->rect.height,
|
|
|
|
frame->window->screen->number);
|
|
|
|
|
2001-06-09 21:58:30 +00:00
|
|
|
meta_verbose ("Frame for %s is 0x%lx\n", frame->window->desc, frame->xwindow);
|
2003-08-16 16:32:10 +00:00
|
|
|
attrs.event_mask = EVENT_MASK;
|
|
|
|
XChangeWindowAttributes (window->display->xdisplay,
|
|
|
|
frame->xwindow, CWEventMask, &attrs);
|
2001-06-02 04:14:18 +00:00
|
|
|
|
2001-05-31 06:42:58 +00:00
|
|
|
meta_display_register_x_window (window->display, &frame->xwindow, window);
|
|
|
|
|
|
|
|
/* Reparent the client window; it may be destroyed,
|
|
|
|
* thus the error trap. We'll get a destroy notify later
|
|
|
|
* and free everything. Comment in FVWM source code says
|
2001-06-11 03:24:20 +00:00
|
|
|
* we need a server grab or the child can get its MapNotify
|
2001-05-31 06:42:58 +00:00
|
|
|
* before we've finished reparenting and getting the decoration
|
2001-06-11 03:24:20 +00:00
|
|
|
* window onscreen, so ensure_frame must be called with
|
|
|
|
* a grab.
|
2001-05-31 06:42:58 +00:00
|
|
|
*/
|
|
|
|
meta_error_trap_push (window->display);
|
2002-01-11 03:31:14 +00:00
|
|
|
if (window->mapped)
|
|
|
|
{
|
|
|
|
window->mapped = FALSE; /* the reparent will unmap the window,
|
|
|
|
* we don't want to take that as a withdraw
|
|
|
|
*/
|
2002-02-08 03:34:26 +00:00
|
|
|
meta_topic (META_DEBUG_WINDOW_STATE,
|
|
|
|
"Incrementing unmaps_pending on %s for reparent\n", window->desc);
|
2002-01-11 03:31:14 +00:00
|
|
|
window->unmaps_pending += 1;
|
|
|
|
}
|
2001-09-09 03:44:42 +00:00
|
|
|
/* window was reparented to this position */
|
2001-06-11 05:47:51 +00:00
|
|
|
window->rect.x = 0;
|
|
|
|
window->rect.y = 0;
|
2001-09-09 03:44:42 +00:00
|
|
|
|
2001-05-31 06:42:58 +00:00
|
|
|
XReparentWindow (window->display->xdisplay,
|
|
|
|
window->xwindow,
|
|
|
|
frame->xwindow,
|
2001-06-11 05:47:51 +00:00
|
|
|
window->rect.x,
|
|
|
|
window->rect.y);
|
2001-10-13 04:00:08 +00:00
|
|
|
/* FIXME handle this error */
|
2002-10-21 21:44:35 +00:00
|
|
|
meta_error_trap_pop (window->display, FALSE);
|
2001-09-09 03:44:42 +00:00
|
|
|
|
2001-05-31 06:42:58 +00:00
|
|
|
/* stick frame to the window */
|
2001-06-04 06:17:52 +00:00
|
|
|
window->frame = frame;
|
2001-06-20 03:01:26 +00:00
|
|
|
|
|
|
|
if (window->title)
|
|
|
|
meta_ui_set_frame_title (window->screen->ui,
|
|
|
|
window->frame->xwindow,
|
|
|
|
window->title);
|
2001-06-23 05:49:35 +00:00
|
|
|
|
|
|
|
/* Move keybindings to frame instead of window */
|
|
|
|
meta_window_grab_keys (window);
|
2002-01-02 17:42:14 +00:00
|
|
|
|
2002-05-31 00:02:54 +00:00
|
|
|
/* Shape mask */
|
|
|
|
meta_ui_apply_frame_shape (frame->window->screen->ui,
|
|
|
|
frame->xwindow,
|
|
|
|
frame->rect.width,
|
2003-01-05 07:51:02 +00:00
|
|
|
frame->rect.height,
|
|
|
|
frame->window->has_shape);
|
|
|
|
frame->need_reapply_frame_shape = FALSE;
|
2002-05-31 00:02:54 +00:00
|
|
|
|
2002-01-02 17:42:14 +00:00
|
|
|
meta_display_ungrab (window->display);
|
2001-05-31 06:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_window_destroy_frame (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaFrame *frame;
|
|
|
|
|
|
|
|
if (window->frame == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-12-26 02:42:38 +00:00
|
|
|
meta_verbose ("Unframing window %s\n", window->desc);
|
|
|
|
|
2001-05-31 06:42:58 +00:00
|
|
|
frame = window->frame;
|
2001-06-23 05:49:35 +00:00
|
|
|
|
2003-01-28 15:07:43 +00:00
|
|
|
meta_bell_notify_frame_destroy (frame);
|
2001-05-31 06:42:58 +00:00
|
|
|
|
|
|
|
/* Unparent the client window; it may be destroyed,
|
|
|
|
* thus the error trap.
|
|
|
|
*/
|
|
|
|
meta_error_trap_push (window->display);
|
2002-01-11 03:31:14 +00:00
|
|
|
if (window->mapped)
|
|
|
|
{
|
|
|
|
window->mapped = FALSE; /* Keep track of unmapping it, so we
|
|
|
|
* can identify a withdraw initiated
|
|
|
|
* by the client.
|
|
|
|
*/
|
2002-02-08 03:34:26 +00:00
|
|
|
meta_topic (META_DEBUG_WINDOW_STATE,
|
|
|
|
"Incrementing unmaps_pending on %s for reparent back to root\n", window->desc);
|
2002-01-11 03:31:14 +00:00
|
|
|
window->unmaps_pending += 1;
|
|
|
|
}
|
2001-05-31 06:42:58 +00:00
|
|
|
XReparentWindow (window->display->xdisplay,
|
|
|
|
window->xwindow,
|
|
|
|
window->screen->xroot,
|
|
|
|
/* FIXME where to put it back depends on the gravity */
|
|
|
|
window->frame->rect.x,
|
|
|
|
window->frame->rect.y);
|
2002-10-21 21:44:35 +00:00
|
|
|
meta_error_trap_pop (window->display, FALSE);
|
2001-05-31 06:42:58 +00:00
|
|
|
|
2003-08-16 16:32:10 +00:00
|
|
|
meta_ui_destroy_frame_window (window->screen->ui, frame->xwindow);
|
|
|
|
|
2001-05-31 06:42:58 +00:00
|
|
|
meta_display_unregister_x_window (window->display,
|
|
|
|
frame->xwindow);
|
|
|
|
|
|
|
|
window->frame = NULL;
|
|
|
|
|
2001-06-23 05:49:35 +00:00
|
|
|
/* Move keybindings to window instead of frame */
|
|
|
|
meta_window_grab_keys (window);
|
|
|
|
|
2001-05-31 06:42:58 +00:00
|
|
|
g_free (frame);
|
2001-06-04 06:17:52 +00:00
|
|
|
|
|
|
|
/* Put our state back where it should be */
|
2001-06-06 04:47:37 +00:00
|
|
|
meta_window_queue_calc_showing (window);
|
2001-05-31 06:42:58 +00:00
|
|
|
}
|
|
|
|
|
2001-06-18 03:24:25 +00:00
|
|
|
|
|
|
|
MetaFrameFlags
|
|
|
|
meta_frame_get_flags (MetaFrame *frame)
|
|
|
|
{
|
|
|
|
MetaFrameFlags flags;
|
|
|
|
|
2002-06-22 03:23:02 +00:00
|
|
|
flags = 0;
|
2001-06-23 18:30:27 +00:00
|
|
|
|
2002-06-22 03:23:02 +00:00
|
|
|
if (frame->window->border_only)
|
|
|
|
{
|
|
|
|
; /* FIXME this may disable the _function_ as well as decor
|
|
|
|
* in some cases, which is sort of wrong.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flags |= META_FRAME_ALLOWS_MENU;
|
|
|
|
|
|
|
|
if (frame->window->has_close_func)
|
|
|
|
flags |= META_FRAME_ALLOWS_DELETE;
|
|
|
|
|
|
|
|
if (frame->window->has_maximize_func)
|
|
|
|
flags |= META_FRAME_ALLOWS_MAXIMIZE;
|
|
|
|
|
|
|
|
if (frame->window->has_minimize_func)
|
|
|
|
flags |= META_FRAME_ALLOWS_MINIMIZE;
|
|
|
|
|
|
|
|
if (frame->window->has_shade_func)
|
|
|
|
flags |= META_FRAME_ALLOWS_SHADE;
|
|
|
|
}
|
|
|
|
|
2002-07-03 02:32:40 +00:00
|
|
|
if (META_WINDOW_ALLOWS_MOVE (frame->window))
|
2001-06-23 18:30:27 +00:00
|
|
|
flags |= META_FRAME_ALLOWS_MOVE;
|
2001-07-03 01:45:43 +00:00
|
|
|
|
2002-07-03 02:32:40 +00:00
|
|
|
if (META_WINDOW_ALLOWS_HORIZONTAL_RESIZE (frame->window))
|
|
|
|
flags |= META_FRAME_ALLOWS_HORIZONTAL_RESIZE;
|
|
|
|
|
|
|
|
if (META_WINDOW_ALLOWS_VERTICAL_RESIZE (frame->window))
|
|
|
|
flags |= META_FRAME_ALLOWS_VERTICAL_RESIZE;
|
2001-06-18 03:24:25 +00:00
|
|
|
|
|
|
|
if (frame->window->has_focus)
|
|
|
|
flags |= META_FRAME_HAS_FOCUS;
|
|
|
|
|
|
|
|
if (frame->window->shaded)
|
|
|
|
flags |= META_FRAME_SHADED;
|
|
|
|
|
|
|
|
if (frame->window->on_all_workspaces)
|
|
|
|
flags |= META_FRAME_STUCK;
|
2001-06-18 06:11:53 +00:00
|
|
|
|
2001-06-23 06:54:28 +00:00
|
|
|
if (frame->window->maximized)
|
2002-06-08 06:07:21 +00:00
|
|
|
flags |= META_FRAME_MAXIMIZED;
|
|
|
|
|
|
|
|
if (frame->window->fullscreen)
|
|
|
|
flags |= META_FRAME_FULLSCREEN;
|
2001-06-23 06:54:28 +00:00
|
|
|
|
2003-01-28 15:07:43 +00:00
|
|
|
if (frame->is_flashing)
|
|
|
|
flags |= META_FRAME_IS_FLASHING;
|
|
|
|
|
2001-06-18 06:11:53 +00:00
|
|
|
return flags;
|
2001-06-18 03:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_frame_calc_geometry (MetaFrame *frame,
|
|
|
|
MetaFrameGeometry *geomp)
|
|
|
|
{
|
|
|
|
MetaFrameGeometry geom;
|
|
|
|
MetaWindow *window;
|
|
|
|
|
|
|
|
window = frame->window;
|
|
|
|
|
|
|
|
meta_ui_get_frame_geometry (window->screen->ui,
|
|
|
|
frame->xwindow,
|
|
|
|
&geom.top_height,
|
|
|
|
&geom.bottom_height,
|
|
|
|
&geom.left_width,
|
|
|
|
&geom.right_width);
|
|
|
|
|
|
|
|
*geomp = geom;
|
|
|
|
}
|
|
|
|
|
2003-01-05 07:51:02 +00:00
|
|
|
static void
|
|
|
|
update_shape (MetaFrame *frame)
|
|
|
|
{
|
|
|
|
if (frame->need_reapply_frame_shape)
|
|
|
|
{
|
|
|
|
meta_ui_apply_frame_shape (frame->window->screen->ui,
|
|
|
|
frame->xwindow,
|
|
|
|
frame->rect.width,
|
|
|
|
frame->rect.height,
|
|
|
|
frame->window->has_shape);
|
|
|
|
frame->need_reapply_frame_shape = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-03 01:33:27 +00:00
|
|
|
void
|
2001-06-10 03:17:15 +00:00
|
|
|
meta_frame_sync_to_window (MetaFrame *frame,
|
2002-01-19 23:59:11 +00:00
|
|
|
int resize_gravity,
|
2001-06-10 03:17:15 +00:00
|
|
|
gboolean need_move,
|
|
|
|
gboolean need_resize)
|
2001-06-03 01:33:27 +00:00
|
|
|
{
|
2001-09-11 02:57:05 +00:00
|
|
|
if (!(need_move || need_resize))
|
2003-01-05 07:51:02 +00:00
|
|
|
{
|
|
|
|
update_shape (frame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-02-24 19:58:27 +00:00
|
|
|
meta_topic (META_DEBUG_GEOMETRY,
|
|
|
|
"Syncing frame geometry %d,%d %dx%d (SE: %d,%d)\n",
|
|
|
|
frame->rect.x, frame->rect.y,
|
|
|
|
frame->rect.width, frame->rect.height,
|
|
|
|
frame->rect.x + frame->rect.width,
|
|
|
|
frame->rect.y + frame->rect.height);
|
2001-06-10 03:17:15 +00:00
|
|
|
|
|
|
|
/* set bg to none to avoid flicker */
|
2001-06-18 03:24:25 +00:00
|
|
|
if (need_resize)
|
2002-05-31 00:02:54 +00:00
|
|
|
{
|
|
|
|
meta_ui_unflicker_frame_bg (frame->window->screen->ui,
|
|
|
|
frame->xwindow,
|
|
|
|
frame->rect.width,
|
|
|
|
frame->rect.height);
|
|
|
|
|
2003-01-05 07:51:02 +00:00
|
|
|
/* we need new shape if we're resized */
|
|
|
|
frame->need_reapply_frame_shape = TRUE;
|
2002-05-31 00:02:54 +00:00
|
|
|
}
|
2003-01-05 07:51:02 +00:00
|
|
|
|
|
|
|
/* Done before the window resize, because doing it before means
|
|
|
|
* part of the window being resized becomes unshaped, which may
|
|
|
|
* be sort of hard to see with bg = None. If we did it after
|
|
|
|
* window resize, part of the window being resized would become
|
|
|
|
* shaped, which might be more visible.
|
|
|
|
*/
|
|
|
|
update_shape (frame);
|
2002-05-31 00:02:54 +00:00
|
|
|
|
2003-08-16 16:32:10 +00:00
|
|
|
meta_ui_move_resize_frame (frame->window->screen->ui,
|
|
|
|
frame->xwindow,
|
|
|
|
frame->rect.x,
|
|
|
|
frame->rect.y,
|
|
|
|
frame->rect.width,
|
|
|
|
frame->rect.height);
|
2001-06-03 21:39:57 +00:00
|
|
|
|
2001-06-18 03:24:25 +00:00
|
|
|
if (need_resize)
|
2002-05-09 22:34:00 +00:00
|
|
|
{
|
|
|
|
meta_ui_reset_frame_bg (frame->window->screen->ui,
|
|
|
|
frame->xwindow);
|
|
|
|
|
|
|
|
/* If we're interactively resizing the frame, repaint
|
|
|
|
* it immediately so we don't start to lag.
|
|
|
|
*/
|
|
|
|
if (frame->window->display->grab_window ==
|
|
|
|
frame->window)
|
|
|
|
meta_ui_repaint_frame (frame->window->screen->ui,
|
|
|
|
frame->xwindow);
|
|
|
|
}
|
2001-06-03 21:39:57 +00:00
|
|
|
}
|
|
|
|
|
2001-06-03 01:33:27 +00:00
|
|
|
void
|
|
|
|
meta_frame_queue_draw (MetaFrame *frame)
|
|
|
|
{
|
2001-06-18 03:24:25 +00:00
|
|
|
meta_ui_queue_frame_draw (frame->window->screen->ui,
|
|
|
|
frame->xwindow);
|
2001-06-09 06:08:44 +00:00
|
|
|
}
|
2002-08-23 18:00:40 +00:00
|
|
|
|
2003-08-16 16:32:10 +00:00
|
|
|
void
|
|
|
|
meta_frame_set_screen_cursor (MetaFrame *frame,
|
|
|
|
MetaCursor cursor)
|
2002-08-23 18:00:40 +00:00
|
|
|
{
|
|
|
|
Cursor xcursor;
|
|
|
|
if (cursor == frame->current_cursor)
|
|
|
|
return;
|
|
|
|
frame->current_cursor = cursor;
|
|
|
|
if (cursor == META_CURSOR_DEFAULT)
|
|
|
|
XUndefineCursor (frame->window->display->xdisplay, frame->xwindow);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xcursor = meta_display_create_x_cursor (frame->window->display, cursor);
|
|
|
|
XDefineCursor (frame->window->display->xdisplay, frame->xwindow, xcursor);
|
|
|
|
XFreeCursor (frame->window->display->xdisplay, xcursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|