diff --git a/utils.js b/utils.js index 8f2873c..5ea50a4 100644 --- a/utils.js +++ b/utils.js @@ -41,7 +41,7 @@ var SCROLL_TIME = Util.SCROLL_TIME / (Util.SCROLL_TIME > 1 ? 1000 : 1); // simplify global signals and function injections handling // abstract class -var BasicHandler = class { +export var BasicHandler = class { constructor() { this._storage = new Object(); @@ -101,7 +101,7 @@ var BasicHandler = class { } // Manage global signals -var GlobalSignalsHandler = class extends BasicHandler { +export var GlobalSignalsHandler = class extends BasicHandler { _create(item) { let handlers = []; @@ -134,7 +134,7 @@ var GlobalSignalsHandler = class extends BasicHandler { * Manage function injection: both instances and prototype can be overridden * and restored */ -var InjectionsHandler = class extends BasicHandler { +export var InjectionsHandler = class extends BasicHandler { _create(item) { let object = item[0]; @@ -157,7 +157,7 @@ var InjectionsHandler = class extends BasicHandler { /** * Manage timeouts: the added timeouts have their id reset on completion */ -var TimeoutsHandler = class extends BasicHandler { +export var TimeoutsHandler = class extends BasicHandler { _create(item) { let name = item[0]; @@ -194,7 +194,7 @@ var TimeoutsHandler = class extends BasicHandler { // This is wrapper to maintain compatibility with GNOME-Shell 3.30+ as well as // previous versions. -var DisplayWrapper = { +export var DisplayWrapper = { getScreen() { return global.screen || global.display; }, @@ -209,7 +209,7 @@ var DisplayWrapper = { }; let unredirectEnabled = true -var setDisplayUnredirect = (enable) => { +export var setDisplayUnredirect = (enable) => { if (enable && !unredirectEnabled) Meta.enable_unredirect_for_display(global.display); else if (!enable && unredirectEnabled) @@ -218,7 +218,7 @@ var setDisplayUnredirect = (enable) => { unredirectEnabled = enable; }; -var getSystemMenuInfo = function() { +export var getSystemMenuInfo = function() { if (Config.PACKAGE_VERSION < '43') return { name: 'aggregateMenu', @@ -231,27 +231,27 @@ var getSystemMenuInfo = function() { }; } -var getCurrentWorkspace = function() { +export var getCurrentWorkspace = function() { return DisplayWrapper.getWorkspaceManager().get_active_workspace(); }; -var getWorkspaceByIndex = function(index) { +export var getWorkspaceByIndex = function(index) { return DisplayWrapper.getWorkspaceManager().get_workspace_by_index(index); }; -var getWorkspaceCount = function() { +export var getWorkspaceCount = function() { return DisplayWrapper.getWorkspaceManager().n_workspaces; }; -var getStageTheme = function() { +export var getStageTheme = function() { return St.ThemeContext.get_for_stage(global.stage); }; -var getScaleFactor = function() { +export var getScaleFactor = function() { return getStageTheme().scale_factor || 1; }; -var findIndex = function(array, predicate) { +export var findIndex = function(array, predicate) { if (array) { if (Array.prototype.findIndex) { return array.findIndex(predicate); @@ -267,7 +267,7 @@ var findIndex = function(array, predicate) { return -1; }; -var find = function(array, predicate) { +export var find = function(array, predicate) { let index = findIndex(array, predicate); if (index > -1) { @@ -275,7 +275,7 @@ var find = function(array, predicate) { } }; -var mergeObjects = function(main, bck) { +export var mergeObjects = function(main, bck) { for (var prop in bck) { if (!main.hasOwnProperty(prop) && bck.hasOwnProperty(prop)) { main[prop] = bck[prop]; @@ -285,7 +285,7 @@ var mergeObjects = function(main, bck) { return main; }; -var hookVfunc = function(proto, symbol, func) { +export var hookVfunc = function(proto, symbol, func) { if (!func) return if (Gi.gobject_prototype_symbol && proto[Gi.gobject_prototype_symbol]) { @@ -295,14 +295,14 @@ var hookVfunc = function(proto, symbol, func) { } }; -var getTrackedActorData = (actor) => { +export var getTrackedActorData = (actor) => { let trackedIndex = Main.layoutManager._findActor(actor); if (trackedIndex >= 0) return Main.layoutManager._trackedActors[trackedIndex] } -var getTransformedAllocation = function(actor) { +export var getTransformedAllocation = function(actor) { let extents = actor.get_transformed_extents(); let topLeft = extents.get_top_left(); let bottomRight = extents.get_bottom_right(); @@ -310,13 +310,13 @@ var getTransformedAllocation = function(actor) { return { x1: topLeft.x, x2: bottomRight.x, y1: topLeft.y, y2: bottomRight.y }; }; -var setClip = function(actor, x, y, width, height) { +export var setClip = function(actor, x, y, width, height) { actor.set_clip(0, 0, width, height); actor.set_position(x, y); actor.set_size(width, height); }; -var addKeybinding = function(key, settings, handler, modes) { +export var addKeybinding = function(key, settings, handler, modes) { if (!Main.wm._allowedKeybindings[key]) { Main.wm.addKeybinding( key, @@ -328,19 +328,19 @@ var addKeybinding = function(key, settings, handler, modes) { } }; -var removeKeybinding = function(key) { +export var removeKeybinding = function(key) { if (Main.wm._allowedKeybindings[key]) { Main.wm.removeKeybinding(key); } }; -var getrgbColor = function(color) { +export var getrgbColor = function(color) { color = typeof color === 'string' ? Clutter.color_from_string(color)[1] : color; return { red: color.red, green: color.green, blue: color.blue }; }; -var getrgbaColor = function(color, alpha, offset) { +export var getrgbaColor = function(color, alpha, offset) { if (alpha <= 0) { return 'transparent; '; } @@ -360,14 +360,14 @@ var getrgbaColor = function(color, alpha, offset) { return 'rgba(' + rgb.red + ',' + rgb.green + ',' + rgb.blue + ',' + (Math.floor(alpha * 100) * 0.01) + '); ' ; }; -var checkIfColorIsBright = function(color) { +export var checkIfColorIsBright = function(color) { let rgb = getrgbColor(color); let brightness = 0.2126 * rgb.red + 0.7152 * rgb.green + 0.0722 * rgb.blue; return brightness > 128; }; -var getMouseScrollDirection = function(event) { +export var getMouseScrollDirection = function(event) { let direction; switch (event.get_scroll_direction()) { @@ -384,7 +384,7 @@ var getMouseScrollDirection = function(event) { return direction; }; -var checkIfWindowHasTransient = function(window) { +export var checkIfWindowHasTransient = function(window) { let hasTransient; window.foreach_transient(t => !(hasTransient = true)); @@ -392,7 +392,7 @@ var checkIfWindowHasTransient = function(window) { return hasTransient; }; -var activateSiblingWindow = function(windows, direction, startWindow) { +export var activateSiblingWindow = function(windows, direction, startWindow) { let windowIndex = windows.indexOf(global.display.focus_window); let nextWindowIndex = windowIndex < 0 ? startWindow ? windows.indexOf(startWindow) : 0 : @@ -409,7 +409,7 @@ var activateSiblingWindow = function(windows, direction, startWindow) { } }; -var animateWindowOpacity = function(window, tweenOpts) { +export var animateWindowOpacity = function(window, tweenOpts) { //there currently is a mutter bug with the windowactor opacity, starting with 3.34 //https://gitlab.gnome.org/GNOME/mutter/issues/836 @@ -438,7 +438,7 @@ var animateWindowOpacity = function(window, tweenOpts) { animate(window, tweenOpts); }; -var animate = function(actor, options) { +export var animate = function(actor, options) { //the original animations used Tweener instead of Clutter animations, so we //use "time" and "delay" properties defined in seconds, as opposed to Clutter //animations "duration" and "delay" which are defined in milliseconds @@ -471,15 +471,15 @@ var animate = function(actor, options) { actor.ease.apply(actor, params); } -var isAnimating = function(actor, prop) { +export var isAnimating = function(actor, prop) { return !!actor.get_transition(prop); } -var stopAnimations = function(actor) { +export var stopAnimations = function(actor) { actor.remove_all_transitions(); } -var getIndicators = function(delegate) { +export var getIndicators = function(delegate) { if (delegate instanceof St.BoxLayout) { return delegate; } @@ -487,11 +487,11 @@ var getIndicators = function(delegate) { return delegate.indicators; } -var getPoint = function(coords) { +export var getPoint = function(coords) { return new imports.gi.Graphene.Point(coords); } -var notify = function(text, iconName, action, isTransient) { +export var notify = function(text, iconName, action, isTransient) { let source = new MessageTray.SystemNotificationSource(); let notification = new MessageTray.Notification(source, 'Dash to Panel', text); let notifyFunc = source.showNotification || source.notify; @@ -522,7 +522,7 @@ var notify = function(text, iconName, action, isTransient) { * it would be clamp to the current one in any case. * Return the amount of shift applied */ -var ensureActorVisibleInScrollView = function(scrollView, actor, fadeSize, onComplete) { +export var ensureActorVisibleInScrollView = function(scrollView, actor, fadeSize, onComplete) { let vadjustment = scrollView.vscroll.adjustment; let hadjustment = scrollView.hscroll.adjustment; let [vvalue, vlower, vupper, vstepIncrement, vpageIncrement, vpageSize] = vadjustment.get_values(); @@ -579,7 +579,7 @@ var ensureActorVisibleInScrollView = function(scrollView, actor, fadeSize, onCom /** * ColorUtils is adapted from https://github.com/micheleg/dash-to-dock */ -var ColorUtils = { +export var ColorUtils = { colorLuminance(r, g, b, dlum) { // Darken or brighten color by a fraction dlum // Each rgb value is modified by the same fraction. @@ -690,7 +690,7 @@ const MAX_CACHED_ITEMS = 1000; const BATCH_SIZE_TO_DELETE = 50; const DOMINANT_COLOR_ICON_SIZE = 64; -var DominantColorExtractor = class { +export var DominantColorExtractor = class { constructor(app){ this._app = app; @@ -880,7 +880,7 @@ var DominantColorExtractor = class { }; -var drawRoundedLine = function(cr, x, y, width, height, isRoundLeft, isRoundRight, stroke, fill) { +export var drawRoundedLine = function(cr, x, y, width, height, isRoundLeft, isRoundRight, stroke, fill) { if (height > width) { y += Math.floor((height - width) / 2.0); height = width; @@ -918,7 +918,7 @@ var drawRoundedLine = function(cr, x, y, width, height, isRoundLeft, isRoundRigh */ var checkedCommandsMap = new Map(); -function checkIfCommandExists(app) { +export function checkIfCommandExists(app) { let answer = checkedCommandsMap.get(app); if (answer === undefined) { // Command is a shell built in, use shell to call it.