Explorar el Código

name change, slrn was taken by some guy from 1994

naelstrof hace 10 años
padre
commit
09205e1be1
Se han modificado 7 ficheros con 66 adiciones y 66 borrados
  1. 11
    11
      README.md
  2. 11
    11
      main.cpp
  3. 2
    2
      makefile
  4. 11
    11
      options.cpp
  5. 2
    2
      options.hpp
  6. 24
    24
      x.cpp
  7. 5
    5
      x.hpp

+ 11
- 11
README.md Ver fichero

@@ -1,12 +1,12 @@
1
-slrn
1
+slop
2 2
 ====
3 3
 
4
-slrn (Select Region) is an application that querys for a selection from the user and prints the region to stdout. It grabs the mouse and turns it into a crosshair, lets the user click and drag to make a selection (or click on a window) while drawing a pretty box around it, then finally prints the selection's dimensions to stdout.
4
+slop (Select Operation) is an application that querys for a selection from the user and prints the region to stdout. It grabs the mouse and turns it into a crosshair, lets the user click and drag to make a selection (or click on a window) while drawing a pretty box around it, then finally prints the selection's dimensions to stdout.
5 5
 
6 6
 features
7 7
 --------
8 8
 * Hovering over a window will cause a selection rectangle to appear over it.
9
-* Clicking on a window makes slrn return the dimensions of the window.
9
+* Clicking on a window makes slop return the dimensions of the window.
10 10
 * Clicking and dragging causes a selection rectangle to appear, renders pretty well (compared to scrot). And will return the dimensions of that rectangle in absolute screen coords.
11 11
 * On startup it turns your cursor into a crosshair, then adjusts the cursor into angles as you drag the selection rectangle.
12 12
 * Supports simple arguments:
@@ -18,27 +18,27 @@ features
18 18
 
19 19
 practical applications
20 20
 ----------------------
21
-slrn can be used to create a video recording script in only two lines of code.
21
+slop can be used to create a video recording script in only two lines of code.
22 22
 ```bash
23 23
 #!/bin/bash
24
-eval `slrn`
24
+eval `slop`
25 25
 ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -f alsa -i pulse ~/myfile.webm
26 26
 ```
27
-slrn lets you select a region or window and ffmpeg will record it in the format of your choice!
27
+slop lets you select a region or window and ffmpeg will record it in the format of your choice!
28 28
 Combined with keybinds and a server on your filesystem you can make a really neat and unobtrusive screenshooter.
29 29
 
30 30
 You can also take images using imagemagick like so:
31 31
 ```bash
32 32
 #!/bin/bash
33
-eval `slrn`
33
+eval `slop`
34 34
 import -window root -crop "$W"x"$H"+$X+$Y ~/myimage.png
35 35
 ```
36 36
 
37 37
 lets see some action
38 38
 --------------------
