ginggs / gelemental

periodic table for GNOME
GNU General Public License v3.0
4 stars 7 forks source link

Buttons are not colored within groups on Linux Mint 20.2 #3

Closed artisticfox8 closed 3 years ago

artisticfox8 commented 3 years ago

By using deafult buttons for the elements, desktop controls themes like Mint-y will affect the buttons colorization and make the program less useful. Attached is screenshot of what the program looks on my system vs what it should look like. Screenshot at 2021-08-03 22-42-27 Screenshot at 2021-08-03 22-43-57

artisticfox8 commented 3 years ago

I'm using gElemental 2.0.0 installed from Linux Mint Software Manager

artisticfox8 commented 3 years ago

When selecting color by element, this is the result: coloring bug

artisticfox8 commented 3 years ago

Hello, I dowloaded Debian KDE edition (Debian Gnome torrent didn't start the install for some reason) and the bug remains. Screenshots from Debian GNU/Linux 10 (buster) KDE edition from a live USB (all settings default). Gelemental fresh install color by elemental gelemental kde] color by elemental gelemental kde

artisticfox8 commented 3 years ago

Found this: If you are affected by a button colour issue and your GTK+ theme (shown in the Controls tab of the GNOME Theme Preferences) is not listed here, please report it to me.

So my gtk+ theme is Mint-Y-Red and Mint-Y-Dark-Red

artisticfox8 commented 3 years ago

But I think it will be the same for all Mint themes. Why is there a themes blacklist at all? I mean doesn't every theme break the colored buttons?

ginggs commented 3 years ago

Found this: If you are affected by a button colour issue and your GTK+ theme (shown in the Controls tab of the GNOME Theme Preferences) is not listed here, please report it to me.

This is really helpful, thanks! This text is from: https://github.com/ginggs/gelemental/blob/master/TODO#L14-L18

I found the list of themes needing the workaround here: https://github.com/ginggs/gelemental/blob/master/src/buttons.cc#L104-L111

I did some testing, and found on Ubuntu 20.04 that the Ambiance, Radiance and HighContrast themes are all OK, but Adwaita needs the workaround, and on Ubuntu 21.04, Yaru, Yaru-light and Yaru-dark all need the workaround.

ginggs commented 3 years ago

But I think it will be the same for all Mint themes.

Would you please test them? You can use the following command to get the exact name that needs to be added:

gsettings get org.gnome.desktop.interface gtk-theme

You'll need to close and re-open gelemental after changing the theme.

Why is there a themes blacklist at all? I mean doesn't every theme break the colored buttons?

This is explained in TODO.

artisticfox8 commented 3 years ago

I will test them when I get to my computer. However, I've got an idea. How about making a menu entry as a way for normal users to report their theme? I still don't understand, why don't you override all themes?

artisticfox8 commented 3 years ago

But I think it will be the same for all Mint themes.

Would you please test them? You can use the following command to get the exact name that needs to be added:

gsettings get org.gnome.desktop.interface gtk-theme

You'll need to close and re-open gelemental after changing the theme.

Why is there a themes blacklist at all? I mean doesn't every theme break the colored buttons?

This is explained in TODO.

I use MATE so the command won't work. Here is the list of themes that need to be added to the list:

Mint-X, Mint-X-Aqua, Mint-X-Blue, Mint-X-Brown, Mint-X-Grey, Mint-X-Orange, Mint-X-Pink, Mint-X-Purple, Mint-X-Red, Mint-X-Sand, Mint-X-Teal, Mint-Y, Mint-Y-Aqua, Mint-Y-Blue, Mint-Y-Brown, Mint-Y-Dark, Mint-Y-Red, Mint-Y-Dark-Red, Mint-Y-Dark-Aqua, Mint-Y-Dark-Blue, Mint-Y-Dark-Brown, Mint-Y-Darker-Aqua, Mint-Y-Darker-Blue, Mint-Y-Darker-Brown, Mint-Y-Darker-Grey, Mint-Y-Darker-Orange, Mint-Y-Darker-Pink, Mint-Y-Darker-Purple, Mint-Y-Darker-Red, Mint-Y-Darker-Sand, Mint-Y-Darker-Teal, Mint-Y-Dark-Grey, Mint-Y-Dark-Orange, Mint-Y-Dark-Pink, Mint-Y-Dark-Purple, Mint-Y-Dark-Sand, Mint-Y-Dark-Teal, Mint-Y-Grey, Mint-Y-Orange, Mint-Y-Pink, Mint-Y-Purple, Mint-Y-Sand, Mint-Y-Teal

I've tested each theme with latest gelemental built from source from github. I've closed the program before applying each theme. With each of the themes above, the View - Color by options were broken. The list above are default themes in Linux Mint 20.2 with the MATE desktop environment.

artisticfox8 commented 3 years ago

After I added these themes it works! working theme2 working dark theme

artisticfox8 commented 3 years ago

Here is the file I modified (pasted all themes mentioned above into it)

/*
 * This file is part of gElemental, a periodic table viewer with detailed
 * information on elements.
 *
 * Copyright (C) 2006-2007 Kevin Daughtridge <kevin@kdau.com>
 * Copyright (C) 2003 Jonas Frantz <jonas.frantz@welho.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "private.hh"
#include <libelemental/table.hh>
#include "misc.hh"
#include "dialogs.hh"
#include "buttons.hh"

#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <gtkmm/settings.h>

namespace gElemental {

//******************************************************************************
// class ColorButton

void
ColorButton::set_color (const color_value_base& value)
{
    Gdk::Color color = allocate (value.get_color ());

    if (is_force_needed ())
    {
        RefPtr<Gtk::Style> style = Gtk::Style::create ();
        style->set_bg (Gtk::STATE_NORMAL, color);
        style->set_bg (Gtk::STATE_ACTIVE, color);
        style->set_bg (Gtk::STATE_PRELIGHT, color);
        set_style (style);
    }
    else
    {
        modify_bg (Gtk::STATE_NORMAL, color);
        modify_bg (Gtk::STATE_ACTIVE, color);
        modify_bg (Gtk::STATE_PRELIGHT, color);
    }

    if (Gtk::Widget *child = get_child ())
        set_fgcolor (*child, value);
}

void
ColorButton::unset_color ()
{
    if (is_force_needed ())
        unset_style ();
    else
    {
        unset_bg (Gtk::STATE_NORMAL);
        unset_bg (Gtk::STATE_ACTIVE);
        unset_bg (Gtk::STATE_PRELIGHT);
    }

    if (Gtk::Widget *child = get_child ())
        unset_fgcolor (*child);
}

void
ColorButton::set_fgcolor (Gtk::Widget& child, const color_value_base& value)
{
    Gdk::Color compliment = allocate (value.get_color ().get_compliment ());

    child.modify_fg (Gtk::STATE_NORMAL, compliment);
    child.modify_fg (Gtk::STATE_ACTIVE, compliment);
    child.modify_fg (Gtk::STATE_PRELIGHT, compliment);
}

void
ColorButton::unset_fgcolor (Gtk::Widget& child)
{
    child.unset_fg (Gtk::STATE_NORMAL);
    child.unset_fg (Gtk::STATE_ACTIVE);
    child.unset_fg (Gtk::STATE_PRELIGHT);
}

bool
ColorButton::is_force_needed ()
{
    static const char *OFFENDING_THEMES[] = 
    {
        "Amaranth",
        "Lush",
        "Nuvola",
        "New Wave",
"Mint-X", "Mint-X-Aqua", "Mint-X-Blue", "Mint-X-Brown", "Mint-X-Grey", "Mint-X-Orange", "Mint-X-Pink", "Mint-X-Purple", "Mint-X-Red", "Mint-X-Sand", "Mint-X-Teal", "Mint-Y", "Mint-Y-Aqua", "Mint-Y-Blue", "Mint-Y-Brown", "Mint-Y-Dark", "Mint-Y-Red", "Mint-Y-Dark-Red", "Mint-Y-Dark-Aqua", "Mint-Y-Dark-Blue", "Mint-Y-Dark-Brown", "Mint-Y-Darker-Aqua", "Mint-Y-Darker-Blue", "Mint-Y-Darker-Brown", "Mint-Y-Darker-Grey", "Mint-Y-Darker-Orange", "Mint-Y-Darker-Pink", "Mint-Y-Darker-Purple", "Mint-Y-Darker-Red", "Mint-Y-Darker-Sand", "Mint-Y-Darker-Teal", "Mint-Y-Dark-Grey", "Mint-Y-Dark-Orange", "Mint-Y-Dark-Pink", "Mint-Y-Dark-Purple", "Mint-Y-Dark-Sand", "Mint-Y-Dark-Teal", "Mint-Y-Grey", "Mint-Y-Orange", "Mint-Y-Pink", "Mint-Y-Purple", "Mint-Y-Sand", "Mint-Y-Teal",
        NULL
    };

    static bool tested = false;
    static bool needed = false;

    if (!tested)
    {
        ustring theme = Gtk::Settings::get_default ()->
            property_gtk_theme_name ().get_value ();

        for (const char **test = OFFENDING_THEMES; *test; ++test)
            if (theme == *test)
            {
                needed = true;
                break;
            }

        tested = true;
    }

    return needed;
}

//******************************************************************************
// class ElementButton

ElementButton::ElementButton (const Element& el_, Gtk::Tooltips& tips)
:   el (el_), group (el.get_property (P_GROUP)),
    period (el.get_property (P_PERIOD))
{
    set_label (el.symbol);

    tips.set_tip (*this, compose::ucompose (_("%1 (%2)"),
        el.get_property (P_NAME).get_string (), el.number));
}

int
ElementButton::get_x_pos () const
{
    switch (period.value)
    {
    case 6:
        if (!group.has_value () || group.value == 3)
            return 3 + (el.number - 57) - 1;
    case 7:
        if (!group.has_value () || group.value == 3)
            return 3 + (el.number - 89) - 1;
    default:
        return group.value - 1;
    }
}

int
ElementButton::get_y_pos () const
{
    switch (period.value)
    {
    case 6:
        if (!group.has_value () || group.value == 3)
            return 9 - 1;
    case 7:
        if (!group.has_value () || group.value == 3)
            return 10 - 1;
    default:
        return period.value - 1;
    }
}

void
ElementButton::show_properties ()
{
    ElementDialog *dialog = new ElementDialog (el);
    if cast (get_toplevel (), Gtk::Window, top)
        dialog->set_transient_for (*top);
    dialog->present ();
}

void
ElementButton::set_color_by_property (const PropertyBase* property,
    double temperature, bool logarithmic)
{
    if (property == NULL)
        unset_color ();

    else if (property == &P_PHASE)
        set_color (el.get_phase (temperature));

    else if cast (property, const FloatProperty, float_prop)
    {
        const Float &float_value = el.get_property (*float_prop);

        if (float_value.has_value () && float_prop->is_scale_valid ())
            set_color (ColorValue
                (float_prop->get_scale_position (float_value, logarithmic)));

        else
            set_color (ColorValue ());
    }

    else if cast (&el.get_property_base (*property),
        const color_value_base, color_value)
        set_color (*color_value);

    else
        unset_color ();
}

void
ElementButton::on_clicked ()
{
    ColorButton::on_clicked ();
    show_properties ();
}

//******************************************************************************
// class ElementIdentity

ElementIdentity::ElementIdentity (const Element& el)
{
    property_can_focus ().set_value (false);
    set_focus_on_click (false);
    set_size_request (-1, 50);

    const ColorValue& color = el.get_property (P_COLOR);
    set_color (color);

    push_composite_child ();

    Gtk::VBox *square = new Gtk::VBox (false, 6);
    square->set_border_width (6);
    add (*Gtk::manage (square));

    Gtk::Label *number = new Gtk::Label ();
    set_fgcolor (*number, color);
    number->set_markup ("<b>" + compose::ucompose1 (el.number) + "</b>");
    square->pack_start (*Gtk::manage (number), Gtk::PACK_EXPAND_PADDING);

    Gtk::Label *symbol = new Gtk::Label ();
    set_fgcolor (*symbol, color);
    symbol->set_markup ("<big><big><b>" + el.symbol + "</b></big></big>");
    square->pack_start (*Gtk::manage (symbol), Gtk::PACK_EXPAND_PADDING);

    pop_composite_child ();
    show_all_children ();
}

//******************************************************************************
// class LegendButton

LegendButton::LegendButton (const color_value_base& value)
{
    if (!CAST (&value, const ColorValue))
        set_label (value.get_string ());
    set_color (value);
    property_can_focus ().set_value (false);
    set_focus_on_click (false);
}

} // namespace gElemental
ginggs commented 3 years ago

Would you please make a pull request with your changes? Please keep the original formatting (one theme per line).

If you are not familiar with git, you can do this from the github web interface: https://docs.github.com/en/github/managing-files-in-a-repository/managing-files-on-github/editing-files-in-another-users-repository

artisticfox8 commented 3 years ago

Would you please make a pull request with your changes? Please keep the original formatting (one theme per line).

If you are not familiar with git, you can do this from the github web interface: https://docs.github.com/en/github/managing-files-in-a-repository/managing-files-on-github/editing-files-in-another-users-repository

It doesn't work: Screenshot 2021-08-29 at 22-52-21 Editing gelemental buttons cc at master · ginggs gelemental

artisticfox8 commented 3 years ago

Would you please make a pull request with your changes? Please keep the original formatting (one theme per line).

If you are not familiar with git, you can do this from the github web interface: https://docs.github.com/en/github/managing-files-in-a-repository/managing-files-on-github/editing-files-in-another-users-repository

I also added two KDE themes