Mostly implement mini window

This commit is contained in:
2022-09-08 01:18:05 -07:00
parent db580641b9
commit d8d47a5f83
9 changed files with 279 additions and 16 deletions
+70
View File
@@ -2,6 +2,7 @@
#include "TimerClock.h"
#include "TimerEditWindow.h"
#include "TimerSettingsWindow.h"
#include "TimerMiniWindow.h"
#include <math.h>
@@ -17,11 +18,15 @@ struct _TimerMainWindow {
GtkWidget *optionsButton;
GtkWidget *taskTreeBox;
GtkWidget *taskTree;
GtkWidget *shrinkButton;
TimerClock *timerClock;
TimerClock *updateClock;
GKeyFile *keyFile;
TimerMiniWindow *miniWindow;
int miniWindowFirstOpen;
char *labelColorString;
GDateTime *lastUpdateTime;
@@ -194,6 +199,7 @@ static gboolean timer_main_window_update_time(TimerMainWindow *self) {
timer_clock_is_running(self->timerClock) ? "red" : self->labelColorString,
hour, minute, second);
gtk_label_set_markup(GTK_LABEL(self->timerLabel), time);
gtk_label_set_markup(timer_mini_window_get_timer_label(self->miniWindow), time);
g_free(time);
return FALSE;
}
@@ -239,11 +245,14 @@ static void start_stop_button_callback(GtkButton *btn, TimerMainWindow *win) {
if (timer_clock_is_running(win->timerClock)) {
timer_clock_stop(win->timerClock);
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Start");
gtk_button_set_label(timer_mini_window_get_start_stop_button(win->miniWindow), "Start");
timer_main_window_update_time(win);
} else {
timer_clock_start(win->timerClock);
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Stop");
gtk_button_set_label(timer_mini_window_get_start_stop_button(win->miniWindow), "Stop");
gtk_widget_set_sensitive(win->resetButton, TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(timer_mini_window_get_reset_button(win->miniWindow)), TRUE);
gtk_widget_set_sensitive(win->saveButton, TRUE);
win->startTime = g_date_time_new_now_local();
timer_main_window_update_time(win);
@@ -257,7 +266,9 @@ static void reset_button_callback(GtkButton *btn, TimerMainWindow *win) {
win->currentTime = 0;
timer_main_window_update_time(win);
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Start");
gtk_button_set_label(timer_mini_window_get_start_stop_button(win->miniWindow), "Start");
gtk_widget_set_sensitive(win->resetButton, FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(timer_mini_window_get_reset_button(win->miniWindow)), FALSE);
gtk_widget_set_sensitive(win->saveButton, FALSE);
g_date_time_unref(win->startTime);
win->startTime = NULL;
@@ -345,6 +356,16 @@ static void timer_main_window_get_defualt_label_color(TimerMainWindow *self) {
(int)round(color.blue * 255));
}
void timer_main_window_save_mini_window_pos(TimerMainWindow *self, int x, int y) {
g_key_file_set_integer(self->keyFile, "Cache", "smallX", x);
g_key_file_set_integer(self->keyFile, "Cache", "smallY", y);
}
void timer_main_window_read_mini_window_pos(TimerMainWindow *self, int *x, int *y) {
*x = g_key_file_get_integer(self->keyFile, "Cache", "smallX", NULL);
*y = g_key_file_get_integer(self->keyFile, "Cache", "smallY", NULL);
}
static gboolean window_configure_callback(TimerMainWindow *win) {
int x, y, w, h;
gtk_window_get_size(GTK_WINDOW(win), &w, &h);
@@ -386,6 +407,50 @@ static gboolean window_delete_event(TimerMainWindow *win, GdkEvent *evt) {
return FALSE;
}
static gboolean mini_window_configure_callback(TimerMiniWindow *win) {
int x, y;
gtk_window_get_position(GTK_WINDOW(win), &x, &y);
timer_main_window_save_mini_window_pos(
TIMER_MAIN_WINDOW(timer_mini_window_get_parent(win)), x, y);
return FALSE;
}
static gboolean mini_window_delete_event(TimerMiniWindow *win, GdkEvent *evt) {
gtk_widget_hide(GTK_WIDGET(win));
gtk_widget_show_all(GTK_WIDGET(timer_mini_window_get_parent(win)));
return FALSE;
}
static void mini_window_expand_callback(GtkButton *btn, TimerMainWindow *win) {
gtk_widget_hide(GTK_WIDGET(win->miniWindow));
gtk_widget_show_all(GTK_WIDGET(win));
}
static void init_mini_window(TimerMainWindow *self) {
self->miniWindowFirstOpen = TRUE;
self->miniWindow = timer_mini_window_new(GTK_WINDOW(self));
g_signal_connect(self->miniWindow, "configure-event", G_CALLBACK(mini_window_configure_callback), NULL);
g_signal_connect(self->miniWindow, "delete-event", G_CALLBACK(mini_window_delete_event), NULL);
g_signal_connect(timer_mini_window_get_start_stop_button(self->miniWindow),
"clicked", G_CALLBACK(start_stop_button_callback), self);
g_signal_connect(timer_mini_window_get_reset_button(self->miniWindow),
"clicked", G_CALLBACK(reset_button_callback), self);
g_signal_connect(timer_mini_window_get_expand_button(self->miniWindow),
"clicked", G_CALLBACK(mini_window_expand_callback), self);
}
static void main_window_collapse_callback(GtkButton *btn, TimerMainWindow *win) {
gtk_widget_hide(GTK_WIDGET(win));
gtk_widget_show_all(GTK_WIDGET(win->miniWindow));
if (win->miniWindowFirstOpen) {
gtk_window_set_keep_above(GTK_WINDOW(win->miniWindow), TRUE);
int x, y;
timer_main_window_read_mini_window_pos(win, &x, &y);
gtk_window_move(GTK_WINDOW(win->miniWindow), x, y);
win->miniWindowFirstOpen = FALSE;
}
}
static void timer_main_window_finalize(GObject *self) {
g_free(TIMER_MAIN_WINDOW(self)->labelColorString);
g_object_unref(TIMER_MAIN_WINDOW(self)->timerClock);
@@ -415,6 +480,8 @@ static void timer_main_window_class_init(TimerMainWindowClass *class) {
TimerMainWindow, resetButton);
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class),
TimerMainWindow, saveButton);
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class),
TimerMainWindow, shrinkButton);
gtk_widget_class_bind_template_child_internal(
GTK_WIDGET_CLASS(class), TimerMainWindow, optionsButton);
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class),
@@ -440,8 +507,11 @@ static void timer_main_window_init(TimerMainWindow *self) {
G_CALLBACK(save_button_callback), self);
g_signal_connect(self->timerButton, "clicked",
G_CALLBACK(timer_button_callback), self);
g_signal_connect(self->shrinkButton, "clicked",
G_CALLBACK(main_window_collapse_callback), self);
g_signal_connect(self, "destroy", G_CALLBACK(window_destroy_callback), NULL);
g_signal_connect(self, "configure-event", G_CALLBACK(window_configure_callback), NULL);
g_signal_connect(self, "delete-event", G_CALLBACK(window_delete_event), NULL);
timer_main_window_get_defualt_label_color(self);
init_mini_window(self);
}