Mostly implement mini window

This commit is contained in:
Alexander Rosenberg 2022-09-08 01:18:05 -07:00
parent db580641b9
commit d8d47a5f83
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730
9 changed files with 279 additions and 16 deletions

4
.gitignore vendored
View File

@ -1,6 +1,4 @@
compile_commands.json compile_commands.json
build build
ui/edit-window.glade~ ui/*.glade~
ui/settings-window.glade~
ui/main-window.glade~
resources.c resources.c

View File

@ -44,7 +44,7 @@ add_custom_command(OUTPUT ${G_RESOURCE_C} MAIN_DEPENDENCY ${G_RESOURCE} DEPENDS
add_custom_target(resource_target DEPENDS ${G_REOSURCE_C}) add_custom_target(resource_target DEPENDS ${G_REOSURCE_C})
add_executable(Practice_Timer main.c TimerApplication.c TimerMainWindow.c TimerEditWindow.c TimerSettingsWindow.c TimerClock.c TimerTaskTree.c TimerGraphWindow.c TimerGraph.c TimerFileWatcher.c ${G_RESOURCE_C}) add_executable(Practice_Timer main.c TimerApplication.c TimerMainWindow.c TimerMiniWindow.c TimerEditWindow.c TimerSettingsWindow.c TimerClock.c TimerTaskTree.c TimerGraphWindow.c TimerGraph.c TimerFileWatcher.c ${G_RESOURCE_C})
set_source_files_properties(${G_RESOURCE_C} PROPERTIES GENERATED TRUE) set_source_files_properties(${G_RESOURCE_C} PROPERTIES GENERATED TRUE)

View File

@ -2,6 +2,7 @@
#include "TimerClock.h" #include "TimerClock.h"
#include "TimerEditWindow.h" #include "TimerEditWindow.h"
#include "TimerSettingsWindow.h" #include "TimerSettingsWindow.h"
#include "TimerMiniWindow.h"
#include <math.h> #include <math.h>
@ -17,11 +18,15 @@ struct _TimerMainWindow {
GtkWidget *optionsButton; GtkWidget *optionsButton;
GtkWidget *taskTreeBox; GtkWidget *taskTreeBox;
GtkWidget *taskTree; GtkWidget *taskTree;
GtkWidget *shrinkButton;
TimerClock *timerClock; TimerClock *timerClock;
TimerClock *updateClock; TimerClock *updateClock;
GKeyFile *keyFile; GKeyFile *keyFile;
TimerMiniWindow *miniWindow;
int miniWindowFirstOpen;
char *labelColorString; char *labelColorString;
GDateTime *lastUpdateTime; GDateTime *lastUpdateTime;
@ -194,6 +199,7 @@ static gboolean timer_main_window_update_time(TimerMainWindow *self) {
timer_clock_is_running(self->timerClock) ? "red" : self->labelColorString, timer_clock_is_running(self->timerClock) ? "red" : self->labelColorString,
hour, minute, second); hour, minute, second);
gtk_label_set_markup(GTK_LABEL(self->timerLabel), time); 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); g_free(time);
return FALSE; return FALSE;
} }
@ -239,11 +245,14 @@ static void start_stop_button_callback(GtkButton *btn, TimerMainWindow *win) {
if (timer_clock_is_running(win->timerClock)) { if (timer_clock_is_running(win->timerClock)) {
timer_clock_stop(win->timerClock); timer_clock_stop(win->timerClock);
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Start"); 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); timer_main_window_update_time(win);
} else { } else {
timer_clock_start(win->timerClock); timer_clock_start(win->timerClock);
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Stop"); 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(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); gtk_widget_set_sensitive(win->saveButton, TRUE);
win->startTime = g_date_time_new_now_local(); win->startTime = g_date_time_new_now_local();
timer_main_window_update_time(win); timer_main_window_update_time(win);
@ -257,7 +266,9 @@ static void reset_button_callback(GtkButton *btn, TimerMainWindow *win) {
win->currentTime = 0; win->currentTime = 0;
timer_main_window_update_time(win); timer_main_window_update_time(win);
gtk_button_set_label(GTK_BUTTON(win->startStopButton), "Start"); 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(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); gtk_widget_set_sensitive(win->saveButton, FALSE);
g_date_time_unref(win->startTime); g_date_time_unref(win->startTime);
win->startTime = NULL; win->startTime = NULL;
@ -345,6 +356,16 @@ static void timer_main_window_get_defualt_label_color(TimerMainWindow *self) {
(int)round(color.blue * 255)); (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) { static gboolean window_configure_callback(TimerMainWindow *win) {
int x, y, w, h; int x, y, w, h;
gtk_window_get_size(GTK_WINDOW(win), &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; 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) { static void timer_main_window_finalize(GObject *self) {
g_free(TIMER_MAIN_WINDOW(self)->labelColorString); g_free(TIMER_MAIN_WINDOW(self)->labelColorString);
g_object_unref(TIMER_MAIN_WINDOW(self)->timerClock); g_object_unref(TIMER_MAIN_WINDOW(self)->timerClock);
@ -415,6 +480,8 @@ static void timer_main_window_class_init(TimerMainWindowClass *class) {
TimerMainWindow, resetButton); TimerMainWindow, resetButton);
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class), gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class),
TimerMainWindow, saveButton); 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_bind_template_child_internal(
GTK_WIDGET_CLASS(class), TimerMainWindow, optionsButton); GTK_WIDGET_CLASS(class), TimerMainWindow, optionsButton);
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class), 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_CALLBACK(save_button_callback), self);
g_signal_connect(self->timerButton, "clicked", g_signal_connect(self->timerButton, "clicked",
G_CALLBACK(timer_button_callback), self); 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, "destroy", G_CALLBACK(window_destroy_callback), NULL);
g_signal_connect(self, "configure-event", G_CALLBACK(window_configure_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); g_signal_connect(self, "delete-event", G_CALLBACK(window_delete_event), NULL);
timer_main_window_get_defualt_label_color(self); timer_main_window_get_defualt_label_color(self);
init_mini_window(self);
} }

View File

@ -17,7 +17,8 @@ TimerDataPoint *timer_main_window_get_task_data(TimerMainWindow *self, gsize *le
TimerDataPoint *timer_main_window_get_day_data(TimerMainWindow *self, gsize *len); TimerDataPoint *timer_main_window_get_day_data(TimerMainWindow *self, gsize *len);
gboolean timer_main_window_is_always_on_top(TimerMainWindow *self); gboolean timer_main_window_is_always_on_top(TimerMainWindow *self);
GDateTime *timer_main_window_get_last_task_end(TimerMainWindow *self); GDateTime *timer_main_window_get_last_task_end(TimerMainWindow *self);
void timer_main_window_save_mini_window_pos(TimerMainWindow *self, int x, int y);
void timer_main_window_read_mini_window_pos(TimerMainWindow *self, int *x, int *y);
G_END_DECLS G_END_DECLS

56
TimerMiniWindow.c Normal file
View File

@ -0,0 +1,56 @@
#include "TimerMiniWindow.h"
struct _TimerMiniWindow {
GtkWindow parent;
GtkWindow *parentWindow;
GtkWidget *startStopButton;
GtkWidget *resetButton;
GtkWidget *expandButton;
GtkWidget *timerLabel;
};
G_DEFINE_TYPE(TimerMiniWindow, timer_mini_window, GTK_TYPE_WINDOW);
TimerMiniWindow *timer_mini_window_new(GtkWindow *parent) {
TimerMiniWindow *self = g_object_new(TIMER_TYPE_MINI_WINDOW, NULL);
self->parentWindow = parent;
return self;
}
GtkWindow *timer_mini_window_get_parent(TimerMiniWindow *self) {
return self->parentWindow;
}
GtkLabel *timer_mini_window_get_timer_label(TimerMiniWindow *self) {
return GTK_LABEL(self->timerLabel);
}
GtkButton *timer_mini_window_get_start_stop_button(TimerMiniWindow *self) {
return GTK_BUTTON(self->startStopButton);
}
GtkButton *timer_mini_window_get_reset_button(TimerMiniWindow *self) {
return GTK_BUTTON(self->resetButton);
}
GtkButton *timer_mini_window_get_expand_button(TimerMiniWindow *self) {
return GTK_BUTTON(self->expandButton);
}
void timer_mini_window_class_init(TimerMiniWindowClass *class) {
gtk_widget_class_set_template_from_resource(
GTK_WIDGET_CLASS(class), "/zander/practicetimer/ui/mini-window.glade");
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class),
TimerMiniWindow, startStopButton);
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class),
TimerMiniWindow, resetButton);
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class),
TimerMiniWindow, expandButton);
gtk_widget_class_bind_template_child_internal(GTK_WIDGET_CLASS(class),
TimerMiniWindow, timerLabel);
}
void timer_mini_window_init(TimerMiniWindow *self) {
gtk_widget_init_template(GTK_WIDGET(self));
}

20
TimerMiniWindow.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef INCLUDED_TIMER_MINI_WINDOW_H
#define INCLUDED_TIMER_MINI_WINDOW_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define TIMER_TYPE_MINI_WINDOW timer_mini_window_get_type()
G_DECLARE_FINAL_TYPE(TimerMiniWindow, timer_mini_window, TIMER, MINI_WINDOW, GtkWindow)
TimerMiniWindow *timer_mini_window_new(GtkWindow *parent);
GtkWindow *timer_mini_window_get_parent(TimerMiniWindow *self);
GtkLabel *timer_mini_window_get_timer_label(TimerMiniWindow *self);
GtkButton *timer_mini_window_get_start_stop_button(TimerMiniWindow *self);
GtkButton *timer_mini_window_get_reset_button(TimerMiniWindow *self);
GtkButton *timer_mini_window_get_expand_button(TimerMiniWindow *self);
G_END_DECLS
#endif /* INCLUDED_TIMER_MINI_WINDOW_H */

