]> git.eshelyaron.com Git - emacs.git/commitdiff
Implement Scroll-bar-forground and scroll-bar-background
authorYuuki Harano <masm+github@masm11.me>
Sun, 21 Jul 2019 14:11:50 +0000 (23:11 +0900)
committerJeff Walsh <fejfighter@gmail.com>
Sun, 22 Nov 2020 03:46:55 +0000 (14:46 +1100)
* src/pgtkterm.h (struct pgtk_output):

* src/pgtkterm.c (x_free_frame_resources):

* src/pgtkfns.c (pgtk_set_scroll_bar_foreground)
(pgtk_set_scroll_bar_background, pgtk_frame_parm_handlers)
(Fx_create_frame):

* src/gtkutil.c (xg_finish_scroll_bar_creation):handle scrollbar css values

* etc/org.gnu.emacs.defaults.gschema.xml: add scroll bar fields

scroll-bar-foreground, scroll-bar-background 実装。

etc/org.gnu.emacs.defaults.gschema.xml
src/gtkutil.c
src/pgtkfns.c
src/pgtkterm.c
src/pgtkterm.h

index 6f2c79196e6e7651205d37176c504844de3adadf..2d206e63a045f7b378131773c9f14346929f01e6 100644 (file)
@@ -35,6 +35,8 @@
     <key name='right-fringe'             type='s'><default>''</default></key>
     <key name='screen-gamma'             type='s'><default>''</default></key>
     <key name='scroll-bar'               type='s'><default>''</default></key>
+    <key name='scroll-bar-background'    type='s'><default>''</default></key>
+    <key name='scroll-bar-foreground'    type='s'><default>''</default></key>
     <key name='scroll-bar-height'        type='s'><default>''</default></key>
     <key name='scroll-bar-width'         type='s'><default>''</default></key>
     <key name='scroll-bars'              type='s'><default>''</default></key>
index 6c2691ecd997b7b179a9f72f20eb0f39d4e7cc8f..b202aa02e2bb9a7ca7033a3b01813bf2a2ad9f02 100644 (file)
@@ -4054,6 +4054,14 @@ xg_finish_scroll_bar_creation (struct frame *f,
   /* Set the cursor to an arrow.  */
   xg_set_cursor (webox, FRAME_DISPLAY_INFO (f)->xg_cursor);
 
+#ifdef HAVE_PGTK
+  GtkStyleContext *ctxt = gtk_widget_get_style_context(wscroll);
+  gtk_style_context_add_provider(ctxt, GTK_STYLE_PROVIDER(FRAME_OUTPUT_DATA (f)->scrollbar_foreground_css_provider),
+                                GTK_STYLE_PROVIDER_PRIORITY_USER);
+  gtk_style_context_add_provider(ctxt, GTK_STYLE_PROVIDER(FRAME_OUTPUT_DATA (f)->scrollbar_background_css_provider),
+                                GTK_STYLE_PROVIDER_PRIORITY_USER);
+#endif
+
   bar->x_window = scroll_id;
 }
 
index f7edc073a0259d87c594fde4d3d192a067fb5b6b..a8f81761b3dae18f16fb6a8c6a1026d34a8a28e6 100644 (file)
@@ -743,6 +743,48 @@ pgtk_set_tool_bar_position (struct frame *f,
     wrong_choice (choice, new_value);
 }
 
