From: David Herrmann Date: Fri, 5 Oct 2012 12:04:54 +0000 (+0200) Subject: wlt: terminal: clear selection on short click X-Git-Tag: kmscon-7~398 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0996ed38a06016e23fbc2f86fc08290cf5b829e3;p=platform%2Fupstream%2Fkmscon.git wlt: terminal: clear selection on short click If the mouse is not moved during a mouse-click, then we clear the current selection. This can be increased to allow a short range of few pixels of mouse-movement if required. Signed-off-by: David Herrmann --- diff --git a/src/wlt_terminal.c b/src/wlt_terminal.c index 1d4ec51..66126e4 100644 --- a/src/wlt_terminal.c +++ b/src/wlt_terminal.c @@ -73,6 +73,9 @@ struct wlt_terminal { int pointer_x; int pointer_y; bool in_selection; + bool selection_started; + int sel_start_x; + int sel_start_y; }; static int draw_cell(struct tsm_screen *scr, @@ -409,16 +412,28 @@ static void pointer_motion(struct wlt_widget *widget, term->pointer_x = -1; term->pointer_y = -1; return; + } else if (term->pointer_x == x - term->alloc.x && + term->pointer_y == y - term->alloc.y) { + return; } else { term->pointer_x = x - term->alloc.x; term->pointer_y = y - term->alloc.y; } - posx = term->pointer_x / term->font_normal->attr.width; - posy = term->pointer_y / term->font_normal->attr.height; - if (term->in_selection) { - tsm_screen_selection_target(term->scr, posx, posy); + if (!term->selection_started) { + term->selection_started = true; + posx = term->sel_start_x / term->font_normal->attr.width; + posy = term->sel_start_y / term->font_normal->attr.height; + + tsm_screen_selection_start(term->scr, posx, posy); + } else { + posx = term->pointer_x / term->font_normal->attr.width; + posy = term->pointer_y / term->font_normal->attr.height; + + tsm_screen_selection_target(term->scr, posx, posy); + } + wlt_window_schedule_redraw(term->wnd); } } @@ -443,7 +458,6 @@ static void pointer_button(struct wlt_widget *widget, uint32_t button, uint32_t state, void *data) { struct wlt_terminal *term = data; - unsigned int posx, posy; if (button != BTN_LEFT) return; @@ -452,14 +466,18 @@ static void pointer_button(struct wlt_widget *widget, if (!term->in_selection && term->pointer_x >= 0 && term->pointer_y >= 0) { term->in_selection = true; + term->selection_started = false; - posx = term->pointer_x / term->font_normal->attr.width; - posy = term->pointer_y / term->font_normal->attr.height; - - tsm_screen_selection_start(term->scr, posx, posy); - wlt_window_schedule_redraw(term->wnd); + term->sel_start_x = term->pointer_x; + term->sel_start_y = term->pointer_y; } } else { + if (term->pointer_x == term->sel_start_x && + term->pointer_y == term->sel_start_y) { + tsm_screen_selection_reset(term->scr); + wlt_window_schedule_redraw(term->wnd); + } + term->in_selection = false; } }