]>
Dogcows Code - chaz/tint2/blob - src/systray/icons.c
7 int window_error_handler(Display
*d
, XErrorEvent
*e
)
10 if (e
->error_code
== BadWindow
) {
13 g_printerr("X ERROR NOT BAD WINDOW!\n");
20 gboolean
icon_swallow(TrayWindow
*traywin
)
25 old
= XSetErrorHandler(window_error_handler
);
26 XReparentWindow(display
, traywin
->id
, win
, 0, 0);
27 XSync(display
, False
);
28 XSetErrorHandler(old
);
35 The traywin must have its id and type set.
37 gboolean
icon_add(Window id
, TrayWindowType type
)
45 /* do we have room in our window for another icon? */
46 unsigned int max
= (width
/ icon_size
) * (height
/ icon_size
);
47 if (g_slist_length(icons
) >= max
)
48 return FALSE
; /* no room, sorry! REJECTED! */
51 traywin
= g_new0(TrayWindow
, 1);
55 if (!icon_swallow(traywin
)) {
60 /* find the positon for the systray app window */
62 traywin
->x
= border
+ (horizontal
? width
: 0);
63 traywin
->y
= border
+ (horizontal
? 0 : height
);
65 int count
= g_slist_length(icons
);
66 traywin
->x
= border
+ ((width
% icon_size
) / 2) +
67 (count
% (width
/ icon_size
)) * icon_size
;
68 traywin
->y
= border
+ ((height
% icon_size
) / 2) +
69 (count
/ (height
/ icon_size
)) * icon_size
;
72 /* add the new icon to the list */
73 icons
= g_slist_append(icons
, traywin
);
75 /* watch for the icon trying to resize itself! BAD ICON! BAD! */
76 XSelectInput(display
, traywin
->id
, StructureNotifyMask
);
78 /* position and size the icon window */
79 XMoveResizeWindow(display
, traywin
->id
,
80 traywin
->x
, traywin
->y
, icon_size
, icon_size
);
82 /* resize our window so that the new window can fit in it */
85 /* flush before clearing, otherwise the clear isn't effective. */
87 /* make sure the new child will get the right stuff in its background
88 for ParentRelative. */
89 XClearWindow(display
, win
);
92 XMapRaised(display
, traywin
->id
);
98 void icon_remove(GSList
*node
)
101 TrayWindow
*traywin
= node
->data
;
102 Window traywin_id
= traywin
->id
;
104 if (traywin
->type
== NET
)
105 net_icon_remove(traywin
);
107 XSelectInput(display
, traywin
->id
, NoEventMask
);
109 /* remove it from our list */
111 icons
= g_slist_remove_link(icons
, node
);
113 /* reparent it to root */
115 old
= XSetErrorHandler(window_error_handler
);
116 XReparentWindow(display
, traywin_id
, root
, 0, 0);
117 XSync(display
, False
);
118 XSetErrorHandler(old
);
This page took 0.038172 seconds and 5 git commands to generate.