Skip to content

Commit

Permalink
appmenu: add loading spinner indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian committed Oct 17, 2023
1 parent 40f35ad commit 1d6cef1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
32 changes: 25 additions & 7 deletions unite@hardpixel.eu/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,40 @@ import Clutter from 'gi://Clutter'
import { AppMenu } from 'resource:///org/gnome/shell/ui/appMenu.js'
import * as Main from 'resource:///org/gnome/shell/ui/main.js'
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js'
import * as Animation from 'resource:///org/gnome/shell/ui/animation.js'

export const AppmenuLabel = GObject.registerClass(
class UniteAppmenuLabel extends PanelMenu.Button {
_init(text) {
super._init(0.0, null, true)

const bin = new St.Bin({ name: 'appMenu' })
this.add_actor(bin)

this.bind_property('reactive', this, 'can-focus', 0)
this.reactive = false

this._container = new St.BoxLayout({ style_class: 'panel-status-menu-box' })
bin.set_child(this._container)

this._label = new St.Label({ y_align: Clutter.ActorAlign.CENTER })
this._container.add_actor(this._label)

this._spinner = new Animation.Spinner(16, { animate: true, hideOnStop: true })
this._container.add_actor(this._spinner)

const menu = new AppMenu(this)
this.setMenu(menu)

this._menuManager = Main.panel.menuManager
this._menuManager.addMenu(menu)

this._label = new St.Label({ y_align: Clutter.ActorAlign.CENTER })
this.add_actor(this._label)

this.reactive = false
this.label_actor = this._label

this.setText(text || '')
this.add_style_class_name('app-menu-label')
}

setApp(app) {
this.setText(app ? app.get_name() : '')
this.setText(app.get_name())
this.menu.setApp(app)
}

Expand All @@ -42,6 +52,14 @@ export const AppmenuLabel = GObject.registerClass(
setVisible(visible) {
this.container.visible = visible
}

stopAnimation() {
this._spinner.stop()
}

startAnimation() {
this._spinner.play()
}
}
)

Expand Down
15 changes: 13 additions & 2 deletions unite@hardpixel.eu/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,20 @@ class AppmenuButton extends Handlers.Feature {
const visible = focused != null && !Main.overview.visibleTarget
const loading = focused != null && (focused.get_state() == astates || focused.get_busy())

if (focused != this.focused) {
if (focused !== this.focused) {
this.focused?.disconnectObject(this)
this.focused = focused
this.button.setApp(this.focused)

if (this.focused) {
this.focused.connectObject('notify::busy', this._syncState.bind(this), this)
this.button.setApp(this.focused)
}
}

if (loading) {
this.button.startAnimation()
} else {
this.button.stopAnimation()
}

this.button.setReactive(visible && !loading)
Expand Down
3 changes: 1 addition & 2 deletions unite@hardpixel.eu/styles/shell/spacing.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

#panel #panelActivities,
#panel .system-tray-icons,
#panel .desktop-name-label,
#panel .app-menu-label {
#panel .desktop-name-label {
-natural-hpadding: 10px;
-minimum-hpadding: 8px;
}
Expand Down

0 comments on commit 1d6cef1

Please sign in to comment.