Selaa lähdekoodia

added window detection

naelstrof 7 vuotta sitten
vanhempi
commit
0faea5852c
7 muutettua tiedostoa jossa 85 lisäystä ja 3 poistoa
  1. 1
    0
      CMakeLists.txt
  2. 7
    2
      src/mouse.cpp
  3. 0
    1
      src/mouse.hpp
  4. 8
    0
      src/slopstates.cpp
  5. 2
    0
      src/slopstates.hpp
  6. 36
    0
      src/windowhelper.cpp
  7. 31
    0
      src/windowhelper.hpp

+ 1
- 0
CMakeLists.txt Näytä tiedosto

@@ -27,6 +27,7 @@ set(EXECUTABLE_NAME "slop")
27 27
 
28 28
 set( source src/x.cpp
29 29
             src/window.cpp
30
+            src/windowhelper.cpp
30 31
             src/mouse.cpp
31 32
             src/keyboard.cpp
32 33
             src/framebuffer.cpp

+ 7
- 2
src/mouse.cpp Näytä tiedosto

@@ -43,9 +43,16 @@ Mouse::Mouse(X11* x11) {
43 43
     this->x11 = x11;
44 44
     currentCursor = XC_cross;
45 45
     xcursor = XCreateFontCursor( x11->display, XC_cross );
46
+    hoverWindow = None;
46 47
     XGrabPointer( x11->display, x11->root, True,
47 48
                   PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
48 49
                   GrabModeAsync, GrabModeAsync, None, xcursor, CurrentTime );
50
+
51
+    Window root;
52
+    int mx, my;
53
+    int wx, wy;
54
+    unsigned int mask;
55
+    XQueryPointer( x11->display, x11->root, &root, &hoverWindow, &mx, &my, &wx, &wy, &mask );
49 56
 }
50 57
 
51 58
 Mouse::~Mouse() {
@@ -61,9 +68,7 @@ void Mouse::update() {
61 68
 		setButton( event.xbutton.button, 0 );
62 69
 	}
63 70
     while ( XCheckTypedEvent( x11->display, EnterNotify, &event ) ) {
64
-        subWindow = event.xcrossing.subwindow;
65 71
         hoverWindow = event.xcrossing.window;
66
-        std::cout << hoverWindow << "\n";
67 72
 	}
68 73
 }
69 74
 

+ 0
- 1
src/mouse.hpp Näytä tiedosto

@@ -36,7 +36,6 @@ private:
36 36
     int currentCursor;
37 37
 public:
38 38
 	Window hoverWindow;
39
-	Window subWindow;
40 39
 	void update();
41 40
     Mouse( X11* x11 );
42 41
     ~Mouse();

+ 8
- 0
src/slopstates.cpp Näytä tiedosto

@@ -16,6 +16,14 @@ void SlopStart::update( SlopMemory& memory, double dt ) {
16 16
     if ( mouse->getButton( 1 ) ) {
17 17
         memory.setState( (SlopState*)new SlopStartDrag( mouse->getMousePos() ) );
18 18
     }
19
+    if ( mouse->hoverWindow != None ) {
20
+        glm::vec4 rect = getWindowGeometry( mouse->hoverWindow, true );
21
+        memory.rectangle->setPoints( glm::vec2( (float)rect.x, (float)rect.y ), glm::vec2( (float)rect.x+rect.z, (float)rect.y+rect.w ) );
22
+    }
23
+}
24
+
25
+void SlopStart::draw( SlopMemory& memory, glm::mat4 matrix ) {
26
+    memory.rectangle->draw( matrix );
19 27
 }
20 28
 
21 29
 SlopStartDrag::SlopStartDrag( glm::vec2 point ) {

+ 2
- 0
src/slopstates.hpp Näytä tiedosto

@@ -23,6 +23,7 @@
23 23
 
24 24
 #include "mouse.hpp"
25 25
 #include "rectangle.hpp"
26
+#include "windowhelper.hpp"
26 27
 #include "slop.hpp"
27 28
 
28 29
 class SlopMemory;
@@ -39,6 +40,7 @@ public:
39 40
 class SlopStart : SlopState {
40 41
 public:
41 42
     virtual void update( SlopMemory& memory, double dt );
43
+    virtual void draw( SlopMemory& memory, glm::mat4 matrix );
42 44
 };
43 45
 
44 46
 class SlopStartDrag : SlopState {

+ 36
- 0
src/windowhelper.cpp Näytä tiedosto

@@ -0,0 +1,36 @@
1
+#include "windowhelper.hpp"
2
+
3
+glm::vec4 getWindowGeometry( Window win, bool removeDecoration ) {
4
+    XWindowAttributes attr;         
5
+    XGetWindowAttributes( x11->display, win, &attr );
6
+    unsigned int width = attr.width;           
7
+    unsigned int height = attr.height;         
8
+    unsigned int border = attr.border_width;   
9
+    int x, y;
10
+    Window junk;
11
+    XTranslateCoordinates( x11->display, win, attr.root, -attr.border_width, -attr.border_width, &x, &y, &junk );
12
+    if ( !removeDecoration ) {
13
+        width += border*2;
14
+        height += border*2;
15
+        return glm::vec4( x, y, width, height );
16
+    }
17
+    // This is required to be defined by the window manager, so we can assume it exists.
18
+    Atom actual_type;
19
+    int actual_format;
20
+    unsigned long nitems, bytes_after;
21
+    unsigned char *data;
22
+    int result = XGetWindowProperty(x11->display, win,
23
+                                    XInternAtom(x11->display, "_NET_FRAME_EXTENTS", true),
24
+                                    0, 4, False, AnyPropertyType, 
25
+                                    &actual_type, &actual_format, &nitems, &bytes_after, &data);
26
+    if ( result == Success ) {
27
+        // Make sure we got the data we expect...
28
+        if ((nitems == 4) && (bytes_after == 0)) {
29
+            x += (int)data[0];
30
+            width -= (int)data[1];
31
+            y += (int)data[2];
32
+            height -= (int)data[3];
33
+        }
34
+    }
35
+    return glm::vec4( x, y, width, height );
36
+}

+ 31
- 0
src/windowhelper.hpp Näytä tiedosto

@@ -0,0 +1,31 @@
1
+/* windowhelper.hpp: Analyzes input windows to determine decorations and such.
2
+ *
3
+ * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
4
+ *
5
+ * This file is part of Slop.
6
+ *
7
+ * Slop is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * Slop is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with Slop.  If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+#ifndef N_WINDOWHELPER_H_
22
+#define N_WINDOWHELPER_H_
23
+
24
+#include <glm/glm.hpp>
25
+#include <X11/Xlib.h>
26
+
27
+#include "x.hpp"
28
+
29
+glm::vec4 getWindowGeometry( Window win, bool removeDecoration );
30
+
31
+#endif