Browse Source

Removed yet another dependency

naelstrof 7 years ago
parent
commit
1ad1b4e23a
9 changed files with 48 additions and 70 deletions
  1. 1
    5
      CMakeLists.txt
  2. 0
    26
      modules/FindXExt.cmake
  3. 1
    4
      src/main.cpp
  4. 38
    25
      src/mouse.cpp
  5. 5
    2
      src/mouse.hpp
  6. 2
    1
      src/slop.cpp
  7. 0
    5
      src/window.cpp
  8. 0
    1
      src/window.hpp
  9. 1
    1
      src/windowhelper.cpp

+ 1
- 5
CMakeLists.txt View File

1
 #Change this if you need to target a specific CMake version
1
 #Change this if you need to target a specific CMake version
2
-cmake_minimum_required(VERSION 3.1)
2
+cmake_minimum_required(VERSION 2.6)
3
 
3
 
4
 set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)")
4
 set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)")
5
 if ( NOT CMAKE_INSTALL_PREFIX )
5
 if ( NOT CMAKE_INSTALL_PREFIX )
9
 project(slop)
9
 project(slop)
10
 add_definitions(-DSLOP_VERSION="v5.3.21")
10
 add_definitions(-DSLOP_VERSION="v5.3.21")
11
 
11
 
12
-set(CMAKE_CXX_STANDARD 14)
13
-set(CMAKE_CXX_STANDARD_REQUIRED on)
14
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-missing-braces")
15
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
12
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
16
 
13
 
17
 include_directories("${PROJECT_BINARY_DIR}")
14
 include_directories("${PROJECT_BINARY_DIR}")
45
 find_package(GLM REQUIRED)
42
 find_package(GLM REQUIRED)
46
 find_package(GLX REQUIRED)
43
 find_package(GLX REQUIRED)
47
 find_package(X11 REQUIRED)
44
 find_package(X11 REQUIRED)
48
-find_package(XExt REQUIRED) 
49
 
45
 
50
 include_directories(${X11_INCLUDE_DIR}
46
 include_directories(${X11_INCLUDE_DIR}
51
                     ${GLM_INCLUDE_DIR}
47
                     ${GLM_INCLUDE_DIR}

+ 0
- 26
modules/FindXExt.cmake View File

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 )

+ 1
- 4
src/main.cpp View File

112
 	std::cout << "                                  --color is set to a transparent color.\n";
112
 	std::cout << "                                  --color is set to a transparent color.\n";
113
 	std::cout << "                                  (default=off)\n";
113
 	std::cout << "                                  (default=off)\n";
114
 	std::cout << "      --shader=STRING           Sets the shader to load and use from\n";
114
 	std::cout << "      --shader=STRING           Sets the shader to load and use from\n";
115
-	std::cout << "                                  ~/.config/slop/ or /usr/share/.\n";
115
+	std::cout << "                                  ~/.config/slop/\n";
116
 	std::cout << "                                  (default=`simple')\n";
116
 	std::cout << "                                  (default=`simple')\n";
117
 	std::cout << "  -f, --format=STRING           Set the output format string. Format specifiers\n";
117
 	std::cout << "  -f, --format=STRING           Set the output format string. Format specifiers\n";
118
 	std::cout << "                                  are %x, %y, %w, %h, %i, %g, and %c.\n";
118
 	std::cout << "                                  are %x, %y, %w, %h, %i, %g, and %c.\n";
130
 	std::cout << "    $ # Classic Windows XP selection.\n";
130
 	std::cout << "    $ # Classic Windows XP selection.\n";
131
 	std::cout << "    $ slop -l -c 0.3,0.4,0.6,0.4\n";
131
 	std::cout << "    $ slop -l -c 0.3,0.4,0.6,0.4\n";
132
 	std::cout << "\n";
132
 	std::cout << "\n";
133
-	std::cout << "    $ # Wiggle wiggle!\n";
134
-	std::cout << "    $ slop --opengl --shader wiggle\n";
135
-	std::cout << "\n";
136
 	std::cout << "    $ # Change output format to use safer parsing\n";
133
 	std::cout << "    $ # Change output format to use safer parsing\n";
137
 	std::cout << "    $ slopoutput=$(slop -f \"%x %y %w %h\")\n";
134
 	std::cout << "    $ slopoutput=$(slop -f \"%x %y %w %h\")\n";
138
 	std::cout << "    $ X=$(echo $slopoutput | awk '{print $1}')\n";
135
 	std::cout << "    $ X=$(echo $slopoutput | awk '{print $1}')\n";

+ 38
- 25
src/mouse.cpp View File

39
                               xcursor, CurrentTime );
