]> git.donarmstrong.com Git - xournal.git/blobdiff - src/xo-misc.c
avoid compile error on GTK+ 2.10
[xournal.git] / src / xo-misc.c
index 65a948e3a7f75694743782b3214a3431cc8b51cb..bc4747cd35e28d75c26f1738610c599e13fada41 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ *  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.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of  
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
@@ -340,6 +355,12 @@ void refstring_unref(struct Refstring *rs)
 
 // some helper functions
 
+int finite_sized(double x) // detect unrealistic coordinate values
+{
+  return (finite(x) && x<1E6 && x>-1E6);
+}
+
+
 void get_pointer_coords(GdkEvent *event, gdouble *ret)
 {
   double x, y;
@@ -373,7 +394,7 @@ void fix_xinput_coords(GdkEvent *event)
 
 #ifdef ENABLE_XINPUT_BUGFIX
   // fix broken events with the core pointer's location
-  if (!finite(axes[0]) || !finite(axes[1]) || (axes[0]==0. && axes[1]==0.)) {
+  if (!finite_sized(axes[0]) || !finite_sized(axes[1]) || axes[0]==0. || axes[1]==0.) {
     gdk_window_get_pointer(GTK_WIDGET(canvas)->window, &ix, &iy, NULL);
     *px = ix + sx; 
     *py = iy + sy;
@@ -388,7 +409,7 @@ void fix_xinput_coords(GdkEvent *event)
       *py = (axes[1]/axis_width)*ui.screen_height + sy - wy;
   }
 #else
-  if (!finite(*px) || !finite(*py) || (*px==0. && *py==0.)) {
+  if (!finite_sized(*px) || !finite_sized(*py) || *px==0. || *py==0.) {
     gdk_window_get_pointer(GTK_WIDGET(canvas)->window, &ix, &iy, NULL);
     *px = ix + sx; 
     *py = iy + sy;
@@ -430,7 +451,7 @@ double get_pressure_multiplier(GdkEvent *event)
       || device->num_axes <= 2) return 1.0;
 
   rawpressure = axes[2]/(device->axes[2].max - device->axes[2].min);
-  if (!finite(rawpressure)) return 1.0;
+  if (!finite_sized(rawpressure)) return 1.0;
 
   return ((1-rawpressure)*ui.width_minimum_multiplier + rawpressure*ui.width_maximum_multiplier);
 }
@@ -1652,6 +1673,10 @@ void process_paperstyle_activate(GtkMenuItem *menuitem, int style)
   if (must_upd) update_page_stuff();
 }
 
+#ifndef GTK_STOCK_DISCARD
+#define GTK_STOCK_DISCARD GTK_STOCK_NO
+#endif
+
 gboolean ok_to_close(void)
 {
   GtkWidget *dialog;