enable shutdown

This commit is contained in:
daleclack 2022-01-14 18:57:58 +08:00
parent 457a3aa767
commit ef35bbe1f4
7 changed files with 183 additions and 56 deletions

View File

@ -15,6 +15,7 @@
<property name="visible">1</property>
<child>
<object class="GtkStackPage">
<property name="name">page0</property>
<property name="title" translatable="1">page0</property>
<property name="child">
<object class="GtkBox" id="begin_box">
@ -58,6 +59,7 @@
</child>
<child>
<object class="GtkStackPage">
<property name="name">page1</property>
<property name="title" translatable="1">page1</property>
<property name="child">
<object class="GtkBox" id="main_box">
@ -66,129 +68,225 @@
<child>
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="1">7-Zip File Manager</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">start</property>
<property name="has-frame">0</property>
<child>
<object class="GtkImage" id="image1">
<object class="GtkBox">
<property name="visible">1</property>
<property name="icon-name">7zFM</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">16</property>
<property name="icon-name">7zFM</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="1"> 7-zip File Manager</property>
<property name="hexpand">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="1">BaiduNetDisk</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">start</property>
<property name="has-frame">0</property>
<child>
<object class="GtkImage" id="image2">
<property name="visible">1</property>
<property name="icon-name">baidunetdisk</property>
</object>
</child>
<object class="GtkBox">
<property name="visible">1</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">16</property>
<property name="icon-name">baidunetdisk</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="1"> BaiduNetDisk</property>
<property name="hexpand">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="1">File Manager</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">start</property>
<property name="has-frame">0</property>
<child>
<object class="GtkImage" id="image6">
<property name="visible">1</property>
<property name="icon-name">file-manager</property>
</object>
</child>
<object class="GtkBox">
<property name="visible">1</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">16</property>
<property name="icon-name">file-manager</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="1"> File Manager</property>
<property name="hexpand">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="1">Glade</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">start</property>
<property name="has-frame">0</property>
<child>
<object class="GtkImage" id="image8">
<property name="visible">1</property>
<property name="icon-name">glade</property>
</object>
</child>
<object class="GtkBox">
<property name="visible">1</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">16</property>
<property name="icon-name">glade</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="1"> Glade</property>
<property name="hexpand">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="1">QEMU</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">start</property>
<property name="has-frame">0</property>
<child>
<object class="GtkImage" id="image7">
<property name="visible">1</property>
<property name="icon-name">qemu-launcher</property>
</object>
</child>
<object class="GtkBox">
<property name="visible">1</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">16</property>
<property name="icon-name">qemu-launcher</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="1"> QEMU</property>
<property name="hexpand">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="1">QQ</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">start</property>
<property name="has-frame">0</property>
<child>
<object class="GtkImage" id="image5">
<property name="visible">1</property>
<property name="icon-name">qq</property>
</object>
</child>
<object class="GtkBox">
<property name="visible">1</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">16</property>
<property name="icon-name">qq</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="1"> QQ</property>
<property name="hexpand">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="1">QQMusic</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">start</property>
<property name="has-frame">0</property>
<child>
<object class="GtkImage" id="image3">
<property name="visible">1</property>
<property name="icon-name">qqmusic</property>
</object>
</child>
<object class="GtkBox">
<property name="visible">1</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">16</property>
<property name="icon-name">qqmusic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="1"> QQMusic</property>
<property name="hexpand">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">1</property>
<property name="label" translatable="1">Visual Studio Code</property>
<property name="focusable">1</property>
<property name="receives-default">1</property>
<property name="halign">start</property>
<property name="has-frame">0</property>
<child>
<object class="GtkImage" id="image4">
<property name="visible">1</property>
<property name="icon-name">visual-studio-code</property>
</object>
</child>
<object class="GtkBox">
<property name="visible">1</property>
<child>
<object class="GtkImage">
<property name="visible">1</property>
<property name="pixel-size">16</property>
<property name="icon-name">visual-studio-code</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="label" translatable="1"> Visual Studio Code</property>
<property name="hexpand">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
@ -281,7 +379,7 @@
<placeholder/>
</child>
<child>
<object class="GtkButton">
<object class="GtkButton" id="btnshut">
<property name="visible">1</property>
<property name="label" translatable="1">Shutdown</property>
<property name="focusable">1</property>

View File

@ -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);
@ -88,3 +88,8 @@ 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);
}

View File

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

View File

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

View File

@ -1,5 +1,6 @@
#pragma once
#include <gtk/gtk.h>
#include "MainWin.h"
void add_dock(GtkWidget * overlay, GtkStyleProvider * provider);
void add_dock(MainWin * win, GtkStyleProvider * provider);

View File

@ -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,6 +16,18 @@ 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);

View File

@ -1,5 +1,6 @@
#pragma once
#include <gtk/gtk.h>
#include "MainWin.h"
void add_start(GtkBox * box);
void add_start(MainWin * win, GtkBox * box);