Skip to content

Commit

Permalink
Try to pass linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsheeler committed Sep 10, 2024
1 parent 17868c0 commit 5374cd0
Show file tree
Hide file tree
Showing 13 changed files with 357 additions and 414 deletions.
81 changes: 26 additions & 55 deletions src/coverflowSwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const BaseSwitcher = Switcher;
import {Preview, Placement, Direction, findUpperLeftFromCenter} from './preview.js'

const SIDE_ANGLE = 90;
const BLEND_OUT_ANGLE = 30;
const ALPHA = 1;

function appendParams(base, extra) {
Expand Down Expand Up @@ -58,13 +57,12 @@ export class CoverflowSwitcher extends BaseSwitcher {
for (let windowActor of global.get_window_actors()) {
let metaWin = windowActor.get_meta_window();
let texture = windowActor.get_texture();
let width, height;
let width, height, _;
if (texture.get_size) {
[width, height] = texture.get_size();
} else {
// TODO: Check this OK!
let preferred_size_ok;
[preferred_size_ok, width, height] = texture.get_preferred_size();
[_, width, height] = texture.get_preferred_size();
}

let scale = 1.0;
Expand All @@ -76,7 +74,7 @@ export class CoverflowSwitcher extends BaseSwitcher {

let preview = new Preview(metaWin, this, {
name: metaWin.title,
opacity: ALPHA * (!metaWin.minimized && metaWin.get_workspace() == currentWorkspace || metaWin.is_on_all_workspaces()) ? 255 : 0,
opacity: ALPHA * (!metaWin.minimized && metaWin.get_workspace() === currentWorkspace || metaWin.is_on_all_workspaces()) ? 255 : 0,
source: texture.get_size ? texture : windowActor,
reactive: true,
x: metaWin.minimized ? 0 :
Expand Down Expand Up @@ -104,17 +102,17 @@ export class CoverflowSwitcher extends BaseSwitcher {
this._previews[this._windows.indexOf(metaWin)] = preview;
}
this._allPreviews.push(preview);

this.previewActor.add_child(preview);
}
}

_usingCarousel() {
return (this._settings.switcher_looping_method == "Carousel");
return (this._settings.switcher_looping_method === "Carousel");
}

_previewNext() {
if (this._currentIndex == this._windows.length - 1) {
if (this._currentIndex === this._windows.length - 1) {
this._setCurrentIndex(0);
if (this._usingCarousel()) {
this._updatePreviews(false)
Expand All @@ -128,7 +126,7 @@ export class CoverflowSwitcher extends BaseSwitcher {
}

_previewPrevious() {
if (this._currentIndex == 0) {
if (this._currentIndex === 0) {
this._setCurrentIndex(this._windows.length-1);
if (this._usingCarousel()) {
this._updatePreviews(false)
Expand All @@ -142,43 +140,15 @@ export class CoverflowSwitcher extends BaseSwitcher {
}

_flipStack(direction) {
//this._looping = true;

let xOffset, angle;
this._updateActiveMonitor();
if (direction === Direction.TO_LEFT) {
xOffset = -this._xOffsetLeft;
angle = BLEND_OUT_ANGLE;
} else {
xOffset = this._activeMonitor.width + this._xOffsetLeft;
angle = -BLEND_OUT_ANGLE;
}

let animation_time = this._settings.animation_time * 2/3;

for (let [i, preview] of this._previews.entries()) {
this._onFlipIn(preview, i, direction);
}
}

_onFlipIn(preview, index, direction) {
let xOffsetStart, xOffsetEnd, angleStart, angleEnd;
let zeroIndexPreview = null;
this._updateActiveMonitor();

if (direction === Direction.TO_LEFT) {
xOffsetStart = this.actor.width + this._xOffsetLeft;
xOffsetEnd = this._xOffsetRight;
angleStart = -BLEND_OUT_ANGLE;
angleEnd = -SIDE_ANGLE + this._getPerspectiveCorrectionAngle(1);
} else {
xOffsetStart = -this._xOffsetLeft;
xOffsetEnd = this._xOffsetLeft;
angleStart = BLEND_OUT_ANGLE;
angleEnd = SIDE_ANGLE + this._getPerspectiveCorrectionAngle(0);
}

//let animation_time = this._settings.animation_time * 2;
let animation_time = this._settings.animation_time * 2 * (direction === Direction.TO_RIGHT ? ((index + 1) / this._previews.length) : (1 - index / this._previews.length));
this._updatePreview(index, zeroIndexPreview, preview, index, false, animation_time);
this._manager.platform.tween(preview, {
Expand All @@ -190,7 +160,7 @@ export class CoverflowSwitcher extends BaseSwitcher {
return;
}

_onFlipComplete(direction) {
_onFlipComplete(_direction) {
this._looping = false;
this._updatePreviews(false);
}
Expand Down Expand Up @@ -219,7 +189,7 @@ export class CoverflowSwitcher extends BaseSwitcher {
let pivot_point = new Graphene.Point({ x: x, y: y });
let half_length = Math.floor(this._previews.length / 2);
let pivot_index = (this._usingCarousel()) ?
half_length : this._currentIndex;
half_length : this._currentIndex;
if (toChangePivotPoint) {
if (index < pivot_index) {
let progress = pivot_index - index < 1 ? pivot_index - index : 1;
Expand Down Expand Up @@ -251,32 +221,33 @@ export class CoverflowSwitcher extends BaseSwitcher {
}

_getPerspectiveCorrectionAngle(side) {
if (this._settings.perspective_correction_method != "Adjust Angles") return 0;
if (this.num_monitors == 1) {
if (this._settings.perspective_correction_method !== "Adjust Angles") return 0;
if (this.num_monitors === 1) {
return 0;
} else if (this.num_monitors == 2) {
if (this.monitor_number == this.monitors_ltr[0].index) {
if (side == 0) return 508/1000 * 90;
} else if (this.num_monitors === 2) {
if (this.monitor_number === this.monitors_ltr[0].index) {
if (side === 0) return 508/1000 * 90;
else return 508/1000 *90;
} else {
if (side == 0) return -508/1000 * 90;
if (side === 0) return -508/1000 * 90;
else return -508/1000 * 90;
}
} else if (this.num_monitors == 3) {
if (this.monitor_number == this.monitors_ltr[0].index) {
if (side == 0) return (666)/1000 * 90;
} else if (this.num_monitors === 3) {
if (this.monitor_number === this.monitors_ltr[0].index) {
if (side === 0) return (666)/1000 * 90;
else return 750/1000 * 90;
} else if (this.monitor_number == this.monitors_ltr[1].index) {
} else if (this.monitor_number === this.monitors_ltr[1].index) {
return 0;
} else {
if (side == 0) return (-750)/1000 * 90;
if (side === 0) return (-750)/1000 * 90;
else return -666/1000 * 90;
}
}
return 0;
}

_updatePreviews(reorder_only=false) {
if (this._previews == null) return;
if (this._previews === null) return;
let half_length = Math.floor(this._previews.length / 2);
let previews = [];
for (let [i, preview] of this._previews.entries()) {
Expand All @@ -289,7 +260,7 @@ export class CoverflowSwitcher extends BaseSwitcher {

let zeroIndexPreview = null;
for (let item of previews) {
let preview = item[2];
let preview = item[2];
let i = item[0];
let idx = item[1];
let animation_time = this._getRandomTime();
Expand All @@ -303,18 +274,18 @@ export class CoverflowSwitcher extends BaseSwitcher {
}
});
}
if (zeroIndexPreview != null) zeroIndexPreview.make_bottom_layer(this.previewActor);
if (zeroIndexPreview !== null) zeroIndexPreview.make_bottom_layer(this.previewActor);
this._raiseIcons();
}

_updatePreview(idx, zeroIndexPreview, preview, i, reorder_only, animation_time) {
let half_length = Math.floor(this._previews.length / 2);
let pivot_index = (this._usingCarousel()) ?
half_length : this._currentIndex;
if (this._usingCarousel() && idx == 0) {
if (this._usingCarousel() && idx === 0) {
zeroIndexPreview = preview;
}
if (i == this._currentIndex) {
if (i === this._currentIndex) {
preview.make_top_layer(this.previewActor);
if (!reorder_only) {
this._animatePreviewToMid(preview, this._settings.animation_time);
Expand Down
18 changes: 6 additions & 12 deletions src/effects/color_effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const get_shader_source = _ => {
try {
return Shell.get_file_contents_utf8_sync(SHADER_PATH);
} catch (e) {
log(`[Coverflow Alt-Tab] error loading shader from ${SHADER_PATH}: ${e}`);
console.log(`[Coverflow Alt-Tab] error loading shader from ${SHADER_PATH}: ${e}`);
return null;
}
};
Expand Down Expand Up @@ -64,28 +64,22 @@ export const ColorEffect = new GObject.registerClass({
),
}
}, class CoverflowAltTabColorShader extends Clutter.ShaderEffect {
_init(params) {
constructor(params) {
let _color = params.color;
delete params.color;
super(params);
this._red = null;
this._green = null;
this._blue = null;
this._blend = null;

// initialize without color as a parameter

let _color = params.color;
delete params.color;

super._init(params);

// set shader source

this._source = get_shader_source();

if (this._source)
this.set_shader_source(this._source);

// set shader color

if (_color)
this.color = _color;

Expand Down Expand Up @@ -173,4 +167,4 @@ export const ColorEffect = new GObject.registerClass({
else
super.vfunc_paint_target();
}
});
});
9 changes: 5 additions & 4 deletions src/effects/glitch_effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import Shell from 'gi://Shell';
import GObject from 'gi://GObject';
import GLib from 'gi://GLib';


const SHADER_PATH = GLib.filename_from_uri(GLib.uri_resolve_relative(import.meta.url, 'glitch_effect.glsl', GLib.UriFlags.NONE))[0];

const get_shader_source = _ => {
try {
return Shell.get_file_contents_utf8_sync(SHADER_PATH);
} catch (e) {
log(`[Coverflow Alt-Tab] error loading shader from ${SHADER_PATH}: ${e}`);
console.log(`[Coverflow Alt-Tab] error loading shader from ${SHADER_PATH}: ${e}`);
return null;
}
};
Expand All @@ -30,8 +31,8 @@ const get_shader_source = _ => {
export const GlitchEffect = new GObject.registerClass({
GTypeName: "CoverflowAltTabGlitchEffect",
}, class CoverflowAltTabGlitchShader extends Clutter.ShaderEffect {
_init(params) {
super._init(params);
constructor(params) {
super(params);
this._timeOffset = Math.random() * 1000000;
// set shader source
this._source = get_shader_source();
Expand All @@ -56,4 +57,4 @@ export const GlitchEffect = new GObject.registerClass({

this.queue_repaint();
}
});
});
74 changes: 74 additions & 0 deletions src/effects/radialShader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import Shell from 'gi://Shell'
import GObject from 'gi://GObject'

const VIGNETTE_DECLARATIONS = ' \
uniform float brightness; \n\
uniform float vignette_sharpness; \n\
float rand(vec2 p) { \n\
return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453123); \n\
} \n';

const VIGNETTE_CODE = ' \
cogl_color_out.a = cogl_color_in.a; \n\
cogl_color_out.rgb = vec3(0.0, 0.0, 0.0); \n\
vec2 position = cogl_tex_coord_in[0].xy - 0.5; \n\
float t = clamp(length(1.41421 * position), 0.0, 1.0); \n\
float pixel_brightness = mix(1.0, 1.0 - vignette_sharpness, t); \n\
cogl_color_out.a *= 1.0 - pixel_brightness * brightness; \n\
cogl_color_out.a += (rand(position) - 0.5) / 100.0; \n';

export const MyRadialShaderEffect = GObject.registerClass({
Properties: {
'brightness': GObject.ParamSpec.float(
'brightness', 'brightness', 'brightness',
GObject.ParamFlags.READWRITE,
0, 1, 1),
'sharpness': GObject.ParamSpec.float(
'sharpness', 'sharpness', 'sharpness',
GObject.ParamFlags.READWRITE,
0, 1, 0),
},
}, class MyRadialShaderEffect extends Shell.GLSLEffect {
constructor(params) {
super(params);
this._brightness = undefined;
this._sharpness = undefined;

this._brightnessLocation = this.get_uniform_location('brightness');
this._sharpnessLocation = this.get_uniform_location('vignette_sharpness');

this.brightness = 1.0;
this.sharpness = 0.0;
}

vfunc_build_pipeline() {
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT,
VIGNETTE_DECLARATIONS, VIGNETTE_CODE, true);
}

get brightness() {
return this._brightness;
}

set brightness(v) {
if (this._brightness === v)
return;
this._brightness = v;
this.set_uniform_float(this._brightnessLocation,
1, [this._brightness]);
this.notify('brightness');
}

get sharpness() {
return this._sharpness;
}

set sharpness(v) {
if (this._sharpness === v)
return;
this._sharpness = v;
this.set_uniform_float(this._sharpnessLocation,
1, [this._sharpness]);
this.notify('sharpness');
}
});
8 changes: 4 additions & 4 deletions src/keybinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const Keybinder330Api = class Keybinder330Api extends AbstractKeybinder {
Main.wm.removeKeybinding(actionName + "-backward");
this._keybindingActions.delete(actionName + "-backward");
}

enable(startAppSwitcherBind, platform) {
let mode = Shell.ActionMode ? Shell.ActionMode : Shell.KeyBindingMode;

Expand Down Expand Up @@ -106,8 +106,8 @@ export const Keybinder330Api = class Keybinder330Api extends AbstractKeybinder {

_onSettingsChanged(settings, key=null) {
let mode = Shell.ActionMode ? Shell.ActionMode : Shell.KeyBindingMode;
if (key == null || key == 'bind-to-switch-applications') {

if (key === null || key === 'bind-to-switch-applications') {
if (settings.get_boolean('bind-to-switch-applications')) {
Main.wm.setCustomKeybindingHandler('switch-applications', mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, this._startAppSwitcherBind);
Expand All @@ -116,7 +116,7 @@ export const Keybinder330Api = class Keybinder330Api extends AbstractKeybinder {
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
}
}
if (key == null || key == 'bind-to-switch-windows') {
if (key === null || key === 'bind-to-switch-windows') {
if (settings.get_boolean('bind-to-switch-windows')) {
Main.wm.setCustomKeybindingHandler('switch-windows', mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, this._startAppSwitcherBind);
Expand Down
Loading

0 comments on commit 5374cd0

Please sign in to comment.