Просмотр исходного кода

added an option to disable auto-window-selection and fixed a few options in the makefile

naelstrof 10 лет назад
Родитель
Сommit
fdd129c997
4 измененных файлов: 24 добавлений и 7 удалений
  1. 15
    6
      main.cpp
  2. 4
    1
      makefile
  3. 4
    0
      options.cpp
  4. 1
    0
      options.hpp

+ 15
- 6
main.cpp Просмотреть файл

@@ -92,7 +92,8 @@ int main( int argc, char** argv ) {
92 92
             case 0: {
93 93
                 // If xengine has found a window we're hovering over (or if it changed)
94 94
                 // create a rectangle around it so the user knows he/she can click on it.
95
-                if ( window != xengine->m_hoverXWindow ) {
95
+                // --but only if the user wants us to
96
+                if ( window != xengine->m_hoverXWindow && options->m_window ) {
96 97
                     // Make sure to delete the old selection rectangle.
97 98
                     if ( windowselection ) {
98 99
                         xengine->removeRect( windowselection ); // removeRect also dealloc's the rectangle for us.
@@ -185,11 +186,19 @@ int main( int argc, char** argv ) {
185 186
                     }
186 187
                 }
187 188
                 // Otherwise lets grab the window's dimensions and use those (with padding).
188
-                slop::WindowRectangle t = xengine->m_hoverWindow;
189
-                x = t.m_x - padding - t.m_border;
190
-                y = t.m_y - padding - t.m_border;
191
-                w = t.m_width + t.m_border + padding*2;
192
-                h = t.m_height + t.m_border + padding*2;
189
+                // --but only if the user lets us, if the user doesn't just select a single pixel there.
190
+                if ( options->m_window ) {
191
+                    slop::WindowRectangle t = xengine->m_hoverWindow;
192
+                    x = t.m_x - padding - t.m_border;
193
+                    y = t.m_y - padding - t.m_border;
194
+                    w = t.m_width + t.m_border + padding*2;
195
+                    h = t.m_height + t.m_border + padding*2;
196
+                } else {
197
+                    x = cx;
198
+                    y = cy;
199
+                    w = 1;
200
+                    h = 1;
201
+                }
193 202
                 printf( "X=%i\n", x );
194 203
                 printf( "Y=%i\n", y );
195 204
                 printf( "W=%i\n", w );

+ 4
- 1
makefile Просмотреть файл

@@ -1,5 +1,5 @@
1 1
 CC=g++
2
-CFLAGS=-O2 -g
2
+CCFLAGS=-O2 -g
3 3
 LDFLAGS=-lX11 -lXext
4 4
 SOURCES=main.cpp x.cpp options.cpp
5 5
 OBJECTS=$(SOURCES:.cpp=.o)
@@ -11,6 +11,9 @@ all: $(SOURCES) $(EXECUTABLE)
11 11
 $(EXECUTABLE): $(OBJECTS)
12 12
 	$(CC) $(OBJECTS) -o $@ $(LDFLAGS)
13 13
 
14
+$(OBJECTS): %.o: %.cpp
15
+	$(CC) $(CCFLAGS) -o $@ -c $<
16
+
14 17
 clean:
15 18
 	rm -rf $(OBJECTS) $(EXECUTABLE)
16 19
 

+ 4
- 0
options.cpp Просмотреть файл

@@ -12,6 +12,7 @@ slop::Options::Options() {
12 12
     m_blue = 0;
13 13
     m_gracetime = 0.1;
14 14
     m_keyboard = true;
15
+    m_window = true;
15 16
 }
16 17
 
17 18
 void slop::Options::printHelp() {
@@ -27,6 +28,7 @@ void slop::Options::printHelp() {
27 28
     printf( "    -x=STRING, --xdisplay=STRING   set x display (STRING must be hostname:number.screen_number format)\n" );
28 29
     printf( "    -c=COLOR, --color=COLOR        set selection rectangle color, COLOR is in format FLOAT,FLOAT,FLOAT\n" );
29 30
     printf( "    -g=FLOAT, --gracetime=FLOAT    set the amount of time before slop will check for keyboard cancellations in seconds.\n" );
31
+    printf( "    -nw, --nowindow                disable automatically selecting a whole window on single-clicks, and instead just select a single pixel.\n" );
30 32
     printf( "examples\n" );
31 33
     printf( "    slop -b=10 -x=:0 -p=-30 -t=4 -c=0.5,0.5,0.5 -g=.2\n" );
32 34
 }
@@ -77,6 +79,8 @@ int slop::Options::parseOptions( int argc, char** argv ) {
77 79
             }
78 80
         } else if ( matches( arg, "-nkb", "--nokeyboard" ) ) {
79 81
             m_keyboard = false;
82
+        } else if ( matches( arg, "-nw", "--nowindow" ) ) {
83
+            m_window = false;
80 84
         } else if ( matches( arg, "-h", "--help" ) ) {
81 85
             printHelp();
82 86
             return 2;

+ 1
- 0
options.hpp Просмотреть файл

@@ -20,6 +20,7 @@ public:
20 20
     std::string m_xdisplay;
21 21
     float       m_gracetime;
22 22
     bool        m_keyboard;
23
+    bool        m_window;
23 24
 private:
24 25
     int         parseInt( std::string arg, int* returnInt );
25 26
     int         parseFloat( std::string arg, float* returnFloat );