]> git.eshelyaron.com Git - emacs.git/commitdiff
Undo C parts of "Don't use the Gtk region face"
authorPo Lu <luangruo@yahoo.com>
Sat, 23 Jul 2022 09:02:22 +0000 (17:02 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 23 Jul 2022 09:03:04 +0000 (17:03 +0800)
This reverts commit a24f710395f9777cb9f8b000300e5e9c892d7794, apart
from the change to faces.el and NEWS.

src/gtkutil.c
src/gtkutil.h
src/pgtkterm.c
src/xfns.c

index 87f166bf54d63e7f845faa9bcf3d0a6d1057a3b6..a6bba096a43b30a279b8d5a024751e94f366ae45 100644 (file)
@@ -727,6 +727,88 @@ get_utf8_string (const char *str)
   return utf8_str;
 }
 
+/* Check for special colors used in face spec for region face.
+   The colors are fetched from the Gtk+ theme.
+   Return true if color was found, false if not.  */
+
+bool
+xg_check_special_colors (struct frame *f,
+                         const char *color_name,
+                         Emacs_Color *color)
+{
+  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;
+
+#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
+  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);
+    }
+
+  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;
+#else
+  sprintf (buf, "#%04x%04x%04x", r, g, b);
+  success_p = pgtk_parse_color (f, buf, color) != 0;
+#endif
+#else
+  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;
+#endif
+  unblock_input ();
+  return success_p;
+}
+
+
 \f
 /***********************************************************************
                               Tooltips
index 32b1fedbaa6841c57061987d409b4acd8f09325f..190d66283142d816c096a66f21b9283ea0882b20 100644 (file)
@@ -179,6 +179,9 @@ extern GdkCursor * xg_create_default_cursor (GdkDisplay *gdpy);
 extern bool xg_create_frame_widgets (struct frame *f);
 extern void xg_free_frame_widgets (struct frame *f);
 extern void xg_set_background_color (struct frame *f, unsigned long bg);
+extern bool xg_check_special_colors (struct frame *f,
+                                    const char *color_name,
+                                    Emacs_Color *color);
 #ifdef HAVE_PGTK
 extern void xg_create_frame_outer_widgets (struct frame *f);
 #endif
index 54e70255f4571ad2d29163c1a4590dcb5bb01676..b283cef7cde22914c019ec321140324b30e0a480 100644 (file)
@@ -6913,7 +6913,9 @@ pgtk_defined_color (struct frame *f, const char *name,
   int r;
 
   block_input ();
-  r = pgtk_parse_color (f, name, color_def);
+  r = xg_check_special_colors (f, name, color_def);
+  if (!r)
+    r = pgtk_parse_color (f, name, color_def);
   unblock_input ();
   return r;
 }
index 7d394bd4f50aac83b91989f626713c2338a8d259..ce867c1619cfd2a432ed09a017a1f952eb960761 100644 (file)
@@ -670,7 +670,11 @@ x_defined_color (struct frame *f, const char *color_name,
   Colormap cmap = FRAME_X_COLORMAP (f);
 
   block_input ();
-  success_p = x_parse_color (f, color_name, color) != 0;
+#ifdef USE_GTK
+  success_p = xg_check_special_colors (f, color_name, color);
+#endif
+  if (!success_p)
+    success_p = x_parse_color (f, color_name, color) != 0;
   if (success_p && alloc_p)
     success_p = x_alloc_nearest_color (f, cmap, color);
   unblock_input ();