aboutsummaryrefslogtreecommitdiff
path: root/screen.c
diff options
context:
space:
mode:
Diffstat (limited to 'screen.c')
-rw-r--r--screen.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/screen.c b/screen.c
index 7bfc0154..c1df95ad 100644
--- a/screen.c
+++ b/screen.c
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $OpenBSD$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -32,12 +32,12 @@ void screen_resize_y(struct screen *, u_int);
void
screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit)
{
- char hn[MAXHOSTNAMELEN];
+ char host[HOST_NAME_MAX+1];
s->grid = grid_create(sx, sy, hlimit);
- if (gethostname(hn, MAXHOSTNAMELEN) == 0)
- s->title = xstrdup(hn);
+ if (gethostname(host, sizeof(host)) == 0)
+ s->title = xstrdup(host);
else
s->title = xstrdup("");
@@ -216,8 +216,8 @@ screen_resize_y(struct screen *s, u_int sy)
}
/* Resize line arrays. */
- gd->linedata = xrealloc(
- gd->linedata, gd->hsize + sy, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, gd->hsize + sy,
+ sizeof *gd->linedata);
/* Size increasing. */
if (sy > oldy) {
@@ -270,6 +270,7 @@ screen_clear_selection(struct screen *s)
struct screen_sel *sel = &s->sel;
sel->flag = 0;
+ sel->lineflag = LINE_SEL_NONE;
}
/* Check if cell in selection. */
@@ -277,6 +278,7 @@ int
screen_check_selection(struct screen *s, u_int px, u_int py)
{
struct screen_sel *sel = &s->sel;
+ u_int xx;
if (!sel->flag)
return (0);
@@ -326,16 +328,24 @@ screen_check_selection(struct screen *s, u_int px, u_int py)
if (py < sel->sy || py > sel->ey)
return (0);
- if ((py == sel->sy && px < sel->sx)
- || (py == sel->ey && px > sel->ex))
+ if (py == sel->sy && px < sel->sx)
+ return (0);
+
+ if (py == sel->ey && px > sel->ex)
return (0);
} else if (sel->sy > sel->ey) {
/* starting line > ending line -- upward selection. */
if (py > sel->sy || py < sel->ey)
return (0);
- if ((py == sel->sy && px >= sel->sx)
- || (py == sel->ey && px < sel->ex))
+ if (py == sel->ey && px < sel->ex)
+ return (0);
+
+ if (sel->modekeys == MODEKEY_EMACS)
+ xx = sel->sx - 1;
+ else
+ xx = sel->sx;
+ if (py == sel->sy && px > xx)
return (0);
} else {
/* starting line == ending line. */
@@ -344,7 +354,11 @@ screen_check_selection(struct screen *s, u_int px, u_int py)
if (sel->ex < sel->sx) {
/* cursor (ex) is on the left */
- if (px > sel->sx || px < sel->ex)
+ if (sel->modekeys == MODEKEY_EMACS)
+ xx = sel->sx - 1;
+ else
+ xx = sel->sx;
+ if (px > xx || px < sel->ex)
return (0);
} else {
/* selection start (sx) is on the left */