39
-Ok. Here's a comparison between 'scrot -s's selection and slrn's:
40
-![scrot](http://farmpolice.com/content/images/scrot_bad.png)
41
-![slrn](http://farmpolice.com/content/images/slrn_good.png)
39
+Ok. Here's a comparison between 'scrot -s's selection and slop's:
40
+![scrotbad](http://farmpolice.com/content/images/scrot_bad.png)
41
+![slopgood](http://farmpolice.com/content/images/slrn_good.png)
42 42
 
43 43
 You can see scrot leaves garbage lines over the things you're trying to screenshot!
44
-While slrn not only looks nicer, it's impossible for it to end up in screenshots or recordings because it shuts down before ffmpeg or imagemagick can take a picture.
44
+While slop not only looks nicer, it's impossible for it to end up in screenshots or recordings because it shuts down before ffmpeg or imagemagick can take a picture.

+ 11
- 11
main.cpp Ver fichero

@@ -10,8 +10,8 @@ int main( int argc, char** argv ) {
10 10
     }
11 11
     int state = 0;
12 12
     bool running = true;
13
-    slrn::Rectangle* selection;
14
-    slrn::Rectangle* windowselection = NULL;
13
+    slop::Rectangle* selection;
14
+    slop::Rectangle* windowselection = NULL;
15 15
     Window window = None;
16 16
     std::string xdisplay = options->m_xdisplay;
17 17
     int padding = options->m_padding;
@@ -27,7 +27,7 @@ int main( int argc, char** argv ) {
27 27
     if ( err ) {
28 28
         return err;
29 29
     }
30
-    err = xengine->grabCursor( slrn::Cross );
30
+    err = xengine->grabCursor( slop::Cross );
31 31
     if ( err ) {
32 32
         return err;
33 33
     }
@@ -70,8 +70,8 @@ int main( int argc, char** argv ) {
70 70
                     if ( windowselection ) {
71 71
                         xengine->removeRect( windowselection ); // removeRect also dealloc's the rectangle for us.
72 72
                     }
73
-                    slrn::WindowRectangle t = xengine->m_hoverWindow;
74
-                    windowselection = new slrn::Rectangle( t.m_x - t.m_border,
73
+                    slop::WindowRectangle t = xengine->m_hoverWindow;
74
+                    windowselection = new slop::Rectangle( t.m_x - t.m_border,
75 75
                                                          t.m_y - t.m_border,
76 76
                                                          t.m_width + t.m_border,
77 77
                                                          t.m_height + t.m_border,
@@ -93,7 +93,7 @@ int main( int argc, char** argv ) {
93 93
             case 1: {
94 94
                 // Simply create a new rectangle at the mouse position and move on
95 95
                 // to the next state.
96
-                selection = new slrn::Rectangle( xengine->m_mousex, xengine->m_mousey, 0, 0, borderSize, padding, r, g, b );
96
+                selection = new slop::Rectangle( xengine->m_mousex, xengine->m_mousey, 0, 0, borderSize, padding, r, g, b );
97 97
                 xengine->addRect( selection );
98 98
                 state++;
99 99
                 break;
@@ -113,13 +113,13 @@ int main( int argc, char** argv ) {
113 113
                 bool x = selection->m_flippedx;
114 114
                 bool y = selection->m_flippedy;
115 115
                 if ( !x && !y ) {
116
-                    xengine->setCursor( slrn::LowerRightCorner );
116
+                    xengine->setCursor( slop::LowerRightCorner );
117 117
                 } else if ( x && !y ) {
118
-                    xengine->setCursor( slrn::LowerLeftCorner );
118
+                    xengine->setCursor( slop::LowerLeftCorner );
119 119
                 } else if ( !x && y ) {
120
-                    xengine->setCursor( slrn::UpperRightCorner );
120
+                    xengine->setCursor( slop::UpperRightCorner );
121 121
                 } else {
122
-                    xengine->setCursor( slrn::UpperLeftCorner );
122
+                    xengine->setCursor( slop::UpperLeftCorner );
123 123
                 }
124 124
 
125 125
                 break;
@@ -147,7 +147,7 @@ int main( int argc, char** argv ) {
147 147
                     break;
148 148
                 }
149 149
                 // Otherwise lets grab the window's dimensions and use those (with padding).
150
-                slrn::WindowRectangle t = xengine->m_hoverWindow;
150
+                slop::WindowRectangle t = xengine->m_hoverWindow;
151 151
                 x = t.m_x - padding - t.m_border;
152 152
                 y = t.m_y - padding - t.m_border;
153 153
                 w = t.m_width + t.m_border + padding*2;

+ 2
- 2
makefile Ver fichero

@@ -3,7 +3,7 @@ CFLAGS=-O2 -g
3 3
 LDFLAGS=-lX11 -lXext
4 4
 SOURCES=main.cpp x.cpp options.cpp
5 5
 OBJECTS=$(SOURCES:.cpp=.o)
6
-EXECUTABLE=slrn
6
+EXECUTABLE=slop
7 7
 BINDIR="usr/bin"
8 8
 
9 9
 all: $(SOURCES) $(EXECUTABLE)
@@ -16,4 +16,4 @@ clean:
16 16
 
17 17
 install: all
18 18
 	mkdir -p $(DESTDIR)/$(BINDIR)
19
-	cp $(CURDIR)/slrn $(DESTDIR)/$(BINDIR)
19
+	cp $(CURDIR)/slop $(DESTDIR)/$(BINDIR)

+ 11
- 11
options.cpp Ver fichero

@@ -1,8 +1,8 @@
1 1
 #include "options.hpp"
2 2
 
3
-slrn::Options* options = new slrn::Options();
3
+slop::Options* options = new slop::Options();
4 4
 
5
-slrn::Options::Options() {
5
+slop::Options::Options() {
6 6
     m_borderSize = 10;
7 7
     m_padding = 0;
8 8
     m_xdisplay = ":0";
@@ -12,22 +12,22 @@ slrn::Options::Options() {
12 12
     m_blue = 0;
13 13
 }
14 14
 
15
-void slrn::Options::printHelp() {
16
-    printf( "Usage: slrn [options]\n" );
15
+void slop::Options::printHelp() {
16
+    printf( "Usage: slop [options]\n" );
17 17
     printf( "Print user selected region to stdout.\n" );
18 18
     printf( "\n" );
19 19
     printf( "options\n" );
20 20
     printf( "    -h, --help                     show this message.\n" );
21 21
     printf( "    -b=INT, --bordersize=INT       set selection rectangle border size.\n" );
22 22
     printf( "    -p=INT, --m_padding=INT        set m_padding size for selection.\n" );
23
-    printf( "    -t=INT, --tolerance=INT        if you have a shaky mouse, increasing this value will make slrn detect single clicks better. Rather than interpreting your shaky clicks as region selections.\n" );
23
+    printf( "    -t=INT, --tolerance=INT        if you have a shaky mouse, increasing this value will make slop detect single clicks better. Rather than interpreting your shaky clicks as region selections.\n" );
24 24
     printf( "    -x=STRING, --xdisplay=STRING   set x display (STRING must be hostname:number.screen_number format)\n" );
25 25
     printf( "    -c=COLOR, --color=COLOR        set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT\n" );
26 26
     printf( "examples\n" );
27
-    printf( "    slrn -b=10 -x=:0 -p=-30 -t=4 -c=0.5,0.5,0.5\n" );
27
+    printf( "    slop -b=10 -x=:0 -p=-30 -t=4 -c=0.5,0.5,0.5\n" );
28 28
 }
29 29
 
30
-int slrn::Options::parseOptions( int argc, char** argv ) {
30
+int slop::Options::parseOptions( int argc, char** argv ) {
31 31
     // Simple command parsing. Just uses sscanf to read each argument.
32 32
     // It looks complicated because you have to have spaces for delimiters for sscanf.
33 33
     for ( int i=0; i<argc; i++ ) {
@@ -78,7 +78,7 @@ int slrn::Options::parseOptions( int argc, char** argv ) {
78 78
     return 0;
79 79
 }
80 80
 
81
-int slrn::Options::parseInt( std::string arg, int* returnInt ) {
81
+int slop::Options::parseInt( std::string arg, int* returnInt ) {
82 82
     std::string copy = arg;
83 83
     int find = copy.find( "=" );
84 84
     if ( find != copy.npos ) {
@@ -99,7 +99,7 @@ int slrn::Options::parseInt( std::string arg, int* returnInt ) {
99 99
     return 0;
100 100
 }
101 101
 
102
-bool slrn::Options::matches( std::string arg, std::string shorthand, std::string longhand ) {
102
+bool slop::Options::matches( std::string arg, std::string shorthand, std::string longhand ) {
103 103
     if ( arg.substr( 0, shorthand.size() ) == shorthand ||
104 104
          arg.substr( 0, longhand.size() ) == longhand ) {
105 105
         return true;
@@ -107,7 +107,7 @@ bool slrn::Options::matches( std::string arg, std::string shorthand, std::string
107 107
     return false;
108 108
 }
109 109
 
110
-int slrn::Options::parseString( std::string arg, std::string* returnString ) {
110
+int slop::Options::parseString( std::string arg, std::string* returnString ) {
111 111
     std::string copy = arg;
112 112
     int find = copy.find( "=" );
113 113
     if ( find != copy.npos ) {
@@ -132,7 +132,7 @@ int slrn::Options::parseString( std::string arg, std::string* returnString ) {
132 132
     return 0;
133 133
 }
134 134
 
135
-int slrn::Options::parseColor( std::string arg, float* r, float* g, float* b ) {
135
+int slop::Options::parseColor( std::string arg, float* r, float* g, float* b ) {
136 136
     std::string copy = arg;
137 137
     int find = copy.find( "=" );
138 138
     while( find != copy.npos ) {

+ 2
- 2
options.hpp Ver fichero

@@ -3,7 +3,7 @@
3 3
 #include <string>
4 4
 #include <cstdio>
5 5
 
6
-namespace slrn {
6
+namespace slop {
7 7
 
8 8
 class Options {
9 9
 public:
@@ -27,6 +27,6 @@ private:
27 27
 
28 28
 }
29 29
 
30
-extern slrn::Options* options;
30
+extern slop::Options* options;
31 31
 
32 32
 #endif // IS_OPTIONS_H_

+ 24
- 24
x.cpp Ver fichero

@@ -1,8 +1,8 @@
1 1
 #include "x.hpp"
2 2
 
3
-slrn::XEngine* xengine = new slrn::XEngine();
3
+slop::XEngine* xengine = new slop::XEngine();
4 4
 
5
-slrn::XEngine::XEngine() {
5
+slop::XEngine::XEngine() {
6 6
     m_keypressed = false;
7 7
     m_display = NULL;
8 8
     m_visual = NULL;
@@ -13,7 +13,7 @@ slrn::XEngine::XEngine() {
13 13
     m_hoverXWindow = None;
14 14
 }
15 15
 
16
-slrn::XEngine::~XEngine() {
16
+slop::XEngine::~XEngine() {
17 17
     if ( !m_good ) {
18 18
         return;
19 19
     }
@@ -29,11 +29,11 @@ slrn::XEngine::~XEngine() {
29 29
 }
30 30
 
31 31
 // We need to keep track of the rectangle windows, so that they don't override our "focus"d windows.
32
-void slrn::XEngine::addRect( Rectangle* rect ) {
32
+void slop::XEngine::addRect( Rectangle* rect ) {
33 33
     m_rects.push_back( rect );
34 34
 }
35 35
 
36
-void slrn::XEngine::removeRect( Rectangle* rect ) {
36
+void slop::XEngine::removeRect( Rectangle* rect ) {
37 37
     for ( unsigned int i=0; i<m_rects.size(); i++ ) {
38 38
         if ( m_rects.at( i ) == rect ) {
39 39
             m_rects.erase( m_rects.begin() + i );
@@ -44,14 +44,14 @@ void slrn::XEngine::removeRect( Rectangle* rect ) {
44 44
     }
45 45
 }
46 46
 
47
-bool slrn::XEngine::mouseDown( unsigned int button ) {
47
+bool slop::XEngine::mouseDown( unsigned int button ) {
48 48
     if ( button >= m_mouse.size() ) {
49 49
         return false;
50 50
     }
51 51
     return m_mouse.at( button );
52 52
 }
53 53
 
54
-int slrn::XEngine::init( std::string display ) {
54
+int slop::XEngine::init( std::string display ) {
55 55
     // Initialize display
56 56
     m_display = XOpenDisplay( display.c_str() );
57 57
     if ( !m_display ) {
@@ -67,7 +67,7 @@ int slrn::XEngine::init( std::string display ) {
67 67
     return 0;
68 68
 }
69 69
 
70
-int slrn::XEngine::grabKeyboard() {
70
+int slop::XEngine::grabKeyboard() {
71 71
     if ( !m_good ) {
72 72
         return 1;
73 73
     }
@@ -75,13 +75,13 @@ int slrn::XEngine::grabKeyboard() {
75 75
                              GrabModeAsync, GrabModeAsync, CurrentTime );
76 76
     if ( err != GrabSuccess ) {
77 77
         fprintf( stderr, "Error: Failed to grab X keyboard.\n" );
78
-        fprintf( stderr, "This can be caused by launching slrn incorrectly.\n" );
78
+        fprintf( stderr, "This can be caused by launching slop incorrectly.\n" );
79 79
         fprintf( stderr, "gnome-session launches it fine from keyboard binds.\n" );
80 80
         return 1;
81 81
     }
82 82
 }
83 83
 
84
-int slrn::XEngine::releaseKeyboard() {
84
+int slop::XEngine::releaseKeyboard() {
85 85
     if ( !m_good ) {
86 86
         return 1;
87 87
     }
@@ -90,7 +90,7 @@ int slrn::XEngine::releaseKeyboard() {
90 90
 }
91 91
 
92 92
 // Grabs the cursor, be wary that setCursor changes the mouse masks.
93
-int slrn::XEngine::grabCursor( slrn::CursorType type ) {
93
+int slop::XEngine::grabCursor( slop::CursorType type ) {
94 94
     if ( !m_good ) {
95 95
         return 1;
96 96
     }
@@ -100,7 +100,7 @@ int slrn::XEngine::grabCursor( slrn::CursorType type ) {
100 100
                             GrabModeAsync, GrabModeAsync, m_root, xfontcursor, CurrentTime );
101 101
     if ( err != GrabSuccess ) {
102 102
         fprintf( stderr, "Error: Failed to grab X cursor.\n" );
103
-        fprintf( stderr, "This can be caused by launching slrn incorrectly.\n" );
103
+        fprintf( stderr, "This can be caused by launching slop incorrectly.\n" );
104 104
         fprintf( stderr, "gnome-session launches it fine from keyboard binds.\n" );
105 105
         return 1;
106 106
     }
@@ -119,7 +119,7 @@ int slrn::XEngine::grabCursor( slrn::CursorType type ) {
119 119
     return 0;
120 120
 }
121 121
 
122
-int slrn::XEngine::releaseCursor() {
122
+int slop::XEngine::releaseCursor() {
123 123
     if ( !m_good ) {
124 124
         return 1;
125 125
     }
@@ -127,7 +127,7 @@ int slrn::XEngine::releaseCursor() {
127 127
     return 0;
128 128
 }
129 129
 
130
-void slrn::XEngine::tick() {
130
+void slop::XEngine::tick() {
131 131
     if ( !m_good ) {
132 132
         return;
133 133
     }
@@ -180,7 +180,7 @@ void slrn::XEngine::tick() {
180 180
 }
181 181
 
182 182
 // This converts an enum into a preallocated cursor, the cursor will automatically deallocate itself on ~XEngine
183
-Cursor slrn::XEngine::getCursor( slrn::CursorType type ) {
183
+Cursor slop::XEngine::getCursor( slop::CursorType type ) {
184 184
     int xfontcursor;
185 185
     switch ( type ) {
186 186
         default:
@@ -205,7 +205,7 @@ Cursor slrn::XEngine::getCursor( slrn::CursorType type ) {
205 205
 }
206 206
 
207 207
 // Swaps out the current cursor, bewary that XChangeActivePointerGrab also resets masks, so if you change the mouse masks on grab you need to change them here too.
208
-void slrn::XEngine::setCursor( slrn::CursorType type ) {
208
+void slop::XEngine::setCursor( slop::CursorType type ) {
209 209
     if ( !m_good ) {
210 210
         return;
211 211
     }
@@ -215,7 +215,7 @@ void slrn::XEngine::setCursor( slrn::CursorType type ) {
215 215
                               xfontcursor, CurrentTime );
216 216
 }
217 217
 
218
-slrn::Rectangle::~Rectangle() {
218
+slop::Rectangle::~Rectangle() {
219 219
     //XFreeGC( xengine->m_display, m_gc );
220 220
     if ( m_window == None ) {
221 221
         return;
@@ -225,7 +225,7 @@ slrn::Rectangle::~Rectangle() {
225 225
     XDestroyWindow( xengine->m_display, m_window );
226 226
 }
227 227
 
228
-slrn::Rectangle::Rectangle( int x, int y, int width, int height, int border, int padding, float r, float g, float b ) {
228
+slop::Rectangle::Rectangle( int x, int y, int width, int height, int border, int padding, float r, float g, float b ) {
229 229
     m_xoffset = 0;
230 230
     m_yoffset = 0;
231 231
     m_x = x;
@@ -274,7 +274,7 @@ slrn::Rectangle::Rectangle( int x, int y, int width, int height, int border, int
274 274
     XMapWindow( xengine->m_display, m_window );
275 275
 }
276 276
 
277
-void slrn::Rectangle::setPos( int x, int y ) {
277
+void slop::Rectangle::setPos( int x, int y ) {
278 278
     if ( m_x == x && m_y == y ) {
279 279
         return;
280 280
     }
@@ -287,7 +287,7 @@ void slrn::Rectangle::setPos( int x, int y ) {
287 287
     XMoveWindow( xengine->m_display, m_window, m_x+m_xoffset, m_y+m_yoffset );
288 288
 }
289 289
 
290
-void slrn::Rectangle::setDim( int w, int h ) {
290
+void slop::Rectangle::setDim( int w, int h ) {
291 291
     if ( m_width == w && m_height == h ) {
292 292
         return;
293 293
     }
@@ -314,7 +314,7 @@ void slrn::Rectangle::setDim( int w, int h ) {
314 314
     XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
315 315
 }
316 316
 
317
-void slrn::XEngine::updateHoverWindow() {
317
+void slop::XEngine::updateHoverWindow() {
318 318
     Window root, child;
319 319
     int mx, my;
320 320
     int wx, wy;
@@ -343,7 +343,7 @@ void slrn::XEngine::updateHoverWindow() {
343 343
                   &(m_hoverWindow.m_border), &depth );
344 344
 }
345 345
 
346
-void slrn::XEngine::updateHoverWindow( Window child ) {
346
+void slop::XEngine::updateHoverWindow( Window child ) {
347 347
     // Same thing as updateHoverWindow but it uses the specified child.
348 348
     // It's used when we first grab the cursor so it's slightly more effecient
349 349
     // than calling XQueryPointer twice.
@@ -369,7 +369,7 @@ void slrn::XEngine::updateHoverWindow( Window child ) {
369 369
 
370 370
 // Keeps our rectangle's sizes all positive, so Xlib doesn't throw an exception.
371 371
 // It also keeps our values in absolute coordinates which is nice.
372
-void slrn::Rectangle::constrain( int w, int h ) {
372
+void slop::Rectangle::constrain( int w, int h ) {
373 373
     int pad = m_padding;
374 374
     if ( pad < 0 && std::abs( w ) < std::abs( pad )*2 ) {
375 375
         pad = 0;
@@ -399,7 +399,7 @@ void slrn::Rectangle::constrain( int w, int h ) {
399 399
     }
400 400
 }
401 401
 
402
-int slrn::Rectangle::convertColor( float r, float g, float b ) {
402
+int slop::Rectangle::convertColor( float r, float g, float b ) {
403 403
     // Convert float colors to shorts.
404 404
     short red   = short( floor( r * 65535.f ) );
405 405
     short green = short( floor( g * 65535.f ) );

+ 5
- 5
x.hpp Ver fichero

@@ -14,7 +14,7 @@
14 14
 #include <string>
15 15
 #include <vector>
16 16
 
17
-namespace slrn {
17
+namespace slop {
18 18
 
19 19
 enum CursorType {
20 20
     Left,
@@ -64,11 +64,11 @@ public:
64 64
                         ~XEngine();
65 65
     int                 init( std::string display );
66 66
     void                tick();
67
-    int                 grabCursor( slrn::CursorType type );
67
+    int                 grabCursor( slop::CursorType type );
68 68
     int                 grabKeyboard();
69 69
     int                 releaseCursor();
70 70
     int                 releaseKeyboard();
71
-    void                setCursor( slrn::CursorType type );
71
+    void                setCursor( slop::CursorType type );
72 72
     void                drawRect( int x, int y, unsigned int w, unsigned int h );
73 73
     void                addRect( Rectangle* rect );
74 74
     void                removeRect( Rectangle* rect );
@@ -90,11 +90,11 @@ private:
90 90
     bool                m_good;
91 91
     std::vector<Cursor> m_cursors;
92 92
     std::vector<Rectangle*> m_rects;
93
-    Cursor              getCursor( slrn::CursorType type );
93
+    Cursor              getCursor( slop::CursorType type );
94 94
 };
95 95
 
96 96
 }
97 97
 
98
-extern slrn::XEngine* xengine;
98
+extern slop::XEngine* xengine;
99 99
 
100 100
 #endif // IS_X_H_