]> git.donarmstrong.com Git - xournal.git/commitdiff
update event processing code for GTK+ 2.18
authorauroux <auroux>
Fri, 25 Sep 2009 22:04:19 +0000 (22:04 +0000)
committerauroux <auroux>
Fri, 25 Sep 2009 22:04:19 +0000 (22:04 +0000)
src/TODO
src/main.c
src/xo-callbacks.c
src/xo-misc.c
src/xo-paint.c
src/xournal.h

index 3c5ec8b1f5b7c8dccaaebc80336eb3cb0b80aff3..b0b973b21e4f5c3e0cb7917e5cf43fd9d54e0d0a 100644 (file)
--- a/src/TODO
+++ b/src/TODO
@@ -48,12 +48,15 @@ DONE: discard Alt-click and Control-click events
 
 (go through Patches tracker and take the good stuff... now at 2009-05-09)
 
-** option to have buttons *toggle* the tool rather than act as tool
-   (ie button 2 causes button 1 to map to tool 2) [Dylan Thurston]
+DONE?? option to have buttons *toggle* the tool rather than act as tool
+       (ie button 2 causes button 1 to map to tool 2) [Dylan Thurston]
+
+** commit patches from Bob McElrath
 
 - paper color chooser (see tracker 2083103)
 - prerelease: update help file (remove references to pdftoppm/libgnomeprint
   & update to poppler/gtkprint)
+- REMOVE BINARY INSTALLER (poppler breaks ABI all the time)
 - document config options into manual file?
 - PDF bg memory usage throttling / delete oldest pdf backgrounds
 - replace ttsubset by something more modern? (eg. from cairo ?)
@@ -71,6 +74,7 @@ DONE: discard Alt-click and Control-click events
    to load pixmaps from pixmaps/$THEME/ (see Jan 9, 2009 emails)
 ** autosave patch (Edward Yang) (fix: optional only, w/ menu + cfgfile
    entries; fix: should clean up autosave.xoj.bg* files too; config interval)
+- horizontal mode instead of dual-view / multicolumn ?
 - patch (ikim@physics.wisc.edu): multicolumn mode + LASSO SELECTION
 - patch: ortho/snap (revised Apr 13 2009)
 ** FIXME: get_pressure_multiplier() should access correct members
@@ -95,6 +99,10 @@ DONE: discard Alt-click and Control-click events
   PDF file, default paper
 - bug in truetype subset generation w/ Adobe 9, see if gtk-print any better?
 
+- drag-and-drop, copy-paste text & images directly into xournal
+- proximity detection: eraser proximity switches mapping? 
+  proximity out removes cursor until next motionnotify?
+
 - render page to bitmap: for export, preview, and copy-paste
     (render using libart, see how gnomecanvas does it?)
     NO: render using Cairo !!! then can switch to GtkPrint as well.
index 2a2dbda4e701a7f89364f99d5fe41c31f042fc07..001d09b6e3bdb6f44cede862f4cc0a011b5a8f92 100644 (file)
@@ -101,6 +101,7 @@ void init_stuff (int argc, char *argv[])
     g_memmove(ui.default_brushes+i, &(ui.brushes[0][i]), sizeof(struct Brush));
 
   ui.cur_mapping = 0;
+  ui.which_unswitch_button = 0;
   
   reset_recognizer();
 
