1 #include "xdo_cmd.h"
2 
cmd_windowmap(context_t * context)3 int cmd_windowmap(context_t *context) {
4   int ret = 0;
5   char *cmd = *context->argv;
6   const char *window_arg = "%1";
7   int opsync = 0;
8 
9   int c;
10   enum { opt_unused, opt_help, opt_sync };
11   static struct option longopts[] = {
12     { "help", no_argument, NULL, opt_help },
13     { "sync", no_argument, NULL, opt_sync },
14     { 0, 0, 0, 0 },
15   };
16   static const char *usage =
17     "Usage: %s [options] [window=%1]\n"
18     "--sync    - only exit once the window has been mapped (is visible)\n"
19     HELP_SEE_WINDOW_STACK;
20 
21   int option_index;
22   while ((c = getopt_long_only(context->argc, context->argv, "+h",
23                                longopts, &option_index)) != -1) {
24     switch (c) {
25       case 'h':
26       case opt_help:
27         printf(usage, cmd);
28         consume_args(context, context->argc);
29         return EXIT_SUCCESS;
30         break;
31       case opt_sync:
32         opsync = 1;
33         break;
34       default:
35         fprintf(stderr, usage, cmd);
36         return EXIT_FAILURE;
37     }
38   }
39 
40   consume_args(context, optind);
41 
42   if (!window_get_arg(context, 0, 0, &window_arg)) {
43     fprintf(stderr, usage, cmd);
44     return EXIT_FAILURE;
45   }
46 
47   window_each(context, window_arg, {
48     ret = xdo_map_window(context->xdo, window);
49     if (ret) {
50       fprintf(stderr, "xdo_map_window reported an error\n");
51     } else {
52       if (opsync) {
53         xdo_wait_for_window_map_state(context->xdo, window, IsViewable);
54       }
55     }
56   }); /* window_each(...) */
57 
58   return ret;
59 }
60