Skip to content

Commit

Permalink
gui: remove obsolete hbox for gtk3/qt5/qt6
Browse files Browse the repository at this point in the history
- gtk3: remove default width/height
- gtk4: remove default width/height
  • Loading branch information
Chilledheart committed Jul 17, 2024
1 parent 46cb974 commit d70e7a6
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 124 deletions.
6 changes: 3 additions & 3 deletions src/gtk/option_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ OptionDialog::OptionDialog(const std::string& title, GtkWindow* parent, bool mod
(modal ? GTK_DIALOG_MODAL : GTK_DIALOG_DESTROY_WITH_PARENT),
nullptr,
nullptr))) {
gtk_window_set_default_size(GTK_WINDOW(impl_), 400, 200);
gtk_window_set_position(GTK_WINDOW(impl_), GTK_WIN_POS_CENTER);

GtkGrid* grid = GTK_GRID(gtk_grid_new());
gtk_grid_set_row_homogeneous(grid, true);
gtk_grid_set_column_homogeneous(grid, true);

auto tcp_keep_alive_label = gtk_label_new(_("TCP keep alive"));
auto tcp_keep_alive_cnt_label = gtk_label_new(_("The number of TCP keep-alive probes"));
Expand All @@ -49,6 +46,9 @@ OptionDialog::OptionDialog(const std::string& title, GtkWindow* parent, bool mod
gtk_grid_attach(grid, GTK_WIDGET(tcp_keep_alive_interval_), 1, 3, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(enable_post_quantum_kyber_), 1, 4, 1, 1);

gtk_widget_set_margin_top(GTK_WIDGET(grid), 12);
gtk_widget_set_margin_bottom(GTK_WIDGET(grid), 12);

#if GTK_CHECK_VERSION(3, 12, 0)
gtk_widget_set_margin_start(GTK_WIDGET(grid), 12);
gtk_widget_set_margin_end(GTK_WIDGET(grid), 12);
Expand Down
110 changes: 42 additions & 68 deletions src/gtk/yass_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ extern "C" void app_indicator_uninit();

YASSWindow::YASSWindow() : impl_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))) {
gtk_window_set_title(GTK_WINDOW(impl_), YASS_APP_PRODUCT_NAME);
gtk_window_set_default_size(GTK_WINDOW(impl_), 530, 540);
gtk_window_set_position(GTK_WINDOW(impl_), GTK_WIN_POS_CENTER);
gtk_window_set_resizable(GTK_WINDOW(impl_), false);
gtk_window_set_icon_name(GTK_WINDOW(impl_), "yass");
Expand All @@ -46,9 +45,8 @@ YASSWindow::YASSWindow() : impl_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))

// vbox, hbox
GtkBox* vbox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
GtkBox* hbox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 20));
GtkBox* left_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
GtkGrid* right_panel_grid = GTK_GRID(gtk_grid_new());
GtkGrid* grid = GTK_GRID(gtk_grid_new());
gtk_grid_set_row_homogeneous(grid, true);

// gtkmm's MenuBar/Menu/MenuItem is binded to model
GtkWidget* menubar;
Expand Down Expand Up @@ -107,13 +105,8 @@ YASSWindow::YASSWindow() : impl_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))
start_button_ = GTK_BUTTON(gtk_button_new());
gtk_button_set_label(start_button_, _("Start"));

gtk_widget_set_margin_top(GTK_WIDGET(start_button_), 30);
gtk_widget_set_margin_bottom(GTK_WIDGET(start_button_), 30);

stop_button_ = GTK_BUTTON(gtk_button_new());
gtk_button_set_label(stop_button_, _("Stop"));
gtk_widget_set_margin_top(GTK_WIDGET(stop_button_), 30);
gtk_widget_set_margin_bottom(GTK_WIDGET(stop_button_), 30);

auto start_callback = [](GtkButton* self, gpointer pointer) {
YASSWindow* window = (YASSWindow*)pointer;
Expand All @@ -131,18 +124,8 @@ YASSWindow::YASSWindow() : impl_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))

gtk_widget_set_sensitive(GTK_WIDGET(stop_button_), false);

gtk_container_add(GTK_CONTAINER(left_box), GTK_WIDGET(start_button_));
gtk_container_add(GTK_CONTAINER(left_box), GTK_WIDGET(stop_button_));

