Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Icons resizes to stay within window border. Takes up half the size of…
Browse files Browse the repository at this point in the history
… the smallest dimension and is bound between min and max value.

Border-radius is also adjusted so that smaller boxes do not look out of place. Most values can be adjusted through constants.
  • Loading branch information
berendkleinhaneveld committed Jan 23, 2012
1 parent ccdfa76 commit b9b7e1b
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions windowoverlay-icons/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const Workspace = imports.ui.workspace;


const WINDOWOVERLAY_ICON_SIZE = 140;
const WINDOWOVERLAY_BOX_SIZE = 160;
const WINDOWOVERLAY_BOX_SIZE_MIN = 50;
const WINDOWOVERLAY_BOX_RADIUS = 10;
const WINDOWOVERLAY_BOX_RADIUS_MIN = 5;

function injectToFunction(parent, name, func) {
let origin = parent[name];
Expand Down Expand Up @@ -40,25 +44,25 @@ function enable() {
wsWinOverInjections['_onDestroy'] = undefined;

wsWinOverInjections['_init'] = injectToFunction(Workspace.WindowOverlay.prototype, '_init', function(windowClone, parentActor) {
let icon = null;
this._icon = null;

let tracker = Shell.WindowTracker.get_default();
let app = tracker.get_window_app(windowClone.metaWindow);

if (app) {
icon = app.create_icon_texture(WINDOWOVERLAY_ICON_SIZE);
this._icon = app.create_icon_texture(WINDOWOVERLAY_ICON_SIZE);
}
if (!icon) {
icon = new St.Icon({ icon_name: 'applications-other',
icon_type: St.IconType.FULLCOLOR,
icon_size: WINDOWOVERLAY_ICON_SIZE });
if (!this._icon) {
this._icon = new St.Icon({ icon_name: 'applications-other',
icon_type: St.IconType.FULLCOLOR,
icon_size: WINDOWOVERLAY_ICON_SIZE });
}
icon.width = WINDOWOVERLAY_ICON_SIZE;
icon.height = WINDOWOVERLAY_ICON_SIZE;
this._icon.width = WINDOWOVERLAY_ICON_SIZE;
this._icon.height = WINDOWOVERLAY_ICON_SIZE;

this._applicationIconBox = new St.Bin({ style_class: 'windowoverlay-application-icon-box' });
this._applicationIconBox.set_opacity(255);
this._applicationIconBox.add_actor(icon);
this._applicationIconBox.add_actor(this._icon);

createdActors.push(this._applicationIconBox);
parentActor.add_actor(this._applicationIconBox);
Expand Down Expand Up @@ -89,12 +93,31 @@ function enable() {
});

wsWinOverInjections['updatePositions'] = injectToFunction(Workspace.WindowOverlay.prototype, 'updatePositions', function(cloneX, cloneY, cloneWidth, cloneHeight) {
let icon = this._applicationIconBox;
let iconBox = this._applicationIconBox;
let icon = this._icon;

let iconX = cloneX + (cloneWidth / 2) - (icon.width / 2);
let iconY = cloneY + (cloneHeight / 2) - (icon.height / 2);
// Calculate the size of the box to be half the size of the smallest dimension, with max and min values
let boxSize = WINDOWOVERLAY_BOX_SIZE;
if (cloneWidth < cloneHeight) {
boxSize = Math.max(Math.min(cloneWidth / 2, WINDOWOVERLAY_BOX_SIZE), WINDOWOVERLAY_BOX_SIZE_MIN);
} else {
boxSize = Math.max(Math.min(cloneHeight / 2, WINDOWOVERLAY_BOX_SIZE), WINDOWOVERLAY_BOX_SIZE_MIN);
}

// Set the size of the box and the icon
iconBox.width = Math.floor(boxSize);
iconBox.height = iconBox.width;
icon.width = Math.floor(iconBox.width * WINDOWOVERLAY_ICON_SIZE / WINDOWOVERLAY_BOX_SIZE);
icon.height = icon.width;

// Set the border radius proportional to the size of the box compared to max and min size
let borderRadius = WINDOWOVERLAY_BOX_RADIUS_MIN + ((iconBox.width - WINDOWOVERLAY_BOX_SIZE_MIN) / (WINDOWOVERLAY_BOX_SIZE - WINDOWOVERLAY_BOX_SIZE_MIN)) * (WINDOWOVERLAY_BOX_RADIUS - WINDOWOVERLAY_BOX_RADIUS_MIN);
iconBox.set_style('border-radius: ' + Math.floor(borderRadius) + 'px');

let iconBoxX = cloneX + (cloneWidth / 2) - (icon.width / 2);
let iconBoxY = cloneY + (cloneHeight / 2) - (icon.height / 2);

icon.set_position(Math.floor(iconX), Math.floor(iconY));
iconBox.set_position(Math.floor(iconBoxX), Math.floor(iconBoxY));
});

wsWinOverInjections['_onDestroy'] = injectToFunction(Workspace.WindowOverlay.prototype, '_onDestroy', function() {
Expand Down

0 comments on commit b9b7e1b

Please sign in to comment.