cvsimport
[fvwm.git] / modules / FvwmDebug / FvwmOldDebug.c
blob5df383189994a76a3f7f929f10e26360c5d3bb52
1 /* -*-c-*- */
2 #define OUTPUT_FLAGS
3 /* This module, and the entire FvwmDebug program, and the concept for
4 * interfacing this module to the Window Manager, are all original work
5 * by Robert Nation
7 * Copyright 1994, Robert Nation. No guarantees or warantees or anything
8 * are provided or implied in any way whatsoever. Use this program at your
9 * own risk. Permission to use this program for any purpose is given,
10 * as long as the copyright is kept intact. */
12 /* This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "config.h"
29 #include <stdio.h>
30 #include <signal.h>
31 #include <fcntl.h>
32 #include <sys/wait.h>
33 #include "libs/ftime.h"
34 #include <unistd.h>
35 #include <ctype.h>
37 #include "FvwmOldDebug.h"
39 #include "fvwm/fvwm.h"
40 #include "libs/Module.h"
41 #include "libs/vpacket.h"
42 #include "libs/System.h"
44 char *MyName;
45 int fd_width;
46 int fd[2];
47 int verbose=0;
48 FILE *output=NULL;
51 ** spawn_xtee - code to execute xtee from a running executable &
52 ** redirect stdout & stderr to it. Currently sends both to same xtee,
53 ** but you rewrite this to spawn off 2 xtee's - one for each stream.
56 pid_t spawn_xtee(void)
58 pid_t pid;
59 int PIPE[2];
60 char *argarray[256];
62 setvbuf(stdout,NULL,_IOLBF,0); /* line buffered */
64 if (pipe(PIPE))
66 perror("spawn_xtee");
67 fprintf(stderr, "ERROR ERRATA -- Failed to create pipe for xtee.\n");
68 return 0;
71 argarray[0] = "xtee";
72 argarray[1] = "-nostdout";
73 argarray[2] = NULL;
75 if (!(pid = fork())) /* child */
77 dup2(PIPE[0], STDIN_FILENO);
78 close(PIPE[0]);
79 close(PIPE[1]);
80 execvp("xtee",argarray);
81 exit(1); /* shouldn't get here... */
83 else /* parent */
85 if (ReapChildrenPid(pid) != pid)
87 dup2(PIPE[1], STDOUT_FILENO);
88 dup2(PIPE[1], STDERR_FILENO);
89 close(PIPE[0]);
90 close(PIPE[1]);
94 return pid;
95 } /* spawn_xtee */
99 * Procedure:
100 * main - start of module
103 int main(int argc, char **argv)
105 const char *temp, *s;
107 /* Save our program name - for error messages */
108 temp = argv[0];
109 s=strrchr(argv[0], '/');
110 if (s != NULL)
111 temp = s + 1;
113 MyName = safemalloc(strlen(temp)+2);
114 strcpy(MyName, "*");
115 strcat(MyName, temp);
117 if((argc < 6)||(argc > 8)) {
118 fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",MyName,
119 VERSION);
120 exit(1);
123 if (argc > 6)
125 if (!(strcmp(argv[6], "-v")))
126 verbose++;
127 else
129 output = fopen( argv[6], "w" );
130 if (output == NULL)
132 fprintf(stderr,"%s Version %s: Failed to open %s\n",
133 MyName,VERSION,argv[6]);
134 exit(1);
138 if (argc > 7)
140 if (verbose)
142 output = fopen( argv[7], "w" );
143 if (output == NULL)
145 fprintf(stderr,"%s Version %s: Failed to open %s\n",
146 MyName,VERSION,argv[7]);
147 exit(1);
150 else
152 if (!(strcmp(argv[7], "-v")))
153 verbose++;
154 else
156 fprintf(stderr,"%s Version %s received two filename args!\n",
157 MyName,VERSION);
158 exit(1);
162 if (output==NULL)
163 output=stderr;
166 /* Dead pipe == Fvwm died */
167 signal(SIGPIPE, DeadPipe);
169 fd[0] = atoi(argv[1]);
170 fd[1] = atoi(argv[2]);
172 #if 0
173 spawn_xtee();
174 #endif
176 /* Data passed in command line */
177 fprintf(output,"Application Window 0x%s\n",argv[4]);
178 fprintf(output,"Application Context %s\n",argv[5]);
180 fd_width = GetFdWidth();
182 /* select all extended messages */
183 SetMessageMask(fd, M_EXTENDED_MSG | MAX_XMSG_MASK);
185 /* Create a list of all windows */
186 /* Request a list of all windows,
187 * wait for ConfigureWindow packets */
188 SendInfo(fd,"Send_WindowList",0);
190 /* tell fvwm we're running */
191 SendFinishedStartupNotification(fd);
193 Loop(fd);
194 return 0;
200 * Procedure:
201 * Loop - wait for data to process
204 void Loop(const int *fd)
206 while (1) {
207 FvwmPacket* packet = ReadFvwmPacket(fd[1]);
208 if ( packet == NULL )
209 exit(0);
210 process_message( packet->type, packet->body );
217 * Procedure:
218 * Process message - examines packet types, and takes appropriate action
221 void process_message(unsigned long type, const unsigned long *body)
223 switch(type)
225 case M_NEW_PAGE:
226 fprintf(output,"new page\n");
227 list_new_page(body);
228 break;
229 case M_NEW_DESK:
230 fprintf(output,"new desk\n");
231 list_new_desk(body);
232 break;
233 case M_OLD_ADD_WINDOW:
234 fprintf(output,"Old Add Window\n");
235 list_old_configure(body);
236 case M_OLD_CONFIGURE_WINDOW:
237 fprintf(output,"Old Configure Window\n");
238 list_old_configure(body);
239 break;
240 case M_RAISE_WINDOW:
241 fprintf(output,"Raise\n");
242 list_winid(body);
243 break;
244 case M_LOWER_WINDOW:
245 fprintf(output,"Lower\n");
246 list_winid(body);
247 break;
248 case M_FOCUS_CHANGE:
249 fprintf(output,"Focus\n");
250 list_focus(body);
251 break;
252 case M_DESTROY_WINDOW:
253 fprintf(output,"Destroy\n");
254 list_winid(body);
255 break;
256 case M_ICONIFY:
257 fprintf(output,"iconify\n");
258 list_icon(body);
259 break;
260 case M_DEICONIFY:
261 fprintf(output,"Deiconify\n");
262 list_icon(body);
263 break;
264 case M_WINDOW_NAME:
265 fprintf(output,"window name\n");
266 list_window_name(body);
267 break;
268 case M_VISIBLE_NAME:
269 fprintf(output,"visible window name\n");
270 list_window_name(body);
271 break;
272 case M_ICON_NAME:
273 fprintf(output,"icon name\n");
274 list_window_name(body);
275 break;
276 case MX_VISIBLE_ICON_NAME:
277 fprintf(output,"visible icon name\n");
278 list_window_name(body);
279 break;
280 case M_RES_CLASS:
281 fprintf(output,"window class\n");
282 list_window_name(body);
283 break;
284 case M_RES_NAME:
285 fprintf(output,"class resource name\n");
286 list_window_name(body);
287 break;
288 case M_END_WINDOWLIST:
289 fprintf(output,"Send_WindowList End\n");
290 break;
291 case M_ICON_LOCATION:
292 fprintf(output,"icon location\n");
293 list_icon(body);
294 break;
295 case M_ICON_FILE:
296 fprintf(output,"icon file\n");
297 list_window_name(body);
298 break;
299 case M_MAP:
300 fprintf(output,"map\n");
301 list_winid(body);
302 break;
303 case M_ERROR:
304 fprintf(output,"Error\n");
305 list_error(body);
306 break;
307 case M_MINI_ICON:
308 fprintf(output,"Mini icon\n");
309 list_winid(body);
310 break;
311 case M_WINDOWSHADE:
312 fprintf(output,"Windowshade\n");
313 list_winid(body);
314 break;
315 case M_DEWINDOWSHADE:
316 fprintf(output,"Dewindowshade\n");
317 list_winid(body);
318 break;
319 case M_RESTACK:
320 fprintf(output,"Restack\n");
321 list_restack(body);
322 break;
323 case M_ADD_WINDOW:
324 fprintf(output,"Add Window\n");
325 list_configure(body);
326 break;
327 case M_CONFIGURE_WINDOW:
328 fprintf(output,"Configure Window\n");
329 list_configure(body);
330 break;
331 default:
332 list_unknown(body);
333 fprintf(output, " 0x%x\n", (int)type);
334 break;
342 * Procedure:
343 * SIGPIPE handler - SIGPIPE means fvwm is dying
346 RETSIGTYPE DeadPipe(int nonsense)
348 (void)nonsense;
349 fprintf(stderr,"FvwmDebug: DeadPipe\n");
350 exit(0);
351 SIGNAL_RETURN;
356 * Procedure:
357 * list_old_configure - displays packet contents to output
360 void list_old_configure(const unsigned long *body)
362 fprintf(output,"\t ID %lx\n",body[0]);
363 fprintf(output,"\t frame ID %lx\n",body[1]);
364 fprintf(output,"\t fvwm ptr %lx\n",body[2]);
365 fprintf(output,"\t frame x %ld\n",(long)body[3]);
366 fprintf(output,"\t frame y %ld\n",(long)body[4]);
367 fprintf(output,"\t frame w %ld\n",(long)body[5]);
368 fprintf(output,"\t frame h %ld\n",(long)body[6]);
369 fprintf(output,"\t desk %ld\n",(long)body[7]);
370 fprintf(output,"\t flags %lx\n",body[8]);
371 fprintf(output,"\t title height %ld\n",(long)body[9]);
372 fprintf(output,"\t border width %ld\n",(long)body[10]);
373 fprintf(output,"\t window base width %ld\n",(long)body[11]);
374 fprintf(output,"\t window base height %ld\n",(long)body[12]);
375 fprintf(output,"\t window resize width increment %ld\n",(long)body[13]);
376 fprintf(output,"\t window resize height increment %ld\n",(long)body[14]);
377 fprintf(output,"\t window min width %ld\n",(long)body[15]);
378 fprintf(output,"\t window min height %ld\n",(long)body[16]);
379 fprintf(output,"\t window max %ld\n",(long)body[17]);
380 fprintf(output,"\t window max %ld\n",(long)body[18]);
381 fprintf(output,"\t icon label window %lx\n",body[19]);
382 fprintf(output,"\t icon pixmap window %lx\n",body[20]);
383 fprintf(output,"\t window gravity %lx\n",body[21]);
384 fflush(output);
389 * Procedure:
390 * list_new_page - displays packet contents to output
393 void list_new_page(const unsigned long *body)
395 fprintf(output,"\t x %ld\n",(long)body[0]);
396 fprintf(output,"\t y %ld\n",(long)body[1]);
397 fprintf(output,"\t desk %ld\n",(long)body[2]);
398 fflush(output);
403 * Procedure:
404 * list_new_desk - displays packet contents to output
407 void list_new_desk(const unsigned long *body)
409 fprintf(output,"\t desk %ld\n",(long)body[0]);
410 fflush(output);
415 * Procedure:
416 * list_focus - displays packet contents to output
419 void list_focus(const unsigned long *body)
421 fprintf(output,"\t ID %lx\n",body[0]);
422 fprintf(output,"\t frame ID %lx\n",body[1]);
423 fprintf(output,"\t focus not by builtin %lx\n",body[2]);
424 fflush(output);
429 * Procedure:
430 * list_winid - displays packet contents to for three-field
431 * window ID-bearing packets
434 void list_winid(const unsigned long *body)
436 fprintf(output,"\t ID %lx\n",body[0]);
437 fprintf(output,"\t frame ID %lx\n",body[1]);
438 fprintf(output,"\t fvwm ptr %lx\n",body[2]);
439 fflush(output);
445 * Procedure:
446 * list_unknown - handles an unrecognized packet.
449 void list_unknown(const unsigned long *body)
451 (void)body;
452 fprintf(output,"Unknown packet type");
453 fflush(output);
458 * Procedure:
459 * list_iconify - displays packet contents to output
462 void list_icon(const unsigned long *body)
464 fprintf(output,"\t ID %lx\n",body[0]);
465 fprintf(output,"\t frame ID %lx\n",body[1]);
466 fprintf(output,"\t fvwm ptr %lx\n",body[2]);
467 fprintf(output,"\t icon x %ld\n",(long)body[3]);
468 fprintf(output,"\t icon y %ld\n",(long)body[4]);
469 fprintf(output,"\t icon w %ld\n",(long)body[5]);
470 fprintf(output,"\t icon h %ld\n",(long)body[6]);
471 fflush(output);
476 * Procedure:
477 * list_window_name - displays packet contents to output
481 void list_window_name(const unsigned long *body)
483 fprintf(output,"\t ID %lx\n",body[0]);
484 fprintf(output,"\t frame ID %lx\n",body[1]);
485 fprintf(output,"\t fvwm ptr %lx\n",body[2]);
486 fprintf(output,"\t name %s\n",(const char *)(&body[3]));
487 fflush(output);
492 * Procedure:
493 * list_restack - displays packet contents to output
497 void list_restack(const unsigned long *body)
499 int i = 3;
501 fprintf(output,"\t Restack beginning with:\n");
502 fprintf(output,"\t\tID %lx\n",body[0]);
503 fprintf(output,"\t\tframe ID %lx\n",body[1]);
504 fprintf(output,"\t\tfvwm ptr %lx\n",body[2]);
506 while (body[i] != 0 && i<FvwmPacketBodyMaxSize)
508 fprintf(output,"\t Next window:\n");
509 fprintf(output,"\t\tID %lx\n",body[i]);
510 fprintf(output,"\t\tframe ID %lx\n",body[i+1]);
511 fprintf(output,"\t\tfvwm ptr %lx\n",body[i+2]);
512 i += 3;
514 fflush(output);
519 * Procedure:
520 * list_error - displays packet contents to output
524 void list_error(const unsigned long *body)
526 fprintf(output,"\t %s\n",(const char *)(&body[3]));
527 fflush(output);
532 * Procedure:
533 * list_configure - displays packet contents to output
536 void list_configure(const unsigned long *body)
538 struct ConfigWinPacket *p = (void *)body;
540 fprintf(output,"\t ID %lx\n",p->w);
541 fprintf(output,"\t frame ID %lx\n",p->frame);
542 fprintf(output,"\t fvwm ptr %lx\n",(unsigned long)p->fvwmwin);
543 fprintf(output,"\t frame x %ld\n",p->frame_x);
544 fprintf(output,"\t frame y %ld\n",p->frame_y);
545 fprintf(output,"\t frame w %ld\n",p->frame_width);
546 fprintf(output,"\t frame h %ld\n",p->frame_height);
547 fprintf(output,"\t desk %ld\n",p->desk);
548 fprintf(output,"\t layer %ld\n",p->layer);
549 fprintf(output,"\t title height %hd\n",p->title_height);
550 fprintf(output,"\t border width %hd\n",p->border_width);
551 fprintf(output,"\t window base width %ld\n",p->hints_base_width);
552 fprintf(output,"\t window base height %ld\n",p->hints_base_height);
553 fprintf(output,"\t window resize width increment %ld\n",p->hints_width_inc);
554 fprintf(output,"\t window resize height increment %ld\n",p->hints_height_inc);
555 fprintf(output,"\t window min width %ld\n",p->hints_min_width);
556 fprintf(output,"\t window min height %ld\n",p->hints_min_height);
557 fprintf(output,"\t window max width %ld\n",p->hints_max_width);
558 fprintf(output,"\t window max height %ld\n",p->hints_max_height);
559 fprintf(output,"\t icon label window %lx\n",p->icon_w);
560 fprintf(output,"\t icon pixmap window %lx\n",p->icon_pixmap_w);
561 fprintf(output,"\t window gravity %lx\n",p->hints_win_gravity);
562 fprintf(output,"\t forecolor %lx\n",p->TextPixel);
563 fprintf(output,"\t backcolor %lx\n",p->BackPixel);
564 if (verbose)
566 fprintf(output,"\t Packet flags\n");
567 fprintf(output,"\t\tis_sticky: %d\n",IS_STICKY(p));
568 fprintf(output,"\t\thas_icon_font: %d\n",HAS_ICON_FONT(p));
569 fprintf(output,"\t\thas_window_font: %d\n",HAS_WINDOW_FONT(p));
570 fprintf(output,"\t\tdo_circulate_skip: %d\n",DO_SKIP_CIRCULATE(p));
571 fprintf(output,"\t\tdo_circulate_skip_icon: %d\n",
572 DO_SKIP_ICON_CIRCULATE(p));
573 fprintf(output,"\t\tdo_circulate_skip_shaded: %d\n",
574 DO_SKIP_SHADED_CIRCULATE(p));
575 fprintf(output,"\t\tdo_grab_focus_when_created: %d\n",
576 FP_DO_GRAB_FOCUS(FW_FOCUS_POLICY(p)));
577 fprintf(output,"\t\tdo_grab_focus_when_transient_created: %d\n",
578 FP_DO_GRAB_FOCUS_TRANSIENT(FW_FOCUS_POLICY(p)));
579 fprintf(output,"\t\tdo_ignore_restack: %d\n", DO_IGNORE_RESTACK(p));
580 fprintf(output,"\t\tdo_lower_transient: %d\n", DO_LOWER_TRANSIENT(p));
581 fprintf(output,"\t\tdo_not_show_on_map: %d\n", DO_NOT_SHOW_ON_MAP(p));
582 fprintf(output,"\t\tdo_not_pass_click_focus_click: %d\n",
583 FP_DO_PASS_FOCUS_CLICK( FW_FOCUS_POLICY(p) ) );
584 fprintf(output,"\t\tdo_raise_transient: %d\n", DO_RAISE_TRANSIENT(p));
585 fprintf(output,"\t\tdo_resize_opaque: %d\n", DO_RESIZE_OPAQUE(p));
586 fprintf(output,"\t\tdo_shrink_windowshade: %d\n", DO_SHRINK_WINDOWSHADE(p));
587 fprintf(output,"\t\tdo_stack_transient_parent: %d\n",
588 DO_STACK_TRANSIENT_PARENT(p));
589 fprintf(output,"\t\tdo_window_list_skip: %d\n", DO_SKIP_WINDOW_LIST(p));
590 fprintf(output,"\t\thas_depressable_border: %d\n",
591 HAS_DEPRESSABLE_BORDER(p));
592 fprintf(output,"\t\thas_mwm_border: %d\n", HAS_MWM_BORDER(p));
593 fprintf(output,"\t\thas_mwm_buttons: %d\n", HAS_MWM_BUTTONS(p));
594 fprintf(output,"\t\thas_mwm_override: %d\n", HAS_MWM_OVERRIDE_HINTS(p));
595 fprintf(output,"\t\thas_no_icon_title: %d\n", HAS_NO_ICON_TITLE(p));
596 fprintf(output,"\t\thas_override_size: %d\n", HAS_OVERRIDE_SIZE_HINTS(p));
597 fprintf(output,"\t\thas_stippled_title: %d\n", HAS_STIPPLED_TITLE(p));
598 fprintf(output,"\t\tis_fixed: %d\n", IS_FIXED(p));
599 fprintf(output,"\t\tis_sticky_icon: %d\n", IS_ICON_STICKY(p));
600 fprintf(output,"\t\tis_icon_suppressed: %d\n", IS_ICON_SUPPRESSED(p));
601 fprintf(output,"\t\tis_lenient: %d\n",
602 FP_IS_LENIENT( FW_FOCUS_POLICY(p) ));
603 fprintf(output,"\t\tdoes_wm_delete_window: %d\n", WM_DELETES_WINDOW(p));
604 fprintf(output,"\t\tdoes_wm_take_focus: %d\n", WM_TAKES_FOCUS(p));
605 fprintf(output,"\t\tdo_iconify_after_map: %d\n", DO_ICONIFY_AFTER_MAP(p));
606 fprintf(output,"\t\tdo_reuse_destroyed: %d\n", DO_REUSE_DESTROYED(p));
607 fprintf(output,"\t\thas_border: %d\n", !HAS_NO_BORDER(p));
608 fprintf(output,"\t\thas_title: %d\n", HAS_TITLE(p));
609 fprintf(output,"\t\tis_iconify_pending: %d\n", IS_ICONIFY_PENDING(p));
610 fprintf(output,"\t\tis_fully_visible: %d\n", IS_FULLY_VISIBLE(p));
611 fprintf(output,"\t\tis_iconified: %d\n", IS_ICONIFIED(p));
612 fprintf(output,"\t\tis_iconfied_by_parent: %d\n",
613 IS_ICONIFIED_BY_PARENT(p));
614 fprintf(output,"\t\tis_icon_entered: %d\n", IS_ICON_ENTERED(p));
615 fprintf(output,"\t\tis_icon_font_loaded: %d\n", IS_ICON_FONT_LOADED(p));
616 fprintf(output,"\t\tis_icon_moved: %d\n", IS_ICON_MOVED(p));
617 fprintf(output,"\t\tis_icon_ours: %d\n", IS_ICON_OURS(p));
618 fprintf(output,"\t\tis_icon_shaped: %d\n", IS_ICON_SHAPED(p));
619 fprintf(output,"\t\tis_icon_unmapped: %d\n", IS_ICON_UNMAPPED(p));
620 fprintf(output,"\t\tis_mapped: %d\n", IS_MAPPED(p));
621 fprintf(output,"\t\tis_map_pending: %d\n", IS_MAP_PENDING(p));
622 fprintf(output,"\t\tis_maximized: %d\n", IS_MAXIMIZED(p));
623 fprintf(output,"\t\tis_name_changed: %d\n", IS_NAME_CHANGED(p));
624 fprintf(output,"\t\tis_partially_visible: %d\n", IS_PARTIALLY_VISIBLE(p));
625 fprintf(output,"\t\tis_pixmap_ours: %d\n", IS_PIXMAP_OURS(p));
626 fprintf(output,"\t\tis_placed_wb3: %d\n", IS_PLACED_WB3(p));
627 fprintf(output,"\t\tis_placed_by_fvwm: %d\n", IS_PLACED_BY_FVWM(p));
628 fprintf(output,"\t\tis_size_inc_set: %d\n", IS_SIZE_INC_SET(p));
629 fprintf(output,"\t\tis_transient: %d\n", IS_TRANSIENT(p));
630 fprintf(output,"\t\tis_window_drawn_once: %d\n", IS_WINDOW_DRAWN_ONCE(p));
631 fprintf(output,"\t\tis_viewport_moved: %d\n", IS_VIEWPORT_MOVED(p));
632 fprintf(output,"\t\tis_window_being_moved_opaque: %d\n",
633 IS_WINDOW_BEING_MOVED_OPAQUE(p));
634 fprintf(output,"\t\tis_window_font_loaded: %d\n", IS_WINDOW_FONT_LOADED(p));
635 fprintf(output,"\t\tis_window_shaded %d\n", IS_SHADED(p));
636 fprintf(output,"\t\ttitle_dir: %d\n", GET_TITLE_DIR(p));
637 fflush(output);