#if GTK_CHECK_VERSION(3, 12, 0)
gtk_widget_set_margin_start(GTK_WIDGET(left_box), 15);
gtk_widget_set_margin_end(GTK_WIDGET(left_box), 5);
#else
gtk_widget_set_margin_left(GTK_WIDGET(left_box), 15);
gtk_widget_set_margin_right(GTK_WIDGET(left_box), 5);
#endif

gtk_container_add(GTK_CONTAINER(hbox), GTK_WIDGET(left_box));
gtk_grid_attach(grid, GTK_WIDGET(start_button_), 0, 2, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(stop_button_), 0, 7, 1, 1);

auto server_host_label_ = gtk_label_new(_("Server Host"));
auto server_sni_label_ = gtk_label_new(_("Server SNI"));
Expand All @@ -159,20 +142,20 @@ YASSWindow::YASSWindow() : impl_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))
auto autostart_label_ = gtk_label_new(_("Auto Start"));
auto systemproxy_label_ = gtk_label_new(_("System Proxy"));

gtk_grid_attach(right_panel_grid, GTK_WIDGET(server_host_label_), 0, 0, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(server_sni_label_), 0, 1, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(server_port_label_), 0, 2, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(username_label_), 0, 3, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(password_label_), 0, 4, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(method_label_), 0, 5, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(local_host_label_), 0, 6, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(local_port_label_), 0, 7, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(doh_url_label_), 0, 8, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(dot_host_label_), 0, 9, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(limit_rate_label_), 0, 10, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(timeout_label_), 0, 11, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(autostart_label_), 0, 12, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(systemproxy_label_), 0, 13, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(server_host_label_), 1, 0, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(server_sni_label_), 1, 1, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(server_port_label_), 1, 2, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(username_label_), 1, 3, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(password_label_), 1, 4, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(method_label_), 1, 5, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(local_host_label_), 1, 6, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(local_port_label_), 1, 7, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(doh_url_label_), 1, 8, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(dot_host_label_), 1, 9, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(limit_rate_label_), 1, 10, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(timeout_label_), 1, 11, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(autostart_label_), 1, 12, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(systemproxy_label_), 1, 13, 1, 1);

server_host_ = GTK_ENTRY(gtk_entry_new());
server_sni_ = GTK_ENTRY(gtk_entry_new());
Expand Down Expand Up @@ -221,44 +204,35 @@ YASSWindow::YASSWindow() : impl_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))

gtk_entry_set_visibility(password_, false);

gtk_grid_attach(right_panel_grid, GTK_WIDGET(server_host_), 1, 0, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(server_sni_), 1, 1, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(server_port_), 1, 2, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(username_), 1, 3, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(password_), 1, 4, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(method_), 1, 5, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(local_host_), 1, 6, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(local_port_), 1, 7, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(doh_url_), 1, 8, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(dot_host_), 1, 9, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(limit_rate_), 1, 10, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(timeout_), 1, 11, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(autostart_), 1, 12, 1, 1);
gtk_grid_attach(right_panel_grid, GTK_WIDGET(systemproxy_), 1, 13, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(server_host_), 2, 0, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(server_sni_), 2, 1, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(server_port_), 2, 2, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(username_), 2, 3, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(password_), 2, 4, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(method_), 2, 5, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(local_host_), 2, 6, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(local_port_), 2, 7, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(doh_url_), 2, 8, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(dot_host_), 2, 9, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(limit_rate_), 2, 10, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(timeout_), 2, 11, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(autostart_), 2, 12, 1, 1);
gtk_grid_attach(grid, GTK_WIDGET(systemproxy_), 2, 13, 1, 1);

gtk_widget_set_margin_top(GTK_WIDGET(grid), 12);
gtk_widget_set_margin_bottom(GTK_WIDGET(grid), 12);

#if GTK_CHECK_VERSION(3, 12, 0)
gtk_widget_set_margin_start(GTK_WIDGET(right_panel_grid), 12);
gtk_widget_set_margin_end(GTK_WIDGET(right_panel_grid), 12);
gtk_widget_set_margin_start(GTK_WIDGET(grid), 12);
gtk_widget_set_margin_end(GTK_WIDGET(grid), 12);
#else
gtk_widget_set_margin_left(GTK_WIDGET(right_panel_grid), 12);
gtk_widget_set_margin_right(GTK_WIDGET(right_panel_grid), 12);
gtk_widget_set_margin_left(GTK_WIDGET(grid), 12);
gtk_widget_set_margin_right(GTK_WIDGET(grid), 12);
#endif
gtk_grid_set_column_spacing(GTK_GRID(right_panel_grid), 12);
gtk_grid_set_row_spacing(GTK_GRID(right_panel_grid), 12);

