aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--st.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/st.c b/st.c
index 741e680..4dc1c5a 100644
--- a/st.c
+++ b/st.c
@@ -259,6 +259,7 @@ static void tsetattr(int*, int);
259static void tsetchar(char*); 259static void tsetchar(char*);
260static void tsetscroll(int, int); 260static void tsetscroll(int, int);
261static void tswapscreen(void); 261static void tswapscreen(void);
262static void tsetdirt(int, int);
262static void tfulldirt(void); 263static void tfulldirt(void);
263 264
264static void ttynew(void); 265static void ttynew(void);
@@ -446,8 +447,8 @@ utf8size(char *s) {
446 447
447void 448void
448selinit(void) { 449selinit(void) {
449 sel.tclick1.tv_sec = 0; 450 memset(&sel.tclick1, 0, sizeof(sel.tclick1));
450 sel.tclick1.tv_usec = 0; 451 memset(&sel.tclick2, 0, sizeof(sel.tclick2));
451 sel.mode = 0; 452 sel.mode = 0;
452 sel.bx = -1; 453 sel.bx = -1;
453 sel.clip = NULL; 454 sel.clip = NULL;
@@ -520,8 +521,7 @@ bpress(XEvent *e) {
520 mousereport(e); 521 mousereport(e);
521 else if(e->xbutton.button == Button1) { 522 else if(e->xbutton.button == Button1) {
522 if(sel.bx != -1) 523 if(sel.bx != -1)
523 for(int i=sel.b.y; i<=sel.e.y; i++) 524 tsetdirt(sel.b.y, sel.e.y);
524 term.dirty[i] = 1;
525 sel.mode = 1; 525 sel.mode = 1;
526 sel.ex = sel.bx = X2COL(e->xbutton.x); 526 sel.ex = sel.bx = X2COL(e->xbutton.x);
527 sel.ey = sel.by = Y2ROW(e->xbutton.y); 527 sel.ey = sel.by = Y2ROW(e->xbutton.y);
@@ -531,21 +531,28 @@ bpress(XEvent *e) {
531void 531void
532selcopy(void) { 532selcopy(void) {
533 char *str, *ptr; 533 char *str, *ptr;
534 int x, y, sz, sl, ls = 0; 534 int x, y, bufsize, is_selected = 0;
535 535
536 if(sel.bx == -1) 536 if(sel.bx == -1)
537 str = NULL; 537 str = NULL;
538
538 else { 539 else {
539 sz = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ; 540 bufsize = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ;
540 ptr = str = malloc(sz); 541 ptr = str = malloc(bufsize);
542
543 /* append every set & selected glyph to the selection */
541 for(y = 0; y < term.row; y++) { 544 for(y = 0; y < term.row; y++) {
542 for(x = 0; x < term.col; x++) 545 for(x = 0; x < term.col; x++) {
543 if(term.line[y][x].state & GLYPH_SET && (ls = selected(x, y))) { 546 is_selected = selected(x, y);
544 sl = utf8size(term.line[y][x].c); 547 if((term.line[y][x].state & GLYPH_SET) && is_selected) {
545 memcpy(ptr, term.line[y][x].c, sl); 548 int size = utf8size(term.line[y][x].c);
546 ptr += sl; 549 memcpy(ptr, term.line[y][x].c, size);
550 ptr += size;
547 } 551 }
548 if(ls && y < sel.e.y) 552 }
553
554 /* \n at the end of every selected line except for the last one */
555 if(is_selected && y < sel.e.y)
549 *ptr++ = '\n'; 556 *ptr++ = '\n';
550 } 557 }
551 *ptr = 0; 558 *ptr = 0;
@@ -687,8 +694,7 @@ bmotion(XEvent *e) {
687 if(oldey != sel.ey || oldex != sel.ex) { 694 if(oldey != sel.ey || oldex != sel.ex) {
688 int starty = MIN(oldey, sel.ey); 695 int starty = MIN(oldey, sel.ey);
689 int endy = MAX(oldey, sel.ey); 696 int endy = MAX(oldey, sel.ey);
690 for(int i = starty; i <= endy; i++) 697 tsetdirt(starty, endy);
691 term.dirty[i] = 1;
692 draw(); 698 draw();
693 } 699 }
694 } 700 }
@@ -813,14 +819,24 @@ ttyresize(int x, int y) {
813} 819}
814 820
815void 821void
816tfulldirt(void) 822tsetdirt(int top, int bot)
817{ 823{
818 int i; 824 int i;
819 for(i = 0; i < term.row; i++) 825
826 LIMIT(top, 0, term.row-1);
827 LIMIT(bot, 0, term.row-1);
828
829 for(i = top; i <= bot; i++)
820 term.dirty[i] = 1; 830 term.dirty[i] = 1;
821} 831}
822 832
823void 833void
834tfulldirt(void)
835{
836 tsetdirt(0, term.row-1);
837}
838
839void
824tcursor(int mode) { 840tcursor(int mode) {
825 static TCursor c; 841 static TCursor c;
826 842