Commits

Jeff Sparkes committed 3505ed3

Support mouse wheel scrolling in Gtk.

* event-gtk.c (handle_scroll_event): Define.
(emacs_gtk_handle_magic_event): Add scroll event.
(set_last_server_timestamp): Handle scroll event.
(emacs_shell_event_handler): Add scroll event.

* frame-gtk.c (gtk_create_widgets): Add scroll-events to requested
events.

  • Participants
  • Parent commits 1ccda2a

Comments (0)

Files changed (3)

File src/ChangeLog.GTK

+2012-05-18  Jeff Sparkes  <jsparkes@gmail.com>
+
+	* event-gtk.c (handle_scroll_event): Define.
+	(emacs_gtk_handle_magic_event): Add scroll event.
+	(set_last_server_timestamp): Handle scroll event.
+	(emacs_shell_event_handler): Add scroll event.
+
+	* frame-gtk.c (gtk_create_widgets): Add scroll-events to requested
+	events.
+
 2012-05-17  Jeff Sparkes  <jsparkes@gmail.com>
 
 	* device-gtk.c (gtk_event_name): Get event names by

File src/event-gtk.c

 }
 
 static void
+handle_scroll_event (struct frame *frame, GdkEvent *event)
+{
+  Lisp_Object f = wrap_frame (frame);
+  Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
+  GdkEventScroll *sevt = &event->scroll;
+
+  /* There are two choices for handling scroll events:
+     1. convert them into the button presses that XEmacs currently uses
+     2. handle the scroll events in elisp
+
+     Here we choose #1 for compatibility. */
+
+  XSET_EVENT_TYPE (emacs_event, button_release_event);
+  XSET_EVENT_CHANNEL (emacs_event, f);
+
+  /* SET_EVENT_BUTTON_MODIFIERS (emacs_event, modifiers); */
+  XSET_EVENT_TIMESTAMP (emacs_event, sevt->time);
+  XSET_EVENT_BUTTON_X (emacs_event, (int) sevt->x);
+  XSET_EVENT_BUTTON_Y (emacs_event, (int) sevt->y);
+
+  switch (sevt->direction)
+    {
+    case GDK_SCROLL_UP:
+      XSET_EVENT_BUTTON_BUTTON (emacs_event, 4);
+      break;
+    case GDK_SCROLL_DOWN:
+      XSET_EVENT_BUTTON_BUTTON (emacs_event, 5);
+      break;
+    case GDK_SCROLL_LEFT:
+      XSET_EVENT_BUTTON_BUTTON (emacs_event, 6);
+      break;
+    case GDK_SCROLL_RIGHT:
+      XSET_EVENT_BUTTON_BUTTON (emacs_event, 7);
+      break;
+#ifdef GDK_SCROLL_SMOOTH
+    case GDK_SCROLL_SMOOTH:
+      /* XXX Implement me. */
+      break;
+#endif
+    default:
+      stderr_out ("Unknown scroll direction %d\n", sevt->direction);
+      break;
+    }
+  enqueue_dispatch_event (emacs_event);
+}
+
+static void
 emacs_gtk_format_magic_event (Lisp_Event *emacs_event, Lisp_Object pstream)
 {
   Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (emacs_event));
 	}
       break;
 
+    case GDK_SCROLL:
+      handle_scroll_event (f, event);
+      break;
+
     default:
       break;
     }
     case GDK_SELECTION_CLEAR:
     case GDK_SELECTION_REQUEST:
     case GDK_SELECTION_NOTIFY: t = gdk_event->selection.time; break;
+    case GDK_SCROLL:           t = gdk_event->scroll.time; break;
     default: return;
     }
   DEVICE_GTK_LAST_SERVER_TIMESTAMP (d) = t;
            (but it definitely should ignore Caps_Lock). */
         SET_EVENT_MOTION_MODIFIERS (emacs_event, modifiers);
       }
-    break;
+      break;
 
     default: /* it's a magic event */
       return (0);
     case GDK_LEAVE_NOTIFY:      FROB(crossing); break;
     case GDK_FOCUS_CHANGE:      FROB(focus_change); break;
     case GDK_VISIBILITY_NOTIFY: FROB(visibility); break;
+    case GDK_SCROLL:            FROB(scroll); break;
     default:
 	ignore_p = TRUE;
 	/* Hrmm... do we really want to swallow all the other events as magic? */

File src/frame-gtk.c

                             G_CALLBACK (delete_event_cb), f));
 
   {
-    static const gchar *events_to_frob[] = { "focus-in-event",
-				      "focus-out-event",
-				      "enter-notify-event",
-				      "leave-notify-event",
-				      "map-event",
-				      "unmap-event",
-				      "property-notify-event",
-				      "selection-clear-event",
-				      "selection-request-event",
-				      "selection-notify-event",
-				      "client-event",
-				      /* "configure-event", */
-				      "visibility-notify-event",
-				      NULL };
+    static const gchar *events_to_frob[] =
+      {
+	"focus-in-event",
+	"focus-out-event",
+	"enter-notify-event",
+	"leave-notify-event",
+	"map-event",
+	"unmap-event",
+	"property-notify-event",
+	"selection-clear-event",
+	"selection-request-event",
+	"selection-notify-event",
+	"client-event",
+	/* "configure-event", */
+	"visibility-notify-event",
+	"scroll-event",
+	NULL
+      };
     int i;
 
     for (i = 0; events_to_frob[i]; i++)
   /* gtk_signal_connect (GTK_OBJECT (shell), "event", G_CALLBACK (emacs_shell_event_handler), f); */
 
   /* Let's make sure we get all the events we can */
-  gtk_widget_set_events (text, GDK_ALL_EVENTS_MASK);
+  gtk_widget_add_events (text, GDK_ALL_EVENTS_MASK);
 
   if (shell != container)
     gtk_container_add (GTK_CONTAINER (shell), container);