diff options
Diffstat (limited to 'src/gtkutil.c')
-rw-r--r-- | src/gtkutil.c | 186 |
1 files changed, 78 insertions, 108 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c index 11e59b9fae5..313cfc82c26 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -81,8 +81,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ gtk_font_selection_dialog_set_font_name (x, y) #endif -#define gdk_window_get_geometry(w, a, b, c, d) \ - gdk_window_get_geometry (w, a, b, c, d, 0) #define gtk_box_new(ori, spacing) \ ((ori) == GTK_ORIENTATION_HORIZONTAL \ ? gtk_hbox_new (FALSE, (spacing)) : gtk_vbox_new (FALSE, (spacing))) @@ -910,70 +908,60 @@ xg_set_geometry (struct frame *f) } } -/* Function to handle resize of our frame. As we have a Gtk+ tool bar - and a Gtk+ menu bar, we get resize events for the edit part of the - frame only. We let Gtk+ deal with the Gtk+ parts. - F is the frame to resize. - PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */ - +/** Function to handle resize of native frame F to WIDTH and HEIGHT + pixels after we got a ConfigureNotify event. */ void -xg_frame_resized (struct frame *f, int pixelwidth, int pixelheight) +xg_frame_resized (struct frame *f, int width, int height) { - int width, height; - - if (pixelwidth == -1 && pixelheight == -1) + /* Ignore case where size of native rectangle didn't change. */ + if (width != FRAME_PIXEL_WIDTH (f) + || height != FRAME_PIXEL_HEIGHT (f) + || (f->new_size_p + && ((f->new_width >= 0 && width != f->new_width) + || (f->new_height >= 0 && height != f->new_height)))) { - if (FRAME_GTK_WIDGET (f) && gtk_widget_get_mapped (FRAME_GTK_WIDGET (f))) - gdk_window_get_geometry (gtk_widget_get_window (FRAME_GTK_WIDGET (f)), - 0, 0, &pixelwidth, &pixelheight); - else - return; - } + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("xg_frame_resized, changed"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + f->new_size_p ? f->new_width : -1, + f->new_size_p ? f->new_height : -1); - width = FRAME_PIXEL_TO_TEXT_WIDTH (f, pixelwidth); - height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixelheight); - - frame_size_history_add - (f, Qxg_frame_resized, width, height, Qnil); - - if (width != FRAME_TEXT_WIDTH (f) - || height != FRAME_TEXT_HEIGHT (f) - || pixelwidth != FRAME_PIXEL_WIDTH (f) - || pixelheight != FRAME_PIXEL_HEIGHT (f)) - { FRAME_RIF (f)->clear_under_internal_border (f); - change_frame_size (f, width, height, 0, 1, 0, 1); + change_frame_size (f, width, height, false, true, false); SET_FRAME_GARBAGED (f); cancel_mouse_face (f); } + else if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("xg_frame_resized, unchanged"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + f->new_size_p ? f->new_width : -1, + f->new_size_p ? f->new_height : -1); + } /** Resize the outer window of frame F. WIDTH and HEIGHT are the new - pixel sizes of F's text area. */ + native pixel sizes of F. */ void xg_frame_set_char_size (struct frame *f, int width, int height) { - int pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); - int pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height); Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); gint gwidth, gheight; - int totalheight - = pixelheight + FRAME_TOOLBAR_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f); - int totalwidth = pixelwidth + FRAME_TOOLBAR_WIDTH (f); + int outer_height + = height + FRAME_TOOLBAR_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f); + int outer_width = width + FRAME_TOOLBAR_WIDTH (f); bool was_visible = false; bool hide_child_frame; - if (FRAME_PIXEL_HEIGHT (f) == 0) - return; - gtk_window_get_size (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), &gwidth, &gheight); /* Do this before resize, as we don't know yet if we will be resized. */ FRAME_RIF (f)->clear_under_internal_border (f); - totalheight /= xg_get_scale (f); - totalwidth /= xg_get_scale (f); + outer_height /= xg_get_scale (f); + outer_width /= xg_get_scale (f); x_wm_set_size_hint (f, 0, 0); @@ -986,35 +974,19 @@ xg_frame_set_char_size (struct frame *f, int width, int height) manager will abolish it. At least the respective size should remain unchanged but giving the frame back its normal size will be broken ... */ - if (EQ (fullscreen, Qfullwidth) && width == FRAME_TEXT_WIDTH (f)) - { - frame_size_history_add - (f, Qxg_frame_set_char_size_1, width, height, - list2i (gheight, totalheight)); - - gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - gwidth, totalheight); - } - else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f)) - { - frame_size_history_add - (f, Qxg_frame_set_char_size_2, width, height, - list2i (gwidth, totalwidth)); - - gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - totalwidth, gheight); - } + if (EQ (fullscreen, Qfullwidth) && width == FRAME_PIXEL_WIDTH (f)) + gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + gwidth, outer_height); + else if (EQ (fullscreen, Qfullheight) && height == FRAME_PIXEL_HEIGHT (f)) + gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + outer_width, gheight); else if (FRAME_PARENT_FRAME (f) && FRAME_VISIBLE_P (f)) { was_visible = true; hide_child_frame = EQ (x_gtk_resize_child_frames, Qhide); - if (totalwidth != gwidth || totalheight != gheight) + if (outer_width != gwidth || outer_height != gheight) { - frame_size_history_add - (f, Qxg_frame_set_char_size_4, width, height, - list2i (totalwidth, totalheight)); - if (hide_child_frame) { block_input (); @@ -1023,7 +995,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height) } gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - totalwidth, totalheight); + outer_width, outer_height); if (hide_child_frame) { @@ -1037,11 +1009,8 @@ xg_frame_set_char_size (struct frame *f, int width, int height) } else { - frame_size_history_add - (f, Qxg_frame_set_char_size_3, width, height, - list2i (totalwidth, totalheight)); gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - totalwidth, totalheight); + outer_width, outer_height); fullscreen = Qnil; } @@ -1057,6 +1026,12 @@ xg_frame_set_char_size (struct frame *f, int width, int height) the frame is mapped again we will (hopefully) get the correct size. */ if (FRAME_VISIBLE_P (f) && !was_visible) { + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("xg_frame_set_char_size, visible"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + f->new_width, f->new_height); + /* Must call this to flush out events */ (void)gtk_events_pending (); gdk_flush (); @@ -1070,8 +1045,17 @@ xg_frame_set_char_size (struct frame *f, int width, int height) } } else - adjust_frame_size (f, width, height, 5, 0, Qxg_frame_set_char_size); - + { + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("xg_frame_set_char_size, invisible"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + f->new_width, f->new_height); + + adjust_frame_size (f, FRAME_PIXEL_TO_TEXT_WIDTH (f, width), + FRAME_PIXEL_TO_TEXT_HEIGHT (f, height), + 5, 0, Qxg_frame_set_char_size); + } } /* Handle height/width changes (i.e. add/remove/move menu/toolbar). @@ -1186,7 +1170,8 @@ style_changed_cb (GObject *go, { FRAME_TERMINAL (f)->set_scroll_bar_default_width_hook (f); FRAME_TERMINAL (f)->set_scroll_bar_default_height_hook (f); - xg_frame_set_char_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f)); + xg_frame_set_char_size (f, FRAME_PIXEL_WIDTH (f), + FRAME_PIXEL_HEIGHT (f)); } } } @@ -3236,7 +3221,7 @@ xg_update_menu_item (widget_value *val, gtk_label_set_text (wkey, utf8_key); } - if (! old_label || strcmp (utf8_label, old_label) != 0) + if (utf8_label && (! old_label || strcmp (utf8_label, old_label) != 0)) { label_changed = true; gtk_label_set_text (wlbl, utf8_label); @@ -4589,10 +4574,7 @@ tb_size_cb (GtkWidget *widget, struct frame *f = user_data; if (xg_update_tool_bar_sizes (f)) - { - frame_size_history_add (f, Qtb_size_cb, 0, 0, Qnil); - adjust_frame_size (f, -1, -1, 5, 0, Qtool_bar_lines); - } + adjust_frame_size (f, -1, -1, 2, false, Qtool_bar_lines); } /* Create a tool bar for frame F. */ @@ -5014,11 +4996,10 @@ update_frame_tool_bar (struct frame *f) GtkWidget *wbutton = NULL; Lisp_Object specified_file; bool vert_only = ! NILP (PROP (TOOL_BAR_ITEM_VERT_ONLY)); - const char *label - = (EQ (style, Qimage) || (vert_only && horiz)) ? NULL - : STRINGP (PROP (TOOL_BAR_ITEM_LABEL)) - ? SSDATA (PROP (TOOL_BAR_ITEM_LABEL)) - : ""; + Lisp_Object label + = (EQ (style, Qimage) || (vert_only && horiz)) + ? Qnil + : PROP (TOOL_BAR_ITEM_LABEL); ti = gtk_toolbar_get_nth_item (GTK_TOOLBAR (wtoolbar), j); @@ -5131,8 +5112,11 @@ update_frame_tool_bar (struct frame *f) /* If there is an existing widget, check if it's stale; if so, remove it and make a new tool item from scratch. */ - if (ti && xg_tool_item_stale_p (wbutton, stock_name, icon_name, - img, label, horiz)) + if (ti && xg_tool_item_stale_p (wbutton, stock_name, icon_name, img, + NILP (label) + ? NULL + : STRINGP (label) ? SSDATA (label) : "", + horiz)) { gtk_container_remove (GTK_CONTAINER (wtoolbar), GTK_WIDGET (ti)); @@ -5189,7 +5173,11 @@ update_frame_tool_bar (struct frame *f) #else if (w) gtk_misc_set_padding (GTK_MISC (w), hmargin, vmargin); #endif - ti = xg_make_tool_item (f, w, &wbutton, label, i, horiz, text_image); + ti = xg_make_tool_item (f, w, &wbutton, + NILP (label) + ? NULL + : STRINGP (label) ? SSDATA (label) : "", + i, horiz, text_image); gtk_toolbar_insert (GTK_TOOLBAR (wtoolbar), ti, j); } @@ -5213,23 +5201,10 @@ update_frame_tool_bar (struct frame *f) xg_pack_tool_bar (f, FRAME_TOOL_BAR_POSITION (f)); gtk_widget_show_all (x->toolbar_widget); if (xg_update_tool_bar_sizes (f)) - { - int inhibit - = ((f->after_make_frame - && !f->tool_bar_resized - && (EQ (frame_inhibit_implied_resize, Qt) - || (CONSP (frame_inhibit_implied_resize) - && !NILP (Fmemq (Qtool_bar_lines, - frame_inhibit_implied_resize)))) - /* This will probably fail to DTRT in the - fullheight/-width cases. */ - && NILP (get_frame_param (f, Qfullscreen))) - ? 0 - : 2); - - frame_size_history_add (f, Qupdate_frame_tool_bar, 0, 0, Qnil); - adjust_frame_size (f, -1, -1, inhibit, 0, Qtool_bar_lines); - } + /* It's not entirely clear whether here we want a treatment + similar to that for frames with internal tool bar. */ + adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); + f->tool_bar_resized = f->tool_bar_redisplayed; } @@ -5278,7 +5253,6 @@ free_frame_tool_bar (struct frame *f) NULL); } - frame_size_history_add (f, Qfree_frame_tool_bar, 0, 0, Qnil); adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); unblock_input (); @@ -5310,11 +5284,7 @@ xg_change_toolbar_position (struct frame *f, Lisp_Object pos) g_object_unref (top_widget); if (xg_update_tool_bar_sizes (f)) - { - frame_size_history_add (f, Qxg_change_toolbar_position, 0, 0, Qnil); - adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); - } - + adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); unblock_input (); } |