Skip to content

Commit

Permalink
move focused app tracking to window manager
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian committed Dec 8, 2023
1 parent beae475 commit 0775aad
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
6 changes: 5 additions & 1 deletion unite@hardpixel.eu/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export default class UniteExtension extends Extension {
enable() {
global.unite = this

this.windowManager = new WindowManager()
this.panelManager = new PanelManager()
this.layoutManager = new LayoutManager()
this.windowManager = new WindowManager()

Handlers.resetGtkStyles()

Expand All @@ -34,6 +34,10 @@ export default class UniteExtension extends Extension {
global.unite = null
}

get focusApp() {
return this.windowManager.focusApp
}

get focusWindow() {
return this.windowManager.focusWindow
}
Expand Down
57 changes: 13 additions & 44 deletions unite@hardpixel.eu/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class AppmenuButton extends Handlers.Feature {
this.timeouts = new Handlers.Timeouts()
this.button = new Buttons.AppmenuLabel()
this.tooltip = new St.Label({ visible: false, style_class: 'dash-label' })

this.focused = null
this.starting = []

this.signals.connect(
Main.overview, 'showing', this._syncState.bind(this)
Expand All @@ -38,7 +36,7 @@ class AppmenuButton extends Handlers.Feature {
)

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

this.signals.connect(
Expand Down Expand Up @@ -98,32 +96,15 @@ class AppmenuButton extends Handlers.Feature {
this.button._label.get_clutter_text().set_ellipsize(Pango.EllipsizeMode[type])
}

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

this._syncState()
}

_onFocusAppChanged() {
if (global.stage.key_focus == null) {
this._syncState()
}
}

_findTargetApp() {
const focusApps = [WinTracker.focus_app].concat(this.starting)
const workspace = global.workspace_manager.get_active_workspace()

return focusApps.find(app => app && app.is_on_workspace(workspace))
}

_syncState() {
const astates = Shell.AppState.STARTING
const focused = this._findTargetApp()
const focused = global.unite.focusApp
const visible = focused != null && !Main.overview.visibleTarget
const loading = focused != null && (focused.get_state() == astates || focused.get_busy())

Expand Down Expand Up @@ -356,7 +337,7 @@ class WindowButtons extends Handlers.Feature {

_syncVisible() {
const overview = Main.overview.visibleTarget
const focusApp = WinTracker.focus_app
const focusApp = global.unite.focusApp

if (!overview && focusApp && focusApp.state == Shell.AppState.RUNNING) {
const win = global.unite.focusWindow
Expand Down Expand Up @@ -476,7 +457,7 @@ class ActivitiesButton extends Handlers.Feature {
)

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

this.settings.connect(
Expand All @@ -494,10 +475,16 @@ class ActivitiesButton extends Handlers.Feature {
return this.settings.get('show-desktop-name')
}

_onFocusAppChanged() {
if (global.stage.key_focus == null) {
this._syncVisible()
}
}

_syncVisible() {
const button = Activities.container
const overview = Main.overview.visibleTarget
const focusApp = WinTracker.focus_app
const focusApp = global.unite.focusApp

if (this.hideButton == 'always') {
return button.hide()
Expand Down Expand Up @@ -553,7 +540,6 @@ 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 @@ -564,7 +550,7 @@ class DesktopName extends Handlers.Feature {
)

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

this.signals.connect(
Expand All @@ -583,32 +569,15 @@ class DesktopName extends Handlers.Feature {
this._syncVisible()
}

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

this._syncVisible()
}

_onFocusAppChanged() {
if (global.stage.key_focus == null) {
this._syncVisible()
}
}

_findFocusedApp() {
const focusApps = [WinTracker.focus_app].concat(this.starting)
const workspace = global.workspace_manager.get_active_workspace()

return focusApps.find(app => app && app.is_on_workspace(workspace))
}

_syncVisible() {
const overview = Main.overview.visibleTarget
const focusApp = this._findFocusedApp()
const focusApp = global.unite.focusApp

this.label.setVisible(!overview && focusApp == null)
}
Expand Down
26 changes: 26 additions & 0 deletions unite@hardpixel.eu/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const MOTIF_HINTS = '_MOTIF_WM_HINTS'
const _SHOW_FLAGS = ['0x2', '0x0', '0x1', '0x0', '0x0']
const _HIDE_FLAGS = ['0x2', '0x0', '0x2', '0x0', '0x0']

const AppSystem = Shell.AppSystem.get_default()
const WinTracker = Shell.WindowTracker.get_default()

function isValid(win) {
Expand Down Expand Up @@ -312,6 +313,9 @@ export const WindowManager = GObject.registerClass(
this.timeouts = new Handlers.Timeouts()
this.styles = new Handlers.Styles()

this._focusWindow = null
this._startingApps = []

this.signals.connect(
global.window_manager, 'map', this._onMapWindow.bind(this)
)
Expand All @@ -328,6 +332,10 @@ export const WindowManager = GObject.registerClass(
global.display, 'window-demands-attention', this._onAttention.bind(this)
)

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

this.settings.connect(
'hide-window-titlebars', this._onStylesChange.bind(this)
)
Expand All @@ -337,6 +345,13 @@ export const WindowManager = GObject.registerClass(
)
}

get focusApp() {
const focusApps = [WinTracker.focus_app].concat(this._startingApps)
const workspace = global.workspace_manager.get_active_workspace()

return focusApps.find(app => app && app.is_on_workspace(workspace))
}

get focusWindow() {
if (this._focusWindow) {
return this.getWindow(this._focusWindow)
Expand Down Expand Up @@ -413,6 +428,14 @@ export const WindowManager = GObject.registerClass(
}
}

_onAppStateChanged(appSys, app) {
if (app.state == Shell.AppState.STARTING) {
this._startingApps.push(app)
} else {
this._startingApps = this._startingApps.filter(item => item !== app)
}
}

_onAttention(actor, win) {
const auto = this.settings.get('autofocus-windows')
const time = global.get_current_time()
Expand Down Expand Up @@ -442,6 +465,9 @@ export const WindowManager = GObject.registerClass(
}

destroy() {
this._focusWindow = null
this._startingApps = []

this.timeouts.removeAll()
this.signals.disconnectAll()
this.settings.disconnectAll()
Expand Down

0 comments on commit 0775aad

Please sign in to comment.