naelstrof преди 7 години
родител
ревизия
c423817ff1
променени са 24 файла, в които са добавени 400 реда и са изтрити 491 реда
  1. 37
    29
      CMakeLists.txt
  2. 0
    53
      modules/FindEGL.cmake
  3. 44
    0
      modules/FindGLX.cmake
  4. 23
    0
      modules/FindRT.cmake
  5. 0
    67
      modules/FindWayland.cmake
  6. 26
    0
      modules/FindXExt.cmake
  7. 47
    0
      modules/FindXRender.cmake
  8. 0
    0
      share/slop/simple.frag
  9. 0
    0
      share/slop/simple.vert
  10. 0
    0
      share/slop/textured.frag
  11. 0
    0
      share/slop/textured.vert
  12. 1
    1
      src/framebuffer.cpp
  13. 29
    46
      src/keyboard.cpp
  14. 6
    9
      src/keyboard.hpp
  15. 40
    80
      src/mouse.cpp
  16. 12
    15
      src/mouse.hpp
  17. 6
    6
      src/resource.cpp
  18. 8
    14
      src/slop.cpp
  19. 6
    6
      src/slopstates.cpp
  20. 0
    55
      src/wayland.cpp
  21. 73
    65
      src/window.cpp
  22. 11
    15
      src/window.hpp
  23. 16
    0
      src/x.cpp
  24. 15
    30
      src/x.hpp

+ 37
- 29
CMakeLists.txt Целия файл

@@ -10,10 +10,10 @@ if( NOT CMAKE_INSTALL_PREFIX )
10 10
 endif()
11 11
 
12 12
 if( NOT SHADER_PREFIX )
13
-    set( SHADER_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "The path where slop thinks it resides in, so that it can find the shaders. This is not necessarily the CMAKE_INSTALL_PREFIX. For example if the shaders will exist in /usr/share/slop-wayland, SHADER_PREFIX should be \"/usr\"." )
13
+    set( SHADER_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "The path where slop thinks it resides in, so that it can find the shaders. This is not necessarily the CMAKE_INSTALL_PREFIX. For example if the shaders will exist in /usr/share/slop, SHADER_PREFIX should be \"/usr\"." )
14 14
 endif()
15 15
 
16
-project(slop-wayland)
16
+project(slop)
17 17
 
18 18
 set(CMAKE_CXX_STANDARD 14)
19 19
 set(CMAKE_CXX_STANDARD_REQUIRED on)
@@ -23,22 +23,21 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
23 23
 include_directories("${PROJECT_BINARY_DIR}")
24 24
 
25 25
 # Define sources and executable
26
-set(EXECUTABLE_NAME "slop-wayland")
27
-
28
-set( source
29
-         src/wayland.cpp
30
-         src/window.cpp
31
-         src/mouse.cpp
32
-         src/keyboard.cpp
33
-         src/framebuffer.cpp
34
-         src/resource.cpp
35
-         src/options.cpp
36
-         src/gl_core_3_3.c
37
-         src/shader.cpp
38
-         src/slopstates.cpp
39
-         src/slop.cpp
40
-         src/rectangle.cpp
41
-         src/main.cpp )
26
+set(EXECUTABLE_NAME "slop")
27
+
28
+set( source src/x.cpp
29
+            src/window.cpp
30
+            src/mouse.cpp
31
+            src/keyboard.cpp
32
+            src/framebuffer.cpp
33
+            src/resource.cpp
34
+            src/options.cpp
35
+            src/gl_core_3_3.c
36
+            src/shader.cpp
37
+            src/slopstates.cpp
38
+            src/slop.cpp
39
+            src/rectangle.cpp
40
+            src/main.cpp )
42 41
 
43 42
 add_executable(${EXECUTABLE_NAME} ${source})
44 43
 
@@ -47,23 +46,32 @@ add_executable(${EXECUTABLE_NAME} ${source})
47 46
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules" )
48 47
 #Find any version 2.X of SFML
49 48
 #See the FindSFML.cmake file for additional details and instructions
50
-find_package(Wayland REQUIRED)
51
-find_package(EGL REQUIRED)
52 49
 find_package(OpenGL REQUIRED)
53 50
 find_package(GLM REQUIRED)
51
+find_package(GLX REQUIRED)
52
+find_package(X11 REQUIRED)
53
+find_package(XExt REQUIRED) 
54
+find_package(XRender REQUIRED)
55
+find_package(RT) 
54 56
 
