#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include "termchar.h"
#include "termopts.h"
#include "window.h"
#include "keymap.h"
#include "blockinput.h"
+#include "intervals.h"
/* For now, don't try to include termcap.h. On some systems,
configure finds a non-standard termcap.h that the main build
#ifdef HAVE_GPM
#include <sys/fcntl.h>
-#include "buffer.h"
/* Nonzero means mouse is enabled on Linux console. */
int term_gpm = 0;
static int mouse_face_beg_row, mouse_face_beg_col;
static int mouse_face_end_row, mouse_face_end_col;
static int mouse_face_past_end;
-static Lisp_Object mouse_face_window;
+static Lisp_Object Qmouse_face_window;
static int mouse_face_face_id;
-/* FRAME and X, Y position of mouse when last checked for
- highlighting. X and Y can be negative or out of range for the frame. */
-struct frame *mouse_face_mouse_frame;
-int mouse_face_mouse_x, mouse_face_mouse_y;
-
static int pos_x, pos_y;
static int last_mouse_x, last_mouse_y;
#endif /* HAVE_GPM */
***********************************************************************/
#ifdef HAVE_GPM
+void
+term_mouse_moveto (int x, int y)
+{
+ /* TODO: how to set mouse position?
+ const char *name;
+ int fd;
+ name = (const char *) ttyname (0);
+ fd = open (name, O_WRONLY);
+ SOME_FUNCTION (x, y, fd);
+ close (fd);
+ last_mouse_x = x;
+ last_mouse_y = y; */
+}
+
static void
term_show_mouse_face (enum draw_glyphs_face draw)
{
- struct window *w = XWINDOW (mouse_face_window);
+ struct window *w = XWINDOW (Qmouse_face_window);
int save_x, save_y;
- int i, j;
+ int i;
if (/* If window is in the process of being destroyed, don't bother
to do anything. */
static void
term_clear_mouse_face ()
{
- if (!NILP (mouse_face_window))
+ if (!NILP (Qmouse_face_window))
term_show_mouse_face (DRAW_NORMAL_TEXT);
mouse_face_beg_row = mouse_face_beg_col = -1;
mouse_face_end_row = mouse_face_end_col = -1;
- mouse_face_window = Qnil;
+ Qmouse_face_window = Qnil;
}
/* Find the glyph matrix position of buffer position POS in window W.
|| !f->glyphs_initialized_p)
return;
- mouse_face_mouse_x = x;
- mouse_face_mouse_y = y;
- mouse_face_mouse_frame = f;
-
/* Which window is that in? */
window = window_from_coordinates (f, x, y, &part, &x, &y, 0);
if (!WINDOWP (window))
return;
- if (!EQ (window, mouse_face_window))
+ if (!EQ (window, Qmouse_face_window))
term_clear_mouse_face ();
w = XWINDOW (window);
{
extern Lisp_Object Qmouse_face;
Lisp_Object mouse_face, overlay, position, *overlay_vec;
- int noverlays, obegv, ozv;;
+ int noverlays, obegv, ozv;
struct buffer *obuf;
/* If we get an out-of-range value, return now; avoid an error. */
noverlays = sort_overlays (overlay_vec, noverlays, w);
/* Check mouse-face highlighting. */
- if (!(EQ (window, mouse_face_window)
+ if (!(EQ (window, Qmouse_face_window)
&& y >= mouse_face_beg_row
&& y <= mouse_face_end_row
&& (y > mouse_face_beg_row
= !fast_find_position (w, XFASTINT (after),
&mouse_face_end_col,
&mouse_face_end_row);
- mouse_face_window = window;
+ Qmouse_face_window = window;
mouse_face_face_id
= face_at_buffer_position (w, pos, 0, 0,
= !fast_find_position (w, XFASTINT (after),
&mouse_face_end_col,
&mouse_face_end_row);
- mouse_face_window = window;
+ Qmouse_face_window = window;
mouse_face_face_id
= face_at_buffer_position (w, pos, 0, 0,
if (event->x != last_mouse_x || event->y != last_mouse_y)
{
frame->mouse_moved = 1;
- term_mouse_highlight (frame, event->x - 1, event->y - 1);
+ term_mouse_highlight (frame, event->x, event->y);
/* Remember which glyph we're now on. */
last_mouse_x = event->x;
last_mouse_y = event->y;
Set *time to the time the mouse was at the returned position.
- This should clear mouse_moved until the next motion
- event arrives.
-
- NOT CURRENTLY INVOKED: see mouse_position_hook below. */
+ This clears mouse_moved until the next motion
+ event arrives. */
static void
term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
enum scroll_bar_part *part, Lisp_Object *x,
Lisp_Object *y, unsigned long *time)
{
- Gpm_Event event;
struct timeval now;
- int i;
-
- BLOCK_INPUT;
*fp = SELECTED_FRAME ();
+ (*fp)->mouse_moved = 0;
*bar_window = Qnil;
*part = 0;
- i = Gpm_GetSnapshot (&event);
-
- XSETINT (*x, event.x);
- XSETINT (*y, event.y);
+ XSETINT (*x, last_mouse_x);
+ XSETINT (*y, last_mouse_y);
gettimeofday(&now, 0);
*time = (now.tv_sec * 1000) + (now.tv_usec / 1000);
-
- UNBLOCK_INPUT;
}
/* Prepare a mouse-event in *RESULT for placement in the input queue.
if (event->type & GPM_DRAG)
result->modifiers |= drag_modifier;
- if (!(event->type & (GPM_MOVE|GPM_DRAG))) {
+ if (!(event->type & (GPM_MOVE | GPM_DRAG))) {
/* 1 << KG_SHIFT */
if (event->modifiers & (1 << 0))
result->modifiers |= meta_modifier;
}
- XSETINT (result->x, event->x - 1);
- XSETINT (result->y, event->y - 1);
+ XSETINT (result->x, event->x);
+ XSETINT (result->y, event->y);
XSETFRAME (result->frame_or_window, f);
result->arg = Qnil;
return Qnil;
handle_one_term_event (Gpm_Event *event, struct input_event* hold_quit)
{
struct frame *f = SELECTED_FRAME ();
- int i, j, fd;
+ int fd;
struct input_event ie;
int do_help = 0;
int count = 0;
ie.kind = NO_EVENT;
ie.arg = Qnil;
- if (event->type & GPM_MOVE) {
+ if (event->type & (GPM_MOVE | GPM_DRAG)) {
unsigned char buf[6 * sizeof (short)];
unsigned short *arg = (unsigned short *) buf + 1;
const char *name;
/* Display mouse pointer */
buf[sizeof(short) - 1] = 2; /* set selection */
- arg[0] = arg[2] = (unsigned short) event->x;
- arg[1] = arg[3] = (unsigned short) event->y;
+ arg[0] = arg[2] = (unsigned short) event->x + gpm_zerobased;
+ arg[1] = arg[3] = (unsigned short) event->y + gpm_zerobased;
arg[4] = (unsigned short) 3;
- name = (const char *) ttyname (0);
+ name = ttyname (0);
fd = open (name, O_WRONLY);
ioctl (fd, TIOCLINUX, buf + sizeof (short) - 1);
- close(fd);
+ close (fd);
- term_mouse_movement (f, event);
+ if (!term_mouse_movement (f, event))
+ help_echo_string = previous_help_echo_string;
/* If the contents of the global variable help_echo_string
has changed, generate a HELP_EVENT. */
else {
f->mouse_moved = 0;
term_mouse_click (&ie, event, f);
- //kbd_buffer_store_event_hold (&ie, hold_quit);
}
done:
connection.defaultMask = ~GPM_HARD;
connection.maxMod = ~0;
connection.minMod = 0;
+ gpm_zerobased = 1;
if (Gpm_Open (&connection, 0) < 0)
return Qnil;
encode_terminal_dst_size = 0;
#ifdef HAVE_GPM
- /* TODO: Can't get Gpm_Snapshot in term_mouse_position to work: test with
- (mouse-position). Also set-mouse-position won't work as is. */
- /* mouse_position_hook = term_mouse_position; */
-
- mouse_face_window = Qnil;
+ mouse_position_hook = term_mouse_position;
+ Qmouse_face_window = Qnil;
#endif
#ifdef WINDOWSNT
#ifdef HAVE_GPM
defsubr (&Sterm_open_connection);
defsubr (&Sterm_close_connection);
+
+ staticpro (&Qmouse_face_window);
#endif /* HAVE_GPM */
fullscreen_hook = NULL;