Update the winsize config

This commit is contained in:
daleclack 2021-06-14 09:49:15 +08:00
parent 27ba4b9c6d
commit 62f1509fc0
4 changed files with 74 additions and 27 deletions

View File

@ -1,6 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">9999</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="upper">9999</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkDialog" id="dialog">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Window size config</property>
@ -64,9 +75,11 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkEntry" id="entry_width">
<object class="GtkSpinButton" id="width_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="adjustment">adjustment1</property>
<property name="value">640</property>
</object>
<packing>
<property name="expand">False</property>
@ -87,9 +100,11 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_height">
<object class="GtkSpinButton" id="height_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="adjustment">adjustment2</property>
<property name="value">480</property>
</object>
<packing>
<property name="expand">False</property>

View File

@ -1,7 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<requires lib="gtk+" version="3.0"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">9999</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
<property name="upper">9999</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkDialog" id="dialog">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Window size config</property>
@ -65,9 +75,11 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkEntry" id="entry_width">
<object class="GtkSpinButton" id="width_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="adjustment">adjustment1</property>
<property name="value">640</property>
</object>
<packing>
<property name="expand">False</property>
@ -88,9 +100,11 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="entry_height">
<object class="GtkSpinButton" id="height_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="adjustment">adjustment2</property>
<property name="value">480</property>
</object>
<packing>
<property name="expand">False</property>

View File

@ -9,10 +9,13 @@ void conf_dialog(GtkWidget *widget,GtkBuilder *builder){
gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(window));
g_signal_connect(dialog,"response",G_CALLBACK(conf_response),conf_size);
//Set default config
GObject *entry_width=gtk_builder_get_object(conf_size,"entry_width");
gtk_entry_set_text(GTK_ENTRY(entry_width),"640");
GObject *entry_height=gtk_builder_get_object(conf_size,"entry_height");
gtk_entry_set_text(GTK_ENTRY(entry_height),"360");
GObject *width_spin=gtk_builder_get_object(conf_size,"width_spin");
gtk_spin_button_set_value((GtkSpinButton*)width_spin,640);
//gtk_entry_set_text(GTK_ENTRY(entry_width),"640");
GObject *height_spin=gtk_builder_get_object(conf_size,"height_spin");
gtk_spin_button_set_value((GtkSpinButton*)height_spin,480);
// GObject *entry_height=gtk_builder_get_object(conf_size,"entry_height");
// gtk_entry_set_text(GTK_ENTRY(entry_height),"360");
//Get window size
GObject *btnGet=gtk_builder_get_object(conf_size,"btnGet");
g_signal_connect(btnGet,"clicked",G_CALLBACK(get_winsize),conf_size);
@ -24,15 +27,21 @@ void conf_dialog(GtkWidget *widget,GtkBuilder *builder){
void conf_response(GtkWidget *widget,int response,GtkBuilder *builder_conf){
//Get width and height config and put the numbers into winsize.conf file
GObject *entry_width,*entry_height;
entry_width=gtk_builder_get_object(builder_conf,"entry_width");
entry_height=gtk_builder_get_object(builder_conf,"entry_height");
GObject *width_spin,*height_spin;
width_spin=gtk_builder_get_object(builder_conf,"width_spin");
height_spin=gtk_builder_get_object(builder_conf,"height_spin");
// GObject *entry_width,*entry_height;
// entry_width=gtk_builder_get_object(builder_conf,"entry_width");
// entry_height=gtk_builder_get_object(builder_conf,"entry_height");
if(response==GTK_RESPONSE_OK){
const gchar *width,*height;
width=gtk_entry_get_text(GTK_ENTRY(entry_width));
height=gtk_entry_get_text(GTK_ENTRY(entry_height));
// const gchar *width,*height;
// width=gtk_entry_get_text(GTK_ENTRY(entry_width));
// height=gtk_entry_get_text(GTK_ENTRY(entry_height));
int width,height;
width=gtk_spin_button_get_value_as_int((GtkSpinButton*)width_spin);
height=gtk_spin_button_get_value_as_int((GtkSpinButton*)height_spin);
freopen("winsize.conf","w",stdout);
g_print("%s %s",width,height);
g_print("%d %d",width,height);
fclose(stdout);
}
gtk_widget_destroy(widget);
@ -40,29 +49,38 @@ void conf_response(GtkWidget *widget,int response,GtkBuilder *builder_conf){
void set_default(GtkWidget *widget,GtkBuilder *builder_conf){
//Discard changes and set to default config
GObject *entry_width=gtk_builder_get_object(builder_conf,"entry_width");
GObject *entry_height=gtk_builder_get_object(builder_conf,"entry_height");
gtk_entry_set_text(GTK_ENTRY(entry_width),"640");
gtk_entry_set_text(GTK_ENTRY(entry_height),"360");
GObject *width_spin=gtk_builder_get_object(builder_conf,"width_spin");
gtk_spin_button_set_value((GtkSpinButton*)width_spin,640);
GObject *height_spin=gtk_builder_get_object(builder_conf,"height_spin");
gtk_spin_button_set_value((GtkSpinButton*)height_spin,480);
// GObject *entry_width=gtk_builder_get_object(builder_conf,"entry_width");
// GObject *entry_height=gtk_builder_get_object(builder_conf,"entry_height");
// gtk_entry_set_text(GTK_ENTRY(entry_width),"640");
// gtk_entry_set_text(GTK_ENTRY(entry_height),"360");
}
void get_winsize(GtkWidget *widget,GtkBuilder *builder_conf){
//Get current window size
int width=640,height=360;
char width1[7],height1[7];
//char width1[7],height1[7];
GtkWindow *window;
//Get dialog window and entry
GObject *dialog=gtk_builder_get_object(builder_conf,"dialog");
GObject *entry_width=gtk_builder_get_object(builder_conf,"entry_width");
GObject *entry_height=gtk_builder_get_object(builder_conf,"entry_height");
GObject *width_spin=gtk_builder_get_object(builder_conf,"width_spin");
//gtk_entry_set_text(GTK_ENTRY(entry_width),"640");
GObject *height_spin=gtk_builder_get_object(builder_conf,"height_spin");
// GObject *entry_width=gtk_builder_get_object(builder_conf,"entry_width");
// GObject *entry_height=gtk_builder_get_object(builder_conf,"entry_height");
//Get main window
window=gtk_window_get_transient_for(GTK_WINDOW(dialog));
gtk_window_get_size(GTK_WINDOW(window),&width,&height);
gtk_spin_button_set_value((GtkSpinButton*)width_spin,width);
gtk_spin_button_set_value((GtkSpinButton*)height_spin,height);
//g_print("%d %d\n",width,height);
sprintf(width1,"%d",width);
sprintf(height1,"%d",height);
gtk_entry_set_text(GTK_ENTRY(entry_width),width1);
gtk_entry_set_text(GTK_ENTRY(entry_height),height1);
// sprintf(width1,"%d",width);
// sprintf(height1,"%d",height);
// gtk_entry_set_text(GTK_ENTRY(entry_width),width1);
// gtk_entry_set_text(GTK_ENTRY(entry_height),height1);
}
void get_config(int *width,int *height){