@@ -223,9 +224,9 @@ void init_stuff (int argc, char *argv[])
   gtk_check_menu_item_set_active(
     GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsUseXInput")), ui.use_xinput);
 
-  /* fix a bug in GTK+ 2.16 and beyond: scrollbars shouldn't get extended
+  /* fix a bug in GTK+ 2.16 and 2.17: scrollbars shouldn't get extended
      input events from pointer motion when cursor moves into main window */
-#if GTK_CHECK_VERSION(2,14,0)
+
   if (!gtk_check_version(2, 16, 0)) {
     g_signal_connect (
       GET_COMPONENT("menubar"),
@@ -256,7 +257,6 @@ void init_stuff (int argc, char *argv[])
       "notify::popup-shown", G_CALLBACK (combobox_popup_disable_xinput),
       NULL);
   }
-#endif
 
   // load the MRU
   
index 71771cd2f0199e6c1aa3a415c1bf6d24466f6e98..b1b35bb732cdae157317539a8b6edf0137154a6e 100644 (file)
@@ -2356,22 +2356,52 @@ on_canvas_button_press_event           (GtkWidget       *widget,
   int mapping;
   gboolean is_core;
   struct Item *item;
+  GdkEvent scroll_event;
 
+#ifdef INPUT_DEBUG
+  printf("DEBUG: ButtonPress (%s) (x,y)=(%.2f,%.2f), button %d, modifier %x\n", 
+    event->device->name, event->x, event->y, event->button, event->state);
+#endif
+
+  if (ui.cur_item_type != ITEM_TEXT) // remove focus from other elements
+    gtk_widget_grab_focus(GTK_WIDGET(canvas));
+    
   is_core = (event->device == gdk_device_get_core_pointer());
   if (!ui.use_xinput && !is_core) return FALSE;
   if (ui.use_xinput && is_core && ui.discard_corepointer) return FALSE;
-  if (event->button > 3) return FALSE; // no painting with the mouse wheel!
   if (event->type != GDK_BUTTON_PRESS) return FALSE; 
     // double-clicks may have broken axes member (free'd) due to a bug in GDK
+
+  if (event->button > 3) { // scroll wheel events! don't paint...
+    if (ui.use_xinput && !gtk_check_version(2, 17, 0) && event->button <= 7) {
+      /* with GTK+ 2.17 and later, the entire widget hierarchy is xinput-aware,
+         so the core button event gets discarded and the scroll event never 
+         gets processed by the main window. This is arguably a GTK+ bug.
+         We work around it. */
+      scroll_event.scroll.type = GDK_SCROLL;
+      scroll_event.scroll.window = event->window;
+      scroll_event.scroll.send_event = event->send_event;
+      scroll_event.scroll.time = event->time;
+      scroll_event.scroll.x = event->x;
+      scroll_event.scroll.y = event->y;
+      scroll_event.scroll.state = event->state;
+      scroll_event.scroll.device = event->device;
+      scroll_event.scroll.x_root = event->x_root;
+      scroll_event.scroll.y_root = event->y_root;
+      if (event->button == 4) scroll_event.scroll.direction = GDK_SCROLL_UP;
+      else if (event->button == 5) scroll_event.scroll.direction = GDK_SCROLL_DOWN;
+      else if (event->button == 6) scroll_event.scroll.direction = GDK_SCROLL_LEFT;
+      else scroll_event.scroll.direction = GDK_SCROLL_RIGHT;
+      printf("sending...\n");
+      gtk_widget_event(GET_COMPONENT("scrolledwindowMain"), &scroll_event);
+    }
+    return FALSE;
+  }
   if ((event->state & (GDK_CONTROL_MASK|GDK_MOD1_MASK)) != 0) return FALSE;
     // no control-clicking or alt-clicking
   if (!is_core)
     fix_xinput_coords((GdkEvent *)event);
 
-#ifdef INPUT_DEBUG
-  printf("DEBUG: ButtonDown (%s) (x,y)=(%.2f,%.2f)\n", 
-    is_core?"core":"xinput", event->x, event->y);
-#endif
   if (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
 
   if (ui.cur_item_type == ITEM_TEXT) {
@@ -2388,17 +2418,21 @@ on_canvas_button_press_event           (GtkWidget       *widget,
 
   // if button_switch_mapping enabled, button 2 or 3 clicks only switch mapping
   if (ui.button_switch_mapping && event->button > 1) {
-    if (is_core == ui.use_xinput) return FALSE; // duplicate event
-    if (ui.cur_mapping == event->button-1) switch_mapping(0);
-    else switch_mapping(event->button-1);
+    ui.which_unswitch_button = event->button;
+    switch_mapping(event->button-1);
     return FALSE;
   }
 
   ui.is_corestroke = is_core;
+  ui.stroke_device = event->device;
 
   if (ui.use_erasertip && event->device->source == GDK_SOURCE_ERASER)
-       mapping = NUM_BUTTONS;
-  else if (ui.button_switch_mapping) mapping = ui.cur_mapping;
+    mapping = NUM_BUTTONS;
+  else if (ui.button_switch_mapping) {
+    mapping = ui.cur_mapping;
+    if (!mapping && (event->state & GDK_BUTTON2_MASK)) mapping = 1;
+    if (!mapping && (event->state & GDK_BUTTON3_MASK)) mapping = 2;
+  }
   else mapping = event->button-1;
 
   // check whether we're in a page
@@ -2493,15 +2527,20 @@ on_canvas_button_release_event         (GtkWidget       *widget,
 {
   gboolean is_core;
   
-  if (ui.cur_item_type == ITEM_NONE) return FALSE; // not doing anything
-
-  if (event->button != ui.which_mouse_button) return FALSE; // ignore
+#ifdef INPUT_DEBUG
+  printf("DEBUG: ButtonRelease (%s) (x,y)=(%.2f,%.2f), button %d, modifier %x\n", 
+      event->device->name, event->x, event->y, event->button, event->state);
+#endif
 
   is_core = (event->device == gdk_device_get_core_pointer());
   if (!ui.use_xinput && !is_core) return FALSE;
   if (ui.use_xinput && is_core && !ui.is_corestroke) return FALSE;
   if (!is_core) fix_xinput_coords((GdkEvent *)event);
 
+  if (event->button != ui.which_mouse_button && 
+      event->button != ui.which_unswitch_button)
+    return FALSE;
+
   if (ui.cur_item_type == ITEM_STROKE) {
     finalize_stroke();
     if (ui.cur_brush->recognizer) recognize_patterns();
@@ -2521,9 +2560,10 @@ on_canvas_button_release_event         (GtkWidget       *widget,
   else if (ui.cur_item_type == ITEM_HAND) {
     ui.cur_item_type = ITEM_NONE;
   }
+  
+  if (!ui.which_unswitch_button || event->button == ui.which_unswitch_button)
+    switch_mapping(0); // will reset ui.which_unswitch_button
 
-  if (!ui.button_switch_mapping || ui.cur_mapping == NUM_BUTTONS) 
-    switch_mapping(0);
   return FALSE;
 }
 
@@ -2603,6 +2643,7 @@ on_canvas_motion_notify_event          (GtkWidget       *widget,
 {
   gboolean looks_wrong, is_core;
   double pt[2];
+  GdkModifierType mask;
 
   /* we don't care about this event unless some operation is in progress;
      or if there's a selection (then we might want to change the mouse
@@ -2625,11 +2666,15 @@ on_canvas_motion_notify_event          (GtkWidget       *widget,
   if (!is_core) ui.is_corestroke = FALSE;
 
 #ifdef INPUT_DEBUG
-  printf("DEBUG: MotionNotify (%s) (x,y)=(%.2f,%.2f)\n", 
-    is_core?"core":"xinput", event->x, event->y);
+  printf("DEBUG: MotionNotify (%s) (x,y)=(%.2f,%.2f), modifier %x\n", 
+    is_core?"core":"xinput", event->x, event->y, event->state);
 #endif
   
   looks_wrong = !(event->state & (1<<(7+ui.which_mouse_button)));
+  if (looks_wrong) {
+    gdk_device_get_state(ui.stroke_device, event->window, NULL, &mask);
+    looks_wrong = !(mask & (1<<(7+ui.which_mouse_button)));
+  }
   
   if (looks_wrong) { /* mouse button shouldn't be up... give up */
     if (ui.cur_item_type == ITEM_STROKE) {
@@ -2734,12 +2779,11 @@ on_optionsUseXInput_activate           (GtkMenuItem     *menuitem,
 
 /* HOW THINGS USED TO BE:
 
-   We'd like ONLY the canvas window itself to receive
-   XInput events, while its child window in the GDK hierarchy (also
-   associated to the canvas widget) receives the core events.
-   This way on_canvas_... will get both types of events -- otherwise,
-   the proximity detection code in GDK is broken and we'll lose core
-   events.
+   We'd like on_canvas_... to get BOTH core and xinput events. Up to
+   GTK+ 2.16 this is achieved by making only the canvas's parent 
+   GdkWindow xinput-aware, rather than the entire hierarchy.
+   Otherwise, the proximity detection code in GDK is broken and 
+   we'll lose core events.
    
    Up to GTK+ 2.10, gtk_widget_set_extension_events() only sets
    extension events for the widget's main window itself; in GTK+ 2.11
@@ -2754,17 +2798,23 @@ on_optionsUseXInput_activate           (GtkMenuItem     *menuitem,
    non-responsive). 
 */
 
-  // this causes core events to be discarded... unwanted!
-/*
-   gtk_widget_set_extension_events(GTK_WIDGET (canvas), 
+  if (!gtk_check_version(2, 17, 0)) {
+    /* GTK+ 2.17 and later: everybody shares a single native window,
+       so we'll never get any core events, and we might as well set 
+       extension events the way we're supposed to. Doing so helps solve 
+       crasher bugs in 2.17, and prevents us from losing two-button
+       events in 2.18 */
+    gtk_widget_set_extension_events(GTK_WIDGET (canvas), 
+       ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
+  } else {
+    /* GTK+ 2.16 and earlier: we only activate extension events on the
+       canvas's parent GdkWindow. This allows us to keep receiving core
+       events. */
+    gdk_input_set_extension_events(GTK_WIDGET(canvas)->window, 
+      GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
       ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
-*/
-
-  // this version only activates extension events on the canvas's parent GdkWindow
-  gdk_input_set_extension_events(GTK_WIDGET(canvas)->window, 
-    GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
-    ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
-
+  }
+  
   update_mappings_menu();
 }
 
index b7448459e2ca69a26ed76e1ea6e5fe22f12d424f..1c29a306a825d679021cf3fc85793a839e09d1f1 100644 (file)
@@ -93,15 +93,15 @@ struct Page *new_page_with_bg(struct Background *bg, double width, double height
 void realloc_cur_path(int n)
 {
   if (n <= ui.cur_path_storage_alloc) return;
-  ui.cur_path_storage_alloc = n+10;
-  ui.cur_path.coords = g_realloc(ui.cur_path.coords, 2*(n+10)*sizeof(double));
+  ui.cur_path_storage_alloc = n+100;
+  ui.cur_path.coords = g_realloc(ui.cur_path.coords, 2*(n+100)*sizeof(double));
 }
 
 void realloc_cur_widths(int n)
 {
   if (n <= ui.cur_widths_storage_alloc) return;
-  ui.cur_widths_storage_alloc = n+10;
-  ui.cur_widths = g_realloc(ui.cur_widths, (n+10)*sizeof(double));
+  ui.cur_widths_storage_alloc = n+100;
+  ui.cur_widths = g_realloc(ui.cur_widths, (n+100)*sizeof(double));
 }
 
 // undo utility functions
@@ -395,14 +395,18 @@ void fix_xinput_coords(GdkEvent *event)
     *py = iy + sy;
   }
   else {
-    *px += sx;
-    *py += sy;
+    /* with GTK+ 2.16 or earlier, the event comes from the parent gdkwindow
+       and so needs to be adjusted for scrolling */
+    if (gtk_major_version == 2 && gtk_minor_version <= 16) {
+      *px += sx;
+      *py += sy;
+    }
     /* with GTK+ 2.17, events come improperly translated, and the event's
        GdkWindow isn't even the same for ButtonDown as for MotionNotify... */
-    if (!gtk_check_version(2,17,0)) { // GTK+ 2.17 issues !!
+    if (gtk_major_version == 2 && gtk_minor_version == 17) { // GTK+ 2.17 issues !!
       gdk_window_get_position(GTK_WIDGET(canvas)->window, &wx, &wy);
-      *px -= wx;
-      *py -= wy;
+      *px += sx - wx;
+      *py += sy - wy;
     }
   }
 #endif
@@ -1798,7 +1802,8 @@ void resize_journal_items_by(GList *itemlist, double scaling_x, double scaling_y
 
 /* NOTE ABOUT BUTTON MAPPINGS: ui.cur_mapping is 0 except while a canvas
    click event is being processed ... or if ui.button_switch_mapping is
-   enabled and mappings are switched! */
+   enabled and mappings are switched (but even then, canvas should have
+   a pointer grab from the initial click that switched the mapping) */
 
 void switch_mapping(int m)
 {
@@ -1809,6 +1814,8 @@ void switch_mapping(int m)
     ui.cur_brush = &(ui.brushes[m][ui.toolno[m]]);
   if (ui.toolno[m] == TOOL_TEXT)
     ui.cur_brush = &(ui.brushes[m][TOOL_PEN]);
+  if (m==0) ui.which_unswitch_button = 0;
+  
   update_tool_buttons();
   update_color_menu();
   update_cursor();
@@ -2114,9 +2121,6 @@ gboolean combobox_popup_disable_xinput (GtkWidget *widget, GdkEvent *event,
   gboolean is_shown;
   
   g_object_get(G_OBJECT(widget), "popup-shown", &is_shown, NULL);
-  gdk_input_set_extension_events(GTK_WIDGET(canvas)->window, 
-     GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
-     (ui.use_xinput && !is_shown)?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
+  gtk_widget_set_extension_events(GTK_WIDGET (canvas), 
+       (ui.use_xinput && !is_shown)?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
 }
-
-
index 85e3536a488430b7c81833475f7431cdd5c1eea9..ba6ffffa694ff9140e3e47f0fd9b738a7da96805 100644 (file)
@@ -1215,13 +1215,10 @@ void start_text(GdkEvent *event, struct Item *item)
   get_pointer_coords(event, pt);
   ui.cur_item_type = ITEM_TEXT;
 
-  // HACK TO BYPASS GTK+ 2.17 issues
+  // HACK TO BYPASS GTK+ 2.17 issue: crash if move text within selection
+  // also bypass: non-responsiveness of clicks in text box with 2.17 & 2.18
   if (!gtk_check_version(2, 17, 0)) {
-    /* first we make *all* canvas subwindows become XInput aware, 
-       so that it'll be safe to disable XInput later on... (!!!) */
-    gtk_widget_set_extension_events(GTK_WIDGET (canvas), 
-       ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
-    /* then we ask the canvas's leave-notify handler to disable 
+    /* ask the canvas's leave-notify handler to disable 
        xinput when it's safe to do so... */
     ui.need_emergency_disable_xinput = TRUE;
   }
@@ -1292,9 +1289,8 @@ void end_text(void)
   // HACK TO BYPASS GTK+ 2.17 issues
   if (!gtk_check_version(2, 17, 0)) {
     // re-enable XInput if needed (we disabled it during text edition)
-    gdk_input_set_extension_events(GTK_WIDGET(canvas)->window, 
-      GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
-      ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
+    gtk_widget_set_extension_events(GTK_WIDGET (canvas), 
+       ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
   }
   
   // finalize the text that's been edited... 
index 6233fe74482c605c59de78d0f431d5b113674958..61eb21801e8549334f127d1a25cee6e9add92592 100644 (file)
@@ -223,6 +223,7 @@ typedef struct UIData {
   gboolean button_switch_mapping; // button clicks switch button 1 mappings
   gboolean use_erasertip;
   int which_mouse_button; // the mouse button drawing the current path
+  int which_unswitch_button; // if button_switch_mapping, the mouse button that switched the mapping
   struct Page default_page;  // the model for the default page
   int layerbox_length;  // the number of entries registered in the layers combo-box
   struct Item *cur_item; // the item being drawn, or NULL
@@ -238,6 +239,7 @@ typedef struct UIData {
   gboolean pressure_sensitivity; // use pen pressure to control stroke width?
   double width_minimum_multiplier, width_maximum_multiplier; // calibration for pressure sensitivity
   gboolean is_corestroke; // this stroke is painted with core pointer
+  GdkDevice *stroke_device; // who's painting this stroke
   int screen_width, screen_height; // initial screen size, for XInput events
   double hand_refpt[2];
   int hand_scrollto_cx, hand_scrollto_cy;