]>
Dogcows Code - chaz/tint2/blob - src/systray/docker.c
12 #include <X11/Xutil.h>
17 Window win
= None
, hint_win
= None
, root
= None
;
18 gboolean wmaker
= FALSE
; /* WindowMakerMode!!! wheeee */
19 Display
*display
= NULL
;
21 int width
= 0, height
= 0;
22 int border
= 1; /* blank area around icons. must be > 0 */
23 gboolean horizontal
= TRUE
; /* layout direction */
24 int icon_size
= 24; /* width and height of systray icons */
26 //static char *display_string = NULL;
27 /* excluding the border. sum of all child apps */
28 static gboolean exit_app
= FALSE
;
34 gboolean help = FALSE;
36 for (i = 1; i < argc; i++) {
37 if (0 == strcasecmp(argv[i], "-display")) {
40 display_string = argv[i];
42 g_printerr("-display requires a parameter\n");
45 } else if (0 == strcasecmp(argv[i], "-wmaker")) {
47 } else if (0 == strcasecmp(argv[i], "-vertical")) {
49 } else if (0 == strcasecmp(argv[i], "-border")) {
53 int b = atoi(argv[i]);
57 g_printerr("-border must be a value greater than 0\n");
61 g_printerr("-border requires a parameter\n");
64 } else if (0 == strcasecmp(argv[i], "-iconsize")) {
67 int s = atoi(argv[i]);
71 g_printerr("-iconsize must be a value greater than 0\n");
75 g_printerr("-iconsize requires a parameter\n");
79 if (argv[i][0] == '-')
86 g_print("%s - version %s\n", argv[0], VERSION);
87 g_print("Copyright 2003, Ben Jansens <ben@orodu.net>\n\n");
88 g_print("Usage: %s [OPTIONS]\n\n", argv[0]);
89 g_print("Options:\n");
90 g_print(" -help Show this help.\n");
91 g_print(" -display DISLPAY The X display to connect to.\n");
92 g_print(" -border The width of the border to put around the\n"
93 " system tray icons. Defaults to 1.\n");
94 g_print(" -vertical Line up the icons vertically. Defaults to\n"
96 g_print(" -wmaker WindowMaker mode. This makes docker a\n"
97 " fixed size (64x64) to appear nicely in\n"
99 " Note: In this mode, you have a fixed\n"
100 " number of icons that docker can hold.\n");
101 g_print(" -iconsize SIZE The size (width and height) to display\n"
102 " icons as in the system tray. Defaults to\n"
110 void create_hint_win()
113 XClassHint classhints
;
115 hint_win
= XCreateSimpleWindow(display
, root
, 0, 0, 1, 1, 0, 0, 0);
118 hints
.flags
= StateHint
| WindowGroupHint
| IconWindowHint
;
119 hints
.initial_state
= WithdrawnState
;
120 hints
.window_group
= hint_win
;
121 hints
.icon_window
= win
;
123 classhints
.res_name
= "docker";
124 classhints
.res_class
= "Docker";
126 XSetWMProperties(display
, hint_win
, NULL
, NULL
, argv
, argc
,
127 NULL
, &hints
, &classhints
);
129 XMapWindow(display
, hint_win
);
133 void create_main_window()
137 char *name
= "Docker";
139 /* the border must be > 0 if not in wmaker mode */
140 assert(wmaker
|| border
> 0);
143 win
= XCreateSimpleWindow(display
, root
, 0, 0,
144 border
* 2, border
* 2, 0, 0, 0);
146 win
= XCreateSimpleWindow(display
, root
, 0, 0,
151 XStringListToTextProperty(&name
, 1, &text
);
152 XSetWMName(display
, win
, &text
);
154 hints
.flags
= StateHint
;
155 hints
.initial_state
= WithdrawnState
;
156 XSetWMHints(display
, win
, &hints
);
160 XSync(display
, False
);
161 XSetWindowBackgroundPixmap(display
, win
, ParentRelative
);
162 XClearWindow(display
, win
);
166 void reposition_icons()
168 int x
= border
+ ((width
% icon_size
) / 2),
169 y
= border
+ ((height
% icon_size
) / 2);
172 for (it
= icons
; it
!= NULL
; it
= g_slist_next(it
)) {
173 TrayWindow
*traywin
= it
->data
;
176 XMoveWindow(display
, traywin
->id
, x
, y
);
177 XSync(display
, False
);
180 if (x
+ icon_size
> width
) {
184 } else if (horizontal
)
196 /* in wmaker mode we're a fixed size */
199 /* find the proper width and height */
200 width
= horizontal
? 0 : icon_size
;
201 height
= horizontal
? icon_size
: 0;
202 for (it
= icons
; it
!= NULL
; it
= g_slist_next(it
)) {
209 XResizeWindow(display
, win
, width
+ border
* 2, height
+ border
* 2);
220 while (XPending(display
)) {
221 XNextEvent(display
, &e
);
226 /* systray window list has changed? */
227 if (e
.xproperty
.atom
== kde_systray_prop
) {
228 XSelectInput(display
, win
, NoEventMask
);
230 XSelectInput(display
, win
, StructureNotifyMask
);
232 while (XCheckTypedEvent(display
, PropertyNotify
, &e
));
237 case ConfigureNotify
:
238 if (e
.xany
.window
!= win
) {
239 /* find the icon it pertains to and beat it into submission */
242 for (it
= icons
; it
!= NULL
; it
= g_slist_next(it
)) {
243 TrayWindow
*traywin
= it
->data
;
244 if (traywin
->id
== e
.xany
.window
) {
245 XMoveResizeWindow(display
, traywin
->id
, traywin
->x
, traywin
->y
,
246 icon_size
, icon_size
);
253 /* briefly cover the entire containing window, which causes it and
254 all of the icons to refresh their windows. finally, they update
255 themselves when the background of the main window's parent changes.
257 cover
= XCreateSimpleWindow(display
, win
, 0, 0,
258 border
* 2 + width
, border
* 2 + height
,
260 XMapWindow(display
, cover
);
261 XDestroyWindow(display
, cover
);
266 if (e
.xany
.window
== win
) /* reparented to us */
270 for (it
= icons
; it
; it
= g_slist_next(it
)) {
271 if (((TrayWindow
*)it
->data
)->id
== e
.xany
.window
) {
279 if (e
.xclient
.message_type
== net_opcode_atom
&&
280 e
.xclient
.format
== 32 &&
281 e
.xclient
.window
== net_sel_win
)
282 net_message(&e
.xclient
);
291 /* remove/unparent all the icons */
293 /* do the remove here explicitly, cuz the event handler isn't going to
300 int main(int c, char **v)
302 struct sigaction act;
306 act.sa_handler = signal_handler;
308 sigaction(SIGSEGV, &act, NULL);
309 sigaction(SIGPIPE, &act, NULL);
310 sigaction(SIGFPE, &act, NULL);
311 sigaction(SIGTERM, &act, NULL);
312 sigaction(SIGINT, &act, NULL);
313 sigaction(SIGHUP, &act, NULL);
315 parse_cmd_line(argc, argv);
317 display = XOpenDisplay(display_string);
319 g_printerr("Unable to open Display %s. Exiting.\n",
320 DisplayString(display_string));
323 root = RootWindow(display, DefaultScreen(display));
327 width = height = 64 - border * 2;
329 create_main_window();
331 // set up to find KDE systray icons, and get any that already exist
336 // we want to get ConfigureNotify events, and assume our parent's background
337 // has changed when we do, so we need to refresh ourself to match
338 XSelectInput(display, win, StructureNotifyMask);
342 XCloseDisplay(display);
This page took 0.05309 seconds and 4 git commands to generate.