Skip to content

Commit

Permalink
[window-buttons] Detect which fallback theme to use
Browse files Browse the repository at this point in the history
...according to color of user's theme
  • Loading branch information
gabrielfin authored and flexiondotorg committed Jun 18, 2019
1 parent 94bc1ee commit 7d71d88
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 7 deletions.
File renamed without changes
Binary file added data/pixmaps/mate-window-applets/White/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/pixmaps/mate-window-applets/White/maximize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/pixmaps/mate-window-applets/White/minimize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions window-buttons-applet/window-buttons-applet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ namespace WindowButtonsApplet{

protected EnabledButtons enabled_buttons = EnabledButtons();

private Gtk.StyleContext* applet_style_context;

// Constructor

public ButtonsApplet(Gtk.Orientation orient){
public ButtonsApplet(Gtk.Orientation orient, Gtk.StyleContext* applet_style_context){
Object(orientation: orient);

this.set_homogeneous(true);

this.applet_style_context = applet_style_context;

this.change_layout();
this.change_theme();
this.change_spacing();
Expand Down Expand Up @@ -150,7 +154,9 @@ namespace WindowButtonsApplet{
public void change_theme(){
string theme_name = marco_gsettings.get_string("theme");

WindowButtonsTheme theme = new WindowButtonsTheme(theme_name);
Gdk.RGBA fg_color = applet_style_context->get_color(Gtk.StateFlags.ACTIVE);

WindowButtonsTheme theme = new WindowButtonsTheme(theme_name, fg_color);

CLOSE.theme = theme;
if(enabled_buttons.close)
Expand Down Expand Up @@ -251,7 +257,7 @@ namespace WindowButtonsApplet{
Gtk.Window settings = builder.get_object("Settings") as Gtk.Window;
Gtk.Window about = builder.get_object("About") as Gtk.Window;

var widget_container = new ButtonsApplet(Gtk.Orientation.HORIZONTAL);
var widget_container = new ButtonsApplet(Gtk.Orientation.HORIZONTAL, applet.get_style_context());

widget_container.show();
widget_container.change_orient(applet.get_orient());
Expand Down
15 changes: 11 additions & 4 deletions window-buttons-applet/window-buttons-theme.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace WindowWidgets {
private string[,] _state_names;
private string[,] _action_names;

public WindowButtonsTheme(string name){
public WindowButtonsTheme(string name, Gdk.RGBA fg_color){
_pixbufs = new Gdk.Pixbuf[
IconType.TYPES,
IconState.STATES,
Expand Down Expand Up @@ -47,7 +47,7 @@ namespace WindowWidgets {
if( _pixbufs[IconType.CLOSE, IconState.FOCUSED, IconAction.NORMAL] == null
|| _pixbufs[IconType.MINIMIZE, IconState.FOCUSED, IconAction.NORMAL] == null
|| _pixbufs[IconType.MAXIMIZE, IconState.FOCUSED, IconAction.NORMAL] == null ) {
load_fallback_icons();
load_fallback_icons(fg_color);
}
}

Expand Down Expand Up @@ -158,8 +158,15 @@ namespace WindowWidgets {
return _pixbufs[type, state, action];
}

private void load_fallback_icons(){
string[] paths = {"/usr/share/pixmaps/mate-window-applets"};
private void load_fallback_icons(Gdk.RGBA fg_color){
double lum = 0.299*fg_color.red + 0.587*fg_color.green + 0.114*fg_color.blue;
string theme;
if(lum > 0.5)
theme = "White";
else
theme = "Black";

string[] paths = {"/usr/share/pixmaps/mate-window-applets/" + theme};
load_icons(paths);
}

Expand Down

0 comments on commit 7d71d88

Please sign in to comment.