From eef50cfd0c7c548c8cc50da22fb41ed1c0de4a6a Mon Sep 17 00:00:00 2001
From: Stefano Guazzotti <avernan@gmail.com>
Date: Sun, 12 Nov 2017 20:06:54 +0000
Subject: [PATCH] Change getmouselocation to set the window stack

Added an option --window-stack in order to leave the default behaviour
unchanged.
---
 cmd_getmouselocation.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/cmd_getmouselocation.c b/cmd_getmouselocation.c
index 1ce8432..27bd912 100644
--- a/cmd_getmouselocation.c
+++ b/cmd_getmouselocation.c
@@ -11,14 +11,17 @@ int cmd_getmouselocation(context_t *context) {
     { "help", no_argument, NULL, 'h' },
     { "shell", no_argument, NULL, 's' },
     { "prefix", required_argument, NULL, 'p' },
+    { "window-stack", no_argument, NULL, 'w' },
     { 0, 0, 0, 0 },
   };
   static const char *usage = 
     "Usage: %s [--shell] [--prefix <STR>]\n"
     "--shell      - output shell variables for use with eval\n"
-    "--prefix STR - use prefix for shell variables names (max 16 chars) \n";
+    "--prefix STR - use prefix for shell variables names (max 16 chars) \n"
+    "--window-stack - add window to the WINDOW STACK\n";
   int option_index;
   int output_shell = 0;
+  int window_stack = 0;
   char out_prefix[17] = {'\0'};
 
   while ((c = getopt_long_only(context->argc, context->argv, "+h",
@@ -36,6 +39,9 @@ int cmd_getmouselocation(context_t *context) {
         strncpy(out_prefix, optarg, sizeof(out_prefix)-1);
         out_prefix[ sizeof(out_prefix)-1 ] = '\0'; //just in case
         break;
+      case 'w':
+        window_stack = 1;
+        break;
       default:
         fprintf(stderr, usage, cmd);
         return EXIT_FAILURE;
@@ -54,6 +60,9 @@ int cmd_getmouselocation(context_t *context) {
   } else {
     xdotool_output(context, "x:%d y:%d screen:%d window:%ld", x, y, screen_num, window);
   }
+  if (window_stack) {
+    window_save(context, window);
+  }
   return ret;
 }