mirror of
https://github.com/google/pebble.git
synced 2025-06-09 19:53:12 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
1498
src/fw/popups/notifications/notification_window.c
Normal file
1498
src/fw/popups/notifications/notification_window.c
Normal file
File diff suppressed because it is too large
Load diff
50
src/fw/popups/notifications/notification_window.h
Normal file
50
src/fw/popups/notifications/notification_window.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "applib/fonts/fonts.h"
|
||||
#include "services/normal/notifications/notifications.h"
|
||||
#include "kernel/events.h"
|
||||
|
||||
void notification_window_service_init(void);
|
||||
|
||||
void notification_window_init(bool is_modal);
|
||||
|
||||
void notification_window_show(void);
|
||||
|
||||
bool notification_window_is_modal(void);
|
||||
|
||||
void notification_window_handle_notification(PebbleSysNotificationEvent *e);
|
||||
|
||||
void notification_window_handle_reminder(PebbleReminderEvent *e);
|
||||
|
||||
void notification_window_handle_dnd_event(PebbleDoNotDisturbEvent *e);
|
||||
|
||||
void notification_window_add_notification_by_id(Uuid *id);
|
||||
|
||||
void notification_window_focus_notification(Uuid *id, bool animated);
|
||||
|
||||
void notification_window_mark_focused_read(void);
|
||||
|
||||
void app_notification_window_add_new_notification_by_id(Uuid *id);
|
||||
|
||||
void app_notification_window_remove_notification_by_id(Uuid *id);
|
||||
|
||||
void app_notification_window_handle_notification_acted_upon_by_id(Uuid *id);
|
64
src/fw/popups/notifications/notification_window_private.h
Normal file
64
src/fw/popups/notifications/notification_window_private.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "applib/ui/action_menu_window.h"
|
||||
#include "applib/ui/status_bar_layer.h"
|
||||
#include "apps/system_apps/timeline/peek_layer.h"
|
||||
#include "services/common/evented_timer.h"
|
||||
#include "services/normal/timeline/swap_layer.h"
|
||||
|
||||
typedef struct NotificationWindowData {
|
||||
Window window;
|
||||
|
||||
RegularTimerInfo reminder_watchdog_timer_id; // Clear stale reminders once a minute
|
||||
|
||||
EventedTimerID pop_timer_id; //!< Timer that automatically pops us in case of inactivity.
|
||||
bool pop_timer_is_final; // true, if pop_timer_id cannot be rescheduled anymore
|
||||
|
||||
bool is_modal;
|
||||
bool window_frozen; // Don't pop when performing an action via a hotkey until the action completes
|
||||
bool first_notif_loaded;
|
||||
|
||||
// Used to keep track of when a notification is modified from a different (event)
|
||||
// task, so the reload only occurs in the correct task when something changes
|
||||
bool notifications_modified;
|
||||
|
||||
// nothing but rendering the action button
|
||||
Layer action_button_layer;
|
||||
|
||||
Uuid notification_app_id; //!< app id for loading custom notification icons
|
||||
|
||||
PeekLayer *peek_layer;
|
||||
TimelineResourceInfo peek_icon_info;
|
||||
EventedTimerID peek_layer_timer;
|
||||
Animation *peek_animation;
|
||||
|
||||
// Handles the multiple layers
|
||||
SwapLayer swap_layer;
|
||||
StatusBarLayer status_layer;
|
||||
ActionMenu *action_menu;
|
||||
|
||||
// Icon in status bar if in DND.
|
||||
// This should really be part of the status bar but support hasn't been
|
||||
// implemented yet. This also won't work well with round displays.
|
||||
// Remove this once the status bar layer supports icons
|
||||
// PBL-22859
|
||||
Layer dnd_icon_layer;
|
||||
GBitmap dnd_icon;
|
||||
bool dnd_icon_visible;
|
||||
} NotificationWindowData;
|
181
src/fw/popups/notifications/notifications_presented_list.c
Normal file
181
src/fw/popups/notifications/notifications_presented_list.c
Normal file
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "notifications_presented_list.h"
|
||||
|
||||
#include "util/list.h"
|
||||
#include "kernel/pbl_malloc.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
// currently focused notification id
|
||||
static NotifList *s_current_notif;
|
||||
|
||||
// List contains all currently presented notifications
|
||||
// The UI can access only notifications of this list
|
||||
static NotifList *s_presented_notifs;
|
||||
|
||||
|
||||
static bool prv_filter_presented_notification_by_id(ListNode *found_node, void *data) {
|
||||
return uuid_equal(&((NotifList*)found_node)->notif.id, (Uuid *)data);
|
||||
}
|
||||
|
||||
static NotifList *prv_find_listnode_for_notif(Uuid *id) {
|
||||
return (NotifList*) list_find((ListNode *) s_presented_notifs,
|
||||
prv_filter_presented_notification_by_id, id);
|
||||
}
|
||||
|
||||
Uuid *notifications_presented_list_first(void) {
|
||||
NotifList * node = (NotifList *)list_get_head((ListNode*)s_presented_notifs);
|
||||
return node ? &node->notif.id : NULL;
|
||||
}
|
||||
|
||||
Uuid *notifications_presented_list_last(void) {
|
||||
NotifList * node = (NotifList *)list_get_tail((ListNode*)s_presented_notifs);
|
||||
return node ? &node->notif.id : NULL;
|
||||
}
|
||||
|
||||
Uuid *notifications_presented_list_relative(Uuid *id, int offset) {
|
||||
NotifList *const start_node = prv_find_listnode_for_notif(id);
|
||||
NotifList *const end_node = (NotifList *)list_get_at((ListNode *)start_node, offset);
|
||||
|
||||
return end_node ? &end_node->notif.id : NULL;
|
||||
}
|
||||
|
||||
int notifications_presented_list_count(void) {
|
||||
return list_count((ListNode*)s_presented_notifs);
|
||||
}
|
||||
|
||||
void notifications_presented_list_remove(Uuid *id) {
|
||||
NotifList *node = prv_find_listnode_for_notif(id);
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node == s_current_notif) {
|
||||
NotifList *prev_node = (NotifList *)list_get_prev((ListNode *)s_current_notif);
|
||||
NotifList *next_node = (NotifList *)list_get_next((ListNode *)s_current_notif);
|
||||
|
||||
// If a notification gets removed, we want to show an older notification next as we assume
|
||||
// that the user scrolls down in the list starting from the newest notification
|
||||
if (next_node) {
|
||||
s_current_notif = next_node;
|
||||
} else {
|
||||
s_current_notif = prev_node;
|
||||
}
|
||||
}
|
||||
|
||||
list_remove((ListNode*)node, (ListNode**)&s_presented_notifs, NULL);
|
||||
task_free(node);
|
||||
}
|
||||
|
||||
static NotifList* prv_add_notification_common(Uuid *id, NotificationType type) {
|
||||
notifications_presented_list_remove(id);
|
||||
|
||||
NotifList *new_entry = task_malloc_check(sizeof(NotifList));
|
||||
list_init((ListNode*)new_entry);
|
||||
new_entry->notif.type = type;
|
||||
new_entry->notif.id = *id;
|
||||
|
||||
return new_entry;
|
||||
}
|
||||
|
||||
void notifications_presented_list_add(Uuid *id, NotificationType type) {
|
||||
NotifList *new_entry = prv_add_notification_common(id, type);
|
||||
s_presented_notifs = (NotifList *)
|
||||
list_prepend(&s_presented_notifs->list_node, &new_entry->list_node);
|
||||
}
|
||||
|
||||
void notifications_presented_list_add_sorted(Uuid *id, NotificationType type,
|
||||
Comparator comparator, bool ascending) {
|
||||
NotifList *new_entry = prv_add_notification_common(id, type);
|
||||
s_presented_notifs = (NotifList *) list_sorted_add(&s_presented_notifs->list_node,
|
||||
&new_entry->list_node, comparator, ascending);
|
||||
}
|
||||
|
||||
NotificationType notifications_presented_list_get_type(Uuid *id) {
|
||||
NotifList *node = prv_find_listnode_for_notif(id);
|
||||
if (!node) {
|
||||
return NotificationInvalid;
|
||||
}
|
||||
return node->notif.type;
|
||||
}
|
||||
|
||||
bool notifications_presented_list_set_current(Uuid *id) {
|
||||
NotifList *node = prv_find_listnode_for_notif(id);
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
s_current_notif = node;
|
||||
return true;
|
||||
}
|
||||
|
||||
Uuid *notifications_presented_list_current(void) {
|
||||
if (!s_current_notif) {
|
||||
return NULL;
|
||||
}
|
||||
return &s_current_notif->notif.id;
|
||||
}
|
||||
|
||||
Uuid *notifications_presented_list_next(void) {
|
||||
NotifList *next_node = (NotifList *)list_get_next((ListNode *)s_current_notif);
|
||||
if (!next_node) {
|
||||
return NULL;
|
||||
}
|
||||
return &next_node->notif.id;
|
||||
}
|
||||
|
||||
int notifications_presented_list_current_idx(void) {
|
||||
Uuid *id = notifications_presented_list_current();
|
||||
if (uuid_is_invalid(id)) {
|
||||
return -1;
|
||||
}
|
||||
return list_count_to_head_from((ListNode*) prv_find_listnode_for_notif(id)) - 1;
|
||||
}
|
||||
|
||||
void notifications_presented_list_init(void) {
|
||||
s_current_notif = NULL;
|
||||
s_presented_notifs = NULL;
|
||||
}
|
||||
|
||||
void notifications_presented_list_deinit(NotificationListEachCallback callback, void *cb_data) {
|
||||
s_current_notif = NULL;
|
||||
|
||||
while (s_presented_notifs) {
|
||||
NotifList *head = s_presented_notifs;
|
||||
list_remove((ListNode *)head, (ListNode **)&s_presented_notifs, NULL);
|
||||
|
||||
if (callback) {
|
||||
callback(&head->notif.id, head->notif.type, cb_data);
|
||||
}
|
||||
|
||||
task_free(head);
|
||||
}
|
||||
}
|
||||
|
||||
void notifications_presented_list_each(NotificationListEachCallback callback, void *cb_data) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
NotifList *itr = s_presented_notifs;
|
||||
while (itr) {
|
||||
NotifList *next = (NotifList *)itr->list_node.next;
|
||||
callback(&itr->notif.id, itr->notif.type, cb_data);
|
||||
itr = next;
|
||||
}
|
||||
}
|
84
src/fw/popups/notifications/notifications_presented_list.h
Normal file
84
src/fw/popups/notifications/notifications_presented_list.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/uuid.h"
|
||||
#include "services/normal/notifications/notification_types.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
//! @file notifications_presented_list.h
|
||||
//!
|
||||
//! \brief File that manages a list of presented notifications.
|
||||
|
||||
typedef struct {
|
||||
ListNode list_node;
|
||||
NotificationInfo notif;
|
||||
} NotifList;
|
||||
|
||||
//! Get the first notification ID in the presented list
|
||||
Uuid *notifications_presented_list_first(void);
|
||||
|
||||
//! Get the last notification ID in the presented list
|
||||
Uuid *notifications_presented_list_last(void);
|
||||
|
||||
//! Get the notification ID that has the given relative offset from the given id
|
||||
Uuid *notifications_presented_list_relative(Uuid *id, int offset);
|
||||
|
||||
//! Get the currently presented notification in the list
|
||||
Uuid *notifications_presented_list_current(void);
|
||||
|
||||
//! Get the next notification in the list
|
||||
Uuid *notifications_presented_list_next(void);
|
||||
|
||||
//! Set the current notification in the presented list (user scrolled, new notif, etc)
|
||||
bool notifications_presented_list_set_current(Uuid *id);
|
||||
|
||||
//! Remove the given notification from the presented list
|
||||
void notifications_presented_list_remove(Uuid *id);
|
||||
|
||||
//! Add the given notification to the presented list
|
||||
void notifications_presented_list_add(Uuid *id, NotificationType type);
|
||||
|
||||
//! Add the given notification to the presented list
|
||||
//! The comparator will have to compare two NotifList*
|
||||
void notifications_presented_list_add_sorted(Uuid *id, NotificationType type,
|
||||
Comparator comparator, bool ascending);
|
||||
|
||||
//! Get the type of the given notification
|
||||
NotificationType notifications_presented_list_get_type(Uuid *id);
|
||||
|
||||
//! Get the count of notifications in the presented list
|
||||
int notifications_presented_list_count(void);
|
||||
|
||||
//! Get the current index (integer based) of the current notification in the presented list
|
||||
//! This is used for the status bar (ex. "2/5")
|
||||
int notifications_presented_list_current_idx(void);
|
||||
|
||||
//! Inits the notification presented list
|
||||
void notifications_presented_list_init(void);
|
||||
|
||||
typedef void (*NotificationListEachCallback)(Uuid *id, NotificationType type, void *cb_data);
|
||||
|
||||
//! Executes the specified callback for each notificaiton in the presented list
|
||||
//! @param callback If null this function is a no-op
|
||||
void notifications_presented_list_each(NotificationListEachCallback callback, void *cb_data);
|
||||
|
||||
//! Deinits the notification presented list
|
||||
//! @param callback - If non-null, notifies the caller what item is being removed.
|
||||
//! The callback routine should not try to modify the notification list
|
||||
void notifications_presented_list_deinit(NotificationListEachCallback callback, void *cb_data);
|
Loading…
Add table
Add a link
Reference in a new issue