Browse Source

Fixed bug where slop would ignore the environment variable DISPLAY.

Dalton Nell 10 years ago
parent
commit
5a98bc1b57
6 changed files with 21 additions and 9 deletions
  1. 1
    1
      CMakeLists.txt
  2. 2
    2
      README.md
  3. 3
    3
      src/cmdline.c
  4. 1
    1
      src/cmdline.in
  5. 14
    1
      src/main.cpp
  6. 0
    1
      src/options.ggo

+ 1
- 1
CMakeLists.txt View File

3
 project( "slop" )
3
 project( "slop" )
4
 set( slop_VERSION_MAJOR 3 )
4
 set( slop_VERSION_MAJOR 3 )
5
 set( slop_VERSION_MINOR 1 )
5
 set( slop_VERSION_MINOR 1 )
6
-set( slop_VERSION_PATCH 10 )
6
+set( slop_VERSION_PATCH 11 )
7
 
7
 
8
 set( BIN_TARGET     "${PROJECT_NAME}" )
8
 set( BIN_TARGET     "${PROJECT_NAME}" )
9
 set( CMAKE_INSTALL_PREFIX "/usr/bin" )
9
 set( CMAKE_INSTALL_PREFIX "/usr/bin" )

+ 2
- 2
README.md View File

82
 help
82
 help
83
 ----
83
 ----
84
 ```text
84
 ```text
85
-slop v3.1.10
85
+slop v3.1.11
86
 
86
 
87
 Copyright (C) 2014 Dalton Nell, Slop Contributors
87
 Copyright (C) 2014 Dalton Nell, Slop Contributors
