Fix filewindow behaviors

This commit is contained in:
daleclack 2024-03-23 08:16:35 +08:00
parent 641e895da5
commit 84fadd1d26
3 changed files with 39 additions and 7 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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");