Skip to content

Commit

Permalink
optimize desktop name visibility tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian committed Oct 15, 2023
1 parent cf87627 commit 0a208f0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
1 change: 0 additions & 1 deletion unite@hardpixel.eu/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const DesktopLabel = GObject.registerClass(

setVisible(visible) {
this.container.visible = visible
Main.panel.statusArea.uniteAppMenu.visible = !visible
}
}
)
Expand Down
42 changes: 39 additions & 3 deletions unite@hardpixel.eu/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ class DesktopName extends Handlers.Feature {
this.signals = new Handlers.Signals()
this.settings = new Handlers.Settings()
this.label = new Buttons.DesktopLabel()
this.starting = []

this.signals.connect(
Main.overview, 'showing', this._syncVisible.bind(this)
Expand All @@ -526,11 +527,11 @@ class DesktopName extends Handlers.Feature {
)

this.signals.connect(
AppSystem, 'app-state-changed', this._syncVisible.bind(this)
AppSystem, 'app-state-changed', this._onAppStateChanged.bind(this)
)

this.signals.connect(
WinTracker, 'notify::focus-app', this._syncVisible.bind(this)
WinTracker, 'notify::focus-app', this._onFocusAppChanged.bind(this)
)

this.settings.connect(
Expand All @@ -545,9 +546,44 @@ class DesktopName extends Handlers.Feature {
this._syncVisible()
}

_onAppStateChanged(appSys, app) {
const state = app.state

if (state != Shell.AppState.STARTING) {
this.starting = this.starting.filter(item => item != app)
} else if (state == Shell.AppState.STARTING) {
this.starting.push(app)
}

this._syncVisible()
}

_onFocusAppChanged() {
if (!WinTracker.focus_app) {
if (global.stage.key_focus != null) return
}

this._syncVisible()
}

_findFocusedApp() {
const focused = WinTracker.focus_app
const workspace = global.workspace_manager.get_active_workspace()

if (focused && focused.is_on_workspace(workspace))
return focused

for (let i = 0; i < this.starting.length; i++) {
if (this.starting[i].is_on_workspace(workspace))
return this.starting[i]
}

return null
}

_syncVisible() {
const overview = Main.overview.visibleTarget
const focusApp = WinTracker.focus_app
const focusApp = this._findFocusedApp()

this.label.setVisible(!overview && focusApp == null)
}
Expand Down

0 comments on commit 0a208f0

Please sign in to comment.