From 5fa4764c989f4fc54090a6084a315fcf8a55b057 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Wed, 4 Mar 2015 12:29:53 +0100 Subject: [PATCH] Move SafeWindowClone into its own file --- docs/Makefile.am | 1 + src/InternalUtils.vala | 53 ---------------------- src/Makefile.am | 1 + src/Widgets/SafeWindowClone.vala | 75 ++++++++++++++++++++++++++++++++ src/Widgets/WindowSwitcher.vala | 9 ++-- src/WindowManager.vala | 2 +- 6 files changed, 81 insertions(+), 60 deletions(-) create mode 100644 src/Widgets/SafeWindowClone.vala diff --git a/docs/Makefile.am b/docs/Makefile.am index 845a3ea9..6ae0221d 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -33,6 +33,7 @@ gala_doc_files = \ $(top_srcdir)/src/Widgets/IconGroupContainer.vala \ $(top_srcdir)/src/Widgets/MonitorClone.vala \ $(top_srcdir)/src/Widgets/MultitaskingView.vala \ + $(top_srcdir)/src/Widgets/SafeWindowClone.vala \ $(top_srcdir)/src/Widgets/WindowClone.vala \ $(top_srcdir)/src/Widgets/WindowCloneContainer.vala \ $(top_srcdir)/src/Widgets/WindowIconActor.vala \ diff --git a/src/InternalUtils.vala b/src/InternalUtils.vala index e47393ba..704f70fc 100644 --- a/src/InternalUtils.vala +++ b/src/InternalUtils.vala @@ -28,59 +28,6 @@ namespace Gala public class InternalUtils { - /** - * A clone for a MetaWindowActor that will guard against the - * meta_window_appears_focused crash by disabling painting the clone - * as soon as it gets unavailable. - */ - public class SafeWindowClone : Clutter.Clone - { - public Window window { get; construct; } - - /** - * If set to true, the SafeWindowClone will destroy itself when the connected - * window is unmanaged - */ - public bool destroy_on_unmanaged { get; construct set; default = false; } - - /** - * Creates a new SafeWindowClone - * - * @param window The window to clone from - * @param destroy_on_unmanaged see destroy_on_unmanaged property - */ - public SafeWindowClone (Window window, bool destroy_on_unmanaged = false) - { - var actor = (WindowActor) window.get_compositor_private (); - - Object (window: window, - source: actor, - destroy_on_unmanaged: destroy_on_unmanaged); - } - - construct - { - if (source != null) - window.unmanaged.connect (reset_source); - } - - ~SafeWindowClone () - { - window.unmanaged.disconnect (reset_source); - } - - void reset_source () - { - // actually destroying the clone will be handled somewhere else (unless we were - // requested to destroy it), we just need to make sure the clone doesn't attempt - // to draw a clone of a window that has been destroyed - source = null; - - if (destroy_on_unmanaged) - destroy (); - } - } - public static bool workspaces_only_on_primary () { return Prefs.get_dynamic_workspaces () diff --git a/src/Makefile.am b/src/Makefile.am index c94f8d80..93601cb2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,6 +48,7 @@ gala_VALASOURCES = \ Widgets/IconGroupContainer.vala \ Widgets/MonitorClone.vala \ Widgets/MultitaskingView.vala \ + Widgets/SafeWindowClone.vala \ Widgets/WindowClone.vala \ Widgets/WindowCloneContainer.vala \ Widgets/WindowIconActor.vala \ diff --git a/src/Widgets/SafeWindowClone.vala b/src/Widgets/SafeWindowClone.vala new file mode 100644 index 00000000..9ae16e60 --- /dev/null +++ b/src/Widgets/SafeWindowClone.vala @@ -0,0 +1,75 @@ +// +// Copyright (C) 2014 Tom Beckmann +// +// 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 3 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, see . +// + +using Meta; + +namespace Gala +{ + /** + * A clone for a MetaWindowActor that will guard against the + * meta_window_appears_focused crash by disabling painting the clone + * as soon as it gets unavailable. + */ + public class SafeWindowClone : Clutter.Clone + { + public Window window { get; construct; } + + /** + * If set to true, the SafeWindowClone will destroy itself when the connected + * window is unmanaged + */ + public bool destroy_on_unmanaged { get; construct set; default = false; } + + /** + * Creates a new SafeWindowClone + * + * @param window The window to clone from + * @param destroy_on_unmanaged see destroy_on_unmanaged property + */ + public SafeWindowClone (Window window, bool destroy_on_unmanaged = false) + { + var actor = (WindowActor) window.get_compositor_private (); + + Object (window: window, + source: actor, + destroy_on_unmanaged: destroy_on_unmanaged); + } + + construct + { + if (source != null) + window.unmanaged.connect (reset_source); + } + + ~SafeWindowClone () + { + window.unmanaged.disconnect (reset_source); + } + + void reset_source () + { + // actually destroying the clone will be handled somewhere else (unless we were + // requested to destroy it), we just need to make sure the clone doesn't attempt + // to draw a clone of a window that has been destroyed + source = null; + + if (destroy_on_unmanaged) + destroy (); + } + } +} + diff --git a/src/Widgets/WindowSwitcher.vala b/src/Widgets/WindowSwitcher.vala index 93d257e9..da8d14cd 100644 --- a/src/Widgets/WindowSwitcher.vala +++ b/src/Widgets/WindowSwitcher.vala @@ -428,11 +428,8 @@ namespace Gala closing = true; last_switch = 0; - var screen = wm.get_screen (); - var workspace = screen.get_active_workspace (); - foreach (var actor in clone_sort_order) { - unowned InternalUtils.SafeWindowClone clone = (InternalUtils.SafeWindowClone) actor; + unowned SafeWindowClone clone = (SafeWindowClone) actor; // current window stays on top if (clone.window == current_window.window) @@ -501,7 +498,7 @@ namespace Gala actor.hide (); - var clone = new InternalUtils.SafeWindowClone (window, true); + var clone = new SafeWindowClone (window, true); clone.x = actor.x; clone.y = actor.y; @@ -526,7 +523,7 @@ namespace Gala var window_opacity = (int) Math.floor (AppearanceSettings.get_default ().alt_tab_window_opacity * 255); foreach (var actor in window_clones.get_children ()) { - unowned InternalUtils.SafeWindowClone clone = (InternalUtils.SafeWindowClone) actor; + unowned SafeWindowClone clone = (SafeWindowClone) actor; actor.save_easing_state (); actor.set_easing_duration (250); diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 86cac9bf..b329b5aa 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -1178,7 +1178,7 @@ namespace Gala // the display stack foreach (var window in docks) { if (!to_has_fullscreened) { - var clone = new InternalUtils.SafeWindowClone (window.get_meta_window ()); + var clone = new SafeWindowClone (window.get_meta_window ()); clone.x = window.x; clone.y = window.y;