Browse Source

Added a workaround for being incapable of selecting the bottom right corner of pixels, and added option --minimumsize for those who don't want to accidentally select a 0x0 size selection.

Dalton Nell 9 years ago
parent
commit
d4e7c44ec5
7 changed files with 55 additions and 5 deletions
  1. 11
    0
      main.cpp
  2. 10
    2
      options.cpp
  3. 1
    0
      options.hpp
  4. 9
    1
      rectangle.cpp
  5. 3
    1
      rectangle.hpp
  6. 16
    0
      x.cpp
  7. 5
    1
      x.hpp

+ 11
- 0
main.cpp View File

55
     int ymem = 0;
55
     int ymem = 0;
56
     int wmem = 0;
56
     int wmem = 0;
57
     int hmem = 0;
57
     int hmem = 0;
58
+    int minimumsize = options->m_minimumsize;
58
 
59
 
59
     // First we set up the x interface and grab the mouse,
60
     // First we set up the x interface and grab the mouse,
60
     // if we fail for either we exit immediately.
61
     // if we fail for either we exit immediately.
112
                                                          t.m_width,
113
                                                          t.m_width,
113
                                                          t.m_height,
114
                                                          t.m_height,
114
                                                          borderSize, padding,
115
                                                          borderSize, padding,
116
+                                                         minimumsize, minimumsize,
115
                                                          r, g, b );
117
                                                          r, g, b );
116
                     } else {
118
                     } else {
117
                         selection->setGeo( t.m_x, t.m_y, t.m_width, t.m_height );
119
                         selection->setGeo( t.m_x, t.m_y, t.m_width, t.m_height );
149
                                                      xengine->m_mousex - cx,
151
                                                      xengine->m_mousex - cx,
150
                                                      xengine->m_mousey - cy,
152
                                                      xengine->m_mousey - cy,
151
                                                      borderSize, padding,
153
                                                      borderSize, padding,
154
+                                                     minimumsize, minimumsize,
152
                                                      r, g, b );
155
                                                      r, g, b );
153
                 }
156
                 }
154
                 // If the user has let go of the mouse button, we'll just
157
                 // If the user has let go of the mouse button, we'll just
180
                 } else if ( x && y ) {
183
                 } else if ( x && y ) {
181
                     xengine->setCursor( slop::UpperLeftCorner );
184
                     xengine->setCursor( slop::UpperLeftCorner );
182
                 }
185
                 }
186
+                // We're 100% accurate, but the mouse can't select the very bottom row or very right column of pixels.
187
+                // We detect if either are 1 pixel off and attempt to correct it.
188
+                if ( w == xengine->getWidth() - 1 ) {
189
+                    w = xengine->getWidth();
190
+                }
191
+                if ( h == xengine->getHeight() - 1 ) {
192
+                    h = xengine->getHeight();
193
+                }
183
                 // Set the selection rectangle's dimensions to mouse movement.
194
                 // Set the selection rectangle's dimensions to mouse movement.
184
                 // We use the function setDim since rectangles can't have negative widths,
195
                 // We use the function setDim since rectangles can't have negative widths,
185
                 // and because the rectangles have borders and padding to worry about.
196
                 // and because the rectangles have borders and padding to worry about.

+ 10
- 2
options.cpp View File

3
 slop::Options* options = new slop::Options();
3
 slop::Options* options = new slop::Options();
4
 
4
 
5
 slop::Options::Options() {
5
 slop::Options::Options() {
6
-    m_version = "v2.0.2";
6
+    m_version = "v2.0.4";
7
     m_borderSize = 10;
7
     m_borderSize = 10;
8
     m_padding = 0;
8
     m_padding = 0;
9
     m_xdisplay = ":0";
9
     m_xdisplay = ":0";
10
-    m_tolerance = 4;
10
+    m_tolerance = 2;
11
     m_red = 0;
11
     m_red = 0;
12
     m_green = 0;
12
     m_green = 0;
13
     m_blue = 0;
13
     m_blue = 0;
14
     m_gracetime = 0.4;
14
     m_gracetime = 0.4;
15
     m_keyboard = true;
15
     m_keyboard = true;
16
     m_decorations = true;
16
     m_decorations = true;
17
+    m_minimumsize = 0;
17
 }
18
 }
