annotate dep/animone/src/a11y/atspi.cc @ 367:8d45d892be88 default tip

*: instead of pugixml, use Qt XML features this means we have one extra Qt dependency though...
author Paper <paper@tflc.us>
date Sun, 17 Nov 2024 22:55:47 -0500
parents 886f66775f31
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
366
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
1 #include <functional>
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
2 #include <string>
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
3 #include <vector>
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
4 #include <memory>
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
5
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
6 #include "animone.h"
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
7 #include "animone/a11y/atspi.h"
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
8
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
9 #include <atspi/atspi.h>
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
10
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
11 namespace animone::internal::atspi {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
12
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
13 /* deleters */
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
14 template<typename T>
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
15 struct g_object_del {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
16 void operator()(T* p) const { ::g_object_unref(p); };
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
17 };
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
18
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
19 template<typename T>
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
20 using GObjectPtr = std::unique_ptr<T, g_object_del<T>>;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
21
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
22 /* ----------------------------------------------------------------- */
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
23
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
24 // FIXME | atspi_exit()
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
25 bool GetWebBrowserInformation(const Result& result, web_browser_proc_t web_browser_proc) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
26 GObjectPtr<AtspiAccessible> desktop;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
27 GObjectPtr<AtspiAccessible> application;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
28
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
29 {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
30 int err = atspi_init();
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
31 if (err != 0 && err != 1)
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
32 return false;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
33 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
34
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
35 // Currently only one desktop is supported, so this is equivalent to doing
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
36 // just atspi_get_desktop(0). However it's nice to futureproof where possible.
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
37 for (gint i = 0; i < atspi_get_desktop_count(); i++) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
38 desktop.reset(atspi_get_desktop(i));
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
39 if (!desktop)
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
40 return false;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
41
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
42 for (gint j = 0; j < atspi_accessible_get_child_count(application.get(), nullptr); j++) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
43 application.reset(atspi_accessible_get_child_at_index(desktop.get(), j, nullptr));
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
44 if (!application)
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
45 return false;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
46
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
47 GError *error = NULL;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
48
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
49 std::uint32_t pid = atspi_accessible_get_process_id(application.get(), &error);
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
50 if (error) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
51 ::g_error_free(error);
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
52 return false;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
53 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
54
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
55 if (pid == result.process.pid)
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
56 goto found; // found it
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
57 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
58 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
59
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
60 // didn't get anything... lol
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
61 return false;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
62
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
63 found:
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
64 // found a matching application
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
65
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
66 gchar *title = atspi_accessible_get_name(application.get(), NULL);
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
67 if (title) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
68 web_browser_proc({WebBrowserInformationType::Title, title});
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
69 ::g_free(title);
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
70 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
71
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
72 // TODO need to find address and tab? idk
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
73
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
74 return true;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
75 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
76
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
diff changeset
77 }