From 84fadd1d264c427cb345e1c3140b88424070f9fd Mon Sep 17 00:00:00 2001 From: daleclack Date: Sat, 23 Mar 2024 08:16:35 +0800 Subject: [PATCH] Fix filewindow behaviors --- Flos_Gtk4/src/core/MyDock.cpp | 36 +++++++++++++++++++++++++++++++---- Flos_Gtk4/src/core/MyDock.h | 4 ++++ Flos_Gtk4/src/core/Start.cpp | 6 +++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Flos_Gtk4/src/core/MyDock.cpp b/Flos_Gtk4/src/core/MyDock.cpp index bf52d16..3b96351 100644 --- a/Flos_Gtk4/src/core/MyDock.cpp +++ b/Flos_Gtk4/src/core/MyDock.cpp @@ -43,7 +43,7 @@ static gboolean file_window_closed(GtkWindow *self, GtkButton *dock_file) // } // } -static void file_window_ctrl(FileWindow *window, GtkWindow *parent) +static void file_window_ctrl(FileWindow *window, GtkWindow *parent, gboolean on_dock) { gboolean visible = gtk_widget_get_visible(GTK_WIDGET(window)); // The unminimize if changed to hide @@ -54,7 +54,35 @@ static void file_window_ctrl(FileWindow *window, GtkWindow *parent) } else { - gtk_widget_set_visible(GTK_WIDGET(window), FALSE); + // Window control only available for icons on dock + if (on_dock){ + gtk_widget_set_visible(GTK_WIDGET(window), FALSE); + } + } +} + +void padfile_clicked(GtkButton *button, GtkWindow *parent) +{ + // If the file app is not running, create a window + GtkWidget *child = gtk_button_get_child(GTK_BUTTON(btnfile)); + const char *icon_name = gtk_image_get_icon_name(GTK_IMAGE(child)); + + if (!file_app_running) + { + // Create the window + main_window = file_window_new(parent); + gtk_image_set_from_icon_name(GTK_IMAGE(child), "file-manager_running"); + + // Link Signals + g_signal_connect(main_window, "close-request", G_CALLBACK(file_window_closed), btnfile); + + // Show the window + file_app_running = TRUE; + gtk_window_present(GTK_WINDOW(main_window)); + } + else + { + file_window_ctrl(main_window, parent, FALSE); } } @@ -79,13 +107,13 @@ void btnfile_clicked(GtkButton *button, GtkWindow *parent) } else { - file_window_ctrl(main_window, parent); + file_window_ctrl(main_window, parent, TRUE); } } void btnhome_clicked(GtkButton *button, GtkWindow *parent) { - btnfile_clicked(button, parent); + padfile_clicked(button, parent); home_clicked(NULL, main_window); } diff --git a/Flos_Gtk4/src/core/MyDock.h b/Flos_Gtk4/src/core/MyDock.h index 6737c97..1c16fb4 100644 --- a/Flos_Gtk4/src/core/MyDock.h +++ b/Flos_Gtk4/src/core/MyDock.h @@ -15,5 +15,9 @@ void add_dock(MainWin *win); void btnfile_clicked(GtkButton *button, GtkWindow *parent); +// For open file manager without click the dock icon + +void padfile_clicked(GtkButton *button, GtkWindow *parent); + // For "Home" Button void btnhome_clicked(GtkButton *button, GtkWindow *parent); diff --git a/Flos_Gtk4/src/core/Start.cpp b/Flos_Gtk4/src/core/Start.cpp index 7dc0790..b38ae4b 100644 --- a/Flos_Gtk4/src/core/Start.cpp +++ b/Flos_Gtk4/src/core/Start.cpp @@ -82,15 +82,15 @@ void add_start(MainWin *win, GtkBox *box) GtkWidget *btnfile1, *btnfile2; btnfile1 = (GtkWidget *)gtk_builder_get_object(startbuilder, "btnfile1"); btnfile2 = (GtkWidget *)gtk_builder_get_object(startbuilder, "btnfile2"); - g_signal_connect(btnfile1, "clicked", G_CALLBACK(btnfile_clicked), win); - g_signal_connect(btnfile2, "clicked", G_CALLBACK(btnfile_clicked), win); + g_signal_connect(btnfile1, "clicked", G_CALLBACK(padfile_clicked), win); + g_signal_connect(btnfile2, "clicked", G_CALLBACK(padfile_clicked), win); // Buttons for control panel GtkWidget *user_button, *btn_computer; user_button = (GtkWidget *)gtk_builder_get_object(startbuilder, "user_button"); btn_computer = (GtkWidget *)gtk_builder_get_object(startbuilder, "btn_computer"); g_signal_connect(user_button, "clicked", G_CALLBACK(btnhome_clicked), win); - g_signal_connect(btn_computer, "clicked", G_CALLBACK(btnfile_clicked), win); + g_signal_connect(btn_computer, "clicked", G_CALLBACK(padfile_clicked), win); // When the button clicked, popdown the menu GtkWidget *start_menu = (GtkWidget *)gtk_builder_get_object(startbuilder, "main_menu");