Mostly implement mini window
This commit is contained in:
parent
db580641b9
commit
d8d47a5f83
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,4 @@
|
||||
compile_commands.json
|
||||
build
|
||||
ui/edit-window.glade~
|
||||
ui/settings-window.glade~
|
||||
ui/main-window.glade~
|
||||
ui/*.glade~
|
||||
resources.c
|
||||
|
@ -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_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)
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
gboolean timer_main_window_is_always_on_top(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
|
||||
|
||||
|
56
TimerMiniWindow.c
Normal file
56
TimerMiniWindow.c
Normal 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
20
TimerMiniWindow.h
Normal 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 */
|
@ -4,5 +4,6 @@
|
||||
<file preprocess="xml-stripblanks">ui/main-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/mini-window.glade</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.38.2 -->
|
||||
<!-- Generated with glade 3.40.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.24"/>
|
||||
<template class="TimerMainWindow" parent="GtkApplicationWindow">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="title" translatable="yes">Practice Timer</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<object class="GtkBox" id="mainBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
@ -32,6 +32,10 @@
|
||||
<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="GtkComboBoxText" id="nameBox">
|
||||
<property name="visible">True</property>
|
||||
@ -39,11 +43,36 @@
|
||||
<property name="has-entry">True</property>
|
||||
<child internal-child="entry">
|
||||
<object class="GtkEntry">
|
||||
<property name="can-focus">True</property>
|
||||
<property name="placeholder-text" translatable="yes">What are you up to?</property>
|
||||
<property name="can-focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
</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>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
@ -96,7 +125,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="optionsButton">
|
||||
<object class="GtkButton" id="shrinkButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
@ -104,7 +133,7 @@
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="icon-name">document-properties</property>
|
||||
<property name="icon-name">go-up</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
@ -122,7 +151,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<object class="GtkScrolledWindow" id="taskTreeScroll">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="shadow-type">in</property>
|
||||
|
88
ui/mini-window.glade
Normal file
88
ui/mini-window.glade
Normal 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>
|
Loading…
Reference in New Issue
Block a user