diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2021-10-12 12:21:47 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2021-10-12 12:21:47 -0300 |
commit | 953631e0827255722a216bd3e7819fdb1f76c4f7 (patch) | |
tree | 06f005fad76f4991fbcb2d3ce0d6c3a7110f1b43 | |
parent | 5fee824c6786ef7dc348c2576dd344b79a69f55c (diff) | |
download | gnome-todo-gbsneto/recoloring.tar.gz |
-rw-r--r-- | src/gui/gtd-omni-area.ui | 2 | ||||
-rw-r--r-- | src/plugins/task-lists-workspace/gtd-sidebar.c | 15 | ||||
-rw-r--r-- | src/plugins/task-lists-workspace/gtd-task-lists-workspace.c | 101 | ||||
-rw-r--r-- | src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui | 3 |
4 files changed, 118 insertions, 3 deletions
diff --git a/src/gui/gtd-omni-area.ui b/src/gui/gtd-omni-area.ui index ea79f1fa..8c4195da 100644 --- a/src/gui/gtd-omni-area.ui +++ b/src/gui/gtd-omni-area.ui @@ -26,7 +26,7 @@ <child> <object class="GtkBox"> <property name="hexpand">true</property> - <property name="css-name">entry</property> + <property name="css-name">button</property> <child> <object class="GtkStack" id="main_stack"> diff --git a/src/plugins/task-lists-workspace/gtd-sidebar.c b/src/plugins/task-lists-workspace/gtd-sidebar.c index 732ff169..2fa18bc9 100644 --- a/src/plugins/task-lists-workspace/gtd-sidebar.c +++ b/src/plugins/task-lists-workspace/gtd-sidebar.c @@ -447,6 +447,11 @@ on_listbox_row_activated_cb (GtkListBox *panels_listbox, "(sv)", gtd_panel_get_panel_name (panel), g_variant_new_maybe (G_VARIANT_TYPE_VARIANT, NULL)); + + gtk_widget_activate_action (GTK_WIDGET (self), + "task-lists-workspace.recolor", + "ms", + NULL); } else if (GTD_IS_SIDEBAR_PROVIDER_ROW (row)) { @@ -454,6 +459,8 @@ on_listbox_row_activated_cb (GtkListBox *panels_listbox, } else if (GTD_IS_SIDEBAR_LIST_ROW (row)) { + g_autofree gchar *color_string = NULL; + g_autoptr(GdkRGBA) color = NULL; GVariantBuilder builder; GtdProvider *provider; GtdTaskList *list; @@ -474,6 +481,14 @@ on_listbox_row_activated_cb (GtkListBox *panels_listbox, "(sv)", "task-list-panel", g_variant_builder_end (&builder)); + + color = gtd_task_list_get_color (list); + if (color) + color_string = gdk_rgba_to_string (color); + gtk_widget_activate_action (GTK_WIDGET (self), + "task-lists-workspace.recolor", + "ms", + color_string); } else if (row == self->archive_row) { diff --git a/src/plugins/task-lists-workspace/gtd-task-lists-workspace.c b/src/plugins/task-lists-workspace/gtd-task-lists-workspace.c index 24d3c66e..e90024e6 100644 --- a/src/plugins/task-lists-workspace/gtd-task-lists-workspace.c +++ b/src/plugins/task-lists-workspace/gtd-task-lists-workspace.c @@ -52,6 +52,8 @@ struct _GtdTaskListsWorkspace PeasExtensionSet *panels_set; GSimpleActionGroup *action_group; + + GtkCssProvider *css_provider; }; static void gtd_workspace_iface_init (GtdWorkspaceInterface *iface); @@ -147,6 +149,76 @@ update_panel_menu (GtdTaskListsWorkspace *self) } } +#define INTENSITY(c) ((c.red) * 0.30 + (c.green) * 0.59 + (c.blue) * 0.11) + +static void +set_color (GtdTaskListsWorkspace *self, + const gchar *color) +{ + g_autofree gchar *formatted_css = NULL; + + if (color) + { + GdkRGBA rgba; + + if (gdk_rgba_parse (&rgba, color)) + { + /* + const gchar *css = + "task-lists-workspace headerbar {" + " color: %1$s;" + " background-color: %2$s;" + "}" + "task-lists-workspace separator," + "task-lists-workspace tasklistview," + "task-lists-workspace taskrow," + "task-lists-workspace newtaskrow," + "task-lists-workspace sidebar {" + " color: %1$s;" + " background-color: %2$s;" + "}"; + */ + /* + const char *css = + "@define-color accent_color %2$s;" + "@define-color accent_bg_color %2$s;" + "@define-color accent_fg_color %1$s;" + ""; + */ + //const gchar *css = + //"task-lists-workspace headerbar.view-headerbar {" + //" color: %1$s;" + //" background-color: %2$s;" + //"}" + //"task-lists-workspace tasklistview," + //"task-lists-workspace taskrow," + //"task-lists-workspace newtaskrow * {" + //" color: %1$s;" + const gchar *css = + "@define-color accent_color %2$s;" + "@define-color accent_bg_color %2$s;" + "@define-color accent_fg_color %1$s;" + "task-lists-workspace headerbar.view-headerbar," + "task-lists-workspace tasklistview {" + " background-color: alpha(%2$s, 0.185);" + "}"; + const gchar *text_color; + + if (INTENSITY (rgba) > 0.5) + text_color = "@dark_5"; + else + text_color = "@light_1"; + + formatted_css = g_strdup_printf (css, text_color, color); + } + } + + if (!formatted_css) + formatted_css = g_strdup (""); + + gtk_css_provider_load_from_data (self->css_provider, formatted_css, -1); +} + /* * Callbacks @@ -196,6 +268,24 @@ on_action_toggle_archive_activated_cb (GSimpleAction *simple, } static void +on_action_recolot_activated_cb (GSimpleAction *simple, + GVariant *parameter, + gpointer user_data) +{ + GtdTaskListsWorkspace *self = GTD_TASK_LISTS_WORKSPACE (user_data); + g_autofree gchar *color = NULL; + + g_message ("%s", g_variant_print (parameter, TRUE)); + + if (parameter) + g_variant_get (parameter, "ms", &color); + + g_message ("Color: %s", color); + + set_color (self, color); +} + +static void on_back_sidebar_button_clicked_cb (GtkButton *button, GtdTaskListsWorkspace *self) { @@ -442,7 +532,7 @@ gtd_task_lists_workspace_class_init (GtdTaskListsWorkspaceClass *klass) * @manager: a #GtdManager * @panel: a #GtdPanel * - * The ::panel-added signal is emmited after a #GtdPanel + * The ::panel-added signal is emitted after a #GtdPanel * is added. */ signals[PANEL_ADDED] = g_signal_new ("panel-added", @@ -461,7 +551,7 @@ gtd_task_lists_workspace_class_init (GtdTaskListsWorkspaceClass *klass) * @manager: a #GtdManager * @panel: a #GtdPanel * - * The ::panel-removed signal is emmited after a #GtdPanel + * The ::panel-removed signal is emitted after a #GtdPanel * is removed from the list. */ signals[PANEL_REMOVED] = g_signal_new ("panel-removed", @@ -482,6 +572,7 @@ gtd_task_lists_workspace_class_init (GtdTaskListsWorkspaceClass *klass) g_type_ensure (GTD_TYPE_SIDEBAR); gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/plugins/task-lists-workspace/gtd-task-lists-workspace.ui"); + gtk_widget_class_set_css_name (widget_class, "task-lists-workspace"); gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, back_button); gtk_widget_class_bind_template_child (widget_class, GtdTaskListsWorkspace, content_box); @@ -510,10 +601,16 @@ gtd_task_lists_workspace_init (GtdTaskListsWorkspace *self) static const GActionEntry entries[] = { { "activate-panel", on_action_activate_panel_activated_cb, "(sv)" }, { "toggle-archive", on_action_toggle_archive_activated_cb, "b" }, + { "recolor", on_action_recolot_activated_cb, "ms" }, }; gtk_widget_init_template (GTK_WIDGET (self)); + self->css_provider = gtk_css_provider_new (); + gtk_style_context_add_provider_for_display (gdk_display_get_default (), + GTK_STYLE_PROVIDER (self->css_provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + self->action_group = g_simple_action_group_new (); g_action_map_add_action_entries (G_ACTION_MAP (self->action_group), entries, diff --git a/src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui b/src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui index d87e9a63..c950490f 100644 --- a/src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui +++ b/src/plugins/task-lists-workspace/gtd-task-lists-workspace.ui @@ -79,6 +79,9 @@ <property name="hexpand">1</property> <property name="show-start-title-buttons" bind-source="leaflet" bind-property="folded" bind-flags="sync-create" /> <property name="show-end-title-buttons">True</property> + <style> + <class name="view-headerbar" /> + </style> <child> <object class="GtkButton" id="back_sidebar_button"> |