diff options
Diffstat (limited to 'extensions/44/vertical-workspaces/lib/workspaceThumbnail.js')
-rw-r--r-- | extensions/44/vertical-workspaces/lib/workspaceThumbnail.js | 248 |
1 files changed, 125 insertions, 123 deletions
diff --git a/extensions/44/vertical-workspaces/lib/workspaceThumbnail.js b/extensions/44/vertical-workspaces/lib/workspaceThumbnail.js index d0bc206..844c224 100644 --- a/extensions/44/vertical-workspaces/lib/workspaceThumbnail.js +++ b/extensions/44/vertical-workspaces/lib/workspaceThumbnail.js @@ -10,56 +10,90 @@ 'use strict'; -const { GLib, Clutter, Graphene, Meta, Shell, St } = imports.gi; +const Clutter = imports.gi.Clutter; +const Gio = imports.gi.Gio; +const GLib = imports.gi.GLib; +const Meta = imports.gi.Meta; +const Shell = imports.gi.Shell; +const St = imports.gi.St; + +const AppDisplay = imports.ui.appDisplay; +const Background = imports.ui.background; const DND = imports.ui.dnd; const Main = imports.ui.main; -const Background = imports.ui.background; +const OverviewControls = imports.ui.overviewControls; const WorkspaceThumbnail = imports.ui.workspaceThumbnail; + +let Me; +let opt; + const ThumbnailState = WorkspaceThumbnail.ThumbnailState; +const ControlsState = OverviewControls.ControlsState; -const ControlsState = imports.ui.overviewControls.ControlsState; +const WORKSPACE_CUT_SIZE = 10; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); +var WorkspaceThumbnailModule = class { + constructor(me) { + Me = me; + opt = Me.opt; -// gettext -const _ = Me.imports.lib.settings._; + this._firstActivation = true; + this.moduleEnabled = false; + this._overrides = null; + } -const _Util = Me.imports.lib.util; -const shellVersion = _Util.shellVersion; + cleanGlobals() { + Me = null; + opt = null; + } -let _overrides; + update(reset) { + this.moduleEnabled = true; + const conflict = false; -const WORKSPACE_CUT_SIZE = 10; -const _originalMaxThumbnailScale = WorkspaceThumbnail.MAX_THUMBNAIL_SCALE; + reset = reset || !this.moduleEnabled || conflict; -let opt = null; + // don't touch the original code if module disabled + if (reset && !this._firstActivation) { + this._disableModule(); + } else if (!reset) { + this._firstActivation = false; + this._activateModule(); + } + if (reset && this._firstActivation) + console.debug(' WorkspaceThumbnailModule - Keeping untouched'); + } -function update(reset = false) { - if (_overrides) - _overrides.removeAll(); + _activateModule() { + if (!this._overrides) + this._overrides = new Me.Util.Overrides(); + if (!this._originalMaxThumbnailScale) + this._originalMaxThumbnailScale = WorkspaceThumbnail.MAX_THUMBNAIL_SCALE; - if (reset) { - if (_originalMaxThumbnailScale) - WorkspaceThumbnail.MAX_THUMBNAIL_SCALE = _originalMaxThumbnailScale; - _overrides = null; - opt = null; - return; - } + // don't limit max thumbnail scale for other clients than overview, specifically AATWS. + WorkspaceThumbnail.MAX_THUMBNAIL_SCALE = 1; + // WorkspaceThumbnail.ThumbnailsBox._MAX_THUMBNAIL_SCALE = 1; + + this._overrides.addOverride('WorkspaceThumbnail', WorkspaceThumbnail.WorkspaceThumbnail.prototype, WorkspaceThumbnailCommon); + this._overrides.addOverride('ThumbnailsBoxCommon', WorkspaceThumbnail.ThumbnailsBox.prototype, ThumbnailsBoxCommon); - opt = Me.imports.lib.settings.opt; - _overrides = new _Util.Overrides(); + // replacing opt.ORIENTATION local constant with boxOrientation internal variable allows external customers such as the AATWS extension to control the box orientation. + Main.overview._overview.controls._thumbnailsBox._boxOrientation = opt.ORIENTATION; + + console.debug(' WorkspaceThumbnailModule - Activated'); + } - // don't limit max thumbnail scale for other clients than overview, for example AATWS. - WorkspaceThumbnail.MAX_THUMBNAIL_SCALE = 1; + _disableModule() { + if (this._overrides) + this._overrides.removeAll(); + this._overrides = null; - _overrides.addOverride('WorkspaceThumbnail', WorkspaceThumbnail.WorkspaceThumbnail.prototype, WorkspaceThumbnailCommon); - _overrides.addOverride('ThumbnailsBoxCommon', WorkspaceThumbnail.ThumbnailsBox.prototype, ThumbnailsBoxCommon); + WorkspaceThumbnail.MAX_THUMBNAIL_SCALE = this._originalMaxThumbnailScale; - // replacing opt.ORIENTATION local constant with boxOrientation internal variable allows external customers such as the AATWS extension to control the box orientation. - Main.overview._overview.controls._thumbnailsBox._boxOrientation = opt.ORIENTATION; -} + console.debug(' WorkspaceThumbnailModule - Disabled'); + } +}; const WorkspaceThumbnailCommon = { // injection to _init() @@ -70,6 +104,8 @@ const WorkspaceThumbnailCommon = { // unless border is removed if (opt.SHOW_WS_TMB_BG) this.add_style_class_name('ws-tmb-labeled'); + else + this.add_style_class_name('ws-tmb-transparent'); // add workspace thumbnails labels if enabled if (opt.SHOW_WST_LABELS) { // 0 - disable @@ -77,7 +113,7 @@ const WorkspaceThumbnailCommon = { const wsIndex = this.metaWorkspace.index(); let label = `${wsIndex + 1}`; if (opt.SHOW_WST_LABELS === 2) { // 2 - index + workspace name - const settings = ExtensionUtils.getSettings('org.gnome.desktop.wm.preferences'); + const settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.wm.preferences' }); const wsLabels = settings.get_strv('workspace-names'); if (wsLabels.length > wsIndex && wsLabels[wsIndex]) label += `: ${wsLabels[wsIndex]}`; @@ -129,7 +165,9 @@ const WorkspaceThumbnailCommon = { } }); this._nWindowsConId = this.metaWorkspace.connect('notify::n-windows', () => { - // wait for new information + if (this._updateLabelTimeout) + return; + // wait for new data this._updateLabelTimeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 250, () => { const newLabel = getLabel(); this._wsLabel.text = newLabel; @@ -168,7 +206,7 @@ const WorkspaceThumbnailCommon = { closeButton.opacity = 255; if (!Meta.prefs_get_dynamic_workspaces() || (Meta.prefs_get_dynamic_workspaces() && global.workspace_manager.get_n_workspaces() - 1 !== this.metaWorkspace.index())) { // color the button red if ready to react on clicks - if (opt.CLOSE_WS_BUTTON_MODE < 3 || (opt.CLOSE_WS_BUTTON_MODE === 3 && _Util.isCtrlPressed())) + if (opt.CLOSE_WS_BUTTON_MODE < 3 || (opt.CLOSE_WS_BUTTON_MODE === 3 && Me.Util.isCtrlPressed())) closeButton.add_style_class_name('workspace-close-button-hover'); } }); @@ -220,12 +258,6 @@ const WorkspaceThumbnailCommon = { this._viewport.set_child_below_sibling(this._bgManager.backgroundActor, null); - this.connect('destroy', () => { - if (this._bgManager) - this._bgManager.destroy(); - this._bgManager = null; - }); - // full brightness of the thumbnail bg draws unnecessary attention // there is a grey bg under the wallpaper this._bgManager.backgroundActor.opacity = 220; @@ -256,7 +288,7 @@ const WorkspaceThumbnailCommon = { this._lastCloseClickTime = Date.now(); return; } - } else if (opt.CLOSE_WS_BUTTON_MODE === 3 && !_Util.isCtrlPressed()) { + } else if (opt.CLOSE_WS_BUTTON_MODE === 3 && !Me.Util.isCtrlPressed()) { return; } @@ -335,7 +367,7 @@ const WorkspaceThumbnailCommon = { if (!source.app && source.shellWorkspaceLaunch) return DND.DragMotionResult.COPY_DROP; - if (source instanceof imports.ui.appDisplay.FolderIcon) + if (source instanceof AppDisplay.FolderIcon) return DND.DragMotionResult.COPY_DROP; @@ -369,8 +401,8 @@ const WorkspaceThumbnailCommon = { timestamp: time, }); return true; - } else if (source instanceof imports.ui.appDisplay.FolderIcon) { - if (shellVersion >= 44) { + } else if (source instanceof AppDisplay.FolderIcon) { + if (Me.shellVersion >= 44) { for (let app of source.view._apps) { // const app = Shell.AppSystem.get_default().lookup_app(id); app.open_new_window(this.metaWorkspace.index()); @@ -419,7 +451,7 @@ const ThumbnailsBoxCommon = { if (!source.metaWindow && (!source.app || !source.app.can_open_new_window()) && (source.app || !source.shellWorkspaceLaunch) && - !(source instanceof imports.ui.appDisplay.FolderIcon)) + !(source instanceof AppDisplay.FolderIcon)) return false; @@ -448,8 +480,8 @@ const ThumbnailsBoxCommon = { workspace: newWorkspaceIndex, timestamp: time, }); - } else if (source instanceof imports.ui.appDisplay.FolderIcon) { - if (shellVersion >= 44) { + } else if (source instanceof AppDisplay.FolderIcon) { + if (Me.shellVersion >= 44) { for (let app of source.view._apps) { // const app = Shell.AppSystem.get_default().lookup_app(id); app.open_new_window(newWorkspaceIndex); @@ -495,7 +527,7 @@ const ThumbnailsBoxCommon = { if (!source.metaWindow && (!source.app || !source.app.can_open_new_window()) && (source.app || !source.shellWorkspaceLaunch) && - source !== Main.xdndHandler && !(source instanceof imports.ui.appDisplay.FolderIcon)) + source !== Main.xdndHandler && !(source instanceof AppDisplay.FolderIcon)) return DND.DragMotionResult.CONTINUE; const rtl = Clutter.get_default_text_direction() === Clutter.TextDirection.RTL; @@ -551,18 +583,18 @@ const ThumbnailsBoxCommon = { return ThumbnailsBoxHorizontal._withinWorkspace.bind(this)(...args); }, - get_preferred_custom_width(...args) { + vfunc_get_preferred_width(...args) { if (this._boxOrientation) - return ThumbnailsBoxVertical.get_preferred_custom_width.bind(this)(...args); + return ThumbnailsBoxVertical.vfunc_get_preferred_width.bind(this)(...args); else - return ThumbnailsBoxHorizontal.get_preferred_custom_width.bind(this)(...args); + return ThumbnailsBoxHorizontal.vfunc_get_preferred_width.bind(this)(...args); }, - get_preferred_custom_height(...args) { + vfunc_get_preferred_height(...args) { if (this._boxOrientation) - return ThumbnailsBoxVertical.get_preferred_custom_height.bind(this)(...args); + return ThumbnailsBoxVertical.vfunc_get_preferred_height.bind(this)(...args); else - return ThumbnailsBoxHorizontal.get_preferred_custom_height.bind(this)(...args); + return ThumbnailsBoxHorizontal.vfunc_get_preferred_height.bind(this)(...args); }, vfunc_allocate(...args) { @@ -632,14 +664,9 @@ const ThumbnailsBoxVertical = { return y > workspaceY1 && y <= workspaceY2; }, - // vfunc_get_preferred_width: function(forHeight) { - // override of this vfunc doesn't work for some reason (tested on Ubuntu and Fedora), it's not reachable - get_preferred_custom_width(forHeight) { - if (!this.visible) - return [0, 0]; - - if (forHeight === -1) - return this.get_preferred_custom_height(forHeight); + vfunc_get_preferred_width(forHeight) { + if (forHeight < 10) + return [this._porthole.width, this._porthole.width]; let themeNode = this.get_theme_node(); @@ -652,19 +679,14 @@ const ThumbnailsBoxVertical = { const avail = forHeight - totalSpacing; let scale = (avail / nWorkspaces) / this._porthole.height; - // scale = Math.min(scale, opt.MAX_THUMBNAIL_SCALE); const width = Math.round(this._porthole.width * scale); return themeNode.adjust_preferred_height(width, width); }, - get_preferred_custom_height(_forWidth) { - if (!this.visible) - return [0, 0]; - - // Note that for getPreferredHeight/Width we cheat a bit and skip propagating - // the size request to our children because we know how big they are and know - // that the actors aren't depending on the virtual functions being called. + vfunc_get_preferred_height(forWidth) { + if (forWidth < 10) + return [0, this._porthole.height]; let themeNode = this.get_theme_node(); let spacing = themeNode.get_length('spacing'); @@ -674,15 +696,14 @@ const ThumbnailsBoxVertical = { let totalSpacing = (nWorkspaces - 3) * spacing; const ratio = this._porthole.width / this._porthole.height; - const tmbHeight = themeNode.adjust_for_width(_forWidth) / ratio; + const tmbHeight = themeNode.adjust_for_width(forWidth) / ratio; const naturalheight = this._thumbnails.reduce((accumulator, thumbnail/* , index*/) => { const progress = 1 - thumbnail.collapse_fraction; const height = tmbHeight * progress; return accumulator + height; }, 0); - - return themeNode.adjust_preferred_width(totalSpacing, naturalheight); + return themeNode.adjust_preferred_width(totalSpacing, Math.round(naturalheight)); }, // removes extra space (extraWidth in the original function), we need the box as accurate as possible @@ -759,16 +780,11 @@ const ThumbnailsBoxVertical = { this._dropPlaceholder.allocate_preferred_size( ...this._dropPlaceholder.get_position()); - if (shellVersion >= 44) { - const laters = global.compositor.get_laters(); - laters.add(Meta.LaterType.BEFORE_REDRAW, () => { - this._dropPlaceholder.hide(); - }); - } else { - Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => { - this._dropPlaceholder.hide(); - }); - } + const laterFunc = () => this._dropPlaceholder.hide(); + if (Meta.later_add) + Meta.later_add(Meta.LaterType.BEFORE_REDRAW, laterFunc); + else + global.compositor.get_laters().add(Meta.LaterType.BEFORE_REDRAW, laterFunc); } let childBox = new Clutter.ActorBox(); @@ -796,16 +812,11 @@ const ThumbnailsBoxVertical = { this._dropPlaceholder.allocate(childBox); - if (shellVersion >= 44) { - const laters = global.compositor.get_laters(); - laters.add(Meta.LaterType.BEFORE_REDRAW, () => { - this._dropPlaceholder.show(); - }); - } else { - Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => { - this._dropPlaceholder.show(); - }); - } + const laterFunc = () => this._dropPlaceholder.show(); + if (Meta.later_add) + Meta.later_add(Meta.LaterType.BEFORE_REDRAW, laterFunc); + else + global.compositor.get_laters().add(Meta.LaterType.BEFORE_REDRAW, laterFunc); y += placeholderHeight + spacing; } @@ -925,7 +936,10 @@ const ThumbnailsBoxHorizontal = { return x > workspaceX1 && x <= workspaceX2; }, - get_preferred_custom_height(forWidth) { + vfunc_get_preferred_height(forWidth) { + if (forWidth < 10) + return [this._porthole.height, this._porthole.height]; + let themeNode = this.get_theme_node(); forWidth = themeNode.adjust_for_width(forWidth); @@ -937,18 +951,15 @@ const ThumbnailsBoxHorizontal = { const avail = forWidth - totalSpacing; let scale = (avail / nWorkspaces) / this._porthole.width; - // scale = Math.min(scale, opt.MAX_THUMBNAIL_SCALE); const height = Math.round(this._porthole.height * scale); + return themeNode.adjust_preferred_height(height, height); }, - get_preferred_custom_width(_forHeight) { - // Note that for getPreferredHeight/Width we cheat a bit and skip propagating - // the size request to our children because we know how big they are and know - // that the actors aren't depending on the virtual functions being called. - if (!this.visible) - return [0, 0]; + vfunc_get_preferred_width(forHeight) { + if (forHeight < 10) + return [0, this._porthole.width]; let themeNode = this.get_theme_node(); @@ -959,13 +970,14 @@ const ThumbnailsBoxHorizontal = { const ratio = this._porthole.height / this._porthole.width; - const tmbWidth = themeNode.adjust_for_height(_forHeight) / ratio; + const tmbWidth = themeNode.adjust_for_height(forHeight) / ratio; const naturalWidth = this._thumbnails.reduce((accumulator, thumbnail) => { const progress = 1 - thumbnail.collapse_fraction; const width = tmbWidth * progress; return accumulator + width; }, 0); + return themeNode.adjust_preferred_width(totalSpacing, naturalWidth); }, @@ -1041,16 +1053,11 @@ const ThumbnailsBoxHorizontal = { this._dropPlaceholder.allocate_preferred_size( ...this._dropPlaceholder.get_position()); - if (shellVersion >= 44) { - const laters = global.compositor.get_laters(); - laters.add(Meta.LaterType.BEFORE_REDRAW, () => { - this._dropPlaceholder.hide(); - }); - } else { - Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => { - this._dropPlaceholder.hide(); - }); - } + const laterFunc = () => this._dropPlaceholder.hide(); + if (Meta.later_add) + Meta.later_add(Meta.LaterType.BEFORE_REDRAW, laterFunc); + else + global.compositor.get_laters().add(Meta.LaterType.BEFORE_REDRAW, laterFunc); } let childBox = new Clutter.ActorBox(); @@ -1078,16 +1085,11 @@ const ThumbnailsBoxHorizontal = { this._dropPlaceholder.allocate(childBox); - if (shellVersion >= 44) { - const laters = global.compositor.get_laters(); - laters.add(Meta.LaterType.BEFORE_REDRAW, () => { - this._dropPlaceholder.show(); - }); - } else { - Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => { - this._dropPlaceholder.show(); - }); - } + const laterFunc = () => this._dropPlaceholder.show(); + if (Meta.later_add) + Meta.later_add(Meta.LaterType.BEFORE_REDRAW, laterFunc); + else + global.compositor.get_laters().add(Meta.LaterType.BEFORE_REDRAW, laterFunc); x += placeholderWidth + spacing; } |