diff --git a/data/sm.puri.phosh.gschema.xml b/data/sm.puri.phosh.gschema.xml index e4e7f3e4d6a143ccfe2b52575fa71f8179554943..fe0bcc37affa513575dbf25ab25c9a57e7f109f5 100644 --- a/data/sm.puri.phosh.gschema.xml +++ b/data/sm.puri.phosh.gschema.xml @@ -70,8 +70,18 @@ false Whether to enable suspend from the power menu - Setting this to true allows manually suspending the device from the power menu. - Suspend is an experimental feature on some devices and may result in crashes or instability. + Setting this to true allows manually suspending the device from the power menu. + Suspend is an experimental feature on some devices and may result in crashes or instability. + + + + + false + Allow to quickly silence the device + + Setting this to true allows to set the phone to silent by + pressing volume-down on incoming calls when the phone is locked. + This feature is experimental. diff --git a/debian/control b/debian/control index 603d7803726cef4ed517f3f0075df5bbc05a55b1..d8eb7e6ab7657952c0cd2addfd0562e9f40240ab 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,7 @@ Build-Depends: libjson-glib-dev, libsecret-1-dev, libsystemd-dev, - libfeedback-dev (>= 0.2.0), + libfeedback-dev (>= 0.4.0), libfribidi-dev, libgcr-3-dev, libgnome-bluetooth-3.0-dev, @@ -65,7 +65,7 @@ Depends: libcap2-bin, phoc (>= 0.33.0), Recommends: - feedbackd, + feedbackd (>= 0.4.0), fonts-cantarell, gnome-session-bin, gnome-session-common, diff --git a/meson.build b/meson.build index 3ecc7765dee15f0ce261887750154de806c4eca6..af5f496911fa8d3b322e8b384ba8ee8fedc584c0 100644 --- a/meson.build +++ b/meson.build @@ -155,7 +155,7 @@ libcall_ui = subproject('libcall-ui', 'install-i18n=@0@'.format(get_option('callui-i18n')), ]) libfeedback_dep = dependency('libfeedback-0.0', - version: '>= 0.2.0', + version: '>= 0.4.0', fallback: ['libfeedback', 'libfeedback_dep'], default_options: ['introspection=disabled', 'daemon=false', 'gtk_doc=false'] ) diff --git a/src/calls-manager.c b/src/calls-manager.c index 5cbd7316bb5052596063aabe21ea3552a8a44724..88138f5a990216e3f03332db9952577aa1dfe8dc 100644 --- a/src/calls-manager.c +++ b/src/calls-manager.c @@ -100,9 +100,12 @@ on_call_state_changed (PhoshCallsManager *self, g_debug ("Call %s, state %d", path, state); if (g_strcmp0 (path, self->active_call) == 0) { - /* current active call became inactive> */ + + self->incoming = state == PHOSH_CALL_STATE_INCOMING; + /* current active call became inactive */ if (!is_active (state)) { g_debug ("No active call, was %s", path); + g_clear_pointer (&self->active_call, g_free); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACTIVE_CALL]); /* TODO: pick new active call from list once calls supports multiple active calls */ @@ -111,12 +114,14 @@ on_call_state_changed (PhoshCallsManager *self, } if (!is_active (state)) - return; + return; /* New active call */ g_free (self->active_call); self->active_call = g_strdup (path); g_debug ("New active call %s", path); + self->incoming = state == PHOSH_CALL_STATE_INCOMING; + g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACTIVE_CALL]); } @@ -432,7 +437,6 @@ phosh_calls_manager_class_init (PhoshCallsManagerClass *klass) G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); - /** * PhoshCallsManager:active-call: * @@ -450,13 +454,13 @@ phosh_calls_manager_class_init (PhoshCallsManagerClass *klass) g_object_class_install_properties (object_class, PROP_LAST_PROP, props); signals[CALL_ADDED] = g_signal_new ("call-added", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, - NULL, - G_TYPE_NONE, - 1, - G_TYPE_STRING); + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + NULL, + G_TYPE_NONE, + 1, + G_TYPE_STRING); signals[CALL_REMOVED] = g_signal_new ("call-removed", G_TYPE_FROM_CLASS (klass), @@ -497,9 +501,16 @@ phosh_calls_manager_get_present (PhoshCallsManager *self) return self->present; } - -int -phosh_calls_manager_get_incoming (PhoshCallsManager *self) +/** + * phosh_calls_manager_has_incoming_call: + * @self: The calls manager + * + * Whether there's currently an incoming call + * + * Returns: `TRUE` if there's an incoming call + */ +gboolean +phosh_calls_manager_has_incoming_call (PhoshCallsManager *self) { g_return_val_if_fail (PHOSH_IS_CALLS_MANAGER (self), FALSE); diff --git a/src/calls-manager.h b/src/calls-manager.h index eebc77676f2116b3db7ad2c99330a1352d236ad7..a5656cee91f38109b373c66ffd6d514c92815ece 100644 --- a/src/calls-manager.h +++ b/src/calls-manager.h @@ -37,7 +37,7 @@ G_DECLARE_FINAL_TYPE (PhoshCallsManager, phosh_calls_manager, PHOSH, CALLS_MANAG PhoshCallsManager *phosh_calls_manager_new (void); gboolean phosh_calls_manager_get_present (PhoshCallsManager *self); -gboolean phosh_calls_manager_get_incoming (PhoshCallsManager *self); +gboolean phosh_calls_manager_has_incoming_call (PhoshCallsManager *self); const char *phosh_calls_manager_get_active_call_handle (PhoshCallsManager *self); PhoshCall *phosh_calls_manager_get_call (PhoshCallsManager *self, const char *handle); diff --git a/src/feedback-manager.c b/src/feedback-manager.c index dd1f55eb0fa59dcf8b39fb27a42315704a0cdbcd..77362b8a21492de03a2b7a700c2e5ad2eea1e58e 100644 --- a/src/feedback-manager.c +++ b/src/feedback-manager.c @@ -238,6 +238,16 @@ phosh_feedback_manager_get_profile (PhoshFeedbackManager *self) } +void +phosh_feedback_manager_set_profile (PhoshFeedbackManager *self, const char *profile) +{ + g_return_if_fail (PHOSH_IS_FEEDBACK_MANAGER (self)); + + g_debug ("Setting feedback profile to %s", profile); + lfb_set_feedback_profile (profile); +} + + void phosh_feedback_manager_toggle (PhoshFeedbackManager *self) { @@ -252,8 +262,7 @@ phosh_feedback_manager_toggle (PhoshFeedbackManager *self) else if (!g_strcmp0 (old, "full")) profile = "quiet"; - g_debug ("Setting feedback profile to %s, was %s", profile, old); - lfb_set_feedback_profile (profile); + phosh_feedback_manager_set_profile (self, profile); } diff --git a/src/feedback-manager.h b/src/feedback-manager.h index de7177401c333a626006104c1bbe4e887babd0e4..806097e0994bbac691545fd50e460ded18119b05 100644 --- a/src/feedback-manager.h +++ b/src/feedback-manager.h @@ -21,6 +21,7 @@ PhoshFeedbackManager *phosh_feedback_manager_new (void); void phosh_feedback_manager_toggle (PhoshFeedbackManager *self); const char * phosh_feedback_manager_get_icon_name (PhoshFeedbackManager *self); const char * phosh_feedback_manager_get_profile (PhoshFeedbackManager *self); +void phosh_feedback_manager_set_profile (PhoshFeedbackManager *self, const char *profile); void phosh_feedback_manager_trigger_feedback (PhoshFeedbackManager *self, const char *event); void phosh_trigger_feedback (const char *name); void phosh_connect_feedback (GtkWidget *widget); diff --git a/src/keyboard-events.c b/src/keyboard-events.c index 6de0dc30aa751349e66b69fbbb25e8393781c747..f2df4cb88e59efbfb1c17e2da0815d853500bbbc 100644 --- a/src/keyboard-events.c +++ b/src/keyboard-events.c @@ -19,6 +19,13 @@ * Grabs and manages special keyboard events */ +enum { + PRESSED, + RELEASED, + N_SIGNALS +}; +static guint signals[N_SIGNALS] = { 0 }; + struct _PhoshKeyboardEvents { GSimpleActionGroup parent; @@ -47,22 +54,12 @@ handle_accelerator_activated_event (void *data, g_debug ("Accelerator %d activated: %s", action_id, action); g_return_if_fail (g_action_group_has_action (G_ACTION_GROUP (self), action)); + g_signal_emit (self, signals[PRESSED], 0, action); if (g_action_group_get_action_parameter_type (G_ACTION_GROUP (self), action)) pressed = g_variant_new_boolean (TRUE); g_action_group_activate_action (G_ACTION_GROUP (self), action, pressed); - - /* - * Emulate key released when running against older phoc, can be - * removed once we require phoc 0.26.0 - */ - if ((phosh_private_keyboard_event_get_version (kbevent) < - PHOSH_PRIVATE_KEYBOARD_EVENT_ACCELERATOR_RELEASED_EVENT_SINCE_VERSION) && - g_action_group_get_action_parameter_type (G_ACTION_GROUP (self), action)) { - g_warning_once ("Emulating accelerator up. Please upgrade phoc"); - g_action_group_activate_action (G_ACTION_GROUP (self), action, g_variant_new_boolean (FALSE)); - } } @@ -81,6 +78,7 @@ handle_accelerator_released_event (void *data, g_debug ("Accelerator %d released: %s", action_id, action); g_return_if_fail (g_action_group_has_action (G_ACTION_GROUP (self), action)); + g_signal_emit (self, signals[RELEASED], 0, action); /* Action doesn't have a parameter so we only notify press */ if (g_action_group_get_action_parameter_type (G_ACTION_GROUP (self), action) == NULL) @@ -276,6 +274,33 @@ phosh_keyboard_events_class_init (PhoshKeyboardEventsClass *klass) object_class->dispose = phosh_keyboard_events_dispose; object_class->finalize = phosh_keyboard_events_finalize; + + /** + * PhoshKeyboardEvents::pressed: + * @self: The keyboard-events instance + * @combo: The pressed global shortcut as string + * + * Emitted when a subscribed key binding was pressed. + */ + signals[PRESSED] = g_signal_new ("pressed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, + 1, G_TYPE_STRING); + /** + * PhoshKeyboardEvents::released: + * @self: The keyboard-events instance + * @combo: The released global shortcut as string + * + * Emitted when a subscribed key binding was released. + */ + signals[RELEASED] = g_signal_new ("released", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, + 1, G_TYPE_STRING); } diff --git a/src/proximity.c b/src/proximity.c index 3a8ca4aa2cfba93a6aff7c62f21c74f95c1418f9..aa5ce72d10037a324ab609f00fa7f67197c11e29 100644 --- a/src/proximity.c +++ b/src/proximity.c @@ -164,7 +164,7 @@ on_has_proximity_changed (PhoshProximity *self, g_debug ("Found %s proximity sensor", has_proximity ? "a" : "no"); - /* If prox went a way we always unclaim but only claim on ongoing calls: */ + /* If the proxy went a way we always unclaim but only claim on ongoing calls: */ if (!phosh_calls_manager_get_active_call_handle (self->calls_manager) && has_proximity) return; diff --git a/src/shell.c b/src/shell.c index ab147d2f23f329ba929927a236549869d45db3d3..3a15d8ca75aba3601e0c83b8054f455c65c868f1 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2018 Purism SPC + * 2023-2024 The Phosh Develpoers * * SPDX-License-Identifier: GPL-3.0-or-later * @@ -961,6 +962,25 @@ on_monitor_removed (PhoshShell *self, PhoshMonitor *monitor) } +static void +on_keyboard_events_pressed (PhoshShell *self, const char *combo) +{ + PhoshShellPrivate *priv = phosh_shell_get_instance_private (self); + + if (!phosh_calls_manager_has_incoming_call (priv->calls_manager)) + return; + + if (!g_settings_get_boolean (priv->settings, "quick-silent")) + return; + + if (g_strcmp0 (combo, "XF86AudioLowerVolume")) + return; + + g_debug ("Vol down pressed, silencing device"); + phosh_feedback_manager_set_profile (priv->feedback_manager, "silent"); +} + + static void phosh_shell_constructed (GObject *object) { @@ -1031,6 +1051,10 @@ phosh_shell_constructed (GObject *object) priv->feedback_manager = phosh_feedback_manager_new (); priv->keyboard_events = phosh_keyboard_events_new (); + g_signal_connect_swapped (priv->keyboard_events, + "pressed", + G_CALLBACK (on_keyboard_events_pressed), + self); id = g_idle_add ((GSourceFunc) setup_idle_cb, self); g_source_set_name_by_id (id, "[PhoshShell] idle");