From: Yuuki Harano Date: Sun, 21 Jul 2019 14:11:50 +0000 (+0900) Subject: Implement Scroll-bar-forground and scroll-bar-background X-Git-Tag: emacs-29.0.90~3833 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b3a20d7a21795f4e2847938ace6dd454f6b4e870;p=emacs.git Implement Scroll-bar-forground and scroll-bar-background * 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 実装。 --- diff --git a/etc/org.gnu.emacs.defaults.gschema.xml b/etc/org.gnu.emacs.defaults.gschema.xml index 6f2c79196e6..2d206e63a04 100644 --- a/etc/org.gnu.emacs.defaults.gschema.xml +++ b/etc/org.gnu.emacs.defaults.gschema.xml @@ -35,6 +35,8 @@ '' '' '' + '' + '' '' '' '' diff --git a/src/gtkutil.c b/src/gtkutil.c index 6c2691ecd99..b202aa02e2b 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -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; } diff --git a/src/pgtkfns.c b/src/pgtkfns.c index f7edc073a02..a8f81761b3d 100644 --- a/src/pgtkfns.c +++ b/src/pgtkfns.c @@ -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 diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 5890326430f..4665a934718 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -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; diff --git a/src/pgtkterm.h b/src/pgtkterm.h index c85a9ea097e..4c6ef0f6bb8 100644 --- a/src/pgtkterm.h +++ b/src/pgtkterm.h @@ -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;