55
-include_directories(${WAYLAND_CLIENT_INCLUDE_DIR}
56
-                    ${WAYLAND_CURSOR_INCLUDE_DIR}
57
-                    ${WAYLAND_EGL_INCLUDE_DIR}
58
-                    ${EGL_INCLUDE_DIR}
57
+include_directories(${X11_INCLUDE_DIR}
59 58
                     ${GLM_INCLUDE_DIR}
59
+                    ${GLX_INCLUDE_DIR}
60
+                    ${XRENDER_INCLUDE_DIRS}
60 61
                     ${OPENGL_INCLUDE_DIR})
61 62
 
62
-target_link_libraries(${EXECUTABLE_NAME} ${WAYLAND_CLIENT_LIBRARIES}
63
-                      ${WAYLAND_CURSOR_LIBRARIES}
64
-                      ${WAYLAND_EGL_LIBRARIES}
65
-                      ${EGL_LIBRARIES}
66
-                      ${OPENGL_LIBRARIES})
63
+if ( RT_INCLUDE_DIR )
64
+    include_directories(${RT_INCLUDE_DIR})
65
+endif()
66
+
67
+target_link_libraries(${EXECUTABLE_NAME} ${X11_LIBRARIES}
68
+                                         ${GLX_LIBRARIES}
69
+                                         ${XRENDER_LIBRARIES}
70
+                                         ${OPENGL_LIBRARIES})
71
+if ( RT_LIBRARY )
72
+    target_link_libraries(${EXECUTABLE_NAME} ${RT_LIBRARY})
73
+endif()
74
+
67 75
 
68 76
 # Install targets
69 77
 install( TARGETS ${EXECUTABLE_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )

+ 0
- 53
modules/FindEGL.cmake Целия файл

@@ -1,53 +0,0 @@
1
-# - Try to Find EGL
2
-# Once done, this will define
3
-#
4
-#  EGL_FOUND - system has EGL installed.
5
-#  EGL_INCLUDE_DIRS - directories which contain the EGL headers.
6
-#  EGL_LIBRARIES - libraries required to link against EGL.
7
-#  EGL_DEFINITIONS - Compiler switches required for using EGL.
8
-#
9
-# Copyright (C) 2012 Intel Corporation. All rights reserved.
10
-#
11
-# Redistribution and use in source and binary forms, with or without
12
-# modification, are permitted provided that the following conditions
13
-# are met:
14
-# 1.  Redistributions of source code must retain the above copyright
15
-#     notice, this list of conditions and the following disclaimer.
16
-# 2.  Redistributions in binary form must reproduce the above copyright
17
-#     notice, this list of conditions and the following disclaimer in the
18
-#     documentation and/or other materials provided with the distribution.
19
-#
20
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
21
-# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
-# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
-# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
24
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27
-# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
-# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29
-# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30
-# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-
33
-find_package(PkgConfig)
34
-
35
-pkg_check_modules(PC_EGL egl)
36
-
37
-if (PC_EGL_FOUND)
38
-    set(EGL_DEFINITIONS ${PC_EGL_CFLAGS_OTHER})
39
-endif ()
40
-
41
-find_path(EGL_INCLUDE_DIRS NAMES EGL/egl.h
42
-    HINTS ${PC_EGL_INCLUDEDIR} ${PC_EGL_INCLUDE_DIRS}
43
-)
44
-
45
-set(EGL_NAMES ${EGL_NAMES} egl EGL)
46
-find_library(EGL_LIBRARIES NAMES ${EGL_NAMES}
47
-    HINTS ${PC_EGL_LIBDIR} ${PC_EGL_LIBRARY_DIRS}
48
-)
49
-
50
-include(FindPackageHandleStandardArgs)
51
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(EGL DEFAULT_MSG EGL_INCLUDE_DIRS EGL_LIBRARIES)
52
-
53
-mark_as_advanced(EGL_INCLUDE_DIRS EGL_LIBRARIES)

+ 44
- 0
modules/FindGLX.cmake Целия файл

@@ -0,0 +1,44 @@
1
+# Try to find GLX. Once done, this will define:
2
+#
3
+#   GLX_FOUND - variable which returns the result of the search
4
+#   GLX_INCLUDE_DIRS - list of include directories
5
+#   GLX_LIBRARIES - options for the linker
6
+
7
+#=============================================================================
8
+# Copyright 2012 Benjamin Eikel
9
+#
10
+# Distributed under the OSI-approved BSD License (the "License");
11
+# see accompanying file Copyright.txt for details.
12
+#
13
+# This software is distributed WITHOUT ANY WARRANTY; without even the
14
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+# See the License for more information.
16
+#=============================================================================
17
+# (To distribute this file outside of CMake, substitute the full
18
+#  License text for the above reference.)
19
+
20
+find_package(PkgConfig)
21
+pkg_check_modules(PC_GLX QUIET glx)
22
+
23
+find_path(GLX_INCLUDE_DIR
24
+    GL/glx.h
25
+    HINTS ${PC_GLX_INCLUDEDIR} ${PC_GLX_INCLUDE_DIRS}
26
+)
27
+find_library(GLX_LIBRARY
28
+    GL
29
+    HINTS ${PC_GLX_LIBDIR} ${PC_GLX_LIBRARY_DIRS}
30
+)
31
+
32
+set(GLX_INCLUDE_DIRS ${GLX_INCLUDE_DIR})
33
+set(GLX_LIBRARIES ${GLX_LIBRARY})
34
+
35
+include(FindPackageHandleStandardArgs)
36
+find_package_handle_standard_args(GLX DEFAULT_MSG
37
+    GLX_INCLUDE_DIR
38
+    GLX_LIBRARY
39
+)
40
+
41
+mark_as_advanced(
42
+    GLX_INCLUDE_DIR
43
+    GLX_LIBRARY
44
+)

+ 23
- 0
modules/FindRT.cmake Целия файл

@@ -0,0 +1,23 @@
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
- 67
modules/FindWayland.cmake Целия файл

@@ -1,67 +0,0 @@
1
-# Try to find Wayland on a Unix system
2
-#
3
-# This will define:
4
-#
5
-#   WAYLAND_FOUND       - True if Wayland is found
6
-#   WAYLAND_LIBRARIES   - Link these to use Wayland
7
-#   WAYLAND_INCLUDE_DIR - Include directory for Wayland
8
-#   WAYLAND_DEFINITIONS - Compiler flags for using Wayland
9
-#
10
-# In addition the following more fine grained variables will be defined:
11
-#
12
-#   WAYLAND_CLIENT_FOUND  WAYLAND_CLIENT_INCLUDE_DIR  WAYLAND_CLIENT_LIBRARIES
13
-#   WAYLAND_SERVER_FOUND  WAYLAND_SERVER_INCLUDE_DIR  WAYLAND_SERVER_LIBRARIES
14
-#   WAYLAND_EGL_FOUND     WAYLAND_EGL_INCLUDE_DIR     WAYLAND_EGL_LIBRARIES
15
-#   WAYLAND_CURSOR_FOUND  WAYLAND_CURSOR_INCLUDE_DIR  WAYLAND_CURSOR_LIBRARIES
16
-#
17
-# Copyright (c) 2013 Martin Gräßlin <mgraesslin@kde.org>
18
-#
19
-# Redistribution and use is allowed according to the terms of the BSD license.
20
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
21
-
22
-IF (NOT WIN32)
23
-  IF (WAYLAND_INCLUDE_DIR AND WAYLAND_LIBRARIES)
24
-    # In the cache already
25
-    SET(WAYLAND_FIND_QUIETLY TRUE)
26
-  ENDIF ()
27
-
28
-  # Use pkg-config to get the directories and then use these values
29
-  # in the FIND_PATH() and FIND_LIBRARY() calls
30
-  FIND_PACKAGE(PkgConfig)
31
-  PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor)
32
-
33
-  SET(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS})
34
-
35
-  FIND_PATH(WAYLAND_CLIENT_INCLUDE_DIR  NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
36
-  FIND_PATH(WAYLAND_SERVER_INCLUDE_DIR  NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
37
-  FIND_PATH(WAYLAND_EGL_INCLUDE_DIR     NAMES wayland-egl.h    HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
38
-  FIND_PATH(WAYLAND_CURSOR_INCLUDE_DIR  NAMES wayland-cursor.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
39
-
40
-  FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
41
-  FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
42
-  FIND_LIBRARY(WAYLAND_EGL_LIBRARIES    NAMES wayland-egl      HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
43
-  FIND_LIBRARY(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
44
-
45
-  set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR})
46
-
47
-  set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES})
48
-
49
-  list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIR)
50
-
51
-  include(FindPackageHandleStandardArgs)
52
-
53
-  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CLIENT  DEFAULT_MSG  WAYLAND_CLIENT_LIBRARIES  WAYLAND_CLIENT_INCLUDE_DIR)
54
-  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_SERVER  DEFAULT_MSG  WAYLAND_SERVER_LIBRARIES  WAYLAND_SERVER_INCLUDE_DIR)
55
-  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_EGL     DEFAULT_MSG  WAYLAND_EGL_LIBRARIES     WAYLAND_EGL_INCLUDE_DIR)
56
-  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CURSOR  DEFAULT_MSG  WAYLAND_CURSOR_LIBRARIES  WAYLAND_CURSOR_INCLUDE_DIR)
57
-  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND         DEFAULT_MSG  WAYLAND_LIBRARIES         WAYLAND_INCLUDE_DIR)
58
-
59
-  MARK_AS_ADVANCED(
60
-        WAYLAND_INCLUDE_DIR         WAYLAND_LIBRARIES
61
-        WAYLAND_CLIENT_INCLUDE_DIR  WAYLAND_CLIENT_LIBRARIES
62
-        WAYLAND_SERVER_INCLUDE_DIR  WAYLAND_SERVER_LIBRARIES
63
-        WAYLAND_EGL_INCLUDE_DIR     WAYLAND_EGL_LIBRARIES
64
-        WAYLAND_CURSOR_INCLUDE_DIR  WAYLAND_CURSOR_LIBRARIES
65
-  )
66
-
67
-ENDIF ()

