Skip to content

Commit

Permalink
[window-buttons] Fix for blurry icons, and hidpi support
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfin authored and flexiondotorg committed Mar 4, 2021
1 parent e70c850 commit 8294ad2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions window-buttons-applet/window-button.vala
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ namespace WindowWidgets{
}

if(icon != null){
icon = icon.scale_simple(_icon_size, _icon_size, Gdk.InterpType.HYPER);
button_image.set_from_pixbuf(icon);
Cairo.Surface surface = Gdk.cairo_surface_create_from_pixbuf(icon, this.get_scale_factor(), null);
button_image.set_from_surface(surface);
}

}
Expand Down
39 changes: 17 additions & 22 deletions window-buttons-applet/window-buttons-applet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,29 @@ namespace WindowButtonsApplet{
protected WindowButton MAXIMIZE = new WindowButton(WindowButtonType.MAXIMIZE);

protected EnabledButtons enabled_buttons = EnabledButtons();
protected int icon_size;

private Gtk.StyleContext* applet_style_context;

// Constructor

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

this.set_homogeneous(true);

this.applet_style_context = applet_style_context;
this.applet_style_context = applet.get_style_context();
this.set_size(applet.get_size());

this.change_layout();
this.change_theme();
this.change_spacing();
this.change_behaviour();

this.marco_gsettings.changed["theme"].connect(this.change_theme);
this.gsettings.changed["spacing"].connect(this.change_spacing);
this.marco_gsettings.changed["button_layout"].connect(this.change_layout);
this.gsettings.changed["spacing"].connect(this.change_spacing);
this.gsettings.changed["padding"].connect( (key) => { this.change_size(applet.get_size()); } );

Wnck.Screen.get_default().active_window_changed.connect(this.reload);

Expand Down Expand Up @@ -164,38 +167,33 @@ namespace WindowButtonsApplet{

Gdk.RGBA fg_color = applet_style_context->get_color(Gtk.StateFlags.ACTIVE);

WindowButtonsTheme theme = new WindowButtonsTheme(theme_name, fg_color);
WindowButtonsTheme theme = new WindowButtonsTheme(theme_name, fg_color, this.icon_size, this.get_scale_factor());

CLOSE.theme = theme;
CLOSE.icon_size = this.icon_size;
if(enabled_buttons.close)
CLOSE.update(true);

MINIMIZE.theme = theme;
MINIMIZE.icon_size = this.icon_size;
if(enabled_buttons.minimize)
MINIMIZE.update(true);

MAXIMIZE.theme = theme;
MAXIMIZE.icon_size = this.icon_size;
if(enabled_buttons.maximize)
MAXIMIZE.update(true);

}

public void change_size(int size){
public void set_size(int size){
int padding = gsettings.get_int("padding");
size -= padding;

CLOSE.icon_size = size;
if(this.enabled_buttons.close == true)
CLOSE.update();

MINIMIZE.icon_size = size;
if(this.enabled_buttons.minimize == true)
MINIMIZE.update();

MAXIMIZE.icon_size = size;
if(this.enabled_buttons.maximize == true)
MAXIMIZE.update();
this.icon_size = size - padding;
}

public void change_size(int size){
this.set_size(size);
this.change_theme();
}

public void change_orient(int orient){
Expand Down Expand Up @@ -302,13 +300,12 @@ 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, applet.get_style_context());
var widget_container = new ButtonsApplet(Gtk.Orientation.HORIZONTAL, applet);

widget_container.monitor = applet.get_parent_window().get_screen().get_display().get_monitor_at_window(applet.get_parent_window());

widget_container.show();
widget_container.change_orient(applet.get_orient());
widget_container.change_size(applet.get_size());

Gtk.ActionGroup action_group = new Gtk.ActionGroup("action_group");

Expand All @@ -329,8 +326,6 @@ namespace WindowButtonsApplet{

widget_container.gsettings.changed["use-marco-layout"].connect(widget_container.change_layout);
widget_container.gsettings.changed["buttons-layout"].connect(widget_container.change_layout);
widget_container.gsettings.changed["spacing"].connect( (key) => { widget_container.change_size(applet.get_size()); } );
widget_container.gsettings.changed["padding"].connect( (key) => { widget_container.change_size(applet.get_size()); } );
widget_container.gsettings.changed["behaviour"].connect( () => { widget_container.change_behaviour(); widget_container.reload(); } );
applet.setup_menu(menu,action_group);

Expand Down
11 changes: 8 additions & 3 deletions window-buttons-applet/window-buttons-theme.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ namespace WindowWidgets {
public class WindowButtonsTheme {

private string _theme_name;
private int _icon_size;
private int _scale_factor;
private Gdk.Pixbuf[,,] _pixbufs;
private string[] _extensions;
private string[] _prefixes;
private string[,] _type_names;
private string[,] _state_names;
private string[,] _action_names;

public WindowButtonsTheme(string name, Gdk.RGBA fg_color){
public WindowButtonsTheme(string name, Gdk.RGBA fg_color, int icon_size, int scale_factor){
_pixbufs = new Gdk.Pixbuf[
IconType.TYPES,
IconState.STATES,
Expand All @@ -18,7 +20,10 @@ namespace WindowWidgets {

_theme_name = name;

_extensions = {"png", "svg"};
_icon_size = icon_size;
_scale_factor = scale_factor;

_extensions = {"svg", "png"};

_prefixes = {null, "button", "icon"};

Expand Down Expand Up @@ -121,7 +126,7 @@ namespace WindowWidgets {
string file_path = find_icon_filepath(paths, icon_names);
if( file_path != null ){
try {
return new Gdk.Pixbuf.from_file(file_path);
return new Gdk.Pixbuf.from_file_at_size(file_path, this._icon_size * this._scale_factor, this._icon_size * this._scale_factor);
} catch (GLib.Error e){
stdout.printf("Error: %s\n", e.message);
}
Expand Down

0 comments on commit 8294ad2

Please sign in to comment.