Quellcode durchsuchen

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

Dalton Nell vor 9 Jahren
Ursprung
Commit
9bd51fe1c2
3 geänderte Dateien mit 24 neuen und 15 gelöschten Zeilen
  1. 5
    4
      README.md
  2. 14
    6
      main.cpp
  3. 5
    5
      options.cpp

+ 5
- 4
README.md Datei anzeigen

14
     * Select X display.
14
     * Select X display.
15
     * Set padding size, even negative padding sizes!
15
     * Set padding size, even negative padding sizes!
16
     * Set click tolerance for if you have a shaky mouse.
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
     * Remove window decorations from selections.
18
     * Remove window decorations from selections.
19
 
19
 
20
 practical applications
20
 practical applications
34
 eval `slop`
34
 eval `slop`
35
 import -window root -crop $G ~/myimage.png
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
 You can see my implementation of slop in a screenshooter here:
39
 You can see my implementation of slop in a screenshooter here:
39
 https://gist.github.com/naelstrof/6530959
40
 https://gist.github.com/naelstrof/6530959
41
 lets see some action
42
 lets see some action
42
 --------------------
43
 --------------------
43
 Ok. Here's a comparison between 'scrot -s's selection and slop's:
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
 You can see scrot leaves garbage lines over the things you're trying to screenshot!
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
 help
51
 help
51
 ----
52
 ----

+ 14
- 6
main.cpp Datei anzeigen

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

+ 5
- 5
options.cpp Datei anzeigen

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.1.3";
6
+    m_version = "v2.1.4";
7
     m_highlight = false;
7
     m_highlight = false;
8
-    m_borderSize = 10;
8
+    m_borderSize = 5;
9
     m_padding = 0;
9
     m_padding = 0;
10
     m_xdisplay = ":0";
10
     m_xdisplay = ":0";
11
     m_tolerance = 2;
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
     m_alpha = 1;
15
     m_alpha = 1;
16
     m_gracetime = 0.4;
16
     m_gracetime = 0.4;
17
     m_keyboard = true;
17
     m_keyboard = true;