Skip to content

Commit

Permalink
[gtk] use symbolic color name to lookup selected color.
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Dec 20, 2017
1 parent 399ae26 commit 78b98d9
Showing 1 changed file with 20 additions and 52 deletions.
72 changes: 20 additions & 52 deletions src/frontend/gtk2/fcitximcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ struct _FcitxIMContext {
GdkWindow *client_window;
GdkRectangle area;
FcitxClient *client;
#if GTK_CHECK_VERSION(3, 0, 0)
GtkStyleContext *style_context;
GtkWidgetPath *empty_path;
#endif
GtkIMContext *slave;
int has_focus;
guint32 time;
Expand Down Expand Up @@ -490,10 +486,6 @@ static void fcitx_im_context_init(FcitxIMContext *context) {
}

context->client = fcitx_client_new_with_connection(_connection);
#if GTK_CHECK_VERSION(3, 0, 0)
context->style_context = gtk_style_context_new();
context->empty_path = gtk_widget_path_new();
#endif
if (context->is_wayland) {
fcitx_client_set_display(context->client, "wayland:");
} else {
Expand Down Expand Up @@ -551,17 +543,6 @@ static void fcitx_im_context_finalize(GObject *obj) {
context->client = NULL;
}

#if GTK_CHECK_VERSION(3, 0, 0)
if (context->style_context) {
g_object_unref(context->style_context);
context->style_context = NULL;
}
if (context->empty_path) {
gtk_widget_path_unref(context->empty_path);
context->empty_path = NULL;
}
#endif

if (context->slave) {
g_signal_handlers_disconnect_by_data(context->slave, context);
g_object_unref(context->slave);
Expand Down Expand Up @@ -786,39 +767,26 @@ static void _fcitx_im_context_update_formatted_preedit_cb(FcitxClient *im,
#if GTK_CHECK_VERSION(3, 0, 0)
GtkStyleContext *styleContext =
gtk_widget_get_style_context(widget);
GtkWidgetPath *path =
gtk_widget_path_copy(gtk_widget_get_path(widget));
gtk_widget_path_append_type(path, G_TYPE_NONE);
gtk_widget_path_iter_set_object_name(path, -1, "selection");
gtk_widget_path_iter_set_state(
path, -1,
gtk_widget_path_iter_get_state(path, -1) |
GTK_STATE_FLAG_SELECTED);
gtk_style_context_set_path(context->style_context, path);
gtk_style_context_set_parent(context->style_context,
styleContext);
gtk_style_context_set_state(context->style_context,
GTK_STATE_FLAG_SELECTED);
GdkRGBA *fg_rgba = NULL;
GdkRGBA *bg_rgba = NULL;
gtk_style_context_get(
context->style_context, GTK_STATE_FLAG_SELECTED,
"background-color", &bg_rgba, "color", &fg_rgba, NULL);

fg.pixel = 0;
fg.red = CLAMP((gint)(fg_rgba->red * 65535), 0, 65535);
fg.green = CLAMP((gint)(fg_rgba->green * 65535), 0, 65535);
fg.blue = CLAMP((gint)(fg_rgba->blue * 65535), 0, 65535);
bg.pixel = 0;
bg.red = CLAMP((gint)(bg_rgba->red * 65535), 0, 65535);
bg.green = CLAMP((gint)(bg_rgba->green * 65535), 0, 65535);
bg.blue = CLAMP((gint)(bg_rgba->blue * 65535), 0, 65535);
gdk_rgba_free(fg_rgba);
gdk_rgba_free(bg_rgba);
gtk_style_context_set_path(context->style_context,
context->empty_path);
gtk_style_context_set_parent(context->style_context, NULL);
gtk_widget_path_unref(path);
GdkRGBA fg_rgba, bg_rgba;
hasColor =
gtk_style_context_lookup_color(
styleContext, "theme_selected_bg_color",
&bg_rgba) &&
gtk_style_context_lookup_color(
styleContext, "theme_selected_fg_color", &fg_rgba);

if (hasColor) {
fg.pixel = 0;
fg.red = CLAMP((gint)(fg_rgba.red * 65535), 0, 65535);
fg.green =
CLAMP((gint)(fg_rgba.green * 65535), 0, 65535);
fg.blue = CLAMP((gint)(fg_rgba.blue * 65535), 0, 65535);
bg.pixel = 0;
bg.red = CLAMP((gint)(bg_rgba.red * 65535), 0, 65535);
bg.green =
CLAMP((gint)(bg_rgba.green * 65535), 0, 65535);
bg.blue = CLAMP((gint)(bg_rgba.blue * 65535), 0, 65535);
}
#else
GtkStyle *style = gtk_widget_get_style(widget);
fg = style->text[GTK_STATE_SELECTED];
Expand Down

0 comments on commit 78b98d9

Please sign in to comment.