Skip to content

Commit 73b434d

Browse files
committed
Animate opacity when showing St.Widget
1 parent a31e733 commit 73b434d

File tree

6 files changed

+41
-15
lines changed

6 files changed

+41
-15
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
"**/Thumbs.db": true,
99
"node_modules": true,
1010
},
11+
"typescript.preferences.importModuleSpecifierEnding": "index",
1112
}

extension/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ export const ExtSettings = {
3838
DEFAULT_OVERVIEW_GESTURE_DIRECTION: true,
3939
};
4040

41-
export const RELOAD_DELAY = 150; // reload extension delay in ms
41+
export const RELOAD_DELAY = 150; // reload extension delay in ms
42+
export const WIGET_SHOWING_DURATION = 100; // animation duration for showing widget

extension/src/animations/arrow.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import St from '@gi-types/st';
66
import { imports } from 'gnome-shell';
77
import { registerClass } from '../../common/utils/gobject';
88
import { easeActor } from '../utils/environment';
9+
import { WIGET_SHOWING_DURATION } from '../../constants';
910

1011
const ExtMe = imports.misc.extensionUtils.getCurrentExtension();
1112
const Util = imports.misc.util;
@@ -59,6 +60,16 @@ export const ArrowIconAnimation = registerClass(
5960
this._outer_circle.scale_x = this._transition.outer_circle.from;
6061
this._outer_circle.scale_y = this._outer_circle.scale_x;
6162
this._arrow_icon.opacity = 255;
63+
64+
// animating showing widget
65+
this.opacity = 0;
66+
this.show();
67+
easeActor(this as St.Widget, {
68+
opacity: 255,
69+
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
70+
duration: WIGET_SHOWING_DURATION,
71+
});
72+
6273
this._arrow_icon.set_gicon(Gio.Icon.new_for_string(`${ExtMe.dir.get_uri()}/assets/${icon_name}`));
6374
}
6475

@@ -73,13 +84,20 @@ export const ArrowIconAnimation = registerClass(
7384
gestureEnd(duration: number, progress: number, callback: () => void) {
7485
if (this._transition === undefined) return;
7586

87+
easeActor(this as St.Widget, {
88+
opacity: 0,
89+
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
90+
duration,
91+
});
92+
7693
const translation_x = Util.lerp(this._transition.arrow.from, this._transition.arrow.end, progress);
7794
easeActor(this._arrow_icon, {
7895
translation_x,
7996
duration,
8097
mode: Clutter.AnimationMode.EASE_OUT_EXPO,
8198
onStopped: () => {
8299
callback();
100+
this.hide();
83101
this._arrow_icon.opacity = 0;
84102
this._arrow_icon.translation_x = 0;
85103
this._outer_circle.scale_x = 1;

extension/src/forwardBack.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export class ForwardBackGestureExtension implements ISubExtension {
120120
const keys = this._getClutterKeyForFocusedApp(SwipeGestureDirection.LeftToRight);
121121
this._keyboard.sendKeys(keys);
122122
}
123-
this._arrowIconAnimation.hide();
124123
});
125124
break;
126125
case AnimationState.LEFT:
@@ -132,7 +131,6 @@ export class ForwardBackGestureExtension implements ISubExtension {
132131
const keys = this._getClutterKeyForFocusedApp(SwipeGestureDirection.RightToLeft);
133132
this._keyboard.sendKeys(keys);
134133
}
135-
this._arrowIconAnimation.hide();
136134
});
137135
}
138136
}
@@ -150,8 +148,6 @@ export class ForwardBackGestureExtension implements ISubExtension {
150148
this._arrowIconAnimation.gestureBegin('arrow1-right-symbolic.svg', false);
151149
this._arrowIconAnimation.set_position(workArea.x + workArea.width - 2 * width, workArea.y + Math.round((workArea.height - height) / 2));
152150
}
153-
154-
this._arrowIconAnimation.show();
155151
}
156152

157153
_getWorkArea() {

extension/src/pinchGestures/closeWindow.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import St from '@gi-types/st';
66
import { global, imports } from 'gnome-shell';
77

88
import { PinchGestureType } from '../../common/settings';
9+
import { WIGET_SHOWING_DURATION } from '../../constants';
910
import { TouchpadPinchGesture } from '../trackers/pinchTracker';
1011
import { easeActor } from '../utils/environment';
1112
import { getVirtualKeyboard, IVirtualKeyboard } from '../utils/keyboard';
1213

1314
const Main = imports.ui.main;
1415
const Util = imports.misc.util;
1516

16-
const START_OPACITY = 0;
17+
const END_OPACITY = 0;
18+
const END_SCALE = 0.5;
1719

1820
enum CloseWindowGestureState {
1921
PINCH_IN = -1,
@@ -37,7 +39,6 @@ export class CloseWindowExtension implements ISubExtension {
3739
reactive: false,
3840
style_class: 'gie-close-window-preview',
3941
visible: false,
40-
opacity: START_OPACITY,
4142
});
4243
this._preview.set_pivot_point(0.5, 0.5);
4344
Main.layoutManager.uiGroup.add_child(this._preview);
@@ -66,13 +67,22 @@ export class CloseWindowExtension implements ISubExtension {
6667
const frame = this._focusWindow.get_frame_rect();
6768
this._preview.set_position(frame.x, frame.y);
6869
this._preview.set_size(frame.width, frame.height);
70+
71+
// animate showing widget
72+
this._preview.opacity = 0;
6973
this._preview.show();
74+
easeActor(this._preview, {
75+
opacity: 255,
76+
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
77+
duration: WIGET_SHOWING_DURATION,
78+
});
7079
}
7180

7281
gestureUpdate(_tracker: unknown, progress: number): void {
73-
progress = progress - CloseWindowGestureState.PINCH_IN;
74-
this._preview.set_scale(progress, progress);
75-
this._preview.opacity = Util.lerp(START_OPACITY, 255, progress);
82+
progress = CloseWindowGestureState.DEFAULT - progress;
83+
const scale = Util.lerp(1, END_SCALE, progress);
84+
this._preview.set_scale(scale, scale);
85+
this._preview.opacity = Util.lerp(255, END_OPACITY, progress);
7686
}
7787

7888
gestureEnd(_tracker: unknown, duration: number, progress: CloseWindowGestureState) {
@@ -97,9 +107,9 @@ export class CloseWindowExtension implements ISubExtension {
97107

98108
private _animatePreview(gestureCompleted: boolean, duration: number, callback?: () => void) {
99109
easeActor(this._preview, {
100-
opacity: gestureCompleted ? 255 : 0,
101-
scaleX: gestureCompleted ? 0 : 1,
102-
scaleY: gestureCompleted ? 0 : 1,
110+
opacity: gestureCompleted ? END_OPACITY : 255,
111+
scaleX: gestureCompleted ? END_SCALE : 1,
112+
scaleY: gestureCompleted ? END_SCALE : 1,
103113
duration,
104114
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
105115
onStopped: () => {
@@ -112,7 +122,7 @@ export class CloseWindowExtension implements ISubExtension {
112122

113123
private _gestureAnimationDone() {
114124
this._preview.hide();
115-
this._preview.opacity = START_OPACITY;
125+
this._preview.opacity = 255;
116126
this._preview.set_scale(1, 1);
117127
}
118128
}

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"settings-schema": "org.gnome.shell.extensions.gestureImprovements",
88
"url": "https://github.com/harshadgavali/gnome-gesture-improvements",
99
"uuid": "gestureImprovements@gestures",
10-
"version": 22
10+
"version": 22.5
1111
}

0 commit comments

Comments
 (0)