Pārlūkot izejas kodu

Changed default color and size, improved readme a little, and slop now outputs the ID of the selected window.

Dalton Nell 9 gadus atpakaļ
vecāks
revīzija
9bd51fe1c2
3 mainītis faili ar 24 papildinājumiem un 15 dzēšanām
  1. 5
    4
      README.md
  2. 14
    6
      main.cpp
  3. 5
    5
      options.cpp

+ 5
- 4
README.md Parādīt failu

@@ -14,7 +14,7 @@ features
14 14
     * Select X display.
15 15
     * Set padding size, even negative padding sizes!
16 16
     * Set click tolerance for if you have a shaky mouse.
17
-    * Set the color of the selection rectangles to match your theme!
17
+    * Set the color of the selection rectangles to match your theme! (Even supports transparency!)
18 18
     * Remove window decorations from selections.
19 19
 
20 20
 practical applications
@@ -34,6 +34,7 @@ You can also take images using imagemagick like so:
34 34
 eval `slop`
35 35
 import -window root -crop $G ~/myimage.png
36 36
 ```
37
+If you don't like ImageMagick's import: Check out [maim](https://github.com/naelstrof/maim) for a better screenshot utility.
37 38
 
38 39
 You can see my implementation of slop in a screenshooter here:
39 40
 https://gist.github.com/naelstrof/6530959
@@ -41,11 +42,11 @@ https://gist.github.com/naelstrof/6530959
41 42
 lets see some action
42 43
 --------------------
43 44
 Ok. Here's a comparison between 'scrot -s's selection and slop's:
44
-![scrotbad](http://farmpolice.com/content/images/scrot_bad.png)
45
-![slopgood](http://farmpolice.com/content/images/slrn_good.png)
45
+![scrotbad](http://farmpolice.com/content/images/2014-10-14-12:08:24.png)
46
+![slopgood](http://farmpolice.com/content/images/2014-10-14-12:14:51.png)
46 47
 
47 48
 You can see scrot leaves garbage lines over the things you're trying to screenshot!
48
-While slop not only looks nicer, it's impossible for it to end up in screenshots or recordings because it waits for DestroyNotify events before completely shutting down. Only after the window is completely destroyed can ffmpeg or imagemagick take a picture.
49
+While slop not only looks nicer, it's impossible for it to end up in screenshots or recordings because it waits for DestroyNotify events before completely shutting down. Only after the window is completely destroyed can anything take a screenshot.
49 50
 
50 51
 help
51 52
 ----

+ 14
- 6
main.cpp Parādīt failu

@@ -4,7 +4,7 @@
4 4
 #include "rectangle.hpp"
5 5
 #include "options.hpp"
6 6
 
7
-void printSelection( bool cancelled, int x, int y, int w, int h ) {
7
+void printSelection( bool cancelled, int x, int y, int w, int h, int window ) {
8 8
     printf( "X=%i\n", x );
9 9
     printf( "Y=%i\n", y );
10 10
     printf( "W=%i\n", w );
@@ -23,6 +23,7 @@ void printSelection( bool cancelled, int x, int y, int w, int h ) {
23 23
         printf( "%i", y );
24 24
     }
25 25
     printf( "\n" );
26
+    printf( "ID=%i\n", window );
26 27
     if ( cancelled ) {
27 28
         printf( "Cancel=true\n" );
28 29
     } else {
@@ -91,6 +92,7 @@ int main( int argc, char** argv ) {
91 92
     bool running = true;
92 93
     slop::Rectangle* selection = NULL;
93 94
     Window window = None;
95
+    Window windowmemory = None;
94 96
     std::string xdisplay = options->m_xdisplay;
95 97
     int padding = options->m_padding;
96 98
     int borderSize = options->m_borderSize;
@@ -116,12 +118,12 @@ int main( int argc, char** argv ) {
116 118
     // if we fail for either we exit immediately.
117 119
     err = xengine->init( xdisplay.c_str() );
118 120
     if ( err ) {
119
-        printSelection( true, 0, 0, 0, 0 );
121
+        printSelection( true, 0, 0, 0, 0, None );
120 122
         return err;
121 123
     }
122 124
     err = xengine->grabCursor( slop::Cross );
123 125
     if ( err ) {
124
-        printSelection( true, 0, 0, 0, 0 );
126
+        printSelection( true, 0, 0, 0, 0, None );
125 127
         return err;
126 128
     }
127 129
     if ( keyboard ) {
@@ -143,7 +145,7 @@ int main( int argc, char** argv ) {
143 145
         double starti = double( start.tv_sec*1000000000L + start.tv_nsec )/1000000000.f;
144 146
         if ( timei - starti > options->m_gracetime ) {
145 147
             if ( ( xengine->anyKeyPressed() && keyboard ) || xengine->mouseDown( 3 ) ) {
146
-                printSelection( true, 0, 0, 0, 0 );
148
+                printSelection( true, 0, 0, 0, 0, None );
147 149
                 fprintf( stderr, "User pressed key. Canceled selection.\n" );
148 150
                 state = -1;
149 151
                 running = false;
@@ -213,6 +215,7 @@ int main( int argc, char** argv ) {
213 215
                                                      highlight,
214 216
                                                      r, g, b, a );
215 217
                 }
218
+                windowmemory = window;
216 219
                 // If the user has let go of the mouse button, we'll just
217 220
                 // continue to the next state.
218 221
                 if ( !xengine->mouseDown( 1 ) ) {
@@ -226,12 +229,17 @@ int main( int argc, char** argv ) {
226 229
                     // We make sure the selection rectangle stays on the window we had selected
227 230
                     selection->setGeo( xmem, ymem, xmem + wmem, ymem + hmem );
228 231
                     xengine->setCursor( slop::Left );
232
+                    // Make sure
233
+                    window = windowmemory;
229 234
                     continue;
230 235
                 }
236
+                // If we're not selecting a window.
237
+                windowmemory = window;
238
+                window = None;
231 239
                 // We also detect which way the user is pulling and set the mouse icon accordingly.
232 240
                 bool x = cx > xengine->m_mousex;
233 241
                 bool y = cy > xengine->m_mousey;
234
-                if ( selection->m_width <= 1 && selection->m_height <= 1 || minimumsize == maximumsize ) {
242
+                if ( selection->m_width <= 1 && selection->m_height <= 1 || ( minimumsize == maximumsize && minimumsize != 0 && maximumsize != 0 ) ) {
235 243
                     xengine->setCursor( slop::Cross );
236 244
                 } else if ( !x && !y ) {
237 245
                     xengine->setCursor( slop::LowerRightCorner );
@@ -263,7 +271,7 @@ int main( int argc, char** argv ) {
263 271
                 // Delete the rectangle, which will remove it from the screen.
264 272
                 delete selection;
265 273
                 // Print the selection :)
266
-                printSelection( false, x, y, w, h );
274
+                printSelection( false, x, y, w, h, window );
267 275
                 break;
268 276
             }
269 277
         }

+ 5
- 5
options.cpp Parādīt failu

@@ -3,15 +3,15 @@
3 3
 slop::Options* options = new slop::Options();
4 4
 
5 5
 slop::Options::Options() {
6
-    m_version = "v2.1.3";
6
+    m_version = "v2.1.4";
7 7
     m_highlight = false;
8
-    m_borderSize = 10;
8
+    m_borderSize = 5;
9 9
     m_padding = 0;
10 10
     m_xdisplay = ":0";
11 11
     m_tolerance = 2;
12
-    m_red = 0;
13
-    m_green = 0;
14
-    m_blue = 0;
12
+    m_red = 0.5;
13
+    m_green = 0.5;
14
+    m_blue = 0.5;
15 15
     m_alpha = 1;
16 16
     m_gracetime = 0.4;
17 17
     m_keyboard = true;