+ 26
- 0
modules/FindXExt.cmake Целия файл

@@ -0,0 +1,26 @@
1
+# - Find XExt
2
+# Find the XExtension libraries (WARNING: It's geared and tested specifically for the XShape extension though)
3
+#
4
+#  This module defines the following variables:
5
+#     XEXT_FOUND        - 1 if XEXT_INCLUDE_DIR & XEXT_LIBRARY are found, 0 otherwise
6
+#     XEXT_INCLUDE_DIR  - where to find Xlib.h, etc.
7
+#     XEXT_LIBRARY      - the X11 library
8
+#
9
+
10
+find_path( XEXT_INCLUDE_DIR
11
+           NAMES X11/extensions/shape.h
12
+           PATH_SUFFIXES X11/extensions
13
+           DOC "The XExtension include directory" )
14
+
15
+find_library( XEXT_LIBRARY
16
+              NAMES Xext
17
+              PATHS /usr/lib /lib
18
+              DOC "The XExtension library" )
19
+
20
+if( XEXT_INCLUDE_DIR AND XEXT_LIBRARY )
21
+    set( XEXT_FOUND 1 )
22
+else()
23
+    set( XEXT_FOUND 0 )
24
+endif()
25
+
26
+mark_as_advanced( XEXT_INCLUDE_DIR XEXT_LIBRARY )

+ 47
- 0
modules/FindXRender.cmake Целия файл

@@ -0,0 +1,47 @@
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)

share/slop-wayland/simple.frag → share/slop/simple.frag Целия файл


share/slop-wayland/simple.vert → share/slop/simple.vert Целия файл


share/slop-wayland/textured.frag → share/slop/textured.frag Целия файл


share/slop-wayland/textured.vert → share/slop/textured.vert Целия файл


+ 1
- 1
src/framebuffer.cpp Целия файл

@@ -6,7 +6,7 @@ Framebuffer::Framebuffer( int w, int h ) {
6 6
     glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
7 7
     glGenTextures(1, &image);
8 8
     glBindTexture(GL_TEXTURE_2D, image);
9
-    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
9
+    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
10 10
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
11 11
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
12 12
     glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, image, 0);

+ 29
- 46
src/keyboard.cpp Целия файл

@@ -1,58 +1,41 @@
1 1
 #include "keyboard.hpp"
2 2
 
