- TrayWindow *traywin;
-
- traywin = g_new0(TrayWindow, 1);
- traywin->id = id;
-
- if (!icon_swallow(traywin)) {
- g_free(traywin);
- return FALSE;
- }
-
- // find the positon for the systray app window
- int count = g_slist_length(icons);
- traywin->x = border + ((width % icon_size) / 2) +
- (count % (width / icon_size)) * icon_size;
- traywin->y = border + ((height % icon_size) / 2) +
- (count / (height / icon_size)) * icon_size;
-
- // add the new icon to the list
- icons = g_slist_append(icons, traywin);
-
- // watch for the icon trying to resize itself!
- XSelectInput(server.dsp, traywin->id, StructureNotifyMask);
-
- // position and size the icon window
- XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, icon_size, icon_size);
-
- // resize our window so that the new window can fit in it
- fix_geometry();
-
- // flush before clearing, otherwise the clear isn't effective.
- XFlush(server.dsp);
- // make sure the new child will get the right stuff in its background
- // for ParentRelative.
- XClearWindow(server.dsp, win);
-
- // show the window
- XMapRaised(server.dsp, traywin->id);
-
- return TRUE;
+ TrayWindow *traywin;
+ XErrorHandler old;
+ Panel *panel = systray.area.panel;
+ int hide = 0;
+
+ error = FALSE;
+ old = XSetErrorHandler(window_error_handler);
+ XReparentWindow(server.dsp, id, panel->main_win, 0, 0);
+ XSync(server.dsp, False);
+ XSetErrorHandler(old);
+ if (error != FALSE) {
+ fprintf(stderr, "tint2 : not icon_swallow\n");
+ return FALSE;
+ }
+
+ {
+ Atom acttype;
+ int actfmt;
+ unsigned long nbitem, bytes;
+ unsigned char *data = 0;
+ int ret;
+
+ ret = XGetWindowProperty(server.dsp, id, server.atom._XEMBED_INFO, 0, 2, False, server.atom._XEMBED_INFO, &acttype, &actfmt, &nbitem, &bytes, &data);
+ if (ret == Success) {
+ if (data) {
+ if (nbitem == 2) {
+ //hide = ((data[1] & XEMBED_MAPPED) == 0);
+ //printf("hide %d\n", hide);
+ }
+ XFree(data);
+ }
+ }
+ else {
+ fprintf(stderr, "tint2 : xembed error\n");
+ return FALSE;
+ }
+ }
+ {
+ XEvent e;
+ e.xclient.type = ClientMessage;
+ e.xclient.serial = 0;
+ e.xclient.send_event = True;
+ e.xclient.message_type = server.atom._XEMBED;
+ e.xclient.window = id;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = CurrentTime;
+ e.xclient.data.l[1] = XEMBED_EMBEDDED_NOTIFY;
+ e.xclient.data.l[2] = 0;
+ e.xclient.data.l[3] = panel->main_win;
+ e.xclient.data.l[4] = 0;
+ XSendEvent(server.dsp, id, False, 0xFFFFFF, &e);
+ }
+
+ traywin = g_new0(TrayWindow, 1);
+ traywin->id = id;
+ traywin->hide = hide;
+
+ if (systray.sort == 3)
+ systray.list_icons = g_slist_prepend(systray.list_icons, traywin);
+ else if (systray.sort == 2)
+ systray.list_icons = g_slist_append(systray.list_icons, traywin);
+ else
+ systray.list_icons = g_slist_insert_sorted(systray.list_icons, traywin, compare_traywindows);
+ systray.area.resize = 1;
+ systray.area.redraw = 1;
+ //printf("add_icon id %lx, %d\n", id, g_slist_length(systray.list_icons));
+
+ // watch for the icon trying to resize itself!
+ XSelectInput(server.dsp, traywin->id, StructureNotifyMask);
+
+ // show the window
+ if (!traywin->hide)
+ XMapRaised(server.dsp, traywin->id);
+
+ // changed in systray force resize on panel
+ panel->area.resize = 1;
+ panel_refresh = 1;
+ return TRUE;