From 4dbea5be1758788d9f6177ca3f7eaedc9e01ad56 Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Mon, 5 Oct 2020 21:18:06 +0900 Subject: [PATCH] Fix Gtk warnings * src/gtkutil.c (xg_frame_set_char_size): Call appropriate function (xg_set_undecorated): Do nothing if child frame. (xg_set_no_focus_on_map): Do nothing if child frame. (xg_set_no_accept_focus): Do nothing if child frame. (xg_set_frame_icon): Do nothing if child frame. (xg_get_file_name): Do nothing if child frame. (xg_get_font): * src/pgtkterm.c (pgtk_focus_frame): Do nothing if child frames. (x_set_frame_alpha): Select correct widget. (x_new_focus_frame): Focus only when non-child frames. (pgtk_set_event_handler): Don't set for child frames. * src/pgtkfns.c (xg_set_icon): Do nothing if child frames. (xg_set_icon_from_xpm_data): Do nothing if child frames. (pgtk_set_sticky): Do nothing if child frames. (Fx_show_tip): Do nothing if child frames. (Fpgtk_set_mouse_absolute_pixel_position): Select correct widget. (Fpgtk_mouse_absolute_pixel_position): Select correct widget. * src/pgtkmenu.c (pgtk_menu_show): (pgtk_dialog_show): --- src/gtkutil.c | 60 ++++++++++++++++++++++++++++++++++++++++++++------ src/pgtkfns.c | 16 ++++++++++++-- src/pgtkmenu.c | 10 +++++++++ src/pgtkterm.c | 37 +++++++++++++++++-------------- 4 files changed, 98 insertions(+), 25 deletions(-) diff --git a/src/gtkutil.c b/src/gtkutil.c index 56d415887d0..a62616bbfc6 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -1098,8 +1098,21 @@ xg_frame_set_char_size (struct frame *f, int width, int height) (f, Qxg_frame_set_char_size_1, width, height, list2i (gheight, totalheight)); +#ifndef HAVE_PGTK gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), gwidth, totalheight); +#else + if (FRAME_GTK_OUTER_WIDGET (f)) + { + gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + gwidth, totalheight); + } + else + { + gtk_widget_set_size_request (FRAME_GTK_WIDGET (f), + gwidth, totalheight); + } +#endif } else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f)) { @@ -1107,8 +1120,21 @@ xg_frame_set_char_size (struct frame *f, int width, int height) (f, Qxg_frame_set_char_size_2, width, height, list2i (gwidth, totalwidth)); +#ifndef HAVE_PGTK gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), totalwidth, gheight); +#else + if (FRAME_GTK_OUTER_WIDGET (f)) + { + gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + totalwidth, gheight); + } + else + { + gtk_widget_set_size_request (FRAME_GTK_WIDGET (f), + totalwidth, gheight); + } +#endif } else if (FRAME_PARENT_FRAME (f) && FRAME_VISIBLE_P (f)) { @@ -1880,6 +1906,10 @@ xg_set_background_color (struct frame *f, unsigned long bg) void xg_set_undecorated (struct frame *f, Lisp_Object undecorated) { +#ifdef HAVE_PGTK + if (!FRAME_GTK_OUTER_WIDGET (f)) + return; +#endif if (FRAME_GTK_WIDGET (f)) { block_input (); @@ -1940,6 +1970,10 @@ xg_set_skip_taskbar (struct frame *f, Lisp_Object skip_taskbar) void xg_set_no_focus_on_map (struct frame *f, Lisp_Object no_focus_on_map) { +#ifdef HAVE_PGTK + if (!FRAME_GTK_OUTER_WIDGET (f)) + return; +#endif block_input (); if (FRAME_GTK_WIDGET (f)) { @@ -1955,14 +1989,12 @@ xg_set_no_focus_on_map (struct frame *f, Lisp_Object no_focus_on_map) void xg_set_no_accept_focus (struct frame *f, Lisp_Object no_accept_focus) { - block_input (); - if ( -#ifndef HAVE_PGTK - FRAME_GTK_WIDGET (f) -#else - FRAME_GTK_OUTER_WIDGET (f) +#ifdef HAVE_PGTK + if (!FRAME_GTK_OUTER_WIDGET (f)) + return; #endif - ) + block_input (); + if (FRAME_GTK_WIDGET (f)) { GtkWindow *gwin = GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)); gboolean g_no_accept_focus = NILP (no_accept_focus) ? TRUE : FALSE; @@ -1994,6 +2026,10 @@ xg_set_override_redirect (struct frame *f, Lisp_Object override_redirect) void xg_set_frame_icon (struct frame *f, Pixmap icon_pixmap, Pixmap icon_mask) { +#ifdef HAVE_PGTK + if (!FRAME_GTK_OUTER_WIDGET (f)) + return; +#endif GdkPixbuf *gp = xg_get_pixbuf_from_pix_and_mask (f, icon_pixmap, icon_mask); @@ -2537,6 +2573,11 @@ xg_get_file_name (struct frame *f, int filesel_done = 0; xg_get_file_func func; +#ifdef HAVE_PGTK + if (!FRAME_GTK_OUTER_WIDGET (f)) + error("Can't open dialog from child frames"); +#endif + #ifdef HAVE_GTK_FILE_SELECTION_NEW if (xg_uses_old_file_dialog ()) @@ -2620,6 +2661,11 @@ xg_get_font (struct frame *f, const char *default_name) int done = 0; Lisp_Object font = Qnil; +#ifdef HAVE_PGTK + if (!FRAME_GTK_OUTER_WIDGET (f)) + error("Can't open dialog from child frames"); +#endif + w = gtk_font_chooser_dialog_new ("Pick a font", GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); diff --git a/src/pgtkfns.c b/src/pgtkfns.c index 4ecb03b91c0..ece63517b22 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -719,6 +719,9 @@ xg_set_icon (struct frame *f, Lisp_Object file) bool result = false; Lisp_Object found; + if (!FRAME_GTK_OUTER_WIDGET (f)) + return false; + found = image_find_image_file (file); if (!NILP (found)) @@ -755,6 +758,9 @@ xg_set_icon_from_xpm_data (struct frame *f, const char **data) if (!pixbuf) return false; + if (!FRAME_GTK_OUTER_WIDGET (f)) + return false; + gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), pixbuf); g_object_unref (pixbuf); return true; @@ -764,6 +770,9 @@ static void pgtk_set_sticky (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { + if (!FRAME_GTK_OUTER_WIDGET (f)) + return; + if (!NILP (new_value)) gtk_window_stick (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); else @@ -3055,6 +3064,9 @@ Text larger than the specified size is clipped. */) frame = selected_frame; f = decode_window_system_frame (frame); + if (!FRAME_GTK_OUTER_WIDGET (f)) + return unbind_to (count, Qnil); + if (NILP (timeout)) timeout = make_fixnum (5); else @@ -3457,7 +3469,7 @@ The coordinates X and Y are interpreted in pixels relative to a position (Lisp_Object x, Lisp_Object y) { struct frame *f = SELECTED_FRAME (); - GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f); + GtkWidget *widget = gtk_widget_get_toplevel (FRAME_WIDGET (f)); GdkWindow *window = gtk_widget_get_window (widget); GdkDisplay *gdpy = gdk_window_get_display (window); GdkScreen *gscr = gdk_window_get_screen (window); @@ -3478,7 +3490,7 @@ position (0, 0) of the selected frame's terminal. */) (void) { struct frame *f = SELECTED_FRAME (); - GtkWidget *widget = FRAME_GTK_OUTER_WIDGET (f); + GtkWidget *widget = gtk_widget_get_toplevel (FRAME_WIDGET (f)); GdkWindow *window = gtk_widget_get_window (widget); GdkDisplay *gdpy = gdk_window_get_display (window); GdkScreen *gscr; diff --git a/src/pgtkmenu.c b/src/pgtkmenu.c index 7d15340b6be..79f562e2ab4 100644 --- a/src/pgtkmenu.c +++ b/src/pgtkmenu.c @@ -640,6 +640,11 @@ pgtk_menu_show (struct frame *f, int x, int y, int menuflags, *error_name = NULL; + if (!FRAME_GTK_OUTER_WIDGET (f)) { + *error_name = "Can't popup from child frames."; + return Qnil; + } + if (menu_items_used <= MENU_ITEMS_PANE_LENGTH) { *error_name = "Empty menu"; @@ -944,6 +949,11 @@ pgtk_dialog_show (struct frame *f, Lisp_Object title, *error_name = NULL; + if (!FRAME_GTK_OUTER_WIDGET (f)) { + *error_name = "Can't popup from child frames."; + return Qnil; + } + if (menu_items_n_panes > 1) { *error_name = "Multiple panes in dialog box"; diff --git a/src/pgtkterm.c b/src/pgtkterm.c index c66379e6e4b..6e2c87f8210 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -4660,7 +4660,7 @@ pgtk_focus_frame (struct frame *f, bool noactivate) GtkWidget *wid = FRAME_GTK_OUTER_WIDGET (f); - if (dpyinfo->x_focus_frame != f) + if (dpyinfo->x_focus_frame != f && wid != NULL) { block_input (); gtk_window_present (GTK_WINDOW (wid)); @@ -4718,9 +4718,9 @@ x_set_frame_alpha (struct frame *f) } #endif - set_opacity_recursively (FRAME_GTK_OUTER_WIDGET (f), &alpha); + set_opacity_recursively (FRAME_WIDGET (f), &alpha); /* without this, blending mode is strange on wayland. */ - gtk_widget_queue_resize_no_redraw (FRAME_GTK_OUTER_WIDGET (f)); + gtk_widget_queue_resize_no_redraw (FRAME_WIDGET (f)); } static void @@ -4891,12 +4891,14 @@ x_new_focus_frame (struct pgtk_display_info *dpyinfo, struct frame *frame) dpyinfo->x_focus_frame = frame; if (old_focus && old_focus->auto_lower) - gdk_window_lower (gtk_widget_get_window - (FRAME_GTK_OUTER_WIDGET (old_focus))); + if (FRAME_GTK_OUTER_WIDGET (old_focus)) + gdk_window_lower (gtk_widget_get_window + (FRAME_GTK_OUTER_WIDGET (old_focus))); if (dpyinfo->x_focus_frame && dpyinfo->x_focus_frame->auto_raise) - gdk_window_raise (gtk_widget_get_window - (FRAME_GTK_OUTER_WIDGET (dpyinfo->x_focus_frame))); + if (FRAME_GTK_OUTER_WIDGET (dpyinfo->x_focus_frame)) + gdk_window_raise (gtk_widget_get_window + (FRAME_GTK_OUTER_WIDGET (dpyinfo->x_focus_frame))); } pgtk_frame_rehighlight (dpyinfo); @@ -6567,15 +6569,18 @@ pgtk_set_event_handler (struct frame *f) GDK_ACTION_COPY); gtk_drag_dest_add_uri_targets (FRAME_GTK_WIDGET (f)); - g_signal_connect (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), - "window-state-event", G_CALLBACK (window_state_event), - NULL); - g_signal_connect (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), "delete-event", - G_CALLBACK (delete_event), NULL); - g_signal_connect (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), "event", - G_CALLBACK (pgtk_handle_event), NULL); - g_signal_connect (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), "configure-event", - G_CALLBACK (configure_event), NULL); + if (FRAME_GTK_OUTER_WIDGET (f)) + { + g_signal_connect (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), + "window-state-event", G_CALLBACK (window_state_event), + NULL); + g_signal_connect (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), "delete-event", + G_CALLBACK (delete_event), NULL); + g_signal_connect (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), "event", + G_CALLBACK (pgtk_handle_event), NULL); + g_signal_connect (G_OBJECT (FRAME_GTK_OUTER_WIDGET (f)), "configure-event", + G_CALLBACK (configure_event), NULL); + } g_signal_connect (G_OBJECT (FRAME_GTK_WIDGET (f)), "map-event", G_CALLBACK (map_event), NULL); -- 2.39.5