[at_spi2_tool] report x, y information of accessible object
[platform/upstream/at-spi2-core.git] / test / at_spi2_tool.c
index 8c6bc6f..7a7b9a5 100644 (file)
@@ -17,6 +17,7 @@
 #define DUMP 0
 #define CHECK 1
 #define FIRST_MATCH 2
+#define VERSION "1.1"
 
 static unsigned indent_width = 2;
 static int module_name_limit = -1;
@@ -72,8 +73,10 @@ static const char* atspi_state_names[] = {
 };
 
 typedef struct _Box_Size {
-       int height;
-       int width;
+       char *x;
+       char *y;
+       char *height;
+       char *width;
 } Box_Size;
 
 char *_strdup(const char *c)
@@ -96,7 +99,7 @@ static char *_multiply_string(char c, unsigned number)
 
 static void _print_module_legend()
 {
-       printf("\n[[node role name],[attributes list],[width,height],[node name],[states list]]\n\n");
+       printf("\n[[node role name],[attributes list],[x,y,width,height],[node name],[states list]]\n\n");
 }
 
 static void _print_atspi_states_legend()
@@ -193,23 +196,42 @@ static Box_Size *_get_box_size(AtspiAccessible *node)
        if (box_size == NULL)
                return NULL;
 
-       box_size->width = -1;
-       box_size->height = -1;
+       char *x = NULL;
+       char *y = NULL;
+       char *width = NULL;
+       char *height = NULL;
 
        AtspiComponent *component = atspi_accessible_get_component_iface(node);
+       AtspiRect *extent = component ? atspi_component_get_extents(component, ATSPI_COORD_TYPE_SCREEN, NULL) : NULL;
 
-       if (component == NULL)
-               return box_size;
+       if (extent == NULL) {
+               _combine_strings(&x, "_");
+               _combine_strings(&y, "_");
+               _combine_strings(&width, "_");
+               _combine_strings(&height, "_");
+       } else {
+               char temp_buff[NUMBER_WIDTH];
+
+               snprintf(temp_buff, NUMBER_WIDTH, "%d", extent->x);
+               _combine_strings(&x, temp_buff);
+
+               snprintf(temp_buff, NUMBER_WIDTH, "%d", extent->y);
+               _combine_strings(&y, temp_buff);
 
-       AtspiRect *extent = atspi_component_get_extents(component, ATSPI_COORD_TYPE_SCREEN, NULL);
-       if (extent == NULL)
-               return box_size;
+               snprintf(temp_buff, NUMBER_WIDTH, "%d", extent->width);
+               _combine_strings(&width, temp_buff);
 
-       box_size->width = extent->width;
-       box_size->height = extent->height;
+               snprintf(temp_buff, NUMBER_WIDTH, "%d", extent->height);
+               _combine_strings(&height, temp_buff);
+
+               g_object_unref(component);
+               g_free(extent);
+       }
 
-       g_object_unref(component);
-       g_free(extent);
+       box_size->x = x;
+       box_size->y = y;
+       box_size->width = width;
+       box_size->height = height;
 
        return box_size;
 }
@@ -279,9 +301,11 @@ static char *_get_info(AtspiAccessible *node, int length_limit)
        _truncate_string(states, length_limit);
 
        char result[SAFE_BUFFER_SIZE];
-       int ret = snprintf(result, SAFE_BUFFER_SIZE, "[[%s],[%s],[%d,%d],[%s],[%s]]",
+       int ret = snprintf(result, SAFE_BUFFER_SIZE, "[[%s],[%s],[%s,%s,%s,%s],[%s],[%s]]",
                                                                                node_role_name,
                                                                                attributes,
+                                                                               box_size->x,
+                                                                               box_size->y,
                                                                                box_size->width,
                                                                                box_size->height,
                                                                                node_name,
@@ -295,7 +319,11 @@ static char *_get_info(AtspiAccessible *node, int length_limit)
        free(node_name);
        free(node_role_name);
        free(attributes);
-       free(box_size);
+       if (box_size) {
+               free(box_size->width);
+               free(box_size->height);
+               free(box_size);
+       }
        free(states);
 
        return _strdup(result);
@@ -357,6 +385,7 @@ void _print_help()
        printf("USAGE: at_spi2_tool [OPTION] [PARAMETER] ...\n\n");
        printf("OPTION LIST:\n");
        printf("-h, --help\t\tshow this message\n");
+       printf("-v, --version\t\tshow actual version of tool\n");
        printf("-g, --show-legend\tprint AT-SPI state legend\n");
        printf("-l, --list-apps\t\tlist all applications of desktop\n");
        printf("-d, --tree-dump\t\tdump tree for selected application\n");
@@ -370,6 +399,10 @@ void _print_help()
        printf("\tat_spi2_tool -i1 -c starter\n");
        printf("\t  show AT-SPI tree with integrity test for node \"starter\" using one-space indentation\n");
 }
+void _print_version()
+{
+       printf("AT-SPI2-CORE-UTIL v%s\n", VERSION);
+}
 
 static void _atspi_tree_traverse(AtspiAccessible *desktop, const char *app_name, bool dump, bool check, bool first_match, int length_limit)
 {
@@ -412,6 +445,7 @@ static void _run_command(int argc, char *argv[], AtspiAccessible *desktop)
 {
        struct option long_options[] = {
                {"help", no_argument, 0, 'h'},
+               {"version", no_argument, 0, 'v'},
                {"show-legend", no_argument, 0, 'g'},
                {"list-apps", no_argument, 0, 'l'},
                {"tree-dump", required_argument, 0, 'd'},
@@ -427,7 +461,7 @@ static void _run_command(int argc, char *argv[], AtspiAccessible *desktop)
        char *app_name = NULL;
 
        while (TRUE) {
-               command = getopt_long(argc, argv, "hgld:c:ft:i:", long_options, &option_index);
+               command = getopt_long(argc, argv, "hvgld:c:ft:i:", long_options, &option_index);
 
                if (command == ERROR_STATE)
                        break;
@@ -437,6 +471,10 @@ static void _run_command(int argc, char *argv[], AtspiAccessible *desktop)
                        _print_help();
                        break;
 
+               case 'v':
+                       _print_version();
+                       break;
+
                case 'g':
                        _print_atspi_states_legend();
                        break;