File xournal-fix-strokes-on-Lenovo-active-pen.patch of Package xournal
ChangeLog | 6 ++++++
src/xo-clipboard.c | 2 ++
src/xo-file.c | 5 +++++
src/xo-paint.c | 35 +++++++++++++++++++++++++++++++++--
src/xournal.h | 1 +
5 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7c6d8c6..8fd18f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+This version:
+ - keep selection in clipboard after exiting
+ - config option to fix unreliable stroke origin (Lenovo AES pen issues)
+ (use in conjunction with xsetwacom to set RawSample = 1 or 2 until
+ wacom driver fix is committed).
+
Version 0.4.8.2016 (July 20, 2017 bugfix release):
* Bug fixes:
- pen and touchscreen input handling bugfixes (bug #136 and others)
diff --git a/src/xo-clipboard.c b/src/xo-clipboard.c
index 253605e..d998648 100644
--- a/src/xo-clipboard.c
+++ b/src/xo-clipboard.c
@@ -189,6 +189,8 @@ void selection_to_clip(void)
gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
targets, n_targets,
callback_clipboard_get, callback_clipboard_clear, sel);
+ gtk_clipboard_set_can_store(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
+ targets, n_targets);
gtk_target_table_free(targets, n_targets);
}
diff --git a/src/xo-file.c b/src/xo-file.c
index 0285b2b..4b8b5b2 100644
--- a/src/xo-file.c
+++ b/src/xo-file.c
@@ -1767,6 +1767,7 @@ void init_config_default(void)
ui.autosave_delay = 5;
ui.autosave_loop_running = FALSE;
ui.autosave_need_catchup = FALSE;
+ ui.fix_stroke_origin = FALSE;
// the default UI vertical order
ui.vertical_order[0][0] = 1;
@@ -1917,6 +1918,9 @@ void save_config_to_file(void)
update_keyval("general", "buttons_switch_mappings",
_(" buttons 2 and 3 switch mappings instead of drawing (useful for some tablets) (true/false)"),
g_strdup(ui.button_switch_mapping?"true":"false"));
+ update_keyval("general", "fix_stroke_origin",
+ _(" fix origin of strokes (devices with unreliable button press coordinates, e.g. Lenovo's AES pens) (true/false)"),
+ g_strdup(ui.fix_stroke_origin?"true":"false"));
update_keyval("general", "autoload_pdf_xoj",
_(" automatically load filename.pdf.xoj instead of filename.pdf (true/false)"),
g_strdup(ui.autoload_pdf_xoj?"true":"false"));
@@ -2337,6 +2341,7 @@ void load_config_from_file(void)
if (parse_keyval_string("general", "touchscreen_device_name", &str))
if (str!=NULL) ui.device_for_touch = str;
parse_keyval_boolean("general", "buttons_switch_mappings", &ui.button_switch_mapping);
+ parse_keyval_boolean("general", "fix_stroke_origin", &ui.fix_stroke_origin);
parse_keyval_boolean("general", "autoload_pdf_xoj", &ui.autoload_pdf_xoj);
parse_keyval_boolean("general", "autocreate_new_xoj", &ui.autocreate_new_xoj);
parse_keyval_boolean("general", "autosave_enabled", &ui.autosave_enabled);
diff --git a/src/xo-paint.c b/src/xo-paint.c
index 2331ff7..cf9614b 100644
--- a/src/xo-paint.c
+++ b/src/xo-paint.c
@@ -258,7 +258,7 @@ void continue_stroke(GdkEvent *event)
}
get_pointer_coords(event, pt+2);
-
+
if (ui.cur_item->brush.variable_width) {
realloc_cur_widths(ui.cur_path.num_points);
pressure = get_pressure_multiplier(event);
@@ -308,8 +308,34 @@ void abort_stroke(void)
ui.cur_item_type = ITEM_NONE;
}
+#define HOOK_MAX_ANGLE_COS 0.9
+
+gboolean fix_origin_if_needed(double *pt)
+{
+ double dotproduct,len1,len2;
+ dotproduct = (pt[2]-pt[0])*(pt[4]-pt[2]) + (pt[3]-pt[1])*(pt[5]-pt[3]);
+ len1 = hypot(pt[2]-pt[0],pt[3]-pt[1]);
+ len2 = hypot(pt[4]-pt[2],pt[5]-pt[3]);
+ if (dotproduct < HOOK_MAX_ANGLE_COS * len1 * len2) {
+ // straighten
+/*
+ if (dotproduct > 0 && len2 > EPSILON) {
+ pt[0] = pt[2]-dotproduct*(pt[4]-pt[2])/len2/len2;
+ pt[1] = pt[3]-dotproduct*(pt[5]-pt[3])/len2/len2;
+ } else */
+ {
+ pt[0] = pt[2];
+ pt[1] = pt[3];
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
void finalize_stroke(void)
{
+ gboolean need_refresh = FALSE;
+
if (ui.cur_path.num_points == 1) { // GnomeCanvas doesn't like num_points=1
ui.cur_path.coords[2] = ui.cur_path.coords[0]+0.1;
ui.cur_path.coords[3] = ui.cur_path.coords[1];
@@ -317,6 +343,11 @@ void finalize_stroke(void)
ui.cur_item->brush.variable_width = FALSE;
}
+ /* fix AES pen mess on Lenovo X1 Yoga 2nd gen and similar... */
+ if (ui.fix_stroke_origin && ui.cur_path.num_points > 2) {
+ need_refresh = fix_origin_if_needed(ui.cur_path.coords);
+ }
+
if (!ui.cur_item->brush.variable_width)
subdivide_cur_path(); // split the segment so eraser will work
@@ -330,7 +361,7 @@ void finalize_stroke(void)
update_item_bbox(ui.cur_item);
ui.cur_path.num_points = 0;
- if (!ui.cur_item->brush.variable_width) {
+ if (!ui.cur_item->brush.variable_width || need_refresh) {
// destroy the entire group of temporary line segments
gtk_object_destroy(GTK_OBJECT(ui.cur_item->canvas_item));
// make a new line item to replace it
diff --git a/src/xournal.h b/src/xournal.h
index 3599e77..d49cdfc 100644
--- a/src/xournal.h
+++ b/src/xournal.h
@@ -271,6 +271,7 @@ typedef struct UIData {
gboolean touch_as_handtool; // always map touch device to hand tool?
gboolean pen_disables_touch; // pen proximity should disable touch device?
gboolean in_proximity;
+ gboolean fix_stroke_origin; // fix for devices with bad button-press coords?
char *device_for_touch;
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