18
 
19
 
19
 void slop::Options::printHelp() {
20
 void slop::Options::printHelp() {
32
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
33
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
33
     printf( "                                   in seconds.\n" );
34
     printf( "                                   in seconds.\n" );
34
     printf( "    -nd, --nodecorations           attempts to remove decorations from window selections.\n" );
35
     printf( "    -nd, --nodecorations           attempts to remove decorations from window selections.\n" );
36
+    printf( "    -m=INT, --minimumsize=INT      sets the minimum output of width or height values, useful to avoid outputting 0\n" );
37
+    printf( "                                   widths or heights.\n" );
35
     printf( "    -v, --version                  prints version.\n" );
38
     printf( "    -v, --version                  prints version.\n" );
36
     printf( "\n" );
39
     printf( "\n" );
37
     printf( "Examples\n" );
40
     printf( "Examples\n" );
58
             if ( m_borderSize < 0 ) {
61
             if ( m_borderSize < 0 ) {
59
                 m_borderSize = 0;
62
                 m_borderSize = 0;
60
             }
63
             }
64
+        } else if ( matches( arg, "-m=", "--minimumsize=" ) ) {
65
+            int err = parseInt( arg, &m_minimumsize );
66
+            if ( err ) {
67
+                return 1;
68
+            }
61
         } else if ( matches( arg, "-p=", "--padding=" ) ) {
69
         } else if ( matches( arg, "-p=", "--padding=" ) ) {
62
             int err = parseInt( arg, &m_padding );
70
             int err = parseInt( arg, &m_padding );
63
             if ( err ) {
71
             if ( err ) {

+ 1
- 0
options.hpp View File

15
     int         m_borderSize;
15
     int         m_borderSize;
16
     int         m_padding;
16
     int         m_padding;
17
     int         m_tolerance;
17
     int         m_tolerance;
18
+    int         m_minimumsize;
18
     float       m_red;
19
     float       m_red;
19
     float       m_green;
20
     float       m_green;
20
     float       m_blue;
21
     float       m_blue;

+ 9
- 1
rectangle.cpp View File

16
     XIfEvent( xengine->m_display, &event, &isDestroyNotify, (XPointer)&m_window );
16
     XIfEvent( xengine->m_display, &event, &isDestroyNotify, (XPointer)&m_window );
17
 }
17
 }
18
 
18
 
19
-slop::Rectangle::Rectangle( int x, int y, int width, int height, int border, int padding, float r, float g, float b ) {
19
+slop::Rectangle::Rectangle( int x, int y, int width, int height, int border, int padding, int minimumwidth, int minimumheight, float r, float g, float b ) {
20
     m_xoffset = 0;
20
     m_xoffset = 0;
21
     m_yoffset = 0;
21
     m_yoffset = 0;
22
     m_x = x;
22
     m_x = x;
23
     m_y = y;
23
     m_y = y;
24
     m_width = width;
24
     m_width = width;
25
     m_height = height;
25
     m_height = height;
26
+    m_minimumwidth = minimumwidth;
27
+    m_minimumheight = minimumheight;
26
     m_border = border;
28
     m_border = border;
27
     m_padding = padding;
29
     m_padding = padding;
28
     m_window = None;
30
     m_window = None;
172
         m_yoffset = -pad;
174
         m_yoffset = -pad;
173
         m_height = h + pad * 2;
175
         m_height = h + pad * 2;
174
     }
176
     }
177
+    if ( m_width < m_minimumwidth ) {
178
+        m_width = m_minimumwidth;
179
+    }
180
+    if ( m_height < m_minimumheight ) {
181
+        m_height = m_minimumheight;
182
+    }
175
 }
183
 }
