Bläddra i källkod

added no decoration flag

naelstrof 7 år sedan
förälder
incheckning
525b3746d4
9 ändrade filer med 62 tillägg och 35 borttagningar
  1. 7
    3
      src/main.cpp
  2. 26
    2
      src/mouse.cpp
  3. 2
    1
      src/mouse.hpp
  4. 4
    4
      src/options.hpp
  5. 10
    5
      src/slop.cpp
  6. 7
    1
      src/slop.hpp
  7. 6
    3
      src/slopstates.cpp
  8. 0
    14
      src/x.cpp
  9. 0
    2
      src/x.hpp

+ 7
- 3
src/main.cpp Visa fil

@@ -27,6 +27,7 @@ SlopOptions* getOptions( Options& options ) {
27 27
     SlopOptions* foo = new SlopOptions();
28 28
     options.getFloat("bordersize", 'b', foo->borderSize);
29 29
     options.getFloat("padding", 'p', foo->padding);
30
+    options.getFloat("tolerance", 't', foo->tolerance);
30 31
     glm::vec4 color = glm::vec4( foo->r, foo->g, foo->b, foo->a );
31 32
     options.getColor("color", 'c', color);
32 33
     foo->r = color.r;
@@ -34,6 +35,7 @@ SlopOptions* getOptions( Options& options ) {
34 35
     foo->b = color.b;
35 36
     foo->a = color.a;
36 37
     options.getBool("highlight", 'h', foo->highlight);
38
+    options.getBool("nodecorations", 'n', foo->nodecorations);
37 39
     return foo;
38 40
 }
39 41
 
@@ -56,8 +58,10 @@ std::string formatOutput( std::string input, SlopSelection selection ) {
56 58
                 case 'g':
57 59
                 case 'G': output << round(selection.w) << "x" << round(selection.h)
58 60
                           << "+" << round(selection.x) << "+" << round(selection.y); break;
61
+                case 'i':
62
+                case 'I': output << selection.id; break;
59 63
                 case '%': output << "%"; break;
60
-                default: throw new std::invalid_argument( std::string()+"Expected x, y, w, h, g, or % after % in format. Got `" + input[i+1] + "`." );
64
+                default: throw new std::invalid_argument( std::string()+"Expected x, y, w, h, g, i, or % after % in format. Got `" + input[i+1] + "`." );
61 65
              }
62 66
             i++;
63 67
             continue;
@@ -75,7 +79,7 @@ int app( int argc, char** argv ) {
75 79
 
76 80
     // We want to validate our format option if we got one, we do that by just doing a dry run
77 81
     // on a fake selection.
78
-    SlopSelection selection(0,0,0,0);
82
+    SlopSelection selection(0,0,0,0,0);
79 83
     std::string format;
80 84
     bool gotFormat = options.getString("format", 'f', format);
81 85
     if ( gotFormat ) {
@@ -99,7 +103,7 @@ int app( int argc, char** argv ) {
99 103
         return 0;
100 104
     }
101 105
     // Otherwise we default to an `eval` compatible format.
102
-    std::cout << formatOutput( "X=%x\nY=%y\nW=%w\nH=%h\nG=%g\n", selection );
106
+    std::cout << formatOutput( "X=%x\nY=%y\nW=%w\nH=%h\nG=%g\nID=%i\n", selection );
103 107
     return 0;
104 108
 }
105 109
 

+ 26
- 2
src/mouse.cpp Visa fil

@@ -39,7 +39,7 @@ void Mouse::setCursor( int cursor ) {
39 39
                               xcursor, CurrentTime );
40 40
 }
41 41
 
42
-Mouse::Mouse(X11* x11) {
42
+Mouse::Mouse(X11* x11, bool nodecorations ) {
43 43
     this->x11 = x11;
44 44
     currentCursor = XC_cross;
45 45
     xcursor = XCreateFontCursor( x11->display, XC_cross );
@@ -52,7 +52,17 @@ Mouse::Mouse(X11* x11) {
52 52
     int mx, my;
53 53
     int wx, wy;
54 54
     unsigned int mask;
55
-    XQueryPointer( x11->display, x11->root, &root, &hoverWindow, &mx, &my, &wx, &wy, &mask );
55
+    if ( nodecorations ) {
56
+        // Get the deepest available window if we don't want decorations.
57
+        Window child = x11->root;
58
+        while( child ) {
59
+            hoverWindow = child;
60
+            XQueryPointer( x11->display, child, &root, &child, &mx, &my, &wx, &wy, &mask );
61
+        }
62
+    } else {
63
+        XQueryPointer( x11->display, x11->root, &root, &hoverWindow, &mx, &my, &wx, &wy, &mask );
64
+    }
65
+    selectAllInputs( x11->root, nodecorations );
56 66
 }
57 67
 
58 68
 Mouse::~Mouse() {
@@ -72,3 +82,17 @@ void Mouse::update() {
72 82
 	}
73 83
 }
74 84
 
85
+// This cheesy function makes sure we get all EnterNotify events on ALL the windows.
86
+void Mouse::selectAllInputs( Window win, bool nodecorations ) {
87
+    Window root, parent;
88
+    Window* children;
89
+    unsigned int nchildren;
90
+    XQueryTree( x11->display, win, &root, &parent, &children, &nchildren );
91
+    for ( unsigned int i=0;i<nchildren;i++ ) {
92
+            XSelectInput( x11->display, children[ i ], EnterWindowMask );
93
+        if ( nodecorations ) {
94
+            selectAllInputs( children[i], nodecorations );
95
+        }
96
+    }
97
+    free( children );
98
+}

+ 2
- 1
src/mouse.hpp Visa fil

@@ -34,10 +34,11 @@ private:
34 34
     std::vector<glm::ivec2> buttons;
35 35
     Cursor xcursor;
36 36
     int currentCursor;
37
+    void selectAllInputs( Window win, bool nodecorations = false );
37 38
 public:
38 39
 	Window hoverWindow;
39 40
 	void update();
40
-    Mouse( X11* x11 );
41
+    Mouse( X11* x11, bool nodecorations );
41 42
     ~Mouse();
42 43
     void setCursor( int cursor );
43 44
     glm::vec2 getMousePos();

+ 4
- 4
src/options.hpp Visa fil

@@ -28,11 +28,11 @@
28 28
 #include <vector>
29 29
 #include <glm/glm.hpp>
30 30
 
31
-static std::string validStringArguments[] = { "bordersize", "padding", "color", "shader", "highlight", "format" };
32
-static char validCharArguments[] = { 'b', 'p', 'c', 's', 'h', 'f' };
31
+static std::string validStringArguments[] = { "bordersize", "padding", "color", "shader", "highlight", "format", "tolerance", "nodecorations", "nokeyboard" };
32
+static char validCharArguments[] = { 'b', 'p', 'c', 's', 'h', 'f', 't', 'n', 'k' };
33 33
 // 0 for flag, 1 for how many arguments to eat up
34
-static unsigned int isFlagArgument[] = { false, false, false, false, true, false };
35
-static unsigned int validArgumentCount = 6;
34
+static unsigned int isFlagArgument[] = { false, false, false, false, true, false, false, true, true };
35
+static unsigned int validArgumentCount = 9;
36 36
 static unsigned int maxFloatingValues = 0;
37 37
 
38 38
 class Options {

+ 10
- 5
src/slop.cpp Visa fil

@@ -8,6 +8,8 @@ Resource* resource;
8 8
 // Defaults!
9 9
 SlopOptions::SlopOptions() {
10 10
     borderSize = 1;
11
+    nodecorations = false;
12
+    tolerance = 4;
11 13
     padding = 0;
12 14
     shader = "textured";
13 15
     highlight = false;
@@ -17,18 +19,22 @@ SlopOptions::SlopOptions() {
17 19
     a = 1;
18 20
 }
19 21
 
20
-SlopSelection::SlopSelection( float x, float y, float w, float h ) {
22
+SlopSelection::SlopSelection( float x, float y, float w, float h, Window id ) {
21 23
     this->x = x;
22 24
     this->y = y;
23 25
     this->w = w;
24 26
     this->h = h;
27
+    this->id = id;
25 28
 }
26 29
 
27 30
 SlopMemory::SlopMemory( SlopOptions* options ) {
28 31
     running = true;
29 32
     state = (SlopState*)new SlopStart();
30 33
     nextState = NULL;
34
+    tolerance = options->tolerance;
35
+    nodecorations = options->nodecorations;
31 36
     rectangle = new Rectangle(glm::vec2(0,0), glm::vec2(0,0), options->borderSize, options->padding, glm::vec4( options->r, options->g, options->b, options->a ), options->highlight);
37
+    selectedWindow = x11->root;
32 38
     state->onEnter( *this );
33 39
 }
34 40
 
@@ -69,9 +75,9 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
69 75
         options = new SlopOptions();
70 76
     }
71 77
     resource = new Resource();
72
-    // Set up wayland temporarily
78
+    // Set up x11 temporarily
73 79
     x11 = new X11(":0");
74
-    mouse = new Mouse( x11 );
80
+    mouse = new Mouse( x11, options->nodecorations );
75 81
     keyboard = new Keyboard( x11 );
76 82
 
77 83
     // Set up window with GL context
@@ -121,7 +127,6 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
121 127
     glClearColor (0.0, 0.0, 0.0, 0.0);
122 128
     glClear (GL_COLOR_BUFFER_BIT);
123 129
     window->display();
124
-    glClearColor (0.0, 0.0, 0.0, 0.0);
125 130
     glClear (GL_COLOR_BUFFER_BIT);
126 131
     window->display();
127 132
     // Then we clean up.
@@ -133,5 +138,5 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
133 138
         delete options;
134 139
     }
135 140
     // Finally return the data.
136
-    return SlopSelection( output.x, output.y, output.z+1, output.w+1 );
141
+    return SlopSelection( output.x, output.y, output.z+1, output.w+1, memory.selectedWindow );
137 142
 }

+ 7
- 1
src/slop.hpp Visa fil

@@ -39,7 +39,9 @@ public:
39 39
     SlopOptions();
40 40
     float borderSize;
41 41
     float padding;
42
+    float tolerance;
42 43
     bool highlight;
44
+    bool nodecorations;
43 45
     std::string shader;
44 46
     float r;
45 47
     float g;
@@ -49,11 +51,12 @@ public:
49 51
 
50 52
 class SlopSelection {
51 53
 public:
52
-    SlopSelection( float x, float y, float w, float h );
54
+    SlopSelection( float x, float y, float w, float h, Window id );
53 55
     float x;
54 56
     float y;
55 57
     float w;
56 58
     float h;
59
+    Window id;
57 60
 };
58 61
 
59 62
 class SlopMemory {
@@ -63,7 +66,10 @@ private:
63 66
 public:
64 67
     SlopMemory( SlopOptions* options );
65 68
     ~SlopMemory();
69
+    Window selectedWindow;
66 70
     bool running;
71
+    float tolerance;
72
+    bool nodecorations;
67 73
     Rectangle* rectangle;
68 74
     void setState( SlopState* state );
69 75
     void update( double dt );

+ 6
- 3
src/slopstates.cpp Visa fil

@@ -19,20 +19,23 @@ void SlopStart::update( SlopMemory& memory, double dt ) {
19 19
         startPos = mouse->getMousePos();
20 20
         setStartPos = true;
21 21
     }
22
-    if ( setStartPos && glm::distance( startPos, mouse->getMousePos() ) > 4 ) {
22
+    if ( setStartPos && glm::distance( startPos, mouse->getMousePos() ) >= memory.tolerance ) {
23 23
         memory.setState( (SlopState*)new SlopStartDrag( startPos ) );
24 24
     }
25 25
     if ( mouse->hoverWindow != None ) {
26
-        glm::vec4 rect = getWindowGeometry( mouse->hoverWindow, true );
26
+        glm::vec4 rect = getWindowGeometry( mouse->hoverWindow, memory.nodecorations );
27 27
         memory.rectangle->setPoints( glm::vec2( (float)rect.x, (float)rect.y ), glm::vec2( (float)rect.x+rect.z, (float)rect.y+rect.w ) );
28 28
     }
29 29
     if ( setStartPos && !mouse->getButton( 1 ) ) {
30
+        memory.selectedWindow = mouse->hoverWindow;
30 31
         memory.setState( (SlopState*)new SlopEndDrag() );
31 32
     }
32 33
 }
33 34
 
34 35
 void SlopStart::draw( SlopMemory& memory, glm::mat4 matrix ) {
35
-    memory.rectangle->draw( matrix );
36
+    if ( memory.tolerance > 0 ) {
37
+        memory.rectangle->draw( matrix );
38
+    }
36 39
 }
37 40
 
38 41
 SlopStartDrag::SlopStartDrag( glm::vec2 point ) {

+ 0
- 14
src/x.cpp Visa fil

@@ -9,22 +9,8 @@ X11::X11( std::string displayName ) {
9 9
     screen = ScreenOfDisplay( display, DefaultScreen( display ) );
10 10
     visual = DefaultVisual( display, XScreenNumberOfScreen( screen ) );
11 11
     root = DefaultRootWindow( display );
12
-    selectAllInputs( root );
13 12
 }
14 13
 
15 14
 X11::~X11() {
16 15
     XCloseDisplay( display );
17 16
 }
18
-
19
-// This cheesy function makes sure we get all EnterNotify events on ALL the windows.
20
-void X11::selectAllInputs( Window win ) {
21
-    Window root, parent;
22
-    Window* children;
23
-    unsigned int nchildren;
24
-    XQueryTree( display, win, &root, &parent, &children, &nchildren );
25
-    for ( unsigned int i=0;i<nchildren;i++ ) {
26
-        XSelectInput( display, children[ i ], EnterWindowMask );
27
-        selectAllInputs( children[i] );
28
-    }
29
-    free( children );
30
-}

+ 0
- 2
src/x.hpp Visa fil

@@ -27,8 +27,6 @@
27 27
 #include <stdexcept>
28 28
 
29 29
 class X11 {
30
-private:
31
-    void selectAllInputs( Window win );
32 30
 public:
33 31
     X11( std::string displayName );
34 32
     ~X11();