summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/tab.vala13
-rw-r--r--core/tally.vala20
-rw-r--r--extensions/colorful-tabs.plugin.in6
-rw-r--r--extensions/colorful-tabs.vala58
-rw-r--r--po/POTFILES.in2
5 files changed, 93 insertions, 6 deletions
diff --git a/core/tab.vala b/core/tab.vala
index 63200bd0..a598399a 100644
--- a/core/tab.vala
+++ b/core/tab.vala
@@ -13,6 +13,7 @@ namespace Midori {
public interface TabActivatable : Peas.ExtensionBase {
public abstract Tab tab { owned get; set; }
public abstract void activate ();
+ public signal void deactivate ();
}
[GtkTemplate (ui = "/ui/tab.ui")]
@@ -24,6 +25,7 @@ namespace Midori {
public DatabaseItem? item { get; protected set; default = null; }
public string display_uri { get; protected set; }
public string display_title { get; protected set; }
+ public string? color { get; set; default = null; }
public bool pinned { get; set; }
public bool secure { get; protected set; }
public string link_uri { get; protected set; }
@@ -75,10 +77,12 @@ namespace Midori {
}
item = new DatabaseItem (display_uri, null, 0);
+ var extensions = Plugins.get_default ().plug<TabActivatable> ("tab", this);
+ extensions.extension_added.connect ((info, extension) => ((TabActivatable)extension).activate ());
+ extensions.extension_removed.connect ((info, extension) => ((TabActivatable)extension).deactivate ());
+ extensions.foreach ((extensions, info, extension) => { extensions.extension_added (info, extension); });
+
if (pinned) {
- var extensions = Plugins.get_default ().plug<TabActivatable> ("tab", this);
- extensions.extension_added.connect ((info, extension) => ((TabActivatable)extension).activate ());
- extensions.foreach ((extensions, info, extension) => { extensions.extension_added (info, extension); });
load_uri (display_uri);
} else {
load_uri_delayed.begin (uri, title);
@@ -102,9 +106,6 @@ namespace Midori {
public override bool focus_in_event (Gdk.EventFocus event) {
// Delayed load on focus
if (display_uri != uri) {
- var extensions = Plugins.get_default ().plug<TabActivatable> ("tab", this);
- extensions.extension_added.connect ((info, extension) => ((TabActivatable)extension).activate ());
- extensions.foreach ((extensions, info, extension) => { extensions.extension_added (info, extension); });
load_uri (display_uri);
}
return true;
diff --git a/core/tally.vala b/core/tally.vala
index 2585ab30..879f684c 100644
--- a/core/tally.vala
+++ b/core/tally.vala
@@ -56,6 +56,8 @@ namespace Midori {
bind_property ("title", this, "tooltip-text");
tab.bind_property ("visible", this, "visible");
close.clicked.connect (() => { tab.try_close (); });
+ tab.notify["color"].connect (apply_color);
+ apply_color ();
tab.notify["is-loading"].connect ((pspec) => {
favicon.visible = !tab.is_loading;
spinner.visible = !favicon.visible;
@@ -74,6 +76,24 @@ namespace Midori {
update_close_position ();
});
}
+
+ void apply_color () {
+ Gdk.Color? background_color = null;
+ if (tab.color != null) {
+ Gdk.Color.parse (tab.color, out background_color);
+ // Ensure high contrast by enforcing black/ white foreground based on Y(UV)
+ float brightness = 0.299f * (float)background_color.red / 255f
+ + 0.587f * (float)background_color.green / 255f
+ + 0.114f * (float)background_color.blue / 255f;
+ Gdk.Color foreground_color;
+ Gdk.Color.parse (brightness < 128 ? "white" : "black", out foreground_color);
+ modify_fg (Gtk.StateType.NORMAL, foreground_color);
+ modify_fg (Gtk.StateType.ACTIVE, foreground_color);
+ }
+ modify_bg (Gtk.StateType.NORMAL, background_color);
+ modify_bg (Gtk.StateType.ACTIVE, background_color);
+ }
+
void update_close_position () {
string layout = Gtk.Settings.get_default ().gtk_decoration_layout;
var box = (Gtk.Box)close.parent;
diff --git a/extensions/colorful-tabs.plugin.in b/extensions/colorful-tabs.plugin.in
new file mode 100644
index 00000000..081e8646
--- /dev/null
+++ b/extensions/colorful-tabs.plugin.in
@@ -0,0 +1,6 @@
+[Plugin]
+Module=colorful-tabs
+IAge=3
+Icon=preferences-color-symbolic
+_Name=Colorful Tabs
+_Description=Tint each tab distinctly
diff --git a/extensions/colorful-tabs.vala b/extensions/colorful-tabs.vala
new file mode 100644
index 00000000..0635e37a
--- /dev/null
+++ b/extensions/colorful-tabs.vala
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2009-2018 Christian Dywan <christian@twotoasts.de>
+ Copyright (C) 2010 Samuel Creshal <creshal@arcor.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+namespace ColorfulTabs {
+ public class Tint : Peas.ExtensionBase, Midori.TabActivatable {
+ public Midori.Tab tab { owned get; set; }
+
+ public void activate () {
+ tab.notify["display-uri"].connect (apply_tint);
+ apply_tint ();
+ deactivate.connect (() => {
+ tab.notify["display-uri"].disconnect (apply_tint);
+ tab.color = null;
+ });
+ }
+
+ void apply_tint () {
+ if ("://" in tab.display_uri) {
+ Gdk.Color color;
+ // Hash the hostname without the protocol or path
+ string hostname = tab.display_uri.chr (-1, '/').offset (2).split ("/")[0];
+ string hash = Checksum.compute_for_string (ChecksumType.MD5, hostname, 1);
+ Gdk.Color.parse ("#" + hash.substring (0, 6), out color);
+ // Adjust background brightness
+ uint16 grey = 137 * 255;
+ uint16 adjustment = 78 * 255;
+ uint16 blue = 39 * 255;
+ uint16 extra = 19 * 255;
+ if (color.red < grey && color.green < grey && color.blue < grey) {
+ color.red += adjustment;
+ color.green += adjustment;
+ color.blue += adjustment;
+ }
+ color.red = color.red < blue ? extra : color.red - extra;
+ color.blue = color.blue < blue ? extra : color.blue - extra;
+ color.green = color.green < blue ? extra : color.green - extra;
+ tab.color = color.to_string ();
+ } else {
+ tab.color = null;
+ }
+ }
+ }
+}
+
+[ModuleInit]
+public void peas_register_types(TypeModule module) {
+ ((Peas.ObjectModule)module).register_extension_type (
+ typeof (Midori.TabActivatable), typeof (ColorfulTabs.Tint));
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d757ffe4..7ca30d29 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -30,6 +30,8 @@ extensions/status-clock.plugin.in
extensions/status-clock.vala
extensions/statusbar-features.in
extensions/statusbar-features.vala
+extensions/colorful-tabs.plugin.in
+extensions/colorful-tabs.vala
ui/bookmarks-button.ui
ui/browser.ui
ui/clear-private-data.ui