Show the local client's state in the system tray

The icon carries the badge the tree draws next to our own nickname on the
active server — idle, talking, away, commander, microphone or speakers
muted — and clicking it brings the window back to the front. Right click
offers "Show TS3J" and "Quit".

AWT's tray icon cannot be transparent on X11: the toolkit embeds a window
of the screen's default, opaque visual and fills it with a background
colour before drawing the image, so every icon sits in a box. Panels that
can show transparent icons advertise an ARGB visual instead, so the icon
is docked by hand over the system tray protocol, in that visual, with the
image put on the window premultiplied. AWT's own icon stays as the
fallback for everything else.

Two details a panel will not forgive: an icon that publishes no size
hints is allocated a one-pixel sliver, and docking is a request, so an
icon that is never adopted has to hand over to the fallback rather than
sit invisible.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-14 22:45:32 +00:00
parent ef95b6305d
commit 32e5ffb576
10 changed files with 1314 additions and 17 deletions

View File

@@ -0,0 +1,52 @@
package com.ts3client.ui;
import javax.swing.ImageIcon;
/**
* The state of the local client on one server, as the tree shows it for any other
* client — the states are listed in the order the official client gives them
* priority, the strongest one first.
*/
enum SelfState {
DISCONNECTED("Not connected"),
DEAFENED("Speakers muted"),
MIC_MUTED("Microphone muted"),
AWAY("Away"),
COMMANDER_TALKING("Talking (channel commander)"),
COMMANDER("Channel commander"),
TALKING("Talking"),
IDLE("Connected");
private final String label;
SelfState(String label) {
this.label = label;
}
String label() {
return label;
}
/** The icon this state is drawn with, from the active icon pack. */
ImageIcon icon(int size) {
switch (this) {
case DISCONNECTED:
return Icons.app(size);
case DEAFENED:
return Icons.speakerMuted(size);
case MIC_MUTED:
return Icons.micMuted(size);
case AWAY:
return Icons.clientAway(size);
case COMMANDER_TALKING:
return Icons.clientCommanderTalking(size);
case COMMANDER:
return Icons.clientCommander(size);
case TALKING:
return Icons.clientTalking(size);
default:
return Icons.clientIdle(size);
}
}
}