From: Po Lu Date: Mon, 23 May 2022 05:30:33 +0000 (+0800) Subject: Minor fixes to PGTK child frames X-Git-Tag: emacs-29.0.90~1910^2~494 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b629cb3f547b5acd6d4ee3574d31b3530f93ff1f;p=emacs.git Minor fixes to PGTK child frames * src/gtkutil.c (xg_check_special_colors): Handle child frames correctly. * src/pgtkfns.c (pgtk_set_child_frame_border_width): Synchronize code from X. (bug#55588) * src/pgtkmenu.c (pgtk_menu_show, pgtk_dialog_show): Allow in child frames. There are no problems here. * src/pgtkterm.c (pgtk_mouse_position): Clean up coding style. --- diff --git a/src/gtkutil.c b/src/gtkutil.c index 11ccbbd6683..f2018bc01f5 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -736,67 +736,74 @@ xg_check_special_colors (struct frame *f, const char *color_name, Emacs_Color *color) { - bool success_p = 0; - bool get_bg = strcmp ("gtk_selection_bg_color", color_name) == 0; - bool get_fg = !get_bg && strcmp ("gtk_selection_fg_color", color_name) == 0; + bool success_p; + bool get_bg; + bool get_fg; +#ifdef HAVE_GTK3 + GtkStyleContext *gsty; + GdkRGBA col; + char buf[sizeof "rgb://rrrr/gggg/bbbb"]; + int state; + GdkRGBA *c; + unsigned short r, g, b; +#else + GtkStyle *gsty; + GdkColor *grgb; +#endif + + get_bg = !strcmp ("gtk_selection_bg_color", color_name); + get_fg = !get_bg && !strcmp ("gtk_selection_fg_color", color_name); + success_p = false; - if (! FRAME_GTK_WIDGET (f) || ! (get_bg || get_fg)) +#ifdef HAVE_PGTK + while (FRAME_PARENT_FRAME (f)) + f = FRAME_PARENT_FRAME (f); +#endif + + if (!FRAME_GTK_WIDGET (f) || !(get_bg || get_fg)) return success_p; block_input (); - { #ifdef HAVE_GTK3 -#ifndef HAVE_PGTK - GtkStyleContext *gsty - = gtk_widget_get_style_context (FRAME_GTK_OUTER_WIDGET (f)); -#else - GtkStyleContext *gsty - = gtk_widget_get_style_context (FRAME_WIDGET (f)); -#endif - GdkRGBA col; - char buf[sizeof "rgb://rrrr/gggg/bbbb"]; - int state = GTK_STATE_FLAG_SELECTED|GTK_STATE_FLAG_FOCUSED; - if (get_fg) - gtk_style_context_get_color (gsty, state, &col); - else - { - GdkRGBA *c; - /* FIXME: Retrieving the background color is deprecated in - GTK+ 3.16. New versions of GTK+ don't use the concept of a - single background color any more, so we shouldn't query for - it. */ - gtk_style_context_get (gsty, state, - GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &c, - NULL); - col = *c; - gdk_rgba_free (c); - } + gsty = gtk_widget_get_style_context (FRAME_GTK_OUTER_WIDGET (f)); + state = GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_FOCUSED; + + if (get_fg) + gtk_style_context_get_color (gsty, state, &col); + else + { + /* FIXME: Retrieving the background color is deprecated in + GTK+ 3.16. New versions of GTK+ don't use the concept of a + single background color any more, so we shouldn't query for + it. */ + gtk_style_context_get (gsty, state, + GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &c, + NULL); + col = *c; + gdk_rgba_free (c); + } - unsigned short - r = col.red * 65535, - g = col.green * 65535, - b = col.blue * 65535; + r = col.red * 65535; + g = col.green * 65535; + b = col.blue * 65535; #ifndef HAVE_PGTK - sprintf (buf, "rgb:%04x/%04x/%04x", r, g, b); - success_p = x_parse_color (f, buf, color) != 0; + sprintf (buf, "rgb:%04x/%04x/%04x", r, g, b); + success_p = x_parse_color (f, buf, color) != 0; #else - sprintf (buf, "#%04x%04x%04x", r, g, b); - success_p = pgtk_parse_color (f, buf, color) != 0; + sprintf (buf, "#%04x%04x%04x", r, g, b); + success_p = pgtk_parse_color (f, buf, color) != 0; #endif #else - GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f)); - GdkColor *grgb = get_bg - ? &gsty->bg[GTK_STATE_SELECTED] - : &gsty->fg[GTK_STATE_SELECTED]; + gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f)); + grgb = (get_bg ? &gsty->bg[GTK_STATE_SELECTED] + : &gsty->fg[GTK_STATE_SELECTED]); - color->red = grgb->red; - color->green = grgb->green; - color->blue = grgb->blue; - color->pixel = grgb->pixel; - success_p = 1; + color->red = grgb->red; + color->green = grgb->green; + color->blue = grgb->blue; + color->pixel = grgb->pixel; + success_p = 1; #endif - - } unblock_input (); return success_p; } diff --git a/src/pgtkfns.c b/src/pgtkfns.c index 1feb3fe250d..b26709d90c0 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -566,15 +566,23 @@ pgtk_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) static void pgtk_set_child_frame_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { - int border = check_int_nonnegative (arg); + int border; + + if (NILP (arg)) + border = -1; + else if (RANGED_FIXNUMP (0, arg, INT_MAX)) + border = XFIXNAT (arg); + else + signal_error ("Invalid child frame border width", arg); if (border != FRAME_CHILD_FRAME_BORDER_WIDTH (f)) { f->child_frame_border_width = border; - if (FRAME_X_WINDOW (f)) + if (FRAME_GTK_WIDGET (f)) { - adjust_frame_size (f, -1, -1, 3, false, Qchild_frame_border_width); + adjust_frame_size (f, -1, -1, 3, + false, Qchild_frame_border_width); pgtk_clear_under_internal_border (f); } } diff --git a/src/pgtkmenu.c b/src/pgtkmenu.c index eec9f419d07..2eabf6ac1bc 100644 --- a/src/pgtkmenu.c +++ b/src/pgtkmenu.c @@ -610,11 +610,6 @@ 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"; @@ -919,11 +914,6 @@ 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 71b5f23283c..da958a6664a 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -3351,15 +3351,10 @@ pgtk_mouse_position (struct frame **fp, int insist, Lisp_Object * bar_window, if (gui_mouse_grabbed (dpyinfo) && (!EQ (track_mouse, Qdropping) && !EQ (track_mouse, Qdrag_source))) - { - /* 1.1. use last_mouse_frame as frame where the pointer is - on. */ - f1 = dpyinfo->last_mouse_frame; - } + f1 = dpyinfo->last_mouse_frame; else { f1 = *fp; - /* 1.2. get frame where the pointer is on. */ win = gtk_widget_get_window (FRAME_GTK_WIDGET (*fp)); seat = gdk_display_get_default_seat (dpyinfo->gdpy); device = gdk_seat_get_pointer (seat); @@ -3385,19 +3380,17 @@ pgtk_mouse_position (struct frame **fp, int insist, Lisp_Object * bar_window, return; } - /* 2. get the display and the device. */ win = gtk_widget_get_window (FRAME_GTK_WIDGET (f1)); - GdkDisplay *gdpy = gdk_window_get_display (win); - seat = gdk_display_get_default_seat (gdpy); + seat = gdk_display_get_default_seat (dpyinfo->gdpy); device = gdk_seat_get_pointer (seat); - /* 3. get x, y relative to edit window of the frame. */ - win = gdk_window_get_device_position (win, device, &win_x, &win_y, &mask); + win = gdk_window_get_device_position (win, device, + &win_x, &win_y, &mask); if (f1 != NULL) { - dpyinfo = FRAME_DISPLAY_INFO (f1); - remember_mouse_glyph (f1, win_x, win_y, &dpyinfo->last_mouse_glyph); + remember_mouse_glyph (f1, win_x, win_y, + &dpyinfo->last_mouse_glyph); dpyinfo->last_mouse_glyph_frame = f1; *bar_window = Qnil;