diff options
Diffstat (limited to 'src/menubar.vala')
-rw-r--r-- | src/menubar.vala | 78 |
1 files changed, 51 insertions, 27 deletions
diff --git a/src/menubar.vala b/src/menubar.vala index f449afa..0ba2903 100644 --- a/src/menubar.vala +++ b/src/menubar.vala @@ -127,6 +127,9 @@ public class MenuBar : Gtk.Grid construct { + // Assure that printf operates in C.UTF-8 locale for float-to-string conversions. + Intl.setlocale(LocaleCategory.NUMERIC, "C.UTF-8"); + this.pMenubar = new Gtk.MenuBar (); this.pMenubar.halign = Gtk.Align.END; this.pMenubar.hexpand = true; @@ -136,27 +139,27 @@ public class MenuBar : Gtk.Grid this.show (); add_style_class (this); Gtk.CssProvider pGridProvider = new Gtk.CssProvider (); - string sBackGround = AGSettings.get_string (AGSettings.KEY_MENUBAR_BGCOLOR); - Gdk.RGBA pBackGround = Gdk.RGBA (); - pBackGround.parse (sBackGround); - int nRed = (int)(pBackGround.red * 255.0); - int nGreen = (int)(pBackGround.green * 255.0); - int nBlue = (int)(pBackGround.blue * 255.0); - double fApha = AGSettings.get_double (AGSettings.KEY_MENUBAR_ALPHA); - - // Assure that printf operates in C.UTF-8 locale for float-to-string conversions. - Intl.setlocale(LocaleCategory.NUMERIC, "C.UTF-8"); + Gtk.StyleContext pGridContext = this.get_style_context (); + Gdk.RGBA pBackground = getBackground (pGridContext, AGSettings.KEY_MENUBAR_BGCOLOR, AGSettings.KEY_MENUBAR_ALPHA); + int nBackgroundRed = (int)(pBackground.red * 255.0); + int nBackgroundGreen = (int)(pBackground.green * 255.0); + int nBackgroundBlue = (int)(pBackground.blue * 255.0); + Gdk.RGBA pShadow = getBackground (pGridContext, AGSettings.KEY_MENUBAR_SHADOW_COLOR, AGSettings.KEY_MENUBAR_SHADOW_ALPHA); + int nShadowRed = (int)(pShadow.red * 255.0); + int nShadowGreen = (int)(pShadow.green * 255.0); + int nShadowBlue = (int)(pShadow.blue * 255.0); + string sBackground = "* {background-color: rgba(%i, %i, %i, %f); border: none; box-shadow: 0px 5px 5px -5px rgba(%i, %i, %i, %f);}".printf (nBackgroundRed, nBackgroundGreen, nBackgroundBlue, pBackground.alpha, nShadowRed, nShadowGreen, nShadowBlue, pShadow.alpha); try { - pGridProvider.load_from_data ("* { background-color: rgba(%i, %i, %i, %f); } *.high_contrast { background-color: #ffffff; color: #000000; text-shadow: none; }".printf (nRed, nGreen, nBlue, fApha), -1); + pGridProvider.load_from_data (sBackground + " *.high_contrast {background-color: #ffffff; color: #000000; text-shadow: none; box-shadow: none;}", -1); } catch (Error pError) { error ("Panic: Failed loading menubar grid colours: %s", pError.message); } - this.get_style_context ().add_provider (pGridProvider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + pGridContext.add_provider (pGridProvider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); Gtk.CssProvider pMenubarProvider = new Gtk.CssProvider (); @@ -171,21 +174,6 @@ public class MenuBar : Gtk.Grid this.pMenubar.get_style_context ().add_provider (pMenubarProvider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - /* Add shadow. */ - var shadow_style = new Gtk.CssProvider (); - - try - { - shadow_style.load_from_data ("* { box-shadow: 0px 0px 5px 5px rgba(%i, %i, %i, %f); }".printf (nRed, nGreen, nBlue, fApha), -1); - } - catch (Error pError) - { - error ("Panic: Failed adding shadow: %s", pError.message); - } - - this.get_style_context ().add_provider (shadow_style, - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - if (AGSettings.get_boolean (AGSettings.KEY_SHOW_HOSTNAME)) { Gtk.Label pLabel = new Gtk.Label (Posix.utsname ().nodename); @@ -222,6 +210,42 @@ public class MenuBar : Gtk.Grid nat = (int)Math.round(greeter.menubar_height - 8); } + private Gdk.RGBA getBackground (Gtk.StyleContext pContext, string sBackgroundKey, string sAlphaKey) + { + string sBackground = AGSettings.get_string (sBackgroundKey); + Gdk.RGBA pBackground; + + if (sBackground != "") + { + pBackground = Gdk.RGBA (); + pBackground.parse (sBackground); + } + else + { + bool bFound = pContext.lookup_color ("osd_bg", out pBackground); + + if (!bFound) + { + bFound = pContext.lookup_color ("dark_bg_color", out pBackground); + + if (!bFound) + { + pBackground = Gdk.RGBA (); + pBackground.parse ("#444444"); + debug ("Failed to retrieve osd_bg and dark_bg_color for %s - falling back to #444444", sBackgroundKey); + } + else + { + debug ("Failed to retrieve osd_bg for %s - falling back to dark_bg_color", sBackgroundKey); + } + } + } + + pBackground.alpha = AGSettings.get_double (sAlphaKey); + + return pBackground; + } + private Indicator.Object? load_indicator_file (string indicator_name) { string dir = Config.INDICATOR_FILE_DIR; |