From ef35bbe1f4755ad6a5f180e7779288ed0058b677 Mon Sep 17 00:00:00 2001 From: daleclack Date: Fri, 14 Jan 2022 18:57:58 +0800 Subject: [PATCH] enable shutdown --- Flos_Gtk4/res/start.ui | 194 +++++++++++++++++++++++++-------- Flos_Gtk4/src/core/MainWin.cpp | 7 +- Flos_Gtk4/src/core/MainWin.h | 2 + Flos_Gtk4/src/core/MyDock.cpp | 6 +- Flos_Gtk4/src/core/MyDock.h | 3 +- Flos_Gtk4/src/core/Start.cpp | 24 +++- Flos_Gtk4/src/core/Start.h | 3 +- 7 files changed, 183 insertions(+), 56 deletions(-) diff --git a/Flos_Gtk4/res/start.ui b/Flos_Gtk4/res/start.ui index 3076356..b6ed2d2 100644 --- a/Flos_Gtk4/res/start.ui +++ b/Flos_Gtk4/res/start.ui @@ -15,6 +15,7 @@ 1 + page0 page0 @@ -58,6 +59,7 @@ + page1 page1 @@ -66,129 +68,225 @@ 1 - 7-Zip File Manager 1 1 start 0 - + 1 - 7zFM - - + + + 1 + 16 + 7zFM + + + + + 1 + 7-zip File Manager + 1 + + + + 1 - BaiduNetDisk 1 1 start 0 - - 1 - baidunetdisk - - + + 1 + + + 1 + 16 + baidunetdisk + + + + + 1 + BaiduNetDisk + 1 + + + + 1 - File Manager 1 1 start 0 - - 1 - file-manager - - + + 1 + + + 1 + 16 + file-manager + + + + + 1 + File Manager + 1 + + + + 1 - Glade 1 1 start 0 - - 1 - glade - - + + 1 + + + 1 + 16 + glade + + + + + 1 + Glade + 1 + + + + 1 - QEMU 1 1 start 0 - - 1 - qemu-launcher - - + + 1 + + + 1 + 16 + qemu-launcher + + + + + 1 + QEMU + 1 + + + + 1 - QQ 1 1 start 0 - - 1 - qq - - + + 1 + + + 1 + 16 + qq + + + + + 1 + QQ + 1 + + + + 1 - QQMusic 1 1 start 0 - - 1 - qqmusic - - + + 1 + + + 1 + 16 + qqmusic + + + + + 1 + QQMusic + 1 + + + + 1 - Visual Studio Code 1 1 start 0 - - 1 - visual-studio-code - - + + 1 + + + 1 + 16 + visual-studio-code + + + + + 1 + Visual Studio Code + 1 + + + + @@ -281,7 +379,7 @@ - + 1 Shutdown 1 diff --git a/Flos_Gtk4/src/core/MainWin.cpp b/Flos_Gtk4/src/core/MainWin.cpp index 51c36d0..29d377b 100644 --- a/Flos_Gtk4/src/core/MainWin.cpp +++ b/Flos_Gtk4/src/core/MainWin.cpp @@ -75,7 +75,7 @@ static void main_win_init(MainWin *win) gtk_overlay_add_overlay(GTK_OVERLAY(win->overlay), time_label); //Add a dock - add_dock(win->overlay, provider); + add_dock(win, provider); // Add widgets gtk_overlay_set_child(GTK_OVERLAY(win->overlay), win->background); @@ -87,4 +87,9 @@ static void main_win_class_init(MainWinClass *klass) {} MainWin *main_win_new(GtkApplication *app) { return (MainWin *)g_object_new(main_win_get_type(), "application", app, NULL); +} + + +GtkOverlay *main_win_get_overlay(MainWin * win){ + return GTK_OVERLAY(win->overlay); } \ No newline at end of file diff --git a/Flos_Gtk4/src/core/MainWin.h b/Flos_Gtk4/src/core/MainWin.h index 02b7ec1..388d563 100644 --- a/Flos_Gtk4/src/core/MainWin.h +++ b/Flos_Gtk4/src/core/MainWin.h @@ -5,3 +5,5 @@ G_DECLARE_FINAL_TYPE(MainWin,main_win,MAIN,WIN,GtkApplicationWindow) MainWin * main_win_new(GtkApplication * app); + +GtkOverlay *main_win_get_overlay(MainWin * win); diff --git a/Flos_Gtk4/src/core/MyDock.cpp b/Flos_Gtk4/src/core/MyDock.cpp index 8898106..5641dc1 100644 --- a/Flos_Gtk4/src/core/MyDock.cpp +++ b/Flos_Gtk4/src/core/MyDock.cpp @@ -1,7 +1,7 @@ #include "MyDock.h" #include "Start.h" -void add_dock(GtkWidget * overlay, GtkStyleProvider * provider){ +void add_dock(MainWin * win, GtkStyleProvider * provider){ GtkWidget * dock_box, * main_box; //Create a box for layout @@ -12,13 +12,13 @@ void add_dock(GtkWidget * overlay, GtkStyleProvider * provider){ dock_box = (GtkWidget*)gtk_builder_get_object(builder,"main_dock"); //Add a start - add_start(GTK_BOX(dock_box)); + add_start(win, GTK_BOX(dock_box)); //Put the dock on the overlay gtk_box_append(GTK_BOX(main_box),dock_box); gtk_widget_set_halign(main_box,GTK_ALIGN_CENTER); gtk_widget_set_valign(main_box,GTK_ALIGN_END); - gtk_overlay_add_overlay(GTK_OVERLAY(overlay),main_box); + gtk_overlay_add_overlay(main_win_get_overlay(win),main_box); //Add a separator GtkWidget * space = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); diff --git a/Flos_Gtk4/src/core/MyDock.h b/Flos_Gtk4/src/core/MyDock.h index 1ec9960..ed35a6b 100644 --- a/Flos_Gtk4/src/core/MyDock.h +++ b/Flos_Gtk4/src/core/MyDock.h @@ -1,5 +1,6 @@ #pragma once #include +#include "MainWin.h" -void add_dock(GtkWidget * overlay, GtkStyleProvider * provider); +void add_dock(MainWin * win, GtkStyleProvider * provider); diff --git a/Flos_Gtk4/src/core/Start.cpp b/Flos_Gtk4/src/core/Start.cpp index de4da86..2e5d38c 100644 --- a/Flos_Gtk4/src/core/Start.cpp +++ b/Flos_Gtk4/src/core/Start.cpp @@ -1,6 +1,14 @@ #include "Start.h" -void add_start(GtkBox * box){ +static void btnprogram_clicked(GtkWidget * widget, GtkStack * stack){ + gtk_stack_set_visible_child_name(stack,"page1"); +} + +static void btnback_clicked(GtkWidget * widget, GtkStack * stack){ + gtk_stack_set_visible_child_name(stack,"page0"); +} + +void add_start(MainWin * win, GtkBox * box){ //Create a builder for menu GtkBuilder * startbuilder = gtk_builder_new_from_resource("/org/gtk/daleclack/start.ui"); @@ -8,7 +16,19 @@ void add_start(GtkBox * box){ GtkWidget * menu_btn = (GtkWidget*)gtk_builder_get_object(startbuilder,"menu_btn"); GtkWidget * label = gtk_label_new(" "); + //Stack Change effect + GtkWidget * stack_program, * btn_program, * btn_back; + stack_program = (GtkWidget*)gtk_builder_get_object(startbuilder,"stack_program"); + btn_program = (GtkWidget*)gtk_builder_get_object(startbuilder,"btn_program"); + btn_back = (GtkWidget*)gtk_builder_get_object(startbuilder,"btn_back"); + g_signal_connect(btn_program,"clicked",G_CALLBACK(btnprogram_clicked),stack_program); + g_signal_connect(btn_back,"clicked",G_CALLBACK(btnback_clicked),stack_program); + + //Enable Shutdown(Close) + GtkWidget * btnshut = (GtkWidget*)gtk_builder_get_object(startbuilder,"btnshut"); + g_signal_connect_swapped(btnshut,"clicked",G_CALLBACK(gtk_window_destroy),win); + //Pack widgets gtk_box_prepend(box,menu_btn); gtk_box_prepend(box,label); -} \ No newline at end of file +} diff --git a/Flos_Gtk4/src/core/Start.h b/Flos_Gtk4/src/core/Start.h index db228bd..2a8eb18 100644 --- a/Flos_Gtk4/src/core/Start.h +++ b/Flos_Gtk4/src/core/Start.h @@ -1,5 +1,6 @@ #pragma once #include +#include "MainWin.h" -void add_start(GtkBox * box); +void add_start(MainWin * win, GtkBox * box);