Add dpi settings

This commit is contained in:
daleclack 2024-08-15 18:24:27 +08:00
parent cfefc444de
commit 71ea347892
2 changed files with 82 additions and 15 deletions

View File

@ -149,7 +149,14 @@
</object> </object>
</child> </child>
<child> <child>
<placeholder/> <object class="GtkBox" id="dpi_box">
<property name="orientation">horizontal</property>
<layout>
<property name="column">1</property>
<property name="row">4</property>
<property name="column-span">3</property>
</layout>
</object>
</child> </child>
<child> <child>
<placeholder/> <placeholder/>

View File

@ -18,14 +18,16 @@ struct _MyPrefs
MyTitleBar *title_bar; MyTitleBar *title_bar;
GtkBuilder *prefs_builder; GtkBuilder *prefs_builder;
GtkWidget *background, *back_page; GtkWidget *background, *back_page;
GtkWidget *stack_box, *combo_box; GtkWidget *stack_box, *combo_box, *dpi_box;
// Widget for window size config // Widget for window size config
GtkWidget *label_size; GtkWidget *label_size, *label_dpi;
GtkWidget *sizes_drop; GtkWidget *sizes_drop, *dpi_drop;
GtkWidget *radio_default, *radio_custom; GtkWidget *radio_default, *radio_custom;
GtkWidget *spin_width, *spin_height; GtkWidget *spin_width, *spin_height;
GtkWidget *btnGet, *btnapply; GtkWidget *btnGet, *btnapply;
float dpi_values[7] = {1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5};
int dpi_set = 0;
// Widget for dock position and mode // Widget for dock position and mode
GtkWidget *mode_check; GtkWidget *mode_check;
@ -317,7 +319,6 @@ static void pics_view_init(MyPrefs *self)
self->factory_pics_string); self->factory_pics_string);
gtk_column_view_append_column(GTK_COLUMN_VIEW(self->images_view), gtk_column_view_append_column(GTK_COLUMN_VIEW(self->images_view),
self->pics_string_column); self->pics_string_column);
} }
static void update_resource_image(MyPrefs *prefs, const char *resource_id) static void update_resource_image(MyPrefs *prefs, const char *resource_id)
@ -384,15 +385,28 @@ static void my_prefs_load_config(MyPrefs *self)
std::string back_filename; std::string back_filename;
// Load data from json // Load data from json
json data = json::parse(json_file); json data = json::parse(json_file);
self->width = data["width"];
self->height = data["height"]; // Check whether json config contains vaild
self->current_folder_index = data["folder_index"]; if (data.contains("width")
self->current_image_index = data["image_index"]; && data.contains("height")
self->dock_pos = data["position"]; && data.contains("folder_index")
back_filename = data["background"]; && data.contains("image_index")
str_vec tmp_vec = data["background_folders"]; && data.contains("position")
strncpy(self->image_file_name, back_filename.c_str(), PATH_MAX); && data.contains("background")
self->back_vec = tmp_vec; && data.contains("background_folders")
&& data.contains("dpi_set"))
{
self->width = data["width"];
self->height = data["height"];
self->current_folder_index = data["folder_index"];
self->current_image_index = data["image_index"];
self->dock_pos = data["position"];
back_filename = data["background"];
str_vec tmp_vec = data["background_folders"];
strncpy(self->image_file_name, back_filename.c_str(), PATH_MAX);
self->back_vec = tmp_vec;
self->dpi_set = data["dpi_set"];
}
} }
else else
{ {
@ -403,11 +417,11 @@ static void my_prefs_load_config(MyPrefs *self)
self->current_image_index = 3; self->current_image_index = 3;
self->dock_pos = DockPos::Pos_Left; self->dock_pos = DockPos::Pos_Left;
strncpy(self->image_file_name, ":4", PATH_MAX); strncpy(self->image_file_name, ":4", PATH_MAX);
self->dpi_set = 1;
} }
json_file.close(); json_file.close();
// Update default selection // Update default selection
} }
// Save configs // Save configs
@ -464,6 +478,7 @@ static void my_prefs_save_config(MyPrefs *self)
{ {
"background_folders": [], "background_folders": [],
"background":"", "background":"",
"dpi_set": 1.0,
"folder_index": 0, "folder_index": 0,
"height": 576, "height": 576,
"image_index": 0, "image_index": 0,
@ -475,6 +490,7 @@ static void my_prefs_save_config(MyPrefs *self)
// g_print("%s", self->image_file_name); // g_print("%s", self->image_file_name);
data["folder_index"] = folder_index; data["folder_index"] = folder_index;
data["background"] = std::string(self->image_file_name); data["background"] = std::string(self->image_file_name);
data["dpi_set"] = self->dpi_set;
data["height"] = self->height; data["height"] = self->height;
data["image_index"] = image_index; data["image_index"] = image_index;
data["panel_mode"] = self->panel_mode; data["panel_mode"] = self->panel_mode;
@ -771,6 +787,32 @@ static void btnapply_clicked(GtkWidget *widget, MyPrefs *self)
self->width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(self->spin_width)); self->width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(self->spin_width));
self->height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(self->spin_height)); self->height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(self->spin_height));
} }
// Get dpi config
self->dpi_set = gtk_drop_down_get_selected(GTK_DROP_DOWN(self->dpi_drop));
// switch (dpi_index){
// case 0:
// self->curr_dpi_value = 1.0;
// break;
// case 1:
// self->curr_dpi_value = 1.25;
// break;
// case 2:
// self->curr_dpi_value = 1.5;
// break;
// case 3:
// self->curr_dpi_value = 1.75;
// break;
// case 4:
// self->curr_dpi_value = 2.0;
// break;
// case 5:
// self->curr_dpi_value = 2.25;
// break;
// case 6:
// self->curr_dpi_value = 2.5;
// break;
// }
my_prefs_save_config(self); my_prefs_save_config(self);
} }
@ -793,6 +835,16 @@ static void my_prefs_init(MyPrefs *self)
"2560x1440", "2560x1440",
NULL}; NULL};
const char *dpi_settings[] = {
"100%",
"125%",
"150%",
"175%",
"200%",
"225%",
"250%",
NULL};
// Load config // Load config
my_prefs_load_config(self); my_prefs_load_config(self);
@ -810,6 +862,7 @@ static void my_prefs_init(MyPrefs *self)
self->stack_box = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "stack_box")); self->stack_box = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "stack_box"));
self->back_page = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "back_page")); self->back_page = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "back_page"));
self->combo_box = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "combo_box")); self->combo_box = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "combo_box"));
self->dpi_box = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "dpi_box"));
self->mode_check = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "mode_check")); self->mode_check = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "mode_check"));
self->label_size = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "label_size")); self->label_size = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "label_size"));
self->radio_custom = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "radio_custom")); self->radio_custom = GTK_WIDGET(gtk_builder_get_object(self->prefs_builder, "radio_custom"));
@ -878,6 +931,13 @@ static void my_prefs_init(MyPrefs *self)
gtk_label_set_label(GTK_LABEL(self->label_size), size); gtk_label_set_label(GTK_LABEL(self->label_size), size);
g_free(size); g_free(size);
// Add a dropdown for DPI Config
self->label_dpi = gtk_label_new("DPI:\t\t");
self->dpi_drop = gtk_drop_down_new_from_strings(dpi_settings);
gtk_drop_down_set_selected(GTK_DROP_DOWN(self->dpi_drop), self->dpi_set);
gtk_box_append(GTK_BOX(self->dpi_box), self->label_dpi);
gtk_box_append(GTK_BOX(self->dpi_box), self->dpi_drop);
// Set default mode for check button // Set default mode for check button
gtk_check_button_set_active(GTK_CHECK_BUTTON(self->mode_check), TRUE); gtk_check_button_set_active(GTK_CHECK_BUTTON(self->mode_check), TRUE);