2 #include <Ecore_Evas.h>
4 #include <atspi/atspi.h>
5 #include <tone_player.h>
7 #include "screen_reader_tts.h"
8 #include "screen_reader_haptic.h"
9 #include "smart_notification.h"
11 #define RED "\x1B[31m"
12 #define RESET "\033[0m"
14 static Eina_Bool status = EINA_FALSE;
16 static void _smart_notification_focus_chain_end(void);
17 static void _smart_notification_realized_items(int start_idx, int end_idx);
20 * @brief Smart Notifications event handler
22 * @param nt Notification event type
23 * @param start_index int first visible items index smart_notification_realized_items
24 * @param end_index int last visible items index used for smart_notification_realized_items
26 void smart_notification(Notification_Type nt, int start_index, int end_index)
34 case FOCUS_CHAIN_END_NOTIFICATION_EVENT:
35 _smart_notification_focus_chain_end();
37 case REALIZED_ITEMS_NOTIFICATION_EVENT:
38 _smart_notification_realized_items(start_index, end_index);
41 DEBUG("Gesture type %d not handled in switch", nt);
46 * @brief Used for getting first and last index of visible items
48 * @param scrollable_object AtspiAccessible object on which scroll was triggered
49 * @param start_index int first visible items index smart_notification_realized_items
50 * @param end_index int last visible items index used for smart_notification_realized_items
52 void get_realized_items_count(AtspiAccessible *scrollable_object, int *start_idx, int *end_idx)
56 AtspiAccessible *child_iter;
57 AtspiStateType state = ATSPI_STATE_SHOWING;
59 if(!scrollable_object)
61 DEBUG("No scrollable object");
65 count_child = atspi_accessible_get_child_count(scrollable_object, NULL);
67 for(jdx = 0; jdx < count_child; jdx++)
69 child_iter = atspi_accessible_get_child_at_index(scrollable_object, jdx, NULL);
70 if (!child_iter) continue;
72 AtspiStateSet* state_set = atspi_accessible_get_state_set(child_iter);
74 gboolean is_visible = atspi_state_set_contains(state_set, state);
78 DEBUG("Item with index %d is visible", jdx);
81 DEBUG("Item with index %d is NOT visible", jdx);
83 *end_idx = *start_idx + 8;
87 * @brief Scroll-start/Scroll-end event callback
89 * @param event AtspiEvent
90 * @param user_data UNUSED
94 _scroll_event_cb(AtspiEvent *event, gpointer user_data)
99 int start_index, end_index;
103 gchar *role_name = atspi_accessible_get_role_name(event->source, NULL);
104 fprintf(stderr, "Event: %s: %d, obj: %p: role: %s\n",
105 event->type, event->detail1, event->source,
109 if (!strcmp(event->type, "object:scroll-start"))
111 DEBUG("Scrolling started");
112 tts_speak("Scrolling started", EINA_TRUE);
114 else if (!strcmp(event->type, "object:scroll-end"))
116 DEBUG("Scrolling finished");
117 tts_speak("Scrolling finished", EINA_FALSE);
118 get_realized_items_count((AtspiAccessible *)event->source, &start_index, &end_index);
119 _smart_notification_realized_items(start_index, end_index);
124 * @brief Initializer for smart notifications
128 void smart_notification_init(void)
130 DEBUG("Smart Notification init!");
132 AtspiEventListener *listener;
134 listener = atspi_event_listener_new(_scroll_event_cb, NULL, NULL);
135 atspi_event_listener_register(listener, "object:scroll-start", NULL);
136 atspi_event_listener_register(listener, "object:scroll-end", NULL);
138 haptic_module_init();
144 * @brief Smart notifications shutdown
147 void smart_notification_shutdown(void)
153 * @brief Smart notifications focus chain event handler
156 static void _smart_notification_focus_chain_end(void)
161 DEBUG(RED"Smart notification - FOCUS CHAIN END"RESET);
164 tone_player_start(TONE_TYPE_SUP_CONFIRM, SOUND_TYPE_MEDIA, 200, NULL);
168 * @brief Smart notifications realized items event handler
171 static void _smart_notification_realized_items(int start_idx, int end_idx)
176 if(start_idx == end_idx)
179 DEBUG(RED"Smart notification - Visible items notification"RESET);
183 snprintf(buf, sizeof(buf), _("IDS_REACHED_ITEMS_NOTIFICATION"), start_idx, end_idx);
185 tts_speak(strdup(buf), EINA_FALSE);