aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan D2010-08-11 20:28:10 +0200
committerJan D2010-08-11 20:28:10 +0200
commit3a46642b081c504b6e25c65d81999fcc0dff5fb2 (patch)
treea7f42c1836467e6c8539cef167977a48c182ad97
parent42ca463309fdb17f04a72dad92696312bf242328 (diff)
downloademacs-3a46642b081c504b6e25c65d81999fcc0dff5fb2.tar.gz
emacs-3a46642b081c504b6e25c65d81999fcc0dff5fb2.zip
Take colors for region face (selected text) from the Gtk+ theme.
* lisp/dynamic-setting.el (dynamic-setting-handle-config-changed-event): Handle theme-name change. * lisp/faces.el (region): Add type gtk that uses gtk colors. * src/gtkutil.c (xg_check_special_colors, style_changed_cb): New functions. (xg_create_frame_widgets): Connect theme name changes to style_changed_cb. * src/gtkutil.h (xg_check_special_colors): Declare. * src/xfns.c (x_defined_color): If USE_GTK, call xg_check_special_colors first.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/dynamic-setting.el5
-rw-r--r--lisp/faces.el3
-rw-r--r--src/ChangeLog9
-rw-r--r--src/gtkutil.c71
-rw-r--r--src/gtkutil.h3
-rw-r--r--src/xfns.c8
8 files changed, 107 insertions, 2 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 9837e6c95b8..a8908379ce4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -109,6 +109,9 @@ The frame-parameter tool-bar-position controls this. It takes the values
109top, left, tight or bottom. The Options => Show/Hide menu has entries 109top, left, tight or bottom. The Options => Show/Hide menu has entries
110for this. 110for this.
111 111
112** The colors for selected text (the region face) are taken from the GTK
113theme when Emacs is built with GTK.
114
112** Emacs uses GTK tooltips by default if built with GTK. You can turn that 115** Emacs uses GTK tooltips by default if built with GTK. You can turn that
113off by customizing x-gtk-use-system-tooltips. 116off by customizing x-gtk-use-system-tooltips.
114 117
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6f15ae942fc..763ffd0dd0f 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12010-08-11 Jan Djärv <jan.h.d@swipnet.se>
2
3 * faces.el (region): Add type gtk that uses gtk colors.
4
5 * dynamic-setting.el (dynamic-setting-handle-config-changed-event):
6 Handle theme-name change.
7
12010-08-10 Michael R. Mauger <mmaug@yahoo.com> 82010-08-10 Michael R. Mauger <mmaug@yahoo.com>
2 9
3 * progmodes/sql.el: Version 2.5 10 * progmodes/sql.el: Version 2.5
diff --git a/lisp/dynamic-setting.el b/lisp/dynamic-setting.el
index f61a0078e17..790aaf7170e 100644
--- a/lisp/dynamic-setting.el
+++ b/lisp/dynamic-setting.el
@@ -96,6 +96,11 @@ Changes can be
96 ((eq type 'font-render) 96 ((eq type 'font-render)
97 (font-setting-change-default-font display-name nil)) 97 (font-setting-change-default-font display-name nil))
98 98
99 ;; This is a bit heavy, ideally we would just clear faces
100 ;; on the affected display, and perhaps only the relevant
101 ;; faces. Oh well.
102 ((eq type 'theme-name) (clear-face-cache))
103
99 ((eq type 'tool-bar-style) (force-mode-line-update t))))) 104 ((eq type 'tool-bar-style) (force-mode-line-update t)))))
100 105
101(define-key special-event-map [config-changed-event] 106(define-key special-event-map [config-changed-event]
diff --git a/lisp/faces.el b/lisp/faces.el
index b7c238e14f3..d8b6f20035c 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -2281,6 +2281,9 @@ terminal type to a different value."
2281(defface region 2281(defface region
2282 '((((class color) (min-colors 88) (background dark)) 2282 '((((class color) (min-colors 88) (background dark))
2283 :background "blue3") 2283 :background "blue3")
2284 (((class color) (min-colors 88) (background light) (type gtk))
2285 :foreground "gtk_selection_fg_color"
2286 :background "gtk_selection_bg_color")
2284 (((class color) (min-colors 88) (background light) (type ns)) 2287 (((class color) (min-colors 88) (background light) (type ns))
2285 :background "ns_selection_color") 2288 :background "ns_selection_color")
2286 (((class color) (min-colors 88) (background light)) 2289 (((class color) (min-colors 88) (background light))
diff --git a/src/ChangeLog b/src/ChangeLog
index 89414fa4d78..1275b4a8def 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,14 @@
12010-08-11 Jan Djärv <jan.h.d@swipnet.se> 12010-08-11 Jan Djärv <jan.h.d@swipnet.se>
2 2
3 * xfns.c (x_defined_color): If USE_GTK, call xg_check_special_colors
4 first.
5
6 * gtkutil.h (xg_check_special_colors): Declare.
7
8 * gtkutil.c (xg_check_special_colors, style_changed_cb): New functions.
9 (xg_create_frame_widgets): Connect theme name changes to
10 style_changed_cb.
11
3 * xterm.c (emacs_class): New char[] for EMACS_CLASS. 12 * xterm.c (emacs_class): New char[] for EMACS_CLASS.
4 (xim_open_dpy, xim_initialize, xim_close_dpy): Use emacs_class. 13 (xim_open_dpy, xim_initialize, xim_close_dpy): Use emacs_class.
5 (x_term_init): Use char[] display_opt and name_opt instead of 14 (x_term_init): Use char[] display_opt and name_opt instead of
diff --git a/src/gtkutil.c b/src/gtkutil.c
index a9f2d103702..fd89015aedc 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -506,6 +506,41 @@ get_utf8_string (const char *str)
506 return utf8_str; 506 return utf8_str;
507} 507}
508 508
509/* Check for special colors used in face spec for region face.
510 The colors are fetched from the Gtk+ theme.
511 Return 1 if color was found, 0 if not. */
512
513int
514xg_check_special_colors (struct frame *f,
515 const char *color_name,
516 XColor *color)
517{
518 int success_p = 0;
519 if (FRAME_GTK_WIDGET (f))
520 {
521 if (strcmp ("gtk_selection_bg_color", color_name) == 0)
522 {
523 GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f));
524 color->red = gsty->bg[GTK_STATE_SELECTED].red;
525 color->green = gsty->bg[GTK_STATE_SELECTED].green;
526 color->blue = gsty->bg[GTK_STATE_SELECTED].blue;
527 color->pixel = gsty->bg[GTK_STATE_SELECTED].pixel;
528 success_p = 1;
529 }
530 else if (strcmp ("gtk_selection_fg_color", color_name) == 0)
531 {
532 GtkStyle *gsty = gtk_widget_get_style (FRAME_GTK_WIDGET (f));
533 color->red = gsty->fg[GTK_STATE_SELECTED].red;
534 color->green = gsty->fg[GTK_STATE_SELECTED].green;
535 color->blue = gsty->fg[GTK_STATE_SELECTED].blue;
536 color->pixel = gsty->fg[GTK_STATE_SELECTED].pixel;
537 success_p = 1;
538 }
539 }
540
541 return success_p;
542}
543
509 544
510 545
511/*********************************************************************** 546/***********************************************************************
@@ -898,6 +933,26 @@ xg_pix_to_gcolor (GtkWidget *w, long unsigned int pixel, GdkColor *c)
898 gdk_colormap_query_color (map, pixel, c); 933 gdk_colormap_query_color (map, pixel, c);
899} 934}
900 935
936/* Callback called when the gtk theme changes.
937 We notify lisp code so it can fix faces used for region for example. */
938
939static void
940style_changed_cb (GObject *go,
941 GParamSpec *spec,
942 gpointer user_data)
943{
944 struct input_event event;
945 GdkDisplay *gdpy = (GdkDisplay *) user_data;
946 const char *display_name = gdk_display_get_name (gdpy);
947
948 EVENT_INIT (event);
949 event.kind = CONFIG_CHANGED_EVENT;
950 event.frame_or_window = make_string (display_name, strlen (display_name));
951 /* Theme doesn't change often, so intern is called seldom. */
952 event.arg = intern ("theme-name");
953 kbd_buffer_store_event (&event);
954}
955
901/* Create and set up the GTK widgets for frame F. 956/* Create and set up the GTK widgets for frame F.
902 Return 0 if creation failed, non-zero otherwise. */ 957 Return 0 if creation failed, non-zero otherwise. */
903 958
@@ -1023,6 +1078,22 @@ xg_create_frame_widgets (FRAME_PTR f)
1023 g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f); 1078 g_signal_connect (wtop, "query-tooltip", G_CALLBACK (qttip_cb), f);
1024#endif 1079#endif
1025 1080
1081 {
1082 GdkScreen *screen = gtk_widget_get_screen (wtop);
1083 GtkSettings *gs = gtk_settings_get_for_screen (screen);
1084 /* Only connect this signal once per screen. */
1085 if (! g_signal_handler_find (G_OBJECT (gs),
1086 G_SIGNAL_MATCH_FUNC,
1087 0, 0, 0,
1088 G_CALLBACK (style_changed_cb),
1089 0))
1090 {
1091 g_signal_connect (G_OBJECT (gs), "notify::gtk-theme-name",
1092 G_CALLBACK (style_changed_cb),
1093 gdk_screen_get_display (screen));
1094 }
1095 }
1096
1026 UNBLOCK_INPUT; 1097 UNBLOCK_INPUT;
1027 1098
1028 return 1; 1099 return 1;
diff --git a/src/gtkutil.h b/src/gtkutil.h
index 6e86425fb74..9b796e1138c 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -156,6 +156,9 @@ extern void x_wm_set_size_hint (FRAME_PTR f,
156 long flags, 156 long flags,
157 int user_position); 157 int user_position);
158extern void xg_set_background_color (FRAME_PTR f, unsigned long bg); 158extern void xg_set_background_color (FRAME_PTR f, unsigned long bg);
159extern int xg_check_special_colors (struct frame *f,
160 const char *color_name,
161 XColor *color);
159 162
160extern void xg_set_frame_icon (FRAME_PTR f, 163extern void xg_set_frame_icon (FRAME_PTR f,
161 Pixmap icon_pixmap, 164 Pixmap icon_pixmap,
diff --git a/src/xfns.c b/src/xfns.c
index bc28ccd3a63..8544d9e3e10 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -648,12 +648,16 @@ int
648x_defined_color (struct frame *f, const char *color_name, 648x_defined_color (struct frame *f, const char *color_name,
649 XColor *color, int alloc_p) 649 XColor *color, int alloc_p)
650{ 650{
651 int success_p; 651 int success_p = 0;
652 Display *dpy = FRAME_X_DISPLAY (f); 652 Display *dpy = FRAME_X_DISPLAY (f);
653 Colormap cmap = FRAME_X_COLORMAP (f); 653 Colormap cmap = FRAME_X_COLORMAP (f);
654 654
655 BLOCK_INPUT; 655 BLOCK_INPUT;
656 success_p = XParseColor (dpy, cmap, color_name, color); 656#ifdef USE_GTK
657 success_p = xg_check_special_colors (f, color_name, color);
658#endif
659 if (!success_p)
660 success_p = XParseColor (dpy, cmap, color_name, color);
657 if (success_p && alloc_p) 661 if (success_p && alloc_p)
658 success_p = x_alloc_nearest_color (f, cmap, color); 662 success_p = x_alloc_nearest_color (f, cmap, color);
659 UNBLOCK_INPUT; 663 UNBLOCK_INPUT;