Skip to content

Commit

Permalink
Restore position when restoring window closed to system tray (issue Q…
Browse files Browse the repository at this point in the history
…alculate#220); Save mode/preferences and definitions before closing to system tray; Use gtk_window_present_with_time()
  • Loading branch information
hanna-kn committed Jan 12, 2021
1 parent f27f7a7 commit ce647a7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2021-01-12 Hanna Knutsson <hanna.knutsson@protonmail.com>

* Restore position when restoring window closed to system tray
* Save mode/preferences and definitions before closing to system tray

2021-01-01 Hanna Knutsson <hanna.knutsson@protonmail.com>

* Make up/down keys in expression history smarter (cycle through expression history in less cases)
Expand Down
39 changes: 22 additions & 17 deletions src/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14273,7 +14273,7 @@ void insert_function(MathFunction *f, GtkWidget *parent = NULL, bool add_to_menu
}
gtk_widget_grab_focus(fd->entry[0]);
}
gtk_window_present(GTK_WINDOW(fd->dialog));
gtk_window_present_with_time(GTK_WINDOW(fd->dialog), GDK_CURRENT_TIME);
return;
}

Expand Down Expand Up @@ -17602,7 +17602,7 @@ void manage_variables() {
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
}
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}

/*
Expand All @@ -17616,7 +17616,7 @@ void manage_functions() {
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
}
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}

/*
Expand All @@ -17630,7 +17630,7 @@ void manage_units() {
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
}
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}

/*
Expand Down Expand Up @@ -18016,7 +18016,7 @@ void on_popup_menu_item_input_base(GtkMenuItem *w, gpointer data) {
GtkWidget *dialog = get_set_base_dialog();
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(setbase_builder, "set_base_radiobutton_input_other")), TRUE);
gtk_widget_grab_focus(GTK_WIDGET(gtk_builder_get_object(setbase_builder, "set_base_entry_input_other")));
} else {
Expand Down Expand Up @@ -21060,8 +21060,13 @@ void on_menu_item_quit_activate(GtkMenuItem*, gpointer user_data) {
on_gcalc_exit(NULL, NULL, user_data);
}

extern gint hidden_x, hidden_y;
void on_main_window_close(GtkWidget *w, GdkEvent *event, gpointer user_data) {
if(has_systray_icon()) {
if(save_mode_on_exit) save_mode();
else save_preferences();
if(save_defs_on_exit) save_defs();
gtk_window_get_position(GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")), &hidden_x, &hidden_y);
gtk_widget_hide(w);
} else {
on_gcalc_exit(w, event, user_data);
Expand Down Expand Up @@ -25350,7 +25355,7 @@ void on_popup_menu_item_history_search_activate(GtkMenuItem*, gpointer) {
gtk_expander_set_expanded(GTK_EXPANDER(expander_history), TRUE);
if(history_search_dialog) {
gtk_widget_show(history_search_dialog);
gtk_window_present(GTK_WINDOW(history_search_dialog));
gtk_window_present_with_time(GTK_WINDOW(history_search_dialog), GDK_CURRENT_TIME);
gtk_widget_grab_focus(history_search_entry);
return;
}
Expand Down Expand Up @@ -25874,7 +25879,7 @@ void on_menu_item_datasets_activate(GtkMenuItem*, gpointer) {
GtkWidget *dialog = get_datasets_dialog();
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}

void on_menu_item_import_csv_file_activate(GtkMenuItem*, gpointer) {
Expand Down Expand Up @@ -27658,7 +27663,7 @@ void on_menu_item_custom_base_activate(GtkMenuItem *w, gpointer) {
GtkWidget *dialog = get_set_base_dialog();
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtk_builder_get_object(setbase_builder, "set_base_radiobutton_output_other")), TRUE);
gtk_widget_grab_focus(GTK_WIDGET(gtk_builder_get_object(setbase_builder, "set_base_entry_output_other")));
}
Expand Down Expand Up @@ -27829,7 +27834,7 @@ void on_menu_item_set_base_activate(GtkMenuItem*, gpointer) {
GtkWidget *dialog = get_set_base_dialog();
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}
void on_set_base_radiobutton_input_binary_toggled(GtkToggleButton *w, gpointer) {
if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) return;
Expand Down Expand Up @@ -28060,7 +28065,7 @@ void convert_number_bases(const gchar *initial_expression, bool b_result) {
}
}
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}
void on_menu_item_convert_number_bases_activate(GtkMenuItem*, gpointer) {
if(displayed_mstruct && !result_text_empty()) return convert_number_bases(((mstruct->isNumber() && !mstruct->number().hasImaginaryPart()) || mstruct->isUndefined()) ? get_result_text().c_str() : "", true);
Expand Down Expand Up @@ -28090,7 +28095,7 @@ void convert_floatingpoint(const gchar *initial_expression, bool b_result) {
}
}
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}
void on_menu_item_convert_floatingpoint_activate(GtkMenuItem*, gpointer) {
if(displayed_mstruct && !result_text_empty()) return convert_floatingpoint(((mstruct->isNumber() && !mstruct->number().hasImaginaryPart()) || mstruct->isUndefined()) ? get_result_text().c_str() : "", true);
Expand All @@ -28109,7 +28114,7 @@ void show_percentage_dialog(const gchar *initial_expression) {
if(strlen(initial_expression) > 0 && strcmp(initial_expression, "0") != 0) gtk_entry_set_text(GTK_ENTRY(gtk_builder_get_object(percentage_builder, "percentage_entry_1")), initial_expression);
gtk_widget_grab_focus(GTK_WIDGET(gtk_builder_get_object(percentage_builder, "percentage_entry_1")));
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}
void on_menu_item_show_percentage_dialog_activate(GtkMenuItem*, gpointer) {
if(!result_text_empty()) return show_percentage_dialog(get_result_text().c_str());
Expand All @@ -28123,7 +28128,7 @@ void show_calendarconversion_dialog() {
gtk_widget_grab_focus(GTK_WIDGET(gtk_builder_get_object(calendarconversion_builder, "year_1")));
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}
bool block_calendar_conversion = false;
void calendar_changed(GtkWidget*, gpointer data) {
Expand Down Expand Up @@ -28201,7 +28206,7 @@ void on_menu_item_periodic_table_activate(GtkMenuItem*, gpointer) {
GtkWidget *dialog = get_periodic_dialog();
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}
void on_menu_item_plot_functions_activate(GtkMenuItem*, gpointer) {
GtkWidget *dialog = get_plot_dialog();
Expand Down Expand Up @@ -28283,7 +28288,7 @@ void on_menu_item_plot_functions_activate(GtkMenuItem*, gpointer) {

gtk_widget_grab_focus(GTK_WIDGET(gtk_builder_get_object(plot_builder, "plot_entry_expression")));
} else {
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}
}
void on_plot_dialog_hide(GtkWidget*, gpointer) {
Expand Down Expand Up @@ -32841,15 +32846,15 @@ void on_menu_item_customize_buttons_activate(GtkMenuItem*, gpointer) {
gtk_window_get_size(GTK_WINDOW(dialog), &w, NULL);
gtk_widget_set_size_request(dialog, w, -1);
}
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}

void on_menu_item_edit_shortcuts_activate(GtkMenuItem*, gpointer) {
GtkWidget *dialog = get_shortcuts_dialog();
gtk_widget_grab_focus(GTK_WIDGET(gtk_builder_get_object(shortcuts_builder, "shortcuts_treeview")));
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
gtk_widget_show(dialog);
gtk_window_present(GTK_WINDOW(dialog));
gtk_window_present_with_time(GTK_WINDOW(dialog), GDK_CURRENT_TIME);
}

void on_tShortcuts_selection_changed(GtkTreeSelection *treeselection, gpointer) {
Expand Down
9 changes: 7 additions & 2 deletions src/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ gint compare_categories(gconstpointer a, gconstpointer b) {
}

bool border_tested = false;
gint hidden_x = -1, hidden_y = -1;

#ifdef _WIN32
# include <gdk/gdkwin32.h>
Expand All @@ -232,8 +233,12 @@ static HWND hwnd = NULL;

INT_PTR CALLBACK tray_window_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
if(message == WIN_TRAY_ICON_MESSAGE && (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONUP)) {
gtk_widget_show(mainwindow);
gtk_window_present(GTK_WINDOW(mainwindow));
if(hidden_x >= 0) {
gtk_widget_show(mainwindow);
gtk_window_move(GTK_WINDOW(mainwindow), hidden_x, hidden_y);
hidden_x = -1;
}
gtk_window_present_with_time(GTK_WINDOW(mainwindow), GDK_CURRENT_TIME);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Expand Down
17 changes: 14 additions & 3 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extern PrintOptions printops;
extern bool ignore_locale;
extern bool title_modified;
extern bool minimal_mode;
extern gint hidden_x, hidden_y;
bool check_version = false;
string custom_title;

Expand Down Expand Up @@ -323,10 +324,15 @@ static void qalculate_activate(GtkApplication *app) {

GList *list;

list = gtk_application_get_windows (app);
list = gtk_application_get_windows(app);

if(list) {
gtk_window_present(GTK_WINDOW(list->data));
if(hidden_x >= 0) {
gtk_widget_show(GTK_WIDGET(list->data));
gtk_window_move(GTK_WINDOW(list->data), hidden_x, hidden_y);
hidden_x = -1;
}
gtk_window_present_with_time(GTK_WINDOW(list->data), GDK_CURRENT_TIME);
return;
}

Expand Down Expand Up @@ -432,7 +438,12 @@ static gint qalculate_command_line(GtkApplication *app, GApplicationCommandLine
title_modified = true;
g_free(str);
}
gtk_window_present(GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")));
if(hidden_x >= 0) {
gtk_widget_show(GTK_WIDGET(gtk_builder_get_object(main_builder, "main_window")));
gtk_window_move(GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")), hidden_x, hidden_y);
hidden_x = -1;
}
gtk_window_present_with_time(GTK_WINDOW(gtk_builder_get_object(main_builder, "main_window")), GDK_CURRENT_TIME);
if(!file_arg.empty()) execute_from_file(file_arg);
if(!calc_arg.empty()) {
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(gtk_builder_get_object(main_builder, "expressionbuffer")), calc_arg.c_str(), -1);
Expand Down

0 comments on commit ce647a7

Please sign in to comment.