From 881e9a45693f4d724512fdc5297ba312d447851b Mon Sep 17 00:00:00 2001 From: auroux Date: Sat, 26 Sep 2009 06:50:45 +0000 Subject: [PATCH] focus and other patches --- src/TODO | 19 +++++++------ src/main.c | 11 ++++++++ src/xo-callbacks.c | 69 ++++++++++++++++++++++++++++++++++++---------- src/xo-file.c | 3 +- src/xo-misc.c | 20 ++++++++++++++ src/xo-misc.h | 4 ++- src/xournal.h | 5 ++++ 7 files changed, 106 insertions(+), 25 deletions(-) diff --git a/src/TODO b/src/TODO index b0b973b..a0a8ef6 100644 --- a/src/TODO +++ b/src/TODO @@ -45,30 +45,31 @@ DONE: disable ctrl-left/right accelerators during text edition DONE: custom color chooser button (after a patch contributed by Alex Ray) DONE: remember last used directory (after a patch contributed by Lu Zhihe) DONE: discard Alt-click and Control-click events - -(go through Patches tracker and take the good stuff... now at 2009-05-09) - -DONE?? option to have buttons *toggle* the tool rather than act as tool +DONE: option to have buttons *toggle* the tool rather than act as tool (ie button 2 causes button 1 to map to tool 2) [Dylan Thurston] +DONE: patch to fix focus + allow up/dn in single page mode (Bob McElrath) + also comment out contents of reset_focus() ? (tracker patch #2494022) +DONE: patch to fix underscores in MRU filename display (Bob McElrath) +DONE: patch to avoid tiny file dialogs (Bob McElrath) -** commit patches from Bob McElrath +(go through Patches tracker and take the good stuff... now at 2009-05-09) - paper color chooser (see tracker 2083103) - prerelease: update help file (remove references to pdftoppm/libgnomeprint & update to poppler/gtkprint) - REMOVE BINARY INSTALLER (poppler breaks ABI all the time) + but add a configure script (+ Makefile.in, etc ?) - document config options into manual file? - PDF bg memory usage throttling / delete oldest pdf backgrounds - replace ttsubset by something more modern? (eg. from cairo ?) - auto-hide patch from ~/prog/src/xournal-autohide/ ? (check for cpu usage; handle BOTH edges and only (un)hide stuff at the correct edge!) +** remove reset_focus() and calls to it, after enough testing. + check if we should call reset_recognizer() in some of those places + (e.g., undo/redo?) ** if bg pdf not found in absolute path, look in path of xoj file before prompting user. -** patch to fix focus + allow up/dn in single page mode (Bob McElrath) - also comment out contents of reset_focus() ? (tracker patch #2494022) -** patch to fix underscores in MRU filename display (McElrath) (tracker) - (fix memory leak) ** UI update (Bob McElrath) -- eliminating status bar, compact layout, "compact interface" by default; themes, with line in config file to load pixmaps from pixmaps/$THEME/ (see Jan 9, 2009 emails) diff --git a/src/main.c b/src/main.c index 001d09b..1c8acbf 100644 --- a/src/main.c +++ b/src/main.c @@ -126,6 +126,15 @@ void init_stuff (int argc, char *argv[]) allow_all_accels(); add_scroll_bindings(); + // prevent interface items from stealing focus + // glade doesn't properly handle can_focus, so manually set it + gtk_combo_box_set_focus_on_click(GTK_COMBO_BOX(GET_COMPONENT("comboLayer")), FALSE); + g_signal_connect(GET_COMPONENT("spinPageNo"), "activate", + G_CALLBACK(handle_activate_signal), NULL); + gtk_container_foreach(GTK_CONTAINER(winMain), unset_flags, (gpointer)GTK_CAN_FOCUS); + GTK_WIDGET_SET_FLAGS(GTK_WIDGET(canvas), GTK_CAN_FOCUS); + GTK_WIDGET_SET_FLAGS(GTK_WIDGET(GET_COMPONENT("spinPageNo")), GTK_CAN_FOCUS); + // set up and initialize the canvas gtk_widget_show (GTK_WIDGET (canvas)); @@ -252,6 +261,8 @@ void init_stuff (int argc, char *argv[]) (gpointer)(gtk_scrolled_window_get_hscrollbar(GTK_SCROLLED_WINDOW(w))), "event", G_CALLBACK (filter_extended_events), NULL); + } + if (!gtk_check_version(2, 17, 0)) { g_signal_connect ( GET_COMPONENT("comboLayer"), "notify::popup-shown", G_CALLBACK (combobox_popup_disable_xinput), diff --git a/src/xo-callbacks.c b/src/xo-callbacks.c index b1b35bb..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")); @@ -2608,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; diff --git a/src/xo-file.c b/src/xo-file.c index 4dd7396..1ae30fc 100644 --- a/src/xo-file.c +++ b/src/xo-file.c @@ -1209,7 +1209,8 @@ void update_mru_menu(void) for (i=0; iwidget); else gtk_widget_grab_focus(GTK_WIDGET(canvas)); reset_recognizer(); +*/ } // selection / clipboard stuff @@ -2124,3 +2126,21 @@ gboolean combobox_popup_disable_xinput (GtkWidget *widget, GdkEvent *event, gtk_widget_set_extension_events(GTK_WIDGET (canvas), (ui.use_xinput && !is_shown)?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE); } + +/* When enter is pressed into page spinbox, send focus back to canvas. */ + +gboolean handle_activate_signal(GtkWidget *widget, gpointer user_data) +{ + gtk_widget_grab_focus(GTK_WIDGET(canvas)); + return FALSE; +} + +/* recursively unset widget flags */ + +void unset_flags(GtkWidget *w, gpointer flag) +{ + GTK_WIDGET_UNSET_FLAGS(w, (GtkWidgetFlags)flag); + if(GTK_IS_CONTAINER(w)) + gtk_container_foreach(GTK_CONTAINER(w), unset_flags, flag); +} + \ No newline at end of file diff --git a/src/xo-misc.h b/src/xo-misc.h index 3a6e029..fbfb337 100644 --- a/src/xo-misc.h +++ b/src/xo-misc.h @@ -102,7 +102,9 @@ gboolean filter_extended_events(GtkWidget *widget, GdkEvent *event, gpointer use // gboolean fix_extended_events(GtkWidget *widget, GdkEvent *event, gpointer user_data); gboolean combobox_popup_disable_xinput(GtkWidget *widget, GdkEvent *event, gpointer user_data); - +// help with focus +gboolean handle_activate_signal(GtkWidget *widget, gpointer user_data); +void unset_flags(GtkWidget *w, gpointer flag); // defines for paper rulings diff --git a/src/xournal.h b/src/xournal.h index 61eb218..277b1d0 100644 --- a/src/xournal.h +++ b/src/xournal.h @@ -12,6 +12,11 @@ XInput and want to try things differently. This will probably break on-the-fly display rotation after application startup, though. */ +#define FILE_DIALOG_SIZE_BUGFIX +/* ugly, but should help users with versions of GTK+ that suffer from the + "tiny file dialog" syndrome, without hurting those with well-behaved + versions of GTK+. Comment out if you'd prefer not to include this fix. */ + // PREF FILES INFO #define CONFIG_DIR ".xournal" -- 2.39.2