1 #include <atspi/atspi.h>
4 #include "screen_reader_tts.h"
5 #include "screen_reader_haptic.h"
6 #include "smart_notification.h"
9 #define RESET "\033[0m"
11 #define ITEMS_NOTIFICATION "Visible items from %d to %d"
13 static gboolean status = FALSE;
15 static void _smart_notification_focus_chain_end(void);
16 static void _smart_notification_realized_items(int start_idx, int end_idx);
19 * @brief Smart Notifications event handler
21 * @param nt Notification event type
22 * @param start_index int first visible items index smart_notification_realized_items
23 * @param end_index int last visible items index used for smart_notification_realized_items
25 void smart_notification(Notification_Type nt, int start_index, int end_index)
32 case FOCUS_CHAIN_END_NOTIFICATION_EVENT:
33 _smart_notification_focus_chain_end();
35 case REALIZED_ITEMS_NOTIFICATION_EVENT:
36 _smart_notification_realized_items(start_index, end_index);
39 DEBUG("Gesture type %d not handled in switch", nt);
44 * @brief Used for getting first and last index of visible items
46 * @param scrollable_object AtspiAccessible object on which scroll was triggered
47 * @param start_index int first visible items index smart_notification_realized_items
48 * @param end_index int last visible items index used for smart_notification_realized_items
50 void get_realized_items_count(AtspiAccessible *scrollable_object, int *start_idx, int *end_idx)
53 AtspiAccessible *child_iter;
54 AtspiStateType state = ATSPI_STATE_SHOWING;
56 if(!scrollable_object)
58 DEBUG("No scrollable object");
62 count_child = atspi_accessible_get_child_count(scrollable_object, NULL);
64 for(jdx = 0; jdx < count_child; jdx++)
66 child_iter = atspi_accessible_get_child_at_index(scrollable_object, jdx, NULL);
68 AtspiStateSet* state_set = atspi_accessible_get_state_set(child_iter);
70 gboolean is_visible = atspi_state_set_contains(state_set, state);
74 DEBUG("Item with index %d is visible", jdx);
77 DEBUG("Item with index %d is NOT visible", jdx);
79 *end_idx = *start_idx + 8;
83 * @brief Scroll-start/Scroll-end event callback
85 * @param event AtspiEvent
86 * @param user_data UNUSED
89 _scroll_event_cb(AtspiEvent *event, void *user_data)
94 int start_index, end_index;
98 DEBUG("Event: %s: %d, obj: %p: role: %s\n", event->type, event->detail1, event->source,
99 atspi_accessible_get_role_name(event->source, NULL));
101 if (!strcmp(event->type, "object:scroll-start"))
103 DEBUG("Scrolling started");
104 tts_speak("Scrolling started", TRUE);
106 else if (!strcmp(event->type, "object:scroll-end"))
108 DEBUG("Scrolling finished");
109 tts_speak("Scrolling finished", FALSE);
110 get_realized_items_count((AtspiAccessible *)event->source, &start_index, &end_index);
111 _smart_notification_realized_items(start_index, end_index);
116 * @brief Initializer for smart notifications
120 void smart_notification_init(void)
122 DEBUG("Smart Notification init!");
124 AtspiEventListener *listener;
126 listener = atspi_event_listener_new(_scroll_event_cb, NULL, NULL);
127 atspi_event_listener_register(listener, "object:scroll-start", NULL);
128 atspi_event_listener_register(listener, "object:scroll-end", NULL);
130 haptic_module_init();
136 * @brief Smart notifications shutdown
139 void smart_notification_shutdown(void)
145 * @brief Smart notifications focus chain event handler
148 static void _smart_notification_focus_chain_end(void)
153 DEBUG(RED"Smart notification - FOCUS CHAIN END"RESET);
157 * @brief Smart notifications realized items event handler
160 static void _smart_notification_realized_items(int start_idx, int end_idx)
165 if(start_idx == end_idx)
168 DEBUG(RED"Smart notification - Visible items notification"RESET);
172 snprintf(buf, sizeof(buf), ITEMS_NOTIFICATION, start_idx, end_idx);
174 tts_speak(strdup(buf), FALSE);