Skip to content

Commit

Permalink
Added active player indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
sakithb committed Sep 13, 2021
1 parent e63e9fb commit 7ce150a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
13 changes: 12 additions & 1 deletion player.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const Player = GObject.registerClass(

this.containerButtonLabel = new St.Button({
style_class: "panel-button",
style: "padding: 0px 5px",
});

this.containerButtonLabel.connect("button-release-event", this._mouseActionButton.bind(this));
Expand Down Expand Up @@ -687,13 +688,13 @@ const Player = GObject.registerClass(

this._menuIcon = new St.Icon({
gicon: this.trackIcon,
y_align: Clutter.ActorAlign.CENTER,
style_class: "popup-menu-icon",
});

this._menuLabel = new St.Label({
text: this.label,
y_align: Clutter.ActorAlign.CENTER,
y_expand: true,
style: this.maxWidthStyle,
});

Expand Down Expand Up @@ -820,5 +821,15 @@ const Player = GObject.registerClass(

return file;
}

set active(active) {
if (active) {
this._menuItem.add_style_class_name("selected");
this._menuItem.track_hover = false;
} else {
this._menuItem.remove_style_class_name("selected");
this._menuItem.track_hover = true;
}
}
}
);
4 changes: 4 additions & 0 deletions stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
background-color: rgba(160, 160, 160, 0.2);
}

.popup-menu-button:active {
background-color: rgba(160, 160, 160, 0.4);
}

.popup-menu-button-active {
border-radius: 99px;
background-color: rgba(160, 160, 160, 0.2);
Expand Down
17 changes: 10 additions & 7 deletions widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ const MediaControls = GObject.registerClass(

this.settings.elementOrder.forEach((element) => {
if (element === "icon" && this.settings.showPlayerIcon) {
log("Adding icon");
this.player.dummyContainer.add_child(this.player.buttonPlayer);
} else if (element === "title" && this.settings.showTrackName) {
log("Adding title");
this.player.dummyContainer.add_child(this.player.containerButtonLabel);
if (this.settings.showSeperators) {
this.player.subContainerLabel.add_child(this.player.labelSeperatorStart);
Expand All @@ -134,7 +132,6 @@ const MediaControls = GObject.registerClass(
this.player.subContainerLabel.add_child(this.player.labelSeperatorEnd);
}
} else if (element === "controls" && this.settings.showControls) {
log("Adding controls");
this.player.dummyContainer.add_child(this.player.containerControls);
if (this.settings.showPrevButton) {
this.player.containerControls.add_child(this.player.buttonPrev);
Expand All @@ -146,7 +143,6 @@ const MediaControls = GObject.registerClass(
this.player.containerControls.add_child(this.player.buttonNext);
}
} else if (element === "menu" && this.settings.showMenu) {
log("Adding menu");
this.player.dummyContainer.add_child(this.player.buttonMenu);
}
});
Expand Down Expand Up @@ -202,9 +198,9 @@ const MediaControls = GObject.registerClass(

_updatePlayer(player = null) {
if (this.player) {
this.player.active = false;
this.removeWidgets();
Gio.bus_unwatch_name(this.playerWatchId);

Main.panel.menuManager.removeMenu(this.player.menu);

this.player = null;
Expand Down Expand Up @@ -242,11 +238,14 @@ const MediaControls = GObject.registerClass(
null,
this.playerVanished.bind(this)
);

this.removeWidgets();
this.addWidgets();

this.player.active = true;
}

log("[MediaControls] Updated player");
log("[MediaControls] Updated player", player ? player.busName : player);
}

_activatePlayer(playerItem) {
Expand Down Expand Up @@ -279,7 +278,11 @@ const MediaControls = GObject.registerClass(
if (playerObj) {
this.menu.addMenuItem(playerObj.menuItem);
playerObj.hidden = false;
this._updatePlayer();
if (this._isFixedPlayer) {
this._updatePlayer(this.player);
} else {
this._updatePlayer();
}
}
}

Expand Down

0 comments on commit 7ce150a

Please sign in to comment.