From 80bc33151d5b5acf7b0046d8576fac783da33cbf Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Thu, 15 Nov 2007 00:20:03 +0000 Subject: Remove old compositor stuff Fix compositor.c to match metacity code style svn path=/branches/iains-blingtastic-bucket-o-bling/; revision=3399 --- src/c-screen.c | 677 ------------------------- src/c-screen.h | 53 -- src/c-window.c | 1259 ----------------------------------------------- src/c-window.h | 72 --- src/compositor.c | 1444 ++++++++++++++++++++++++++++-------------------------- src/compositor.h | 31 +- src/display.c | 2 +- 7 files changed, 749 insertions(+), 2789 deletions(-) delete mode 100644 src/c-screen.c delete mode 100644 src/c-screen.h delete mode 100644 src/c-window.c delete mode 100644 src/c-window.h diff --git a/src/c-screen.c b/src/c-screen.c deleted file mode 100644 index ea6f95e9..00000000 --- a/src/c-screen.c +++ /dev/null @@ -1,677 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2006 Red Hat, Inc. - * - * 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 - -#ifdef HAVE_COMPOSITE_EXTENSIONS -#include -#include -#include -#include -#include -#include -#include -#include - -#include "screen.h" -#include "c-screen.h" -#include "c-window.h" - -struct MetaCompScreen -{ - WsDisplay *display; - CmStacker *stacker; - CmMagnifier *magnifier; - - WsWindow *gl_window; - WsWindow *root_window; - - WsScreen *screen; - MetaScreen *meta_screen; - - int repaint_id; - int idle_id; - - WsWindow *selection_window; - - GHashTable *windows_by_xid; -}; - -static MetaCompWindow * -meta_comp_window_lookup (MetaCompScreen *info, - Window xid) -{ - MetaCompWindow *window; - - window = g_hash_table_lookup (info->windows_by_xid, (gpointer)xid); - - return window; -} - -MetaCompWindow * -meta_comp_screen_lookup_window (MetaCompScreen *info, - Window xwindow) -{ - return meta_comp_window_lookup (info, xwindow); -} - -#if 0 -static void -update_frame_counter (void) -{ -#define BUFSIZE 128 - static GTimer *timer; - static double buffer [BUFSIZE]; - static int next = 0; - - if (!timer) - timer = g_timer_new (); - - buffer[next++] = g_timer_elapsed (timer, NULL); - - if (next == BUFSIZE) - { - int i; - double total; - - next = 0; - - total = 0.0; - for (i = 1; i < BUFSIZE; ++i) - total += buffer[i] - buffer[i - 1]; - - g_print ("frames per second: %f\n", 1 / (total / (BUFSIZE - 1))); - } -} -#endif - -static void -dump_stacking_order (GList *nodes) -{ - GList *list; - - for (list = nodes; list != NULL; list = list->next) - { - CmDrawableNode *node = list->data; - - if (node) - g_print ("%lx, ", WS_RESOURCE_XID (node->drawable)); - } - g_print ("\n"); -} - -static gboolean -repaint (gpointer data) -{ - MetaCompScreen *info = data; - CmState *state; -#if 0 - g_print ("repaint\n"); -#endif - glViewport (0, 0, - info->meta_screen->rect.width, - info->meta_screen->rect.height); - - glLoadIdentity(); - -#if 0 - glClearColor (0, 0, 0, 1.0); - glClear (GL_COLOR_BUFFER_BIT); -#endif - - ws_window_raise (info->gl_window); - -#if 0 - glDisable (GL_TEXTURE_2D); - glDisable (GL_TEXTURE_RECTANGLE_ARB); - glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); - glColor4f (0.0, 1.0, 0.0, 1.0); - glRectf (-1.0, -1.0, 1.0, 1.0); - glFinish(); -#endif - - state = cm_state_new (); - - cm_state_disable_depth_buffer_update (state); - - cm_node_render (CM_NODE (info->magnifier), state); - - cm_state_enable_depth_buffer_update (state); - - g_object_unref (state); - - ws_window_gl_swap_buffers (info->gl_window); - glFinish(); - -#if 0 - dump_stacking_order (info->stacker->children); -#endif - - info->idle_id = 0; - return FALSE; -} - -static MetaCompWindow * -find_comp_window (MetaCompScreen *info, - Window xwindow) -{ - return meta_comp_window_lookup (info, xwindow); -} - -static CmNode * -find_node (MetaCompScreen *info, - Window xwindow) -{ - MetaCompWindow *window = meta_comp_window_lookup (info, xwindow); - - if (window) - return meta_comp_window_get_node (window); - - return NULL; -} - -static GList *all_screen_infos; - -MetaCompScreen * -meta_comp_screen_get_by_xwindow (Window xwindow) -{ - GList *list; - - for (list = all_screen_infos; list != NULL; list = list->next) - { - MetaCompScreen *info = list->data; - - if (find_node (info, xwindow)) - return info; - } - - return NULL; -} - -MetaCompScreen * -meta_comp_screen_new (WsDisplay *display, - MetaScreen *screen) -{ - MetaCompScreen *scr_info = g_new0 (MetaCompScreen, 1); - - scr_info->screen = ws_display_get_screen_from_number ( - display, screen->number); - scr_info->root_window = ws_screen_get_root_window (scr_info->screen); - scr_info->display = display; - scr_info->meta_screen = screen; - scr_info->windows_by_xid = g_hash_table_new (g_direct_hash, g_direct_equal); - - all_screen_infos = g_list_prepend (all_screen_infos, scr_info); - - return scr_info; -} - -static char * -make_selection_name (MetaCompScreen *info) -{ - char *buffer; - - buffer = g_strdup_printf ("_NET_WM_CM_S%d", info->meta_screen->number); - - return buffer; -} - -static void -on_selection_clear (WsWindow *window, - WsSelectionClearEvent *event, - gpointer data) -{ - MetaCompScreen *info = data; - char *buffer = make_selection_name (info); - - if (strcmp (event->selection, buffer)) - { - /* We lost the selection */ - meta_comp_screen_unredirect (info); - } -} - -static WsWindow * -claim_selection (MetaCompScreen *info) -{ - WsWindow *window = ws_window_new (info->root_window); - char *buffer = make_selection_name (info); - -#if 0 - g_print ("selection window: %lx\n", WS_RESOURCE_XID (window)); -#endif - - ws_window_own_selection (window, buffer, WS_CURRENT_TIME); - - g_signal_connect (window, "selection_clear_event", G_CALLBACK (on_selection_clear), info); - - g_free (buffer); - - return window; -} - -static void -queue_paint (CmNode *node, - MetaCompScreen *info) -{ -#if 0 - g_print ("queueing %s\n", G_OBJECT_TYPE_NAME (node)); -#endif - meta_comp_screen_queue_paint (info); -} - -void -meta_comp_screen_redirect (MetaCompScreen *info) -{ - WsWindow *root = ws_screen_get_root_window (info->screen); - WsRectangle source; - WsRectangle target; - WsServerRegion *region; - int screen_w; - int screen_h; - CmSquare *square; - -#if 0 - g_print ("redirecting %lx\n", WS_RESOURCE_XID (root)); -#endif - - ws_window_redirect_subwindows (root); - info->gl_window = ws_screen_get_gl_window (info->screen); - /* FIXME: This should probably happen in libcm */ - ws_window_set_override_redirect (info->gl_window, TRUE); - region = ws_server_region_new (info->display); - ws_window_set_input_shape (info->gl_window, region); - g_object_unref (G_OBJECT (region)); - - ws_display_begin_error_trap (info->display); - - ws_window_unredirect (info->gl_window); - - ws_display_end_error_trap (info->display); - - info->selection_window = claim_selection (info); - - ws_window_map (info->gl_window); - - info->stacker = cm_stacker_new (); - - square = cm_square_new (0.3, 0.3, 0.8, 1.0); - - cm_stacker_add_child (info->stacker, CM_NODE (square)); - - g_object_unref (square); - - screen_w = ws_screen_get_width (info->screen); - screen_h = ws_screen_get_height (info->screen); - -#if 0 - g_print ("width: %d height %d\n", screen_w, screen_h); -#endif - - source.x = (screen_w - (screen_w / 4)) / 2; - source.y = screen_h / 16; - source.width = screen_w / 4; - source.height = screen_h / 16; - - target.x = 0; - target.y = screen_h - screen_h / 4; - target.width = screen_w; - target.height = screen_h / 4; - - info->magnifier = cm_magnifier_new (CM_NODE (info->stacker), &source, &target); - - if (g_getenv ("USE_MAGNIFIER")) - cm_magnifier_set_active (info->magnifier, TRUE); - else - cm_magnifier_set_active (info->magnifier, FALSE); - - info->repaint_id = - g_signal_connect (info->magnifier, "need_repaint", - G_CALLBACK (queue_paint), info); - - ws_display_sync (info->display); -} - -static void -listify (gpointer key, - gpointer value, - gpointer data) -{ - GList **windows = data; - - *windows = g_list_prepend (*windows, (gpointer)value); -} - -static void -free_all_windows (MetaCompScreen *info) -{ - GList *windows = NULL, *list; - - g_hash_table_foreach (info->windows_by_xid, listify, &windows); - - for (list = windows; list != NULL; list = list->next) - { - MetaCompWindow *window = list->data; - - meta_comp_window_free (window); - } - - g_list_free (windows); -} - -void -meta_comp_screen_unredirect (MetaCompScreen *info) -{ - WsScreen *ws_screen = info->screen; - WsWindow *root = ws_screen_get_root_window (ws_screen); - - g_signal_handler_disconnect (info->magnifier, info->repaint_id); - g_object_unref (info->magnifier); - - ws_window_unredirect_subwindows (root); - ws_screen_release_gl_window (ws_screen); - - free_all_windows (info); - - ws_display_sync (info->display); - - /* FIXME: libcm needs a way to guarantee that a window is destroyed, - * without relying on ref counting having it as a side effect - */ - g_object_unref (info->selection_window); -} - -void -meta_comp_screen_queue_paint (MetaCompScreen *info) -{ -#if 0 - g_print ("queuing\n"); -#endif - if (!info->idle_id) - info->idle_id = g_idle_add (repaint, info); -} - -void -meta_comp_screen_restack (MetaCompScreen *info, - Window window, - Window above_this) -{ - MetaCompWindow *comp_window = find_comp_window (info, window); - MetaCompWindow *above_comp_window = find_comp_window (info, above_this); - CmNode *window_node = find_node (info, window); - CmNode *above_node = find_node (info, above_this); - - if ((comp_window && meta_comp_window_stack_frozen (comp_window)) || - (above_comp_window && meta_comp_window_stack_frozen (above_comp_window))) - { - return; - } - -#if 0 - dump_stacking_order (info->stacker->children); -#endif - - if (window_node == above_node) - return; - - if (window_node && above_this == WS_RESOURCE_XID (info->gl_window)) - { - cm_stacker_raise_child (info->stacker, window_node); - } - else if (window_node && above_this == None) - { - cm_stacker_lower_child (info->stacker, window_node); - } - else if (window_node && above_node) - { - cm_stacker_restack_child (info->stacker, window_node, above_node); - } -#if 0 - else - g_print ("nothing happened\n"); -#endif - -#if 0 - g_print ("done restacking; new order:\n"); -#endif -#if 0 - dump_stacking_order (info->stacker->children); -#endif - -} - -void -meta_comp_screen_raise_window (MetaCompScreen *info, - Window window) -{ - CmNode *node = find_node (info, window); - - if (node) - cm_stacker_raise_child (info->stacker, node); -} - -void -meta_comp_screen_set_size (MetaCompScreen *info, - Window xwindow, - gint x, - gint y, - gint width, - gint height) -{ - MetaCompWindow *comp_window = meta_comp_window_lookup (info, xwindow); - - if (comp_window) - { - WsRectangle rect; - - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - - meta_comp_window_set_size (comp_window, &rect); - } -} - -static void -print_child_titles (WsWindow *window) -{ - GList *children = ws_window_query_subwindows (window); - GList *list; - int i; - - g_print ("window: %lx %s\n", WS_RESOURCE_XID (window), ws_window_query_title (window)); - - i = 0; - for (list = children; list != NULL; list = list->next) - { - WsWindow *child = list->data; - - g_print (" %d adding: %lx %s\n", i++, WS_RESOURCE_XID (child), ws_window_query_title (child)); - } -} - -typedef struct -{ - MetaCompScreen *cscreen; - XID xid; -} DestroyData; - -static void -on_window_destroy (MetaCompWindow *comp_window, - gpointer closure) -{ - DestroyData *data = closure; - CmNode *node = meta_comp_window_get_node (comp_window); - - cm_stacker_remove_child (data->cscreen->stacker, node); - g_hash_table_remove (data->cscreen->windows_by_xid, (gpointer)data->xid); -} - -void -meta_comp_screen_add_window (MetaCompScreen *info, - Window xwindow) -{ - WsDrawable *drawable; - MetaCompWindow *comp_window; - DestroyData *data; - - ws_display_begin_error_trap (info->display); - - comp_window = meta_comp_window_lookup (info, xwindow); - - if (comp_window) - goto out; - - drawable = WS_DRAWABLE (ws_window_lookup (info->display, xwindow)); - - if (ws_window_query_input_only (WS_WINDOW (drawable))) - goto out; - - if (WS_WINDOW (drawable) == info->gl_window || - WS_WINDOW (drawable) == info->screen->overlay_window) - { -#if 0 - g_print ("gl window\n"); -#endif - goto out; - } - - data = g_new (DestroyData, 1); - data->cscreen = info; - data->xid = WS_RESOURCE_XID (drawable); - - comp_window = meta_comp_window_new (info->meta_screen, drawable, - on_window_destroy, data); - - g_hash_table_insert (info->windows_by_xid, (gpointer)WS_RESOURCE_XID (drawable), comp_window); - - cm_stacker_add_child (info->stacker, meta_comp_window_get_node (comp_window)); - - out: - if (comp_window) - { - /* This function is called both when windows are created and when they - * are mapped, so for now we have this silly function. - */ - meta_comp_window_refresh_attrs (comp_window); - } - - ws_display_end_error_trap (info->display); - -#if 0 - g_print ("done checking\n"); -#endif - - return; -} - - -void -meta_comp_screen_remove_window (MetaCompScreen *info, - Window xwindow) -{ - MetaCompWindow *comp_window = meta_comp_window_lookup (info, xwindow); - - if (comp_window) - meta_comp_window_free (comp_window); -} - -void -meta_comp_screen_set_updates (MetaCompScreen *info, - Window xwindow, - gboolean updates) -{ - MetaCompWindow *comp_window = meta_comp_window_lookup (info, xwindow); - - meta_comp_window_set_updates (comp_window, updates); -} - - -void -meta_comp_screen_set_patch (MetaCompScreen *info, - Window xwindow, - CmPoint points[4][4]) -{ - CmDrawableNode *node = CM_DRAWABLE_NODE (find_node (info, xwindow)); - - if (node) - cm_drawable_node_set_patch (node, points); -} - -void -meta_comp_screen_unset_patch (MetaCompScreen *info, - Window xwindow) -{ - CmDrawableNode *node = CM_DRAWABLE_NODE (find_node (info, xwindow)); - - if (node) - cm_drawable_node_unset_patch (node); -} - -void -meta_comp_screen_set_alpha (MetaCompScreen *info, - Window xwindow, - gdouble alpha) -{ - CmDrawableNode *node = CM_DRAWABLE_NODE (find_node (info, xwindow)); -#if 0 - g_print ("alpha: %f\n", alpha); -#endif - cm_drawable_node_set_alpha (node, alpha); -} - -void -meta_comp_screen_get_real_size (MetaCompScreen *info, - Window xwindow, - WsRectangle *size) -{ - CmDrawableNode *node = CM_DRAWABLE_NODE (find_node (info, xwindow)); - - if (!size) - return; - - cm_drawable_node_get_clipbox (node, size); -} - -void -meta_comp_screen_unmap (MetaCompScreen *info, - Window xwindow) -{ - MetaCompWindow *window = find_comp_window (info, xwindow); - - if (window) - meta_comp_window_hide (window); -} - -void -meta_comp_screen_set_target_rect (MetaCompScreen *info, - Window xwindow, - WsRectangle *rect) -{ - CmDrawableNode *node = CM_DRAWABLE_NODE (find_node (info, xwindow)); - - if (node) - cm_drawable_node_set_scale_rect (node, rect); -} - -#endif - diff --git a/src/c-screen.h b/src/c-screen.h deleted file mode 100644 index 7d6c2167..00000000 --- a/src/c-screen.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -#include "screen.h" -#include "c-window.h" - -typedef struct MetaCompScreen MetaCompScreen; - -MetaCompScreen *meta_comp_screen_new (WsDisplay *display, - MetaScreen *screen); -MetaCompScreen *meta_comp_screen_get_by_xwindow (Window xwindow); -void meta_comp_screen_destroy (MetaCompScreen *scr_info); -void meta_comp_screen_redirect (MetaCompScreen *info); -void meta_comp_screen_unredirect (MetaCompScreen *info); -void meta_comp_screen_add_window (MetaCompScreen *scr_info, - Window xwindow); -void meta_comp_screen_remove_window (MetaCompScreen *scr_info, - Window xwindow); -void meta_comp_screen_restack (MetaCompScreen *scr_info, - Window window, - Window above_this); -void meta_comp_screen_set_size (MetaCompScreen *info, - Window window, - gint x, - gint y, - gint width, - gint height); -void meta_comp_screen_raise_window (MetaCompScreen *scr_info, - Window window); -void meta_comp_screen_queue_paint (MetaCompScreen *info); -void meta_comp_screen_set_updates (MetaCompScreen *info, - Window xwindow, - gboolean updates); -void meta_comp_screen_set_patch (MetaCompScreen *info, - Window xwindow, - CmPoint points[4][4]); -void meta_comp_screen_unset_patch (MetaCompScreen *info, - Window xwindow); -void meta_comp_screen_set_alpha (MetaCompScreen *info, - Window xwindow, - gdouble alpha); -void meta_comp_screen_get_real_size (MetaCompScreen *info, - Window xwindow, - WsRectangle *size); -void meta_comp_screen_set_target_rect (MetaCompScreen *info, - Window xwindow, - WsRectangle *rect); -void meta_comp_screen_set_explode (MetaCompScreen *info, - Window xwindow, - gdouble level); -void meta_comp_screen_unmap (MetaCompScreen *info, - Window xwindow); -MetaCompWindow *meta_comp_screen_lookup_window (MetaCompScreen *info, - Window xwindow); diff --git a/src/c-window.c b/src/c-window.c deleted file mode 100644 index 43cb7067..00000000 --- a/src/c-window.c +++ /dev/null @@ -1,1259 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2006 Red Hat, Inc. - * - * 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 - -#ifdef HAVE_COMPOSITE_EXTENSIONS - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "effects.h" -#include "c-window.h" -#include "window.h" -#include "frame.h" -#include "compositor.h" -#include "workspace.h" - -typedef struct UnminimizeInfo UnminimizeInfo; - -struct _MetaCompWindow -{ - MetaDisplay *display; - MetaScreen *screen; - WsDrawable *drawable; - WsPixmap *pixmap; - CmDrawableNode *node; - gboolean updates; - WsSyncAlarm *alarm; - - WsRectangle size; - gboolean waiting_for_paint; - - gint64 counter_value; - gint ref_count; - - gboolean animation_in_progress; - gboolean hide_after_animation; - - int stack_freeze_count; - int fade_in_idle_id; - - MetaCompWindowDestroy destroy; - gpointer closure; - - UnminimizeInfo *unminimize_info; -}; - -static void cancel_fade (MetaCompWindow *comp_window); -static void start_unminimize (MetaCompWindow *comp_window); - -static Window -find_app_window (MetaCompWindow *comp_window) -{ - Window xwindow = WS_RESOURCE_XID (comp_window->drawable); - MetaWindow *meta_window = - meta_display_lookup_x_window (comp_window->display, xwindow); - - if (meta_window) - return meta_window->xwindow; - else - return xwindow; -} - -static WsPixmap * -take_snapshot (WsDrawable *drawable) -{ - WsDisplay *display = WS_RESOURCE (drawable)->display; - WsRectangle geometry; - WsPixmap *pixmap; - - ws_display_begin_error_trap (display); - - ws_drawable_query_geometry (drawable, &geometry); - - pixmap = ws_pixmap_new (drawable, geometry.width, geometry.height); - - ws_drawable_copy_area (drawable, 0, 0, geometry.width, geometry.height, - WS_DRAWABLE (pixmap), 0, 0, - NULL); - - ws_display_end_error_trap (display); - - return pixmap; -} - -static void -on_alarm (WsSyncAlarm *alarm, - WsAlarmNotifyEvent *event, - MetaCompWindow *window) -{ - if (window->pixmap) - g_object_unref (window->pixmap); - - window->pixmap = take_snapshot (window->drawable); - - ws_sync_alarm_set (window->alarm, event->counter_value + 2); - ws_sync_counter_change (event->counter, 1); -} - -static gboolean -has_counter (MetaCompWindow *comp_window) -{ - Window xwindow = find_app_window (comp_window); - WsDisplay *display = WS_RESOURCE (comp_window->drawable)->display; - WsWindow *window = ws_window_lookup (display, xwindow); - WsSyncCounter *counter; - - ws_display_init_sync (display); - - counter = ws_window_get_property_sync_counter ( - window, "_NET_WM_FINISH_FRAME_COUNTER"); - - if (counter) - { - WsSyncAlarm *alarm; - gint64 value = ws_sync_counter_query_value (counter); - -#if 0 - g_print ("counter value %lld\n", ws_sync_counter_query_value (counter)); - alarm = ws_sync_alarm_new (WS_RESOURCE (comp_window->drawable)->display, - - display, counter); -#endif - - g_signal_connect (alarm, "alarm_notify_event", - G_CALLBACK (on_alarm), comp_window); - - if (value % 2 == 1) - { - ws_sync_alarm_set (alarm, value + 2); - -#if 0 - g_print ("wait for %lld\n", value + 2); - - g_print ("increasing counter\n"); -#endif - ws_sync_counter_change (counter, 1); - -#if 0 - g_print ("counter value %lld\n", - ws_sync_counter_query_value (counter)); -#endif - } - else - { -#if 0 - g_print ("wait for %lld\n", value + 1); -#endif - ws_sync_alarm_set (alarm, value + 1); - } - - comp_window->alarm = alarm; - - } - - if (counter) - return TRUE; - else - return FALSE; - -#if 0 - if (counter) - { - g_print ("found counter %lx on %lx\n", - WS_RESOURCE_XID (counter), - WS_RESOURCE_XID (window)); - } - else - { - g_print ("no counter found for %lx\n", WS_RESOURCE_XID (window)); - } -#endif - - return TRUE; -} - -void -meta_comp_window_show (MetaCompWindow *comp_window) -{ - if (comp_window->animation_in_progress) - comp_window->hide_after_animation = FALSE; - - cm_drawable_node_set_viewable (CM_DRAWABLE_NODE (comp_window->node), TRUE); - cm_drawable_node_update_pixmap (CM_DRAWABLE_NODE (comp_window->node)); -} - -void -meta_comp_window_hide (MetaCompWindow *comp_window) -{ - if (comp_window->animation_in_progress) - { - comp_window->hide_after_animation = TRUE; - return; - } - - cancel_fade (comp_window); - - cm_drawable_node_set_viewable (CM_DRAWABLE_NODE (comp_window->node), - FALSE); -} - -MetaCompWindow * -meta_comp_window_new (MetaScreen *screen, - WsDrawable *drawable, - MetaCompWindowDestroy destroy, - gpointer closure) -{ - MetaDisplay *display = screen->display; - MetaCompWindow *window; - WsRectangle geometry; - - ws_drawable_query_geometry (drawable, &geometry); - - window = g_new0 (MetaCompWindow, 1); - - window->screen = screen; - window->display = display; - window->drawable = g_object_ref (drawable); - window->node = cm_drawable_node_new (drawable, &geometry); - window->updates = TRUE; - window->counter_value = 1; - window->ref_count = 1; - window->destroy = destroy; - window->closure = closure; - - meta_comp_window_hide (window); - - return window; -} - -static MetaCompWindow * -comp_window_ref (MetaCompWindow *comp_window) -{ - comp_window->ref_count++; - - return comp_window; -} - -static gboolean -comp_window_unref (MetaCompWindow *comp_window) -{ - if (--comp_window->ref_count == 0) - { - if (comp_window->destroy) - comp_window->destroy (comp_window, comp_window->closure); - - g_object_unref (comp_window->drawable); - g_object_unref (comp_window->node); - if (comp_window->alarm) - g_object_unref (comp_window->alarm); - memset (comp_window, 'e', sizeof (MetaCompWindow)); - g_free (comp_window); - - return TRUE; - } - - return FALSE; -} - -gboolean -meta_comp_window_free (MetaCompWindow *window) -{ - return comp_window_unref (window); -} - -void -meta_comp_window_set_size (MetaCompWindow *comp_window, - WsRectangle *rect) -{ - if (comp_window->updates) - { - WsWindow *window = WS_WINDOW (comp_window->drawable); - WsDisplay *display = WS_RESOURCE (window)->display; - CmDrawableNode *dnode = CM_DRAWABLE_NODE (comp_window->node); - WsRegion *shape; - - ws_display_begin_error_trap (display); - - cm_drawable_node_set_geometry (dnode, rect); - shape = ws_window_get_output_shape (window); - cm_drawable_node_set_shape (dnode, shape); - ws_region_destroy (shape); - - if (rect->width != comp_window->size.width || - rect->height != comp_window->size.height) - { - cm_drawable_node_update_pixmap (dnode); - } - - comp_window->size = *rect; - - ws_display_end_error_trap (display); - } -} - -static gboolean -has_type (WsWindow *window, const char *check_type) -{ - gchar **types = ws_window_get_property_atom_list (window, "_NET_WM_WINDOW_TYPE"); - int i; - gboolean result; - - if (!types) - return FALSE; - - result = FALSE; - - for (i = 0; types[i] != NULL; ++i) - { - gchar *type = types[i]; - - if (strcmp (type, check_type) == 0) - { - result = TRUE; - break; - } - } - - g_strfreev (types); - return result; -} - -static MetaWindow * -find_meta_window (MetaCompWindow *comp_window) -{ - Window xwindow = WS_RESOURCE_XID (comp_window->drawable); - MetaWindow *window = - meta_display_lookup_x_window (comp_window->display, xwindow); - - return window; -} - -static void -send_configure_notify (WsDrawable *drawable) -{ - WsWindow *window = WS_WINDOW (drawable); - WsRectangle geo; - - ws_drawable_query_geometry (drawable, &geo); - -#if 0 - g_print ("sending configure notify %d %d %d %d\n", - geo.x, geo.y, geo.width, geo.height); -#endif - - ws_window_send_configure_notify ( - window, geo.x, geo.y, geo.width, geo.height, - 0 /* border width */, ws_window_query_override_redirect (window)); -} - -static WsWindow * -find_client_window (MetaCompWindow *comp_window) -{ - MetaWindow *meta_window = find_meta_window (comp_window); - - if (meta_window && meta_window->frame) - { - WsDisplay *ws_display = WS_RESOURCE (comp_window->drawable)->display; - -#if 0 - g_print ("framed window (client: %lx)\n", WS_RESOURCE_XID (comp_window->drawable)); -#endif - -#if 0 - g_print ("framed window (client: %lx\n", meta_window->xwindow); -#endif - -#if 0 - g_print ("framed window: %p\n", comp_window); -#endif - return ws_window_lookup (ws_display, meta_window->xwindow); - } - else - { -#if 0 - if (meta_window) - g_print ("window not framed, but managed (%p)\n", comp_window); - else - g_print ("no meta window %p\n", comp_window); -#endif - - return WS_WINDOW (comp_window->drawable); - } -} - -static gboolean -private_metacity_window (MetaCompWindow *comp_window) -{ - /* Returns TRUE if this is a private metacity window - * such as a tooltip or a menu - */ - XID xid = WS_RESOURCE_XID (comp_window->drawable); - - return meta_ui_window_is_widget (comp_window->screen->ui, xid); -} - -static gboolean -frameless_managed (MetaCompWindow *comp_window) -{ - /* For some reason frameless, managed windows don't respond to - * sync requests messages. FIXME: at some point need to find out - * what's going on - */ - MetaWindow *mw = find_meta_window (comp_window); - - return mw && !mw->frame; -} - -static gdouble -interpolate (gdouble t, gdouble begin, gdouble end, double power) -{ - return (begin + (end - begin) * pow (t, power)); -} - -static void -interpolate_rectangle (gdouble t, - WsRectangle * from, - WsRectangle * to, - WsRectangle * result) -{ - if (!result) - return; - - result->x = interpolate (t, from->x, to->x, 1); - result->y = interpolate (t, from->y, to->y, 1); - result->width = interpolate (t, from->width, to->width, 1); - result->height = interpolate (t, from->height, to->height, 1); -} - -static void -comp_window_set_target_rect (MetaCompWindow *window, - WsRectangle *rect) -{ - cm_drawable_node_set_scale_rect (window->node, rect); -} - -static void -comp_window_get_real_size (MetaCompWindow *window, - WsRectangle *size) -{ - if (!size) - return; - - cm_drawable_node_get_clipbox (window->node, size); -} - -#define FADE_TIME 0.225 - -typedef struct -{ - MetaEffect *effect; - MetaCompWindow *window; - GTimer * timer; - WsRectangle from; - WsRectangle to; - gboolean first_time; - gdouble start_alpha; - gdouble end_alpha; -} FadeInfo; - -static gboolean -update_fade (gpointer data) -{ - FadeInfo *info = data; - gdouble elapsed = g_timer_elapsed (info->timer, NULL); - gdouble t = elapsed / FADE_TIME; - - if (elapsed >= FADE_TIME) - { - comp_window_set_target_rect (info->window, &info->to); - cm_drawable_node_set_alpha (info->window->node, info->end_alpha); - cm_drawable_node_unset_patch (info->window->node); - comp_window_unref (info->window); - return FALSE; - } - else - { - gdouble alpha = interpolate (t, info->start_alpha, info->end_alpha, 1.0); - WsRectangle cur; - - if (info->first_time) - { - meta_comp_window_show (info->window); - info->first_time = FALSE; - } - - interpolate_rectangle (t, &info->from, &info->to, &cur); - comp_window_set_target_rect (info->window, &cur); - cm_drawable_node_set_alpha (info->window->node, alpha); - return TRUE; - } -} - -static void -cancel_fade (MetaCompWindow *comp_window) -{ - if (comp_window->fade_in_idle_id) - { - g_source_remove (comp_window->fade_in_idle_id); - comp_window->fade_in_idle_id = 0; - } -} - -static void -meta_comp_window_fade_in (MetaCompWindow *comp_window) -{ - FadeInfo *info = g_new0 (FadeInfo, 1); - WsWindow *window = find_client_window (comp_window); - - if (comp_window->fade_in_idle_id) - return; - - info->window = comp_window_ref (comp_window); - info->timer = g_timer_new (); - - comp_window_get_real_size (info->window, &info->to); - info->from = info->to; - - info->start_alpha = 0.1; - info->first_time = TRUE; - - if (has_type (window, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU") || - has_type (window, "_NET_WM_WINDOW_TYPE_POPUP_MENU")) - { - info->end_alpha = 0.9; - info->from.width *= 0.6; - info->from.height *= 0.4; - } - else if (has_type (window, "_NET_WM_WINDOW_TYPE_DIALOG")) - { - info->end_alpha = 0.9; - } - else - { - info->end_alpha = 1.0; - } - - comp_window->fade_in_idle_id = g_idle_add (update_fade, info); -} - -static void -on_request_alarm (WsSyncAlarm *alarm, - WsAlarmNotifyEvent *event, - MetaCompWindow *comp_window) -{ - /* This alarm means that the window is ready to be shown on screen */ - - if (comp_window->unminimize_info) - start_unminimize (comp_window); - else - meta_comp_window_fade_in (comp_window); - - g_object_unref (alarm); -} - -static gboolean -send_sync_request (MetaCompWindow *comp_window) -{ - WsDisplay *display; - WsWindow *client_window = find_client_window (comp_window); - WsSyncCounter *request_counter; - WsSyncAlarm *alarm; - guint32 msg[5]; - display = WS_RESOURCE (comp_window->drawable)->display; - ws_display_init_sync (display); - - if (!client_window) - return FALSE; - - request_counter = ws_window_get_property_sync_counter ( - client_window, "_NET_WM_SYNC_REQUEST_COUNTER"); - - if (!request_counter) - return FALSE; - - comp_window->counter_value = ws_sync_counter_query_value (request_counter) + 1; - - msg[0] = comp_window->display->atom_net_wm_sync_request; - msg[1] = meta_display_get_current_time (comp_window->display); - msg[2] = comp_window->counter_value & 0xffffffff; - msg[3] = (comp_window->counter_value >> 32) & 0xffffffff; - - alarm = ws_sync_alarm_new (display, request_counter); - - ws_sync_alarm_set (alarm, comp_window->counter_value); - - g_signal_connect (alarm, "alarm_notify_event", - G_CALLBACK (on_request_alarm), comp_window); - - ws_window_send_client_message (client_window, - "WM_PROTOCOLS", msg); - - send_configure_notify (WS_DRAWABLE (client_window)); - - ws_display_flush (WS_RESOURCE (client_window)->display); - - return TRUE; -} - -void -meta_comp_window_refresh_attrs (MetaCompWindow *comp_window) -{ - /* FIXME: this function should not exist - the real problem is - * probably in meta_screen_info_add_window() where it it called. - */ - - double alpha = 1.0; - CmDrawableNode *node = CM_DRAWABLE_NODE (comp_window->node); - -#if 0 - g_print ("waiting for paint: %d\n", comp_window->waiting_for_paint); -#endif - - if (ws_window_query_mapped (WS_WINDOW (comp_window->drawable)) -#if 0 - && !comp_window->waiting_for_paint -#endif - ) - { - WsWindow *window = WS_WINDOW (comp_window->drawable); - - cm_drawable_node_unset_patch (CM_DRAWABLE_NODE (node)); - - if (has_type (window, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU")) - { - alpha = 0.9; - } - else if (has_type (window, "_NET_WM_WINDOW_TYPE_POPUP_MENU")) - { - alpha = 0.9; - } - else - { - alpha = 1.0; - } - - cm_drawable_node_set_alpha (node, alpha); - - if (!cm_drawable_node_get_viewable (node)) - { - comp_window->waiting_for_paint = TRUE; -#if 0 - alarm = ws_alarm_new (comp_window->display); -#endif -#if 0 - finish_counter = ws_window_get_property_sync_counter ( - window, "_NET_WM_FINISH_FRAME_COUNTER"); -#endif - - /* For some reason the panel and nautilus don't respond to the - * sync counter stuff. FIXME: this should be figured out at - * some point. - */ - if (frameless_managed (comp_window) || - private_metacity_window (comp_window) || - !send_sync_request (comp_window)) - { - meta_comp_window_show (comp_window); - } - } - } - else - { -#if 0 - g_print ("unmapping %p\n", node); -#endif - - meta_comp_window_hide (comp_window); - } -} - -void -meta_comp_window_set_updates (MetaCompWindow *comp_window, - gboolean updates) -{ - CmDrawableNode *node = CM_DRAWABLE_NODE (comp_window->node); - - comp_window->updates = updates; - - cm_drawable_node_set_updates (node, updates); - - if (updates) - { - WsRectangle rect; - WsRegion *shape; - WsDisplay *display = WS_RESOURCE (node->drawable)->display; - - ws_display_begin_error_trap (display); - ws_drawable_query_geometry (node->drawable, &rect); - cm_drawable_node_update_pixmap (node); - cm_drawable_node_set_geometry (node, &rect); - shape = ws_window_get_output_shape (WS_WINDOW (node->drawable)); - cm_drawable_node_set_shape (node, shape); - ws_region_destroy (shape); - ws_display_end_error_trap (display); - } -} - -CmNode * -meta_comp_window_get_node (MetaCompWindow *comp_window) -{ - return CM_NODE (comp_window->node); -} - -/* - * Explosion effect - */ -#define EXPLODE_TIME 1.0 - -#define BASE 0.5 - -static double -transform (double in) -{ - return (pow (BASE, in) - 1) / (BASE - 1); -} - -typedef struct -{ - MetaEffect *effect; - MetaCompWindow *comp_window; - gdouble level; - GTimer * timer; -} ExplodeInfo; - -static gboolean -update_explosion (gpointer data) -{ - ExplodeInfo *info = data; - CmDrawableNode *node = CM_DRAWABLE_NODE (info->comp_window->node); - gdouble elapsed = g_timer_elapsed (info->timer, NULL); - - if (!cm_drawable_node_get_viewable (node) || elapsed > EXPLODE_TIME) - { - meta_effect_end (info->effect); - - info->comp_window->animation_in_progress = FALSE; - if (info->comp_window->hide_after_animation) - meta_comp_window_hide (info->comp_window); - - cm_drawable_node_set_explosion_level (node, 0.0); - - comp_window_unref (info->comp_window); - return FALSE; - } - else - { - gdouble t = elapsed / EXPLODE_TIME; - - cm_drawable_node_set_explosion_level ( - node, transform (t)); - return TRUE; - } -} - -void -meta_comp_window_explode (MetaCompWindow *comp_window, - MetaEffect *effect) -{ - ExplodeInfo *info = g_new0 (ExplodeInfo, 1); - - if (!cm_drawable_node_get_viewable (comp_window->node)) - return; - - comp_window->animation_in_progress = TRUE; - - info->comp_window = comp_window_ref (comp_window); - info->effect = effect; - info->level = 0.0; - info->timer = g_timer_new (); - - g_idle_add (update_explosion, info); -} - -/* shrinkydink minimize effect */ - -#define N_PHASES 5 - -typedef struct -{ - WsRectangle start_rect; - WsRectangle end_rect; - gdouble start_alpha; - gdouble end_alpha; - gdouble start_time; - gdouble end_time; -} Phase; - -typedef struct -{ - GTimer *timer; - - MetaCompWindow *comp_window; - - MetaEffect *effect; - - Phase phases[N_PHASES]; -} MiniInfo; - -static void -set_geometry (MetaCompWindow *window, - Phase *phase, - gdouble elapsed) -{ - WsRectangle rect; - gdouble alpha; - gdouble t = (elapsed - phase->start_time) / (phase->end_time - phase->start_time); - - interpolate_rectangle (t, &phase->start_rect, &phase->end_rect, &rect); - alpha = interpolate (t, phase->start_alpha, phase->end_alpha, 1.0); - - comp_window_set_target_rect (window, &rect); - cm_drawable_node_set_alpha (window->node, alpha); -} - -static int -center (gdouble what, gdouble in) -{ - return (in - what) / 2.0 + 0.5; -} - -#define WOBBLE_FACTOR 1.5 - -static void -generate_phases (WsRectangle *start, - WsRectangle *icon, - Phase phases[N_PHASES]) -{ - const double phase_times[5] = { - 0.225, /* scale to size of button */ - 0.100, /* scale up a little */ - 0.100, /* scale back a little */ - 0.100, /* drop down to icon */ - 0.350, /* fade out */ - }; - - WsRectangle cur; - gdouble alpha; - gdouble aspect_ratio; - gdouble time; - int i; - - aspect_ratio = (double)start->width / (double)start->height; - cur = *start; - time = 0.0; - alpha = 1.0; - for (i = 0; i < N_PHASES; ++i) - { - Phase *phase = &(phases[i]); - WsRectangle *end = &(phase->end_rect); - - phase->start_time = time; - phase->start_rect = cur; - phase->start_alpha = alpha; - phase->end_alpha = 1.0; - phase->end_time = time + phase_times[i]; - - if (i == 0) - { - /* Shrink to a little rectangle */ - end->height = icon->height; - end->width = icon->height * aspect_ratio; -#if 0 - end->x = icon->x + center (end->width, icon->width); -#endif - end->x = cur.x + center (end->width, cur.width); - end->y = cur.y + center (icon->height, cur.height); - } - else if (i == 1) - { - /* Zoom out a little */ - end->x = cur.x + center (WOBBLE_FACTOR * cur.width, cur.width); - end->y = cur.y + center (WOBBLE_FACTOR * cur.height, cur.height); - end->width = cur.width * WOBBLE_FACTOR; - end->height = cur.height * WOBBLE_FACTOR; - } - else if (i == 2) - { - /* Zoom back */ - end->height = icon->height; - end->width = icon->height * aspect_ratio; -#if 0 - end->x = icon->x + center (end->width, icon->width); -#endif - end->x = cur.x + center (end->width, cur.width); - end->y = cur.y + center (icon->height, cur.height); - } - else if (i == 3) - { - /* Move down to the button */ - end->height = icon->height; - end->width = icon->height * aspect_ratio; - end->x = icon->x + center (end->width, icon->width); - end->y = icon->y; - } - else if (i == 4) - { - /* Fade out */ - end->x = icon->x; - end->y = icon->y; - end->width = icon->width; - end->height = icon->height; - - phases[i].end_alpha = 0.0; - } - - alpha = phase->end_alpha; - cur = phase->end_rect; - time += phase_times[i]; - } -} - -static gboolean -update_minimize (gpointer data) -{ - MiniInfo *info = data; - Phase *current_phase; - int i; - gdouble elapsed = g_timer_elapsed (info->timer, NULL); - - current_phase = NULL; - for (i = 0; i < N_PHASES; ++i) - { - Phase *p = &(info->phases[i]); - - if (p->start_time < elapsed && p->end_time >= elapsed) - { - current_phase = p; - break; - } - } - - if (current_phase) - { - set_geometry (info->comp_window, current_phase, elapsed); - return TRUE; - } - else - { - meta_comp_window_hide (info->comp_window); - cm_drawable_node_set_alpha (info->comp_window->node, 1.0); - cm_drawable_node_unset_patch (info->comp_window->node); - comp_window_unref (info->comp_window); - - meta_effect_end (info->effect); - - return FALSE; - } -} - -static void -meta_rect_to_ws_rect (MetaRectangle *mrect, - WsRectangle *wrect) -{ - if (!mrect || !wrect) - return; - - wrect->x = mrect->x; - wrect->y = mrect->y; - wrect->width = mrect->width; - wrect->height = mrect->height; -} - -void -meta_comp_window_run_minimize (MetaCompWindow *window, - MetaEffect *effect) -{ - MiniInfo *info = g_new (MiniInfo, 1); - WsRectangle start, end; - - info->timer = g_timer_new (); - - info->comp_window = comp_window_ref (window); - - info->effect = effect; - - meta_rect_to_ws_rect (&(effect->u.minimize.window_rect), &start); - meta_rect_to_ws_rect (&(effect->u.minimize.icon_rect), &end); - - generate_phases (&start, &end, info->phases); - - g_idle_add (update_minimize, info); -} - -struct UnminimizeInfo -{ - GTimer *timer; - - MetaCompWindow *comp_window; - - Phase phases[N_PHASES]; - gboolean first_time; -}; - -#define WOBBLE_FACTOR_OUT 0.7 - -static void -generate_unminimize_phases (WsRectangle *icon, - WsRectangle *full, - Phase phases[N_PHASES]) -{ - const double phase_times[5] = { - 0.350, /* fade in */ - 0.100, /* move up from icon */ - 0.225, /* scale to full size */ - 0.100, /* scale down a little */ - 0.100, /* scale to full size */ - }; - - WsRectangle cur; - gdouble aspect_ratio; - gdouble time; - int i; - - aspect_ratio = (double)full->width / (double)full->height; - cur = *icon; - time = 0.0; - for (i = 0; i < N_PHASES; ++i) - { - Phase *phase = &(phases[i]); - WsRectangle *end = &(phase->end_rect); - - phase->start_time = time; - phase->start_rect = cur; - phase->start_alpha = 1.0; - phase->end_alpha = 1.0; - phase->end_time = time + phase_times[i]; - - if (i == 0) - { - /* Fade in */ - phase->end_alpha = 1.0; - phase->start_alpha = 0.0; - end->height = icon->height; - end->width = icon->height * aspect_ratio; - end->x = icon->x + center (end->width, icon->width); - end->y = icon->y; - } - else if (i == 1) - { - /* Move up from icon */ - end->width = cur.width; - end->height = cur.height; -#if 0 - end->x = cur.x; -#endif - end->x = full->x + center (end->width, full->width); - end->y = full->y + center (icon->height, full->height); - } - else if (i == 2) - { - /* Zoom to full size */ - *end = *full; - } - else if (i == 3) - { - /* Scale down a little */ - end->x = cur.x + center (cur.width * WOBBLE_FACTOR_OUT, cur.width); - end->y = cur.y + center (cur.height * WOBBLE_FACTOR_OUT, cur.height); - end->width = cur.width * WOBBLE_FACTOR_OUT; - end->height = cur.height * WOBBLE_FACTOR_OUT; - } - else if (i == 4) - { - /* Scale up to full size again */ - *end = *full; - } - - cur = phase->end_rect; - time += phase_times[i]; - } -} - -static gboolean -update_unminimize (gpointer data) -{ - UnminimizeInfo *info = data; - Phase *current_phase; - int i; - gdouble elapsed = g_timer_elapsed (info->timer, NULL); - - current_phase = NULL; - for (i = 0; i < N_PHASES; ++i) - { - Phase *p = &(info->phases[i]); - - if (p->start_time < elapsed && p->end_time >= elapsed) - { - current_phase = p; - break; - } - } - - if (current_phase) - { - if (info->first_time) - { - meta_comp_window_show (info->comp_window); - info->first_time = FALSE; - } - - set_geometry (info->comp_window, current_phase, elapsed); - return TRUE; - } - else - { - cm_drawable_node_set_alpha (info->comp_window->node, 1.0); - cm_drawable_node_unset_patch (info->comp_window->node); - comp_window_unref (info->comp_window); -#if 0 - g_print ("done\n"); -#endif - - return FALSE; - } - -} - -static void -start_unminimize (MetaCompWindow *comp_window) -{ - UnminimizeInfo *info = comp_window->unminimize_info; - - if (!info) - return; - - comp_window->unminimize_info = NULL; - - info->timer = g_timer_new (); - info->first_time = TRUE; - - g_idle_add (update_unminimize, info); -} - -void -meta_comp_window_run_unminimize (MetaCompWindow *comp_window, - MetaEffect *effect) -{ - WsRectangle start, end; - UnminimizeInfo *info = g_new0 (UnminimizeInfo, 1); - - meta_rect_to_ws_rect (&(effect->u.unminimize.icon_rect), &start); - meta_rect_to_ws_rect (&(effect->u.unminimize.window_rect), &end); - - generate_unminimize_phases (&start, &end, info->phases); - - info->comp_window = comp_window_ref (comp_window); - - comp_window->unminimize_info = info; - - meta_effect_end (effect); -} - -/* bounce effect */ - -typedef struct -{ - MetaEffect *effect; - MetaCompWindow *window; - GTimer *timer; - Model *model; - MetaRectangle rect; - gdouble last_time; -} FocusInfo; - -static gboolean -update_focus (gpointer data) -{ - FocusInfo *info = data; - CmDrawableNode *node = (CmDrawableNode *)info->window->node; - gdouble elapsed = g_timer_elapsed (info->timer, NULL); - int i; - int n_steps = floor ((elapsed - info->last_time) * 60); - CmPoint points[4][4]; - - if (model_is_calm (info->model) || elapsed > 0.7) - { - cm_drawable_node_unset_patch (node); - meta_effect_end (info->effect); - g_free(info); - return FALSE; - } - - for (i = 0; i < n_steps; ++i) - model_step (info->model); - - if (i > 0) - info->last_time = elapsed; - - get_patch_points (info->model, points); - - cm_drawable_node_set_patch (node, points); - return TRUE; -} - -void -meta_comp_window_run_focus (MetaCompWindow *comp_window, - MetaEffect *effect) -{ - FocusInfo *info = g_new0 (FocusInfo, 1); - MetaWindow *meta_window = - meta_display_lookup_x_window (comp_window->display, - WS_RESOURCE_XID (comp_window->drawable)); - - info->window = comp_window; - info->effect = effect; - info->timer = g_timer_new (); - info->last_time = 0; - - compute_window_rect (meta_window, &info->rect); - info->model = model_new (&info->rect, TRUE); - - g_idle_add (update_focus, info); -} - -void -meta_comp_window_freeze_stack (MetaCompWindow *comp_window) -{ - comp_window->stack_freeze_count++; -} - -void -meta_comp_window_thaw_stack (MetaCompWindow *comp_window) -{ - comp_window->stack_freeze_count--; -} - -gboolean -meta_comp_window_stack_frozen (MetaCompWindow *comp_window) -{ - return comp_window->stack_freeze_count > 0; -} - -#endif - diff --git a/src/c-window.h b/src/c-window.h deleted file mode 100644 index c7a574fb..00000000 --- a/src/c-window.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* - * Copyright (C) 2006 Red Hat, Inc. - * - * 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 -#include "display.h" -#include "effects.h" - -#ifndef C_WINDOW_H -#define C_WINDOW_H - -typedef struct _MetaCompWindow MetaCompWindow; - -typedef void (* MetaCompWindowDestroy) (MetaCompWindow *window, - gpointer closure); - -MetaCompWindow *meta_comp_window_new (MetaScreen *screen, - WsDrawable *drawable, - MetaCompWindowDestroy destroy, - gpointer data); -CmNode *meta_comp_window_get_node (MetaCompWindow *window); -gboolean meta_comp_window_free (MetaCompWindow *window); -void meta_comp_window_set_size (MetaCompWindow *window, - WsRectangle *size); - -void meta_comp_window_hide (MetaCompWindow *comp_window); -void meta_comp_window_show (MetaCompWindow *comp_window); -void meta_comp_window_refresh_attrs (MetaCompWindow *comp_window); -void meta_comp_window_set_updates (MetaCompWindow *comp_window, - gboolean updates); - -void meta_comp_window_explode (MetaCompWindow *comp_window, - MetaEffect *effect); -void meta_comp_window_shrink (MetaCompWindow *comp_window, - MetaEffect *effect); -void meta_comp_window_unshrink (MetaCompWindow *comp_window, - MetaEffect *effect); -void meta_comp_window_run_focus (MetaCompWindow *comp_window, - MetaEffect *effect); -void meta_comp_window_restack (MetaCompWindow *comp_window, - MetaCompWindow *above); -void meta_comp_window_freeze_stack (MetaCompWindow *comp_window); -void meta_comp_window_thaw_stack (MetaCompWindow *comp_window); -gboolean meta_comp_window_stack_frozen (MetaCompWindow *comp_window); -void meta_comp_window_run_minimize (MetaCompWindow *window, - MetaEffect *effect); -void meta_comp_window_run_unminimize (MetaCompWindow *comp_window, - MetaEffect *effect); - -#if 0 -void meta_comp_window_set_explode (MetaCompWindow *comp_window, - double level); -#endif - -#endif - diff --git a/src/compositor.c b/src/compositor.c index a0b865b2..82235b1a 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -23,18 +23,21 @@ #define HAVE_NAME_WINDOW_PIXMAP 1 #endif -struct _MetaCompositor { +struct _MetaCompositor +{ MetaDisplay *display; guint enabled : 1; }; -typedef struct _conv { +typedef struct _conv +{ int size; double *data; } conv; -typedef struct _MetaCompScreen { +typedef struct _MetaCompScreen +{ MetaScreen *screen; GList *windows; GHashTable *windows_by_xid; @@ -55,7 +58,8 @@ typedef struct _MetaCompScreen { gboolean clip_changed; } MetaCompScreen; -typedef struct _MetaCompWindow { +typedef struct _MetaCompWindow +{ MetaScreen *screen; Window id; XWindowAttributes attrs; @@ -126,20 +130,24 @@ make_gaussian_map (double r) c->data = (double *) (c + 1); t = 0.0; - for (y = 0; y < size; y++) { - for (x = 0; x < size; x++) { - g = gaussian (r, (double) (x - centre), (double) (y - centre)); - t += g; - c->data[y * size + x] = g; + for (y = 0; y < size; y++) + { + for (x = 0; x < size; x++) + { + g = gaussian (r, (double) (x - centre), (double) (y - centre)); + t += g; + c->data[y * size + x] = g; + } } - } - - for (y = 0; y < size; y++) { - for (x = 0; x < size; x++) { - c->data[y * size + x] /= t; + + for (y = 0; y < size; y++) + { + for (x = 0; x < size; x++) + { + c->data[y * size + x] /= t; + } } - } - + return c; } @@ -178,39 +186,36 @@ sum_gaussian (conv *map, g_size = map->size; centre = g_size / 2; fx_start = centre - x; - if (fx_start < 0) { + if (fx_start < 0) fx_start = 0; - } fx_end = width + centre - x; - if (fx_end > g_size) { + if (fx_end > g_size) fx_end = g_size; - } fy_start = centre - y; - if (fy_start < 0) { + if (fy_start < 0) fy_start = 0; - } fy_end = height + centre - y; - if (fy_end > g_size) { + if (fy_end > g_size) fy_end = g_size; - } + g_line = g_line + fy_start * g_size + fx_start; v = 0.0; - for (fy = fy_start; fy < fy_end; fy++) { - g_data = g_line; - g_line += g_size; - - for (fx = fx_start; fx < fx_end; fx++) { - v += *g_data++; + for (fy = fy_start; fy < fy_end; fy++) + { + g_data = g_line; + g_line += g_size; + + for (fx = fx_start; fx < fx_end; fx++) + v += *g_data++; } - } - if (v > 1.0) { + + if (v > 1.0) v = 1.0; - } - + return ((guchar) (v * opacity * 255.0)); } @@ -227,47 +232,49 @@ presum_gaussian (MetaCompScreen *info) msize = map->size; centre = map->size / 2; - if (info->shadow_corner) { + if (info->shadow_corner) g_free (info->shadow_corner); - } - if (info->shadow_top) { + if (info->shadow_top) g_free (info->shadow_top); - } info->shadow_corner = (guchar *)(g_malloc ((msize + 1) * (msize + 1) * 26)); info->shadow_top = (guchar *) (g_malloc ((msize + 1) * 26)); - - for (x = 0; x <= msize; x++) { - - info->shadow_top[25 * (msize + 1) + x] = - sum_gaussian (map, 1, x - centre, centre, msize * 2, msize * 2); - for (opacity = 0; opacity < 25; opacity++) { - info->shadow_top[opacity * (msize + 1) + x] = - info->shadow_top[25 * (msize + 1) + x] * opacity / 25; - } - - for (y = 0; y <= x; y++) { - info->shadow_corner[25 * (msize + 1) * (msize + 1) - + y * (msize + 1) - + x] - = sum_gaussian (map, 1, x - centre, y - centre, - msize * 2, msize * 2); - - info->shadow_corner[25 * (msize + 1) * (msize + 1) - + x * (msize + 1) + y] = - info->shadow_corner[25 * (msize + 1) * (msize + 1) - + y * (msize + 1) + x]; - - for (opacity = 0; opacity < 25; opacity++) { - info->shadow_corner[opacity * (msize + 1) * (msize + 1) - + y * (msize + 1) + x] - = info->shadow_corner[opacity * (msize + 1) * (msize + 1) - + x * (msize + 1) + y] - = info->shadow_corner[25 * (msize + 1) * (msize + 1) - + y * (msize + 1) + x] * opacity / 25; - } + + for (x = 0; x <= msize; x++) + { + + info->shadow_top[25 * (msize + 1) + x] = + sum_gaussian (map, 1, x - centre, centre, msize * 2, msize * 2); + for (opacity = 0; opacity < 25; opacity++) + { + info->shadow_top[opacity * (msize + 1) + x] = + info->shadow_top[25 * (msize + 1) + x] * opacity / 25; + } + + for (y = 0; y <= x; y++) + { + info->shadow_corner[25 * (msize + 1) * (msize + 1) + + y * (msize + 1) + + x] + = sum_gaussian (map, 1, x - centre, y - centre, + msize * 2, msize * 2); + + info->shadow_corner[25 * (msize + 1) * (msize + 1) + + x * (msize + 1) + y] = + info->shadow_corner[25 * (msize + 1) * (msize + 1) + + y * (msize + 1) + x]; + + for (opacity = 0; opacity < 25; opacity++) + { + info->shadow_corner[opacity * (msize + 1) * (msize + 1) + + y * (msize + 1) + x] + = info->shadow_corner[opacity * (msize + 1) * (msize + 1) + + x * (msize + 1) + y] + = info->shadow_corner[25 * (msize + 1) * (msize + 1) + + y * (msize + 1) + x] * opacity / 25; + } + } } - } } static XImage * @@ -296,10 +303,11 @@ make_shadow (MetaDisplay *display, DefaultVisual (display->xdisplay, screen->number), 8, ZPixmap, 0, (char *) data, swidth, sheight, 8, swidth * sizeof (guchar)); - if (!ximage) { - g_free (data); - return NULL; - } + if (!ximage) + { + g_free (data); + return NULL; + } /* * Build the gaussian in sections @@ -308,75 +316,77 @@ make_shadow (MetaDisplay *display, /* * centre (fill the complete data array */ - if (msize > 0) { + if (msize > 0) d = info->shadow_top[opacity_int * (msize + 1) + msize]; - } else { + else d = sum_gaussian (info->gaussian_map, opacity, centre, centre, width, height); - } memset (data, d, sheight * swidth); /* * corners */ ylimit = msize; - if (ylimit > sheight / 2) { + if (ylimit > sheight / 2) ylimit = (sheight + 1) / 2; - } + xlimit = msize; - if (xlimit > swidth / 2) { + if (xlimit > swidth / 2) xlimit = (swidth + 1) / 2; - } - for (y = 0; y < ylimit; y++) { - for (x = 0; x < xlimit; x++) { - - if (xlimit == msize && ylimit == msize) { - d = info->shadow_corner[opacity_int * (msize + 1) * (msize + 1) + y * (msize + 1) + x]; - } else { - d = sum_gaussian (info->gaussian_map, opacity, x - centre, - y - centre, width, height); - } - - data[y * swidth + x] = d; - data[(sheight - y - 1) * swidth + x] = d; - data[(sheight - y - 1) * swidth + (swidth - x - 1)] = d; - data[y * swidth + (swidth - x - 1)] = d; + for (y = 0; y < ylimit; y++) + { + for (x = 0; x < xlimit; x++) + { + + if (xlimit == msize && ylimit == msize) + d = info->shadow_corner[opacity_int * (msize + 1) * (msize + 1) + y * (msize + 1) + x]; + else + d = sum_gaussian (info->gaussian_map, opacity, x - centre, + y - centre, width, height); + + data[y * swidth + x] = d; + data[(sheight - y - 1) * swidth + x] = d; + data[(sheight - y - 1) * swidth + (swidth - x - 1)] = d; + data[y * swidth + (swidth - x - 1)] = d; + } } - } - + /* top/bottom */ x_diff = swidth - (msize * 2); - if (x_diff > 0 && ylimit > 0) { - for (y = 0; y < ylimit; y++) { - if (ylimit == msize) { - d = info->shadow_top[opacity_int * (msize + 1) + y]; - } else { - d = sum_gaussian (info->gaussian_map, opacity, centre, - y - centre, width, height); - } - memset (&data[y * swidth + msize], d, x_diff); - memset (&data[(sheight - y - 1) * swidth + msize], d, x_diff); + if (x_diff > 0 && ylimit > 0) + { + for (y = 0; y < ylimit; y++) + { + if (ylimit == msize) + d = info->shadow_top[opacity_int * (msize + 1) + y]; + else + d = sum_gaussian (info->gaussian_map, opacity, centre, + y - centre, width, height); + + memset (&data[y * swidth + msize], d, x_diff); + memset (&data[(sheight - y - 1) * swidth + msize], d, x_diff); + } } - } /* * sides */ - for (x = 0; x < xlimit; x++) { - if (xlimit == msize) { - d = info->shadow_top[opacity_int * (msize + 1) + x]; - } else { - d = sum_gaussian (info->gaussian_map, opacity, x - centre, + for (x = 0; x < xlimit; x++) + { + if (xlimit == msize) + d = info->shadow_top[opacity_int * (msize + 1) + x]; + else + d = sum_gaussian (info->gaussian_map, opacity, x - centre, centre, width, height); - } - for (y = msize; y < sheight - msize; y++) { - data[y * swidth + x] = d; - data[y * swidth + (swidth - x - 1)] = d; + for (y = msize; y < sheight - msize; y++) + { + data[y * swidth + x] = d; + data[y * swidth + (swidth - x - 1)] = d; + } } - } - + return ximage; } @@ -396,43 +406,45 @@ shadow_picture (MetaDisplay *display, GC gc; shadow_image = make_shadow (display, screen, opacity, width, height); - if (!shadow_image) { + if (!shadow_image) return None; - } shadow_pixmap = XCreatePixmap (display->xdisplay, screen->xroot, shadow_image->width, shadow_image->height, 8); - if (!shadow_pixmap) { - XDestroyImage (shadow_image); - return None; - } + if (!shadow_pixmap) + { + XDestroyImage (shadow_image); + return None; + } shadow_picture = XRenderCreatePicture (display->xdisplay, shadow_pixmap, XRenderFindStandardFormat (display->xdisplay, PictStandardA8), 0, 0); - if (!shadow_picture) { - XDestroyImage (shadow_image); - XFreePixmap (display->xdisplay, shadow_pixmap); - return None; - } - + if (!shadow_picture) + { + XDestroyImage (shadow_image); + XFreePixmap (display->xdisplay, shadow_pixmap); + return None; + } + gc = XCreateGC (display->xdisplay, shadow_pixmap, 0, 0); - if (!gc) { - XDestroyImage (shadow_image); - XFreePixmap (display->xdisplay, shadow_pixmap); - XRenderFreePicture (display->xdisplay, shadow_picture); - return None; - } + if (!gc) + { + XDestroyImage (shadow_image); + XFreePixmap (display->xdisplay, shadow_pixmap); + XRenderFreePicture (display->xdisplay, shadow_picture); + return None; + } XPutImage (display->xdisplay, shadow_pixmap, gc, shadow_image, 0, 0, 0, 0, shadow_image->width, shadow_image->height); *wp = shadow_image->width; *hp = shadow_image->height; - + XFreeGC (display->xdisplay, gc); XDestroyImage (shadow_image); XFreePixmap (display->xdisplay, shadow_pixmap); - + return shadow_picture; } @@ -442,10 +454,9 @@ find_window_for_screen (MetaScreen *screen, { MetaCompScreen *info = screen->compositor_data; - if (info == NULL) { + if (info == NULL) return NULL; - } - + return g_hash_table_lookup (info->windows_by_xid, (gpointer) xwindow); } @@ -455,13 +466,14 @@ find_window_in_display (MetaDisplay *display, { GSList *index; - for (index = display->screens; index; index = index->next) { - MetaCompWindow *cw = find_window_for_screen (index->data, xwindow); - if (cw != NULL) { - return cw; - } - } + for (index = display->screens; index; index = index->next) + { + MetaCompWindow *cw = find_window_for_screen (index->data, xwindow); + if (cw != NULL) + return cw; + } + return NULL; } @@ -490,20 +502,21 @@ solid_picture (MetaDisplay *display, pa.repeat = TRUE; picture = XRenderCreatePicture (display->xdisplay, pixmap, render_format, CPRepeat, &pa); - if (picture == None) { - XFreePixmap (display->xdisplay, pixmap); - g_warning ("(picture != None) failed"); - return None; - } + if (picture == None) + { + XFreePixmap (display->xdisplay, pixmap); + g_warning ("(picture != None) failed"); + return None; + } c.alpha = a * 0xffff; c.red = r * 0xffff; c.green = g * 0xffff; c.blue = b * 0xffff; - + XRenderFillRectangle (display->xdisplay, PictOpSrc, picture, &c, 0, 0, 1, 1); XFreePixmap (display->xdisplay, pixmap); - + return picture; } @@ -527,36 +540,38 @@ root_tile (MetaScreen *screen) background_atoms[2] = display->atom_e_set_root; pixmap_atom = XInternAtom (display->xdisplay, "PIXMAP", False); - for (p = 0; p < 3; p++) { - Atom actual_type; - int actual_format; - gulong nitems, bytes_after; - guchar *prop; - - if (XGetWindowProperty (display->xdisplay, screen->xroot, - background_atoms[p], - 0, 4, FALSE, AnyPropertyType, - &actual_type, &actual_format, - &nitems, &bytes_after, &prop) == Success) - { - if (actual_type == pixmap_atom && - actual_format == 32 && - nitems == 1) - { - memcpy (&pixmap, prop, 4); - XFree (prop); - fill = FALSE; - break; - } - } - } + for (p = 0; p < 3; p++) + { + Atom actual_type; + int actual_format; + gulong nitems, bytes_after; + guchar *prop; + + if (XGetWindowProperty (display->xdisplay, screen->xroot, + background_atoms[p], + 0, 4, FALSE, AnyPropertyType, + &actual_type, &actual_format, + &nitems, &bytes_after, &prop) == Success) + { + if (actual_type == pixmap_atom && + actual_format == 32 && + nitems == 1) + { + memcpy (&pixmap, prop, 4); + XFree (prop); + fill = FALSE; + break; + } + } + } - if (!pixmap) { - pixmap = XCreatePixmap (display->xdisplay, screen->xroot, 1, 1, - DefaultDepth (display->xdisplay, screen->number)); - g_return_val_if_fail (pixmap != None, None); - fill = TRUE; - } + if (!pixmap) + { + pixmap = XCreatePixmap (display->xdisplay, screen->xroot, 1, 1, + DefaultDepth (display->xdisplay, screen->number)); + g_return_val_if_fail (pixmap != None, None); + fill = TRUE; + } pa.repeat = TRUE; format = XRenderFindVisualFormat (display->xdisplay, @@ -566,20 +581,20 @@ root_tile (MetaScreen *screen) picture = XRenderCreatePicture (display->xdisplay, pixmap, format, CPRepeat, &pa); - if ((picture != None) && (fill)) { - XRenderColor c; - - /* Background default to just plain ugly grey */ - c.red = 0x8080; - c.green = 0x8080; - c.blue = 0x8080; - c.alpha = 0xffff; - - XRenderFillRectangle (display->xdisplay, PictOpSrc, picture, - &c, 0, 0, 1, 1); - } - /* FIXME: Leak? */ -/* XFreePixmap (display->xdisplay, pixmap); */ + if ((picture != None) && (fill)) + { + XRenderColor c; + + /* Background default to just plain ugly grey */ + c.red = 0x8080; + c.green = 0x8080; + c.blue = 0x8080; + c.alpha = 0xffff; + + XRenderFillRectangle (display->xdisplay, PictOpSrc, picture, + &c, 0, 0, 1, 1); + } + XFreePixmap (display->xdisplay, pixmap); return picture; } @@ -622,11 +637,12 @@ paint_root (MetaScreen *screen) g_return_if_fail (info->root_buffer != None); - if (info->root_tile == None) { - info->root_tile = root_tile (screen); - g_return_if_fail (info->root_tile != None); - } - + if (info->root_tile == None) + { + info->root_tile = root_tile (screen); + g_return_if_fail (info->root_tile != None); + } + XRenderComposite (display->xdisplay, PictOpSrc, info->root_tile, None, info->root_buffer, 0, 0, 0, 0, 0, 0, @@ -655,46 +671,48 @@ win_extents (MetaCompWindow *cw) * the window is ARGB and override redirected. */ - if (! (cw->mode == WINDOW_ARGB && cw->attrs.override_redirect)) { - XRectangle sr; - - cw->shadow_dx = SHADOW_OFFSET_X; - cw->shadow_dy = SHADOW_OFFSET_Y; - if (!cw->shadow) { - double opacity = SHADOW_OPACITY; - if (cw->mode == WINDOW_TRANS) { - opacity = opacity * ((double) cw->opacity) / ((double) OPAQUE); - } - - cw->shadow = shadow_picture (display, screen, opacity, cw->alpha_pict, - cw->attrs.width + cw->attrs.border_width * 2, - cw->attrs.height + cw->attrs.border_width * 2, - &cw->shadow_width, &cw->shadow_height); - } - - sr.x = cw->attrs.x + cw->shadow_dx; - sr.y = cw->attrs.y + cw->shadow_dy; - sr.width = cw->shadow_width; - sr.height = cw->shadow_height; - - if (sr.x < r.x) { - r.width = (r.x + r.width) - sr.x; - r.x = sr.x; - } - - if (sr.y < r.y) { - r.height = (r.y + r.height) - sr.y; - r.y = sr.y; - } - - if (sr.x + sr.width > r.x + r.width) { - r.width = sr.x + sr.width - r.x; - } - if (sr.y + sr.height > r.y + r.height) { - r.height = sr.y + sr.height - r.y; + if (! (cw->mode == WINDOW_ARGB && cw->attrs.override_redirect)) + { + XRectangle sr; + + cw->shadow_dx = SHADOW_OFFSET_X; + cw->shadow_dy = SHADOW_OFFSET_Y; + if (!cw->shadow) + { + double opacity = SHADOW_OPACITY; + if (cw->mode == WINDOW_TRANS) + opacity = opacity * ((double) cw->opacity) / ((double) OPAQUE); + + cw->shadow = shadow_picture (display, screen, opacity, cw->alpha_pict, + cw->attrs.width + cw->attrs.border_width * 2, + cw->attrs.height + cw->attrs.border_width * 2, + &cw->shadow_width, &cw->shadow_height); + } + + sr.x = cw->attrs.x + cw->shadow_dx; + sr.y = cw->attrs.y + cw->shadow_dy; + sr.width = cw->shadow_width; + sr.height = cw->shadow_height; + + if (sr.x < r.x) + { + r.width = (r.x + r.width) - sr.x; + r.x = sr.x; + } + + if (sr.y < r.y) + { + r.height = (r.y + r.height) - sr.y; + r.y = sr.y; + } + + if (sr.x + sr.width > r.x + r.width) + r.width = sr.x + sr.width - r.x; + + if (sr.y + sr.height > r.y + r.height) + r.height = sr.y + sr.height - r.y; } - } - + return XFixesCreateRegion (display->xdisplay, &r, 1); } @@ -722,12 +740,10 @@ get_window_format (MetaCompWindow *cw) XRenderPictFormat *format; format = XRenderFindVisualFormat (display->xdisplay, cw->attrs.visual); - if (!format) { + if (!format) format = XRenderFindVisualFormat (display->xdisplay, DefaultVisual (display->xdisplay, screen->number)); - } - return format; } @@ -743,20 +759,20 @@ get_window_picture (MetaCompWindow *cw) draw = cw->id; #ifdef HAVE_NAME_WINDOW_PIXMAP - if (cw->pixmap == None) { + if (cw->pixmap == None) cw->pixmap = XCompositeNameWindowPixmap (display->xdisplay, cw->id); - } - if (cw->pixmap != None) { + + if (cw->pixmap != None) draw = cw->pixmap; - } #endif format = get_window_format (cw); - if (format) { - pa.subwindow_mode = IncludeInferiors; - return XRenderCreatePicture (display->xdisplay, draw, - format, CPSubwindowMode, &pa); - } + if (format) + { + pa.subwindow_mode = IncludeInferiors; + return XRenderCreatePicture (display->xdisplay, draw, + format, CPSubwindowMode, &pa); + } return None; } @@ -779,18 +795,18 @@ paint_all (MetaScreen *screen, xroot = screen->xroot; /* Create root buffer if not done yet */ - if (info->root_buffer == None) { + if (info->root_buffer == None) info->root_buffer = create_root_buffer (screen); - } - if (region == None) { - XRectangle r; - r.x = 0; - r.y = 0; - r.width = screen_width; - r.height = screen_height; - region = XFixesCreateRegion (xdisplay, &r, 1); - } + if (region == None) + { + XRectangle r; + r.x = 0; + r.y = 0; + r.width = screen_width; + r.height = screen_height; + region = XFixesCreateRegion (xdisplay, &r, 1); + } /* Set clipping to the given region */ XFixesSetPictureClipRegion (xdisplay, info->root_picture, 0, 0, region); @@ -799,155 +815,168 @@ paint_all (MetaScreen *screen, * Painting from top to bottom, reducing the clipping area at * each iteration. Only the opaque windows are painted 1st. */ - for (index = info->windows; index; index = index->next) { - cw = (MetaCompWindow *) index->data; - - if (!cw->damaged) { - /* Not damaged */ - continue; - } - - if ((cw->attrs.x + cw->attrs.width < 1) || - (cw->attrs.y + cw->attrs.height < 1) || - (cw->attrs.x >= screen_width) || (cw->attrs.y >= screen_height)) { - /* Off screen */ - continue; - } - - if (cw->picture == None) { - cw->picture = get_window_picture (cw); - } - - if (info->clip_changed) { - if (cw->border_size) { - XFixesDestroyRegion (xdisplay, cw->border_size); - cw->border_size = None; - } - - if (cw->extents) { - XFixesDestroyRegion (xdisplay, cw->extents); - cw->extents = None; - } - } - if (cw->border_size == None) { - cw->border_size = border_size (cw); - } - - if (cw->extents == None) { - cw->extents = win_extents (cw); - } - - if (cw->mode == WINDOW_SOLID) { - int x, y, wid, hei; - + for (index = info->windows; index; index = index->next) + { + cw = (MetaCompWindow *) index->data; + + if (!cw->damaged) + { + /* Not damaged */ + continue; + } + + if ((cw->attrs.x + cw->attrs.width < 1) || + (cw->attrs.y + cw->attrs.height < 1) || + (cw->attrs.x >= screen_width) || (cw->attrs.y >= screen_height)) + { + /* Off screen */ + continue; + } + + if (cw->picture == None) + cw->picture = get_window_picture (cw); + + /* If the clip region of the screen has been changed + then we need to recreate the extents of the window */ + if (info->clip_changed) + { + if (cw->border_size) + { + XFixesDestroyRegion (xdisplay, cw->border_size); + cw->border_size = None; + } + + if (cw->extents) + { + XFixesDestroyRegion (xdisplay, cw->extents); + cw->extents = None; + } + } + + if (cw->border_size == None) + cw->border_size = border_size (cw); + + if (cw->extents == None) + cw->extents = win_extents (cw); + + if (cw->mode == WINDOW_SOLID) + { + int x, y, wid, hei; + #ifdef HAVE_NAME_WINDOW_PIXMAP - x = cw->attrs.x; - y = cw->attrs.y; - wid = cw->attrs.width + cw->attrs.border_width * 2; - hei = cw->attrs.height + cw->attrs.border_width * 2; + x = cw->attrs.x; + y = cw->attrs.y; + wid = cw->attrs.width + cw->attrs.border_width * 2; + hei = cw->attrs.height + cw->attrs.border_width * 2; #else - x = cw->attrs.x + cw->attrs.border_width; - y = cw->attrs.y + cw->attrs.border_width; - wid = cw->attrs.width; - hei = cw->attrs.height; + x = cw->attrs.x + cw->attrs.border_width; + y = cw->attrs.y + cw->attrs.border_width; + wid = cw->attrs.width; + hei = cw->attrs.height; #endif - - XFixesSetPictureClipRegion (xdisplay, info->root_buffer, 0, 0, region); - XRenderComposite (xdisplay, PictOpSrc, cw->picture, - None, info->root_buffer, 0, 0, 0, 0, - x, y, wid, hei); - XFixesSubtractRegion (xdisplay, region, region, cw->border_size); - } - if (!cw->border_clip) { - cw->border_clip = XFixesCreateRegion (xdisplay, 0, 0); - XFixesCopyRegion (xdisplay, cw->border_clip, region); + + XFixesSetPictureClipRegion (xdisplay, info->root_buffer, + 0, 0, region); + XRenderComposite (xdisplay, PictOpSrc, cw->picture, + None, info->root_buffer, 0, 0, 0, 0, + x, y, wid, hei); + XFixesSubtractRegion (xdisplay, region, region, cw->border_size); + } + + if (!cw->border_clip) + { + cw->border_clip = XFixesCreateRegion (xdisplay, 0, 0); + XFixesCopyRegion (xdisplay, cw->border_clip, region); + } } - } - + XFixesSetPictureClipRegion (xdisplay, info->root_buffer, 0, 0, region); paint_root (screen); /* * Painting from bottom to top, translucent windows and shadows are painted */ - for (index = g_list_last (info->windows); index; index = index->prev) { - XserverRegion shadow_clip; - - cw = (MetaCompWindow *) index->data; - shadow_clip = None; - - if (cw->picture) { -#if 0 - XFixesSetPictureClipRegion (xdisplay, info->root_buffer, - 0, 0, cw->border_clip); -#endif - if (cw->shadow) { - shadow_clip = XFixesCreateRegion (xdisplay, NULL, 0); - XFixesSubtractRegion (xdisplay, shadow_clip, cw->border_clip, - cw->border_size); - XFixesSetPictureClipRegion (xdisplay, info->root_buffer, 0, 0, - shadow_clip); - - XRenderComposite (xdisplay, PictOpOver, info->black_picture, - cw->shadow, info->root_buffer, - 0, 0, 0, 0, - cw->attrs.x + cw->shadow_dx, - cw->attrs.y + cw->shadow_dy, - cw->shadow_width, cw->shadow_height); - } - - if ((cw->opacity != (int) OPAQUE) && !(cw->alpha_pict)) { - cw->alpha_pict = solid_picture (display, screen, FALSE, - (double) cw->opacity / OPAQUE, - 0, 0, 0); - } + for (index = g_list_last (info->windows); index; index = index->prev) + { + XserverRegion shadow_clip; - XFixesIntersectRegion (xdisplay, cw->border_clip, cw->border_clip, - cw->border_size); - XFixesSetPictureClipRegion (xdisplay, info->root_buffer, 0, 0, - cw->border_clip); - - if (cw->mode == WINDOW_TRANS || cw->mode == WINDOW_ARGB) { - int x, y, wid, hei; + cw = (MetaCompWindow *) index->data; + shadow_clip = None; + + if (cw->picture) + { + if (cw->shadow) + { + shadow_clip = XFixesCreateRegion (xdisplay, NULL, 0); + XFixesSubtractRegion (xdisplay, shadow_clip, cw->border_clip, + cw->border_size); + XFixesSetPictureClipRegion (xdisplay, info->root_buffer, 0, 0, + shadow_clip); + + XRenderComposite (xdisplay, PictOpOver, info->black_picture, + cw->shadow, info->root_buffer, + 0, 0, 0, 0, + cw->attrs.x + cw->shadow_dx, + cw->attrs.y + cw->shadow_dy, + cw->shadow_width, cw->shadow_height); + } + + if ((cw->opacity != (int) OPAQUE) && !(cw->alpha_pict)) + { + cw->alpha_pict = solid_picture (display, screen, FALSE, + (double) cw->opacity / OPAQUE, + 0, 0, 0); + } + + XFixesIntersectRegion (xdisplay, cw->border_clip, cw->border_clip, + cw->border_size); + XFixesSetPictureClipRegion (xdisplay, info->root_buffer, 0, 0, + cw->border_clip); + + if (cw->mode == WINDOW_TRANS || cw->mode == WINDOW_ARGB) + { + int x, y, wid, hei; #ifdef HAVE_NAME_WINDOW_PIXMAP - x = cw->attrs.x; - y = cw->attrs.y; - wid = cw->attrs.width + cw->attrs.border_width * 2; - hei = cw->attrs.height + cw->attrs.border_width * 2; + x = cw->attrs.x; + y = cw->attrs.y; + wid = cw->attrs.width + cw->attrs.border_width * 2; + hei = cw->attrs.height + cw->attrs.border_width * 2; #else - x = cw->attrs.x + cw->attrs.border_width; - y = cw->attrs.y + cw->attrs.border_height; - wid = cw->attrs.width; - hei = cw->attrs.height; + x = cw->attrs.x + cw->attrs.border_width; + y = cw->attrs.y + cw->attrs.border_height; + wid = cw->attrs.width; + hei = cw->attrs.height; #endif - - XRenderComposite (xdisplay, PictOpOver, cw->picture, cw->alpha_pict, - info->root_buffer, 0, 0, 0, 0, - x, y, wid, hei); - } - - if (shadow_clip) { - XFixesDestroyRegion (xdisplay, shadow_clip); - } - - if (cw->border_clip) { - XFixesDestroyRegion (xdisplay, cw->border_clip); - cw->border_clip = None; - } + + XRenderComposite (xdisplay, PictOpOver, cw->picture, + cw->alpha_pict, info->root_buffer, 0, 0, 0, 0, + x, y, wid, hei); + } + + if (shadow_clip) + XFixesDestroyRegion (xdisplay, shadow_clip); + + if (cw->border_clip) + { + XFixesDestroyRegion (xdisplay, cw->border_clip); + cw->border_clip = None; + } + } + + if (cw->border_clip) + { + XFixesDestroyRegion (xdisplay, cw->border_clip); + cw->border_clip = None; + } } - - if (cw->border_clip) { - XFixesDestroyRegion (xdisplay, cw->border_clip); - cw->border_clip = None; + + if (info->root_picture != info->root_buffer) + { + XFixesSetPictureClipRegion (xdisplay, info->root_buffer, 0, 0, None); + XRenderComposite (xdisplay, PictOpSrc, info->root_buffer, None, + info->root_picture, 0, 0, 0, 0, 0, 0, + screen_width, screen_height); } - } - - if (info->root_picture != info->root_buffer) { - XFixesSetPictureClipRegion (xdisplay, info->root_buffer, 0, 0, None); - XRenderComposite (xdisplay, PictOpSrc, info->root_buffer, None, - info->root_picture, 0, 0, 0, 0, 0, 0, - screen_width, screen_height); - } } static void @@ -956,12 +985,13 @@ repair_screen (MetaScreen *screen) MetaCompScreen *info = screen->compositor_data; MetaDisplay *display = screen->display; - if (info->all_damage != None) { - paint_all (screen, info->all_damage); - XFixesDestroyRegion (display->xdisplay, info->all_damage); - info->all_damage = None; - info->clip_changed = FALSE; - } + if (info->all_damage != None) + { + paint_all (screen, info->all_damage); + XFixesDestroyRegion (display->xdisplay, info->all_damage); + info->all_damage = None; + info->clip_changed = FALSE; + } } static void @@ -969,9 +999,8 @@ repair_display (MetaDisplay *display) { GSList *screens; - for (screens = display->screens; screens; screens = screens->next) { + for (screens = display->screens; screens; screens = screens->next) repair_screen ((MetaScreen *) screens->data); - } } static void @@ -981,13 +1010,14 @@ add_damage (MetaDisplay *display, { MetaCompScreen *info = screen->compositor_data; - if (info->all_damage) { - XFixesUnionRegion (display->xdisplay, info->all_damage, - info->all_damage, damage); - XFixesDestroyRegion (display->xdisplay, damage); - } else { + if (info->all_damage) + { + XFixesUnionRegion (display->xdisplay, info->all_damage, + info->all_damage, damage); + XFixesDestroyRegion (display->xdisplay, damage); + } + else info->all_damage = damage; - } } static void @@ -997,17 +1027,20 @@ repair_win (MetaCompWindow *cw) MetaDisplay *display = screen->display; XserverRegion parts; - if (!cw->damaged) { - parts = win_extents (cw); - XDamageSubtract (display->xdisplay, cw->damage, None, None); - } else { - parts = XFixesCreateRegion (display->xdisplay, 0, 0); - XDamageSubtract (display->xdisplay, cw->damage, None, parts); - XFixesTranslateRegion (display->xdisplay, parts, - cw->attrs.x + cw->attrs.border_width, - cw->attrs.y + cw->attrs.border_width); - } - + if (!cw->damaged) + { + parts = win_extents (cw); + XDamageSubtract (display->xdisplay, cw->damage, None, None); + } + else + { + parts = XFixesCreateRegion (display->xdisplay, 0, 0); + XDamageSubtract (display->xdisplay, cw->damage, None, parts); + XFixesTranslateRegion (display->xdisplay, parts, + cw->attrs.x + cw->attrs.border_width, + cw->attrs.y + cw->attrs.border_width); + } + add_damage (display, screen, parts); cw->damaged = TRUE; } @@ -1019,57 +1052,66 @@ free_win (MetaCompWindow *cw, MetaDisplay *display = cw->screen->display; #ifdef HAVE_NAME_WINDOW_PIXMAP - if (cw->pixmap) { - XFreePixmap (display->xdisplay, cw->pixmap); - cw->pixmap = None; - } + if (cw->pixmap) + { + XFreePixmap (display->xdisplay, cw->pixmap); + cw->pixmap = None; + } #endif - if (cw->picture) { - XRenderFreePicture (display->xdisplay, cw->picture); - cw->picture = None; - } - - if (cw->shadow) { - XRenderFreePicture (display->xdisplay, cw->shadow); - cw->shadow = None; - } - - if (cw->alpha_pict) { - XRenderFreePicture (display->xdisplay, cw->alpha_pict); - cw->alpha_pict = None; - } - - if (cw->shadow_pict) { - XRenderFreePicture (display->xdisplay, cw->shadow_pict); - cw->shadow_pict = None; - } - - if (cw->border_size) { - XFixesDestroyRegion (display->xdisplay, cw->border_size); - cw->border_size = None; - } - - if (cw->border_clip) { - XFixesDestroyRegion (display->xdisplay, cw->border_clip); - cw->border_clip = None; - } - - if (cw->extents) { - XFixesDestroyRegion (display->xdisplay, cw->extents); - cw->extents = None; - } - - if (destroy) { - if (cw->damage != None) { - /* If we've got here, then the window has already been destroyed - so this will cause a BadWindow */ -/* XDamageDestroy (display->xdisplay, cw->damage); */ - cw->damage = None; + if (cw->picture) + { + XRenderFreePicture (display->xdisplay, cw->picture); + cw->picture = None; + } + + if (cw->shadow) + { + XRenderFreePicture (display->xdisplay, cw->shadow); + cw->shadow = None; + } + + if (cw->alpha_pict) + { + XRenderFreePicture (display->xdisplay, cw->alpha_pict); + cw->alpha_pict = None; + } + + if (cw->shadow_pict) + { + XRenderFreePicture (display->xdisplay, cw->shadow_pict); + cw->shadow_pict = None; } - g_free (cw); - } + if (cw->border_size) + { + XFixesDestroyRegion (display->xdisplay, cw->border_size); + cw->border_size = None; + } + + if (cw->border_clip) + { + XFixesDestroyRegion (display->xdisplay, cw->border_clip); + cw->border_clip = None; + } + + if (cw->extents) + { + XFixesDestroyRegion (display->xdisplay, cw->extents); + cw->extents = None; + } + + if (destroy) + { + if (cw->damage != None) { + /* If we've got here, then the window has already been destroyed + so this will cause a BadWindow */ + /* XDamageDestroy (display->xdisplay, cw->damage); */ + cw->damage = None; + } + + g_free (cw); + } } static void @@ -1079,9 +1121,8 @@ map_win (MetaDisplay *display, { MetaCompWindow *cw = find_window_for_screen (screen, id); - if (cw == NULL) { + if (cw == NULL) return; - } cw->attrs.map_state = IsViewable; cw->damaged = FALSE; @@ -1095,17 +1136,19 @@ unmap_win (MetaDisplay *display, MetaCompWindow *cw = find_window_for_screen (screen, id); MetaCompScreen *info = screen->compositor_data; - if (cw == NULL) { - return; - } + if (cw == NULL) + { + return; + } cw->attrs.map_state = IsUnmapped; cw->damaged = FALSE; - if (cw->extents != None) { - add_damage (display, screen, cw->extents); - cw->extents = None; - } + if (cw->extents != None) + { + add_damage (display, screen, cw->extents); + cw->extents = None; + } free_win (cw, FALSE); info->clip_changed = TRUE; @@ -1119,38 +1162,39 @@ determine_mode (MetaDisplay *display, XRenderPictFormat *format; int mode; - if (cw->alpha_pict) { - XRenderFreePicture (display->xdisplay, cw->alpha_pict); - cw->alpha_pict = None; - } + if (cw->alpha_pict) + { + XRenderFreePicture (display->xdisplay, cw->alpha_pict); + cw->alpha_pict = None; + } - if (cw->shadow_pict) { - XRenderFreePicture (display->xdisplay, cw->shadow_pict); - cw->shadow_pict = None; - } + if (cw->shadow_pict) + { + XRenderFreePicture (display->xdisplay, cw->shadow_pict); + cw->shadow_pict = None; + } - if (cw->attrs.class == InputOnly) { + if (cw->attrs.class == InputOnly) format = NULL; - } else { + else format = XRenderFindVisualFormat (display->xdisplay, cw->attrs.visual); - } - if (format && format->type == PictTypeDirect && format->direct.alphaMask) { + if (format && format->type == PictTypeDirect && format->direct.alphaMask) mode = WINDOW_ARGB; - } else if (cw->opacity != (int) OPAQUE) { + else if (cw->opacity != (int) OPAQUE) mode = WINDOW_TRANS; - } else { + else mode = WINDOW_SOLID; - } cw->mode = mode; - if (cw->extents) { - XserverRegion damage; - damage = XFixesCreateRegion (display->xdisplay, NULL, 0); - XFixesCopyRegion (display->xdisplay, damage, cw->extents); - - add_damage (display, screen, damage); - } + if (cw->extents) + { + XserverRegion damage; + damage = XFixesCreateRegion (display->xdisplay, NULL, 0); + XFixesCopyRegion (display->xdisplay, damage, cw->extents); + + add_damage (display, screen, damage); + } } static gboolean @@ -1180,19 +1224,22 @@ add_win (MetaScreen *screen, MetaCompScreen *info = screen->compositor_data; MetaCompWindow *cw = g_new0 (MetaCompWindow, 1); - if (info == NULL) { - g_warning ("Screen not managed"); - g_free (cw); - return; - } + if (info == NULL) + { + g_warning ("Screen not managed"); + g_free (cw); + return; + } cw->screen = screen; cw->id = xwindow; - if (!XGetWindowAttributes (display->xdisplay, xwindow, &cw->attrs)) { - g_warning ("Could not get attrs"); - g_free (cw); - return; - } + + if (!XGetWindowAttributes (display->xdisplay, xwindow, &cw->attrs)) + { + g_warning ("Could not get attrs"); + g_free (cw); + return; + } #ifdef HAVE_NAME_WINDOW_PIXMAP cw->pixmap = None; @@ -1201,12 +1248,11 @@ add_win (MetaScreen *screen, cw->damaged = FALSE; cw->shaped = is_shaped (display, xwindow); - if (cw->attrs.class == InputOnly) { + if (cw->attrs.class == InputOnly) cw->damage = None; - } else { + else cw->damage = XDamageCreate (display->xdisplay, xwindow, XDamageReportNonEmpty); - } cw->alpha_pict = None; cw->shadow_pict = None; @@ -1228,9 +1274,8 @@ add_win (MetaScreen *screen, info->windows = g_list_prepend (info->windows, cw); g_hash_table_insert (info->windows_by_xid, (gpointer) xwindow, cw); - if (cw->attrs.map_state == IsViewable) { + if (cw->attrs.map_state == IsViewable) map_win (display, screen, xwindow); - } } static void @@ -1238,27 +1283,28 @@ destroy_win (MetaDisplay *display, Window xwindow, gboolean gone) { + MetaScreen *screen; + MetaCompScreen *info; MetaCompWindow *cw; cw = find_window_in_display (display, xwindow); - if (cw) { - MetaScreen *screen; - MetaCompScreen *info; - - screen = cw->screen; + if (cw == NULL) + return; - if (cw->extents != None) { + screen = cw->screen; + + if (cw->extents != None) + { add_damage (display, screen, cw->extents); cw->extents = None; } - - info = screen->compositor_data; - info->windows = g_list_remove (info->windows, (gconstpointer) cw); - g_hash_table_remove (info->windows_by_xid, (gpointer) xwindow); - - free_win (cw, TRUE); - } + + info = screen->compositor_data; + info->windows = g_list_remove (info->windows, (gconstpointer) cw); + g_hash_table_remove (info->windows_by_xid, (gpointer) xwindow); + + free_win (cw, TRUE); } static void @@ -1277,33 +1323,37 @@ restack_win (MetaCompWindow *cw, next = g_list_next (sibling); previous_above = None; - if (next) { - MetaCompWindow *ncw = (MetaCompWindow *) next->data; - previous_above = ncw->id; - } + if (next) + { + MetaCompWindow *ncw = (MetaCompWindow *) next->data; + previous_above = ncw->id; + } /* If above is set to None, the window whose state was changed is on * the bottom of the stack with respect to sibling. */ - if (above == None) { - /* Insert at bottom of window stack */ - info->windows = g_list_delete_link (info->windows, sibling); - info->windows = g_list_append (info->windows, cw); - } else if (previous_above != above) { - GList *index; - - for (index = info->windows; index; index = index->next) { - MetaCompWindow *cw2 = (MetaCompWindow *) index->data; - if (cw2->id == above) { - break; - } - } - - if (index != NULL) { + if (above == None) + { + /* Insert at bottom of window stack */ info->windows = g_list_delete_link (info->windows, sibling); - info->windows = g_list_insert_before (info->windows, index, cw); + info->windows = g_list_append (info->windows, cw); + } + else if (previous_above != above) + { + GList *index; + + for (index = info->windows; index; index = index->next) { + MetaCompWindow *cw2 = (MetaCompWindow *) index->data; + if (cw2->id == above) + break; + } + + if (index != NULL) + { + info->windows = g_list_delete_link (info->windows, sibling); + info->windows = g_list_insert_before (info->windows, index, cw); + } } - } } static void @@ -1326,44 +1376,48 @@ resize_win (MetaCompWindow *cw, damage = None; damage = XFixesCreateRegion (display->xdisplay, NULL, 0); - if (cw->extents) { + if (cw->extents) XFixesCopyRegion (display->xdisplay, damage, cw->extents); - } cw->attrs.x = x; cw->attrs.y = y; - if (cw->attrs.width != width || cw->attrs.height != height) { + if (cw->attrs.width != width || cw->attrs.height != height) + { #ifdef HAVE_NAME_WINDOW_PIXMAP - if (cw->pixmap) { - XFreePixmap (display->xdisplay, cw->pixmap); - cw->pixmap = None; - } + if (cw->pixmap) + { + XFreePixmap (display->xdisplay, cw->pixmap); + cw->pixmap = None; + } #endif - if (cw->picture) { - XRenderFreePicture (display->xdisplay, cw->picture); - cw->picture = None; - } - - if (cw->shadow) { - XRenderFreePicture (display->xdisplay, cw->shadow); - cw->shadow = None; + if (cw->picture) + { + XRenderFreePicture (display->xdisplay, cw->picture); + cw->picture = None; + } + + if (cw->shadow) + { + XRenderFreePicture (display->xdisplay, cw->shadow); + cw->shadow = None; + } } - } cw->attrs.width = width; cw->attrs.height = height; cw->attrs.border_width = border_width; cw->attrs.override_redirect = override_redirect; - if (damage) { - XserverRegion extents = win_extents (cw); - - XFixesUnionRegion (display->xdisplay, damage, damage, extents); - XFixesDestroyRegion (display->xdisplay, extents); - - add_damage (display, screen, damage); - } + if (damage) + { + XserverRegion extents = win_extents (cw); + + XFixesUnionRegion (display->xdisplay, damage, damage, extents); + XFixesDestroyRegion (display->xdisplay, extents); + + add_damage (display, screen, damage); + } info->clip_changed = TRUE; } @@ -1380,20 +1434,18 @@ process_circulate_notify (MetaCompositor *compositor, GList *first; Window above; - if (!cw) { + if (!cw) return; - } screen = cw->screen; info = screen->compositor_data; first = info->windows; top = (MetaCompWindow *) first->data; - if ((event->place == PlaceOnTop) && top) { + if ((event->place == PlaceOnTop) && top) above = top->id; - } else { + else above = None; - } restack_win (cw, above); info->clip_changed = TRUE; @@ -1406,11 +1458,12 @@ process_configure_notify (MetaCompositor *compositor, MetaCompWindow *cw = find_window_in_display (compositor->display, event->window); - if (cw) { - restack_win (cw, event->above); - resize_win (cw, event->x, event->y, event->width, event->height, - event->border_width, event->override_redirect); - } + if (cw) + { + restack_win (cw, event->above); + resize_win (cw, event->x, event->y, event->width, event->height, + event->border_width, event->override_redirect); + } } static void @@ -1436,20 +1489,21 @@ process_expose (MetaCompositor *compositor, MetaScreen *screen = NULL; XRectangle rect[1]; - if (cw != NULL) { + if (cw != NULL) screen = cw->screen; - } else { - screen = meta_display_screen_for_root (compositor->display, event->window); - if (screen == NULL) { - return; + else + { + screen = meta_display_screen_for_root (compositor->display, + event->window); + if (screen == NULL) + return; } - } rect[0].x = event->x; rect[0].y = event->y; rect[0].width = event->width; rect[0].height = event->height; - + expose_area (screen, rect, 1); } @@ -1459,15 +1513,15 @@ process_unmap (MetaCompositor *compositor, { MetaCompWindow *cw; - if (event->from_configure) { - /* Ignore unmap caused by parent's resize */ - return; - } - + if (event->from_configure) + { + /* Ignore unmap caused by parent's resize */ + return; + } + cw = find_window_in_display (compositor->display, event->window); - if (cw) { + if (cw) unmap_win (compositor->display, cw->screen, event->window); - } } static void @@ -1477,9 +1531,8 @@ process_map (MetaCompositor *compositor, MetaCompWindow *cw = find_window_in_display (compositor->display, event->window); - if (cw) { + if (cw) map_win (compositor->display, cw->screen, event->window); - } } static void @@ -1489,11 +1542,10 @@ process_reparent (MetaCompositor *compositor, MetaScreen *screen; screen = meta_display_screen_for_root (compositor->display, event->parent); - if (screen != NULL) { + if (screen != NULL) add_win (screen, event->window); - } else { + else destroy_win (compositor->display, event->window, FALSE); - } } static void @@ -1505,11 +1557,11 @@ process_create (MetaCompositor *compositor, be caught by normal metacity functions */ screen = meta_display_screen_for_root (compositor->display, event->parent); - if (screen != NULL) { - if (!find_window_in_display (compositor->display, event->window)) { - add_win (screen, event->window); - } - } + if (screen == NULL) + return; + + if (!find_window_in_display (compositor->display, event->window)) + add_win (screen, event->window); } static void @@ -1525,9 +1577,9 @@ process_damage (MetaCompositor *compositor, { MetaCompWindow *cw = find_window_in_display (compositor->display, event->drawable); - if (cw == NULL) { + if (cw == NULL) return; - } + repair_win (cw); } @@ -1538,23 +1590,21 @@ process_shape (MetaCompositor *compositor, MetaCompWindow *cw = find_window_in_display (compositor->display, event->window); - if (cw == NULL) { + if (cw == NULL) return; - } - - if (event->kind == ShapeBounding) { - if (!event->shaped && cw->shaped) { - cw->shaped = FALSE; - } - - resize_win (cw, cw->attrs.x, cw->attrs.y, - event->width + event->x, event->height + event->y, - cw->attrs.border_width, cw->attrs.override_redirect); - if (event->shaped && !cw->shaped) { - cw->shaped = TRUE; + if (event->kind == ShapeBounding) + { + if (!event->shaped && cw->shaped) + cw->shaped = FALSE; + + resize_win (cw, cw->attrs.x, cw->attrs.y, + event->width + event->x, event->height + event->y, + cw->attrs.border_width, cw->attrs.override_redirect); + + if (event->shaped && !cw->shaped) + cw->shaped = TRUE; } - } } MetaCompositor * @@ -1569,13 +1619,6 @@ meta_compositor_new (MetaDisplay *display) return compositor; } -/* Should this be removed and _destroy used instead? */ -void -meta_compositor_unref (MetaCompositor *compositor) -{ - g_free (compositor); -} - void meta_compositor_add_window (MetaCompositor *compositor, Window xwindow, @@ -1602,9 +1645,8 @@ meta_compositor_manage_screen (MetaCompositor *compositor, XRenderPictFormat *visual_format; /* Check if the screen is already managed */ - if (screen->compositor_data) { + if (screen->compositor_data) return; - } gdk_error_trap_push (); /* FIXME: Use correct composite mode */ @@ -1612,11 +1654,12 @@ meta_compositor_manage_screen (MetaCompositor *compositor, CompositeRedirectManual); XSync (display->xdisplay, FALSE); - if (gdk_error_trap_pop ()) { - g_warning ("Another compositing manager is running on screen %i", - screen->number); - return; - } + if (gdk_error_trap_pop ()) + { + g_warning ("Another compositing manager is running on screen %i", + screen->number); + return; + } info = g_new0 (MetaCompScreen, 1); info->screen = screen; @@ -1624,19 +1667,21 @@ meta_compositor_manage_screen (MetaCompositor *compositor, visual_format = XRenderFindVisualFormat (display->xdisplay, DefaultVisual (display->xdisplay, screen->number)); - if (!visual_format) { - g_warning ("Cannot find visual format on screen %i", screen->number); - return; - } + if (!visual_format) + { + g_warning ("Cannot find visual format on screen %i", screen->number); + return; + } pa.subwindow_mode = IncludeInferiors; info->root_picture = XRenderCreatePicture (display->xdisplay, screen->xroot, visual_format, CPSubwindowMode, &pa); - if (info->root_picture == None) { - g_warning ("Cannot create root picture on screen %i", screen->number); - return; - } + if (info->root_picture == None) + { + g_warning ("Cannot create root picture on screen %i", screen->number); + return; + } info->root_buffer = None; info->black_picture = solid_picture (display, screen, TRUE, 1, 0, 0, 0); @@ -1656,7 +1701,6 @@ meta_compositor_manage_screen (MetaCompositor *compositor, XClearArea (display->xdisplay, screen->xroot, 0, 0, 0, 0, TRUE); - g_print ("Setting selection\n"); meta_screen_set_cm_selection (screen); screen->compositor_data = info; @@ -1671,27 +1715,25 @@ meta_compositor_unmanage_screen (MetaCompositor *compositor, GList *index; /* This screen isn't managed */ - if (screen->compositor_data == NULL) { + if (screen->compositor_data == NULL) return; - } info = screen->compositor_data; /* Destroy the windows */ - for (index = info->windows; index; index = index->next) { - MetaCompWindow *cw = (MetaCompWindow *) index->data; - free_win (cw, TRUE); - } + for (index = info->windows; index; index = index->next) + { + MetaCompWindow *cw = (MetaCompWindow *) index->data; + free_win (cw, TRUE); + } g_list_free (info->windows); g_hash_table_destroy (info->windows_by_xid); - if (info->root_picture) { + if (info->root_picture) XRenderFreePicture (display->xdisplay, info->root_picture); - } - if (info->black_picture) { + if (info->black_picture) XRenderFreePicture (display->xdisplay, info->black_picture); - } g_free (info->gaussian_map); @@ -1757,53 +1799,55 @@ meta_compositor_process_event (MetaCompositor *compositor, * enough about Metacity/X to know how else you are supposed to do it */ meta_error_trap_push (compositor->display); - switch (event->type) { - case CirculateNotify: - process_circulate_notify (compositor, (XCirculateEvent *) event); - break; - - case ConfigureNotify: - process_configure_notify (compositor, (XConfigureEvent *) event); - break; - - case Expose: - process_expose (compositor, (XExposeEvent *) event); - break; - - case UnmapNotify: - process_unmap (compositor, (XUnmapEvent *) event); - break; - - case MapNotify: - process_map (compositor, (XMapEvent *) event); - break; - - case ReparentNotify: - process_reparent (compositor, (XReparentEvent *) event); - break; - - case CreateNotify: - process_create (compositor, (XCreateWindowEvent *) event); - break; - - case DestroyNotify: - process_destroy (compositor, (XDestroyWindowEvent *) event); - break; - - default: - if (event->type == compositor->display->damage_event_base + XDamageNotify) { - process_damage (compositor, (XDamageNotifyEvent *) event); - } else if (event->type == compositor->display->shape_event_base + ShapeNotify) { - process_shape (compositor, (XShapeEvent *) event); - } else { - meta_error_trap_pop (compositor->display, FALSE); - return; + switch (event->type) + { + case CirculateNotify: + process_circulate_notify (compositor, (XCirculateEvent *) event); + break; + + case ConfigureNotify: + process_configure_notify (compositor, (XConfigureEvent *) event); + break; + + case Expose: + process_expose (compositor, (XExposeEvent *) event); + break; + + case UnmapNotify: + process_unmap (compositor, (XUnmapEvent *) event); + break; + + case MapNotify: + process_map (compositor, (XMapEvent *) event); + break; + + case ReparentNotify: + process_reparent (compositor, (XReparentEvent *) event); + break; + + case CreateNotify: + process_create (compositor, (XCreateWindowEvent *) event); + break; + + case DestroyNotify: + process_destroy (compositor, (XDestroyWindowEvent *) event); + break; + + default: + if (event->type == compositor->display->damage_event_base + XDamageNotify) + process_damage (compositor, (XDamageNotifyEvent *) event); + else if (event->type == compositor->display->shape_event_base + ShapeNotify) + process_shape (compositor, (XShapeEvent *) event); + else + { + meta_error_trap_pop (compositor->display, FALSE); + return; + } + break; } - break; - } - + meta_error_trap_pop (compositor->display, FALSE); repair_display (compositor->display); - + return; } diff --git a/src/compositor.h b/src/compositor.h index a41ce9c0..99330f24 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -28,16 +28,7 @@ #include "display.h" #include "spring-model.h" -#ifdef HAVE_COMPOSITE_EXTENSIONS -#endif - -typedef void (* MetaAnimationFinishedFunc) (gpointer data); - -/* XXX namespace me */ -void compute_window_rect (MetaWindow *window, MetaRectangle *rect); - MetaCompositor* meta_compositor_new (MetaDisplay *display); -void meta_compositor_unref (MetaCompositor *compositor); void meta_compositor_process_event (MetaCompositor *compositor, XEvent *xevent, MetaWindow *window); @@ -54,23 +45,11 @@ void meta_compositor_manage_screen (MetaCompositor *compositor, void meta_compositor_unmanage_screen (MetaCompositor *compositor, MetaScreen *screen); -#if 0 -void meta_compositor_minimize (MetaCompositor *compositor, - MetaWindow *window, - int x, - int y, - int width, - int height, - MetaAnimationFinishedFunc finished_cb, - gpointer finished_data); -#endif +void meta_compositor_set_updates (MetaCompositor *compositor, + MetaWindow *window, + gboolean updates); -void -meta_compositor_set_updates (MetaCompositor *compositor, - MetaWindow *window, - gboolean updates); -void -meta_compositor_destroy (MetaCompositor *compositor); +void meta_compositor_destroy (MetaCompositor *compositor); void meta_compositor_begin_move (MetaCompositor *compositor, MetaWindow *window, @@ -83,7 +62,5 @@ void meta_compositor_end_move (MetaCompositor *compositor, MetaWindow *window); void meta_compositor_free_window (MetaCompositor *compositor, MetaWindow *window); -void meta_compositor_free_window (MetaCompositor *compositor, - MetaWindow *window); #endif /* META_COMPOSITOR_H */ diff --git a/src/display.c b/src/display.c index 29804a3c..63e80530 100644 --- a/src/display.c +++ b/src/display.c @@ -1013,7 +1013,7 @@ meta_display_close (MetaDisplay *display, meta_display_shutdown_keys (display); if (display->compositor) - meta_compositor_unref (display->compositor); + meta_compositor_destroy (display->compositor); g_free (display); -- cgit v1.2.1