2005-07-01 02:53:39 -07:00
|
|
|
/*
|
2005-07-13 08:46:11 -07:00
|
|
|
* mooterm/mooterminput.c
|
2005-07-01 02:53:39 -07:00
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
2005-07-14 23:37:09 -07:00
|
|
|
*
|
|
|
|
* moo_term_key_press() code is taken from libvte vte.c,
|
|
|
|
* Copyright (C) 2001-2004 Red Hat, Inc.
|
2005-07-01 02:53:39 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define MOOTERM_COMPILATION
|
2005-07-13 08:46:11 -07:00
|
|
|
#include "mooterm/mooterm-keymap.h"
|
2005-07-16 21:49:01 -07:00
|
|
|
#include "mooterm/mooterm-selection.h"
|
2005-07-01 02:53:39 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
#define META_MASK GDK_MOD1_MASK
|
2005-07-01 02:53:39 -07:00
|
|
|
|
|
|
|
|
|
|
|
static GtkWidgetClass *widget_class (void)
|
|
|
|
{
|
|
|
|
static GtkWidgetClass *klass = NULL;
|
|
|
|
if (!klass)
|
|
|
|
klass = GTK_WIDGET_CLASS (g_type_class_peek (GTK_TYPE_WIDGET));
|
|
|
|
return klass;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void moo_term_im_commit (G_GNUC_UNUSED GtkIMContext *imcontext,
|
|
|
|
gchar *arg,
|
|
|
|
MooTerm *term)
|
|
|
|
{
|
2005-07-13 08:46:11 -07:00
|
|
|
if (moo_term_pt_child_alive (term->priv->pt))
|
|
|
|
moo_term_feed_child (term, arg, -1);
|
2005-07-01 02:53:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
/* shamelessly taken from vte.c */
|
2005-07-01 02:53:39 -07:00
|
|
|
gboolean moo_term_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event)
|
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
MooTerm *term;
|
|
|
|
char *string = NULL;
|
|
|
|
gssize string_length = 0;
|
|
|
|
int i;
|
|
|
|
gboolean scrolled = FALSE;
|
|
|
|
gboolean steal = FALSE;
|
|
|
|
gboolean is_modifier = FALSE;
|
|
|
|
gboolean handled;
|
|
|
|
gboolean suppress_meta_esc = FALSE;
|
|
|
|
guint keyval = 0;
|
|
|
|
gunichar keychar = 0;
|
|
|
|
char keybuf[6]; /* 6 bytes for UTF-8 character */
|
|
|
|
GdkModifierType modifiers;
|
|
|
|
|
|
|
|
term = MOO_TERM (widget);
|
|
|
|
|
|
|
|
/* First, check if GtkWidget's behavior already does something with
|
|
|
|
* this key. */
|
|
|
|
if (widget_class()->key_press_event (widget, event))
|
2005-07-01 02:53:39 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
return TRUE;
|
2005-07-01 02:53:39 -07:00
|
|
|
}
|
2005-07-14 23:37:09 -07:00
|
|
|
|
|
|
|
keyval = event->keyval;
|
|
|
|
|
|
|
|
/* If it's a keypress, record that we got the event, in case the
|
|
|
|
* input method takes the event from us. */
|
|
|
|
term->priv->modifiers = modifiers = event->state;
|
|
|
|
modifiers &= (GDK_SHIFT_MASK | GDK_CONTROL_MASK | META_MASK);
|
|
|
|
|
|
|
|
/* Determine if this is just a modifier key. */
|
|
|
|
is_modifier = key_is_modifier (keyval);
|
|
|
|
|
|
|
|
/* Unless it's a modifier key, hide the pointer. */
|
|
|
|
if (!is_modifier &&
|
2005-07-15 03:05:27 -07:00
|
|
|
term->priv->settings.hide_pointer_on_keypress &&
|
2005-07-14 23:37:09 -07:00
|
|
|
moo_term_pt_child_alive (term->priv->pt))
|
2005-07-01 02:53:39 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
moo_term_set_pointer_visible (term, FALSE);
|
2005-07-13 08:46:11 -07:00
|
|
|
}
|
2005-07-14 23:37:09 -07:00
|
|
|
|
|
|
|
/* We steal many keypad keys here. */
|
|
|
|
if (!term->priv->im_preedit_active)
|
2005-07-13 08:46:11 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
switch (keyval)
|
2005-07-01 02:53:39 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
CASE_GDK_KP_SOMETHING
|
|
|
|
steal = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modifiers & META_MASK)
|
|
|
|
{
|
|
|
|
steal = TRUE;
|
2005-07-01 02:53:39 -07:00
|
|
|
}
|
|
|
|
}
|
2005-07-14 23:37:09 -07:00
|
|
|
|
|
|
|
/* Let the input method at this one first. */
|
|
|
|
if (!steal)
|
2005-07-01 02:53:39 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
if (gtk_im_context_filter_keypress(term->priv->im, event))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_modifier)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Now figure out what to send to the child. */
|
|
|
|
handled = FALSE;
|
|
|
|
|
|
|
|
switch (keyval)
|
|
|
|
{
|
|
|
|
case GDK_BackSpace:
|
|
|
|
get_backspace_key (term, &string,
|
|
|
|
&string_length,
|
|
|
|
&suppress_meta_esc);
|
|
|
|
handled = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Delete:
|
|
|
|
get_delete_key (term, &string,
|
|
|
|
&string_length,
|
|
|
|
&suppress_meta_esc);
|
|
|
|
handled = TRUE;
|
|
|
|
suppress_meta_esc = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Insert:
|
|
|
|
if (modifiers & GDK_SHIFT_MASK)
|
|
|
|
{
|
2005-07-17 09:41:15 -07:00
|
|
|
moo_term_paste_clipboard (term,
|
|
|
|
GDK_SELECTION_CLIPBOARD);
|
2005-07-01 02:53:39 -07:00
|
|
|
handled = TRUE;
|
2005-07-14 23:37:09 -07:00
|
|
|
suppress_meta_esc = TRUE;
|
|
|
|
}
|
|
|
|
else if (modifiers & GDK_CONTROL_MASK)
|
|
|
|
{
|
2005-07-17 09:41:15 -07:00
|
|
|
moo_term_copy_clipboard (term,
|
|
|
|
GDK_SELECTION_CLIPBOARD);
|
2005-07-01 02:53:39 -07:00
|
|
|
handled = TRUE;
|
2005-07-14 23:37:09 -07:00
|
|
|
suppress_meta_esc = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-03 02:44:29 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
case GDK_Page_Up:
|
|
|
|
case GDK_KP_Page_Up:
|
|
|
|
if (modifiers & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
moo_term_scroll_pages (term, -1);
|
|
|
|
scrolled = TRUE;
|
2005-07-13 08:46:11 -07:00
|
|
|
handled = TRUE;
|
2005-07-14 23:37:09 -07:00
|
|
|
suppress_meta_esc = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-03 02:44:29 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
case GDK_Page_Down:
|
|
|
|
case GDK_KP_Page_Down:
|
|
|
|
if (modifiers & GDK_SHIFT_MASK)
|
2005-07-13 08:46:11 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
moo_term_scroll_pages (term, 1);
|
|
|
|
scrolled = TRUE;
|
|
|
|
handled = TRUE;
|
|
|
|
suppress_meta_esc = TRUE;
|
2005-07-13 08:46:11 -07:00
|
|
|
}
|
2005-07-14 23:37:09 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Home:
|
|
|
|
case GDK_KP_Home:
|
|
|
|
if (modifiers & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
moo_term_scroll_to_top (term);
|
|
|
|
scrolled = TRUE;
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GDK_End:
|
|
|
|
case GDK_KP_End:
|
|
|
|
if (modifiers & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
moo_term_scroll_to_bottom (term);
|
|
|
|
scrolled = TRUE;
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GDK_Up:
|
|
|
|
case GDK_KP_Up:
|
|
|
|
if (modifiers & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
moo_term_scroll_lines (term, -1);
|
|
|
|
scrolled = TRUE;
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GDK_Down:
|
|
|
|
case GDK_KP_Down:
|
|
|
|
if (modifiers & GDK_SHIFT_MASK)
|
|
|
|
{
|
|
|
|
moo_term_scroll_lines (term, 1);
|
|
|
|
scrolled = TRUE;
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_Break:
|
|
|
|
moo_term_ctrl_c (term);
|
|
|
|
handled = TRUE;
|
|
|
|
break;
|
2005-07-01 02:53:39 -07:00
|
|
|
}
|
2005-07-14 23:37:09 -07:00
|
|
|
|
|
|
|
/* If the above switch statement didn't do the job, try mapping
|
|
|
|
* it to a literal or capability name. */
|
|
|
|
if (!handled)
|
2005-07-01 02:53:39 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
if (!(modifiers & GDK_CONTROL_MASK))
|
|
|
|
get_vt_key (term, keyval, &string, &string_length);
|
|
|
|
else
|
|
|
|
get_vt_ctl_key (term, keyval, &string, &string_length);
|
2005-07-01 02:53:39 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
/* If we found something this way, suppress
|
|
|
|
* escape-on-meta. */
|
|
|
|
if (string != NULL && string_length > 0)
|
|
|
|
suppress_meta_esc = TRUE;
|
|
|
|
}
|
2005-07-13 08:46:11 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
/* If we didn't manage to do anything, try to salvage a
|
|
|
|
* printable string. */
|
|
|
|
if (!handled && !string)
|
2005-07-13 08:46:11 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
/* Convert the keyval to a gunichar. */
|
|
|
|
keychar = gdk_keyval_to_unicode(keyval);
|
|
|
|
string_length = 0;
|
2005-07-13 08:46:11 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
if (keychar != 0)
|
2005-07-13 08:46:11 -07:00
|
|
|
{
|
2005-07-14 23:37:09 -07:00
|
|
|
/* Convert the gunichar to a string. */
|
|
|
|
string_length = g_unichar_to_utf8(keychar, keybuf);
|
2005-07-13 08:46:11 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
if (string_length)
|
|
|
|
{
|
|
|
|
string = g_malloc0 (string_length + 1);
|
|
|
|
memcpy (string, keybuf, string_length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string = NULL;
|
|
|
|
}
|
|
|
|
}
|
2005-07-13 08:46:11 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
if (string && (modifiers & GDK_CONTROL_MASK))
|
|
|
|
{
|
|
|
|
/* Replace characters which have "control"
|
|
|
|
* counterparts with those counterparts. */
|
|
|
|
for (i = 0; i < string_length; i++)
|
|
|
|
{
|
|
|
|
if ((((guint8)string[i]) >= 0x40) &&
|
|
|
|
(((guint8)string[i]) < 0x80))
|
|
|
|
{
|
|
|
|
string[i] &= (~(0x60));
|
|
|
|
}
|
|
|
|
}
|
2005-07-13 08:46:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
/* If we got normal characters, send them to the child. */
|
|
|
|
if (string)
|
|
|
|
{
|
|
|
|
if (moo_term_pt_child_alive (term->priv->pt))
|
|
|
|
{
|
|
|
|
if (term->priv->settings.meta_sends_escape &&
|
|
|
|
!suppress_meta_esc &&
|
|
|
|
string_length > 0 &&
|
|
|
|
(modifiers & META_MASK))
|
|
|
|
{
|
2005-07-16 19:53:33 -07:00
|
|
|
moo_term_feed_child (term, VT_ESC_, 1);
|
2005-07-14 23:37:09 -07:00
|
|
|
}
|
2005-07-10 19:54:58 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
if (string_length > 0)
|
|
|
|
{
|
|
|
|
moo_term_feed_child (term, string, string_length);
|
|
|
|
}
|
|
|
|
}
|
2005-07-10 19:54:58 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
/* Keep the cursor on-screen. */
|
|
|
|
if (!scrolled && term->priv->settings.scroll_on_keystroke)
|
|
|
|
moo_term_scroll_to_bottom (term);
|
2005-07-01 02:53:39 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
g_free(string);
|
|
|
|
}
|
2005-07-01 02:53:39 -07:00
|
|
|
|
2005-07-14 23:37:09 -07:00
|
|
|
return TRUE;
|
2005-07-01 02:53:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean moo_term_key_release (GtkWidget *widget,
|
|
|
|
GdkEventKey *event)
|
|
|
|
{
|
|
|
|
MooTerm *term = MOO_TERM (widget);
|
|
|
|
if (!gtk_im_context_filter_keypress (term->priv->im, event))
|
|
|
|
return widget_class()->key_release_event (widget, event);
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-07-12 07:23:08 -07:00
|
|
|
|
|
|
|
|
2005-07-15 02:55:18 -07:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Mouse handling
|
|
|
|
*/
|
|
|
|
|
2005-07-15 04:41:00 -07:00
|
|
|
static void start_press_tracking (MooTerm *term);
|
|
|
|
static void start_button_tracking (MooTerm *term);
|
|
|
|
static void stop_mouse_tracking (MooTerm *term);
|
|
|
|
|
|
|
|
static gboolean button_press (MooTerm *term,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gboolean button_press_or_release (MooTerm *term,
|
|
|
|
GdkEventButton *event);
|
2005-07-15 09:27:09 -07:00
|
|
|
static gboolean scroll_event (MooTerm *term,
|
|
|
|
GdkEventScroll *event);
|
2005-07-15 04:41:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
void moo_term_set_mouse_tracking (MooTerm *term,
|
|
|
|
int tracking_type)
|
2005-07-12 07:23:08 -07:00
|
|
|
{
|
2005-07-15 04:41:00 -07:00
|
|
|
if (tracking_type != term->priv->tracking_mouse)
|
2005-07-15 02:55:18 -07:00
|
|
|
{
|
2005-07-15 04:41:00 -07:00
|
|
|
term->priv->tracking_mouse = tracking_type;
|
|
|
|
moo_term_update_pointer (term);
|
|
|
|
stop_mouse_tracking (term);
|
2005-07-19 02:43:44 -07:00
|
|
|
moo_term_selection_clear (term);
|
2005-07-15 02:55:18 -07:00
|
|
|
|
2005-07-15 04:41:00 -07:00
|
|
|
switch (tracking_type)
|
|
|
|
{
|
|
|
|
case MODE_PRESS_TRACKING:
|
|
|
|
start_press_tracking (term);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_PRESS_AND_RELEASE_TRACKING:
|
|
|
|
term->priv->tracking_mouse = TRUE;
|
|
|
|
start_button_tracking (term);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
term->priv->tracking_mouse = FALSE;
|
|
|
|
stop_mouse_tracking (term);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-15 02:55:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-15 04:41:00 -07:00
|
|
|
static void stop_mouse_tracking (MooTerm *term)
|
2005-07-15 02:55:18 -07:00
|
|
|
{
|
2005-07-15 04:41:00 -07:00
|
|
|
if (term->priv->track_press_id)
|
|
|
|
g_signal_handler_disconnect (term, term->priv->track_press_id);
|
|
|
|
if (term->priv->track_release_id)
|
|
|
|
g_signal_handler_disconnect (term, term->priv->track_release_id);
|
2005-07-15 09:27:09 -07:00
|
|
|
if (term->priv->track_scroll_id)
|
|
|
|
g_signal_handler_disconnect (term, term->priv->track_scroll_id);
|
2005-07-15 04:41:00 -07:00
|
|
|
term->priv->track_press_id = 0;
|
|
|
|
term->priv->track_release_id = 0;
|
2005-07-15 09:27:09 -07:00
|
|
|
term->priv->track_scroll_id = 0;
|
2005-07-15 04:41:00 -07:00
|
|
|
}
|
2005-07-15 02:55:18 -07:00
|
|
|
|
|
|
|
|
2005-07-15 04:41:00 -07:00
|
|
|
static void start_press_tracking (MooTerm *term)
|
|
|
|
{
|
|
|
|
term->priv->track_press_id =
|
|
|
|
g_signal_connect (term, "button-press-event",
|
|
|
|
G_CALLBACK (button_press), NULL);
|
|
|
|
}
|
2005-07-15 02:55:18 -07:00
|
|
|
|
2005-07-15 04:41:00 -07:00
|
|
|
|
|
|
|
static void start_button_tracking (MooTerm *term)
|
|
|
|
{
|
|
|
|
term->priv->track_press_id =
|
|
|
|
g_signal_connect (term, "button-press-event",
|
|
|
|
G_CALLBACK (button_press_or_release), NULL);
|
|
|
|
term->priv->track_release_id =
|
|
|
|
g_signal_connect (term, "button-release-event",
|
|
|
|
G_CALLBACK (button_press_or_release), NULL);
|
2005-07-15 09:27:09 -07:00
|
|
|
term->priv->track_scroll_id =
|
|
|
|
g_signal_connect (term, "scroll-event",
|
|
|
|
G_CALLBACK (scroll_event), NULL);
|
2005-07-15 02:55:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-15 04:41:00 -07:00
|
|
|
static void get_mouse_coordinates (MooTerm *term,
|
|
|
|
GdkEventButton *event,
|
|
|
|
int *x,
|
|
|
|
int *y)
|
|
|
|
{
|
|
|
|
guint char_width = term_char_width (term);
|
|
|
|
guint char_height = term_char_height (term);
|
|
|
|
|
|
|
|
*x = event->x / char_width;
|
|
|
|
*x = CLAMP (*x, 0, (int)term->priv->width - 1);
|
|
|
|
|
|
|
|
*y = event->y / char_height;
|
|
|
|
*y = CLAMP (*y, 0, (int)term->priv->height - 1);
|
2005-07-15 02:55:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-15 04:41:00 -07:00
|
|
|
static gboolean button_press (MooTerm *term,
|
|
|
|
GdkEventButton *event)
|
2005-07-15 02:55:18 -07:00
|
|
|
{
|
2005-07-15 04:41:00 -07:00
|
|
|
int x, y;
|
2005-07-15 09:36:15 -07:00
|
|
|
guchar button;
|
2005-07-15 04:41:00 -07:00
|
|
|
char *string;
|
|
|
|
|
2005-07-15 09:36:15 -07:00
|
|
|
if (event->type != GDK_BUTTON_PRESS ||
|
|
|
|
event->button < 1 || event->button > 5)
|
|
|
|
{
|
2005-07-15 04:41:00 -07:00
|
|
|
return TRUE;
|
2005-07-15 09:36:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (event->button < 4)
|
|
|
|
button = 040 + event->button - 1;
|
|
|
|
else
|
|
|
|
button = 0140 + event->button - 4;
|
2005-07-15 04:41:00 -07:00
|
|
|
|
|
|
|
get_mouse_coordinates (term, event, &x, &y);
|
|
|
|
|
2005-07-16 19:53:33 -07:00
|
|
|
string = g_strdup_printf (VT_CSI_ "M%c%c%c", button,
|
2005-07-15 04:41:00 -07:00
|
|
|
(guchar) (x + 1 + 040),
|
|
|
|
(guchar) (y + 1 + 040));
|
|
|
|
|
|
|
|
moo_term_feed_child (term, string, 6);
|
|
|
|
|
|
|
|
g_free (string);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-07-15 02:55:18 -07:00
|
|
|
|
|
|
|
|
2005-07-15 04:41:00 -07:00
|
|
|
static gboolean button_press_or_release (MooTerm *term,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
|
|
|
int x, y;
|
2005-07-15 09:41:58 -07:00
|
|
|
guint button;
|
2005-07-15 04:41:00 -07:00
|
|
|
char *string;
|
|
|
|
|
|
|
|
if ((event->type != GDK_BUTTON_PRESS && event->type != GDK_BUTTON_RELEASE) ||
|
2005-07-15 09:27:09 -07:00
|
|
|
event->button < 1 || event->button > 5)
|
2005-07-15 04:41:00 -07:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_mouse_coordinates (term, event, &x, &y);
|
|
|
|
|
|
|
|
if (event->type == GDK_BUTTON_PRESS)
|
2005-07-15 09:36:15 -07:00
|
|
|
{
|
|
|
|
if (event->button < 4)
|
2005-07-15 09:41:58 -07:00
|
|
|
button = event->button - 1;
|
2005-07-15 09:36:15 -07:00
|
|
|
else
|
2005-07-15 09:41:58 -07:00
|
|
|
button = 0100 + event->button - 4;
|
2005-07-15 09:36:15 -07:00
|
|
|
}
|
2005-07-15 04:41:00 -07:00
|
|
|
else
|
2005-07-15 09:36:15 -07:00
|
|
|
{
|
2005-07-15 09:41:58 -07:00
|
|
|
button = 3;
|
2005-07-15 09:36:15 -07:00
|
|
|
}
|
2005-07-15 04:41:00 -07:00
|
|
|
|
|
|
|
if (event->state & GDK_SHIFT_MASK)
|
|
|
|
button |= 4;
|
|
|
|
if (event->state & META_MASK)
|
|
|
|
button |= 8;
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
|
|
|
button |= 16;
|
|
|
|
|
2005-07-16 19:53:33 -07:00
|
|
|
string = g_strdup_printf (VT_CSI_ "M%c%c%c",
|
2005-07-15 09:41:58 -07:00
|
|
|
(guchar) (button + 040),
|
2005-07-15 04:41:00 -07:00
|
|
|
(guchar) (x + 1 + 040),
|
|
|
|
(guchar) (y + 1 + 040));
|
|
|
|
|
|
|
|
moo_term_feed_child (term, string, 6);
|
|
|
|
|
|
|
|
g_free (string);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-07-15 09:27:09 -07:00
|
|
|
|
|
|
|
|
|
|
|
static gboolean scroll_event (MooTerm *term,
|
|
|
|
GdkEventScroll *event)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
guchar button;
|
|
|
|
char *string;
|
|
|
|
|
|
|
|
if (event->direction != GDK_SCROLL_UP &&
|
|
|
|
event->direction != GDK_SCROLL_DOWN)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_mouse_coordinates (term, (GdkEventButton*)event, &x, &y);
|
|
|
|
|
|
|
|
if (event->direction == GDK_SCROLL_UP)
|
2005-07-15 09:41:58 -07:00
|
|
|
button = 0100;
|
2005-07-15 09:27:09 -07:00
|
|
|
else
|
2005-07-15 09:41:58 -07:00
|
|
|
button = 0101;
|
2005-07-15 09:27:09 -07:00
|
|
|
|
|
|
|
if (event->state & GDK_SHIFT_MASK)
|
|
|
|
button |= 4;
|
|
|
|
if (event->state & META_MASK)
|
|
|
|
button |= 8;
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
|
|
|
button |= 16;
|
|
|
|
|
2005-07-16 19:53:33 -07:00
|
|
|
string = g_strdup_printf (VT_CSI_ "M%c%c%c",
|
2005-07-15 09:41:58 -07:00
|
|
|
(guchar) (button + 040),
|
2005-07-15 09:27:09 -07:00
|
|
|
(guchar) (x + 1 + 040),
|
|
|
|
(guchar) (y + 1 + 040));
|
|
|
|
|
|
|
|
moo_term_feed_child (term, string, 6);
|
|
|
|
|
|
|
|
g_free (string);
|
|
|
|
return TRUE;
|
|
|
|
}
|