Skip to content

Commit 49977bf

Browse files
committed
Add transparency support for tray icon
The selection manager of tray may hold a property to indicate the tray icon window visual. Try to use the visual with alpha channel when composite is enabled. REVIEW: 127009
1 parent 1a13806 commit 49977bf

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

Diff for: xembed-sni-proxy/fdoselectionmanager.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ void FdoSelectionManager::undock(xcb_window_t winId)
171171
void FdoSelectionManager::onClaimedOwnership()
172172
{
173173
qCDebug(SNIPROXY) << "Manager selection claimed";
174+
175+
connect(KWindowSystem::self(), &KWindowSystem::compositingChanged, this, &FdoSelectionManager::compositingChanged);
176+
compositingChanged();
174177
}
175178

176179
void FdoSelectionManager::onFailedToClaimOwnership()
@@ -182,5 +185,46 @@ void FdoSelectionManager::onFailedToClaimOwnership()
182185
void FdoSelectionManager::onLostOwnership()
183186
{
184187
qCWarning(SNIPROXY) << "lost ownership of Systray Manager";
188+
disconnect(KWindowSystem::self(), &KWindowSystem::compositingChanged, this, &FdoSelectionManager::compositingChanged);
185189
qApp->exit(-1);
186190
}
191+
192+
void FdoSelectionManager::compositingChanged()
193+
{
194+
xcb_connection_t *c = QX11Info::connection();
195+
auto screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
196+
auto trayVisual = screen->root_visual;
197+
if (KWindowSystem::compositingActive()) {
198+
xcb_depth_iterator_t depth_iterator = xcb_screen_allowed_depths_iterator(screen);
199+
xcb_depth_t *depth = nullptr;
200+
201+
while (depth_iterator.rem) {
202+
if (depth_iterator.data->depth == 32) {
203+
depth = depth_iterator.data;
204+
break;
205+
}
206+
xcb_depth_next(&depth_iterator);
207+
}
208+
209+
if (depth) {
210+
xcb_visualtype_iterator_t visualtype_iterator = xcb_depth_visuals_iterator(depth);
211+
while (visualtype_iterator.rem) {
212+
xcb_visualtype_t *visualtype = visualtype_iterator.data;
213+
if (visualtype->_class == XCB_VISUAL_CLASS_TRUE_COLOR) {
214+
trayVisual = visualtype->visual_id;
215+
break;
216+
}
217+
xcb_visualtype_next(&visualtype_iterator);
218+
}
219+
}
220+
}
221+
222+
xcb_change_property(c,
223+
XCB_PROP_MODE_REPLACE,
224+
m_selectionOwner->ownerWindow(),
225+
Xcb::atoms->visualAtom,
226+
XCB_ATOM_VISUALID,
227+
32,
228+
1,
229+
&trayVisual);
230+
}

Diff for: xembed-sni-proxy/fdoselectionmanager.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private Q_SLOTS:
5151
void addDamageWatch(xcb_window_t client);
5252
void dock(xcb_window_t embed_win);
5353
void undock(xcb_window_t client);
54+
void compositingChanged();
5455

5556
uint8_t m_damageEventBase;
5657

Diff for: xembed-sni-proxy/sniproxy.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ QImage SNIProxy::getImageNonComposite() const
262262
return QImage();
263263
}
264264

265-
xcb_image_t *image = xcb_image_get(c, m_windowId, 0, 0, geom->width, geom->height, 0xFFFFFF, XCB_IMAGE_FORMAT_Z_PIXMAP);
265+
xcb_image_t *image = xcb_image_get(c, m_windowId, 0, 0, geom->width, geom->height, 0xFFFFFFFF, XCB_IMAGE_FORMAT_Z_PIXMAP);
266266

267267
// Don't hook up cleanup yet, we may use a different QImage after all
268268
QImage naiveConversion = QImage(image->data, image->width, image->height, QImage::Format_ARGB32);

Diff for: xembed-sni-proxy/xcbutils.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ class Atoms {
109109
xembedAtom("_XEMBED"),
110110
selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", QX11Info::appScreen())),
111111
opcodeAtom("_NET_SYSTEM_TRAY_OPCODE"),
112-
messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA")
112+
messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA"),
113+
visualAtom("_NET_SYSTEM_TRAY_VISUAL")
113114
{}
114115

115116
Atom xembedAtom;
116117
Atom selectionAtom;
117118
Atom opcodeAtom;
118119
Atom messageData;
119-
120+
Atom visualAtom;
120121
};
121122

122123
extern Atoms* atoms;

0 commit comments

Comments
 (0)