Bladeren bron

getting closer

naelstrof 7 jaren geleden
bovenliggende
commit
e20e54cbf0
12 gewijzigde bestanden met toevoegingen van 64 en 102 verwijderingen
  1. 0
    12
      CMakeLists.txt
  2. 0
    23
      modules/FindRT.cmake
  3. 0
    47
      modules/FindXRender.cmake
  4. 21
    9
      src/keyboard.cpp
  5. 3
    0
      src/keyboard.hpp
  6. 4
    6
      src/mouse.cpp
  7. 3
    1
      src/mouse.hpp
  8. 3
    3
      src/slop.cpp
  9. 13
    1
      src/window.cpp
  10. 1
    0
      src/window.hpp
  11. 14
    0
      src/x.cpp
  12. 2
    0
      src/x.hpp

+ 0
- 12
CMakeLists.txt Bestand weergeven

@@ -51,27 +51,15 @@ find_package(GLM REQUIRED)
51 51
 find_package(GLX REQUIRED)
52 52
 find_package(X11 REQUIRED)
53 53
 find_package(XExt REQUIRED) 
54
-find_package(XRender REQUIRED)
55
-find_package(RT) 
56 54
 
57 55
 include_directories(${X11_INCLUDE_DIR}
58 56
                     ${GLM_INCLUDE_DIR}
59 57
                     ${GLX_INCLUDE_DIR}
60
-                    ${XRENDER_INCLUDE_DIRS}
61 58
                     ${OPENGL_INCLUDE_DIR})
62 59
 
63
-if ( RT_INCLUDE_DIR )
64
-    include_directories(${RT_INCLUDE_DIR})
65
-endif()
66
-
67 60
 target_link_libraries(${EXECUTABLE_NAME} ${X11_LIBRARIES}
68 61
                                          ${GLX_LIBRARIES}
69
-                                         ${XRENDER_LIBRARIES}
70 62
                                          ${OPENGL_LIBRARIES})
71
-if ( RT_LIBRARY )
72
-    target_link_libraries(${EXECUTABLE_NAME} ${RT_LIBRARY})
73
-endif()
74
-
75 63
 
76 64
 # Install targets
