|
| 1 | +// Through the module: a window holding a button built, read back through the |
| 2 | +// library's debug view, and on Linux served by an AT-SPI adapter. The names |
| 3 | +// are AccessKit's own (no namespace of this package's). |
| 4 | +import std; |
| 5 | +import mcpplibs.mwrap.accesskit; |
| 6 | + |
| 7 | +namespace { |
| 8 | + |
| 9 | +accesskit_tree_update* tree(void*) { |
| 10 | + accesskit_node* window = accesskit_node_new(ACCESSKIT_ROLE_WINDOW); |
| 11 | + accesskit_node_set_label(window, "Settings"); |
| 12 | + accesskit_node_push_child(window, 2); |
| 13 | + accesskit_node* button = accesskit_node_new(ACCESSKIT_ROLE_BUTTON); |
| 14 | + accesskit_node_set_label(button, "Save"); |
| 15 | + accesskit_node_add_action(button, ACCESSKIT_ACTION_CLICK); |
| 16 | + accesskit_node_set_toggled(button, ACCESSKIT_TOGGLED_FALSE); |
| 17 | + accesskit_tree_update* update = accesskit_tree_update_with_capacity_and_focus(2, 2); |
| 18 | + accesskit_tree_update_set_tree_info(update, accesskit_tree_info_new(1)); |
| 19 | + accesskit_tree_update_push_node(update, 1, window); |
| 20 | + accesskit_tree_update_push_node(update, 2, button); |
| 21 | + return update; |
| 22 | +} |
| 23 | + |
| 24 | +} // namespace |
| 25 | + |
| 26 | +int main() { |
| 27 | + accesskit_tree_update* update = tree(nullptr); |
| 28 | + char* debug = accesskit_tree_update_debug(update); |
| 29 | + const bool named = debug && std::string_view(debug).contains("Save") && std::string_view(debug).contains("Settings"); |
| 30 | + if (debug) accesskit_string_free(debug); |
| 31 | + accesskit_tree_update_free(update); |
| 32 | + if (!named) { |
| 33 | + std::println(std::cerr, "the update does not hold the window and its button"); |
| 34 | + return 1; |
| 35 | + } |
| 36 | +#if defined(__linux__) |
| 37 | + accesskit_unix_adapter* adapter = accesskit_unix_adapter_new( |
| 38 | + tree, nullptr, [](accesskit_action_request* r, void*) { accesskit_action_request_free(r); }, nullptr, [](void*) {}, nullptr); |
| 39 | + if (!adapter) { |
| 40 | + std::println(std::cerr, "no AT-SPI adapter"); |
| 41 | + return 1; |
| 42 | + } |
| 43 | + accesskit_unix_adapter_update_window_focus_state(adapter, true); |
| 44 | + accesskit_unix_adapter_free(adapter); |
| 45 | +#endif |
| 46 | + std::println("accesskit through its module: a window and its button"); |
| 47 | + return 0; |
| 48 | +} |
0 commit comments