Skip to content

Commit

Permalink
Ported minimap.js to ESM.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtaala committed Sep 16, 2023
1 parent 8bde99a commit 864f8d2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
3 changes: 2 additions & 1 deletion gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import Shell from 'gi://Shell';

import * as Main from 'resource:///org/gnome/shell/ui/main.js';

import { Patches, Settings, Tiling, Utils, Lib, Easer, Navigator } from './imports.js';
import { Patches, Settings, Tiling, Utils, Lib, Navigator } from './imports.js';
import { Easer } from './utils.js';

const DIRECTIONS = {
Horizontal: true,
Expand Down
3 changes: 2 additions & 1 deletion grab.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import St from 'gi://St';

import * as Main from 'resource:///org/gnome/shell/ui/main.js';

import { Settings, Utils, Tiling, Navigator, Scratch, Easer } from './imports.js';
import { Settings, Utils, Tiling, Navigator, Scratch } from './imports.js';
import { Easer } from './utils.js';

/**
* Returns a virtual pointer (i.e. mouse) device that can be used to
Expand Down
79 changes: 38 additions & 41 deletions minimap.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,53 @@
const ExtensionUtils = imports.misc.extensionUtils;
const Extension = ExtensionUtils.getCurrentExtension();
const Settings = Extension.imports.settings;
const Utils = Extension.imports.utils;
const Lib = Extension.imports.lib;
const Easer = Extension.imports.utils.easer;

const Clutter = imports.gi.Clutter;
const Main = imports.ui.main;
const St = imports.gi.St;
const Pango = imports.gi.Pango;

function calcOffset(metaWindow) {
import Clutter from 'gi://Clutter';
import St from 'gi://St';
import Pango from 'gi://Pango';

import * as Main from 'resource:///org/gnome/shell/ui/main.js';

import { Settings, Utils, Lib } from './imports.js';
import { Easer } from './utils.js';

export function calcOffset(metaWindow) {
let buffer = metaWindow.get_buffer_rect();
let frame = metaWindow.get_frame_rect();
let x_offset = frame.x - buffer.x;
let y_offset = frame.y - buffer.y;
return [x_offset, y_offset];
}

var Minimap = class Minimap extends Array {
export class Minimap extends Array {
constructor(space, monitor) {
super();
this.space = space;
this.monitor = monitor;
let actor = new St.Widget({
name: 'minimap',
style_class: 'paperwm-minimap switcher-list'
style_class: 'paperwm-minimap switcher-list',
});
this.actor = actor;
actor.height = space.height*0.20;
actor.height = space.height * 0.20;

let highlight = new St.Widget({
name: 'minimap-selection',
style_class: 'paperwm-minimap-selection item-box'
style_class: 'paperwm-minimap-selection item-box',
});
highlight.add_style_pseudo_class('selected');
this.highlight = highlight;
let label = new St.Label({style_class: 'paperwm-minimap-label'});
let label = new St.Label({ style_class: 'paperwm-minimap-label' });
label.clutter_text.ellipsize = Pango.EllipsizeMode.END;
this.label = label;

let clip = new St.Widget({name: 'container-clip'});
let clip = new St.Widget({ name: 'container-clip' });
this.clip = clip;
let container = new St.Widget({name: 'minimap-container'});
let container = new St.Widget({ name: 'minimap-container' });
this.container = container;
container.height = Math.round(space.height*Settings.prefs.minimap_scale) - Settings.prefs.window_gap;
container.height = Math.round(space.height * Settings.prefs.minimap_scale) - Settings.prefs.window_gap;

actor.add_actor(highlight);
actor.add_actor(label);
actor.add_actor(clip);
clip.add_actor(container);
clip.set_position(12 + Settings.prefs.window_gap, 12 + Math.round(1.5*Settings.prefs.window_gap));
clip.set_position(12 + Settings.prefs.window_gap, 12 + Math.round(1.5 * Settings.prefs.window_gap));
highlight.y = clip.y - 10;
Main.uiGroup.add_actor(this.actor);
this.actor.opacity = 0;
Expand All @@ -70,8 +67,8 @@ var Minimap = class Minimap extends Array {
static get [Symbol.species]() { return Array; }

reset() {
this.splice(0,this.length).forEach(c => c.forEach(x => x.destroy()))
this.createClones()
this.splice(0, this.length).forEach(c => c.forEach(x => x.destroy()));
this.createClones();
this.layout();
}

Expand Down Expand Up @@ -127,7 +124,7 @@ var Minimap = class Minimap extends Array {
Easer.addEase(this.actor,
{
opacity: 0, time, mode: Clutter.AnimationMode.EASE_OUT_EXPO,
onComplete: () => this.actor.hide()
onComplete: () => this.actor.hide(),
});
}

Expand All @@ -142,7 +139,7 @@ var Minimap = class Minimap extends Array {
let clone = new Clutter.Clone({ source: windowActor });
let container = new Clutter.Actor({
// layout_manager: new WindowCloneLayout(this),
name: "window-clone-container"
name: "window-clone-container",
});
clone.meta_window = mw;
container.clone = clone;
Expand All @@ -159,10 +156,10 @@ var Minimap = class Minimap extends Array {
let buffer = meta_window.get_buffer_rect();
let frame = meta_window.get_frame_rect();
let scale = Settings.prefs.minimap_scale;
clone.set_size(buffer.width*scale, buffer.height*scale - Settings.prefs.window_gap);
clone.set_position(((buffer.x - frame.x)*scale),
(buffer.y - frame.y)*scale);
container.set_size(frame.width*scale, frame.height*scale);
clone.set_size(buffer.width * scale, buffer.height * scale - Settings.prefs.window_gap);
clone.set_position((buffer.x - frame.x) * scale,
(buffer.y - frame.y) * scale);
container.set_size(frame.width * scale, frame.height * scale);
}

layout() {
Expand All @@ -182,13 +179,13 @@ var Minimap = class Minimap extends Array {
}

this.clip.width = Math.min(this.container.width,
this.monitor.width - this.clip.x*2 - 24);
this.actor.width = this.clip.width + this.clip.x*2;
this.monitor.width - this.clip.x * 2 - 24);
this.actor.width = this.clip.width + this.clip.x * 2;
this.clip.set_clip(0, 0, this.clip.width, this.clip.height);
this.label.set_style(`max-width: ${this.clip.width}px;`);
this.actor.set_position(
this.monitor.x + Math.floor((this.monitor.width - this.actor.width)/2),
this.monitor.y + Math.floor((this.monitor.height - this.actor.height)/2));
this.monitor.x + Math.floor((this.monitor.width - this.actor.width) / 2),
this.monitor.y + Math.floor((this.monitor.height - this.actor.height) / 2));
this.select();
}

Expand All @@ -214,12 +211,12 @@ var Minimap = class Minimap extends Array {

if (selected.x + selected.width + container.x > clip.width) {
// Align right edge of selected with the clip
container.x = clip.width - (selected.x + selected.width)
container.x = clip.width - (selected.x + selected.width);
container.x -= 500; // margin
}
if (selected.x + container.x < 0) {
// Align left edge of selected with the clip
container.x = -selected.x
container.x = -selected.x;
container.x += 500; // margin
}

Expand All @@ -231,14 +228,14 @@ var Minimap = class Minimap extends Array {

let gap = Settings.prefs.window_gap;
highlight.x = Math.round(
clip.x + container.x + selected.x - gap/2);
clip.x + container.x + selected.x - gap / 2);
highlight.y = Math.round(
clip.y + selected.y - Settings.prefs.window_gap);
highlight.set_size(Math.round(selected.width + gap),
Math.round(Math.min(selected.height, this.clip.height + gap) + gap));
Math.round(Math.min(selected.height, this.clip.height + gap) + gap));

let x = highlight.x
+ (highlight.width - label.width)/2;
let x = highlight.x +
(highlight.width - label.width) / 2;
if (x + label.width > clip.x + clip.width)
x = clip.x + clip.width - label.width + 5;
if (x < 0)
Expand All @@ -257,7 +254,7 @@ var Minimap = class Minimap extends Array {
this.destroyed = true;
this.signals.destroy();
this.signals = null;
this.splice(0,this.length);
this.splice(0, this.length);
this.actor.destroy();
this.actor = null;
}
Expand Down

0 comments on commit 864f8d2

Please sign in to comment.