Browse Source

getting closer

naelstrof 7 years ago
parent
commit
e20e54cbf0
12 changed files with 64 additions and 102 deletions
  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 View File

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

+ 0
- 23
modules/FindRT.cmake View File

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 View File

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 View File

14
 }
14
 }
15
 
15
 
16
 bool Keyboard::anyKeyDown() {
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
     XQueryKeymap( x11->display, keys );
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
 Keyboard::Keyboard( X11* x11 ) {
41
 Keyboard::Keyboard( X11* x11 ) {
34
     if ( err != GrabSuccess ) {
44
     if ( err != GrabSuccess ) {
35
         throw new std::runtime_error( "Failed to grab keyboard.\n" );
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
 Keyboard::~Keyboard() {
51
 Keyboard::~Keyboard() {

+ 3
- 0
src/keyboard.hpp View File

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

+ 4
- 6
src/mouse.cpp View File

52
 	XUngrabPointer( x11->display, CurrentTime );
52
 	XUngrabPointer( x11->display, CurrentTime );
53
 }
53
 }
54
 
54
 
55
-void Mouse::tick() {
55
+void Mouse::update() {
56
     XEvent event;
56
     XEvent event;
57
     while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
57
     while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
58
 		setButton( event.xbutton.button, 1 );
58
 		setButton( event.xbutton.button, 1 );
61
 		setButton( event.xbutton.button, 0 );
61
 		setButton( event.xbutton.button, 0 );
62
 	}
62
 	}
63
     while ( XCheckTypedEvent( x11->display, EnterNotify, &event ) ) {
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 View File

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

+ 3
- 3
src/slop.cpp View File

82
     SlopMemory memory( options );
82
     SlopMemory memory( options );
83
 
83
 
84
     // This is where we'll run through all of our stuffs
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
     while( memory.running ) {
85
     while( memory.running ) {
87
-        mouse->tick();
86
+        mouse->update();
87
+        keyboard->update();
88
         // We move our statemachine forward.
88
         // We move our statemachine forward.
89
         memory.update( 1 );
89
         memory.update( 1 );
90
 
90
 
102
         if ( err != GL_NO_ERROR ) {
102
         if ( err != GL_NO_ERROR ) {
103
             throw err;
103
             throw err;
104
         }
104
         }
105
-        if ( keyboard->anyKeyDown() || mouse->getButton( 2 ) ) {
105
+        if ( keyboard->anyKeyDown() || mouse->getButton( 3 ) ) {
106
             memory.running = false;
106
             memory.running = false;
107
             if ( cancelled ) {
107
             if ( cancelled ) {
108
                 *cancelled = true;
108
                 *cancelled = true;

+ 13
- 1
src/window.cpp View File

61
         throw new std::runtime_error("Failed to load function pointers for OpenGL.");
61
         throw new std::runtime_error("Failed to load function pointers for OpenGL.");
62
     }
62
     }
63
     framebuffer = new Framebuffer( WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
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
     glViewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
66
     glViewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
66
     camera = glm::ortho( 0.0f, (float)WidthOfScreen( x11->screen ), (float)HeightOfScreen( x11->screen ), 0.0f, -1.0f, 1.0f);
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
 SlopWindow::~SlopWindow() {
81
 SlopWindow::~SlopWindow() {

+ 1
- 0
src/window.hpp View File

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

+ 14
- 0
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 );
12
 }
13
 }
13
 
14
 
14
 X11::~X11() {
15
 X11::~X11() {
15
     XCloseDisplay( display );
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 View File

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