mirror of
https://github.com/elementary/gala.git
synced 2024-09-11 07:05:30 +03:00
workspacethumb: use a new DnD action class to fix various problems with the clutter one
This commit is contained in:
parent
86e789323d
commit
1e7ab1d307
@ -66,6 +66,7 @@ ensure_vala_version("0.16.1" MINIMUM)
|
||||
include(ValaPrecompile)
|
||||
vala_precompile(VALA_C
|
||||
src/DBus.vala
|
||||
src/DragDropAction.vala
|
||||
src/Main.vala
|
||||
src/Plugin.vala
|
||||
src/Settings.vala
|
||||
|
@ -35,77 +35,68 @@ namespace Gala
|
||||
set_from_pixbuf (Utils.get_icon_for_window (window, WorkspaceThumb.APP_ICON_SIZE));
|
||||
} catch (Error e) { warning (e.message); }
|
||||
|
||||
var action = new DragAction ();
|
||||
action.drag_begin.connect (drag_begin);
|
||||
action.drag_end.connect (drag_end);
|
||||
var action = new DragDropAction (DragDropActionType.SOURCE, "app-icon");
|
||||
action.started.connect (drag_started);
|
||||
action.finished.connect (drag_finished);
|
||||
action.canceled.connect (drag_failed);
|
||||
|
||||
add_action_with_name ("drag", action);
|
||||
reactive = true;
|
||||
}
|
||||
|
||||
void drag_end (Actor actor, float x, float y, ModifierType modifier)
|
||||
void drag_failed ()
|
||||
{
|
||||
var action = actor.get_action ("drag") as DragAction;
|
||||
Actor handle = null;
|
||||
if (action != null)
|
||||
handle = action.drag_handle;
|
||||
if (WorkspaceThumb.destination == null) {
|
||||
float ax, ay;
|
||||
actor.get_parent ().animate (AnimationMode.LINEAR, 150, opacity:255);
|
||||
actor.get_transformed_position (out ax, out ay);
|
||||
handle.animate (AnimationMode.EASE_OUT_BOUNCE, 250, x:ax, y:ay)
|
||||
.completed.connect (() => {
|
||||
if (handle != null)
|
||||
handle.destroy ();
|
||||
actor.opacity = 255;
|
||||
});
|
||||
} else {
|
||||
WorkspaceThumb old = actor.get_parent ().get_parent () as WorkspaceThumb;
|
||||
actor.get_parent ().remove_child (actor);
|
||||
actor.opacity = 255;
|
||||
|
||||
var icons = (WorkspaceThumb.destination as WorkspaceThumb).icons;
|
||||
var wallpaper = (WorkspaceThumb.destination as WorkspaceThumb).wallpaper;
|
||||
|
||||
icons.add_child (actor);
|
||||
var action = get_action ("drag") as DragDropAction;
|
||||
|
||||
// get all the windows that belong to this app, if possible
|
||||
if (app != null && app.get_xids ().length > 1) {
|
||||
var wins = window.get_workspace ().list_windows ();
|
||||
var xids = app.get_xids ();
|
||||
for (var i = 0; i < xids.length; i++) {
|
||||
foreach (var win in wins) {
|
||||
if (xids.index (i) == (uint32)win.get_xwindow ())
|
||||
win.change_workspace ((WorkspaceThumb.destination as WorkspaceThumb).workspace);
|
||||
}
|
||||
float ax, ay;
|
||||
get_transformed_position (out ax, out ay);
|
||||
action.handle.animate (AnimationMode.EASE_OUT_BOUNCE, 250, x:ax, y:ay).
|
||||
completed.connect (() => {
|
||||
action.handle.destroy ();
|
||||
opacity = 255;
|
||||
});
|
||||
}
|
||||
|
||||
void drag_finished (Actor destination)
|
||||
{
|
||||
var action = get_action ("drag") as DragDropAction;
|
||||
action.handle.destroy ();
|
||||
|
||||
WorkspaceThumb old = get_parent ().get_parent () as WorkspaceThumb;
|
||||
get_parent ().remove_child (this);
|
||||
opacity = 255;
|
||||
|
||||
var icons = (destination as WorkspaceThumb).icons;
|
||||
var wallpaper = (destination as WorkspaceThumb).wallpaper;
|
||||
|
||||
icons.add_child (this);
|
||||
|
||||
// get all the windows that belong to this app, if possible
|
||||
if (app != null && app.get_xids ().length > 1) {
|
||||
var wins = window.get_workspace ().list_windows ();
|
||||
var xids = app.get_xids ();
|
||||
for (var i = 0; i < xids.length; i++) {
|
||||
foreach (var win in wins) {
|
||||
if (xids.index (i) == (uint32)win.get_xwindow ())
|
||||
win.change_workspace ((destination as WorkspaceThumb).workspace);
|
||||
}
|
||||
} else
|
||||
window.change_workspace ((WorkspaceThumb.destination as WorkspaceThumb).workspace);
|
||||
|
||||
if (handle != null)
|
||||
handle.destroy ();
|
||||
|
||||
if (old != null)
|
||||
old.icons.animate (AnimationMode.LINEAR, 100, x:Math.floorf (old.wallpaper.x + old.wallpaper.width / 2 - old.icons.width / 2));
|
||||
icons.animate (AnimationMode.LINEAR, 100, x:Math.floorf (wallpaper.x + wallpaper.width / 2 - icons.width / 2));
|
||||
}
|
||||
|
||||
WorkspaceThumb.destination = null;
|
||||
}
|
||||
} else
|
||||
window.change_workspace ((destination as WorkspaceThumb).workspace);
|
||||
|
||||
if (old != null)
|
||||
old.icons.animate (AnimationMode.LINEAR, 100, x:Math.floorf (old.wallpaper.x + old.wallpaper.width / 2 - old.icons.width / 2));
|
||||
icons.animate (AnimationMode.LINEAR, 100, x:Math.floorf (wallpaper.x + wallpaper.width / 2 - icons.width / 2));
|
||||
}
|
||||
|
||||
void drag_begin (Actor actor, float x, float y, ModifierType modifier)
|
||||
Clutter.Actor drag_started ()
|
||||
{
|
||||
actor.opacity = 0;
|
||||
opacity = 0;
|
||||
|
||||
float ax, ay;
|
||||
actor.get_transformed_position (out ax, out ay);
|
||||
var handle = new Clone (this);
|
||||
|
||||
var handle = new Clone (actor);
|
||||
handle.set_position (ax, ay);
|
||||
|
||||
Compositor.get_stage_for_screen (window.get_screen ()).add_child (handle);
|
||||
WorkspaceThumb.destination = null;
|
||||
(actor.get_action ("drag") as DragAction).drag_handle = handle;
|
||||
get_stage ().add_child (handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,10 +22,6 @@ namespace Gala
|
||||
{
|
||||
public class WorkspaceThumb : Clutter.Actor
|
||||
{
|
||||
|
||||
//target for DnD
|
||||
internal static Actor? destination = null;
|
||||
|
||||
static const int INDICATOR_BORDER = 5;
|
||||
internal static const int APP_ICON_SIZE = 32;
|
||||
static const float THUMBNAIL_HEIGHT = 80.0f;
|
||||
@ -175,10 +171,8 @@ namespace Gala
|
||||
canvas.set_size ((int)plus.width, (int)plus.height);
|
||||
}
|
||||
|
||||
add_action_with_name ("drop", new DropAction ());
|
||||
(get_action ("drop") as DropAction).over_in.connect (over_in);
|
||||
(get_action ("drop") as DropAction).over_out.connect (over_out);
|
||||
(get_action ("drop") as DropAction).drop.connect (drop);
|
||||
add_action_with_name ("drop", new DragDropAction (DragDropActionType.DESTINATION, "app-icon"));
|
||||
(get_action ("drop") as DragDropAction).crossed.connect (crossed);
|
||||
|
||||
check_last_workspace ();
|
||||
|
||||
@ -230,29 +224,17 @@ namespace Gala
|
||||
Cogl.Path.stroke ();
|
||||
}
|
||||
|
||||
void over_in (Actor actor)
|
||||
void crossed (bool over)
|
||||
{
|
||||
if (indicator.opacity != 255)
|
||||
indicator.animate (AnimationMode.LINEAR, 100, opacity:200);
|
||||
}
|
||||
void over_out (Actor actor)
|
||||
{
|
||||
if (indicator.opacity != 255)
|
||||
indicator.animate (AnimationMode.LINEAR, 100, opacity:0);
|
||||
|
||||
//when draggin, the leave event isn't emitted
|
||||
// when draggin, the leave event isn't emitted
|
||||
if (close_button.visible)
|
||||
hide_close_button ();
|
||||
}
|
||||
void drop (Actor actor, float x, float y)
|
||||
{
|
||||
float ax, ay;
|
||||
actor.transform_stage_point (x, y, out ax, out ay);
|
||||
|
||||
destination = actor;
|
||||
|
||||
if (indicator.opacity != 255)
|
||||
indicator.animate (AnimationMode.LINEAR, 100, opacity:0);
|
||||
|
||||
// if we're the active workspace, don't show any changes
|
||||
if (indicator.opacity == 255)
|
||||
return;
|
||||
|
||||
indicator.animate (AnimationMode.LINEAR, 100, opacity: over ? 200 : 0);
|
||||
}
|
||||
|
||||
~WorkspaceThumb ()
|
||||
|
Loading…
Reference in New Issue
Block a user