X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/52a3ff02366002595d19efd9f5e29fc523ae7d2c..45fc0b87cfcdcb7ee121034f369804b72b49b57e:/disobedience/disobedience.c diff --git a/disobedience/disobedience.c b/disobedience/disobedience.c index 10b62eb..639eb73 100644 --- a/disobedience/disobedience.c +++ b/disobedience/disobedience.c @@ -44,6 +44,9 @@ GtkWidget *report_label; /** @brief Main tab group */ GtkWidget *tabs; +/** @brief Mini-mode widget for playing track */ +GtkWidget *playing_mini; + /** @brief Main client */ disorder_eclient *client; @@ -104,8 +107,6 @@ static GtkWidget *queue; static GtkWidget *notebook_box; -static int main_current_fullmode = 1; - static void check_rtp_address(const char *event, void *eventdata, void *callbackdata); @@ -171,50 +172,78 @@ static GtkWidget *notebook(void) { return tabs; } +/* Tracking of window sizes */ +static int toplevel_width = 640, toplevel_height = 480; +static int mini_width = 480, mini_height = 140; +static struct timeval last_mode_switch; + static void main_minimode(const char attribute((unused)) *event, void attribute((unused)) *evendata, void attribute((unused)) *callbackdata) { - if(full_mode == main_current_fullmode) - return; if(full_mode) { - /* Remove queue from display */ - g_object_ref(queue); - gtk_container_remove(GTK_CONTAINER(notebook_box), queue); - /* Add queue to notebook */ - gtk_notebook_prepend_page(GTK_NOTEBOOK(tabs), queue, - gtk_label_new("Queue")); - g_object_unref(queue); - /* Add notebook to display */ - gtk_container_add(GTK_CONTAINER(notebook_box), tabs); - g_object_unref(tabs); + gtk_window_resize(GTK_WINDOW(toplevel), toplevel_width, toplevel_height); + gtk_widget_show(tabs); + gtk_widget_hide(playing_mini); /* Show the queue (bit confusing otherwise!) */ gtk_notebook_set_current_page(GTK_NOTEBOOK(tabs), 0); } else { - /* Remove notebook from display */ - g_object_ref(tabs); - gtk_container_remove(GTK_CONTAINER(notebook_box), tabs); - /* Remove queue from notebook */ - g_object_ref(queue); - gtk_container_remove(GTK_CONTAINER(tabs), queue); - /* Add queue to display */ - gtk_container_add(GTK_CONTAINER(notebook_box), queue); - g_object_unref(queue); + gtk_window_resize(GTK_WINDOW(toplevel), mini_width, mini_height); + gtk_widget_hide(tabs); + gtk_widget_show(playing_mini); + } + xgettimeofday(&last_mode_switch, NULL); +} + +/* Called when the window size is allocate */ +static void toplevel_size_allocate(GtkWidget attribute((unused)) *w, + GtkAllocation *a, + gpointer attribute((unused)) user_data) { + struct timeval now; + xgettimeofday(&now, NULL); + if(tvdouble(tvsub(now, last_mode_switch)) < 0.5) { + /* Suppress size-allocate signals that are within half a second of a mode + * switch: they are quite likely to be the result of re-arranging widgets + * within the old size, not the application of the new size. Yes, this is + * a disgusting hack! */ + return; /* OMG too soon! */ + } + if(full_mode) { + toplevel_width = a->width; + toplevel_height = a->height; + } else { + mini_width = a->width; + mini_height = a->height; } - main_current_fullmode = full_mode; +} + +/* Periodically check the toplevel's size + * (the hack in toplevel_size_allocate() means we could in principle + * miss a user-initiated resize) + */ +static void check_toplevel_size(const char attribute((unused)) *event, + void attribute((unused)) *evendata, + void attribute((unused)) *callbackdata) { + GtkAllocation a; + gtk_window_get_size(GTK_WINDOW(toplevel), &a.width, &a.height); + toplevel_size_allocate(NULL, &a, NULL); } /** @brief Create and populate the main window */ static void make_toplevel_window(void) { - GtkWidget *const vbox = gtk_vbox_new(FALSE, 1); + GtkWidget *const vbox = gtk_vbox_new(FALSE/*homogeneous*/, 1/*spacing*/); GtkWidget *const rb = report_box(); D(("top_window")); toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* default size is too small */ - gtk_window_set_default_size(GTK_WINDOW(toplevel), 640, 480); + gtk_window_set_default_size(GTK_WINDOW(toplevel), + toplevel_width, toplevel_height); /* terminate on close */ g_signal_connect(G_OBJECT(toplevel), "delete_event", G_CALLBACK(delete_event), NULL); + /* track size */ + g_signal_connect(G_OBJECT(toplevel), "size-allocate", + G_CALLBACK(toplevel_size_allocate), NULL); /* lay out the window */ gtk_window_set_title(GTK_WINDOW(toplevel), "Disobedience"); gtk_container_add(GTK_CONTAINER(toplevel), vbox); @@ -229,6 +258,12 @@ static void make_toplevel_window(void) { FALSE, /* expand */ FALSE, /* fill */ 0); + playing_mini = playing_widget(); + gtk_box_pack_start(GTK_BOX(vbox), + playing_mini, + FALSE, + FALSE, + 0); notebook_box = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(notebook_box), notebook()); gtk_container_add(GTK_CONTAINER(vbox), notebook_box); @@ -239,6 +274,7 @@ static void make_toplevel_window(void) { 0); gtk_widget_set_style(toplevel, tool_style); event_register("mini-mode-changed", main_minimode, 0); + event_register("periodic-fast", check_toplevel_size, 0); } static void userinfo_rights_completed(void attribute((unused)) *v, @@ -518,6 +554,7 @@ int main(int argc, char **argv) { /* reset styles now everything has its name */ gtk_rc_reset_styles(gtk_settings_get_for_screen(gdk_screen_get_default())); gtk_widget_show_all(toplevel); + gtk_widget_hide(playing_mini); /* issue a NOP every so often */ g_timeout_add_full(G_PRIORITY_LOW, 2000/*interval, ms*/,