aboutsummaryrefslogtreecommitdiffstats
path: root/menu.c
diff options
context:
space:
mode:
authorokan2012-10-23 15:32:38 +0000
committerokan2012-10-23 15:32:38 +0000
commitaf4604f740e5a494de8226697fbe0e942a1fbe45 (patch)
treed563cbadb14317a18d209c7db227fd35024e1b93 /menu.c
parent0e921af581eb2c54d6c706a9730bac1114304d0b (diff)
downloadcwm-af4604f740e5a494de8226697fbe0e942a1fbe45.tar.gz
Stop drawing when menu doesn't fit inside the screen; picked from a
larger diff from Alexander Polakov.
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/menu.c b/menu.c
index 3423d6e..219431a 100644
--- a/menu.c
+++ b/menu.c
@@ -16,7 +16,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: menu.c,v 1.36 2012/08/07 14:05:49 okan Exp $
+ * $OpenBSD: menu.c,v 1.37 2012/10/23 15:32:38 okan Exp $
*/
#include <sys/param.h>
@@ -387,9 +387,14 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
TAILQ_FOREACH(mi, resultq, resultentry) {
char *text = mi->print[0] != '\0' ?
mi->print : mi->text;
+ int y = n * font_height(sc) + font_ascent(sc) + 1;
+
+ /* Stop drawing when menu doesn't fit inside the screen. */
+ if (mc->y + y > ymax)
+ break;
font_draw(sc, text, MIN(strlen(text), MENU_MAXENTRY),
- sc->menuwin, 0, n * font_height(sc) + font_ascent(sc) + 1);
+ sc->menuwin, 0, y);
n++;
}