gtk_widget_set_margin_top(GTK_WIDGET(hbox), 15);
gtk_widget_set_margin_bottom(GTK_WIDGET(hbox), 10);
#if GTK_CHECK_VERSION(3, 12, 0)
gtk_widget_set_margin_start(GTK_WIDGET(hbox), 20);
gtk_widget_set_margin_end(GTK_WIDGET(hbox), 20);
#else
gtk_widget_set_margin_left(GTK_WIDGET(hbox), 20);
gtk_widget_set_margin_right(GTK_WIDGET(hbox), 20);
#endif

gtk_container_add(GTK_CONTAINER(hbox), GTK_WIDGET(right_panel_grid));
gtk_grid_set_column_spacing(GTK_GRID(grid), 12);
gtk_grid_set_row_spacing(GTK_GRID(grid), 12);

gtk_box_pack_start(vbox, GTK_WIDGET(hbox), true, false, 0);
gtk_box_pack_start(vbox, GTK_WIDGET(grid), true, false, 0);

status_bar_ = GTK_STATUSBAR(gtk_statusbar_new());
gtk_statusbar_remove_all(status_bar_, 0);
Expand Down
2 changes: 0 additions & 2 deletions src/gtk4/option_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<interface>
<template class="OptionGtkDialog" parent="GtkDialog">
<property name="title" translatable="yes">Option</property>
<property name="default-width">400</property>
<property name="default-height">200</property>
<child>
<object class="GtkBox" id="content_box">
<property name="orientation">vertical</property>
Expand Down
3 changes: 1 addition & 2 deletions src/gtk4/yass_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<interface>
<template class="YASSGtkWindow" parent="GtkApplicationWindow">
<property name="title" translatable="yes">Yet Another Shadow Socket</property>
<property name="default-width">450</property>
<property name="default-height">420</property>
<property name="resizable">0</property>
<property name="modal">0</property>
<child type="titlebar">
Expand All @@ -26,6 +24,7 @@
<property name="margin-bottom">12</property>
<property name="row-spacing">12</property>
<property name="column-spacing">12</property>
<property name="row-homogeneous">true</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Server Host:</property>
Expand Down
88 changes: 39 additions & 49 deletions src/qt6/yass_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,23 @@ YASSWindow::YASSWindow(QWidget* parent) : QMainWindow(parent) {
menubar->addMenu(help_menu);
vbox->addWidget(menubar);

// Horizon Box << Vertical Box
// Grid << Vertical Box

QHBoxLayout* hbox = new QHBoxLayout;
hbox->addSpacing(20);
hbox->setContentsMargins(0, 0, 0, 0);
QGridLayout* grid = new QGridLayout;
grid->setContentsMargins(12, 12, 12, 12);
grid->setSpacing(12);

// Left Box << Horizon Box << Vertical Box
// Left (Column 0) << Grid << Vertical Box

QVBoxLayout* left_box = new QVBoxLayout;
left_box->addSpacing(0);
left_box->setContentsMargins(15, 0, 15, 0);
start_button_ = new QPushButton(tr("Start"));
stop_button_ = new QPushButton(tr("Stop"));
start_button_->setContentsMargins(0, 30, 0, 30);
connect(start_button_, &QPushButton::clicked, this, &YASSWindow::OnStartButtonClicked);
left_box->addWidget(start_button_);
stop_button_->setContentsMargins(0, 30, 0, 30);
grid->addWidget(start_button_, 2, 0);
connect(stop_button_, &QPushButton::clicked, this, &YASSWindow::OnStopButtonClicked);
stop_button_->setEnabled(false);
left_box->addWidget(stop_button_);
hbox->addItem(left_box);
grid->addWidget(stop_button_, 7, 0);

// Right Grid << Horizon Box << Vertical Box

QGridLayout* right_grid = new QGridLayout;
right_grid->setContentsMargins(12, 12, 24, 12);
right_grid->setSpacing(12);
// Left (Column 1) << Grid << Vertical Box

auto server_host_label = new QLabel(tr("Server Host"));
auto server_sni_label = new QLabel(tr("Server SNI"));
Expand All @@ -106,20 +96,22 @@ YASSWindow::YASSWindow(QWidget* parent) : QMainWindow(parent) {
auto autostart_label = new QLabel(tr("Auto Start"));
auto systemproxy_label = new QLabel(tr("System Proxy"));

right_grid->addWidget(server_host_label, 0, 0);
right_grid->addWidget(server_sni_label, 1, 0);
right_grid->addWidget(server_port_label, 2, 0);
right_grid->addWidget(username_label, 3, 0);
right_grid->addWidget(password_label, 4, 0);
right_grid->addWidget(method_label, 5, 0);
right_grid->addWidget(local_host_label, 6, 0);
right_grid->addWidget(local_port_label, 7, 0);
right_grid->addWidget(doh_url_label, 8, 0);
right_grid->addWidget(dot_host_label, 9, 0);
right_grid->addWidget(limit_rate_label, 10, 0);
right_grid->addWidget(timeout_label, 11, 0);
right_grid->addWidget(autostart_label, 12, 0);
right_grid->addWidget(systemproxy_label, 13, 0);
grid->addWidget(server_host_label, 0, 1);
grid->addWidget(server_sni_label, 1, 1);
grid->addWidget(server_port_label, 2, 1);
grid->addWidget(username_label, 3, 1);
grid->addWidget(password_label, 4, 1);
grid->addWidget(method_label, 5, 1);
grid->addWidget(local_host_label, 6, 1);
grid->addWidget(local_port_label, 7, 1);
grid->addWidget(doh_url_label, 8, 1);
grid->addWidget(dot_host_label, 9, 1);
grid->addWidget(limit_rate_label, 10, 1);
grid->addWidget(timeout_label, 11, 1);
grid->addWidget(autostart_label, 12, 1);
grid->addWidget(systemproxy_label, 13, 1);

// Right (Column 2) << Grid << Vertical Box

server_host_ = new QLineEdit;
server_sni_ = new QLineEdit;
Expand Down Expand Up @@ -159,26 +151,24 @@ YASSWindow::YASSWindow(QWidget* parent) : QMainWindow(parent) {
connect(autostart_, &QPushButton::clicked, this, &YASSWindow::OnAutoStartClicked);
connect(systemproxy_, &QPushButton::clicked, this, &YASSWindow::OnSystemProxyClicked);

right_grid->addWidget(server_host_, 0, 1);
right_grid->addWidget(server_sni_, 1, 1);
right_grid->addWidget(server_port_, 2, 1);
right_grid->addWidget(username_, 3, 1);
right_grid->addWidget(password_, 4, 1);
right_grid->addWidget(method_, 5, 1);
right_grid->addWidget(local_host_, 6, 1);
right_grid->addWidget(local_port_, 7, 1);
right_grid->addWidget(doh_url_, 8, 1);
right_grid->addWidget(dot_host_, 9, 1);
right_grid->addWidget(limit_rate_, 10, 1);
right_grid->addWidget(timeout_, 11, 1);
right_grid->addWidget(autostart_, 12, 1);
right_grid->addWidget(systemproxy_, 13, 1);

hbox->addItem(right_grid);
grid->addWidget(server_host_, 0, 2);
grid->addWidget(server_sni_, 1, 2);
grid->addWidget(server_port_, 2, 2);
grid->addWidget(username_, 3, 2);
grid->addWidget(password_, 4, 2);
grid->addWidget(method_, 5, 2);
grid->addWidget(local_host_, 6, 2);
grid->addWidget(local_port_, 7, 2);
grid->addWidget(doh_url_, 8, 2);
grid->addWidget(dot_host_, 9, 2);
grid->addWidget(limit_rate_, 10, 2);
grid->addWidget(timeout_, 11, 2);
grid->addWidget(autostart_, 12, 2);
grid->addWidget(systemproxy_, 13, 2);

// StatusBar << Vertical Box

vbox->addItem(hbox);
vbox->addItem(grid);
status_bar_ = new QStatusBar;
status_bar_->showMessage(tr("READY"));
vbox->addWidget(status_bar_);
Expand Down

0 comments on commit d70e7a6

Please sign in to comment.