Browse Source

added no decoration flag

naelstrof 7 years ago
parent
commit
525b3746d4
9 changed files with 62 additions and 35 deletions
  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 View File

27
     SlopOptions* foo = new SlopOptions();
27
     SlopOptions* foo = new SlopOptions();
28
     options.getFloat("bordersize", 'b', foo->borderSize);
28
     options.getFloat("bordersize", 'b', foo->borderSize);
29
     options.getFloat("padding", 'p', foo->padding);
29
     options.getFloat("padding", 'p', foo->padding);
30
+    options.getFloat("tolerance", 't', foo->tolerance);
30
     glm::vec4 color = glm::vec4( foo->r, foo->g, foo->b, foo->a );
31
     glm::vec4 color = glm::vec4( foo->r, foo->g, foo->b, foo->a );
31
     options.getColor("color", 'c', color);
32
     options.getColor("color", 'c', color);
32
     foo->r = color.r;
33
     foo->r = color.r;
34
     foo->b = color.b;
35
     foo->b = color.b;
35
     foo->a = color.a;
36
     foo->a = color.a;
36
     options.getBool("highlight", 'h', foo->highlight);
37
     options.getBool("highlight", 'h', foo->highlight);
38
+    options.getBool("nodecorations", 'n', foo->nodecorations);
37
     return foo;
39
     return foo;
38
 }
40
 }
39
 
41
 
56
                 case 'g':
58
                 case 'g':
57
                 case 'G': output << round(selection.w) << "x" << round(selection.h)
59
                 case 'G': output << round(selection.w) << "x" << round(selection.h)
58
                           << "+" << round(selection.x) << "+" << round(selection.y); break;
60
                           << "+" << round(selection.x) << "+" << round(selection.y); break;
61
+                case 'i':
62
+                case 'I': output << selection.id; break;
59
                 case '%': output << "%"; break;
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
             i++;
66
             i++;
63
             continue;
67
             continue;
75
 
79
 
76
     // We want to validate our format option if we got one, we do that by just doing a dry run
80
     // We want to validate our format option if we got one, we do that by just doing a dry run
77
     // on a fake selection.
81
     // on a fake selection.
78
-    SlopSelection selection(0,0,0,0);
82
+    SlopSelection selection(0,0,0,0,0);
79
     std::string format;
83
     std::string format;
80
     bool gotFormat = options.getString("format", 'f', format);
84
     bool gotFormat = options.getString("format", 'f', format);
81
     if ( gotFormat ) {
85
     if ( gotFormat ) {
99
         return 0;
103
         return 0;
100
     }
104
     }
101
     // Otherwise we default to an `eval` compatible format.
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
     return 0;
107
     return 0;
104
 }
108
 }
105
 
109
 

+ 26
- 2
src/mouse.cpp View File

39
                               xcursor, CurrentTime );
39
                               xcursor, CurrentTime );
40
 }
40
 }
41
 
41
 
