From 4ea4e513d1bc305876b01339f6fe480435aac6c6 Mon Sep 17 00:00:00 2001 From: daleclack Date: Sun, 22 Sep 2024 20:34:45 +0800 Subject: [PATCH] Add dpi setting for launchpad --- Gtk4_Reset/res/mydock.ui | 34 +++++++++++----------- Gtk4_Reset/src/ui/AppView.cpp | 8 ++++-- Gtk4_Reset/src/ui/AppView.h | 2 +- Gtk4_Reset/src/ui/MyDock.cpp | 54 +++++++++++++++++++++++++++++------ 4 files changed, 70 insertions(+), 28 deletions(-) diff --git a/Gtk4_Reset/res/mydock.ui b/Gtk4_Reset/res/mydock.ui index f11e2ea..1346e5b 100644 --- a/Gtk4_Reset/res/mydock.ui +++ b/Gtk4_Reset/res/mydock.ui @@ -245,7 +245,7 @@ vertical 5 - + 0 0 48 @@ -278,7 +278,7 @@ vertical 5 - + 48 audacious_whitesur @@ -306,7 +306,7 @@ vertical 5 - + 48 drawing_app @@ -334,7 +334,7 @@ vertical 5 - + 48 file-app @@ -362,7 +362,7 @@ vertical 5 - + 48 my_textedit @@ -390,7 +390,7 @@ vertical 5 - + 48 game @@ -418,7 +418,7 @@ vertical 5 - + 48 image_app @@ -446,7 +446,7 @@ vertical 5 - + 48 my_textedit @@ -474,7 +474,7 @@ vertical 5 - + 48 my_textedit @@ -502,7 +502,7 @@ vertical 5 - + 48 vlc_whitesur @@ -530,7 +530,7 @@ vertical 5 - + 48 vlc_whitesur @@ -558,7 +558,7 @@ vertical 5 - + 48 myrunner @@ -586,7 +586,7 @@ vertical 5 - + 48 my_prefs @@ -614,7 +614,7 @@ vertical 5 - + 48 24game @@ -642,7 +642,7 @@ vertical 5 - + 48 calcapp @@ -670,7 +670,7 @@ vertical 5 - + mines_app 48 @@ -698,7 +698,7 @@ vertical 5 - + media-app 48 diff --git a/Gtk4_Reset/src/ui/AppView.cpp b/Gtk4_Reset/src/ui/AppView.cpp index 26ba8e9..84404b8 100644 --- a/Gtk4_Reset/src/ui/AppView.cpp +++ b/Gtk4_Reset/src/ui/AppView.cpp @@ -1,5 +1,7 @@ #include "AppView.h" +static double dpi_value; + // Create a model for application static GListModel *create_app_model() { @@ -31,7 +33,7 @@ static void app_ext_view_setup(GtkListItemFactory *factory, GtkListItem *item) app_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); image = gtk_image_new(); label = gtk_label_new(" "); - gtk_image_set_pixel_size(GTK_IMAGE(image), 40); + gtk_image_set_pixel_size(GTK_IMAGE(image), 36 * dpi_value); gtk_widget_set_size_request(label, 76, 12); gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); @@ -101,12 +103,14 @@ static void app_view_activate(GtkGridView *list, guint position, gpointer data) g_object_unref(app_info); } -GtkWidget *app_view_new(gboolean external) +GtkWidget *app_view_new(gboolean external, double dpi) { GtkWidget *list, *sw; GListModel *model; GtkListItemFactory *factory; + dpi_value = dpi; + // Create widgets sw = gtk_scrolled_window_new(); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), diff --git a/Gtk4_Reset/src/ui/AppView.h b/Gtk4_Reset/src/ui/AppView.h index edfc233..d96e893 100644 --- a/Gtk4_Reset/src/ui/AppView.h +++ b/Gtk4_Reset/src/ui/AppView.h @@ -2,4 +2,4 @@ #include -GtkWidget *app_view_new(gboolean external); +GtkWidget *app_view_new(gboolean external, double dpi); diff --git a/Gtk4_Reset/src/ui/MyDock.cpp b/Gtk4_Reset/src/ui/MyDock.cpp index 273ced5..7e107f6 100644 --- a/Gtk4_Reset/src/ui/MyDock.cpp +++ b/Gtk4_Reset/src/ui/MyDock.cpp @@ -41,11 +41,15 @@ struct _MyDock GtkWidget *btnfiles, *btndraw, *btncalc, *btnedit, *btnimage, // Dock buttons *btnset, *btngame, *btngame24, *btnmine, *btnmedia; 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_edit, *image_viewer, *image_game24, *image_mine, *image_set, *image_launch, *image_media, *image_trash; GtkWidget *padabout, *padaud, *paddraw, *padfile, *padgedit, // Launchpad icons *padgame, *padimage, *padnote, *padedit, *padvlc, *padvlc_win32, *padrun, *padset, *padgame24, *padcalc, *padmine, *padmedia; + GtkWidget *padabout_image, *padaud_image, *paddraw_image, *padfile_image, // Launchpad icon images + *padgedit_image, *padgame_image, *padimage_image, *padnote_image, + *padedit_image, *padvlc_image, *padvlc_win32_image, *padrun_image, + *padset_image, *padgame24_image, *padcalc_image, *padmine_image, *padmedia_image; PadPage current_page; GtkBuilder *menu_builder; GMenuModel *menu_model; @@ -162,7 +166,7 @@ static void my_dock_set_icon_name(MyDock *dock, GtkImage *image, const char *ico char icon_name[NAME_MAX]; // Set icon with dock position setting DockPos dock_pos = my_prefs_get_dock_pos(dock->prefs_win); - switch(dock_pos) + switch (dock_pos) { case DockPos::Pos_Left: snprintf(icon_name, NAME_MAX - 1, "%s_running", icon_name1); @@ -676,6 +680,23 @@ static void my_dock_apply_dpi(MyDock *self, double 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); + gtk_image_set_pixel_size(GTK_IMAGE(self->padabout_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padaud_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padcalc_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->paddraw_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padedit_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padfile_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padgame24_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padgame_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padgedit_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padimage_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padmedia_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padmine_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padnote_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padrun_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padset_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padvlc_image), 40 * dpi); + gtk_image_set_pixel_size(GTK_IMAGE(self->padvlc_win32_image), 40 * dpi); } static void my_dock_get_widgets(MyDock *self) @@ -736,6 +757,23 @@ static void my_dock_get_widgets(MyDock *self) self->padset = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padset")); self->padvlc = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padvlc")); self->padvlc_win32 = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padvlc_win32")); + self->padaud_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padaud_image")); + self->padabout_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padabout_image")); + self->padcalc_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padcalc_image")); + self->paddraw_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "paddraw_image")); + self->padedit_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padedit_image")); + self->padfile_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padfile_image")); + self->padgame24_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padgame24_image")); + self->padgame_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padgame_image")); + self->padgedit_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padgedit_image")); + self->padimage_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padimage_image")); + self->padmine_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padmine_image")); + self->padmedia_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padmedia_image")); + self->padnote_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padnote_image")); + self->padrun_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padrun_image")); + self->padset_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padset_image")); + self->padvlc_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padvlc_image")); + self->padvlc_win32_image = GTK_WIDGET(gtk_builder_get_object(self->dock_builder, "padvlc_win32_image")); // Hide ScrollBar for icons scrolled window GtkWidget *scrollbar = gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(self->icons_sw)); @@ -906,6 +944,11 @@ static void my_dock_init(MyDock *self) // Add Style for finder my_finder_add_style(MY_FINDER(self->finder), provider); + // Apply DPI Setting for the dock and the finder + double dpi_value = my_prefs_get_dpi_value(self->prefs_win); + my_dock_apply_dpi(self, dpi_value); + my_finder_apply_dpi(MY_FINDER(self->finder), dpi_value); + // Add Apps grid // To make the default view layout same as the addon apps view self->appgrid_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); @@ -917,7 +960,7 @@ static void my_dock_init(MyDock *self) gtk_grid_set_row_spacing(GTK_GRID(self->apps_grid), 20); // Add Addon apps view - self->apps_view = app_view_new(TRUE); + self->apps_view = app_view_new(TRUE, dpi_value); gtk_box_append(GTK_BOX(self->addon_box), self->apps_view); gtk_widget_set_halign(self->addon_box, GTK_ALIGN_CENTER); gtk_widget_set_halign(self->apps_view, GTK_ALIGN_CENTER); @@ -974,11 +1017,6 @@ static void my_dock_init(MyDock *self) gtk_style_context_add_provider_for_display(gtk_widget_get_display(self->context_menu), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - - // Apply DPI Setting for the dock and the finder - double dpi_value = my_prefs_get_dpi_value(self->prefs_win); - my_dock_apply_dpi(self, dpi_value); - my_finder_apply_dpi(MY_FINDER(self->finder), dpi_value); } static void my_dock_class_init(MyDockClass *klass)