dot
vizie's NixOS desktop: Hyprland, CachyOS kernel and gaming tweaks
| 1 | diff --color -ruN a/xembed-sni-proxy/sniproxy.cpp b/xembed-sni-proxy/sniproxy.cpp |
| 2 | |
| 3 | |
| 4 | |
| 5 | QDBusConnection::disconnectFromBus(m_dbus.name()); |
| 6 | } |
| 7 | |
| 8 | +// Crop the fully transparent margin around an icon, keeping the icon centred. |
| 9 | +// Wine, for one, draws a 16px icon in a 20px window; a tray that scales the whole |
| 10 | +// pixmap to its icon size then shows it smaller than every other icon. |
| 11 | +static QImage trimTransparentMargin(const QImage &image) |
| 12 | +{ |
| 13 | + if (!image.hasAlphaChannel()) { |
| 14 | + return image; |
| 15 | + } |
| 16 | + |
| 17 | + const int w = image.width(); |
| 18 | + const int h = image.height(); |
| 19 | + int margin = std::min(w, h); |
| 20 | + for (int y = 0; y < h; ++y) { |
| 21 | + for (int x = 0; x < w; ++x) { |
| 22 | + if (qAlpha(image.pixel(x, y)) != 0) { |
| 23 | + margin = std::min({margin, x, y, w - 1 - x, h - 1 - y}); |
| 24 | + } |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + // nothing to trim, or nothing but margin |
| 29 | + if (margin <= 0 || margin * 2 >= std::min(w, h)) { |
| 30 | + return image; |
| 31 | + } |
| 32 | + return image.copy(margin, margin, w - 2 * margin, h - 2 * margin); |
| 33 | +} |
| 34 | + |
| 35 | void SNIProxy::update() |
| 36 | { |
| 37 | QImage image = getImageNonComposite(); |
| 38 | |
| 39 | qCDebug(SNIPROXY) << "No xembed icon for" << m_windowId << Title(); |
| 40 | return; |
| 41 | } |
| 42 | + image = trimTransparentMargin(image); |
| 43 | |
| 44 | int w = image.width(); |
| 45 | int h = image.height(); |