Re: Middle mouse button map to a double click
- From: José Geraldo Alves Brito Neto <jgabrito iq usp br>
- To: alex_short payanybill com
- Cc: gtk-devel-list gnome org
- Subject: Re: Middle mouse button map to a double click
- Date: Wed, 02 Aug 2000 13:39:58 -0300
From: Alex Short <alex_short@payanybill.com>
Subject: Middle mouse button map to a double click
Date: Tue, 01 Aug 2000 11:33:27 -0400
> I was just wondering if anyone knows how to map the middle mouse button
> to a double click under linux.
>
Hi,
With GTK+, you can capture the middle mouse button click event and
synthetize a double-click event for the left one. On the program I
attached to this message, I do this with the GtkCList widget.
[]s
#include <gtk/gtk.h>
#include <gdk/gdk.h>
gint
clist_event (GtkWidget *wid,
GdkEventAny *ev,
gpointer data) {
GdkEventButton *btev = (GdkEventButton *)ev;
if ((ev->type == GDK_BUTTON_PRESS) &&
(btev->button == 2)) {
/* Middle mouse button pressed. Simply ignore the event. */
return 1;
}
if ((ev->type == GDK_BUTTON_RELEASE) &&
(btev->button == 2)) {
GdkEventButton my_event;
/* Middle mouse button has just been released. This signals a
click. Now, synthetize a 2BUTTON_PRESS event for the left
button */
g_memmove (&my_event, btev, sizeof (GdkEventButton));
my_event.send_event = TRUE;
my_event.button = 1;
gdk_window_ref (my_event.window);
my_event.time += 10; /* 10ms ?? */
my_event.type = GDK_2BUTTON_PRESS;
gtk_widget_event (wid, (GdkEvent *)(&my_event));
gdk_window_unref (my_event.window);
return 1;
}
if ((ev->type == GDK_2BUTTON_PRESS) &&
(btev->button == 1)) {
gint r,c;
gchar *text;
/* Double click on left button detected. Show text. */
gtk_clist_get_selection_info (GTK_CLIST(wid), btev->x, btev->y,
&r, &c);
if (gtk_clist_get_text (GTK_CLIST(wid), r, c, &text))
g_print ("Double click on row=%d, col=%d, text=\"%s\"\n", r, c, text);
return 0;
}
return 0;
}
gint
main (gint argc, gchar **argv) {
GtkWidget *win;
GtkWidget *clist;
gtk_init (&argc, &argv);
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW(win), 100, 100);
gtk_signal_connect (GTK_OBJECT(win), "delete_event",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
clist = gtk_clist_new (1);
gtk_signal_connect (GTK_OBJECT(clist), "event",
GTK_SIGNAL_FUNC(clist_event), NULL);
{
gchar *text[] = { "text 1", "text 2", "text 3" };
gint n = sizeof(text)/sizeof (gchar *);
gint ind;
for (ind=0; ind<n; ind++)
gtk_clist_append (GTK_CLIST(clist), text + ind);
}
gtk_container_add (GTK_CONTAINER(win), clist);
gtk_widget_show (clist);
gtk_widget_show (win);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]