Ticket #3571: 3571-WEdit-get-rid-of-mouse-event-pump.patch
File 3571-WEdit-get-rid-of-mouse-event-pump.patch, 10.0 KB (added by mooffie, 9 years ago) |
---|
-
src/editor/editwidget.c
From 52676419a293f162a6ee866d7e60daac703bf4e6 Mon Sep 17 00:00:00 2001 From: Mooffie <mooffie@gmail.com> Date: Sat, 26 Mar 2016 22:31:04 +0300 Subject: [PATCH] WEdit: get rid of mouse event pump. --- src/editor/editwidget.c | 169 +++++++++++++++++------------------------------- 1 file changed, 60 insertions(+), 109 deletions(-) diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index 277af8e..b2f1ee0 100644
a b edit_update_cursor (WEdit * edit, const mouse_event_t * event) 752 752 } 753 753 754 754 /* --------------------------------------------------------------------------------------------- */ 755 756 static inline void757 edit_mouse_move_resize (WEdit * edit, mouse_event_t event)758 {759 Widget *w = WIDGET (edit);760 Gpm_Event gevent;761 762 /* init with 1-based global coordinates */763 gevent.y = w->y + event.y + 1;764 gevent.x = w->x + event.x + 1;765 766 while (edit->drag_state != MCEDIT_DRAG_NORMAL)767 {768 int c;769 770 if (event.msg == MSG_MOUSE_UP)771 goto finish;772 773 /* resize or move */774 if (!edit->fullscreen)775 {776 Widget *h = WIDGET (w->owner);777 778 if (edit->drag_state == MCEDIT_DRAG_MOVE)779 {780 /* make 0-based */781 gevent.y--;782 gevent.x--;783 784 gevent.y = max (gevent.y, h->y + 1); /* status line */785 gevent.y = min (gevent.y, h->y + h->lines - 2); /* buttonbar */786 gevent.x = max (gevent.x, h->x);787 gevent.x = min (gevent.x, h->x + h->cols - 1);788 789 /* don't use widget_set_size() here to avoid double draw */790 w->y = gevent.y;791 w->x = gevent.x - edit->drag_state_start;792 edit->force |= REDRAW_COMPLETELY;793 }794 else if (edit->drag_state == MCEDIT_DRAG_RESIZE)795 {796 gevent.y = min (gevent.y, h->y + h->lines - 1); /* buttonbar */797 gevent.x = min (gevent.x, h->x + h->cols);798 gevent = mouse_get_local (&gevent, w);799 800 /* don't use widget_set_size() here to avoid double draw */801 w->lines = max (WINDOW_MIN_LINES, gevent.y);802 w->cols = max (WINDOW_MIN_COLS, gevent.x);803 edit->force |= REDRAW_COMPLETELY;804 }805 806 dlg_redraw (w->owner);807 }808 809 /* Get next event.810 * Don't use standard way in order to continue event handling811 * outside of widget */812 c = tty_get_event (&gevent, FALSE, TRUE);813 if (c == EV_MOUSE)814 event = mouse_translate_event (w, &gevent);815 else816 {817 finish:818 /* redraw frame */819 edit->drag_state = MCEDIT_DRAG_NORMAL;820 edit->force |= REDRAW_COMPLETELY;821 edit_update_screen (edit);822 w->mouse.forced_capture = FALSE;823 }824 }825 }826 827 /* --------------------------------------------------------------------------------------------- */828 755 /** Callback for the edit dialog */ 829 756 830 757 static cb_ret_t … … edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da 1072 999 /* --------------------------------------------------------------------------------------------- */ 1073 1000 1074 1001 /** 1002 * Handle move/resize mouse events. 1003 */ 1004 static void 1005 edit_mouse_handle_move_resize (Widget * w, mouse_msg_t msg, mouse_event_t * event) 1006 { 1007 WEdit *edit = (WEdit *) (w); 1008 Widget *h = WIDGET (w->owner); 1009 int global_x, global_y; 1010 1011 if (msg == MSG_MOUSE_UP) 1012 { 1013 /* Exit drag mode. */ 1014 edit_execute_cmd (edit, CK_Enter, -1); 1015 return; 1016 } 1017 1018 /* Convert point to global coordinates for easier calculations. */ 1019 global_x = event->x + w->x; 1020 global_y = event->y + w->y; 1021 1022 /* Clamp the point to the dialog's client area. */ 1023 global_y = CLAMP (global_y, h->y + 1, h->y + h->lines - 2); /* Status line, buttonbar */ 1024 global_x = CLAMP (global_x, h->x, h->x + h->cols - 1); /* Currently a no-op, as the dialog has no left/right margins. */ 1025 1026 if (edit->drag_state == MCEDIT_DRAG_MOVE) 1027 { 1028 w->y = global_y; 1029 w->x = global_x - edit->drag_state_start; 1030 } 1031 else if (edit->drag_state == MCEDIT_DRAG_RESIZE) 1032 { 1033 w->lines = max (WINDOW_MIN_LINES, global_y - w->y + 1); 1034 w->cols = max (WINDOW_MIN_COLS, global_x - w->x + 1); 1035 } 1036 1037 edit->force |= REDRAW_COMPLETELY; /* Not really needed as WEdit's MSG_DRAW already does this. */ 1038 1039 /* We draw the whole dialog because dragging/resizing exposes area beneath. */ 1040 dlg_redraw (w->owner); 1041 } 1042 1043 /* --------------------------------------------------------------------------------------------- */ 1044 1045 /** 1075 1046 * Handle mouse events of editor window 1076 1047 * 1077 1048 * @param w Widget object (the editor window) … … edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 1090 1061 close_x = (w->cols - 1) - dx - 1; 1091 1062 toggle_fullscreen_x = close_x - 3; 1092 1063 1064 if (edit->drag_state != MCEDIT_DRAG_NORMAL) 1065 { 1066 /* window is being resized/moved */ 1067 edit_mouse_handle_move_resize (w, msg, event); 1068 return; 1069 } 1070 1093 1071 switch (msg) 1094 1072 { 1095 1073 case MSG_MOUSE_DOWN: 1096 if (w->mouse.forced_capture)1097 /* window is being resized/moved by keys */1098 break;1099 1100 1074 dlg_set_top_widget (w); 1101 1075 edit_update_curs_row (edit); 1102 1076 edit_update_curs_col (edit); … … edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 1113 1087 { 1114 1088 /* start window move */ 1115 1089 edit->drag_state_start = event->x; 1116 edit->drag_state = MCEDIT_DRAG_MOVE; 1117 edit->force |= REDRAW_COMPLETELY; 1118 edit_update_screen (edit); 1090 edit_execute_cmd (edit, CK_WindowMove, -1); 1119 1091 } 1120 1092 break; 1121 1093 } … … edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 1123 1095 if (event->y == w->lines - 1 && event->x == w->cols - 1) 1124 1096 { 1125 1097 /* bottom-right corner -- start window resize */ 1126 edit->drag_state = MCEDIT_DRAG_RESIZE; 1127 edit->force |= REDRAW_COMPLETELY; 1128 edit_update_screen (edit); 1098 edit_execute_cmd (edit, CK_WindowResize, -1); 1129 1099 break; 1130 1100 } 1131 1101 } 1132 1102 1133 /* fall through tto start/stop text selection */1103 /* fall through to start/stop text selection */ 1134 1104 1135 1105 case MSG_MOUSE_UP: 1136 edit->drag_state = MCEDIT_DRAG_NORMAL;1137 1106 edit_update_cursor (edit, event); 1138 1107 edit_total_update (edit); 1139 w->mouse.forced_capture = FALSE;1140 1108 break; 1141 1109 1142 1110 case MSG_MOUSE_CLICK: 1143 edit->drag_state = MCEDIT_DRAG_NORMAL;1144 1145 1111 if (event->y == 0) 1146 1112 { 1147 1113 if (event->x == close_x) … … edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 1149 1115 else if (event->x == toggle_fullscreen_x) 1150 1116 edit_toggle_fullscreen (edit); 1151 1117 else if (!edit->fullscreen && event->count == GPM_DOUBLE) 1152 {1153 1118 /* double click on top line (toggle fullscreen) */ 1154 1119 edit_toggle_fullscreen (edit); 1155 edit->drag_state = MCEDIT_DRAG_NORMAL;1156 edit->force |= REDRAW_COMPLETELY;1157 edit_update_screen (edit);1158 }1159 1120 } 1160 1121 else if (event->count == GPM_DOUBLE) 1161 1122 { … … edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 1172 1133 break; 1173 1134 1174 1135 case MSG_MOUSE_DRAG: 1175 if (edit->drag_state == MCEDIT_DRAG_NORMAL) 1176 { 1177 edit_update_cursor (edit, event); 1178 edit_total_update (edit); 1179 } 1180 else 1181 edit_mouse_move_resize (edit, *event); 1136 edit_update_cursor (edit, event); 1137 edit_total_update (edit); 1182 1138 break; 1183 1139 1184 1140 case MSG_MOUSE_SCROLL_UP: … … edit_add_window (WDialog * h, int y, int x, int lines, int cols, const vfs_path_ 1405 1361 gboolean 1406 1362 edit_handle_move_resize (WEdit * edit, long command) 1407 1363 { 1408 Widget *w = WIDGET (edit);1409 1364 gboolean ret = FALSE; 1410 1365 1411 1366 if (edit->fullscreen) 1412 1367 { 1413 1368 edit->drag_state = MCEDIT_DRAG_NORMAL; 1414 w->mouse.forced_capture = FALSE;1415 1369 return ret; 1416 1370 } 1417 1371 … … edit_handle_move_resize (WEdit * edit, long command) 1424 1378 case CK_WindowMove: 1425 1379 edit->drag_state = MCEDIT_DRAG_MOVE; 1426 1380 edit_save_size (edit); 1381 edit_status (edit, TRUE); /* redraw frame and status */ 1427 1382 ret = TRUE; 1428 1383 break; 1429 1384 case CK_WindowResize: 1430 1385 edit->drag_state = MCEDIT_DRAG_RESIZE; 1431 1386 edit_save_size (edit); 1387 edit_status (edit, TRUE); /* redraw frame and status */ 1432 1388 ret = TRUE; 1433 1389 break; 1434 1390 default: … … edit_handle_move_resize (WEdit * edit, long command) 1453 1409 case CK_Enter: 1454 1410 case CK_WindowMove: 1455 1411 edit->drag_state = MCEDIT_DRAG_NORMAL; 1456 /* redraw frame and status */ 1457 edit_status (edit, TRUE); 1412 edit_status (edit, TRUE); /* redraw frame and status */ 1458 1413 default: 1459 1414 ret = TRUE; 1460 1415 break; … … edit_handle_move_resize (WEdit * edit, long command) 1478 1433 case CK_Enter: 1479 1434 case CK_WindowResize: 1480 1435 edit->drag_state = MCEDIT_DRAG_NORMAL; 1481 /* redraw frame and status */ 1482 edit_status (edit, TRUE); 1436 edit_status (edit, TRUE); /* redraw frame and status */ 1483 1437 default: 1484 1438 ret = TRUE; 1485 1439 break; … … edit_handle_move_resize (WEdit * edit, long command) 1490 1444 break; 1491 1445 } 1492 1446 1493 /* allow stop resize/move by mouse click outside window */1494 w->mouse.forced_capture = ret;1495 1496 1447 return ret; 1497 1448 } 1498 1449