From 6bfe4867a794590561e788e99e28752e7a8c76fe Mon Sep 17 00:00:00 2001 From: auroux Date: Sat, 11 Aug 2012 21:32:22 +0000 Subject: [PATCH] ignore events from non-drawing devices by default (ignore_other_devices) --- ChangeLog | 1 + src/xo-callbacks.c | 10 ++++++++-- src/xo-clipboard.c | 2 +- src/xo-file.c | 17 +++++++++++------ src/xo-misc.c | 8 ++++---- src/xournal.h | 1 + 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b464b9..0d7dc74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ This version: - work around Win32 bug: refuse paste if mismatched format - Chinese (simplified) translation (by Mutse) - updated German translation (Stefan Holtzhauer) + - ignore events from non-drawing devices by default (ignore_other_devices) Version 0.4.7 (July 4, 2012): - insert image tool (based on patches by Victor Saase and Simon Guest) diff --git a/src/xo-callbacks.c b/src/xo-callbacks.c index 50672f6..8dad7c9 100644 --- a/src/xo-callbacks.c +++ b/src/xo-callbacks.c @@ -2457,6 +2457,7 @@ on_canvas_button_press_event (GtkWidget *widget, ui.cur_path.num_points == 1) { // Xorg 7.3+ sent core event before XInput event: fix initial point ui.is_corestroke = FALSE; + ui.stroke_device = event->device; get_pointer_coords((GdkEvent *)event, ui.cur_path.coords); } if (ui.cur_item_type != ITEM_NONE) return FALSE; // we're already doing something @@ -2573,6 +2574,7 @@ on_canvas_button_release_event (GtkWidget *widget, 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 (ui.ignore_other_devices && ui.stroke_device!=event->device) return FALSE; if (!is_core) fix_xinput_coords((GdkEvent *)event); if (event->button != ui.which_mouse_button && @@ -2760,11 +2762,15 @@ on_canvas_motion_notify_event (GtkWidget *widget, } if (ui.use_xinput && is_core && !ui.is_corestroke) return FALSE; - if (!is_core) ui.is_corestroke = FALSE; + if (!is_core && ui.is_corestroke) { + ui.is_corestroke = FALSE; + ui.stroke_device = event->device; + } + if (ui.ignore_other_devices && ui.stroke_device!=event->device) return FALSE; #ifdef INPUT_DEBUG printf("DEBUG: MotionNotify (%s) (x,y)=(%.2f,%.2f), modifier %x\n", - is_core?"core":"xinput", event->x, event->y, event->state); + event->device->name, event->x, event->y, event->state); #endif looks_wrong = !(event->state & (1<<(7+ui.which_mouse_button))); diff --git a/src/xo-clipboard.c b/src/xo-clipboard.c index 3d6cb41..7beef32 100644 --- a/src/xo-clipboard.c +++ b/src/xo-clipboard.c @@ -71,7 +71,7 @@ void callback_clipboard_clear(GtkClipboard *clipboard, gpointer user_data) if (sel->xo_data!=NULL) g_free(sel->xo_data); if (sel->text_data!=NULL) g_free(sel->text_data); - if (sel->image_data!=NULL) gdk_pixbuf_unref(sel->image_data); + if (sel->image_data!=NULL) g_object_unref(sel->image_data); g_free(sel); } diff --git a/src/xo-file.c b/src/xo-file.c index 082d399..ac8753c 100644 --- a/src/xo-file.c +++ b/src/xo-file.c @@ -456,7 +456,7 @@ void xoj_parser_start_element(GMarkupParseContext *context, { *error = xoj_invalid(); return; } tmpPage->bg->filename = refstring_ref(tmpbg->filename); tmpPage->bg->pixbuf = tmpbg->pixbuf; - if (tmpbg->pixbuf!=NULL) gdk_pixbuf_ref(tmpbg->pixbuf); + if (tmpbg->pixbuf!=NULL) g_object_ref(tmpbg->pixbuf); tmpPage->bg->file_domain = tmpbg->file_domain; } else { @@ -1033,7 +1033,7 @@ GList *attempt_load_gv_bg(char *filename) if (remnlen == 0) { // make a new bg pix = gdk_pixbuf_loader_get_pixbuf(loader); if (pix == NULL) break; - gdk_pixbuf_ref(pix); + g_object_ref(pix); gdk_pixbuf_loader_close(loader, NULL); g_object_unref(loader); loader = NULL; @@ -1177,7 +1177,7 @@ gboolean bgpdf_scheduler_callback(gpointer data) bgpdf.npages++; } bgpg = g_list_nth_data(bgpdf.pages, req->pageno-1); - if (bgpg->pixbuf!=NULL) gdk_pixbuf_unref(bgpg->pixbuf); + if (bgpg->pixbuf!=NULL) g_object_unref(bgpg->pixbuf); bgpg->pixbuf = pixbuf; bgpg->dpi = req->dpi; bgpg->pixel_height = scaled_height; @@ -1240,7 +1240,7 @@ void shutdown_bgpdf(void) refstring_unref(bgpdf.filename); for (list = bgpdf.pages; list != NULL; list = list->next) { pdfpg = (struct BgPdfPage *)list->data; - if (pdfpg->pixbuf!=NULL) gdk_pixbuf_unref(pdfpg->pixbuf); + if (pdfpg->pixbuf!=NULL) g_object_unref(pdfpg->pixbuf); g_free(pdfpg); } g_list_free(bgpdf.pages); @@ -1358,8 +1358,8 @@ void bgpdf_update_bg(int pageno, struct BgPdfPage *bgpg) for (list = journal.pages; list!= NULL; list = list->next) { pg = (struct Page *)list->data; if (pg->bg->type == BG_PDF && pg->bg->file_page_seq == pageno) { - if (pg->bg->pixbuf!=NULL) gdk_pixbuf_unref(pg->bg->pixbuf); - pg->bg->pixbuf = gdk_pixbuf_ref(bgpg->pixbuf); + if (pg->bg->pixbuf!=NULL) g_object_unref(pg->bg->pixbuf); + pg->bg->pixbuf = g_object_ref(bgpg->pixbuf); pg->bg->pixel_width = bgpg->pixel_width; pg->bg->pixel_height = bgpg->pixel_height; update_canvas_bg(pg); @@ -1477,6 +1477,7 @@ void init_config_default(void) ui.view_continuous = TRUE; ui.allow_xinput = TRUE; ui.discard_corepointer = FALSE; + ui.ignore_other_devices = TRUE; ui.left_handed = FALSE; ui.shorten_menus = FALSE; ui.shorten_menu_items = g_strdup(DEFAULT_SHORTEN_MENUS); @@ -1629,6 +1630,9 @@ void save_config_to_file(void) update_keyval("general", "discard_corepointer", _(" discard Core Pointer events in XInput mode (true/false)"), g_strdup(ui.discard_corepointer?"true":"false")); + update_keyval("general", "ignore_other_devices", + _(" ignore events from other devices while drawing (true/false)"), + g_strdup(ui.ignore_other_devices?"true":"false")); update_keyval("general", "use_erasertip", _(" always map eraser tip to eraser (true/false)"), g_strdup(ui.use_erasertip?"true":"false")); @@ -2022,6 +2026,7 @@ void load_config_from_file(void) parse_keyval_boolean("general", "view_continuous", &ui.view_continuous); parse_keyval_boolean("general", "use_xinput", &ui.allow_xinput); parse_keyval_boolean("general", "discard_corepointer", &ui.discard_corepointer); + parse_keyval_boolean("general", "ignore_other_devices", &ui.ignore_other_devices); parse_keyval_boolean("general", "use_erasertip", &ui.use_erasertip); parse_keyval_boolean("general", "buttons_switch_mappings", &ui.button_switch_mapping); parse_keyval_boolean("general", "autoload_pdf_xoj", &ui.autoload_pdf_xoj); diff --git a/src/xo-misc.c b/src/xo-misc.c index 3d866cf..43279f2 100644 --- a/src/xo-misc.c +++ b/src/xo-misc.c @@ -65,7 +65,7 @@ struct Page *new_page(struct Page *template) pg->bg = (struct Background *)g_memdup(template->bg, sizeof(struct Background)); pg->bg->canvas_item = NULL; if (pg->bg->type == BG_PIXMAP || pg->bg->type == BG_PDF) { - gdk_pixbuf_ref(pg->bg->pixbuf); + g_object_ref(pg->bg->pixbuf); refstring_ref(pg->bg->filename); } pg->group = (GnomeCanvasGroup *) gnome_canvas_item_new( @@ -204,7 +204,7 @@ void clear_redo_stack(void) else if (redo->type == ITEM_NEW_BG_ONE || redo->type == ITEM_NEW_BG_RESIZE || redo->type == ITEM_NEW_DEFAULT_BG) { if (redo->bg->type == BG_PIXMAP || redo->bg->type == BG_PDF) { - if (redo->bg->pixbuf!=NULL) gdk_pixbuf_unref(redo->bg->pixbuf); + if (redo->bg->pixbuf!=NULL) g_object_unref(redo->bg->pixbuf); refstring_unref(redo->bg->filename); } g_free(redo->bg); @@ -276,7 +276,7 @@ void clear_undo_stack(void) else if (undo->type == ITEM_NEW_BG_ONE || undo->type == ITEM_NEW_BG_RESIZE || undo->type == ITEM_NEW_DEFAULT_BG) { if (undo->bg->type == BG_PIXMAP || undo->bg->type == BG_PDF) { - if (undo->bg->pixbuf!=NULL) gdk_pixbuf_unref(undo->bg->pixbuf); + if (undo->bg->pixbuf!=NULL) g_object_unref(undo->bg->pixbuf); refstring_unref(undo->bg->filename); } g_free(undo->bg); @@ -333,7 +333,7 @@ void delete_page(struct Page *pg) if (pg->group!=NULL) gtk_object_destroy(GTK_OBJECT(pg->group)); // this also destroys the background's canvas items if (pg->bg->type == BG_PIXMAP || pg->bg->type == BG_PDF) { - if (pg->bg->pixbuf != NULL) gdk_pixbuf_unref(pg->bg->pixbuf); + if (pg->bg->pixbuf != NULL) g_object_unref(pg->bg->pixbuf); if (pg->bg->filename != NULL) refstring_unref(pg->bg->filename); } g_free(pg->bg); diff --git a/src/xournal.h b/src/xournal.h index 3ef9b27..62625ab 100644 --- a/src/xournal.h +++ b/src/xournal.h @@ -276,6 +276,7 @@ typedef struct UIData { gboolean is_corestroke; // this stroke is painted with core pointer gboolean saved_is_corestroke; GdkDevice *stroke_device; // who's painting this stroke + gboolean ignore_other_devices; int screen_width, screen_height; // initial screen size, for XInput events double hand_refpt[2]; int hand_scrollto_cx, hand_scrollto_cy; -- 2.39.2