From ea9c0bf8c6016888c9942f4d31589e84c21058d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 22 Apr 2024 19:19:11 +0200 Subject: [PATCH 1/8] top-panel: Fix property doc string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adjust the ident while at that, this is ancient code. Gbp-Dch: Ignore Signed-off-by: Guido Günther --- src/top-panel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/top-panel.c b/src/top-panel.c index 2f35e4a288..3454e06e51 100644 --- a/src/top-panel.c +++ b/src/top-panel.c @@ -684,7 +684,8 @@ phosh_top_panel_class_init (PhoshTopPanelClass *klass) gtk_widget_class_set_css_name (widget_class, "phosh-top-panel"); - /* PhoshTopPanel:on-lockscreen: + /** + * PhoshTopPanel:on-lockscreen: * * Whether top-panel is shown on lockscreen (%TRUE) or in the unlocked shell * (%FALSE). @@ -693,10 +694,9 @@ phosh_top_panel_class_init (PhoshTopPanelClass *klass) * use a property binding with the [type@Shell]s "locked" property. */ props[PROP_ON_LOCKSCREEN] = - g_param_spec_boolean ( - "on-lockscreen", "", "", - FALSE, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_param_spec_boolean ("on-lockscreen", "", "", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); -- GitLab From f4ec6ef0415c46ac94663978418f37ebc1a76fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 22 Apr 2024 19:34:44 +0200 Subject: [PATCH 2/8] top-panel: Don't init state twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther --- src/top-panel.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/top-panel.c b/src/top-panel.c index 3454e06e51..2d4a5803ac 100644 --- a/src/top-panel.c +++ b/src/top-panel.c @@ -506,8 +506,6 @@ phosh_top_panel_constructed (GObject *object) G_OBJECT_CLASS (phosh_top_panel_parent_class)->constructed (object); - self->state = PHOSH_TOP_PANEL_STATE_FOLDED; - g_object_bind_property (phosh_shell_get_default (), "locked", self, "on-lockscreen", G_BINDING_SYNC_CREATE); -- GitLab From 20e32a959fd5a8b6324f6df409fbcdf4d7f3380f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 22 Apr 2024 19:20:44 +0200 Subject: [PATCH 3/8] top-panel: Export state as property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have the enum and the getter already so let's make it simple to track changes. Signed-off-by: Guido Günther --- src/top-panel.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/top-panel.c b/src/top-panel.c index 2d4a5803ac..8934ff8ca3 100644 --- a/src/top-panel.c +++ b/src/top-panel.c @@ -43,6 +43,7 @@ */ enum { PROP_0, + PROP_TOP_PANEL_STATE, PROP_ON_LOCKSCREEN, PROP_LAST_PROP, }; @@ -126,6 +127,9 @@ phosh_top_panel_get_property (GObject *object, PhoshTopPanel *self = PHOSH_TOP_PANEL (object); switch (property_id) { + case PROP_TOP_PANEL_STATE: + g_value_set_enum (value, self->state); + break; case PROP_ON_LOCKSCREEN: g_value_set_boolean (value, self->on_lockscreen); break; @@ -482,7 +486,11 @@ on_drag_state_changed (PhoshTopPanel *self) gtk_stack_set_visible_child_name (GTK_STACK (self->stack), visible); phosh_arrow_set_progress (PHOSH_ARROW (self->arrow), arrow); - self->state = state; + if (self->state != state) { + self->state = state; + g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TOP_PANEL_STATE]); + } + phosh_layer_surface_set_kbd_interactivity (PHOSH_LAYER_SURFACE (self), kbd_interactivity); phosh_layer_surface_wl_surface_commit (PHOSH_LAYER_SURFACE (self)); } @@ -682,6 +690,19 @@ phosh_top_panel_class_init (PhoshTopPanelClass *klass) gtk_widget_class_set_css_name (widget_class, "phosh-top-panel"); + /** + * PhoshTopPanel:state: + * + * Whether the top-panel is currently `folded` (only top-bar is + * visible) or `unfolded` (settings and notification area are + * visible). The property is updated when the widget reaches its + * target state. + */ + props[PROP_TOP_PANEL_STATE] = + g_param_spec_enum ("state", "", "", + PHOSH_TYPE_HOME_STATE, + PHOSH_TOP_PANEL_STATE_UNFOLDED, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); /** * PhoshTopPanel:on-lockscreen: * -- GitLab From 3445d0bc74b82a9675f36bf89411088ba9bb7c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 22 Apr 2024 14:48:40 +0200 Subject: [PATCH 4/8] shell: Indent signal connects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use current coding style Gbp-Dch: Ignore Signed-off-by: Guido Günther --- src/shell.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/shell.c b/src/shell.c index b31929defe..ba59081d54 100644 --- a/src/shell.c +++ b/src/shell.c @@ -364,17 +364,15 @@ panels_create (PhoshShell *self) monitor)); gtk_widget_show (GTK_WIDGET (priv->home)); - g_signal_connect_swapped ( - priv->top_panel, - "activated", - G_CALLBACK (on_top_panel_activated), - self); - - g_signal_connect_swapped ( - priv->home, - "notify::state", - G_CALLBACK(on_home_state_changed), - self); + g_signal_connect_swapped (priv->top_panel, + "activated", + G_CALLBACK (on_top_panel_activated), + self); + + g_signal_connect_swapped (priv->home, + "notify::state", + G_CALLBACK (on_home_state_changed), + self); app_grid = phosh_overview_get_app_grid (phosh_home_get_overview (PHOSH_HOME (priv->home))); g_object_bind_property (priv->docked_manager, -- GitLab From 296e111a815abc43ddff7e386e1cb4a60a950316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 22 Apr 2024 14:49:29 +0200 Subject: [PATCH 5/8] shell: Track settings shell state too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `PhoshShellState` has a `Settings` flag but so far we never set it. Augments: 59c8074c9 ("home: Update PhoshShellState") Signed-off-by: Guido Günther --- src/shell.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/shell.c b/src/shell.c index ba59081d54..108bf09a26 100644 --- a/src/shell.c +++ b/src/shell.c @@ -275,6 +275,22 @@ on_proximity_fader_changed (PhoshShell *self) } +static void +on_top_panel_state_changed (PhoshShell *self, GParamSpec *pspec, PhoshTopPanel *top_panel) +{ + PhoshShellPrivate *priv; + PhoshTopPanelState state; + + g_return_if_fail (PHOSH_IS_SHELL (self)); + g_return_if_fail (PHOSH_IS_TOP_PANEL (top_panel)); + + priv = phosh_shell_get_instance_private (self); + + state = phosh_top_panel_get_state (PHOSH_TOP_PANEL (priv->top_panel)); + phosh_shell_set_state (self, PHOSH_STATE_SETTINGS, state == PHOSH_TOP_PANEL_STATE_UNFOLDED); +} + + static void on_home_state_changed (PhoshShell *self, GParamSpec *pspec, PhoshHome *home) { @@ -369,6 +385,11 @@ panels_create (PhoshShell *self) G_CALLBACK (on_top_panel_activated), self); + g_signal_connect_swapped (priv->top_panel, + "notify::state", + G_CALLBACK (on_top_panel_state_changed), + self); + g_signal_connect_swapped (priv->home, "notify::state", G_CALLBACK (on_home_state_changed), -- GitLab From 2b2aa43cebfa51519a5a50a55d9298b49a174d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 22 Apr 2024 19:58:19 +0200 Subject: [PATCH 6/8] top-panel: Set initial shell state to unfolded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an artifact of the fact that the drag surface code needs some time to wiggle the surface into place (which we want to fix on the compositor side). We can then revert this patch. Signed-off-by: Guido Günther --- src/shell.c | 2 +- src/top-panel.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shell.c b/src/shell.c index 108bf09a26..d6aaf85351 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1274,7 +1274,7 @@ phosh_shell_init (PhoshShell *self) self); on_gtk_theme_name_changed (self, NULL, gtk_settings); - priv->shell_state = PHOSH_STATE_NONE; + priv->shell_state = PHOSH_STATE_SETTINGS; priv->action_map = g_simple_action_group_new (); } diff --git a/src/top-panel.c b/src/top-panel.c index 8934ff8ca3..e410e6cb9a 100644 --- a/src/top-panel.c +++ b/src/top-panel.c @@ -817,7 +817,7 @@ phosh_top_panel_init (PhoshTopPanel *self) gtk_widget_init_template (GTK_WIDGET (self)); - self->state = PHOSH_TOP_PANEL_STATE_FOLDED; + self->state = PHOSH_TOP_PANEL_STATE_UNFOLDED; self->kb_settings = g_settings_new (KEYBINDINGS_SCHEMA_ID); g_signal_connect (self, "configure-event", G_CALLBACK (on_configure_event), NULL); -- GitLab From 59089e6157ea6ba4acf9e4fe3baee6375d46e49d Mon Sep 17 00:00:00 2001 From: Sam Day Date: Mon, 22 Apr 2024 20:20:52 +0200 Subject: [PATCH 7/8] top-panel: Generate enum type for state Fixes: 6ab2b3ec --- src/meson.build | 1 + src/phosh-enums.c.in | 1 + src/top-panel.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/meson.build b/src/meson.build index 90249dbd35..f482652391 100644 --- a/src/meson.build +++ b/src/meson.build @@ -26,6 +26,7 @@ phosh_enum_headers = files( 'phosh-wayland.h', 'rotation-manager.h', 'shell.h', + 'top-panel.h', ) + schema_enum_headers phosh_enums = gnome.mkenums('phosh-enums', diff --git a/src/phosh-enums.c.in b/src/phosh-enums.c.in index c8372b0569..98f49af782 100644 --- a/src/phosh-enums.c.in +++ b/src/phosh-enums.c.in @@ -18,6 +18,7 @@ #include "phosh-wayland.h" #include "rotation-manager.h" #include "shell.h" +#include "top-panel.h" #include "wwan/phosh-wwan-backend.h" #include "phosh-enums.h" diff --git a/src/top-panel.c b/src/top-panel.c index e410e6cb9a..cc0f458dc2 100644 --- a/src/top-panel.c +++ b/src/top-panel.c @@ -700,7 +700,7 @@ phosh_top_panel_class_init (PhoshTopPanelClass *klass) */ props[PROP_TOP_PANEL_STATE] = g_param_spec_enum ("state", "", "", - PHOSH_TYPE_HOME_STATE, + PHOSH_TYPE_TOP_PANEL_STATE, PHOSH_TOP_PANEL_STATE_UNFOLDED, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); /** -- GitLab From c60532159a0e5d5ecd57d99913c3a50df308a549 Mon Sep 17 00:00:00 2001 From: Sam Day Date: Sun, 21 Apr 2024 23:32:22 +0200 Subject: [PATCH 8/8] tests: Wait for top-panel folded in screenshots Otherwise, the first screenshot is often taken before the panel has fully folded, and thus the arrow is still showing, and/or the top panel text is still fading in. --- tests/meson.build | 3 +- tests/test-take-screenshots.c | 19 ++++++++++ tests/testlib-wait-for-shell-state.c | 52 ++++++++++++++++++++++++++++ tests/testlib-wait-for-shell-state.h | 26 ++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 tests/testlib-wait-for-shell-state.c create mode 100644 tests/testlib-wait-for-shell-state.h diff --git a/tests/meson.build b/tests/meson.build index 606ddeb8e7..e0e4457c3a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -77,7 +77,8 @@ testlib_sources = [ 'testlib-full-shell.c', 'testlib-calls-mock.c', 'testlib-mpris-mock.c', - 'testlib-emergency-calls.c' + 'testlib-emergency-calls.c', + 'testlib-wait-for-shell-state.c', ] + test_resources testlib = static_library('phoshtest', testlib_sources, diff --git a/tests/test-take-screenshots.c b/tests/test-take-screenshots.c index f86c4e50c4..439bffcb3b 100644 --- a/tests/test-take-screenshots.c +++ b/tests/test-take-screenshots.c @@ -12,11 +12,13 @@ #include "phosh-test-resources.h" #include "portal-dbus.h" #include "shell.h" +#include "top-panel.h" #include "testlib-full-shell.h" #include "testlib-calls-mock.h" #include "testlib-mpris-mock.h" #include "testlib-emergency-calls.h" +#include "testlib-wait-for-shell-state.h" #include "phosh-screen-saver-dbus.h" @@ -95,6 +97,22 @@ wait_a_bit (GMainLoop *loop, int msecs) g_main_loop_run (loop); } +static void +wait_for_top_panel_folded (void) +{ + PhoshShellStateFlags flags; + g_autoptr (PhoshTestWaitForShellState) waiter; + + waiter = phosh_test_wait_for_shell_state_new (phosh_shell_get_default ()); + + while (1) { + flags = phosh_test_wait_for_shell_state_next (waiter, 5000); + if (!(flags & PHOSH_STATE_SETTINGS)) { + return; + } + } +} + static void toggle_overview (GMainLoop *loop, @@ -539,6 +557,7 @@ test_take_screenshots (PhoshTestFullShellFixture *fixture, gconstpointer unused) loop = g_main_loop_new (context, FALSE); /* Give overview animation time to finish */ + wait_for_top_panel_folded (); wait_a_bit (loop, 500); take_screenshot (what, i++, "overview-empty"); diff --git a/tests/testlib-wait-for-shell-state.c b/tests/testlib-wait-for-shell-state.c new file mode 100644 index 0000000000..be42f97f38 --- /dev/null +++ b/tests/testlib-wait-for-shell-state.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "testlib-wait-for-shell-state.h" + + +static void +on_shell_state (PhoshShell *shell, GParamSpec *pspec, GAsyncQueue *queue) +{ + PhoshShellStateFlags flags = phosh_shell_get_state (shell); + g_assert_nonnull (queue); + g_async_queue_push (queue, GUINT_TO_POINTER (flags)); +} + + +PhoshTestWaitForShellState* +phosh_test_wait_for_shell_state_new (PhoshShell *shell) +{ + PhoshTestWaitForShellState *self; + + self = g_new0 (PhoshTestWaitForShellState, 1); + self->queue = g_async_queue_new (); + self->shell = shell; + self->signal_id = g_signal_connect (self->shell, "notify::shell-state", + G_CALLBACK (on_shell_state), self->queue); + + return self; +} + + +void +phosh_test_wait_for_shell_state_dispose (PhoshTestWaitForShellState *self) +{ + g_assert_nonnull (self); + + g_clear_pointer (&self->queue, g_async_queue_unref); + g_signal_handler_disconnect (self->shell, self->signal_id); + + g_free (self); +} + +PhoshShellStateFlags +phosh_test_wait_for_shell_state_next (PhoshTestWaitForShellState *self, guint64 timeout_ms) +{ + gpointer flags; + flags = g_async_queue_timeout_pop (self->queue, timeout_ms * 1000); + g_assert_nonnull (flags); + return (PhoshShellStateFlags) GPOINTER_TO_UINT (flags); +} diff --git a/tests/testlib-wait-for-shell-state.h b/tests/testlib-wait-for-shell-state.h new file mode 100644 index 0000000000..64d4edd70b --- /dev/null +++ b/tests/testlib-wait-for-shell-state.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2024 The Phosh Developers + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "testlib.h" +#include "shell.h" + +G_BEGIN_DECLS + +typedef struct _PhoshTestWaitForShellState { + GAsyncQueue *queue; + gulong signal_id; + guint timeout_id; + PhoshShell *shell; +} PhoshTestWaitForShellState; + +PhoshTestWaitForShellState *phosh_test_wait_for_shell_state_new (PhoshShell *shell); +void phosh_test_wait_for_shell_state_dispose (PhoshTestWaitForShellState *self); +PhoshShellStateFlags phosh_test_wait_for_shell_state_next (PhoshTestWaitForShellState *self, + guint64 timeout); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (PhoshTestWaitForShellState, phosh_test_wait_for_shell_state_dispose) + +G_END_DECLS -- GitLab