wmmisc: Add support for wmgeneral's -display command line argument
[dockapps.git] / wmmisc / src / dockapp_main.c
blobbc014d5fcc29bdd00d468b4b28b426521a7725ce
1 /*
2 * wmmisc - WindowMaker Dockapp for monitoring misc. information.
3 * Copyright (C) 2003-2006 Jesse S. (luxorfalls@sbcglobal.net)
5 * wmmisc is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * wmmisc is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with wmmisc; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <getopt.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <bits/getopt_core.h>
26 #include <signal.h>
28 #ifdef USE_MTRACE
29 #include <mcheck.h>
30 #endif /* USE_MTRACE */
32 #include <libdockapp/wmgeneral.h>
34 #include "wmmisc-master.xpm"
35 #include "dockapp_main.h"
36 #include "dockapp_draw.h"
38 void
39 dockapp_show_help( const char* wm_name )
41 printf( "Usage: %s [OPTION]...\n", wm_name );
42 printf( "This is a simple WindowMaker 'DockApp' that will monitor the following:\n" );
43 printf( "Number of users logged in, total processes, total number of processes running,\n" );
44 printf( "the system's fork count and load average.\n\n" );
45 printf( " -h display this help and exit\n" );
46 printf( " -v output version information and exit\n" );
47 printf( " -display DISPLAY set display\n\n");
48 printf( "Report bugs to <" PACKAGE_BUGREPORT ">.\n" );
51 void
52 dockapp_show_version( void )
54 printf( "%s\n", PACKAGE_STRING);
55 printf( "Written by %s <%s>\n\n", DOCKAPP_AUTHOR, DOCKAPP_AUTHOR_EMAIL );
56 printf( "Copyright (C) 2003-2006 %s\n", DOCKAPP_AUTHOR );
57 printf( "This is free software; see the source for copying conditions. There is NO\n" );
58 printf( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" );
61 void
62 dockapp_exit( int signal_received )
64 #ifdef USE_MTRACE
65 muntrace();
66 #endif /* USE_MTRACE */
68 #ifdef DEBUG
69 fprintf( stderr,
70 "%s: Exiting cleanly with signal %d\n",
71 DOCKAPP_NAME,
72 signal_received );
73 #endif /* DEBUG */
75 exit( 0 );
78 void
79 dockapp_crash( int signal_received )
81 fprintf( stderr,
82 "%s: got signal %d -- bailing out!\n",
83 DOCKAPP_NAME,
84 signal_received );
85 fprintf( stderr,
86 "It appears that %s has encountered an error.\n",
87 DOCKAPP_NAME );
88 fprintf( stderr,
89 "If this continues to happen, please run '%s core' from a debugger,\n",
90 DOCKAPP_NAME );
91 fprintf( stderr,
92 "such as gdb, and report the output to <%s>.\n",
93 PACKAGE_BUGREPORT );
95 abort();
98 int
99 main( int argc, char** argv )
101 int opt = 0;
102 const struct option longopts[] = {
103 {"display", required_argument, NULL, 0},
104 {0, 0, 0, 0}
107 #ifdef USE_MTRACE
108 mtrace();
109 #endif /* USE_MTRACE */
111 signal( SIGINT, dockapp_exit );
112 signal( SIGSEGV, dockapp_crash );
114 opt = getopt_long_only( argc, argv, "hv", longopts, NULL);
116 while ( -1 != opt )
118 switch ( opt )
120 case 'h':
122 dockapp_show_help( argv[0] );
123 exit( 1 );
124 /* Never reached. */
127 case 'v':
129 dockapp_show_version();
130 exit( 1 );
131 /* Never reached. */
135 opt = getopt_long_only( argc, argv, "hv", longopts, NULL);
138 createXBMfromXPM( wmmisc_mask_bits,
139 wmmisc_master_xpm,
140 wmmisc_mask_width,
141 wmmisc_mask_height );
143 openXwindow( argc,
144 argv,
145 wmmisc_master_xpm,
146 wmmisc_mask_bits,
147 wmmisc_mask_width,
148 wmmisc_mask_height );
150 RedrawWindow();
152 dockapp_draw_small_str( "USERS", 4, 4 );
153 dockapp_draw_small_str( "PROCS", 4, 11 );
154 dockapp_draw_small_str( "ACTIVE", 4, 18 );
156 dockapp_draw_small_str( "UP", 4, 28 );
157 dockapp_draw_small_str( "DAYS", 4, 37 );
158 dockapp_draw_small_str( "WEEKS", 4, 44 );
160 dockapp_draw_small_str( "LOAD", 4, 53 );
164 dockapp_draw_data();
165 usleep( 250000L );
166 } while( 1 );
168 return 0;