Skip to content

Commit

Permalink
Merge branch 'fix-liveAltTab-size-scales-with-minimap' into gnome-45
Browse files Browse the repository at this point in the history
  • Loading branch information
jtaala committed Sep 30, 2023
2 parents 96b3cb2 + fd1aac1 commit e14cdb5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 14 deletions.
21 changes: 10 additions & 11 deletions liveAltTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import GObject from 'gi://GObject';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as AltTab from 'resource:///org/gnome/shell/ui/altTab.js';

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

let switcherSettings;
Expand All @@ -20,10 +20,17 @@ export function disable() {
switcherSettings = null;
}

export function liveAltTab(meta_window, space, { display, screen, binding }) {
let tabPopup = new LiveAltTab(binding.is_reversed());
tabPopup.show(binding.is_reversed(), binding.get_name(), binding.get_mask());
}

export const LiveAltTab = GObject.registerClass(
class LiveAltTab extends AltTab.WindowSwitcherPopup {
_init(reverse) {
this.reverse = reverse;
this.space = Tiling.spaces.selectedSpace;
this.monitor = Tiling.spaces.selectedSpace.monitor;
super._init();
}

Expand All @@ -45,11 +52,8 @@ export const LiveAltTab = GObject.registerClass(
}

_initialSelection(backward, actionName) {
this.space = Tiling.spaces.selectedSpace;
this.space.startAnimate();

let monitor = Tiling.spaces.selectedSpace.monitor;
let workArea = Main.layoutManager.getWorkAreaForMonitor(monitor.index);
let workArea = Main.layoutManager.getWorkAreaForMonitor(this.monitor.index);
let fog = new Clutter.Actor({
x: workArea.x, y: workArea.y,
width: workArea.width, height: workArea.height,
Expand Down Expand Up @@ -164,9 +168,4 @@ export const LiveAltTab = GObject.registerClass(
}
actor.set_scale(1, 1);
}
});

export function liveAltTab(meta_window, space, { display, screen, binding }) {
let tabPopup = new LiveAltTab(binding.is_reversed());
tabPopup.show(binding.is_reversed(), binding.get_name(), binding.get_mask());
}
});
2 changes: 1 addition & 1 deletion minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@ export class Minimap extends Array {
this.actor.destroy();
this.actor = null;
}
}
};
75 changes: 73 additions & 2 deletions patches.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import Meta from 'gi://Meta';
import Clutter from 'gi://Clutter';
import Gio from 'gi://Gio';
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import St from 'gi://St';

import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Workspace from 'resource:///org/gnome/shell/ui/workspace.js';
import * as WorkspaceThumbnail from 'resource:///org/gnome/shell/ui/workspaceThumbnail.js';
import * as WorkspaceAnimation from 'resource:///org/gnome/shell/ui/workspaceAnimation.js';
import * as AltTab from 'resource:///org/gnome/shell/ui/altTab.js';
import * as WindowManager from 'resource:///org/gnome/shell/ui/windowManager.js';
import * as WindowPreview from 'resource:///org/gnome/shell/ui/windowPreview.js';
import * as Params from 'resource:///org/gnome/shell/misc/params.js';

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

/**
Some of Gnome Shell's default behavior is really sub-optimal when using
Expand Down Expand Up @@ -246,6 +249,74 @@ export function setupOverrides() {
this._shouldShow = shouldShow;
this.notify('should-show');
});

/**
* Provides ability to set AltTab window preview sizes (which is a little harder in 45+).
* https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/altTab.js#L1002
*/
registerOverridePrototype(AltTab.WindowIcon, '_init', function(window, mode) {
const saved = getSavedPrototype(AltTab.WindowIcon, '_init');
saved.call(this, window, mode);

const WINDOW_PREVIEW_SIZE = 128;
const AppIconMode = {
THUMBNAIL_ONLY: 1,
APP_ICON_ONLY: 2,
BOTH: 3,
};ss
const APP_ICON_SIZE = 96;
const APP_ICON_SIZE_SMALL = 48;

let mutterWindow = this.window.get_compositor_private();

this._icon.destroy_all_children();

this.monitor = Tiling.spaces.selectedSpace.monitor;
let _createWindowClone = (window, size) => {
let [width, height] = window.get_size();
let scale = Math.min(1.0, size / width, size / height);
return new Clutter.Clone({
source: window,
width: width * scale,
height: height * scale,
x_align: Clutter.ActorAlign.CENTER,
y_align: Clutter.ActorAlign.CENTER,
// usual hack for the usual bug in ClutterBinLayout...
x_expand: true,
y_expand: true,
});
}

let size;
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
const mscale = Settings.prefs.minimap_scale;
// scale size based on PaperWM's minimap-scale
if (mscale > 0) {
size = Math.round(this.monitor.height * mscale);
} else {
size = WINDOW_PREVIEW_SIZE;
}
switch (mode) {
case AppIconMode.THUMBNAIL_ONLY:
this._icon.add_actor(_createWindowClone(mutterWindow, size * scaleFactor));
break;

case AppIconMode.BOTH:
this._icon.add_actor(_createWindowClone(mutterWindow, size * scaleFactor));

if (this.app) {
this._icon.add_actor(
this._createAppIcon(this.app, APP_ICON_SIZE_SMALL));
}
break;

case AppIconMode.APP_ICON_ONLY:
size = APP_ICON_SIZE;
this._icon.add_actor(this._createAppIcon(this.app, size));
}

this._icon.set_size(size * scaleFactor, size * scaleFactor);
});
}

/**
Expand Down
3 changes: 3 additions & 0 deletions stackoverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ export class StackOverlay {

// set clone parameters
let scale = Settings.prefs.minimap_scale;
if (scale <= 0) {
scale = 0.15; // original default minimap scale
}
clone.opacity = 255 * 0.95;

clone.set_scale(scale, scale);
Expand Down

0 comments on commit e14cdb5

Please sign in to comment.