77 65
 install( TARGETS ${EXECUTABLE_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )

+ 0
- 23
modules/FindRT.cmake Bestand weergeven

@@ -1,23 +0,0 @@
1
-# - Find rt
2
-# Find the rt libraries, this is to fix ubuntu not having clock_gettime defined without it.
3
-#
4
-#  This module defines the following variables:
5
-#     RT_FOUND        - 1 if RT_INCLUDE_DIR & RT_LIBRARY are found, 0 otherwise
6
-#     RT_INCLUDE_DIR  - where to find Xlib.h, etc.
7
-#     RT_LIBRARY      - the X11 library
8
-#
9
-
10
-find_path( RT_INCLUDE_DIR
11
-           NAMES time.h )
12
-
13
-find_library( RT_LIBRARY
14
-              NAMES rt
15
-              PATHS /usr/lib /lib )
16
-
17
-if( RT_INCLUDE_DIR AND RT_LIBRARY )
18
-    set( RT_FOUND 1 )
19
-else()
20
-    set( RT_FOUND 0 )
21
-endif()
22
-
23
-mark_as_advanced( RT_INCLUDE_DIR RT_LIBRARY )

+ 0
- 47
modules/FindXRender.cmake Bestand weergeven

@@ -1,47 +0,0 @@
1
-# - Find XRender
2
-# Find the XRender libraries
3
-#
4
-# This module defines the following variables:
5
-#   XRENDER_FOUND - true if XRENDER_INCLUDE_DIR & XRENDER_LIBRARY are found
6
-#   XRENDER_LIBRARIES - Set when Xrender_LIBRARY is found
7
-#   XRENDER_INCLUDE_DIRS - Set when Xrender_INCLUDE_DIR is found
8
-#
9
-#   XRENDER_INCLUDE_DIR - where to find Xrender.h, etc.
10
-#   XRENDER_LIBRARY - the Xrender library
11
-#
12
-
13
-#=============================================================================
14
-# Copyright 2013 Corey Clayton <can.of.tuna@gmail.com>
15
-#
16
-# Licensed under the Apache License, Version 2.0 (the "License");
17
-# you may not use this file except in compliance with the License.
18
-# You may obtain a copy of the License at
19
-#
20
-#     http://www.apache.org/licenses/LICENSE-2.0
21
-#
22
-# Unless required by applicable law or agreed to in writing, software
23
-# distributed under the License is distributed on an "AS IS" BASIS,
24
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
-# See the License for the specific language governing permissions and
26
-# limitations under the License.
27
-#=============================================================================
28
-
29
-find_path(XRENDER_INCLUDE_DIR NAMES X11/extensions/Xrender.h
30
-          PATHS /opt/X11/include
31
-          DOC "The Xrender include directory")
32
-
33
-find_library(XRENDER_LIBRARY NAMES Xrender
34
-          PATHS /opt/X11/lib
35
-          DOC "The Xrender library")
36
-
37
-include(FindPackageHandleStandardArgs)
38
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(Xrender DEFAULT_MSG XRENDER_LIBRARY XRENDER_INCLUDE_DIR)
39
-
40
-if(XRENDER_FOUND)
41
-
42
-    set(XRENDER_LIBRARIES ${XRENDER_LIBRARY})
43
-    set(XRENDER_INCLUDE_DIRS ${XRENDER_INCLUDE_DIR})
44
-
45
-endif()
46
-
47
-mark_as_advanced(XRENDER_INCLUDE_DIR XRENDER_LIBRARY)

+ 21
- 9
src/keyboard.cpp Bestand weergeven

@@ -14,18 +14,28 @@ bool Keyboard::getKey( KeySym key ) {
14 14
 }
15 15
 
16 16
 bool Keyboard::anyKeyDown() {
17
-    // Thanks to SFML for some reliable key state grabbing.
18
-    // Get the whole keyboard state
19
-    char keys[ 32 ];
17
+    return keyDown;
18
+}
19
+
20
+void Keyboard::update() {
21
+    char keys[32];
20 22
     XQueryKeymap( x11->display, keys );
21
-    // Each bit indicates a different key, 1 for pressed, 0 otherwise.
22
-    // Every bit should be 0 if nothing is pressed.
23
-    for ( unsigned int i = 0; i < 32; i++ ) {
24
-        if ( keys[ i ] != 0 ) {
25
-            return true;
23
+    keyDown = false;
24
+    for ( int i=0;i<32;i++ ) {
25
+        if ( deltaState[i] == keys[i] ) {
26
+            continue;
27
+        }
28
+        // Found a key in a group of 4 that's different
29
+        char a = deltaState[i];
30
+        char b = keys[i];
31
+        // Find the "different" bits
32
+        char c = a^b;
33
+        // A new key was pressed since the last update.
34
+        if ( c && b&c ) {
35
+            keyDown = true;
26 36
         }
37
+        deltaState[i] = keys[i];
27 38
     }
28
-    return false;
29 39
 }
30 40
 
31 41
 Keyboard::Keyboard( X11* x11 ) {
@@ -34,6 +44,8 @@ Keyboard::Keyboard( X11* x11 ) {
34 44
     if ( err != GrabSuccess ) {
35 45
         throw new std::runtime_error( "Failed to grab keyboard.\n" );
36 46
     }
47
+    XQueryKeymap( x11->display, deltaState );
48
+    keyDown = false;
37 49
 }
38 50
 
39 51
 Keyboard::~Keyboard() {

+ 3
- 0
src/keyboard.hpp Bestand weergeven

@@ -25,10 +25,13 @@
25 25
 
26 26
 class Keyboard {
27 27
 private:
28
+    char deltaState[32];
28 29
     X11* x11;
30
+    bool keyDown;
29 31
 public:
30 32
     Keyboard( X11* x11 );
31 33
     ~Keyboard();
34
+    void update();
32 35
     bool getKey( KeySym key );
33 36
     bool anyKeyDown();
34 37
 };

+ 4
- 6
src/mouse.cpp Bestand weergeven

@@ -52,7 +52,7 @@ Mouse::~Mouse() {
52 52
 	XUngrabPointer( x11->display, CurrentTime );
53 53
 }
54 54
 
55
-void Mouse::tick() {
55
+void Mouse::update() {
56 56
     XEvent event;
57 57
     while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
58 58
 		setButton( event.xbutton.button, 1 );
@@ -61,11 +61,9 @@ void Mouse::tick() {
61 61
 		setButton( event.xbutton.button, 0 );
62 62
 	}
63 63
     while ( XCheckTypedEvent( x11->display, EnterNotify, &event ) ) {
64
-		if ( event.xcrossing.subwindow != None ) {
65
-			hoverWindow = event.xcrossing.subwindow;
66
-		} else {
67
-			hoverWindow = event.xcrossing.window;
68
-		}
64
+        subWindow = event.xcrossing.subwindow;
65
+        hoverWindow = event.xcrossing.window;
66
+        std::cout << hoverWindow << "\n";
69 67
 	}
70 68
 }
71 69
 

+ 3
- 1
src/mouse.hpp Bestand weergeven

@@ -24,6 +24,7 @@
24 24
 #include <vector>
25 25
 #include <glm/glm.hpp>
26 26
 #include <X11/cursorfont.h>
27
+#include <iostream>
27 28
 
28 29
 #include "x.hpp"
29 30
 
@@ -35,7 +36,8 @@ private:
35 36
     int currentCursor;
36 37
 public:
37 38
 	Window hoverWindow;
38
-	void tick();
39
+	Window subWindow;
40
+	void update();
39 41
     Mouse( X11* x11 );
40 42
     ~Mouse();
41 43
     void setCursor( int cursor );

+ 3
- 3
src/slop.cpp Bestand weergeven

@@ -82,9 +82,9 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
82 82
     SlopMemory memory( options );
83 83
 
84 84
     // This is where we'll run through all of our stuffs
85
-    //FIXME: We need to sync up with wayland's draw pings so that we don't overdraw ever...
86 85
     while( memory.running ) {
87
-        mouse->tick();
86
+        mouse->update();
87
+        keyboard->update();
88 88
         // We move our statemachine forward.
89 89
         memory.update( 1 );
90 90
 
@@ -102,7 +102,7 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
102 102
         if ( err != GL_NO_ERROR ) {
103 103
             throw err;
104 104
         }
105
-        if ( keyboard->anyKeyDown() || mouse->getButton( 2 ) ) {
105
+        if ( keyboard->anyKeyDown() || mouse->getButton( 3 ) ) {
106 106
             memory.running = false;
107 107
             if ( cancelled ) {
108 108
                 *cancelled = true;

+ 13
- 1
src/window.cpp Bestand weergeven

@@ -61,9 +61,21 @@ SlopWindow::SlopWindow() {
61 61
         throw new std::runtime_error("Failed to load function pointers for OpenGL.");
62 62
     }
63 63
     framebuffer = new Framebuffer( WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
64
-	XMapWindow( x11->display, window );
64
+
65
+    // Then we do a basic double clear (double buffered).
65 66
     glViewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
66 67
     camera = glm::ortho( 0.0f, (float)WidthOfScreen( x11->screen ), (float)HeightOfScreen( x11->screen ), 0.0f, -1.0f, 1.0f);
68
+    glClearColor( 0, 0, 0, 0 );
69
+    glClear( GL_COLOR_BUFFER_BIT );
70
+    display();
71
+
72
+    // Make it so all input falls through
73
+    XRectangle rect;
74
+    rect.x = rect.y = rect.width = rect.height = 0; 
75
+    XShapeCombineRectangles( x11->display, window, ShapeInput, 0, 0, &rect, 1, ShapeSet, 0);
76
+
77
+    // Last, we actually display the window <:o)
78
+	XMapWindow( x11->display, window );
67 79
 }
68 80
 
69 81
 SlopWindow::~SlopWindow() {

+ 1
- 0
src/window.hpp Bestand weergeven

@@ -31,6 +31,7 @@
31 31
 #include <glm/gtc/matrix_transform.hpp>
32 32
 #include <X11/Xutil.h>
33 33
 #include <X11/Xatom.h>
34
+#include <X11/extensions/shape.h>
34 35
 
35 36
 #include "x.hpp"
36 37
 #include "framebuffer.hpp"

+ 14
- 0
src/x.cpp Bestand weergeven

@@ -9,8 +9,22 @@ 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 );
12 13
 }
13 14
 
14 15
 X11::~X11() {
15 16
     XCloseDisplay( display );
16 17
 }
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
+}

+ 2
- 0
src/x.hpp Bestand weergeven

@@ -21,12 +21,14 @@
21 21
 #ifndef N_X_H_
22 22
 #define N_X_H_
23 23
 
24
+#include <iostream>
24 25
 #include <X11/Xlib.h>
25 26
 #include <string>
26 27
 #include <stdexcept>
27 28
 
28 29
 class X11 {
29 30
 private:
31
+    void selectAllInputs( Window win );
30 32
 public:
31 33
     X11( std::string displayName );
32 34
     ~X11();