summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/events.c74
-rw-r--r--src/input.c2
-rw-r--r--src/list.c8
-rw-r--r--src/main.c68
-rw-r--r--src/manage.c22
-rw-r--r--src/number.c4
-rw-r--r--src/ratpoison.h15
7 files changed, 120 insertions, 73 deletions
diff --git a/src/events.c b/src/events.c
index a835eb3..a4f3ce7 100644
--- a/src/events.c
+++ b/src/events.c
@@ -41,16 +41,14 @@ spawn(char *prog)
if (fork() == 0) {
putenv(DisplayString(dpy));
execlp(prog, prog, 0);
- fprintf(stderr, "ratpoison: exec %s ", prog);
+ fprintf (stderr, "exec %s ", prog);
perror(" failed");
exit(EXIT_FAILURE);
}
exit(0);
}
wait((int *) 0);
-#ifdef DEBUG
- printf ("spawned %s\n", prog);
-#endif
+ PRINT_DEBUG ("spawned %s\n", prog);
}
void
@@ -115,7 +113,7 @@ map_request (XEvent *ev)
}
else
{
- printf ("Not managed.\n");
+ PRINT_DEBUG ("Not managed.\n");
XMapWindow (dpy, ev->xmap.window);
}
}
@@ -151,7 +149,7 @@ destroy_window (XDestroyWindowEvent *ev)
/* Goto the last accessed window. */
if (win == rp_current_window)
{
- printf ("Destroying current window.\n");
+ PRINT_DEBUG ("Destroying current window.\n");
/* tell ratpoison to switch to the last window when all the
destroy events have been delt with. */
@@ -160,7 +158,7 @@ destroy_window (XDestroyWindowEvent *ev)
}
else
{
- printf ("Destroying some other window.\n");
+ PRINT_DEBUG ("Destroying some other window.\n");
unmanage (win);
}
}
@@ -226,7 +224,7 @@ delete_window ()
ev.xclient.data.l[1] = CurrentTime;
status = XSendEvent(dpy, rp_current_window->w, False, 0, &ev);
- if (status == 0) fprintf(stderr, "ratpoison: XSendEvent failed\n");
+ if (status == 0) fprintf(stderr, "ratpoison: delete window failed\n");
}
void
@@ -240,7 +238,7 @@ kill_window ()
static void
client_msg (XClientMessageEvent *ev)
{
- printf ("Recieved client message.\n");
+ PRINT_DEBUG ("Recieved client message.\n");
}
static void
@@ -249,7 +247,7 @@ goto_win_by_name (screen_info *s)
char winname[100];
get_input (s, "Window: ", winname, 100);
- printf ("user entered: %s\n", winname);
+ PRINT_DEBUG ("user entered: %s\n", winname);
goto_window_name (winname);
}
@@ -262,9 +260,7 @@ handle_key (screen_info *s)
XEvent ev;
int keysym;
-#ifdef DEBUG
- printf ("handling key.\n");
-#endif
+ PRINT_DEBUG ("handling key.\n");
XGetInputFocus (dpy, &fwin, &revert);
XSetInputFocus (dpy, s->key_window, RevertToPointerRoot, CurrentTime);
@@ -327,7 +323,7 @@ handle_key (screen_info *s)
else delete_window ();
break;
default:
- fprintf (stderr, "Unknown key command '%c'\n", (char)keysym);
+ PRINT_DEBUG ("Unknown key command '%c'\n", (char)keysym);
break;
}
}
@@ -352,7 +348,7 @@ property_notify (XEvent *ev)
{
rp_window *win;
- printf ("atom: %ld\n", ev->xproperty.atom);
+ PRINT_DEBUG ("atom: %ld\n", ev->xproperty.atom);
win = find_window (ev->xproperty.window);
@@ -360,7 +356,7 @@ property_notify (XEvent *ev)
{
if (ev->xproperty.atom == XA_WM_NAME)
{
- printf ("updating window name\n");
+ PRINT_DEBUG ("updating window name\n");
if (update_window_name (win))
{
update_window_names (win->scr);
@@ -376,85 +372,85 @@ delegate_event (XEvent *ev)
switch (ev->type)
{
case ConfigureRequest:
- printf ("ConfigureRequest\n");
+ PRINT_DEBUG ("ConfigureRequest\n");
configure_request (&ev->xconfigurerequest);
break;
case CirculateRequest:
- printf ("CirculateRequest\n");
+ PRINT_DEBUG ("CirculateRequest\n");
break;
case CreateNotify:
- printf ("CreateNotify\n");
+ PRINT_DEBUG ("CreateNotify\n");
new_window (&ev->xcreatewindow);
break;
case DestroyNotify:
- printf ("DestroyNotify\n");
+ PRINT_DEBUG ("DestroyNotify\n");
destroy_window (&ev->xdestroywindow);
break;
case ClientMessage:
+ PRINT_DEBUG ("ClientMessage\n");
client_msg (&ev->xclient);
- printf ("ClientMessage\n");
break;
case ColormapNotify:
- printf ("ColormapNotify\n");
+ PRINT_DEBUG ("ColormapNotify\n");
break;
case PropertyNotify:
- printf ("PropertyNotify\n");
+ PRINT_DEBUG ("PropertyNotify\n");
property_notify (ev);
break;
case SelectionClear:
- printf ("SelectionClear\n");
+ PRINT_DEBUG ("SelectionClear\n");
break;
case SelectionNotify:
- printf ("SelectionNotify\n");
+ PRINT_DEBUG ("SelectionNotify\n");
break;
case SelectionRequest:
- printf ("SelectionRequest\n");
+ PRINT_DEBUG ("SelectionRequest\n");
break;
case EnterNotify:
- printf ("EnterNotify\n");
+ PRINT_DEBUG ("EnterNotify\n");
break;
case ReparentNotify:
- printf ("ReparentNotify\n");
+ PRINT_DEBUG ("ReparentNotify\n");
break;
case FocusIn:
- printf ("FocusIn\n");
+ PRINT_DEBUG ("FocusIn\n");
break;
case MapRequest:
- printf ("MapRequest\n");
+ PRINT_DEBUG ("MapRequest\n");
map_request (ev);
break;
case KeyPress:
- printf ("KeyPress\n");
+ PRINT_DEBUG ("KeyPress\n");
key_press (ev);
break;
case UnmapNotify:
- printf ("UnmapNotify\n");
+ PRINT_DEBUG ("UnmapNotify\n");
unmap_notify (ev);
break;
case MotionNotify:
- printf ("MotionNotify\n");
+ PRINT_DEBUG ("MotionNotify\n");
break;
case Expose:
- printf ("Expose\n");
+ PRINT_DEBUG ("Expose\n");
break;
case FocusOut:
- printf ("FocusOut\n");
+ PRINT_DEBUG ("FocusOut\n");
break;
case ConfigureNotify:
- printf ("ConfigureNotify\n");
+ PRINT_DEBUG ("ConfigureNotify\n");
break;
case MapNotify:
- printf ("MapNotify\n");
+ PRINT_DEBUG ("MapNotify\n");
break;
case MappingNotify:
- printf ("MappingNotify\n");
+ PRINT_DEBUG ("MappingNotify\n");
break;
default:
- printf ("Unhandled event %d\n", ev->type);
+ PRINT_DEBUG ("Unhandled event %d\n", ev->type);
}
}
diff --git a/src/input.c b/src/input.c
index ad8f093..222e3e6 100644
--- a/src/input.c
+++ b/src/input.c
@@ -48,7 +48,7 @@ get_input (screen_info *s, char *prompt, char *str, int len)
cur_len = 0;
while ((ch = read_key ()) != XK_Return)
{
- printf ("key %d\n", ch);
+ PRINT_DEBUG ("key %d\n", ch);
if (ch == XK_BackSpace)
{
if (cur_len > 0) cur_len--;
diff --git a/src/list.c b/src/list.c
index ee04b34..0393923 100644
--- a/src/list.c
+++ b/src/list.c
@@ -35,7 +35,7 @@ add_to_window_list (screen_info *s, Window w)
new_window = malloc (sizeof (rp_window));
if (new_window == NULL)
{
- fprintf (stderr, "list.c:add_to_window_list():Out of memory!\n");
+ PRINT_ERROR ("Out of memory!\n");
exit (EXIT_FAILURE);
}
new_window->w = w;
@@ -48,7 +48,7 @@ add_to_window_list (screen_info *s, Window w)
if ((new_window->name = malloc (strlen ("Unnamed") + 1)) == NULL)
{
- fprintf (stderr, "list.c:add_to_window_list():Out of memory.\n");
+ PRINT_ERROR ("Out of memory!\n");
exit (EXIT_FAILURE);
}
strcpy (new_window->name, "Unnamed");
@@ -96,9 +96,7 @@ remove_from_window_list (rp_window *w)
if (rp_current_window == w) rp_current_window = NULL;
free (w);
-#ifdef DEBUG
- printf ("Removed window from list.\n");
-#endif
+ PRINT_DEBUG ("Removed window from list.\n");
}
void
diff --git a/src/main.c b/src/main.c
index 313d7fc..39856f7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
+#include <getopt.h>
#include "ratpoison.h"
@@ -49,6 +50,12 @@ static XFontStruct *font;
char **myargv;
+/* Command line options */
+static struct option ratpoison_longopts[] = { {"help", no_argument, 0, 'h'},
+ {"version", no_argument, 0, 'v'},
+ {0, 0, 0, 0} };
+static char ratpoison_opts[] = "hv";
+
void
sighandler ()
{
@@ -72,9 +79,7 @@ alrm_handler ()
{
int i;
-#ifdef DEBUG
- printf ("alarm recieved.\n");
-#endif
+ PRINT_DEBUG ("alarm recieved.\n");
/* FIXME: should only hide 1 bar, but we hide them all. */
for (i=0; i<num_screens; i++)
@@ -101,13 +106,54 @@ handler (Display *d, XErrorEvent *e)
// exit (EXIT_FAILURE);
}
+void
+print_version ()
+{
+ printf ("%s %s\n", PACKAGE, VERSION);
+ printf ("Copyright (C) 2000 Shawn Betts\n\n");
+
+ exit (EXIT_SUCCESS);
+}
+
+void
+print_help ()
+{
+ printf ("Help for %s %s\n\n", PACKAGE, VERSION);
+ printf ("-h, --help Display this help screen\n");
+ printf ("-v, --version Display the version\n\n");
+
+ printf ("Report bugs to ratpoison-devel@lists.sourceforge.net\n\n");
+
+ exit (EXIT_SUCCESS);
+}
+
int
main (int argc, char *argv[])
{
int i;
+ int c;
myargv = argv;
+ /* Parse the arguments */
+ while (1)
+ {
+ int option_index = 0;
+
+ c = getopt_long (argc, argv, ratpoison_opts, ratpoison_longopts, &option_index);
+ if (c == -1) break;
+
+ switch (c)
+ {
+ case 'h':
+ print_help ();
+ break;
+ case 'v':
+ print_version ();
+ break;
+ }
+ }
+
if (!(dpy = XOpenDisplay (NULL)))
{
fprintf (stderr, "Can't open display\n");
@@ -119,11 +165,7 @@ main (int argc, char *argv[])
if (signal (SIGALRM, alrm_handler) == SIG_IGN) signal (SIGALRM, SIG_IGN);
if (signal (SIGTERM, sighandler) == SIG_IGN) signal (SIGTERM, SIG_IGN);
if (signal (SIGINT, sighandler) == SIG_IGN) signal (SIGINT, SIG_IGN);
- if (signal (SIGHUP, hup_handler) == SIG_IGN)
- {
- printf ("Ignoring HUP.\n");
- signal (SIGHUP, SIG_IGN);
- }
+ if (signal (SIGHUP, hup_handler) == SIG_IGN) signal (SIGHUP, SIG_IGN);
init_numbers ();
init_window_list ();
@@ -138,11 +180,11 @@ main (int argc, char *argv[])
num_screens = ScreenCount (dpy);
if ((screens = (screen_info *)malloc (sizeof (screen_info) * num_screens)) == NULL)
{
- fprintf (stderr, "ratpoison:main.c:Out of memory!\n");
+ PRINT_ERROR ("Out of memory!\n");
exit (EXIT_FAILURE);
}
- printf ("%d screens.\n", num_screens);
+ PRINT_DEBUG ("%d screens.\n", num_screens);
/* Initialize the screens */
for (i=0; i<num_screens; i++)
@@ -186,17 +228,17 @@ init_screen (screen_info *s, int screen_num)
/* Get our program bar colors */
if (!XAllocNamedColor (dpy, s->def_cmap, BAR_FG_COLOR, &fg_color, &junk))
{
- fprintf (stderr, "Unknown color '%s'\n", BAR_FG_COLOR);
+ fprintf (stderr, "ratpoison: Unknown color '%s'\n", BAR_FG_COLOR);
}
if (!XAllocNamedColor (dpy, s->def_cmap, BAR_BG_COLOR, &bg_color, &junk))
{
- fprintf (stderr, "Unknown color '%s'\n", BAR_BG_COLOR);
+ fprintf (stderr, "ratpoison: Unknown color '%s'\n", BAR_BG_COLOR);
}
if (!XAllocNamedColor (dpy, s->def_cmap, BAR_BOLD_COLOR, &bold_color, &junk))
{
- fprintf (stderr, "Unknown color '%s'\n", BAR_BOLD_COLOR);
+ fprintf (stderr, "ratpoison: Unknown color '%s'\n", BAR_BOLD_COLOR);
}
/* Setup the GC for drawing the font. */
diff --git a/src/manage.c b/src/manage.c
index 592e391..90a3a2c 100644
--- a/src/manage.c
+++ b/src/manage.c
@@ -53,20 +53,22 @@ update_window_name (rp_window *win)
if (!XGetWMName (dpy, win->w, &text))
{
- fprintf (stderr, "ratpoison:manage.c: I can't get the WMName.\n");
+ PRINT_DEBUG ("I can't get the WMName.\n");
return 0;
}
if (!XTextPropertyToStringList (&text, &name_list, &list_len))
{
- fprintf (stderr, "ratpoison:manage.c:Error retrieving TextList.\n");
+ PRINT_DEBUG ("Error retrieving TextList.\n");
return 0;
}
+#ifdef DEBUG
for (i=0; i<list_len; i++)
{
- printf ("WMName: %s\n", name_list[i]);
+ PRINT_DEBUG ("WMName: %s\n", name_list[i]);
}
+#endif /* DEBUG */
/* Set the window's name to the first in the name_list */
if (list_len > 0)
@@ -76,7 +78,7 @@ update_window_name (rp_window *win)
free (win->name);
if ((win->name = malloc (strlen (name_list[0]) + 1)) == NULL)
{
- fprintf (stderr, "manage.c:update_window_name():Out of memory!\n");
+ PRINT_ERROR ("Out of memory!\n");
exit (EXIT_FAILURE);
}
strcpy (win->name, name_list[0]);
@@ -103,13 +105,13 @@ rename_current_window ()
if (rp_current_window == NULL) return;
get_input (rp_current_window->scr, "Name: ", winname, 100);
- printf ("user entered: %s\n", winname);
+ PRINT_DEBUG ("user entered: %s\n", winname);
free (rp_current_window->name);
rp_current_window->name = malloc (sizeof (char) * strlen (winname) + 1);
if (rp_current_window->name == NULL)
{
- fprintf (stderr, "ratpoison:rename_window(): Out of memory\n");
+ PRINT_ERROR ("Out of memory\n");
exit (EXIT_FAILURE);
}
strcpy (rp_current_window->name, winname);
@@ -134,9 +136,7 @@ manage (rp_window *win, screen_info *s)
win->state = STATE_MAPPED;
win->number = get_unique_window_number ();
-#ifdef DEBUG
- printf ("window '%s' managed.\n", win->name);
-#endif
+ PRINT_DEBUG ("window '%s' managed.\n", win->name);
}
void
@@ -156,9 +156,7 @@ scanwins(screen_info *s)
Window dw1, dw2, *wins;
XQueryTree(dpy, s->root, &dw1, &dw2, &wins, &nwins);
-#ifdef DEBUG
- printf ("windows: %d\n", nwins);
-#endif
+ PRINT_DEBUG ("windows: %d\n", nwins);
for (i = 0; i < nwins; i++)
{
diff --git a/src/number.c b/src/number.c
index 6bd11c6..1d46e45 100644
--- a/src/number.c
+++ b/src/number.c
@@ -63,7 +63,7 @@ find_empty_cell ()
numbers_taken = realloc (numbers_taken, sizeof (int) * max_taken);
if (numbers_taken == NULL)
{
- fprintf (stderr, "numbers.c: Out of memory\n");
+ PRINT_ERROR ("Out of memory\n");
exit (EXIT_FAILURE);
}
}
@@ -123,7 +123,7 @@ init_numbers ()
numbers_taken = malloc (max_taken * sizeof (int));
if (numbers_taken == NULL)
{
- fprintf (stderr, "numbers.c: Cannot alloc numbers_taken.\n");
+ PRINT_ERROR ("Cannot allocate memory for numbers_taken.\n");
exit (EXIT_FAILURE);
}
diff --git a/src/ratpoison.h b/src/ratpoison.h
index 8b83866..089fcb9 100644
--- a/src/ratpoison.h
+++ b/src/ratpoison.h
@@ -21,9 +21,22 @@
#define _RATPOISON_H
#ifdef HAVE_CONFIG_H
-# include "config.h"
+# include <config.h>
#endif /* HAVE_CONFIG_H */
+/* Some error reporting macros */
+#define PRE_PRINT_LOCATION fprintf (stderr, "%s:%s():%d: ", __FILE__, __FUNCTION__, __LINE__);
+#define PRINT_ERROR(format, args...) \
+ { fprintf (stderr, PACKAGE ":error -- "); PRE_PRINT_LOCATION; fprintf (stderr, format, ## args); }
+
+/* Some debugging macros */
+#ifdef DEBUG
+# define PRINT_DEBUG(format, args...) \
+ { fprintf (stderr, PACKAGE ":debug -- "); PRE_PRINT_LOCATION; fprintf (stderr, format, ## args); }
+#else
+# define PRINT_DEBUG(format, args...)
+#endif /* DEBUG */
+
#include "conf.h"
#include "data.h"