X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fxo-callbacks.c;h=7c520229fbbd68c8137da2525b4d139069569eb5;hb=881e9a45693f4d724512fdc5297ba312d447851b;hp=71771cd2f0199e6c1aa3a415c1bf6d24466f6e98;hpb=34dbe92edd95fbf7082c3e54f438c76355254fe5;p=xournal.git diff --git a/src/xo-callbacks.c b/src/xo-callbacks.c index 71771cd..7c52022 100644 --- a/src/xo-callbacks.c +++ b/src/xo-callbacks.c @@ -53,6 +53,9 @@ on_fileNewBackground_activate (GtkMenuItem *menuitem, dialog = gtk_file_chooser_dialog_new(_("Open PDF"), GTK_WINDOW (winMain), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); +#ifdef FILE_DIALOG_SIZE_BUGFIX + gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400); +#endif filt_all = gtk_file_filter_new(); gtk_file_filter_set_name(filt_all, _("All files")); @@ -124,6 +127,9 @@ on_fileOpen_activate (GtkMenuItem *menuitem, dialog = gtk_file_chooser_dialog_new(_("Open Journal"), GTK_WINDOW (winMain), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); +#ifdef FILE_DIALOG_SIZE_BUGFIX + gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400); +#endif filt_all = gtk_file_filter_new(); gtk_file_filter_set_name(filt_all, _("All files")); @@ -202,6 +208,9 @@ on_fileSaveAs_activate (GtkMenuItem *menuitem, dialog = gtk_file_chooser_dialog_new(_("Save Journal"), GTK_WINDOW (winMain), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); +#ifdef FILE_DIALOG_SIZE_BUGFIX + gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400); +#endif if (ui.filename!=NULL) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), ui.filename); @@ -357,6 +366,9 @@ on_filePrintPDF_activate (GtkMenuItem *menuitem, dialog = gtk_file_chooser_dialog_new(_("Export to PDF"), GTK_WINDOW (winMain), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL); +#ifdef FILE_DIALOG_SIZE_BUGFIX + gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400); +#endif if (ui.filename!=NULL) { if (g_str_has_suffix(ui.filename, ".xoj")) { @@ -1446,6 +1458,9 @@ on_journalLoadBackground_activate (GtkMenuItem *menuitem, dialog = gtk_file_chooser_dialog_new(_("Open Background"), GTK_WINDOW (winMain), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); +#ifdef FILE_DIALOG_SIZE_BUGFIX + gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400); +#endif filt_all = gtk_file_filter_new(); gtk_file_filter_set_name(filt_all, _("All files")); @@ -2356,22 +2371,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 +2433,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 +2542,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 +2575,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; } @@ -2568,28 +2623,54 @@ on_canvas_key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { + GtkAdjustment *adj; + gint pgheight; + // Esc leaves text edition, or leaves fullscreen mode if (event->keyval == GDK_Escape) { - if (ui.cur_item_type == ITEM_TEXT) { end_text(); reset_focus(); } - else if (ui.fullscreen) do_fullscreen(FALSE); + if (ui.cur_item_type == ITEM_TEXT) { + end_text(); + reset_focus(); + return TRUE; + } + else if (ui.fullscreen) { + do_fullscreen(FALSE); + return TRUE; + } + else return FALSE; } - // If zoomed-out and in single page mode, switch pages with PgUp/PgDn. - if (!ui.view_continuous && - (0.96 * ui.zoom * ui.cur_page->height < - GTK_WIDGET(canvas)->allocation.height)) { - if (event->keyval == GDK_Page_Down) { + /* In single page mode, switch pages with PgUp/PgDn (or Up/Dn) + when there's nowhere else to go. */ + pgheight = GTK_WIDGET(canvas)->allocation.height; + adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(GET_COMPONENT("scrolledwindowMain"))); + + if (event->keyval == GDK_Page_Down || event->keyval == GDK_Down) { + if (!ui.view_continuous && + (0.96 * ui.zoom * ui.cur_page->height < pgheight || + adj->value == adj->upper-pgheight)) + { end_text(); - reset_focus(); - if (ui.pageno == journal.npages-1) { return FALSE; } - do_switch_page(ui.pageno+1, TRUE, FALSE); + if (ui.pageno < journal.npages-1) + do_switch_page(ui.pageno+1, TRUE, FALSE); + return TRUE; } - if (event->keyval == GDK_Page_Up) { + if (adj->value == adj->upper-pgheight) return TRUE; // don't send focus away + } + + if (event->keyval == GDK_Page_Up || event->keyval == GDK_Up) { + if (!ui.view_continuous && + (0.96 * ui.zoom * ui.cur_page->height < pgheight || + adj->value == adj->lower)) + { end_text(); - reset_focus(); - if (ui.pageno == 0) { return FALSE; } - do_switch_page(ui.pageno-1, TRUE, FALSE); + if (ui.pageno != 0) { + do_switch_page(ui.pageno-1, TRUE, FALSE); + gtk_adjustment_set_value(adj, adj->upper-pgheight); + } + return TRUE; } + if (adj->value == adj->lower) return TRUE; // don't send focus away } return FALSE; @@ -2603,6 +2684,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 +2707,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 +2820,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 +2839,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(); }