Skip to content

Commit

Permalink
Merge pull request #476 from fredcw/master
Browse files Browse the repository at this point in the history
[email protected]: Fix bug for mint version 20.3 and earlier.
  • Loading branch information
claudiux authored Aug 2, 2023
2 parents 6fd881d + abffea6 commit a97da37
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 55 deletions.
123 changes: 123 additions & 0 deletions [email protected]/files/[email protected]/5.4/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*const St = imports.gi.St;
const Lang = imports.lang;
const Main = imports.ui.main;*/
const Clutter = imports.gi.Clutter;
const Settings = imports.ui.settings;
const Tweener = imports.ui.tweener;
const Meta = imports.gi.Meta;

let beginGrabOpId;
let endGrabOpId;
let settings;

// globally unique strings, set in init()
let tweenOpacity;
let originalOpacity;
// (nerdy note: we could have used the same string for both purposes!
// but that'd be needlessly confusing)

// opacity getter and setter for Tweener
function getWindowOpacity(window, params, extra) {
return window.get_opacity();
}

function setWindowOpacity(window, value, params, extra) {
window.set_opacity(value);
}

function init(metadata)
{
settings = new SettingsHandler(metadata.uuid);

// globally unique strings:
tweenOpacity = "tween_opacity@" + metadata.uuid;
originalOpacity = "original_opacity@" + metadata.uuid;

// tell Tweener to call our set/get functions instead of setting opacity directly
Tweener.registerSpecialProperty(tweenOpacity, getWindowOpacity, setWindowOpacity);
}

function SettingsHandler(uuid) {
this._init(uuid);
}

SettingsHandler.prototype = {
_init: function(uuid) {
this.settings = new Settings.ExtensionSettings(this, uuid);
this.settings.bindProperty(Settings.BindingDirection.IN, "opacity", "opacity", function(){});
this.settings.bindProperty(Settings.BindingDirection.IN, "beginTime", "beginTime", function(){});
this.settings.bindProperty(Settings.BindingDirection.IN, "beginEffect", "beginEffect", function(){});
this.settings.bindProperty(Settings.BindingDirection.IN, "endTime", "endTime", function(){});
this.settings.bindProperty(Settings.BindingDirection.IN, "endEffect", "endEffect", function(){});
}
}

// onStart and onComplete handlers for Tweener
function windowSaveOriginalOpacity() {
if (!(originalOpacity in this))
this[originalOpacity] = this.get_opacity();
}

function windowDeleteOriginalOpacity() {
delete this[originalOpacity];
}

// window grab handler
function onBeginGrabOp(display, screen, window, op) {
if ((op == Meta.GrabOp.MOVING) || (op == Meta.GrabOp.KEYBOARD_MOVING) ||
(op == Meta.GrabOp.RESIZING_E) || (op == Meta.GrabOp.RESIZING_N) ||
(op == Meta.GrabOp.RESIZING_NE) || (op == Meta.GrabOp.RESIZING_NW) ||
(op == Meta.GrabOp.RESIZING_S) || (op == Meta.GrabOp.RESIZING_SE) ||
(op == Meta.GrabOp.RESIZING_SW) || (op == Meta.GrabOp.RESIZING_W) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_E) || (op == Meta.GrabOp.KEYBOARD_RESIZING_N) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_NE) || (op == Meta.GrabOp.KEYBOARD_RESIZING_NW) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_S) || (op == Meta.GrabOp.KEYBOARD_RESIZING_SE) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_SW) || (op == Meta.GrabOp.KEYBOARD_RESIZING_W)||
(op == Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN))
{
// change opacity according to user's preference
Tweener.addTween(window, {
[tweenOpacity]: settings.opacity,
time: settings.beginTime/1000,
transition: settings.beginEffect,
onStart: windowSaveOriginalOpacity,
});
}
}

