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

Port to GNOME 3.34 #21

Draft
wants to merge 3 commits into
base: feat-ES6-porting
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function previewLastWindow(preview) {
// I don't know exactly the reason, but some windows
// do not get shown properly without putting this on async
// The thumbnail seems not to be ready yet
Mainloop.timeout_add(100, function () {
Mainloop.timeout_add(100, () => {
preview.window = anyWindow;
preview.show();
});
Expand All @@ -108,20 +108,20 @@ function previewLastWindow(preview) {
// the array is already filled
const windows = getMetawindows();
if (windows.length) {
windows.forEach(function (window) {
windows.forEach((window) => {
shouldBePreviewed(window);
});
}
else {

getWorkspaces().forEach(function (workspace) {
signals.tryConnectAfter(workspace, "window-added", function (workspace, window) {
getWorkspaces().forEach((workspace) => {
signals.tryConnectAfter(workspace, "window-added", (workspace, window) => {
shouldBePreviewed(window);
});
});

const TIMEOUT = 10000;
timer = Mainloop.timeout_add(TIMEOUT, function () {
timer = Mainloop.timeout_add(TIMEOUT, () => {
// In case the last window previewed could not be found, stop listening
done = true;
signals.disconnectAll();
Expand Down
113 changes: 55 additions & 58 deletions [email protected]/indicator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

// Global modules
const Lang = imports.lang;
const GObject = imports.gi.GObject;
const St = imports.gi.St;
const Util = imports.misc.util;
const PanelMenu = imports.ui.panelMenu;
Expand All @@ -26,90 +26,87 @@ const MAX_CROP_RATIO = Preview.MAX_CROP_RATIO;
const DEFAULT_ZOOM = Preview.DEFAULT_ZOOM;
const DEFAULT_CROP_RATIO = Preview.DEFAULT_CROP_RATIO;

var WindowCornerIndicator = new Lang.Class({
var WindowCornerIndicator = GObject.registerClass(class WindowCornerIndicator extends PanelMenu.Button {

Name: "WindowCornerPreview.indicator",
Extends: PanelMenu.Button,

_init: function() {
this.parent(null, "WindowCornerPreview.indicator");
},
_init() {
super._init(null, "WindowCornerPreview.indicator");
}

// Handler to turn preview on / off
_onMenuIsEnabled: function(item) {
_onMenuIsEnabled(item) {
(item.state) ? this.preview.show() : this.preview.hide();
},
}

_updateSliders: function() {
_updateSliders() {
this.menuZoom.value = this.preview.zoom;
this.menuZoomLabel.label.set_text("Monitor Zoom: " + Math.floor(this.preview.zoom * 100).toString() + "%");

this.menuLeftCrop.value = this.preview.leftCrop;
this.menuRightCrop.value = this.preview.rightCrop;
this.menuTopCrop.value = this.preview.topCrop;
this.menuBottomCrop.value = this.preview.bottomCrop;
},
}

_onZoomChanged: function(source, value) {
_onZoomChanged(source, value) {
this.preview.zoom = value;
this._updateSliders();
this.preview.emit("zoom-changed");
},
}

_onLeftCropChanged: function(source, value) {
_onLeftCropChanged(source, value) {
this.preview.leftCrop = value;
this._updateSliders();
this.preview.emit("crop-changed");
},
}

_onRightCropChanged: function(source, value) {
_onRightCropChanged(source, value) {
this.preview.rightCrop = value;
this._updateSliders();
this.preview.emit("crop-changed");
},
}

_onTopCropChanged: function(source, value) {
_onTopCropChanged(source, value) {
this.preview.topCrop = value;
this._updateSliders();
this.preview.emit("crop-changed");
},
}

_onBottomCropChanged: function(source, value) {
_onBottomCropChanged(source, value) {
this.preview.bottomCrop = value;
this._updateSliders();
this.preview.emit("crop-changed");
},
}

_onClearCropActivate: function(source) {
_onClearCropActivate(source) {
this.preview.topCrop = 0.0;
this.preview.leftCrop = 0.0;
this.preview.rightCrop = 0.0;
this.preview.bottomCrop = 0.0;
this._updateSliders();
this.preview.emit("crop-changed");
},
}

_onCornerActivate: function(source, event, corner) {
_onCornerActivate(source, event, corner) {
this.preview.corner = corner;
this._updateSliders();
this.preview.emit("corner-changed");
},
}

_onSettings: function() {
_onSettings() {
Util.trySpawnCommandLine("gnome-shell-extension-prefs [email protected]");
},
}

_onWindowActivate: function() {
_onWindowActivate() {
if (this.preview.window) {
this.preview.window.activate(global.get_current_time());
}
},
}

// Update windows list and other menus before menu pops up
_onUserTriggered: function() {
_onUserTriggered() {
this.menuIsEnabled.setToggleState(this.preview.visible);
this.menuIsEnabled.actor.reactive = this.preview.window;
this.menuActivate.actor.visible = this.preview.visible;
this.menuIsEnabled.reactive = this.preview.window;
this.menuActivate.visible = this.preview.visible;
this.menuActivate.label.set_text(
["◪", "⬕", "◩", "⬔"][this.preview.corner] + " " +
spliceTitle(this.preview.window && this.preview.window.get_title())
Expand All @@ -132,32 +129,32 @@ var WindowCornerIndicator = new Lang.Class({
);
this._updateSliders()
this.menuWindows.menu.removeAll();
getWorkspaceWindowsArray().forEach(function(workspace, i) {
getWorkspaceWindowsArray().forEach((workspace, i) => {
if (i > 0) {
this.menuWindows.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
}

// Populate window list on submenu
workspace.windows.forEach(function(window) {
workspace.windows.forEach((window) => {
let winMenuItem = new PopupMenu.PopupMenuItem(spliceTitle(window.get_title()));
winMenuItem.connect("activate", Lang.bind(this, function() {
winMenuItem.connect("activate", () => {
this.preview.window = window;
this.preview.show();
}));
});

this.menuWindows.menu.addMenuItem(winMenuItem);
}, this);
}, this);
},
});
});
}

enable: function() {
enable() {

// Add icon
this.icon = new St.Icon({
icon_name: "face-monkey-symbolic",
style_class: "system-status-icon"
});
this.actor.add_actor(this.icon);
this.add_actor(this.icon);

// Prepare Menu...

Expand All @@ -166,13 +163,13 @@ var WindowCornerIndicator = new Lang.Class({
hover: false,
reactive: true
});
this.menuIsEnabled.connect("toggled", Lang.bind(this, this._onMenuIsEnabled));
this.menuIsEnabled.connect("toggled", (...params) => this._onMenuIsEnabled(...params));
this.menu.addMenuItem(this.menuIsEnabled);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

// 1.5 Activate Mirrored window
this.menuActivate = new PopupMenu.PopupMenuItem("Activate");
this.menuActivate.connect("activate", Lang.bind(this, this._onWindowActivate));
this.menuActivate.connect("activate", (...params) => this._onWindowActivate(...params));
this.menu.addMenuItem(this.menuActivate);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

Expand All @@ -190,31 +187,31 @@ var WindowCornerIndicator = new Lang.Class({

// 3b, Zoom slider
this.menuZoom = new PopupSliderMenuItem(false, DEFAULT_ZOOM, MIN_ZOOM, MAX_ZOOM, 0.005); // slider step: 0.5%
this.menuZoom.connect("value-changed", Lang.bind(this, this._onZoomChanged));
this.menuZoom.connect("value-changed", (...params) => this._onZoomChanged(...params));
this.menu.addMenuItem(this.menuZoom);

// 4. Crop Sliders
this.menuCrop = new PopupMenu.PopupSubMenuMenuItem("Crop");
this.menu.addMenuItem(this.menuCrop);

this.menuTopCrop = new PopupSliderMenuItem("Top", DEFAULT_CROP_RATIO, 0.0, MAX_CROP_RATIO);
this.menuTopCrop.connect("value-changed", Lang.bind(this, this._onTopCropChanged));
this.menuTopCrop.connect("value-changed", (...params) => this._onTopCropChanged(...params));
this.menuCrop.menu.addMenuItem(this.menuTopCrop);

this.menuLeftCrop = new PopupSliderMenuItem("Left", DEFAULT_CROP_RATIO, 0.0, MAX_CROP_RATIO);
this.menuLeftCrop.connect("value-changed", Lang.bind(this, this._onLeftCropChanged));
this.menuLeftCrop.connect("value-changed", (...params) => this._onLeftCropChanged(...params));
this.menuCrop.menu.addMenuItem(this.menuLeftCrop);

this.menuRightCrop = new PopupSliderMenuItem("Right", DEFAULT_CROP_RATIO, 0.0, MAX_CROP_RATIO);
this.menuRightCrop.connect("value-changed", Lang.bind(this, this._onRightCropChanged));
this.menuRightCrop.connect("value-changed", (...params) => this._onRightCropChanged(...params));
this.menuCrop.menu.addMenuItem(this.menuRightCrop);

this.menuBottomCrop = new PopupSliderMenuItem("Bottom", DEFAULT_CROP_RATIO, 0.0, MAX_CROP_RATIO);
this.menuBottomCrop.connect("value-changed", Lang.bind(this, this._onBottomCropChanged));
this.menuBottomCrop.connect("value-changed", (...params) => this._onBottomCropChanged(...params));
this.menuCrop.menu.addMenuItem(this.menuBottomCrop);

this.menuClearCrop = new PopupMenu.PopupMenuItem("Clear");
this.menuClearCrop.connect("activate", Lang.bind(this, this._onClearCropActivate));
this.menuClearCrop.connect("activate", (...params) => this._onClearCropActivate(...params));
this.menuCrop.menu.addMenuItem(this.menuClearCrop);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

Expand All @@ -224,31 +221,31 @@ var WindowCornerIndicator = new Lang.Class({
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());

this.menuTopRightCorner = new PopupMenu.PopupMenuItem("");
this.menuTopRightCorner.connect("activate", Lang.bind(this, this._onCornerActivate, 1));
this.menuTopRightCorner.connect("activate", (...params) => this._onCornerActivate(...params, 1));
this.menuCorner.menu.addMenuItem(this.menuTopRightCorner);

this.menuBottomRightCorner = new PopupMenu.PopupMenuItem("");
this.menuBottomRightCorner.connect("activate", Lang.bind(this, this._onCornerActivate, 2));
this.menuBottomRightCorner.connect("activate", (...params) => this._onCornerActivate(...params, 2));
this.menuCorner.menu.addMenuItem(this.menuBottomRightCorner);

this.menuBottomLeftCorner = new PopupMenu.PopupMenuItem("");
this.menuBottomLeftCorner.connect("activate", Lang.bind(this, this._onCornerActivate, 3));
this.menuBottomLeftCorner.connect("activate", (...params) => this._onCornerActivate(...params, 3));
this.menuCorner.menu.addMenuItem(this.menuBottomLeftCorner);

this.menuTopLeftCorner = new PopupMenu.PopupMenuItem("");
this.menuTopLeftCorner.connect("activate", Lang.bind(this, this._onCornerActivate, 0));
this.menuTopLeftCorner.connect("activate", (...params) => this._onCornerActivate(...params, 0));
this.menuCorner.menu.addMenuItem(this.menuTopLeftCorner);

// 6. Settings
this.menuSettings = new PopupMenu.PopupMenuItem("Settings");
this.menuSettings.connect("activate", Lang.bind(this, this._onSettings));
this.menuSettings.connect("activate", (...params) => this._onSettings(...params));
this.menu.addMenuItem(this.menuSettings);

this.actor.connect("enter-event", Lang.bind(this, this._onUserTriggered));
this.connect("enter-event", (...params) => this._onUserTriggered(...params));

},
}

disable: function() {
disable() {
this.menu.removeAll();
}
});
2 changes: 1 addition & 1 deletion [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"settings-schema": "org.gnome.shell.extensions.window-corner-preview",
"gettext-domain": "gnome-shell-extensions",
"shell-version": [
"3.32"
"3.34"
],
"url": "https://github.com/medenagan/window-corner-preview",
"uuid": "[email protected]",
Expand Down
14 changes: 6 additions & 8 deletions [email protected]/polygnome.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
// Global modules
const Meta = imports.gi.Meta;

// This is wrapper to maintain compatibility with GNOME-Shell 3.30+ as well as
// previous versions.
var DisplayWrapper = {
getScreen: function() {
return global.screen || global.display;
getScreen() {
return global.display;
},
getWorkspaceManager: function() {
return global.screen || global.workspace_manager;
getWorkspaceManager() {
return global.workspace_manager;
},
getMonitorManager: function() {
return global.screen || Meta.MonitorManager.get();
getMonitorManager() {
return Meta.MonitorManager.get();
}
};

Expand Down
Loading