+static void
+pgtk_set_scroll_bar_foreground (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+{
+  GtkCssProvider *css_provider = FRAME_X_OUTPUT (f)->scrollbar_foreground_css_provider;
+
+  if (NILP (new_value)) {
+    gtk_css_provider_load_from_data(css_provider, "", -1, NULL);
+  } else if (STRINGP (new_value)) {
+    Emacs_Color rgb;
+
+    if (!pgtk_parse_color (SSDATA (new_value), &rgb))
+      error ("Unknown color.");
+
+    char css[64];
+    sprintf(css, "scrollbar slider { background-color: #%06x; }", (unsigned int) rgb.pixel & 0xffffff);
+    gtk_css_provider_load_from_data(css_provider, css, -1, NULL);
+
+  } else
+    error ("Invalid scroll-bar-foreground.");
+}
+
+static void
+pgtk_set_scroll_bar_background (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+{
+  GtkCssProvider *css_provider = FRAME_X_OUTPUT (f)->scrollbar_background_css_provider;
+
+  if (NILP (new_value)) {
+    gtk_css_provider_load_from_data(css_provider, "", -1, NULL);
+  } else if (STRINGP (new_value)) {
+    Emacs_Color rgb;
+
+    if (!pgtk_parse_color (SSDATA (new_value), &rgb))
+      error ("Unknown color.");
+
+    char css[64];
+    sprintf(css, "scrollbar trough { background-color: #%06x; }", (unsigned int) rgb.pixel & 0xffffff);
+    gtk_css_provider_load_from_data(css_provider, css, -1, NULL);
+
+  } else
+    error ("Invalid scroll-bar-background.");
+}
+
 /* Note: see frame.c for template, also where generic functions are impl */
 frame_parm_handler pgtk_frame_parm_handlers[] =
 {
@@ -771,8 +813,8 @@ frame_parm_handler pgtk_frame_parm_handlers[] =
   gui_set_horizontal_scroll_bars, /* generic OK */
   gui_set_visibility, /* generic OK */
   x_set_tool_bar_lines,
-  0, /* x_set_scroll_bar_foreground, will ignore */
-  0, /* x_set_scroll_bar_background,  will ignore */
+  pgtk_set_scroll_bar_foreground,
+  pgtk_set_scroll_bar_background,
   gui_set_screen_gamma, /* generic OK */
   gui_set_line_spacing, /* generic OK, sets f->extra_line_spacing to int */
   gui_set_left_fringe, /* generic OK */
@@ -1043,13 +1085,12 @@ This function is an internal primitive--use `make-frame' instead.  */)
   FRAME_X_OUTPUT(f)->icon_bitmap = -1;
 #endif
   FRAME_FONTSET (f) = -1;
-#if 0
-  FRAME_X_OUTPUT(f)->scroll_bar_foreground_pixel = -1;
-  FRAME_X_OUTPUT(f)->scroll_bar_background_pixel = -1;
-#endif
   FRAME_X_OUTPUT(f)->white_relief.pixel = -1;
   FRAME_X_OUTPUT(f)->black_relief.pixel = -1;
 
+  FRAME_X_OUTPUT(f)->scrollbar_foreground_css_provider = gtk_css_provider_new();
+  FRAME_X_OUTPUT(f)->scrollbar_background_css_provider = gtk_css_provider_new();
+
   fset_icon_name (f,
                  gui_display_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
                             RES_TYPE_STRING));
@@ -1195,14 +1236,10 @@ This function is an internal primitive--use `make-frame' instead.  */)
   gui_default_parameter (f, parms, Qno_special_glyphs, Qnil,
                       NULL, NULL, RES_TYPE_BOOLEAN);
 
-#if 0
-  x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground,
-                                       "scrollBarForeground",
-                                       "ScrollBarForeground", true);
-  x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background,
-                                       "scrollBarBackground",
-                                       "ScrollBarBackground", false);
-#endif
+  gui_default_parameter (f, parms, Qscroll_bar_foreground, Qnil,
+                        "scrollBarForeground", "ScrollBarForeground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qscroll_bar_background, Qnil,
+                        "scrollBarBackground", "ScrollBarBackground", RES_TYPE_STRING);
 
   /* Init faces before gui_default_parameter is called for the
      scroll-bar-width parameter because otherwise we end up in
index 5890326430fdfff7808231992a87e62fe36ca3a6..4665a93471890621e328299a4ae30848cb4d1484 100644 (file)
@@ -194,8 +194,6 @@ x_free_frame_resources (struct frame *f)
   if (f == hlinfo->mouse_face_mouse_frame)
     reset_mouse_highlight (hlinfo);
 
-  gtk_widget_destroy(FRAME_GTK_OUTER_WIDGET(f));
-
   if (FRAME_X_OUTPUT(f)->border_color_css_provider != NULL) {
     GtkStyleContext *ctxt = gtk_widget_get_style_context(FRAME_GTK_OUTER_WIDGET(f));
     GtkCssProvider *old = FRAME_X_OUTPUT(f)->border_color_css_provider;
@@ -203,6 +201,20 @@ x_free_frame_resources (struct frame *f)
     FRAME_X_OUTPUT(f)->border_color_css_provider = NULL;
   }
 
+  if (FRAME_X_OUTPUT(f)->scrollbar_foreground_css_provider != NULL) {
+    GtkCssProvider *old = FRAME_X_OUTPUT(f)->scrollbar_foreground_css_provider;
+    g_object_unref (old);
+    FRAME_X_OUTPUT(f)->scrollbar_foreground_css_provider = NULL;
+  }
+
+  if (FRAME_X_OUTPUT(f)->scrollbar_background_css_provider != NULL) {
+    GtkCssProvider *old = FRAME_X_OUTPUT(f)->scrollbar_background_css_provider;
+    g_object_unref (old);
+    FRAME_X_OUTPUT(f)->scrollbar_background_css_provider = NULL;
+  }
+
+  gtk_widget_destroy(FRAME_GTK_OUTER_WIDGET(f));
+
   if (FRAME_X_OUTPUT(f)->cr_surface_visible_bell != NULL) {
     cairo_surface_destroy(FRAME_X_OUTPUT(f)->cr_surface_visible_bell);
     FRAME_X_OUTPUT(f)->cr_surface_visible_bell = NULL;
index c85a9ea097eb1a792d20e086017502d9757ca74d..4c6ef0f6bb895cfb07f019b548331b721148fa03 100644 (file)
@@ -265,6 +265,10 @@ struct pgtk_output
   unsigned long border_pixel;
   GtkCssProvider *border_color_css_provider;
 
+  /* scrollbar color */
+  GtkCssProvider *scrollbar_foreground_css_provider;
+  GtkCssProvider *scrollbar_background_css_provider;
+
   /* Widget whose cursor is hourglass_cursor.  This widget is temporarily
      mapped to display an hourglass cursor.  */
   GtkWidget *hourglass_widget;