X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fxo-misc.c;h=5733f5b1ae018e46e39725426913491b0c294200;hb=72a310c8265a0d1e3e95fabb2987f70cfecbf525;hp=410797cd875af6a4ec2a19fbb298a56524389482;hpb=dcbb0ab8521a5e166f257d86884407eb98ef63f0;p=xournal.git diff --git a/src/xo-misc.c b/src/xo-misc.c index 410797c..5733f5b 100644 --- a/src/xo-misc.c +++ b/src/xo-misc.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "xournal.h" #include "xo-interface.h" @@ -351,10 +352,9 @@ void get_pointer_coords(GdkEvent *event, gdouble *ret) void fix_xinput_coords(GdkEvent *event) { -#ifdef ENABLE_XINPUT_BUGFIX double *axes, *px, *py, axis_width; GdkDevice *device; - int wx, wy, sx, sy; + int wx, wy, sx, sy, ix, iy; if (event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) { axes = event->button.axes; @@ -369,18 +369,26 @@ void fix_xinput_coords(GdkEvent *event) device = event->motion.device; } else return; // nothing we know how to do - + // use canvas window, not event window (else get GTK+ 2.11 bugs!) gdk_window_get_origin(GTK_WIDGET(canvas)->window, &wx, &wy); gnome_canvas_get_scroll_offsets(canvas, &sx, &sy); - - axis_width = device->axes[0].max - device->axes[0].min; - if (axis_width>EPSILON) - *px = (axes[0]/axis_width)*ui.screen_width + sx - wx; - axis_width = device->axes[1].max - device->axes[1].min; - if (axis_width>EPSILON) - *py = (axes[1]/axis_width)*ui.screen_height + sy - wy; +#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.)) { + gdk_window_get_pointer(GTK_WIDGET(canvas)->window, &ix, &iy, NULL); + *px = ix + sx; + *py = iy + sy; + } + else { + axis_width = device->axes[0].max - device->axes[0].min; + if (axis_width>EPSILON) + *px = (axes[0]/axis_width)*ui.screen_width + sx - wx; + axis_width = device->axes[1].max - device->axes[1].min; + if (axis_width>EPSILON) + *py = (axes[1]/axis_width)*ui.screen_height + sy - wy; + } #endif } @@ -512,6 +520,7 @@ void update_canvas_bg(struct Page *pg) double *pt; double x, y; int w, h; + gboolean is_well_scaled; if (pg->bg->canvas_item != NULL) gtk_object_destroy(GTK_OBJECT(pg->bg->canvas_item)); @@ -596,15 +605,23 @@ void update_canvas_bg(struct Page *pg) if (pg->bg->type == BG_PDF) { if (pg->bg->pixbuf == NULL) return; - pg->bg->canvas_item = gnome_canvas_item_new(pg->group, - gnome_canvas_pixbuf_get_type(), - "pixbuf", pg->bg->pixbuf, - "width", pg->width, "height", pg->height, - "width-set", TRUE, "height-set", TRUE, - NULL); + is_well_scaled = (fabs(pg->bg->pixel_width - pg->width*ui.zoom) < 2. + && fabs(pg->bg->pixel_height - pg->height*ui.zoom) < 2.); + if (is_well_scaled) + pg->bg->canvas_item = gnome_canvas_item_new(pg->group, + gnome_canvas_pixbuf_get_type(), + "pixbuf", pg->bg->pixbuf, + "width-in-pixels", TRUE, "height-in-pixels", TRUE, + NULL); + else + pg->bg->canvas_item = gnome_canvas_item_new(pg->group, + gnome_canvas_pixbuf_get_type(), + "pixbuf", pg->bg->pixbuf, + "width", pg->width, "height", pg->height, + "width-set", TRUE, "height-set", TRUE, + NULL); lower_canvas_item_to(pg->group, pg->bg->canvas_item, NULL); } - } gboolean is_visible(struct Page *pg) @@ -624,6 +641,8 @@ void rescale_bg_pixmaps(void) GList *pglist; struct Page *pg; GdkPixbuf *pix; + gboolean is_well_scaled; + gdouble zoom_to_request; for (pglist = journal.pages; pglist!=NULL; pglist = pglist->next) { pg = (struct Page *)pglist->data; @@ -649,10 +668,24 @@ void rescale_bg_pixmaps(void) pg->bg->pixbuf_scale = 0; } } - if (pg->bg->type == BG_PDF) { // request an asynchronous update - if (pg->bg->pixbuf_scale == ui.zoom) continue; - add_bgpdf_request(pg->bg->file_page_seq, ui.zoom, FALSE); - pg->bg->pixbuf_scale = ui.zoom; + if (pg->bg->type == BG_PDF) { + // make pixmap scale to correct size if current one is wrong + is_well_scaled = (fabs(pg->bg->pixel_width - pg->width*ui.zoom) < 2. + && fabs(pg->bg->pixel_height - pg->height*ui.zoom) < 2.); + if (pg->bg->canvas_item != NULL && !is_well_scaled) { + g_object_get(pg->bg->canvas_item, "width-in-pixels", &is_well_scaled, NULL); + if (is_well_scaled) + gnome_canvas_item_set(pg->bg->canvas_item, + "width", pg->width, "height", pg->height, + "width-in-pixels", FALSE, "height-in-pixels", FALSE, + "width-set", TRUE, "height-set", TRUE, + NULL); + } + // request an asynchronous update to a better pixmap if needed + zoom_to_request = MIN(ui.zoom, MAX_SAFE_RENDER_DPI/72.0); + if (pg->bg->pixbuf_scale == zoom_to_request) continue; + add_bgpdf_request(pg->bg->file_page_seq, zoom_to_request); + pg->bg->pixbuf_scale = zoom_to_request; } } } @@ -1209,12 +1242,12 @@ void update_page_stuff(void) gtk_spin_button_set_range(spin, 1, journal.npages+1); /* npages+1 will be used to create a new page at end */ gtk_spin_button_set_value(spin, ui.pageno+1); - g_snprintf(tmp, 10, " of %d", journal.npages); + g_snprintf(tmp, 10, _(" of %d"), journal.npages); gtk_label_set_text(GTK_LABEL(GET_COMPONENT("labelNumpages")), tmp); layerbox = GTK_COMBO_BOX(GET_COMPONENT("comboLayer")); if (ui.layerbox_length == 0) { - gtk_combo_box_prepend_text(layerbox, "Background"); + gtk_combo_box_prepend_text(layerbox, _("Background")); ui.layerbox_length++; } while (ui.layerbox_length > ui.cur_page->nlayers+1) { @@ -1222,7 +1255,7 @@ void update_page_stuff(void) ui.layerbox_length--; } while (ui.layerbox_length < ui.cur_page->nlayers+1) { - g_snprintf(tmp, 10, "Layer %d", ui.layerbox_length++); + g_snprintf(tmp, 10, _("Layer %d"), ui.layerbox_length++); gtk_combo_box_prepend_text(layerbox, tmp); } gtk_combo_box_set_active(layerbox, ui.cur_page->nlayers-1-ui.layerno); @@ -1338,13 +1371,13 @@ void update_file_name(char *filename) if (ui.filename != NULL) g_free(ui.filename); ui.filename = filename; if (filename == NULL) { - gtk_window_set_title(GTK_WINDOW (winMain), "Xournal"); + gtk_window_set_title(GTK_WINDOW (winMain), _("Xournal")); return; } p = g_utf8_strrchr(filename, -1, '/'); if (p == NULL) p = filename; else p = g_utf8_next_char(p); - g_snprintf(tmp, 100, "Xournal - %s", p); + g_snprintf(tmp, 100, _("Xournal - %s"), p); gtk_window_set_title(GTK_WINDOW (winMain), tmp); new_mru_entry(filename); } @@ -1577,8 +1610,8 @@ gboolean ok_to_close(void) if (ui.saved) return TRUE; dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, "Save changes to '%s'?", - (ui.filename!=NULL) ? ui.filename:"Untitled"); + GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, _("Save changes to '%s'?"), + (ui.filename!=NULL) ? ui.filename:_("Untitled")); gtk_dialog_add_button(GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); response = gtk_dialog_run(GTK_DIALOG (dialog)); gtk_widget_destroy(dialog); @@ -1591,12 +1624,6 @@ gboolean ok_to_close(void) return TRUE; } -// test if we're still busy loading a PDF background file -gboolean page_ops_forbidden(void) -{ - return (bgpdf.status != STATUS_NOT_INIT && bgpdf.create_pages); -} - // send the focus back to the appropriate widget void reset_focus(void) { @@ -1622,6 +1649,7 @@ void reset_selection(void) update_thickness_buttons(); update_color_buttons(); update_font_button(); + update_cursor(); } void move_journal_items_by(GList *itemlist, double dx, double dy, @@ -1883,6 +1911,8 @@ void allow_all_accels(void) "can-activate-accel", G_CALLBACK(can_accel), NULL); g_signal_connect((gpointer) GET_COMPONENT("toolsRuler"), "can-activate-accel", G_CALLBACK(can_accel), NULL); + g_signal_connect((gpointer) GET_COMPONENT("toolsReco"), + "can-activate-accel", G_CALLBACK(can_accel), NULL); } void add_scroll_bindings(void) @@ -1940,9 +1970,105 @@ void hide_unimplemented(void) gtk_widget_hide(GET_COMPONENT("colorOther")); gtk_widget_hide(GET_COMPONENT("helpIndex")); - /* config file only works with glib 2.6 */ + /* config file only works with glib 2.6 and beyond */ if (glib_minor_version<6) { gtk_widget_hide(GET_COMPONENT("optionsAutoSavePrefs")); gtk_widget_hide(GET_COMPONENT("optionsSavePreferences")); } + /* gtkprint only works with gtk+ 2.10 and beyond */ + if (gtk_check_version(2, 10, 0)) { + gtk_widget_hide(GET_COMPONENT("filePrint")); + } } + +// toggle fullscreen mode +void do_fullscreen(gboolean active) +{ + end_text(); + reset_focus(); + ui.fullscreen = active; + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(GET_COMPONENT("viewFullscreen")), ui.fullscreen); + gtk_toggle_tool_button_set_active( + GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonFullscreen")), ui.fullscreen); + + if (ui.fullscreen) gtk_window_fullscreen(GTK_WINDOW(winMain)); + else gtk_window_unfullscreen(GTK_WINDOW(winMain)); + + update_vbox_order(ui.vertical_order[ui.fullscreen?1:0]); +} + +/* attempt to work around GTK+ 2.16/2.17 bugs where random interface + elements receive XInput events that they can't handle properly */ + +// prevent interface items from getting bogus XInput events + +gboolean filter_extended_events (GtkWidget *widget, GdkEvent *event, + gpointer user_data) +{ + if (event->type == GDK_MOTION_NOTIFY && + event->motion.device != gdk_device_get_core_pointer()) + return TRUE; + if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS || + event->type == GDK_3BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) && + event->button.device != gdk_device_get_core_pointer()) + return TRUE; + return FALSE; +} + +/* Code to turn an extended input event into a core event and send it to + a different GdkWindow -- e.g. could be used when a click in a text edit box + gets sent to the canvas instead due to incorrect event translation. + We now turn off xinput altogether while editing text under GTK+ 2.17, so + this isn't needed any more... but could become useful again someday! +*/ + +/* +gboolean fix_extended_events (GtkWidget *widget, GdkEvent *event, + gpointer user_data) +{ + int ix, iy; + GdkWindow *window; + + if (user_data) window = (GdkWindow *)user_data; + else window = widget->window; + + if (event->type == GDK_MOTION_NOTIFY && + event->motion.device != gdk_device_get_core_pointer()) { +// printf("fixing motion\n"); + gdk_window_get_pointer(window, &ix, &iy, NULL); + event->motion.x = ix; event->motion.y = iy; + event->motion.device = gdk_device_get_core_pointer(); + g_object_unref(event->motion.window); + event->motion.window = g_object_ref(window); + gtk_widget_event(widget, event); + return TRUE; + } + if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) && + event->button.device != gdk_device_get_core_pointer()) { +// printf("fixing button from pos = %f, %f\n", event->button.x, event->button.y); + gdk_window_get_pointer(window, &ix, &iy, NULL); + event->button.x = ix; event->button.y = iy; + event->button.device = gdk_device_get_core_pointer(); + g_object_unref(event->button.window); + event->button.window = g_object_ref(window); +// printf("fixing button to pos = %f, %f\n", event->button.x, event->button.y); + gtk_widget_event(widget, event); + return TRUE; + } + return FALSE; +} +*/ + +// disable xinput when layer combo box is popped up, to avoid crash + +gboolean combobox_popup_disable_xinput (GtkWidget *widget, GdkEvent *event, + gpointer user_data) +{ + 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); +}