diff options
| -rw-r--r-- | st.c | 50 |
1 files changed, 33 insertions, 17 deletions
| @@ -259,6 +259,7 @@ static void tsetattr(int*, int); | |||
| 259 | static void tsetchar(char*); | 259 | static void tsetchar(char*); |
| 260 | static void tsetscroll(int, int); | 260 | static void tsetscroll(int, int); |
| 261 | static void tswapscreen(void); | 261 | static void tswapscreen(void); |
| 262 | static void tsetdirt(int, int); | ||
| 262 | static void tfulldirt(void); | 263 | static void tfulldirt(void); |
| 263 | 264 | ||
| 264 | static void ttynew(void); | 265 | static void ttynew(void); |
| @@ -446,8 +447,8 @@ utf8size(char *s) { | |||
| 446 | 447 | ||
| 447 | void | 448 | void |
| 448 | selinit(void) { | 449 | selinit(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) { | |||
| 531 | void | 531 | void |
| 532 | selcopy(void) { | 532 | selcopy(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 | ||
| 815 | void | 821 | void |
| 816 | tfulldirt(void) | 822 | tsetdirt(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 | ||
| 823 | void | 833 | void |
| 834 | tfulldirt(void) | ||
| 835 | { | ||
| 836 | tsetdirt(0, term.row-1); | ||
| 837 | } | ||
| 838 | |||
| 839 | void | ||
| 824 | tcursor(int mode) { | 840 | tcursor(int mode) { |
| 825 | static TCursor c; | 841 | static TCursor c; |
| 826 | 842 | ||