39
                               xcursor, CurrentTime );
40
 }
40
 }
41
 
41
 
42
-Mouse::Mouse(X11* x11, bool nodecorations ) {
42
+Mouse::Mouse(X11* x11, bool nodecorations, Window ignoreWindow ) {
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 );
47
     XGrabPointer( x11->display, x11->root, True,
47
     XGrabPointer( x11->display, x11->root, True,
48
                   PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
48
                   PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
49
                   GrabModeAsync, GrabModeAsync, None, xcursor, CurrentTime );
49
                   GrabModeAsync, GrabModeAsync, None, xcursor, CurrentTime );
50
-
51
-    Window root;
52
-    int mx, my;
53
-    int wx, wy;
54
-    unsigned int 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 );
50
+    this->nodecorations = nodecorations;
51
+    this->ignoreWindow = ignoreWindow;
52
+    hoverWindow = findWindow(x11->root);
66
 }
53
 }
67
 
54
 
68
 Mouse::~Mouse() {
55
 Mouse::~Mouse() {
74
     while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
61
     while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
75
 		setButton( event.xbutton.button, 1 );
62
 		setButton( event.xbutton.button, 1 );
76
 	}
63
 	}
64
+    bool findNewWindow = false;
65
+    while ( XCheckTypedEvent( x11->display, MotionNotify, &event ) ) {
66
+        findNewWindow = true;
67
+	}
68
+    if ( findNewWindow ) {
69
+        hoverWindow = findWindow(x11->root);
70
+    }
77
     while ( XCheckTypedEvent( x11->display, ButtonRelease, &event ) ) {
71
     while ( XCheckTypedEvent( x11->display, ButtonRelease, &event ) ) {
78
 		setButton( event.xbutton.button, 0 );
72
 		setButton( event.xbutton.button, 0 );
79
 	}
73
 	}
82
 	}
76
 	}
83
 }
77
 }
84
 
78
 
85
-// This cheesy function makes sure we get all EnterNotify events on ALL the windows.
86
-void Mouse::selectAllInputs( Window win, bool nodecorations ) {
79
+Window Mouse::findWindow( Window foo ) {
80
+    glm::vec2 pos = getMousePos();
87
     Window root, parent;
81
     Window root, parent;
88
     Window* children;
82
     Window* children;
89
     unsigned int nchildren;
83
     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 );
84
+    Window selectedWindow;
85
+    XQueryTree( x11->display, foo, &root, &parent, &children, &nchildren );
86
+    // The children are ordered, so we traverse backwards.
87
+    if ( !children || nchildren <= 0 ) {
88
+        return foo;
89
+    }
90
+    for( int i=nchildren-1;i>=0;i-- ) {
91
+        if ( children[i] == ignoreWindow ) {
92
+            continue;
93
+        }
94
+        glm::vec4 rect = getWindowGeometry(children[i], false);
95
+        float a = pos.x - rect.x;
96
+        float b = pos.y - rect.y;
97
+        if ( a <= rect.z && a >= 0 ) {
98
+            if ( b <= rect.w && b >= 0 ) {
99
+                selectedWindow = children[i];
100
+                if ( !nodecorations ) {
101
+                    XFree(children);
102
+                    return selectedWindow;
103
+                } else {
104
+                    XFree(children);
105
+                    return findWindow( selectedWindow );
106
+                }
107
+            }
95
         }
108
         }
96
     }
