Scaling support - scale by screen height (issue #656)

This commit is contained in:
o9000 2018-01-19 21:37:56 +00:00
parent b2b0119f4d
commit 965a2665b0
6 changed files with 28 additions and 2 deletions

View file

@ -246,6 +246,8 @@ void add_entry(char *key, char *value)
/* Background and border */
if (strcmp(key, "scale_relative_to_dpi") == 0) {
ui_scale_dpi_ref = atof(value);
} else if (strcmp(key, "scale_relative_to_screen_height") == 0) {
ui_scale_monitor_size_ref = atof(value);
} else if (strcmp(key, "rounded") == 0) {
// 'rounded' is the first parameter => alloc a new background
if (backgrounds->len > 0) {

View file

@ -80,6 +80,7 @@ GArray *backgrounds;
GArray *gradients;
double ui_scale_dpi_ref;
double ui_scale_monitor_size_ref;
Imlib_Image default_icon;
char *default_font = NULL;
@ -87,6 +88,7 @@ char *default_font = NULL;
void default_panel()
{
ui_scale_dpi_ref = 0;
ui_scale_monitor_size_ref = 0;
panels = NULL;
num_panels = 0;
default_icon = NULL;
@ -225,6 +227,8 @@ void init_panel()
p->scale = server.monitors[p->monitor].dpi / ui_scale_dpi_ref;
else
p->scale = 1;
if (ui_scale_monitor_size_ref > 0)
p->scale *= server.monitors[p->monitor].height / ui_scale_monitor_size_ref;
fprintf(stderr, BLUE "tint2: panel %d uses scale %g " RESET "\n", i + 1, p->scale);
if (!p->area.bg)
p->area.bg = &g_array_index(backgrounds, Background, 0);

View file

@ -96,6 +96,7 @@ extern double tracing_fps_threshold;
extern gboolean debug_frames;
extern gboolean debug_thumbnails;
extern double ui_scale_dpi_ref;
extern double ui_scale_monitor_size_ref;
typedef struct Panel {
Area area;

View file

@ -22,7 +22,7 @@
#include "gradient_gui.h"
#include "strlcat.h"
GtkWidget *scale_relative_to_dpi;
GtkWidget *scale_relative_to_dpi, *scale_relative_to_screen_height;
GtkWidget *panel_width, *panel_height, *panel_margin_x, *panel_margin_y, *panel_padding_x, *panel_padding_y,
*panel_spacing;
GtkWidget *panel_wm_menu, *panel_dock, *panel_autohide, *panel_autohide_show_time, *panel_autohide_hide_time,
@ -614,6 +614,19 @@ void create_panel(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), scale_relative_to_dpi, col, col + 1, row, row + 1, GTK_FILL, 0, 0, 0);
col++;
row++;
col = 2;
label = gtk_label_new(_("Scale relative to screen height"));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_widget_show(label);
gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, 0, 0, 0);
col++;
scale_relative_to_screen_height = gtk_spin_button_new_with_range(0, 9000, 1);
gtk_widget_show(scale_relative_to_screen_height);
gtk_table_attach(GTK_TABLE(table), scale_relative_to_screen_height, col, col + 1, row, row + 1, GTK_FILL, 0, 0, 0);
col++;
change_paragraph(parent);
label = gtk_label_new(_("<b>Appearance</b>"));

View file

@ -9,7 +9,7 @@
#include "../launcher/icon-theme-common.h"
// panel
extern GtkWidget *scale_relative_to_dpi;
extern GtkWidget *scale_relative_to_dpi, *scale_relative_to_screen_height;
extern GtkWidget *panel_width, *panel_height, *panel_margin_x, *panel_margin_y, *panel_padding_x, *panel_padding_y,
*panel_spacing;
extern GtkWidget *panel_wm_menu, *panel_dock, *panel_autohide, *panel_autohide_show_time, *panel_autohide_hide_time,

View file

@ -381,6 +381,9 @@ void config_write_panel(FILE *fp)
fprintf(fp,
"scale_relative_to_dpi = %d\n",
(int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scale_relative_to_dpi)));
fprintf(fp,
"scale_relative_to_screen_height = %d\n",
(int)gtk_spin_button_get_value(GTK_SPIN_BUTTON(scale_relative_to_screen_height)));
fprintf(fp, "\n");
}
@ -1115,6 +1118,9 @@ void add_entry(char *key, char *value)
if (strcmp(key, "scale_relative_to_dpi") == 0) {
extract_values(value, &value1, &value2, &value3);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(scale_relative_to_dpi), atoi(value1));
} else if (strcmp(key, "scale_relative_to_screen_height") == 0) {
extract_values(value, &value1, &value2, &value3);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(scale_relative_to_screen_height), atoi(value1));
} else if (strcmp(key, "gradient") == 0) {
finalize_gradient();
GradientConfigType t;