comparison src/term.c @ 81102:a00e7c5f2faa

(mouse_face_window): Rename... (Qmouse_face_window): ...to this. (term_show_mouse_face, term_clear_mouse_face) (term_mouse_highlight): Use Qmouse_face_window. (term_mouse_moveto): New function. (term_mouse_position): Make it work. (syms_of_term): Uncomment assignment to mouse_position_hook. Staticpro Qmouse_face_window.
author Nick Roberts <nickrob@snap.net.nz>
date Wed, 30 May 2007 05:19:55 +0000
parents 223bb8e66f74
children a9d423c1c1d4 4c726a40604c 648e6c714c7d
comparison
equal deleted inserted replaced
81101:a60f9776dcd0 81102:a00e7c5f2faa
423 its account. Rows and columns are glyph matrix positions in 423 its account. Rows and columns are glyph matrix positions in
424 MOUSE_FACE_WINDOW. */ 424 MOUSE_FACE_WINDOW. */
425 static int mouse_face_beg_row, mouse_face_beg_col; 425 static int mouse_face_beg_row, mouse_face_beg_col;
426 static int mouse_face_end_row, mouse_face_end_col; 426 static int mouse_face_end_row, mouse_face_end_col;
427 static int mouse_face_past_end; 427 static int mouse_face_past_end;
428 static Lisp_Object mouse_face_window; 428 static Lisp_Object Qmouse_face_window;
429 static int mouse_face_face_id; 429 static int mouse_face_face_id;
430 430
431 /* FRAME and X, Y position of mouse when last checked for 431 /* FRAME and X, Y position of mouse when last checked for
432 highlighting. X and Y can be negative or out of range for the frame. */ 432 highlighting. X and Y can be negative or out of range for the frame. */
433 struct frame *mouse_face_mouse_frame; 433 struct frame *mouse_face_mouse_frame;
2380 /*********************************************************************** 2380 /***********************************************************************
2381 Mouse 2381 Mouse
2382 ***********************************************************************/ 2382 ***********************************************************************/
2383 2383
2384 #ifdef HAVE_GPM 2384 #ifdef HAVE_GPM
2385 void term_mouse_moveto (int x, int y)
2386 {
2387 const char *name;
2388 int fd;
2389 name = (const char *) ttyname (0);
2390 fd = open (name, O_WRONLY);
2391 /* TODO: how to set mouse position?
2392 SOME_FUNCTION (x, y, fd); */
2393 close (fd);
2394 last_mouse_x = x;
2395 last_mouse_y = y;
2396 }
2397
2385 static void 2398 static void
2386 term_show_mouse_face (enum draw_glyphs_face draw) 2399 term_show_mouse_face (enum draw_glyphs_face draw)
2387 { 2400 {
2388 struct window *w = XWINDOW (mouse_face_window); 2401 struct window *w = XWINDOW (Qmouse_face_window);
2389 int save_x, save_y; 2402 int save_x, save_y;
2390 int i, j; 2403 int i, j;
2391 2404
2392 if (/* If window is in the process of being destroyed, don't bother 2405 if (/* If window is in the process of being destroyed, don't bother
2393 to do anything. */ 2406 to do anything. */
2459 } 2472 }
2460 2473
2461 static void 2474 static void
2462 term_clear_mouse_face () 2475 term_clear_mouse_face ()
2463 { 2476 {
2464 if (!NILP (mouse_face_window)) 2477 if (!NILP (Qmouse_face_window))
2465 term_show_mouse_face (DRAW_NORMAL_TEXT); 2478 term_show_mouse_face (DRAW_NORMAL_TEXT);
2466 2479
2467 mouse_face_beg_row = mouse_face_beg_col = -1; 2480 mouse_face_beg_row = mouse_face_beg_col = -1;
2468 mouse_face_end_row = mouse_face_end_col = -1; 2481 mouse_face_end_row = mouse_face_end_col = -1;
2469 mouse_face_window = Qnil; 2482 Qmouse_face_window = Qnil;
2470 } 2483 }
2471 2484
2472 /* Find the glyph matrix position of buffer position POS in window W. 2485 /* Find the glyph matrix position of buffer position POS in window W.
2473 *HPOS and *VPOS are set to the positions found. W's current glyphs 2486 *HPOS and *VPOS are set to the positions found. W's current glyphs
2474 must be up to date. If POS is above window start return (0, 0). 2487 must be up to date. If POS is above window start return (0, 0).
2565 2578
2566 /* Not on a window -> return. */ 2579 /* Not on a window -> return. */
2567 if (!WINDOWP (window)) 2580 if (!WINDOWP (window))
2568 return; 2581 return;
2569 2582
2570 if (!EQ (window, mouse_face_window)) 2583 if (!EQ (window, Qmouse_face_window))
2571 term_clear_mouse_face (); 2584 term_clear_mouse_face ();
2572 2585
2573 w = XWINDOW (window); 2586 w = XWINDOW (window);
2574 2587
2575 /* Are we in a window whose display is up to date? 2588 /* Are we in a window whose display is up to date?
2648 GET_OVERLAYS_AT (pos, overlay_vec, noverlays, NULL, 0); 2661 GET_OVERLAYS_AT (pos, overlay_vec, noverlays, NULL, 0);
2649 /* Sort overlays into increasing priority order. */ 2662 /* Sort overlays into increasing priority order. */
2650 noverlays = sort_overlays (overlay_vec, noverlays, w); 2663 noverlays = sort_overlays (overlay_vec, noverlays, w);
2651 2664
2652 /* Check mouse-face highlighting. */ 2665 /* Check mouse-face highlighting. */
2653 if (!(EQ (window, mouse_face_window) 2666 if (!(EQ (window, Qmouse_face_window)
2654 && y >= mouse_face_beg_row 2667 && y >= mouse_face_beg_row
2655 && y <= mouse_face_end_row 2668 && y <= mouse_face_end_row
2656 && (y > mouse_face_beg_row 2669 && (y > mouse_face_beg_row
2657 || x >= mouse_face_beg_col) 2670 || x >= mouse_face_beg_col)
2658 && (y < mouse_face_end_row 2671 && (y < mouse_face_end_row
2698 2711
2699 mouse_face_past_end 2712 mouse_face_past_end
2700 = !fast_find_position (w, XFASTINT (after), 2713 = !fast_find_position (w, XFASTINT (after),
2701 &mouse_face_end_col, 2714 &mouse_face_end_col,
2702 &mouse_face_end_row); 2715 &mouse_face_end_row);
2703 mouse_face_window = window; 2716 Qmouse_face_window = window;
2704 2717
2705 mouse_face_face_id 2718 mouse_face_face_id
2706 = face_at_buffer_position (w, pos, 0, 0, 2719 = face_at_buffer_position (w, pos, 0, 0,
2707 &ignore, pos + 1, 1); 2720 &ignore, pos + 1, 1);
2708 2721
2733 &mouse_face_beg_row); 2746 &mouse_face_beg_row);
2734 mouse_face_past_end 2747 mouse_face_past_end
2735 = !fast_find_position (w, XFASTINT (after), 2748 = !fast_find_position (w, XFASTINT (after),
2736 &mouse_face_end_col, 2749 &mouse_face_end_col,
2737 &mouse_face_end_row); 2750 &mouse_face_end_row);
2738 mouse_face_window = window; 2751 Qmouse_face_window = window;
2739 2752
2740 mouse_face_face_id 2753 mouse_face_face_id
2741 = face_at_buffer_position (w, pos, 0, 0, 2754 = face_at_buffer_position (w, pos, 0, 0,
2742 &ignore, pos + 1, 1); 2755 &ignore, pos + 1, 1);
2743 2756
2820 row of the character cell the mouse is over. 2833 row of the character cell the mouse is over.
2821 2834
2822 Set *time to the time the mouse was at the returned position. 2835 Set *time to the time the mouse was at the returned position.
2823 2836
2824 This should clear mouse_moved until the next motion 2837 This should clear mouse_moved until the next motion
2825 event arrives. 2838 event arrives. */
2826
2827 NOT CURRENTLY INVOKED: see mouse_position_hook below. */
2828 static void 2839 static void
2829 term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, 2840 term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
2830 enum scroll_bar_part *part, Lisp_Object *x, 2841 enum scroll_bar_part *part, Lisp_Object *x,
2831 Lisp_Object *y, unsigned long *time) 2842 Lisp_Object *y, unsigned long *time)
2832 { 2843 {
2833 Gpm_Event event;
2834 struct timeval now; 2844 struct timeval now;
2835 int i; 2845 Lisp_Object frame, window;
2836 2846 struct window *w;
2837 BLOCK_INPUT;
2838 2847
2839 *fp = SELECTED_FRAME (); 2848 *fp = SELECTED_FRAME ();
2849 (*fp)->mouse_moved = 0;
2840 2850
2841 *bar_window = Qnil; 2851 *bar_window = Qnil;
2842 *part = 0; 2852 *part = 0;
2843 2853
2844 i = Gpm_GetSnapshot (&event); 2854 XSETINT (*x, last_mouse_x);
2845 2855 XSETINT (*y, last_mouse_y);
2846 XSETINT (*x, event.x); 2856 XSETFRAME (frame, *fp);
2847 XSETINT (*y, event.y); 2857 window = Fwindow_at (*x, *y, frame);
2858
2859 XSETINT (*x, last_mouse_x - WINDOW_LEFT_EDGE_COL (XWINDOW (window)));
2860 XSETINT (*y, last_mouse_y - WINDOW_TOP_EDGE_LINE (XWINDOW (window)));
2848 gettimeofday(&now, 0); 2861 gettimeofday(&now, 0);
2849 *time = (now.tv_sec * 1000) + (now.tv_usec / 1000); 2862 *time = (now.tv_sec * 1000) + (now.tv_usec / 1000);
2850
2851 UNBLOCK_INPUT;
2852 } 2863 }
2853 2864
2854 /* Prepare a mouse-event in *RESULT for placement in the input queue. 2865 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2855 2866
2856 If the event is a button press, then note that we have grabbed 2867 If the event is a button press, then note that we have grabbed
2945 arg[4] = (unsigned short) 3; 2956 arg[4] = (unsigned short) 3;
2946 2957
2947 name = (const char *) ttyname (0); 2958 name = (const char *) ttyname (0);
2948 fd = open (name, O_WRONLY); 2959 fd = open (name, O_WRONLY);
2949 ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1); 2960 ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1);
2950 close(fd); 2961 close (fd);
2951 2962
2952 term_mouse_movement (f, event); 2963 term_mouse_movement (f, event);
2953 2964
2954 /* If the contents of the global variable help_echo_string 2965 /* If the contents of the global variable help_echo_string
2955 has changed, generate a HELP_EVENT. */ 2966 has changed, generate a HELP_EVENT. */
2960 goto done; 2971 goto done;
2961 } 2972 }
2962 else { 2973 else {
2963 f->mouse_moved = 0; 2974 f->mouse_moved = 0;
2964 term_mouse_click (&ie, event, f); 2975 term_mouse_click (&ie, event, f);
2965 //kbd_buffer_store_event_hold (&ie, hold_quit);
2966 } 2976 }
2967 2977
2968 done: 2978 done:
2969 if (ie.kind != NO_EVENT) 2979 if (ie.kind != NO_EVENT)
2970 { 2980 {
3044 struct frame *sf = XFRAME (selected_frame); 3054 struct frame *sf = XFRAME (selected_frame);
3045 3055
3046 encode_terminal_bufsize = 0; 3056 encode_terminal_bufsize = 0;
3047 3057
3048 #ifdef HAVE_GPM 3058 #ifdef HAVE_GPM
3049 /* TODO: Can't get Gpm_Snapshot in term_mouse_position to work: test with 3059 mouse_position_hook = term_mouse_position;
3050 (mouse-position). Also set-mouse-position won't work as is. */ 3060 Qmouse_face_window = Qnil;
3051 /* mouse_position_hook = term_mouse_position; */
3052
3053 mouse_face_window = Qnil;
3054 #endif 3061 #endif
3055 3062
3056 #ifdef WINDOWSNT 3063 #ifdef WINDOWSNT
3057 initialize_w32_display (); 3064 initialize_w32_display ();
3058 3065
3501 defsubr (&Stty_display_color_cells); 3508 defsubr (&Stty_display_color_cells);
3502 defsubr (&Stty_no_underline); 3509 defsubr (&Stty_no_underline);
3503 #ifdef HAVE_GPM 3510 #ifdef HAVE_GPM
3504 defsubr (&Sterm_open_connection); 3511 defsubr (&Sterm_open_connection);
3505 defsubr (&Sterm_close_connection); 3512 defsubr (&Sterm_close_connection);
3513
3514 staticpro (&Qmouse_face_window);
3506 #endif /* HAVE_GPM */ 3515 #endif /* HAVE_GPM */
3507 3516
3508 fullscreen_hook = NULL; 3517 fullscreen_hook = NULL;
3509 } 3518 }
3510 3519