109
     }
97
-    free( children );
110
+    return foo;
98
 }
111
 }

+ 5
- 2
src/mouse.hpp View File

27
 #include <iostream>
27
 #include <iostream>
28
 
28
 
29
 #include "x.hpp"
29
 #include "x.hpp"
30
+#include "windowhelper.hpp"
30
 
31
 
31
 class Mouse {
32
 class Mouse {
32
 private:
33
 private:
34
     std::vector<glm::ivec2> buttons;
35
     std::vector<glm::ivec2> buttons;
35
     Cursor xcursor;
36
     Cursor xcursor;
36
     int currentCursor;
37
     int currentCursor;
37
-    void selectAllInputs( Window win, bool nodecorations = false );
38
+    Window findWindow( Window foo );
39
+    bool nodecorations;
40
+    Window ignoreWindow;
38
 public:
41
 public:
39
 	Window hoverWindow;
42
 	Window hoverWindow;
40
 	void update();
43
 	void update();
41
-    Mouse( X11* x11, bool nodecorations );
44
+    Mouse( X11* x11, bool nodecorations, Window ignoreWindow );
42
     ~Mouse();
45
     ~Mouse();
43
     void setCursor( int cursor );
46
     void setCursor( int cursor );
44
     glm::vec2 getMousePos();
47
     glm::vec2 getMousePos();

+ 2
- 1
src/slop.cpp View File

78
     resource = new Resource();
78
     resource = new Resource();
79
     // Set up x11 temporarily
79
     // Set up x11 temporarily
80
     x11 = new X11(options->xdisplay);
80
     x11 = new X11(options->xdisplay);
81
-    mouse = new Mouse( x11, options->nodecorations );
82
     keyboard = new Keyboard( x11 );
81
     keyboard = new Keyboard( x11 );
83
 
82
 
84
     // Set up window with GL context
83
     // Set up window with GL context
85
     SlopWindow* window = new SlopWindow();
84
     SlopWindow* window = new SlopWindow();
86
 
85
 
86
+    mouse = new Mouse( x11, options->nodecorations, window->window );
87
+
87
     if ( options->shader != "textured" ) {
88
     if ( options->shader != "textured" ) {
88
         window->framebuffer->setShader( options->shader );
89
         window->framebuffer->setShader( options->shader );
89
     }
90
     }

+ 0
- 5
src/window.cpp View File

65
     glViewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
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);
66
     camera = glm::ortho( 0.0f, (float)WidthOfScreen( x11->screen ), (float)HeightOfScreen( x11->screen ), 0.0f, -1.0f, 1.0f);
67
 
67
 
68
-    // Make it so all input falls through
69
-    XRectangle rect;
70
-    rect.x = rect.y = rect.width = rect.height = 0; 
71
-    XShapeCombineRectangles( x11->display, window, ShapeInput, 0, 0, &rect, 1, ShapeSet, 0);
72
-
73
     // Last, we actually display the window <:o)
68
     // Last, we actually display the window <:o)
74
 	XMapWindow( x11->display, window );
69
 	XMapWindow( x11->display, window );
75
 }
70
 }

+ 0
- 1
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>
35
 
34
 
36
 #include "x.hpp"
35
 #include "x.hpp"
37
 #include "framebuffer.hpp"
36
 #include "framebuffer.hpp"

+ 1
- 1
src/windowhelper.cpp View File

1
 #include "windowhelper.hpp"
1
 #include "windowhelper.hpp"
2
 
2
 
3
-glm::vec4 getWindowGeometry( Window win, bool removeDecoration ) {
3
+glm::vec4 getWindowGeometry( Window win, bool removeDecoration) {
4
     XWindowAttributes attr;         
4
     XWindowAttributes attr;         
5
     XGetWindowAttributes( x11->display, win, &attr );
5
     XGetWindowAttributes( x11->display, win, &attr );
6
     unsigned int width = attr.width;           
6
     unsigned int width = attr.width;