View File

@ -4,5 +4,6 @@
<file preprocess="xml-stripblanks">ui/main-window.glade</file> <file preprocess="xml-stripblanks">ui/main-window.glade</file>
<file preprocess="xml-stripblanks">ui/edit-window.glade</file> <file preprocess="xml-stripblanks">ui/edit-window.glade</file>
<file preprocess="xml-stripblanks">ui/settings-window.glade</file> <file preprocess="xml-stripblanks">ui/settings-window.glade</file>
<file preprocess="xml-stripblanks">ui/mini-window.glade</file>
</gresource> </gresource>
</gresources> </gresources>

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 --> <!-- Generated with glade 3.40.0 -->
<interface> <interface>
<requires lib="gtk+" version="3.24"/> <requires lib="gtk+" version="3.24"/>
<template class="TimerMainWindow" parent="GtkApplicationWindow"> <template class="TimerMainWindow" parent="GtkApplicationWindow">
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="title" translatable="yes">Practice Timer</property> <property name="title" translatable="yes">Practice Timer</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox" id="mainBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
@ -33,15 +33,44 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkComboBoxText" id="nameBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="has-entry">True</property> <child>
<child internal-child="entry"> <object class="GtkComboBoxText" id="nameBox">
<object class="GtkEntry"> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">False</property>
<property name="placeholder-text" translatable="yes">What are you up to?</property> <property name="has-entry">True</property>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can-focus">False</property>
</object>
</child>
</object> </object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="optionsButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">document-properties</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child> </child>
</object> </object>
<packing> <packing>
@ -96,7 +125,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="optionsButton"> <object class="GtkButton" id="shrinkButton">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="receives-default">True</property> <property name="receives-default">True</property>
@ -104,7 +133,7 @@
<object class="GtkImage"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="icon-name">document-properties</property> <property name="icon-name">go-up</property>
</object> </object>
</child> </child>
</object> </object>
@ -122,7 +151,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkScrolledWindow"> <object class="GtkScrolledWindow" id="taskTreeScroll">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="shadow-type">in</property> <property name="shadow-type">in</property>

88
ui/mini-window.glade Normal file
View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<template class="TimerMiniWindow" parent="GtkWindow">
<property name="can-focus">False</property>
<property name="resizable">False</property>
<property name="type-hint">utility</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="timerLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">00:00:00</property>
<attributes>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="startStopButton">
<property name="label" translatable="yes">Start</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="resetButton">
<property name="label" translatable="yes">Reset</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="expandButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">go-down</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</template>
</interface>