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

Fix scrolling on space workspace name indicator #833

Merged
merged 10 commits into from
Apr 22, 2024
15 changes: 14 additions & 1 deletion tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,20 @@ export class Space extends Array {
name: 'panel',
style_class: 'space-workspace-indicator',
});
workspaceIndicator.connect('button-press-event', () => Main.overview.toggle());
signals.connect(workspaceIndicator, 'button-press-event', () => Main.overview.toggle());
signals.connect(workspaceIndicator, 'scroll-event', (_actor, event) => {
let direction = event.get_scroll_direction();
switch (direction) {
case Clutter.ScrollDirection.DOWN:
spaces.selectSequenceSpace(Meta.MotionDirection.DOWN);
Navigator.getNavigator().finish();
break;
case Clutter.ScrollDirection.UP:
spaces.selectSequenceSpace(Meta.MotionDirection.UP);
Navigator.getNavigator().finish();
break;
}
});
this.workspaceIndicator = workspaceIndicator;
let workspaceLabel = new St.Label();
workspaceIndicator.add_child(workspaceLabel);
Expand Down
130 changes: 8 additions & 122 deletions topbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,130 +735,16 @@ export const WorkspaceMenu = GObject.registerClass(

if (["NORMAL", "SCROLL"].includes(this.state) &&
type === Clutter.EventType.SCROLL) {
if (!this._navigator) {
this.state = 'SCROLL';
this._navigator = Navigator.getNavigator();
Tiling.spaces.initWorkspaceSequence();
this._enterbox = new Clutter.Actor({ reactive: true });
Main.uiGroup.add_child(this._enterbox);
this._enterbox.set_position(panelBox.x, panelBox.y + panelBox.height + 20);
// eslint-disable-next-line no-undef
this._enterbox.set_size(global.screen_width, global.screen_height);
Main.layoutManager.trackChrome(this._enterbox);

this._navigator.connect('destroy', this._finishWorkspaceSelect.bind(this));

this._enterbox.connect('enter-event', () => {
this._navigator.finish();
});
}

let device = event.get_source_device();
// console.debug(`source: ${device.get_device_type()}`);
let direction = event.get_scroll_direction();
if (direction === Clutter.ScrollDirection.SMOOTH &&
device.get_device_type() !== Clutter.InputDeviceType.POINTER_DEVICE) {
this.state = 'SMOOTH';
}

if (direction === Clutter.ScrollDirection.DOWN) {
const direction = event.get_scroll_direction();
switch (direction) {
case Clutter.ScrollDirection.DOWN:
Tiling.spaces.selectSequenceSpace(Meta.MotionDirection.DOWN);
}
if (direction === Clutter.ScrollDirection.UP) {
Navigator.getNavigator().finish();
break;
case Clutter.ScrollDirection.UP:
Tiling.spaces.selectSequenceSpace(Meta.MotionDirection.UP);
}
}

if (this.state === 'SMOOTH' && type === Clutter.EventType.SCROLL &&
event.get_scroll_direction() === Clutter.ScrollDirection.SMOOTH) {
let spaces = Tiling.spaces;
let active = spaces.activeSpace;

let [, dy] = event.get_scroll_delta();
dy *= active.height * 0.05;
let t = event.get_time();
let v = -dy / (this.time - t);
// console.debug(`v ${v}, dy: ${dy}`);

let firstEvent = false;
if (!this.selected) {
firstEvent = true;
this.selected = spaces.selectedSpace;
}
let mode = Clutter.AnimationMode.EASE_IN_OUT_QUAD;
const StackPositions = Tiling.StackPositions;
const upEdge = 0.385 * active.height;
const downEdge = 0.60 * active.height;
if (dy > 0 &&
this.selected !== active &&
((this.selected.actor.y > upEdge &&
this.selected.actor.y - dy < upEdge) ||
(this.selected.actor.y - dy < StackPositions.up * active.height))
) {
dy = 0;
v = 0.1;
spaces.selectSequenceSpace(Meta.MotionDirection.UP);
this.selected = spaces.selectedSpace;
Easer.removeEase(this.selected.actor);
Easer.addEase(this.selected.actor,
{ scale_x: 0.9, scale_y: 0.9, time: Settings.prefs.animation_time, mode });
} else if (dy < 0 &&
((this.selected.actor.y < downEdge &&
this.selected.actor.y - dy > downEdge) ||
(this.selected.actor.y - dy > StackPositions.down * active.height))
) {
dy = 0;
v = 0.1;
spaces.selectSequenceSpace(Meta.MotionDirection.DOWN);
this.selected = spaces.selectedSpace;
Easer.removeEase(this.selected.actor);
Easer.addEase(this.selected.actor,
{ scale_x: 0.9, scale_y: 0.9, time: Settings.prefs.animation_time, mode });
}

this.selected.actor.y -= dy;
if (this.selected === active) {
let scale = 0.90;
let s = 1 - (1 - scale) * (this.selected.actor.y / (0.1 * this.selected.height));
s = Math.max(s, scale);
Easer.removeEase(this.selected.actor);
this.selected.actor.set_scale(s, s);
}

if (v === 0 && !firstEvent) {
// console.debug(`finish: ${this.velocity}`);
let test;
if (this.velocity > 0)
test = () => this.velocity > 0;
else
test = () => this.velocity < 0;

let y = this.selected.actor.y;
let friction = 0.5;
while (test()) {
let dy = this.velocity * 16;
y -= dy;
// console.debug(`calc target: ${dy} ${y} ${this.velocity}`);
if (this.velocity > 0)
this.velocity -= friction;
else
this.velocity += friction;
}
// console.debug(`zero: ${y/this.selected.height}`);

if (this.selected === active && y <= 0.1 * this.selected.height) {
this._navigator.finish();
return;
} else if (y > downEdge) {
spaces.selectSequenceSpace(Meta.MotionDirection.DOWN);
this.selected = spaces.selectedSpace;
} else {
spaces.selectSequenceSpace(Meta.MotionDirection.DOWN);
spaces.selectSequenceSpace(Meta.MotionDirection.UP);
}
} else {
this.time = t;
this.velocity = v;
Navigator.getNavigator().finish();
break;
}
}

Expand Down