diff --git a/shell/taskband/src/application.c b/shell/taskband/src/application.c index d08922b..ad3b9f6 100644 --- a/shell/taskband/src/application.c +++ b/shell/taskband/src/application.c @@ -55,6 +55,15 @@ static const GOptionEntry S_OPTIONS[] = { "Quit a running Windows taskband instance.", NULL }, + { + "start", + 's', + G_OPTION_FLAG_NONE, + G_OPTION_ARG_NONE, + NULL, + "Toggle the Start menu open or closed.", + NULL + }, { 0 } }; @@ -140,10 +149,13 @@ static gint wintc_taskband_application_command_line( GApplicationCommandLine* command_line ) { + WinTCTaskbandApplication* taskband_app = + WINTC_TASKBAND_APPLICATION(application); + GVariantDict* options = g_application_command_line_get_options_dict(command_line); - // Just check for --quit + // --quit takes priority // if (g_variant_dict_contains(options, "quit")) { @@ -151,6 +163,15 @@ static gint wintc_taskband_application_command_line( return 0; } + // Handle action switches + // + if (g_variant_dict_contains(options, "start")) + { + wintc_taskband_window_toggle_start_menu( + WINTC_TASKBAND_WINDOW(taskband_app->host_window) + ); + } + g_application_activate(application); return 0; diff --git a/shell/taskband/src/start/personal.c b/shell/taskband/src/start/personal.c index abc703f..c10b0b0 100644 --- a/shell/taskband/src/start/personal.c +++ b/shell/taskband/src/start/personal.c @@ -1062,6 +1062,13 @@ static void on_personal_menu_hide( WinTCTaskbandToolbar* toolbar = WINTC_TASKBAND_TOOLBAR(user_data); WinTCToolbarStart* toolbar_start = WINTC_TOOLBAR_START(user_data); + // Track the last closed time, important for toggling the menu properly + // (see toolbar.c) + // + toolbar_start->time_menu_closed = g_get_monotonic_time(); + + // Sync Start button state + // toolbar_start->sync_button = TRUE; gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(toolbar->widget_root), diff --git a/shell/taskband/src/start/shared.h b/shell/taskband/src/start/shared.h index ba4027f..9fa4e0e 100644 --- a/shell/taskband/src/start/shared.h +++ b/shell/taskband/src/start/shared.h @@ -49,6 +49,8 @@ typedef struct _WinTCToolbarStart // gboolean sync_button; gboolean sync_menu_should_close; + + gint64 time_menu_closed; } WinTCToolbarStart; #endif diff --git a/shell/taskband/src/start/toolbar.c b/shell/taskband/src/start/toolbar.c index d1e4a36..525ad68 100644 --- a/shell/taskband/src/start/toolbar.c +++ b/shell/taskband/src/start/toolbar.c @@ -123,6 +123,32 @@ static void wintc_toolbar_start_dispose( (G_OBJECT_CLASS(wintc_toolbar_start_parent_class))->dispose(object); } +// +// PUBLIC FUNCTIONS +// +void wintc_toolbar_start_toggle_menu( + WinTCToolbarStart* toolbar_start +) +{ + WinTCTaskbandToolbar* toolbar = WINTC_TASKBAND_TOOLBAR(toolbar_start); + + GtkToggleButton* start_button = GTK_TOGGLE_BUTTON(toolbar->widget_root); + + // Rate-limit toggling, prevents glitchy behaviour especially when launched + // via cmdline/keyboard shortcut (so the menu loses focus then immediately + // toggles open) + // + if (g_get_monotonic_time() - toolbar_start->time_menu_closed < 150000) + { + return; + } + + gtk_toggle_button_set_active( + start_button, + !gtk_toggle_button_get_active(start_button) + ); +} + // // CALLBACKS // diff --git a/shell/taskband/src/start/toolbar.h b/shell/taskband/src/start/toolbar.h index 365d7a6..e6c8310 100644 --- a/shell/taskband/src/start/toolbar.h +++ b/shell/taskband/src/start/toolbar.h @@ -4,6 +4,8 @@ #include #include +#include "shared.h" + // // GTK OOP BOILERPLATE // @@ -16,5 +18,12 @@ GType wintc_toolbar_start_get_type(void) G_GNUC_CONST; +// +// PUBLIC FUNCTIONS +// +void wintc_toolbar_start_toggle_menu( + WinTCToolbarStart* toolbar_start +); + #endif diff --git a/shell/taskband/src/window.c b/shell/taskband/src/window.c index 69726f1..dfdcd8a 100644 --- a/shell/taskband/src/window.c +++ b/shell/taskband/src/window.c @@ -33,7 +33,7 @@ static void wintc_taskband_window_dispose( GObject* object ); -static void wintc_taskband_window_create_toolbar( +static WinTCTaskbandToolbar* wintc_taskband_window_create_toolbar( WinTCTaskbandWindow* taskband, GType toolbar_type, gboolean expand @@ -71,13 +71,13 @@ struct _WinTCTaskbandWindow // UI // - GtkWidget* main_box; - - GtkWidget* notification_area; - GtkWidget* start_button; - GtkWidget* taskbuttons; + GtkWidget* main_box; GSList* toolbars; + + WinTCTaskbandToolbar* toolbar_notifarea; + WinTCTaskbandToolbar* toolbar_start; + WinTCTaskbandToolbar* toolbar_taskbuttons; }; // @@ -168,10 +168,19 @@ GtkWidget* wintc_taskband_window_new( ); } +void wintc_taskband_window_toggle_start_menu( + WinTCTaskbandWindow* taskband +) +{ + wintc_toolbar_start_toggle_menu( + WINTC_TOOLBAR_START(taskband->toolbar_start) + ); +} + // // PRIVATE FUNCTIONS // -static void wintc_taskband_window_create_toolbar( +static WinTCTaskbandToolbar* wintc_taskband_window_create_toolbar( WinTCTaskbandWindow* taskband, GType toolbar_type, gboolean expand @@ -197,6 +206,8 @@ static void wintc_taskband_window_create_toolbar( ); gtk_widget_show_all(root); + + return toolbar; } // @@ -217,27 +228,30 @@ static gboolean on_window_map_event( switch (s_layout[i]) { case WINTC_TASKBAND_TOOLBAR_START: - wintc_taskband_window_create_toolbar( - taskband, - WINTC_TYPE_TOOLBAR_START, - FALSE - ); + taskband->toolbar_start = + wintc_taskband_window_create_toolbar( + taskband, + WINTC_TYPE_TOOLBAR_START, + FALSE + ); break; case WINTC_TASKBAND_TOOLBAR_BUTTONS: - wintc_taskband_window_create_toolbar( - taskband, - WINTC_TYPE_TOOLBAR_TASK_BUTTONS, - TRUE - ); + taskband->toolbar_taskbuttons = + wintc_taskband_window_create_toolbar( + taskband, + WINTC_TYPE_TOOLBAR_TASK_BUTTONS, + TRUE + ); break; case WINTC_TASKBAND_TOOLBAR_NOTIFICATION_AREA: - wintc_taskband_window_create_toolbar( - taskband, - WINTC_TYPE_TOOLBAR_NOTIF_AREA, - FALSE - ); + taskband->toolbar_notifarea = + wintc_taskband_window_create_toolbar( + taskband, + WINTC_TYPE_TOOLBAR_NOTIF_AREA, + FALSE + ); break; case WINTC_TASKBAND_TOOLBAR_QUICK_ACCESS: diff --git a/shell/taskband/src/window.h b/shell/taskband/src/window.h index 8ac5a6b..6c43171 100644 --- a/shell/taskband/src/window.h +++ b/shell/taskband/src/window.h @@ -28,5 +28,9 @@ GtkWidget* wintc_taskband_window_new( WinTCTaskbandApplication* app ); +void wintc_taskband_window_toggle_start_menu( + WinTCTaskbandWindow* taskband +); + #endif