@@ -130,11 +130,11 @@ distance_to_window(Window *w, OSWindow *os_window) {
130
130
static bool clamp_to_window = false;
131
131
132
132
static inline bool
133
- cell_for_pos (Window * w , unsigned int * x , unsigned int * y , OSWindow * os_window ) {
133
+ cell_for_pos (Window * w , unsigned int * x , unsigned int * y , unsigned int * edge_x , unsigned int * edge_y , OSWindow * os_window ) {
134
134
WindowGeometry * g = & w -> geometry ;
135
135
Screen * screen = w -> render_data .screen ;
136
136
if (!screen ) return false;
137
- unsigned int qx = 0 , qy = 0 ;
137
+ double qx = 0 , qy = 0 ;
138
138
double mouse_x = global_state .callback_os_window -> mouse_x ;
139
139
double mouse_y = global_state .callback_os_window -> mouse_y ;
140
140
double left = window_left (w , os_window ), top = window_top (w , os_window ), right = window_right (w , os_window ), bottom = window_bottom (w , os_window );
@@ -143,12 +143,15 @@ cell_for_pos(Window *w, unsigned int *x, unsigned int *y, OSWindow *os_window) {
143
143
mouse_y = MIN (MAX (mouse_y , top ), bottom );
144
144
}
145
145
if (mouse_x < left || mouse_y < top || mouse_x > right || mouse_y > bottom ) return false;
146
- if (mouse_x >= g -> right ) qx = screen -> columns - 1 ;
147
- else if (mouse_x >= g -> left ) qx = (unsigned int )( (double )(mouse_x - g -> left ) / os_window -> fonts_data -> cell_width );
148
- if (mouse_y >= g -> bottom ) qy = screen -> lines - 1 ;
149
- else if (mouse_y >= g -> top ) qy = (unsigned int )( (double )(mouse_y - g -> top ) / os_window -> fonts_data -> cell_height );
146
+ if (mouse_x >= g -> right ) qx = screen -> columns - 0.5 ;
147
+ else if (mouse_x >= g -> left ) qx = ((double )(mouse_x - g -> left ) / os_window -> fonts_data -> cell_width );
148
+ if (mouse_y >= g -> bottom ) qy = screen -> lines - 0.5 ;
149
+ else if (mouse_y >= g -> top ) qy = ((double )(mouse_y - g -> top ) / os_window -> fonts_data -> cell_height );
150
150
if (qx < screen -> columns && qy < screen -> lines ) {
151
- * x = qx ; * y = qy ;
151
+ * x = (unsigned int )qx ;
152
+ * y = (unsigned int )qy ;
153
+ * edge_x = (unsigned int )(qx + 0.5 );
154
+ * edge_y = (unsigned int )(qy + 0.5 );
152
155
return true;
153
156
}
154
157
return false;
@@ -164,14 +167,15 @@ update_drag(bool from_button, Window *w, bool is_release, int modifiers) {
164
167
global_state .active_drag_in_window = 0 ;
165
168
w -> last_drag_scroll_at = 0 ;
166
169
if (screen -> selection .in_progress )
167
- screen_update_selection (screen , w -> mouse_cell_x , w -> mouse_cell_y , true);
170
+ screen_update_selection (screen , w -> mouse_edge_x , screen -> selection . rectangle_select ? w -> mouse_edge_y : w -> mouse_cell_y , true);
168
171
}
169
172
else {
173
+ bool rectangle_select = modifiers == (int )OPT (rectangle_select_modifiers ) || modifiers == ((int )OPT (rectangle_select_modifiers ) | GLFW_MOD_SHIFT );
170
174
global_state .active_drag_in_window = w -> id ;
171
- screen_start_selection (screen , w -> mouse_cell_x , w -> mouse_cell_y , modifiers == ( int ) OPT ( rectangle_select_modifiers ) || modifiers == (( int ) OPT ( rectangle_select_modifiers ) | GLFW_MOD_SHIFT ) , EXTEND_CELL );
175
+ screen_start_selection (screen , w -> mouse_edge_x , rectangle_select ? w -> mouse_edge_y : w -> mouse_cell_y , rectangle_select , EXTEND_CELL );
172
176
}
173
177
} else if (screen -> selection .in_progress ) {
174
- screen_update_selection (screen , w -> mouse_cell_x , w -> mouse_cell_y , false);
178
+ screen_update_selection (screen , w -> mouse_edge_x , screen -> selection . rectangle_select ? w -> mouse_edge_y : w -> mouse_cell_y , false);
175
179
}
176
180
}
177
181
@@ -266,18 +270,21 @@ detect_url(Screen *screen, unsigned int x, unsigned int y) {
266
270
267
271
268
272
HANDLER (handle_move_event ) {
269
- unsigned int x = 0 , y = 0 ;
273
+ unsigned int x = 0 , y = 0 , edge_x = 0 , edge_y = 0 ;
270
274
if (OPT (focus_follows_mouse )) {
271
275
Tab * t = global_state .callback_os_window -> tabs + global_state .callback_os_window -> active_tab ;
272
276
if (window_idx != t -> active_window ) {
273
277
call_boss (switch_focus_to , "I" , window_idx );
274
278
}
275
279
}
276
- if (!cell_for_pos (w , & x , & y , global_state .callback_os_window )) return ;
280
+ if (!cell_for_pos (w , & x , & y , & edge_x , & edge_y , global_state .callback_os_window )) return ;
281
+
277
282
Screen * screen = w -> render_data .screen ;
278
283
detect_url (screen , x , y );
279
284
bool mouse_cell_changed = x != w -> mouse_cell_x || y != w -> mouse_cell_y ;
285
+ bool mouse_edge_changed = edge_x != w -> mouse_edge_x || edge_y != w -> mouse_edge_y ;
280
286
w -> mouse_cell_x = x ; w -> mouse_cell_y = y ;
287
+ w -> mouse_edge_x = edge_x ; w -> mouse_edge_y = edge_y ;
281
288
bool handle_in_kitty = (
282
289
(screen -> modes .mouse_tracking_mode == ANY_MODE ||
283
290
(screen -> modes .mouse_tracking_mode == MOTION_MODE && button >= 0 )) &&
@@ -286,7 +293,7 @@ HANDLER(handle_move_event) {
286
293
if (handle_in_kitty ) {
287
294
if (screen -> selection .in_progress && button == GLFW_MOUSE_BUTTON_LEFT ) {
288
295
double now = monotonic ();
289
- if ((now - w -> last_drag_scroll_at ) >= 0.02 || mouse_cell_changed ) {
296
+ if ((now - w -> last_drag_scroll_at ) >= 0.02 || mouse_edge_changed || mouse_cell_changed ) {
290
297
update_drag (false, w , false, 0 );
291
298
w -> last_drag_scroll_at = monotonic ();
292
299
}
0 commit comments