88
 (https://github.com/naelstrof/slop/graphs/contributors)
88
 (https://github.com/naelstrof/slop/graphs/contributors)
96
   -V, --version                 Print version and exit
96
   -V, --version                 Print version and exit
97
 Options
97
 Options
98
       --xdisplay=hostname:number.screen_number
98
       --xdisplay=hostname:number.screen_number
99
-                                Sets the x display.  (default=`:0')
99
+                                Sets the x display.
100
       --nokeyboard              Disables the ability to cancel selections with
100
       --nokeyboard              Disables the ability to cancel selections with
101
                                   the keyboard.  (default=off)
101
                                   the keyboard.  (default=off)
102
   -b, --bordersize=INT          Set the selection rectangle's thickness. Does
102
   -b, --bordersize=INT          Set the selection rectangle's thickness. Does

+ 3
- 3
src/cmdline.c View File

37
   "  -h, --help                    Print help and exit",
37
   "  -h, --help                    Print help and exit",
38
   "  -V, --version                 Print version and exit",
38
   "  -V, --version                 Print version and exit",
39
   "Options",
39
   "Options",
40
-  "      --xdisplay=hostname:number.screen_number\n                                Sets the x display.  (default=`:0')",
40
+  "      --xdisplay=hostname:number.screen_number\n                                Sets the x display.",
41
   "      --nokeyboard              Disables the ability to cancel selections with\n                                  the keyboard.  (default=off)",
41
   "      --nokeyboard              Disables the ability to cancel selections with\n                                  the keyboard.  (default=off)",
42
   "  -b, --bordersize=INT          Set the selection rectangle's thickness. Does\n                                  nothing when --highlight is enabled.\n                                  (default=`5')",
42
   "  -b, --bordersize=INT          Set the selection rectangle's thickness. Does\n                                  nothing when --highlight is enabled.\n                                  (default=`5')",
43
   "  -p, --padding=INT             Set the padding size of the selection. Can be\n                                  negative.  (default=`0')",
43
   "  -p, --padding=INT             Set the padding size of the selection. Can be\n                                  negative.  (default=`0')",
95
 void clear_args (struct gengetopt_args_info *args_info)
95
 void clear_args (struct gengetopt_args_info *args_info)
96
 {
96
 {
97
   FIX_UNUSED (args_info);
97
   FIX_UNUSED (args_info);
98
-  args_info->xdisplay_arg = gengetopt_strdup (":0");
98
+  args_info->xdisplay_arg = NULL;
99
   args_info->xdisplay_orig = NULL;
99
   args_info->xdisplay_orig = NULL;
100
   args_info->nokeyboard_flag = 0;
100
   args_info->nokeyboard_flag = 0;
101
   args_info->bordersize_arg = 5;
101
   args_info->bordersize_arg = 5;
680
           
680
           
681
             if (update_arg( (void *)&(args_info->xdisplay_arg), 
681
             if (update_arg( (void *)&(args_info->xdisplay_arg), 
682
                  &(args_info->xdisplay_orig), &(args_info->xdisplay_given),
682
                  &(args_info->xdisplay_orig), &(args_info->xdisplay_given),
683
-                &(local_args_info.xdisplay_given), optarg, 0, ":0", ARG_STRING,
683
+                &(local_args_info.xdisplay_given), optarg, 0, 0, ARG_STRING,
684
                 check_ambiguity, override, 0, 0,
684
                 check_ambiguity, override, 0, 0,
685
                 "xdisplay", '-',
685
                 "xdisplay", '-',
686
                 additional_error))
686
                 additional_error))

+ 1
- 1
src/cmdline.in View File

39
 {
39
 {
40
   const char *help_help; /**< @brief Print help and exit help description.  */
40
   const char *help_help; /**< @brief Print help and exit help description.  */
41
   const char *version_help; /**< @brief Print version and exit help description.  */
41
   const char *version_help; /**< @brief Print version and exit help description.  */
42
-  char * xdisplay_arg;	/**< @brief Sets the x display. (default=':0').  */
42
+  char * xdisplay_arg;	/**< @brief Sets the x display..  */
43
   char * xdisplay_orig;	/**< @brief Sets the x display. original value given at command line.  */
43
   char * xdisplay_orig;	/**< @brief Sets the x display. original value given at command line.  */
44
   const char *xdisplay_help; /**< @brief Sets the x display. help description.  */
44
   const char *xdisplay_help; /**< @brief Sets the x display. help description.  */
45
   int nokeyboard_flag;	/**< @brief Disables the ability to cancel selections with the keyboard. (default=off).  */
45
   int nokeyboard_flag;	/**< @brief Disables the ability to cancel selections with the keyboard. (default=off).  */

+ 14
- 1
src/main.cpp View File

191
     slop::Rectangle* selection = NULL;
191
     slop::Rectangle* selection = NULL;
192
     Window window = None;
192
     Window window = None;
193
     Window windowmemory = None;
193
     Window windowmemory = None;
194
-    std::string xdisplay = options.xdisplay_arg;
194
+    std::string xdisplay;
195
+    if ( options.xdisplay_given ) {
196
+        xdisplay = options.xdisplay_arg;
197
+    } else {
198
+        // If we weren't specifically given a xdisplay, we try
199
+        // to parse it from environment variables
200
+        char* display = getenv( "DISPLAY" );
201
+        if ( display ) {
202
+            xdisplay = display;
203
+        } else {
204
+            fprintf( stderr, "Warning: Failed to parse environment variable: DISPLAY. Using \":0\" instead.\n" );
205
+            xdisplay = ":0";
206
+        }
207
+    }
195
     int padding = options.padding_arg;
208
     int padding = options.padding_arg;
196
     int borderSize = options.bordersize_arg;
209
     int borderSize = options.bordersize_arg;
197
     int tolerance = options.tolerance_arg;
210
     int tolerance = options.tolerance_arg;

+ 0
- 1
src/options.ggo View File

9
 option "xdisplay" - "Sets the x display."
9
 option "xdisplay" - "Sets the x display."
10
     string
10
     string
11
     typestr="hostname:number.screen_number"
11
     typestr="hostname:number.screen_number"
12
-    default=":0"
13
     optional
12
     optional
14
 
13
 
15
 option "nokeyboard" - "Disables the ability to cancel selections with the keyboard."
14
 option "nokeyboard" - "Disables the ability to cancel selections with the keyboard."