aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2022-03-11 20:07:52 +0800
committerPo Lu2022-03-11 20:10:23 +0800
commit7ad1df5e1684532efeec435be4ac7fc76affc814 (patch)
treee1fa68133b3802e1810440358f1327b3c115e608
parent92ebfe7da4af5c60d33538d3526ef06d2a0142c4 (diff)
downloademacs-7ad1df5e1684532efeec435be4ac7fc76affc814.tar.gz
emacs-7ad1df5e1684532efeec435be4ac7fc76affc814.zip
Implement customization of scroll bar colors on GTK 3
* src/gtkutil.c (xg_create_frame_widgets): Create CSS providers for scroll bars. (xg_finish_scroll_bar_creation): Attach created CSS providers. * src/xfns.c (x_set_scroll_bar_foreground): (x_set_scroll_bar_background): Put appropriate content into CSS providers. * src/xterm.c (x_free_frame_resources): Free CSS providers. * src/xterm.h (struct x_output): New fields for scroll bar stylesheet providers.
-rw-r--r--src/gtkutil.c30
-rw-r--r--src/xfns.c46
-rw-r--r--src/xterm.c8
-rw-r--r--src/xterm.h7
4 files changed, 80 insertions, 11 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 1b4ecaf9492..f488b0ff752 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1612,10 +1612,7 @@ xg_create_frame_widgets (struct frame *f)
1612 with regular X drawing primitives, so from a GTK/GDK point of 1612 with regular X drawing primitives, so from a GTK/GDK point of
1613 view, the widget is totally blank. When an expose comes, this 1613 view, the widget is totally blank. When an expose comes, this
1614 will make the widget blank, and then Emacs redraws it. This flickers 1614 will make the widget blank, and then Emacs redraws it. This flickers
1615 a lot, so we turn off double buffering. 1615 a lot, so we turn off double buffering. */
1616 FIXME: gtk_widget_set_double_buffered is deprecated and might stop
1617 working in the future. We need to migrate away from combining
1618 X and GTK+ drawing to a pure GTK+ build. */
1619 1616
1620#ifndef HAVE_PGTK 1617#ifndef HAVE_PGTK
1621 gtk_widget_set_double_buffered (wfixed, FALSE); 1618 gtk_widget_set_double_buffered (wfixed, FALSE);
@@ -1634,6 +1631,14 @@ xg_create_frame_widgets (struct frame *f)
1634 G_CALLBACK (delete_cb), f); 1631 G_CALLBACK (delete_cb), f);
1635#endif 1632#endif
1636 1633
1634#if defined HAVE_GTK3 && !defined HAVE_PGTK
1635 /* On PGTK this is done in Fx_create_frame. */
1636 FRAME_OUTPUT_DATA (f)->scrollbar_background_css_provider
1637 = gtk_css_provider_new ();
1638 FRAME_OUTPUT_DATA (f)->scrollbar_foreground_css_provider
1639 = gtk_css_provider_new ();
1640#endif
1641
1637 /* Convert our geometry parameters into a geometry string 1642 /* Convert our geometry parameters into a geometry string
1638 and specify it. 1643 and specify it.
1639 GTK will itself handle calculating the real position this way. */ 1644 GTK will itself handle calculating the real position this way. */
@@ -4448,6 +4453,10 @@ xg_finish_scroll_bar_creation (struct frame *f,
4448 const char *scroll_bar_name) 4453 const char *scroll_bar_name)
4449{ 4454{
4450 GtkWidget *webox = gtk_event_box_new (); 4455 GtkWidget *webox = gtk_event_box_new ();
4456#ifdef HAVE_GTK3
4457 GtkCssProvider *foreground_provider;
4458 GtkCssProvider *background_provider;
4459#endif
4451 4460
4452 gtk_widget_set_name (wscroll, scroll_bar_name); 4461 gtk_widget_set_name (wscroll, scroll_bar_name);
4453#ifndef HAVE_GTK3 4462#ifndef HAVE_GTK3
@@ -4496,15 +4505,14 @@ xg_finish_scroll_bar_creation (struct frame *f,
4496 /* Set the cursor to an arrow. */ 4505 /* Set the cursor to an arrow. */
4497 xg_set_cursor (webox, FRAME_DISPLAY_INFO (f)->xg_cursor); 4506 xg_set_cursor (webox, FRAME_DISPLAY_INFO (f)->xg_cursor);
4498 4507
4499#ifdef HAVE_PGTK 4508#ifdef HAVE_GTK3
4500 GtkStyleContext *ctxt = gtk_widget_get_style_context (wscroll); 4509 GtkStyleContext *ctxt = gtk_widget_get_style_context (wscroll);
4501 gtk_style_context_add_provider (ctxt, 4510 foreground_provider = FRAME_OUTPUT_DATA (f)->scrollbar_foreground_css_provider;
4502 GTK_STYLE_PROVIDER (FRAME_OUTPUT_DATA (f)-> 4511 background_provider = FRAME_OUTPUT_DATA (f)->scrollbar_background_css_provider;
4503 scrollbar_foreground_css_provider), 4512
4513 gtk_style_context_add_provider (ctxt, GTK_STYLE_PROVIDER (foreground_provider),
4504 GTK_STYLE_PROVIDER_PRIORITY_USER); 4514 GTK_STYLE_PROVIDER_PRIORITY_USER);
4505 gtk_style_context_add_provider (ctxt, 4515 gtk_style_context_add_provider (ctxt, GTK_STYLE_PROVIDER (background_provider),
4506 GTK_STYLE_PROVIDER (FRAME_OUTPUT_DATA (f)->
4507 scrollbar_background_css_provider),
4508 GTK_STYLE_PROVIDER_PRIORITY_USER); 4516 GTK_STYLE_PROVIDER_PRIORITY_USER);
4509#endif 4517#endif
4510 4518
diff --git a/src/xfns.c b/src/xfns.c
index a3236efbcc6..65f3b5097c3 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1943,6 +1943,10 @@ static void
1943x_set_scroll_bar_foreground (struct frame *f, Lisp_Object value, Lisp_Object oldval) 1943x_set_scroll_bar_foreground (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1944{ 1944{
1945 unsigned long pixel; 1945 unsigned long pixel;
1946#ifdef HAVE_GTK3
1947 XColor color;
1948 char css[64];
1949#endif
1946 1950
1947 if (STRINGP (value)) 1951 if (STRINGP (value))
1948 pixel = x_decode_color (f, value, BLACK_PIX_DEFAULT (f)); 1952 pixel = x_decode_color (f, value, BLACK_PIX_DEFAULT (f));
@@ -1964,6 +1968,25 @@ x_set_scroll_bar_foreground (struct frame *f, Lisp_Object value, Lisp_Object old
1964 update_face_from_frame_parameter (f, Qscroll_bar_foreground, value); 1968 update_face_from_frame_parameter (f, Qscroll_bar_foreground, value);
1965 redraw_frame (f); 1969 redraw_frame (f);
1966 } 1970 }
1971
1972#ifdef HAVE_GTK3
1973 if (pixel != -1)
1974 {
1975 color.pixel = pixel;
1976
1977 XQueryColor (FRAME_X_DISPLAY (f),
1978 FRAME_X_COLORMAP (f),
1979 &color);
1980
1981 sprintf (css, "scrollbar slider { background-color: #%02x%02x%02x; }",
1982 color.red >> 8, color.green >> 8, color.blue >> 8);
1983 gtk_css_provider_load_from_data (FRAME_X_OUTPUT (f)->scrollbar_foreground_css_provider,
1984 css, -1, NULL);
1985 }
1986 else
1987 gtk_css_provider_load_from_data (FRAME_X_OUTPUT (f)->scrollbar_foreground_css_provider,
1988 "", -1, NULL);
1989#endif
1967} 1990}
1968 1991
1969 1992
@@ -1976,6 +1999,10 @@ static void
1976x_set_scroll_bar_background (struct frame *f, Lisp_Object value, Lisp_Object oldval) 1999x_set_scroll_bar_background (struct frame *f, Lisp_Object value, Lisp_Object oldval)
1977{ 2000{
1978 unsigned long pixel; 2001 unsigned long pixel;
2002#ifdef HAVE_GTK3
2003 XColor color;
2004 char css[64];
2005#endif
1979 2006
1980 if (STRINGP (value)) 2007 if (STRINGP (value))
1981 pixel = x_decode_color (f, value, WHITE_PIX_DEFAULT (f)); 2008 pixel = x_decode_color (f, value, WHITE_PIX_DEFAULT (f));
@@ -2011,6 +2038,25 @@ x_set_scroll_bar_background (struct frame *f, Lisp_Object value, Lisp_Object old
2011 update_face_from_frame_parameter (f, Qscroll_bar_background, value); 2038 update_face_from_frame_parameter (f, Qscroll_bar_background, value);
2012 redraw_frame (f); 2039 redraw_frame (f);
2013 } 2040 }
2041
2042#ifdef HAVE_GTK3
2043 if (pixel != -1)
2044 {
2045 color.pixel = pixel;
2046
2047 XQueryColor (FRAME_X_DISPLAY (f),
2048 FRAME_X_COLORMAP (f),
2049 &color);
2050
2051 sprintf (css, "scrollbar trough { background-color: #%02x%02x%02x; }",
2052 color.red >> 8, color.green >> 8, color.blue >> 8);
2053 gtk_css_provider_load_from_data (FRAME_X_OUTPUT (f)->scrollbar_background_css_provider,
2054 css, -1, NULL);
2055 }
2056 else
2057 gtk_css_provider_load_from_data (FRAME_X_OUTPUT (f)->scrollbar_background_css_provider,
2058 "", -1, NULL);
2059#endif
2014} 2060}
2015 2061
2016 2062
diff --git a/src/xterm.c b/src/xterm.c
index 2adf70b829d..cf79135497c 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -16579,6 +16579,14 @@ x_free_frame_resources (struct frame *f)
16579 XFlush (FRAME_X_DISPLAY (f)); 16579 XFlush (FRAME_X_DISPLAY (f));
16580 } 16580 }
16581 16581
16582#ifdef HAVE_GTK3
16583 if (FRAME_OUTPUT_DATA (f)->scrollbar_background_css_provider)
16584 g_object_unref (FRAME_OUTPUT_DATA (f)->scrollbar_background_css_provider);
16585
16586 if (FRAME_OUTPUT_DATA (f)->scrollbar_foreground_css_provider)
16587 g_object_unref (FRAME_OUTPUT_DATA (f)->scrollbar_foreground_css_provider);
16588#endif
16589
16582 xfree (f->output_data.x->saved_menu_event); 16590 xfree (f->output_data.x->saved_menu_event);
16583 xfree (f->output_data.x); 16591 xfree (f->output_data.x);
16584 f->output_data.x = NULL; 16592 f->output_data.x = NULL;
diff --git a/src/xterm.h b/src/xterm.h
index 4875eabafe6..5b199cab6b6 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -758,6 +758,13 @@ struct x_output
758 GtkWindow *ttip_window; 758 GtkWindow *ttip_window;
759 759
760 GtkIMContext *im_context; 760 GtkIMContext *im_context;
761
762#ifdef HAVE_GTK3
763 /* The CSS providers used for scroll bar foreground and background
764 colors. */
765 GtkCssProvider *scrollbar_foreground_css_provider;
766 GtkCssProvider *scrollbar_background_css_provider;
767#endif
761#endif /* USE_GTK */ 768#endif /* USE_GTK */
762 769
763 /* If >=0, a bitmap index. The indicated bitmap is used for the 770 /* If >=0, a bitmap index. The indicated bitmap is used for the