176
 
184
 
177
 int slop::Rectangle::convertColor( float r, float g, float b ) {
185
 int slop::Rectangle::convertColor( float r, float g, float b ) {

+ 3
- 1
rectangle.hpp View File

20
 
20
 
21
 class Rectangle {
21
 class Rectangle {
22
 public:
22
 public:
23
-            Rectangle( int x, int y, int width, int height, int border, int padding, float r, float g, float b );
23
+            Rectangle( int x, int y, int width, int height, int border, int padding, int minimumwidth, int minimumheight, float r, float g, float b );
24
             ~Rectangle();
24
             ~Rectangle();
25
     void    setPos( int x, int y );
25
     void    setPos( int x, int y );
26
     void    setDim( int w, int h );
26
     void    setDim( int w, int h );
31
     int     m_y;
31
     int     m_y;
32
     int     m_xoffset;
32
     int     m_xoffset;
33
     int     m_yoffset;
33
     int     m_yoffset;
34
+    int     m_minimumwidth;
35
+    int     m_minimumheight;
34
     int     m_width;
36
     int     m_width;
35
     int     m_height;
37
     int     m_height;
36
     int     m_border;
38
     int     m_border;

+ 16
- 0
x.cpp View File

20
     exit(1);
20
     exit(1);
21
 }
21
 }
22
 
22
 
23
+int slop::XEngine::getWidth() {
24
+    if ( !m_good ) {
25
+        return -1;
26
+    }
27
+    return (int)WidthOfScreen( m_screen );
28
+}
29
+
30
+int slop::XEngine::getHeight() {
31
+    if ( !m_good ) {
32
+        return -1;
33
+    }
34
+    return (int)HeightOfScreen( m_screen );
35
+}
36
+
23
 slop::XEngine::XEngine() {
37
 slop::XEngine::XEngine() {
24
     m_display = NULL;
38
     m_display = NULL;
25
     m_visual = NULL;
39
     m_visual = NULL;
228
         case UpperRightCorner:      xfontcursor = XC_ur_angle; break;
242
         case UpperRightCorner:      xfontcursor = XC_ur_angle; break;
229
         case LowerLeftCorner:       xfontcursor = XC_ll_angle; break;
243
         case LowerLeftCorner:       xfontcursor = XC_ll_angle; break;
230
         case LowerRightCorner:      xfontcursor = XC_lr_angle; break;
244
         case LowerRightCorner:      xfontcursor = XC_lr_angle; break;
245
+        case Dot:                   xfontcursor = XC_dot; break;
246
+        case Box:                   xfontcursor = 40; break;
231
     }
247
     }
232
     Cursor newcursor = 0;
248
     Cursor newcursor = 0;
233
     if ( m_cursors.size() > xfontcursor ) {
249
     if ( m_cursors.size() > xfontcursor ) {

+ 5
- 1
x.hpp View File

24
     UpperLeftCorner,
24
     UpperLeftCorner,
25
     UpperRightCorner,
25
     UpperRightCorner,
26
     LowerRightCorner,
26
     LowerRightCorner,
27
-    LowerLeftCorner
27
+    LowerLeftCorner,
28
+    Dot,
29
+    Box
28
 };
30
 };
29
 
31
 
30
 class WindowRectangle {
32
 class WindowRectangle {
51
     int                 releaseKeyboard();
53
     int                 releaseKeyboard();
52
     void                setCursor( slop::CursorType type );
54
     void                setCursor( slop::CursorType type );
53
     void                drawRect( int x, int y, unsigned int w, unsigned int h );
55
     void                drawRect( int x, int y, unsigned int w, unsigned int h );
56
+    int                 getWidth();
57
+    int                 getHeight();
54
     int                 m_mousex;
58
     int                 m_mousex;
55
     int                 m_mousey;
59
     int                 m_mousey;
56
     Display*            m_display;
60
     Display*            m_display;