perf(wim ags player): hide not visible players
This commit is contained in:
parent
0a6570739e
commit
f47b5abc3f
2 changed files with 53 additions and 30 deletions
|
@ -18,20 +18,34 @@ export default ({
|
||||||
const widget = EventBox();
|
const widget = EventBox();
|
||||||
const gesture = Gtk.GestureDrag.new(widget);
|
const gesture = Gtk.GestureDrag.new(widget);
|
||||||
|
|
||||||
|
// Have empty PlayerBox to define the size of the widget
|
||||||
|
const emptyPlayer = Box({ className: 'player' });
|
||||||
|
|
||||||
|
// Set this prop to differentiate it easily
|
||||||
|
emptyPlayer.empty = true;
|
||||||
|
|
||||||
widget.add(Overlay({
|
widget.add(Overlay({
|
||||||
...props,
|
...props,
|
||||||
properties: [
|
properties: [
|
||||||
...properties,
|
...properties,
|
||||||
['dragging', false],
|
['dragging', false],
|
||||||
|
['showTopOnly', (overlay) => overlay.list()
|
||||||
|
.forEach((over) => {
|
||||||
|
if (over === overlay.list().at(-1)) {
|
||||||
|
over.visible = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
over.visible = false;
|
||||||
|
}
|
||||||
|
})],
|
||||||
],
|
],
|
||||||
|
|
||||||
// Have empty PlayerBox to define the size of the widget
|
child: emptyPlayer,
|
||||||
child: Box({ className: 'player' }),
|
|
||||||
|
|
||||||
connections: [
|
connections: [
|
||||||
...connections,
|
...connections,
|
||||||
|
|
||||||
[gesture, (overlay) => {
|
[gesture, (overlay, x) => {
|
||||||
// Don't allow gesture when only one player
|
// Don't allow gesture when only one player
|
||||||
if (overlay.list().length <= 1) {
|
if (overlay.list().length <= 1) {
|
||||||
return;
|
return;
|
||||||
|
@ -42,6 +56,15 @@ export default ({
|
||||||
|
|
||||||
const playerBox = overlay.list().at(-1);
|
const playerBox = overlay.list().at(-1);
|
||||||
|
|
||||||
|
if (x) {
|
||||||
|
overlay.list().forEach((over) => {
|
||||||
|
over.visible = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
overlay._showTopOnly(overlay);
|
||||||
|
}
|
||||||
|
|
||||||
// Slide right
|
// Slide right
|
||||||
if (offset >= 0) {
|
if (offset >= 0) {
|
||||||
playerBox.setCss(`
|
playerBox.setCss(`
|
||||||
|
@ -104,6 +127,8 @@ export default ({
|
||||||
playerBox.setCss(playerBox._bgStyle);
|
playerBox.setCss(playerBox._bgStyle);
|
||||||
|
|
||||||
widget.sensitive = true;
|
widget.sensitive = true;
|
||||||
|
|
||||||
|
overlay._showTopOnly(overlay);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -115,7 +140,7 @@ export default ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
widget.child.list = () => widget.child.get_children()
|
widget.child.list = () => widget.child.get_children()
|
||||||
.filter((ch) => ch._bgStyle);
|
.filter((ch) => !ch.empty);
|
||||||
|
|
||||||
return widget;
|
return widget;
|
||||||
};
|
};
|
||||||
|
|
|
@ -85,16 +85,22 @@ const Bottom = (player) => Box({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const PlayerBox = (player) => mpris.CoverArt(player, {
|
const PlayerBox = (player) => {
|
||||||
className: `player ${player.name}`,
|
const widget = mpris.CoverArt(player, {
|
||||||
hexpand: true,
|
className: `player ${player.name}`,
|
||||||
|
hexpand: true,
|
||||||
|
|
||||||
children: [
|
children: [
|
||||||
Top(player),
|
Top(player),
|
||||||
Center(player),
|
Center(player),
|
||||||
Bottom(player),
|
Bottom(player),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
widget.visible = false;
|
||||||
|
|
||||||
|
return widget;
|
||||||
|
};
|
||||||
|
|
||||||
export default () => Box({
|
export default () => Box({
|
||||||
className: 'media',
|
className: 'media',
|
||||||
|
@ -135,19 +141,13 @@ export default () => Box({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make the new player
|
||||||
const player = Mpris.getPlayer(busName);
|
const player = Mpris.getPlayer(busName);
|
||||||
|
|
||||||
player.colors = Variable();
|
player.colors = Variable();
|
||||||
|
|
||||||
overlay._players.set(busName, PlayerBox(player));
|
overlay._players.set(busName, PlayerBox(player));
|
||||||
|
overlay.overlays = Array.from(overlay._players.values())
|
||||||
const result = [];
|
.map((widget) => widget);
|
||||||
|
|
||||||
overlay._players.forEach((widget) => {
|
|
||||||
result.push(widget);
|
|
||||||
});
|
|
||||||
|
|
||||||
overlay.overlays = result;
|
|
||||||
|
|
||||||
// Select favorite player at startup
|
// Select favorite player at startup
|
||||||
if (!overlay._setup && overlay._players.has(FAVE_PLAYER)) {
|
if (!overlay._setup && overlay._players.has(FAVE_PLAYER)) {
|
||||||
|
@ -157,6 +157,8 @@ export default () => Box({
|
||||||
);
|
);
|
||||||
overlay._setup = true;
|
overlay._setup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move previousFirst on top again
|
||||||
else if (overlay._players.get(previousFirst)) {
|
else if (overlay._players.get(previousFirst)) {
|
||||||
overlay.reorder_overlay(
|
overlay.reorder_overlay(
|
||||||
overlay._players.get(previousFirst),
|
overlay._players.get(previousFirst),
|
||||||
|
@ -181,16 +183,12 @@ export default () => Box({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remake overlays without deleted one
|
||||||
overlay._players.delete(busName);
|
overlay._players.delete(busName);
|
||||||
|
overlay.overlays = Array.from(overlay._players.values())
|
||||||
|
.map((widget) => widget);
|
||||||
|
|
||||||
const result = [];
|
// Move previousFirst on top again
|
||||||
|
|
||||||
overlay._players.forEach((widget) => {
|
|
||||||
result.push(widget);
|
|
||||||
});
|
|
||||||
|
|
||||||
overlay.overlays = result;
|
|
||||||
|
|
||||||
if (overlay._players.has(previousFirst)) {
|
if (overlay._players.has(previousFirst)) {
|
||||||
overlay.reorder_overlay(
|
overlay.reorder_overlay(
|
||||||
overlay._players.get(previousFirst),
|
overlay._players.get(previousFirst),
|
||||||
|
|
Loading…
Reference in a new issue