42
-Mouse::Mouse(X11* x11) {
42
+Mouse::Mouse(X11* x11, bool nodecorations ) {
43
     this->x11 = x11;
43
     this->x11 = x11;
44
     currentCursor = XC_cross;
44
     currentCursor = XC_cross;
45
     xcursor = XCreateFontCursor( x11->display, XC_cross );
45
     xcursor = XCreateFontCursor( x11->display, XC_cross );
52
     int mx, my;
52
     int mx, my;
53
     int wx, wy;
53
     int wx, wy;
54
     unsigned int mask;
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
 Mouse::~Mouse() {
68
 Mouse::~Mouse() {
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 View File

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

+ 4
- 4
src/options.hpp View File

28
 #include <vector>
28
 #include <vector>
29
 #include <glm/glm.hpp>
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
 // 0 for flag, 1 for how many arguments to eat up
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
 static unsigned int maxFloatingValues = 0;
36
 static unsigned int maxFloatingValues = 0;
37
 
37
 
38
 class Options {
38
 class Options {

+ 10
- 5
src/slop.cpp View File

8
 // Defaults!
8
 // Defaults!
9
 SlopOptions::SlopOptions() {
9
 SlopOptions::SlopOptions() {
10
     borderSize = 1;
10
     borderSize = 1;
11
+    nodecorations = false;
12
+    tolerance = 4;
11
     padding = 0;
13
     padding = 0;
12
     shader = "textured";
14
     shader = "textured";
13
     highlight = false;
15
     highlight = false;
17
     a = 1;
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
     this->x = x;
23
     this->x = x;
22
     this->y = y;
24
     this->y = y;
23
     this->w = w;
25
     this->w = w;
24
     this->h = h;
26
     this->h = h;
27
+    this->id = id;
25
 }
28
 }
26
 
29
 
27
 SlopMemory::SlopMemory( SlopOptions* options ) {
30
 SlopMemory::SlopMemory( SlopOptions* options ) {
28
     running = true;
31
     running = true;
29
     state = (SlopState*)new SlopStart();
32
     state = (SlopState*)new SlopStart();
30
     nextState = NULL;
33
     nextState = NULL;
34
+    tolerance = options->tolerance;
35
+    nodecorations = options->nodecorations;
31
     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);
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
     state->onEnter( *this );
38
     state->onEnter( *this );
33
 }
39
 }
34
 
40
 
69
         options = new SlopOptions();
75
         options = new SlopOptions();
70
     }
76
     }
71
     resource = new Resource();
77
     resource = new Resource();
72
-    // Set up wayland temporarily
78
+    // Set up x11 temporarily
73
     x11 = new X11(":0");
79
     x11 = new X11(":0");
74
-    mouse = new Mouse( x11 );
80
+    mouse = new Mouse( x11, options->nodecorations );
75
     keyboard = new Keyboard( x11 );
81
     keyboard = new Keyboard( x11 );
76
 
82
 
77
     // Set up window with GL context
83
     // Set up window with GL context
121
     glClearColor (0.0, 0.0, 0.0, 0.0);
127
     glClearColor (0.0, 0.0, 0.0, 0.0);
122
     glClear (GL_COLOR_BUFFER_BIT);
128
     glClear (GL_COLOR_BUFFER_BIT);
123
     window->display();
129
     window->display();
124
-    glClearColor (0.0, 0.0, 0.0, 0.0);
125
     glClear (GL_COLOR_BUFFER_BIT);
130
     glClear (GL_COLOR_BUFFER_BIT);
126
     window->display();
131
     window->display();
127
     // Then we clean up.
132
     // Then we clean up.
133
         delete options;
138
         delete options;
134
     }
139
     }
135
     // Finally return the data.
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 View File

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

+ 6
- 3
src/slopstates.cpp View File

19
         startPos = mouse->getMousePos();
19
         startPos = mouse->getMousePos();
20
         setStartPos = true;
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
         memory.setState( (SlopState*)new SlopStartDrag( startPos ) );
23
         memory.setState( (SlopState*)new SlopStartDrag( startPos ) );
24
     }
24
     }
25
     if ( mouse->hoverWindow != None ) {
25
     if ( mouse->hoverWindow != None ) {
26
-        glm::vec4 rect = getWindowGeometry( mouse->hoverWindow, true );
26
+        glm::vec4 rect = getWindowGeometry( mouse->hoverWindow, memory.nodecorations );
27
         memory.rectangle->setPoints( glm::vec2( (float)rect.x, (float)rect.y ), glm::vec2( (float)rect.x+rect.z, (float)rect.y+rect.w ) );
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
     if ( setStartPos && !mouse->getButton( 1 ) ) {
29
     if ( setStartPos && !mouse->getButton( 1 ) ) {
30
+        memory.selectedWindow = mouse->hoverWindow;
30
         memory.setState( (SlopState*)new SlopEndDrag() );
31
         memory.setState( (SlopState*)new SlopEndDrag() );
31
     }
32
     }
32
 }
33
 }
33
 
34
 
34
 void SlopStart::draw( SlopMemory& memory, glm::mat4 matrix ) {
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
 SlopStartDrag::SlopStartDrag( glm::vec2 point ) {
41
 SlopStartDrag::SlopStartDrag( glm::vec2 point ) {

+ 0
- 14
src/x.cpp View File

9
     screen = ScreenOfDisplay( display, DefaultScreen( display ) );
9
     screen = ScreenOfDisplay( display, DefaultScreen( display ) );
10
     visual = DefaultVisual( display, XScreenNumberOfScreen( screen ) );
10
     visual = DefaultVisual( display, XScreenNumberOfScreen( screen ) );
11
     root = DefaultRootWindow( display );
11
     root = DefaultRootWindow( display );
12
-    selectAllInputs( root );
13
 }
12
 }
14
 
13
 
15
 X11::~X11() {
14
 X11::~X11() {
16
     XCloseDisplay( display );
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 View File

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