summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOkan Demirmen <okan@cvs.openbsd.org>2012-10-23 15:32:39 +0000
committerOkan Demirmen <okan@cvs.openbsd.org>2012-10-23 15:32:39 +0000
commit31479c45513eeafb4654193c0d6d14e3ced84256 (patch)
tree48f2548ec9a0d7a8e65e52977c3fe4eb5b486704
parentd4951790dec719507d9115477c792128e39f5601 (diff)
Stop drawing when menu doesn't fit inside the screen; picked from a
larger diff from Alexander Polakov.
-rw-r--r--app/cwm/menu.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/app/cwm/menu.c b/app/cwm/menu.c
index 3423d6e05..219431a98 100644
--- a/app/cwm/menu.c
+++ b/app/cwm/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++;
}