Commit 949ab0e1 authored by Artyom Zorin's avatar Artyom Zorin Committed by David Keogh
Browse files

Add option to get the indicator color automatically from the Gtk theme foreground color

parent a7fd43ce
Pipeline #12294 passed with stages
in 2 minutes and 20 seconds
......@@ -294,21 +294,41 @@ void Group::onDraw(cairo_t* cr)
{
int w = gtk_widget_get_allocated_width(mButton);
int h = gtk_widget_get_allocated_height(mButton);
double rgba[4];
if (mSFocus)
if (Settings::indicatorColorFromTheme)
{
rgba[0] = (*Settings::indicatorColor).red;
rgba[1] = (*Settings::indicatorColor).green;
rgba[2] = (*Settings::indicatorColor).blue;
rgba[3] = (*Settings::indicatorColor).alpha;
GtkWidget* menu = gtk_menu_new();
GtkStyleContext* sc = gtk_widget_get_style_context(menu);
GValue gv = G_VALUE_INIT;
gtk_style_context_get_property(sc, "color", GTK_STATE_FLAG_NORMAL, &gv);
GdkRGBA* indicatorColor = (GdkRGBA*)g_value_get_boxed(&gv);
gtk_widget_destroy(menu);
rgba[0] = (*indicatorColor).red;
rgba[1] = (*indicatorColor).green;
rgba[2] = (*indicatorColor).blue;
rgba[3] = (*indicatorColor).alpha;
}
else
{
rgba[0] = (*Settings::inactiveColor).red;
rgba[1] = (*Settings::inactiveColor).green;
rgba[2] = (*Settings::inactiveColor).blue;
rgba[3] = (*Settings::inactiveColor).alpha;
else
{
if (mSFocus)
{
rgba[0] = (*Settings::indicatorColor).red;
rgba[1] = (*Settings::indicatorColor).green;
rgba[2] = (*Settings::indicatorColor).blue;
rgba[3] = (*Settings::indicatorColor).alpha;
}
else
{
rgba[0] = (*Settings::inactiveColor).red;
rgba[1] = (*Settings::inactiveColor).green;
rgba[2] = (*Settings::inactiveColor).blue;
rgba[3] = (*Settings::inactiveColor).alpha;
}
}
const float BAR_WEIGHT = 0.935;
......
......@@ -22,6 +22,7 @@ namespace Settings
State<int> indicatorOrientation;
State<int> indicatorStyle;
State<bool> indicatorColorFromTheme;
State<GdkRGBA*> indicatorColor;
State<GdkRGBA*> inactiveColor;
......@@ -99,6 +100,15 @@ namespace Settings
Dock::drawGroups();
});
indicatorColorFromTheme.setup(g_key_file_get_boolean(mFile, "user", "indicatorColorFromTheme", NULL),
[](bool indicatorColorFromTheme) -> void {
g_key_file_set_boolean(mFile, "user", "indicatorColorFromTheme", indicatorColorFromTheme);
saveFile();
Theme::load();
Dock::drawGroups();
});
gchar* colorString = g_key_file_get_string(mFile, "user", "indicatorColor", NULL);
GdkRGBA* color = (GdkRGBA*)malloc(sizeof(GdkRGBA));
......
......@@ -41,6 +41,7 @@ namespace Settings
extern State<int> indicatorOrientation;
extern State<int> indicatorStyle;
extern State<bool> indicatorColorFromTheme;
extern State<GdkRGBA*> indicatorColor;
extern State<GdkRGBA*> inactiveColor;
......
......@@ -111,6 +111,9 @@ namespace SettingsDialog
}),
dialog);
GObject* customIndicatorColors = gtk_builder_get_object(builder, "g_customIndicatorColors");
gtk_widget_set_sensitive(GTK_WIDGET(customIndicatorColors), !Settings::indicatorColorFromTheme);
GObject* indicatorColor = gtk_builder_get_object(builder, "cp_indicatorColor");
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(indicatorColor), Settings::indicatorColor);
g_signal_connect(indicatorColor, "color-set",
......@@ -133,6 +136,15 @@ namespace SettingsDialog
}),
dialog);
GObject* indicatorColorFromTheme = gtk_builder_get_object(builder, "c_indicatorColorFromTheme");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(indicatorColorFromTheme), Settings::indicatorColorFromTheme);
g_signal_connect(indicatorColorFromTheme, "toggled",
G_CALLBACK(+[](GtkToggleButton* indicatorColorFromTheme, GtkWidget* customIndicatorColors) {
Settings::indicatorColorFromTheme.set(gtk_toggle_button_get_active(indicatorColorFromTheme));
gtk_widget_set_sensitive(GTK_WIDGET(customIndicatorColors), !Settings::indicatorColorFromTheme);
}),
customIndicatorColors);
// =====================================================================
GObject* iconSize = gtk_builder_get_object(builder, "e_iconSize");
......
......@@ -68,6 +68,14 @@ std::string Theme::get_theme_colors()
std::string indicatorColor = gdk_rgba_to_string(Settings::indicatorColor);
std::string inactiveColor = gdk_rgba_to_string(Settings::inactiveColor);
if (Settings::indicatorColorFromTheme)
{
gv = G_VALUE_INIT;
gtk_style_context_get_property(sc, "color", GTK_STATE_FLAG_NORMAL, &gv);
indicatorColor = gdk_rgba_to_string((GdkRGBA*)g_value_get_boxed(&gv));
inactiveColor = gdk_rgba_to_string((GdkRGBA*)g_value_get_boxed(&gv));
}
gtk_widget_destroy(menu);
g_value_unset(&gv);
......
......@@ -264,11 +264,14 @@
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkCheckButton" id="c_indicatorColorFromTheme">
<property name="label" translatable="yes">Get indicator color from theme</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Active indicator:</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">0</property>
......@@ -276,15 +279,65 @@
</packing>
</child>
<child>
<object class="GtkColorButton" id="cp_indicatorColor">
<object class="GtkGrid" id="g_customIndicatorColors">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_alpha">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Active indicator:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="cp_indicatorColor">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_alpha">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Inactive indicator:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="cp_inactiveColor">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_alpha">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
......@@ -327,30 +380,6 @@
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkColorButton" id="cp_inactiveColor">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_alpha">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Inactive indicator:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
</object>
</child>
<child type="label">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment