Ver código fonte

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 anos atrás
pai
commit
d4e7c44ec5
7 arquivos alterados com 55 adições e 5 exclusões
  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 Ver arquivo

@@ -55,6 +55,7 @@ int main( int argc, char** argv ) {
55 55
     int ymem = 0;
56 56
     int wmem = 0;
57 57
     int hmem = 0;
58
+    int minimumsize = options->m_minimumsize;
58 59
 
59 60
     // First we set up the x interface and grab the mouse,
60 61
     // if we fail for either we exit immediately.
@@ -112,6 +113,7 @@ int main( int argc, char** argv ) {
112 113
                                                          t.m_width,
113 114
                                                          t.m_height,
114 115
                                                          borderSize, padding,
116
+                                                         minimumsize, minimumsize,
115 117
                                                          r, g, b );
116 118
                     } else {
117 119
                         selection->setGeo( t.m_x, t.m_y, t.m_width, t.m_height );
@@ -149,6 +151,7 @@ int main( int argc, char** argv ) {
149 151
                                                      xengine->m_mousex - cx,
150 152
                                                      xengine->m_mousey - cy,
151 153
                                                      borderSize, padding,
154
+                                                     minimumsize, minimumsize,
152 155
                                                      r, g, b );
153 156
                 }
154 157
                 // If the user has let go of the mouse button, we'll just
@@ -180,6 +183,14 @@ int main( int argc, char** argv ) {
180 183
                 } else if ( x && y ) {
181 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 194
                 // Set the selection rectangle's dimensions to mouse movement.
184 195
                 // We use the function setDim since rectangles can't have negative widths,
185 196
                 // and because the rectangles have borders and padding to worry about.

+ 10
- 2
options.cpp Ver arquivo

@@ -3,17 +3,18 @@
3 3
 slop::Options* options = new slop::Options();
4 4
 
5 5
 slop::Options::Options() {
6
-    m_version = "v2.0.2";
6
+    m_version = "v2.0.4";
7 7
     m_borderSize = 10;
8 8
     m_padding = 0;
9 9
     m_xdisplay = ":0";
10
-    m_tolerance = 4;
10
+    m_tolerance = 2;
11 11
     m_red = 0;
12 12
     m_green = 0;
13 13
     m_blue = 0;
14 14
     m_gracetime = 0.4;
15 15
     m_keyboard = true;
16 16
     m_decorations = true;
17
+    m_minimumsize = 0;
17 18
 }
18 19
 
19 20
 void slop::Options::printHelp() {
@@ -32,6 +33,8 @@ void slop::Options::printHelp() {
32 33
     printf( "    -g=FLOAT, --gracetime=FLOAT    Set the amount of time before slop will check for keyboard cancellations\n" );
33 34
     printf( "                                   in seconds.\n" );
34 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 38
     printf( "    -v, --version                  prints version.\n" );
36 39
     printf( "\n" );
37 40
     printf( "Examples\n" );
@@ -58,6 +61,11 @@ int slop::Options::parseOptions( int argc, char** argv ) {
58 61
             if ( m_borderSize < 0 ) {
59 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 69
         } else if ( matches( arg, "-p=", "--padding=" ) ) {
62 70
             int err = parseInt( arg, &m_padding );
63 71
             if ( err ) {

+ 1
- 0
options.hpp Ver arquivo

@@ -15,6 +15,7 @@ public:
15 15
     int         m_borderSize;
16 16
     int         m_padding;
17 17
     int         m_tolerance;
18
+    int         m_minimumsize;
18 19
     float       m_red;
19 20
     float       m_green;
20 21
     float       m_blue;

+ 9
- 1
rectangle.cpp Ver arquivo

@@ -16,13 +16,15 @@ slop::Rectangle::~Rectangle() {
16 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 20
     m_xoffset = 0;
21 21
     m_yoffset = 0;
22 22
     m_x = x;
23 23
     m_y = y;
24 24
     m_width = width;
25 25
     m_height = height;
26
+    m_minimumwidth = minimumwidth;
27
+    m_minimumheight = minimumheight;
26 28
     m_border = border;
27 29
     m_padding = padding;
28 30
     m_window = None;
@@ -172,6 +174,12 @@ void slop::Rectangle::constrain( int w, int h ) {
172 174
         m_yoffset = -pad;
173 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 185
 int slop::Rectangle::convertColor( float r, float g, float b ) {

+ 3
- 1
rectangle.hpp Ver arquivo

@@ -20,7 +20,7 @@ namespace slop {
20 20
 
21 21
 class Rectangle {
22 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 24
             ~Rectangle();
25 25
     void    setPos( int x, int y );
26 26
     void    setDim( int w, int h );
@@ -31,6 +31,8 @@ public:
31 31
     int     m_y;
32 32
     int     m_xoffset;
33 33
     int     m_yoffset;
34
+    int     m_minimumwidth;
35
+    int     m_minimumheight;
34 36
     int     m_width;
35 37
     int     m_height;
36 38
     int     m_border;

+ 16
- 0
x.cpp Ver arquivo

@@ -20,6 +20,20 @@ int slop::XEngineErrorHandler( Display* dpy, XErrorEvent* event ) {
20 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 37
 slop::XEngine::XEngine() {
24 38
     m_display = NULL;
25 39
     m_visual = NULL;
@@ -228,6 +242,8 @@ Cursor slop::XEngine::getCursor( slop::CursorType type ) {
228 242
         case UpperRightCorner:      xfontcursor = XC_ur_angle; break;
229 243
         case LowerLeftCorner:       xfontcursor = XC_ll_angle; break;
230 244
         case LowerRightCorner:      xfontcursor = XC_lr_angle; break;
245
+        case Dot:                   xfontcursor = XC_dot; break;
246
+        case Box:                   xfontcursor = 40; break;
231 247
     }
232 248
     Cursor newcursor = 0;
233 249
     if ( m_cursors.size() > xfontcursor ) {

+ 5
- 1
x.hpp Ver arquivo

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