3
-static void keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size) {
4
-}
5
-
6
-static void keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
7
-}
8
-
9
-static void keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface) {
10
-}
11
-
12
-static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
13
-    Keyboard* kb = (Keyboard*)data;
14
-    kb->setKey( key, state );
15
-}
16
-
17
-static void keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) {
18
-}
19
-
20
-static const struct wl_keyboard_listener keyboard_listener = {
21
-    keyboard_handle_keymap,
22
-    keyboard_handle_enter,
23
-    keyboard_handle_leave,
24
-    keyboard_handle_key,
25
-    keyboard_handle_modifiers,
26
-};
27
-
28
-Keyboard::Keyboard(Wayland* wayland) {
29
-    wl_keyboard_add_listener(wl_seat_get_keyboard(wayland->seat), &keyboard_listener, this);
3
+bool Keyboard::getKey( KeySym key ) {
4
+    KeyCode keycode = XKeysymToKeycode( x11->display, key );
5
+    if ( keycode != 0 ) {
6
+        // Get the whole keyboard state
7
+        char keys[32];
8
+        XQueryKeymap( x11->display, keys );
9
+        // Check our keycode
10
+        return ( keys[ keycode / 8 ] & ( 1 << ( keycode % 8 ) ) ) != 0;
11
+    } else {
12
+        return false;
13
+    }
30 14
 }
31 15
 
32
-void Keyboard::setKey( int key, int state ) {
33
-    for (unsigned int i=0;i<keys.size();i++ ) {
34
-        if ( keys[i].x == key ) {
35
-            keys[i].y = state;
36
-            return;
16
+bool Keyboard::anyKeyDown() {
17
+    // Thanks to SFML for some reliable key state grabbing.
18
+    // Get the whole keyboard state
19
+    char keys[ 32 ];
20
+    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;
37 26
         }
38 27
     }
39
-    keys.push_back(glm::ivec2(key,state));
28
+    return false;
40 29
 }
41 30
 
42
-int Keyboard::getKey( int button ) {
43
-    for (unsigned int i=0;i<keys.size();i++ ) {
44
-        if ( keys[i].x == button ) {
45
-            return keys[i].y;
46
-        }
31
+Keyboard::Keyboard( X11* x11 ) {
32
+    this->x11 = x11;
33
+    int err = XGrabKeyboard( x11->display, x11->root, False, GrabModeAsync, GrabModeAsync, CurrentTime );
34
+    if ( err != GrabSuccess ) {
35
+        throw new std::runtime_error( "Failed to grab keyboard.\n" );
47 36
     }
48
-    return 0;
49 37
 }
50 38
 
51
-bool Keyboard::anyKeyDown() {
52
-    for ( glm::ivec2 combo : keys ) {
53
-        if ( combo.y == 1 ) {
54
-            return true;
55
-        }
56
-    }
57
-    return false;
39
+Keyboard::~Keyboard() {
40
+    XUngrabKeyboard( x11->display, CurrentTime );
58 41
 }

+ 6
- 9
src/keyboard.hpp Целия файл

@@ -1,4 +1,4 @@
1
-/* keyboard.hpp: Interfaces with wayland to grab key press information.
1
+/* keyboard.hpp: Interfaces with x11 to grab key press information.
2 2
  *
3 3
  * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
4 4
  *
@@ -21,18 +21,15 @@
21 21
 #ifndef N_KEYBOARD_H_
22 22
 #define N_KEYBOARD_H_
23 23
 
24
-#include <glm/glm.hpp>
25
-#include <wayland-client.h>
26
-#include <vector>
27
-#include "wayland.hpp"
24
+#include "x.hpp"
28 25
 
29 26
 class Keyboard {
30 27
 private:
31
-    std::vector<glm::ivec2> keys;
28
+    X11* x11;
32 29
 public:
33
-    Keyboard( Wayland* wayland );
34
-    void setKey( int key, int state );
35
-    int getKey( int key );
30
+    Keyboard( X11* x11 );
31
+    ~Keyboard();
32
+    bool getKey( KeySym key );
36 33
     bool anyKeyDown();
37 34
 };
38 35
 

+ 40
- 80
src/mouse.cpp Целия файл

@@ -1,51 +1,5 @@
1 1
 #include "mouse.hpp"
2 2
 
3
-static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
4
-		                         uint32_t serial, struct wl_surface *surface,
5
-		                         wl_fixed_t sx_w, wl_fixed_t sy_w) {
6
-    Mouse* m = (Mouse*)data;
7
-	float sx = wl_fixed_to_double(sx_w);
8
-	float sy = wl_fixed_to_double(sy_w);
9
-    m->setMousePos( sx, sy );
10
-    m->serial = serial;
11
-    m->pointer = pointer;
12
-    struct wl_cursor_image *image = m->cursor->images[0];
13
-    wl_pointer_set_cursor(pointer, serial, m->surface, image->hotspot_x, image->hotspot_y);
14
-}
15
-
16
-static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
17
-		                         uint32_t serial, struct wl_surface *surface) {
18
-}
19
-
20
-static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
21
-		                          uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
22
-{
23
-    Mouse* m = (Mouse*)data;
24
-	float sx = wl_fixed_to_double(sx_w);
25
-	float sy = wl_fixed_to_double(sy_w);
26
-    m->pointer = pointer;
27
-    m->setMousePos( sx, sy );
28
-}
29
-
30
-static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
31
-                                  uint32_t time, uint32_t button, uint32_t state_w) {
32
-    Mouse* m = (Mouse*)data;
33
-    m->pointer = pointer;
34
-    m->setButton( button, state_w );
35
-}
36
-
37
-static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
38
-		                        uint32_t time, uint32_t axis, wl_fixed_t value) {
39
-}
40
-
41
-static const struct wl_pointer_listener pointer_listener = {
42
-	pointer_handle_enter,
43
-	pointer_handle_leave,
44
-	pointer_handle_motion,
45
-	pointer_handle_button,
46
-	pointer_handle_axis,
47
-};
48
-
49 3
 void Mouse::setButton( int button, int state ) {
50 4
     for (unsigned int i=0;i<buttons.size();i++ ) {
51 5
         if ( buttons[i].x == button ) {
@@ -65,47 +19,53 @@ int Mouse::getButton( int button ) {
65 19
     return 0;
66 20
 }
67 21
 
68
-void Mouse::setMousePos(float x, float y) {
69
-    this->x = x;
70
-    this->y = y;
71
-}
72
-
73 22
 glm::vec2 Mouse::getMousePos() {
74
-    return glm::vec2( x, y );
23
+    Window root, child;
24
+    int mx, my;
25
+    int wx, wy;
26
+    unsigned int mask;
27
+    XQueryPointer( x11->display, x11->root, &root, &child, &mx, &my, &wx, &wy, &mask );
28
+    return glm::vec2( mx, my );
75 29
 }
76 30
 
77
-void Mouse::setCursor( std::string name ) {
78
-    if ( name == currentMouseCursor ) {
31
+void Mouse::setCursor( int cursor ) {
32
+    if ( currentCursor == cursor ) {
79 33
         return;
80 34
     }
81
-    // First we gotta delete the old mouse surface.
82
-    wl_surface_destroy( surface );
83
-
84
-    // Then we get the new cursor image.
85
-    cursor = wl_cursor_theme_get_cursor(theme, name.c_str());
86
-    struct wl_cursor_image *image = cursor->images[0];
87
-    struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
88
-    
89
-    // Then we create the new surface
90
-    surface = wl_compositor_create_surface(wayland->compositor);
91
-    wl_surface_attach(surface, cursor_buf, 0, 0);
92
-    wl_surface_damage(surface, 0, 0, image->width, image->height);
93
-    wl_surface_commit(surface);
35
+    XFreeCursor( x11->display, xcursor );
36
+    xcursor = XCreateFontCursor( x11->display, cursor );
37
+    XChangeActivePointerGrab( x11->display,
38
+                              PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
39
+                              xcursor, CurrentTime );
40
+}
94 41
 
95
-    // Finally assign the surface as a pointer
96
-    wl_pointer_set_cursor(pointer, serial, surface, image->hotspot_x, image->hotspot_y);
42
+Mouse::Mouse(X11* x11) {
43
+    this->x11 = x11;
44
+    currentCursor = XC_cross;
45
+    xcursor = XCreateFontCursor( x11->display, XC_cross );
46
+    XGrabPointer( x11->display, x11->root, True,
47
+                  PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
48
+                  GrabModeAsync, GrabModeAsync, None, xcursor, CurrentTime );
97 49
 }
98 50
 
99
-Mouse::Mouse(Wayland* wayland) {
100
-    wl_pointer_add_listener(wl_seat_get_pointer(wayland->seat), &pointer_listener, this);
101
-    theme = wl_cursor_theme_load("default", 16, wayland->shm );
102
-    cursor = wl_cursor_theme_get_cursor(theme, "cross");
103
-    std::string currentMouseCursor = "cross";
51
+Mouse::~Mouse() {
52
+	XUngrabPointer( x11->display, CurrentTime );
53
+}
104 54
 
105
-    surface = wl_compositor_create_surface(wayland->compositor);
106
-    struct wl_cursor_image *image = cursor->images[0];
107
-    struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
108
-    wl_surface_attach(surface, cursor_buf, 0, 0);
109
-    wl_surface_damage(surface, 0, 0, image->width, image->height);
110
-    wl_surface_commit(surface);
55
+void Mouse::tick() {
56
+    XEvent event;
57
+    while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
58
+		setButton( event.xbutton.button, 1 );
59
+	}
60
+    while ( XCheckTypedEvent( x11->display, ButtonRelease, &event ) ) {
61
+		setButton( event.xbutton.button, 0 );
62
+	}
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
+		}
69
+	}
111 70
 }
71
+

+ 12
- 15
src/mouse.hpp Целия файл

@@ -1,4 +1,4 @@
1
-/* mouse.hpp: Interfaces with wayland to grab mouse information.
1
+/* mouse.hpp: Interfaces with x11 to grab mouse information.
2 2
  *
3 3
  * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
4 4
  *
@@ -21,27 +21,24 @@
21 21
 #ifndef N_MOUSE_H_
22 22
 #define N_MOUSE_H_
23 23
 
24
-#include <wayland-client.h>
25
-#include <wayland-cursor.h>
26 24
 #include <vector>
27 25
 #include <glm/glm.hpp>
28
-#include "linux/input-event-codes.h"
29
-#include "wayland.hpp"
26
+#include <X11/cursorfont.h>
27
+
28
+#include "x.hpp"
30 29
 
31 30
 class Mouse {
32 31
 private:
33
-    wl_cursor_theme* theme;
34
-    float x,y;
32
+    X11* x11;
35 33
     std::vector<glm::ivec2> buttons;
36
-    std::string currentMouseCursor;
34
+    Cursor xcursor;
35
+    int currentCursor;
37 36
 public:
38
-    wl_surface* surface;
39
-    wl_cursor* cursor;
40
-    wl_pointer* pointer;
41
-    int serial;
42
-    Mouse( Wayland* wayland );
43
-    void setMousePos( float x, float y );
44
-    void setCursor( std::string name );
37
+	Window hoverWindow;
38
+	void tick();
39
+    Mouse( X11* x11 );
40
+    ~Mouse();
41
+    void setCursor( int cursor );
45 42
     glm::vec2 getMousePos();
46 43
     void setButton( int button, int state );
47 44
     int getButton( int button );

+ 6
- 6
src/resource.cpp Целия файл

@@ -22,21 +22,21 @@
22 22
 
23 23
 Resource::Resource() {
24 24
     // Find the configuration directory.
25
-    // usually ~/.config/slop-wayland and /usr/share/slop-wayland
25
+    // usually ~/.config/slop and /usr/share/slop
26 26
     char* config = getenv( "XDG_CONFIG_HOME" );
27 27
     if ( config == NULL ) {
28 28
         char* home = getpwuid(getuid())->pw_dir;
29 29
         usrconfig += home;
30
-        usrconfig += "/.config/slop-wayland/";
31
-        // SHADER_PREFIX is defined within the CMakeLists.txt
30
+        usrconfig += "/.config/slop/";
31
+        // SHADER_PREFIX is defined by the user within CMake, defaults to `/usr`.
32 32
         sysconfig = SHADER_PREFIX;
33
-        sysconfig += "/share/slop-wayland/";
33
+        sysconfig += "/share/slop/";
34 34
         return;
35 35
     }
36 36
     usrconfig += config;
37
-    usrconfig += "/slop-wayland/";
37
+    usrconfig += "/slop/";
38 38
     sysconfig = SHADER_PREFIX;
39
-    sysconfig += "/share/slop-wayland/";
39
+    sysconfig += "/share/slop/";
40 40
 }
41 41
 
42 42
 std::string Resource::getRealPath( std::string localpath ) {

+ 8
- 14
src/slop.cpp Целия файл

@@ -1,6 +1,6 @@
1 1
 #include "slop.hpp"
2 2
 
3
-Wayland* wayland;
3
+X11* x11;
4 4
 Mouse* mouse;
5 5
 Keyboard* keyboard;
6 6
 Resource* resource;
@@ -69,17 +69,12 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
69 69
     }
70 70
     resource = new Resource();
71 71
     // Set up wayland temporarily
72
-    wayland = new Wayland();
73
-    wayland->init();
74
-    mouse = new Mouse( wayland );
75
-    keyboard = new Keyboard( wayland );
72
+    x11 = new X11(":0");
73
+    mouse = new Mouse( x11 );
74
+    keyboard = new Keyboard( x11 );
76 75
 
77 76
     // Set up window with GL context
78
-    Window* window = new Window( 1, 1 );
79
-    window->setTitle("slop");
80
-    window->setClass("slop");
81
-    window->setFullScreen();
82
-    window->setCurrent();
77
+    SlopWindow* window = new SlopWindow();
83 78
 
84 79
     window->framebuffer->setShader( options->shader );
85 80
 
@@ -89,8 +84,7 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
89 84
     // This is where we'll run through all of our stuffs
90 85
     //FIXME: We need to sync up with wayland's draw pings so that we don't overdraw ever...
91 86
     while( memory.running ) {
92
-        // This is specifically for wayland updates.
93
-        wl_display_dispatch_pending(wayland->display);
87
+        mouse->tick();
94 88
         // We move our statemachine forward.
95 89
         memory.update( 1 );
96 90
 
@@ -108,7 +102,7 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
108 102
         if ( err != GL_NO_ERROR ) {
109 103
             throw err;
110 104
         }
111
-        if ( keyboard->anyKeyDown() || mouse->getButton( BTN_RIGHT ) ) {
105
+        if ( keyboard->anyKeyDown() || mouse->getButton( 2 ) ) {
112 106
             memory.running = false;
113 107
             if ( cancelled ) {
114 108
                 *cancelled = true;
@@ -132,7 +126,7 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
132 126
     // Then we clean up.
133 127
     delete window;
134 128
     delete mouse;
135
-    delete wayland;
129
+    delete x11;
136 130
     delete resource;
137 131
     if ( deleteOptions ) {
138 132
         delete options;

+ 6
- 6
src/slopstates.cpp Целия файл

@@ -13,7 +13,7 @@ void SlopState::draw( SlopMemory& memory, glm::mat4 matrix ) {
13 13
 
14 14
 // Start
15 15
 void SlopStart::update( SlopMemory& memory, double dt ) {
16
-    if ( mouse->getButton( BTN_LEFT ) ) {
16
+    if ( mouse->getButton( 1 ) ) {
17 17
         memory.setState( (SlopState*)new SlopStartDrag( mouse->getMousePos() ) );
18 18
     }
19 19
 }
@@ -32,12 +32,12 @@ void SlopStartDrag::update( SlopMemory& memory, double dt ) {
32 32
     char b = startPoint.x > mouse->getMousePos().x;
33 33
     char c = (a << 1) | b;
34 34
     switch ( c ) {
35
-        case 0: mouse->setCursor( "lr_angle" ); break;
36
-        case 1: mouse->setCursor( "ll_angle" ); break;
37
-        case 2: mouse->setCursor( "ur_angle" ); break;
38
-        case 3: mouse->setCursor( "ul_angle" ); break;
35
+        case 0: mouse->setCursor( XC_lr_angle ); break;
36
+        case 1: mouse->setCursor( XC_ll_angle ); break;
37
+        case 2: mouse->setCursor( XC_ur_angle ); break;
38
+        case 3: mouse->setCursor( XC_ul_angle ); break;
39 39
     }
40
-    if ( !mouse->getButton( BTN_LEFT ) ) {
40
+    if ( !mouse->getButton( 1 ) ) {
41 41
         memory.setState( (SlopState*)new SlopEndDrag() );
42 42
     }
43 43
 }

+ 0
- 55
src/wayland.cpp Целия файл

@@ -1,55 +0,0 @@
1
-#include "wayland.hpp"
2
-
3
-static void global_registry_handler(void *data, wl_registry* registry,
4
-                                    uint32_t id, const char* interface, uint32_t version) {
5
-    //std::cout << "Got register " << interface << " with id " << id << "\n";
6
-    if (std::string(interface) == "wl_compositor") {
7
-        wayland->compositor = (wl_compositor*)wl_registry_bind(registry, id, &wl_compositor_interface, 1);
8
-    } else if(std::string(interface) == "wl_shell") {
9
-        wayland->shell = (wl_shell*)wl_registry_bind(registry, id, &wl_shell_interface, 1);
10
-    } else if(std::string(interface) == "wl_shm") {
11
-        wayland->shm = (wl_shm*)wl_registry_bind(registry, id, &wl_shm_interface, 1);
12
-    } else if(std::string(interface) == "wl_seat") {
13
-        wayland->seat = (wl_seat*)wl_registry_bind(registry, id, &wl_seat_interface, 1);
14
-    } else if(std::string(interface) == "wl_output") {
15
-        wayland->output = (wl_output*)wl_registry_bind(registry, id, &wl_output_interface, 1);
16
-        //wl_list_insert(&output_list, &output->link);
17
-        //wl_output_add_listener(output->output, &output_listener, output);
18
-    }
19
-}
20
-
21
-static void global_registry_remover(void *data, struct wl_registry *registry, uint32_t id) {
22
-}
23
-
24
-static const struct wl_registry_listener registry_listener = {
25
-    global_registry_handler,
26
-    global_registry_remover
27
-};
28
-
29
-Wayland::Wayland() {
30
-    display = wl_display_connect(NULL);
31
-    if (!display) {
32
-        throw new std::runtime_error("Failed to connect to display.");
33
-    }
34
-}
35
-
36
-Wayland::~Wayland() {
37
-    wl_display_disconnect(display);
38
-}
39
-
40
-void Wayland::init() {
41
-    struct wl_registry *registry = wl_display_get_registry(display);
42
-    wl_registry_add_listener(registry, &registry_listener, NULL);
43
-
44
-    wl_display_dispatch(display);
45
-    wl_display_roundtrip(display);
46
-    if (!compositor) {
47
-        throw new std::runtime_error("Can't find compositor.");
48
-    }
49
-
50
-    egl_display = eglGetDisplay( display );
51
-    eglInitialize( egl_display, NULL, NULL );
52
-    if ( !egl_display ) {
53
-        throw new std::runtime_error("Failed to initialize EGL! (Thats the graphics stuff.)");
54
-    }
55
-}

+ 73
- 65
src/window.cpp Целия файл

@@ -1,80 +1,88 @@
1 1
 #include "window.hpp"
2 2
 
3
-static void shell_surface_ping (void *data, struct wl_shell_surface *shell_surface, uint32_t serial) {
4
-	wl_shell_surface_pong (shell_surface, serial);
5
-}
6
-static void shell_surface_configure (void *data, struct wl_shell_surface *shell_surface, uint32_t edges, int32_t width, int32_t height) {
7
-	Window* window = (Window*)data;
8
-	wl_egl_window_resize (window->egl_window, width, height, 0, 0);
9
-    window->camera = glm::ortho( 0.0f, (float)width, (float)height, 0.0f, -1.0f, 1.0f);
10
-    window->width = width;
11
-    window->height = height;
12
-    glViewport(0,0,width,height);
13
-    window->framebuffer->resize( width, height );
14
-}
15
-static void shell_surface_popup_done (void *data, struct wl_shell_surface *shell_surface) {
16
-	
17
-}
18
-static struct wl_shell_surface_listener shell_surface_listener = {&shell_surface_ping, &shell_surface_configure, &shell_surface_popup_done};
3
+SlopWindow::SlopWindow() {
4
+    XVisualInfo visual;
5
+    XMatchVisualInfo(x11->display, DefaultScreen(x11->display), 32, TrueColor, &visual);
6
+
7
+    XSetWindowAttributes attributes;
8
+    attributes.colormap = XCreateColormap( x11->display, x11->root, visual.visual, AllocNone );
9
+    attributes.background_pixmap = None;
10
+    attributes.border_pixel = 0;
11
+    // Disable window decorations.
12
+    attributes.override_redirect = True;
13
+    // Make sure we know when we've been successfully destroyed later!
14
+    //attributes.event_mask = StructureNotifyMask;
15
+    unsigned long valueMask = CWOverrideRedirect | CWColormap | CWBackPixmap | CWBorderPixel;
16
+
19 17
 
20
-Window::Window( unsigned int w, unsigned int h ) {
21
-    eglBindAPI (EGL_OPENGL_API);
22
-	EGLint attributes[] = {
23
-        EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
24
-		EGL_RED_SIZE, 8,
25
-		EGL_GREEN_SIZE, 8,
26
-		EGL_BLUE_SIZE, 8,
27
-		EGL_ALPHA_SIZE, 8,
28
-	EGL_NONE};
29
-    camera = glm::ortho( 0.0f, (float)w, (float)h, 0.0f, -1.0f, 1.0f);
30
-	EGLConfig config;
31
-	EGLint num_config;
32
-	eglChooseConfig (wayland->egl_display, attributes, &config, 1, &num_config);
33
-	egl_context = eglCreateContext (wayland->egl_display, config, EGL_NO_CONTEXT, NULL);
34
-	
35
-	surface = wl_compositor_create_surface (wayland->compositor);
36
-	shell_surface = wl_shell_get_shell_surface (wayland->shell, surface);
37
-	wl_shell_surface_add_listener (shell_surface, &shell_surface_listener, this);
38
-	wl_shell_surface_set_toplevel (shell_surface);
39
-	egl_window = wl_egl_window_create (surface, w, h);
40
-	egl_surface = eglCreateWindowSurface (wayland->egl_display, config, egl_window, NULL);
18
+    // Create the window
19
+    window = XCreateWindow( x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ),
20
+                            0, visual.depth, InputOutput,
21
+                            visual.visual, valueMask, &attributes );
22
+
23
+    if ( !window ) {
24
+        throw new std::runtime_error( "Couldn't create a GL window!" );
25
+    }
26
+
27
+	// Prep some hints for the window
28
+    static char title[] = "slop";
29
+    XWMHints* startup_state = XAllocWMHints();
30
+    startup_state->initial_state = NormalState;
31
+    startup_state->flags = StateHint;
32
+    XTextProperty textprop;
33
+    textprop.value = (unsigned char*)title;
34
+    textprop.encoding = XA_STRING;
35
+    textprop.format = 8;
36
+    textprop.nitems = strlen( title );
37
+    XSizeHints sizehints;
38
+    sizehints.x = 0;
39
+    sizehints.y = 0;
40
+    sizehints.width = WidthOfScreen( x11->screen );
41
+    sizehints.height = HeightOfScreen( x11->screen );
42
+    sizehints.flags = USPosition | USSize;
43
+    XClassHint classhints;
44
+    char name[] = "slop";
45
+    classhints.res_name = name;
46
+    classhints.res_class = name;
47
+	// Finally send it all over...
48
+    XSetClassHint( x11->display, window, &classhints );
49
+    XSetWMProperties( x11->display, window, &textprop, &textprop, NULL, 0, &sizehints, startup_state, NULL );
50
+    XFree( startup_state );
51
+
52
+    // Load up a opengl context
53
+    context = glXCreateContext( x11->display, &visual, 0, True );
54
+    if ( !context ) {
55
+		throw new std::runtime_error( "Failed to create an OpenGL context." );
56
+    }
57
+    setCurrent();
58
+    // Finally we grab some OpenGL 3.3 stuffs.
41 59
     if(ogl_LoadFunctions() == ogl_LOAD_FAILED)
42 60
     {
43 61
         throw new std::runtime_error("Failed to load function pointers for OpenGL.");
44 62
     }
45
-    setCurrent();
46
-    framebuffer = new Framebuffer( w, h );
63
+    framebuffer = new Framebuffer( WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
64
+	XMapWindow( x11->display, window );
65
+    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);
47 67
 }
48 68
 
49
-Window::~Window() {
69
+SlopWindow::~SlopWindow() {
50 70
     delete framebuffer;
51
-	eglDestroySurface (wayland->egl_display, egl_surface);
52
-	wl_egl_window_destroy (egl_window);
53
-	wl_surface_destroy (surface);
54
-	wl_shell_surface_destroy (shell_surface);
55
-	eglDestroyContext (wayland->egl_display, egl_context);
56
-}
57
-
58
-void Window::display() {
59
-	if (!eglSwapBuffers(wayland->egl_display, egl_surface)) {
60
-        throw new std::runtime_error("Failed to swap buffers.");
61
-    }
62
-}
63
-
64
-void Window::setFullScreen() {
65
-	wl_shell_surface_set_fullscreen(shell_surface, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, NULL);
66
-}
67
-
68
-void Window::setCurrent() {
69
-	if (!eglMakeCurrent (wayland->egl_display, egl_surface, egl_surface, egl_context)) {
70
-        throw new std::runtime_error("Failed set EGL's current surface for rendering.");
71
-    }
71
+    // Try to erase the window before destroying it.
72
+    glClearColor( 0, 0, 0, 0 );
73
+    glClear( GL_COLOR_BUFFER_BIT );
74
+    display();
75
+    glClearColor( 0, 0, 0, 0 );
76
+    glClear( GL_COLOR_BUFFER_BIT );
77
+    display();
78
+    XDestroyWindow( x11->display, window );
72 79
 }
73 80
 
74
-void Window::setTitle(std::string title) {
75
-	wl_shell_surface_set_title(shell_surface, title.c_str());
81
+void SlopWindow::display() {
82
+    glXSwapBuffers( x11->display, window );
83
+    glXWaitGL();
76 84
 }
77 85
 
78
-void Window::setClass(std::string title) {
79
-	wl_shell_surface_set_class(shell_surface, title.c_str());
86
+void SlopWindow::setCurrent() {
87
+    glXMakeCurrent( x11->display, window, context ) ;
80 88
 }

+ 11
- 15
src/window.hpp Целия файл

@@ -24,33 +24,29 @@
24 24
 #include <string>
25 25
 #include <exception>
26 26
 
27
+#include <iostream>
27 28
 #include "gl_core_3_3.h"
28
-#include "wayland.hpp"
29
-//#include <GL/glew.h>
30
-#include <wayland-egl.h>
31
-#include <EGL/egl.h>
32 29
 #include <GL/gl.h>
30
+#include <GL/glx.h>
33 31
 #include <glm/gtc/matrix_transform.hpp>
32
+#include <X11/Xutil.h>
33
+#include <X11/Xatom.h>
34 34
 
35
+#include "x.hpp"
35 36
 #include "framebuffer.hpp"
36 37
 
37
-class Window {
38
+// Gotta name it SlopWindow since Window and GLXWindow are taken... :/
39
+class SlopWindow {
38 40
 public:
39 41
     Framebuffer* framebuffer;
40 42
     int width, height;
41 43
     glm::mat4 camera;
42
-    Window( unsigned int w, unsigned int h );
43
-    ~Window();
44
-    void setFullScreen();
44
+    GLXWindow window;
45
+    GLXContext context;
46
+    SlopWindow();
47
+    ~SlopWindow();
45 48
     void setCurrent();
46
-    void setTitle( std::string title );
47
-    void setClass( std::string c );
48 49
     void display();
49
-    EGLContext egl_context;
50
-    struct wl_surface *surface;
51
-    struct wl_shell_surface *shell_surface;
52
-    struct wl_egl_window *egl_window;
53
-    EGLSurface egl_surface;
54 50
 };
55 51
 
56 52
 #endif // N_WINDOW_H_

+ 16
- 0
src/x.cpp Целия файл

@@ -0,0 +1,16 @@
1
+#include "x.hpp"
2
+
3
+X11::X11( std::string displayName ) {
4
+    // Initialize display
5
+    display = XOpenDisplay( displayName.c_str() );
6
+    if ( !display ) {
7
+        throw new std::runtime_error(std::string("Error: Failed to open X display: ") + displayName );
8
+    }
9
+    screen = ScreenOfDisplay( display, DefaultScreen( display ) );
10
+    visual = DefaultVisual( display, XScreenNumberOfScreen( screen ) );
11
+    root = DefaultRootWindow( display );
12
+}
13
+
14
+X11::~X11() {
15
+    XCloseDisplay( display );
16
+}

src/wayland.hpp → src/x.hpp Целия файл

@@ -1,4 +1,4 @@
1
-/* wayland.hpp: Interfaces with wayland to get keyboard, mouse, windows...
1
+/* x.hpp: initializes x11
2 2
  *
3 3
  * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
4 4
  *
@@ -18,39 +18,24 @@
18 18
  * along with Slop.  If not, see <http://www.gnu.org/licenses/>.
19 19
  */
20 20
 
21
-#ifndef N_WAYLAND_H_
22
-#define N_WAYLAND_H_
21
+#ifndef N_X_H_
22
+#define N_X_H_
23 23
 
24
-#include <wayland-client.h>
25
-#include <wayland-egl.h>
26
-#include <EGL/egl.h>
24
+#include <X11/Xlib.h>
27 25
 #include <string>
28
-#include <iostream>
29
-#include <vector>
30
-#include <glm/glm.hpp>
26
+#include <stdexcept>
31 27
 
32
-//#include <mutter/meta/compositor-mutter.h>
33
-
34
-#ifndef NULL
35
-#define NULL 0
36
-#endif
37
-
38
-class Wayland {
28
+class X11 {
29
+private:
39 30
 public:
40
-    Wayland();
41
-    ~Wayland();
42
-    void init();
43
-    wl_display* display;
44
-    wl_compositor* compositor;
45
-    wl_seat* seat;
46
-    wl_shell* shell;
47
-    wl_shm* shm;
48
-    wl_output* output;
49
-    EGLDisplay egl_display;
50
-    glm::vec2 mousepos;
51
-    std::vector<glm::vec4> getWindows();
31
+    X11( std::string displayName );
32
+    ~X11();
33
+    Display* display;
34
+    Visual* visual;
35
+    Screen* screen;
36
+    Window root;
52 37
 };
53 38
 
54
-extern Wayland* wayland;
39
+extern X11* x11;
55 40
 
56
-#endif // N_WAYLAND_H_
41
+#endif