Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WorkspaceInsertThumb: Code style fixes #1533

Merged
merged 1 commit into from Feb 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
208 changes: 97 additions & 111 deletions src/Widgets/WorkspaceInsertThumb.vala
@@ -1,126 +1,112 @@
//
// 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 Clutter;
using Meta;

namespace Gala {
public class WorkspaceInsertThumb : Actor {
public const int EXPAND_DELAY = 300;

public int workspace_index { get; construct set; }
public bool expanded { get; set; default = false; }
public int delay { get; set; default = EXPAND_DELAY; }

uint expand_timeout = 0;

public WorkspaceInsertThumb (int workspace_index) {
Object (workspace_index: workspace_index);

var scale = InternalUtils.get_ui_scaling_factor ();
width = IconGroupContainer.SPACING * scale;
height = IconGroupContainer.GROUP_WIDTH * scale;
y = (IconGroupContainer.GROUP_WIDTH * scale - IconGroupContainer.SPACING * scale) / 2;
opacity = 0;
set_pivot_point (0.5f, 0.5f);
reactive = true;
x_align = Clutter.ActorAlign.CENTER;

var drop = new DragDropAction (DragDropActionType.DESTINATION, "multitaskingview-window");
drop.crossed.connect ((target, hovered) => {
if (!Prefs.get_dynamic_workspaces () && (target != null && target is WindowClone))
return;

if (!hovered) {
if (expand_timeout != 0) {
Source.remove (expand_timeout);
expand_timeout = 0;
}

transform (false);
} else
expand_timeout = Timeout.add (delay, expand);
});

add_action (drop);
}
/*
* Copyright 2014 Tom Beckmann
* Copyright 2023 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/

public class Gala.WorkspaceInsertThumb : Clutter.Actor {
public const int EXPAND_DELAY = 300;

public int workspace_index { get; construct set; }
public bool expanded { get; set; default = false; }
public int delay { get; set; default = EXPAND_DELAY; }

uint expand_timeout = 0;

public WorkspaceInsertThumb (int workspace_index) {
Object (workspace_index: workspace_index);

var scale = InternalUtils.get_ui_scaling_factor ();
width = IconGroupContainer.SPACING * scale;
height = IconGroupContainer.GROUP_WIDTH * scale;
y = (IconGroupContainer.GROUP_WIDTH * scale - IconGroupContainer.SPACING * scale) / 2;
opacity = 0;
set_pivot_point (0.5f, 0.5f);
reactive = true;
x_align = Clutter.ActorAlign.CENTER;

var drop = new DragDropAction (DragDropActionType.DESTINATION, "multitaskingview-window");
drop.crossed.connect ((target, hovered) => {
if (!Meta.Prefs.get_dynamic_workspaces () && (target != null && target is WindowClone)) {
return;
}

public void set_window_thumb (Window window) {
destroy_all_children ();
if (!hovered) {
if (expand_timeout != 0) {
Source.remove (expand_timeout);
expand_timeout = 0;
}

var scale = InternalUtils.get_ui_scaling_factor ();
var icon = new WindowIcon (window, IconGroupContainer.GROUP_WIDTH, scale) {
x = IconGroupContainer.SPACING,
x_align = ActorAlign.CENTER
};
add_child (icon);
}
transform (false);
} else {
expand_timeout = Timeout.add (delay, expand);
}
});

bool expand () {
expand_timeout = 0;
add_action (drop);
}

transform (true);
public void set_window_thumb (Meta.Window window) {
destroy_all_children ();

return false;
}
var scale = InternalUtils.get_ui_scaling_factor ();
var icon = new WindowIcon (window, IconGroupContainer.GROUP_WIDTH, scale) {
x = IconGroupContainer.SPACING,
x_align = Clutter.ActorAlign.CENTER
};
add_child (icon);
}

void transform (bool expand) {
save_easing_state ();
set_easing_mode (AnimationMode.EASE_OUT_QUAD);
set_easing_duration (200);

var scale = InternalUtils.get_ui_scaling_factor ();
if (!expand) {
remove_transition ("pulse");
opacity = 0;
width = IconGroupContainer.SPACING * scale;
expanded = false;
} else {
add_pulse_animation ();
opacity = 200;
width = IconGroupContainer.GROUP_WIDTH * scale + IconGroupContainer.SPACING * 2;
expanded = true;
}
private bool expand () {
expand_timeout = 0;

transform (true);

return Source.REMOVE;
}

private new void transform (bool expand) {
save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
set_easing_duration (200);

restore_easing_state ();
var scale = InternalUtils.get_ui_scaling_factor ();
if (!expand) {
remove_transition ("pulse");
opacity = 0;
width = IconGroupContainer.SPACING * scale;
expanded = false;
} else {
add_pulse_animation ();
opacity = 200;
width = IconGroupContainer.GROUP_WIDTH * scale + IconGroupContainer.SPACING * 2;
expanded = true;
}

void add_pulse_animation () {
var transition = new TransitionGroup () {
duration = 800,
auto_reverse = true,
repeat_count = -1,
progress_mode = AnimationMode.LINEAR
};
restore_easing_state ();
}

var scale_x_transition = new PropertyTransition ("scale-x");
scale_x_transition.set_from_value (0.8);
scale_x_transition.set_to_value (1.1);
scale_x_transition.auto_reverse = true;
private void add_pulse_animation () {
var transition = new Clutter.TransitionGroup () {
duration = 800,
auto_reverse = true,
repeat_count = -1,
progress_mode = Clutter.AnimationMode.LINEAR
};

var scale_y_transition = new PropertyTransition ("scale-y");
scale_y_transition.set_from_value (0.8);
scale_y_transition.set_to_value (1.1);
scale_y_transition.auto_reverse = true;
var scale_x_transition = new Clutter.PropertyTransition ("scale-x");
scale_x_transition.set_from_value (0.8);
scale_x_transition.set_to_value (1.1);
scale_x_transition.auto_reverse = true;

transition.add_transition (scale_x_transition);
transition.add_transition (scale_y_transition);
var scale_y_transition = new Clutter.PropertyTransition ("scale-y");
scale_y_transition.set_from_value (0.8);
scale_y_transition.set_to_value (1.1);
scale_y_transition.auto_reverse = true;

add_transition ("pulse", transition);
}
transition.add_transition (scale_x_transition);
transition.add_transition (scale_y_transition);

add_transition ("pulse", transition);
}
}