// window release handler
function onEndGrabOp(display, screen, window, op) {
if (!window || !(originalOpacity in window)) return; // releasing a window we haven't touched

if ((op == Meta.GrabOp.MOVING) || (op == Meta.GrabOp.KEYBOARD_MOVING) ||
(op == Meta.GrabOp.RESIZING_E) || (op == Meta.GrabOp.RESIZING_N) ||
(op == Meta.GrabOp.RESIZING_NE) || (op == Meta.GrabOp.RESIZING_NW) ||
(op == Meta.GrabOp.RESIZING_S) || (op == Meta.GrabOp.RESIZING_SE) ||
(op == Meta.GrabOp.RESIZING_SW) || (op == Meta.GrabOp.RESIZING_W) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_E) || (op == Meta.GrabOp.KEYBOARD_RESIZING_N) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_NE) || (op == Meta.GrabOp.KEYBOARD_RESIZING_NW) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_S) || (op == Meta.GrabOp.KEYBOARD_RESIZING_SE) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_SW) || (op == Meta.GrabOp.KEYBOARD_RESIZING_W)||
(op == Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN))
{
// restore opacity to what it was before
Tweener.addTween(window, {
[tweenOpacity]: window[originalOpacity],
time: settings.endTime/1000,
transition: settings.endEffect,
onComplete: windowDeleteOriginalOpacity,
});
}
}

function enable()
{
beginGrabOpId = global.display.connect('grab-op-begin', onBeginGrabOp);
endGrabOpId = global.display.connect('grab-op-end', onEndGrabOp);
}

