Add DPI support for dock

This commit is contained in:
daleclack 2024-09-22 19:15:05 +08:00
parent 3c36574c83
commit 0fab8c60cf
5 changed files with 29 additions and 6 deletions

View File

@ -17,7 +17,7 @@
<property name="focusable">1</property> <property name="focusable">1</property>
<property name="receives-default">1</property> <property name="receives-default">1</property>
<property name="child"> <property name="child">
<object class="GtkImage" id="image1"> <object class="GtkImage" id="image_launch">
<property name="pixel-size">48</property> <property name="pixel-size">48</property>
<property name="icon-name">My_GtkUI</property> <property name="icon-name">My_GtkUI</property>
</object> </object>
@ -205,7 +205,7 @@
<property name="focusable">1</property> <property name="focusable">1</property>
<property name="receives-default">1</property> <property name="receives-default">1</property>
<property name="child"> <property name="child">
<object class="GtkImage" id="image21"> <object class="GtkImage" id="image_trash">
<property name="pixel-size">48</property> <property name="pixel-size">48</property>
<property name="icon-name">my_trash</property> <property name="icon-name">my_trash</property>
</object> </object>

View File

@ -135,7 +135,7 @@ void create_main_stack(GtkWindow *win)
main_win_set_prefs(MAIN_WIN(win), prefs); main_win_set_prefs(MAIN_WIN(win), prefs);
// Get DPI setting // Get DPI setting
double dpi = my_prefs_get_dpi(prefs); double dpi = my_prefs_get_dpi_value(prefs);
gtk_widget_set_size_request(btnlogin, 60 * dpi, 25 * dpi); gtk_widget_set_size_request(btnlogin, 60 * dpi, 25 * dpi);
gtk_widget_set_size_request(user_label, 60 * dpi, 25 * dpi); gtk_widget_set_size_request(user_label, 60 * dpi, 25 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(user_image), 40 * dpi); gtk_image_set_pixel_size(GTK_IMAGE(user_image), 40 * dpi);

View File

@ -41,7 +41,8 @@ struct _MyDock
GtkWidget *btnfiles, *btndraw, *btncalc, *btnedit, *btnimage, // Dock buttons GtkWidget *btnfiles, *btndraw, *btncalc, *btnedit, *btnimage, // Dock buttons
*btnset, *btngame, *btngame24, *btnmine, *btnmedia; *btnset, *btngame, *btngame24, *btnmine, *btnmedia;
GtkWidget *image_file, *image_draw, *image_calc, *image_game, // Image widget for dock buttons GtkWidget *image_file, *image_draw, *image_calc, *image_game, // Image widget for dock buttons
*image_edit, *image_viewer, *image_game24, *image_mine, *image_set, *image_media; *image_edit, *image_viewer, *image_game24, *image_mine, *image_set,
*image_launch, *image_media, *image_trash;
GtkWidget *padabout, *padaud, *paddraw, *padfile, *padgedit, // Launchpad icons GtkWidget *padabout, *padaud, *paddraw, *padfile, *padgedit, // Launchpad icons
*padgame, *padimage, *padnote, *padedit, *padvlc, *padvlc_win32, *padgame, *padimage, *padnote, *padedit, *padvlc, *padvlc_win32,
*padrun, *padset, *padgame24, *padcalc, *padmine, *padmedia; *padrun, *padset, *padgame24, *padcalc, *padmine, *padmedia;
@ -661,6 +662,22 @@ static void padvlc_win32(GtkWidget *widget, MyDock *dock)
btnlaunch_clicked(NULL, dock); btnlaunch_clicked(NULL, dock);
} }
static void my_dock_apply_dpi(MyDock *self, double dpi)
{
gtk_image_set_pixel_size(GTK_IMAGE(self->image_launch), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_file), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_calc), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_draw), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_edit), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_game24), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_game), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_viewer), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_mine), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_set), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_media), 40 * dpi);
gtk_image_set_pixel_size(GTK_IMAGE(self->image_trash), 40 * dpi);
}
static void my_dock_get_widgets(MyDock *self) static void my_dock_get_widgets(MyDock *self)
{ {
// Get widgets // Get widgets
@ -673,6 +690,7 @@ static void my_dock_get_widgets(MyDock *self)
self->icons_sw = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "icons_sw")); self->icons_sw = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "icons_sw"));
self->icons_box = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "icons_box")); self->icons_box = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "icons_box"));
self->btnlaunch = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btnlaunch")); self->btnlaunch = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btnlaunch"));
self->image_launch = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_launch"));
self->btnfiles = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btnfiles")); self->btnfiles = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btnfiles"));
self->image_file = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_file")); self->image_file = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_file"));
self->btncalc = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btncalc")); self->btncalc = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btncalc"));
@ -693,6 +711,7 @@ static void my_dock_get_widgets(MyDock *self)
self->image_set = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_set")); self->image_set = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_set"));
self->btnmedia = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btnmedia")); self->btnmedia = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "btnmedia"));
self->image_media = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_media")); self->image_media = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_media"));
self->image_trash = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "image_trash"));
self->launchpad_stack = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "launchpad_stack")); self->launchpad_stack = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "launchpad_stack"));
self->default_page = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "default_page")); self->default_page = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "default_page"));
self->launchpad_page = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "launchpad_page")); self->launchpad_page = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "launchpad_page"));
@ -955,6 +974,10 @@ static void my_dock_init(MyDock *self)
gtk_style_context_add_provider_for_display(gtk_widget_get_display(self->context_menu), gtk_style_context_add_provider_for_display(gtk_widget_get_display(self->context_menu),
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
// Apply DPI Setting for the dock
double dpi_value = my_prefs_get_dpi_value(self->prefs_win);
my_dock_apply_dpi(self, dpi_value);
} }
static void my_dock_class_init(MyDockClass *klass) static void my_dock_class_init(MyDockClass *klass)

View File

@ -1045,7 +1045,7 @@ void my_prefs_set_background(MyPrefs *prefs_win, GtkWidget *back)
is_internal, prefs_win); is_internal, prefs_win);
} }
double my_prefs_get_dpi(MyPrefs *self) double my_prefs_get_dpi_value(MyPrefs *self)
{ {
return dpi_values[self->dpi_set]; return dpi_values[self->dpi_set];
} }

View File

@ -21,6 +21,6 @@ DockPos my_prefs_get_dock_pos(MyPrefs *self);
void my_prefs_set_background(MyPrefs *prefs_win, GtkWidget *back); void my_prefs_set_background(MyPrefs *prefs_win, GtkWidget *back);
double my_prefs_get_dpi(MyPrefs *self); double my_prefs_get_dpi_value(MyPrefs *self);
MyPrefs *my_prefs_new(); MyPrefs *my_prefs_new();