summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsabetts <sabetts>2002-02-01 09:17:35 +0000
committersabetts <sabetts>2002-02-01 09:17:35 +0000
commit5ca712fc606b1839de5bcbe80833fa9d3a17332d (patch)
treea7daabf975a14649cbbaf4f054508b7ab59cd657 /src
parent7457d9f3ac419123239f0e02fbcdfd0db1013138 (diff)
downloadratpoison-5ca712fc606b1839de5bcbe80833fa9d3a17332d.zip
* src/actions.c (command): bail out if alias recursion gets too deep.
* src/conf.h (MAX_ALIAS_RECURSIVE_DEPTH): new define * src/bar.c (bar_x): update to work with all X11 gravity values. (bar_y): likewise * src/actions.c (cmd_defbargravity): Rename from cmd_defbarloc. Dependant code updated. (cmd_defbargravity): accept all gravity arguments.
Diffstat (limited to 'src')
-rw-r--r--src/actions.c35
-rw-r--r--src/actions.h2
-rw-r--r--src/bar.c56
-rw-r--r--src/conf.h4
4 files changed, 67 insertions, 30 deletions
diff --git a/src/actions.c b/src/actions.c
index e0d4188..bbb50b9 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -85,7 +85,7 @@ static user_command user_commands[] =
/*@end (tag required for genrpbindings) */
/* Commands to set default behavior. */
- {"defbarloc", cmd_defbarloc, arg_STRING},
+ {"defbargravity", cmd_defbargravity, arg_STRING},
{"msgwait", cmd_msgwait, arg_STRING},
{"defborder", cmd_defborder, arg_STRING},
{"deffont", cmd_deffont, arg_STRING},
@@ -840,6 +840,8 @@ cmd_version (int interactive, void *data)
char *
command (int interactive, char *data)
{
+ /* This static counter is used to exit from recursive alias calls. */
+ static int alias_recursive_depth = 0;
char *result = NULL;
char *cmd, *rest;
char *input;
@@ -894,7 +896,12 @@ command (int interactive, char *data)
if (rest != NULL)
sbuf_printf_concat (s, " %s", rest);
- result = command (interactive, sbuf_get (s));
+ alias_recursive_depth++;
+ if (alias_recursive_depth >= MAX_ALIAS_RECURSIVE_DEPTH)
+ message (" command: alias recursion has exceeded maximum depth ");
+ else
+ result = command (interactive, sbuf_get (s));
+ alias_recursive_depth--;
sbuf_free (s);
goto done;
@@ -1695,37 +1702,27 @@ cmd_msgwait (int interactive, void *data)
}
char *
-cmd_defbarloc (int interactive, void *data)
+cmd_defbargravity (int interactive, void *data)
{
- int loc;
+ int gravity;
if (data == NULL && !interactive)
return xstrdup (wingravity_to_string (defaults.bar_location));
if (data == NULL)
{
- message (" defbarloc: One argument required ");
+ message (" defbargravity: One argument required ");
return NULL;
}
- if ((loc = parse_wingravity (data)) < 0)
+ if ((gravity = parse_wingravity (data)) < 0)
{
- message (" defbarloc: Bad location ");
+ message (" defbargravity: Bad location ");
return NULL;
}
-
- switch (loc)
+ else
{
- case NorthWestGravity:
- case NorthEastGravity:
- case SouthWestGravity:
- case SouthEastGravity:
- defaults.bar_location = loc;
- break;
-
- default:
- message (" defbarloc: Bad location ");
- break;
+ defaults.bar_location = gravity;
}
return NULL;
diff --git a/src/actions.h b/src/actions.h
index 5f76206..a727254 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -80,7 +80,7 @@ char * cmd_defwingravity (int interactive, void *data);
char * cmd_deftransgravity (int interactive, void *data);
char * cmd_defmaxsizegravity (int interactive, void *data);
char * cmd_msgwait (int interactive, void *data);
-char * cmd_defbarloc (int interactive, void *data);
+char * cmd_defbargravity (int interactive, void *data);
char * cmd_deffont (int interactive, void *data);
char * cmd_defpadding (int interactive, void *data);
char * cmd_defborder (int interactive, void *data);
diff --git a/src/bar.c b/src/bar.c
index 44aeac9..617eee2 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -82,21 +82,57 @@ show_bar (screen_info *s)
int
bar_x (screen_info *s, int width)
{
- if (defaults.bar_location == SouthEastGravity
- || defaults.bar_location == NorthEastGravity)
- return s->root_attr.width - width - defaults.bar_border_width * 2;
- else
- return 0;
+ int x = 0;
+
+ switch (defaults.bar_location)
+ {
+ case NorthWestGravity:
+ case WestGravity:
+ case SouthWestGravity:
+ x = 0;
+ break;
+ case NorthGravity:
+ case CenterGravity:
+ case SouthGravity:
+ x = (s->root_attr.width - width - defaults.bar_border_width * 2) / 2;
+ break;
+ case NorthEastGravity:
+ case EastGravity:
+ case SouthEastGravity:
+ x = s->root_attr.width - width - defaults.bar_border_width * 2;
+ break;
+ }
+
+ return x;
}
int
bar_y (screen_info *s)
{
- if (defaults.bar_location == NorthWestGravity
- || defaults.bar_location == NorthEastGravity )
- return 0;
- else
- return s->root_attr.height - (FONT_HEIGHT (defaults.font) + defaults.bar_y_padding * 2) - defaults.bar_border_width * 2;
+ int y = 0;
+
+ switch (defaults.bar_location)
+ {
+ case NorthEastGravity:
+ case NorthGravity:
+ case NorthWestGravity:
+ y = 0;
+ break;
+ case EastGravity:
+ case CenterGravity:
+ case WestGravity:
+ y = (s->root_attr.height - (FONT_HEIGHT (defaults.font) + defaults.bar_y_padding * 2)
+ - defaults.bar_border_width * 2) / 2;
+ break;
+ case SouthEastGravity:
+ case SouthGravity:
+ case SouthWestGravity:
+ y = (s->root_attr.height - (FONT_HEIGHT (defaults.font) + defaults.bar_y_padding * 2)
+ - defaults.bar_border_width * 2);
+ break;
+ }
+
+ return y;
}
void
diff --git a/src/conf.h b/src/conf.h
index fbe1871..ed6d7c2 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -47,6 +47,10 @@
(don't hide the windows underneath, and center them) */
#define MAXSIZE_WINDOWS_ARE_TRANSIENTS
+/* An alias command could recursively call inself infinitely. This
+ stops that behavior. */
+#define MAX_ALIAS_RECURSIVE_DEPTH 16
+
/* Pressing a key sends the mouse to the bottom right corner. This
doesn't work very well yet. */
/* #define HIDE_MOUSE */