function disable()
{
global.display.disconnect(beginGrabOpId);
global.display.disconnect(endGrabOpId);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"opacity": {
"type": "scale",
"description": "Opacity",
"min": 20,
"max": 255,
"step": 10,
"default": 100
},

"sep1": {
"type": "separator"
},

"h1": {
"type": "header",
"description": "Start of Drag"
},

"beginTime": {
"type": "spinbutton",
"description": "Transition time",
"min": 0,
"max": 2000,
"step": 50,
"units": "milliseconds",
"default": 100
},

"beginEffect": {
"type": "tween",
"description": "Effect",
"default": "easeOutSine"
},

"sep2": {
"type": "separator"
},

"h2": {
"type": "header",
"description": "End of Drag"
},

"endTime": {
"type": "spinbutton",
"description": "Transition time",
"min": 0,
"max": 2000,
"step": 50,
"units": "milliseconds",
"default": 100
},

"endEffect": {
"type": "tween",
"description": "Effect",
"default": "easeInSine"
}
}
93 changes: 39 additions & 54 deletions [email protected]/files/[email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,9 @@ let beginGrabOpId;
let endGrabOpId;
let settings;

// globally unique strings, set in init()
let tweenOpacity;
let originalOpacity;
// (nerdy note: we could have used the same string for both purposes!
// but that'd be needlessly confusing)

// opacity getter and setter for Tweener
function getWindowOpacity(window, params, extra) {
return window.get_opacity();
}

function setWindowOpacity(window, value, params, extra) {
window.set_opacity(value);
}

function init(metadata)
{
settings = new SettingsHandler(metadata.uuid);

// globally unique strings:
tweenOpacity = "tween_opacity@" + metadata.uuid;
originalOpacity = "original_opacity@" + metadata.uuid;

// tell Tweener to call our set/get functions instead of setting opacity directly
Tweener.registerSpecialProperty(tweenOpacity, getWindowOpacity, setWindowOpacity);
}

function SettingsHandler(uuid) {
Expand All @@ -52,18 +30,9 @@ SettingsHandler.prototype = {
}
}

// onStart and onComplete handlers for Tweener
function windowSaveOriginalOpacity() {
if (!(originalOpacity in this))
this[originalOpacity] = this.get_opacity();
}

function windowDeleteOriginalOpacity() {
delete this[originalOpacity];
}

// window grab handler
function onBeginGrabOp(display, screen, window, op) {
function onBeginGrabOp(display, screen, window, op) {
let actor = window.get_compositor_private();
if (!actor) { return; }
if ((op == Meta.GrabOp.MOVING) || (op == Meta.GrabOp.KEYBOARD_MOVING) ||
(op == Meta.GrabOp.RESIZING_E) || (op == Meta.GrabOp.RESIZING_N) ||
(op == Meta.GrabOp.RESIZING_NE) || (op == Meta.GrabOp.RESIZING_NW) ||
Expand All @@ -74,21 +43,18 @@ function onBeginGrabOp(display, screen, window, op) {
(op == Meta.GrabOp.KEYBOARD_RESIZING_S) || (op == Meta.GrabOp.KEYBOARD_RESIZING_SE) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_SW) || (op == Meta.GrabOp.KEYBOARD_RESIZING_W)||
(op == Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN))
{
// change opacity according to user's preference
Tweener.addTween(window, {
[tweenOpacity]: settings.opacity,
time: settings.beginTime/1000,
transition: settings.beginEffect,
onStart: windowSaveOriginalOpacity,
});
{
Tweener.addTween(actor, {
opacity: settings.opacity,
time: settings.beginTime/1000,
transition: settings.beginEffect });
}
}

// window release handler
function onEndGrabOp(display, screen, window, op) {
if (!(originalOpacity in window)) return; // releasing a window we haven't touched

function onEndGrabOp(display, screen, window, op) {
let actor = window.get_compositor_private();
if (!actor) { return; }
//if ((op == Meta.GrabOp.MOVING) || (op == Meta.GrabOp.KEYBOARD_MOVING))
if ((op == Meta.GrabOp.MOVING) || (op == Meta.GrabOp.KEYBOARD_MOVING) ||
(op == Meta.GrabOp.RESIZING_E) || (op == Meta.GrabOp.RESIZING_N) ||
(op == Meta.GrabOp.RESIZING_NE) || (op == Meta.GrabOp.RESIZING_NW) ||
Expand All @@ -99,17 +65,36 @@ function onEndGrabOp(display, screen, window, op) {
(op == Meta.GrabOp.KEYBOARD_RESIZING_S) || (op == Meta.GrabOp.KEYBOARD_RESIZING_SE) ||
(op == Meta.GrabOp.KEYBOARD_RESIZING_SW) || (op == Meta.GrabOp.KEYBOARD_RESIZING_W)||
(op == Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN))
{
// restore opacity to what it was before
Tweener.addTween(window, {
[tweenOpacity]: window[originalOpacity],
time: settings.endTime/1000,
transition: settings.endEffect,
onComplete: windowDeleteOriginalOpacity,
});
{
Tweener.addTween(actor, {
opacity: 255,
time: settings.endTime/1000,
transition: settings.endEffect });
}
}

/*
function onBeginGrabOp(display, screen, window, op) {
let compositor = window.get_compositor_private();
Tweener.addTween(compositor, {
opacity: settings.opacity,
time: settings.beginTime/1000,
transition: settings.beginEffect
});
}
*/

/*
function onEndGrabOp(display, screen, window, op) {
let compositor = window.get_compositor_private();
Tweener.addTween(compositor, {
opacity: 255,
time: settings.endTime/1000,
transition: settings.endEffect
});
}
*/

function enable()
{
beginGrabOpId = global.display.connect('grab-op-begin', onBeginGrabOp);
Expand Down
3 changes: 2 additions & 1 deletion [email protected]/files/[email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"2.2",
"2.4"
],
"url": "https://github.com/AnishN/Cinnamon-Extensions.git",
"url": "https://github.com/AnishN/Cinnamon-Extensions.git",
"version": "1.0",
"description": "Fade out the current window that the user is resizing or dragging.",
"uuid": "[email protected]"
}

0 comments on commit a97da37

Please sign in to comment.