comparison src/gtkutil.c @ 109749:be18c3b67d66

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.
author Jan D <jan.h.d@swipnet.se>
date Wed, 11 Aug 2010 20:28:10 +0200
parents e2f8226efb99
children c917fbc9b294
comparison
equal deleted inserted replaced
109748:e2f8226efb99 109749:be18c3b67d66
502 g_error_free (error); 502 g_error_free (error);
503 error = NULL; 503 error = NULL;
504 } 504 }
505 } 505 }
506 return utf8_str; 506 return utf8_str;
507 }
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
513 int
514 xg_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;
507 } 542 }
508 543
509 544
510 545
511 /*********************************************************************** 546 /***********************************************************************
896 { 931 {
897 GdkColormap *map = gtk_widget_get_colormap (w); 932 GdkColormap *map = gtk_widget_get_colormap (w);
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
939 static void
940 style_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
904 int 959 int
905 xg_create_frame_widgets (FRAME_PTR f) 960 xg_create_frame_widgets (FRAME_PTR f)
1020 f->output_data.x->ttip_lbl = 0; 1075 f->output_data.x->ttip_lbl = 0;
1021 f->output_data.x->ttip_window = 0; 1076 f->output_data.x->ttip_window = 0;
1022 gtk_widget_set_tooltip_text (wtop, "Dummy text"); 1077 gtk_widget_set_tooltip_text (wtop, "Dummy text");
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
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 }
1025 1096
1026 UNBLOCK_INPUT; 1097 UNBLOCK_INPUT;
1027 1098
1028 return 1; 1099 return 1;
1029 } 1100 }