Skip to content

Commit

Permalink
window buttons: use single function to sync buttons visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian committed Apr 22, 2020
1 parent 5a47835 commit 6f231d4
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions [email protected]/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ var WindowButtons = class WindowButtons extends PanelExtension {
this.controls = new Buttons.WindowControls()

this.signals.connect(
Main.overview, 'showing', this._onOverviewShowing.bind(this)
Main.overview, 'showing', this._syncVisible.bind(this)
)

this.signals.connect(
Main.overview, 'hiding', this._onOverviewHiding.bind(this)
Main.overview, 'hiding', this._syncVisible.bind(this)
)

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

this.settings.connect(
Expand All @@ -95,7 +95,7 @@ var WindowButtons = class WindowButtons extends PanelExtension {

this._onPositionChange()
this._onThemeChange()
this._onOverviewHiding()
this._syncVisible()
}

get position() {
Expand Down Expand Up @@ -134,23 +134,6 @@ var WindowButtons = class WindowButtons extends PanelExtension {
}
}

_onOverviewShowing() {
this.controls.setVisible(false)
}

_onOverviewHiding() {
const focused = global.unite.focusWindow
this.controls.setVisible(focused && focused.showButtons)
}

_onFocusAppChange() {
const focused = WinTracker.focus_app

if (focused == null || focused.state != Shell.AppState.RUNNING) {
this.controls.setVisible(false)
}
}

_onLayoutChange() {
const buttons = this.settings.get('window-buttons-layout')

Expand All @@ -159,6 +142,7 @@ var WindowButtons = class WindowButtons extends PanelExtension {
}

this.controls.addButtons(buttons)
this._syncVisible()
}

_onPositionChange() {
Expand Down Expand Up @@ -190,6 +174,18 @@ var WindowButtons = class WindowButtons extends PanelExtension {
this.controls.add_style_class_name(this.theme)
}

_syncVisible() {
const overview = Main.overview.visibleTarget
const focusApp = WinTracker.focus_app || AppMenu._targetApp

if (!overview && focusApp && focusApp.state == Shell.AppState.RUNNING) {
const win = global.unite.focusWindow
this.controls.setVisible(win && win.showButtons)
} else {
this.controls.setVisible(false)
}
}

_destroy() {
this.controls.destroy()

Expand Down

0 comments on commit 6f231d4

Please sign in to comment.