Move SafeWindowClone into its own file

This commit is contained in:
Rico Tzschichholz 2015-03-04 12:29:53 +01:00
parent ebaa88ed2e
commit 5fa4764c98
6 changed files with 81 additions and 60 deletions

View File

@ -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 \

View File

@ -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 ()

View File

@ -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 \

View File

@ -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 <http://www.gnu.org/licenses/>.
//
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 ();
}
}
}

View File

@ -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);

View File

@ -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;