Quellcode durchsuchen

Removed yet another dependency

naelstrof vor 7 Jahren
Ursprung
Commit
1ad1b4e23a
9 geänderte Dateien mit 48 neuen und 70 gelöschten Zeilen
  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 Datei anzeigen

@@ -1,5 +1,5 @@
1 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 4
 set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)")
5 5
 if ( NOT CMAKE_INSTALL_PREFIX )
@@ -9,9 +9,6 @@ endif()
9 9
 project(slop)
10 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 12
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
16 13
 
17 14
 include_directories("${PROJECT_BINARY_DIR}")
@@ -45,7 +42,6 @@ find_package(OpenGL REQUIRED)
45 42
 find_package(GLM REQUIRED)
46 43
 find_package(GLX REQUIRED)
47 44
 find_package(X11 REQUIRED)
48
-find_package(XExt REQUIRED) 
49 45
 
50 46
 include_directories(${X11_INCLUDE_DIR}
51 47
                     ${GLM_INCLUDE_DIR}

+ 0
- 26
modules/FindXExt.cmake Datei anzeigen

@@ -1,26 +0,0 @@
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 Datei anzeigen

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

+ 38
- 25
src/mouse.cpp Datei anzeigen

@@ -39,7 +39,7 @@ void Mouse::setCursor( int cursor ) {
39 39
                               xcursor, CurrentTime );
40 40
 }
41 41
 
42
-Mouse::Mouse(X11* x11, bool nodecorations ) {
42
+Mouse::Mouse(X11* x11, bool nodecorations, Window ignoreWindow ) {
43 43
     this->x11 = x11;
44 44
     currentCursor = XC_cross;
45 45
     xcursor = XCreateFontCursor( x11->display, XC_cross );
@@ -47,22 +47,9 @@ Mouse::Mouse(X11* x11, bool nodecorations ) {
47 47
     XGrabPointer( x11->display, x11->root, True,
48 48
                   PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
49 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 55
 Mouse::~Mouse() {
@@ -74,6 +61,13 @@ void Mouse::update() {
74 61
     while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
75 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 71
     while ( XCheckTypedEvent( x11->display, ButtonRelease, &event ) ) {
78 72
 		setButton( event.xbutton.button, 0 );
79 73
 	}
@@ -82,17 +76,36 @@ void Mouse::update() {
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 81
     Window root, parent;
88 82
     Window* children;
89 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 Datei anzeigen

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

+ 2
- 1
src/slop.cpp Datei anzeigen

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

+ 0
- 5
src/window.cpp Datei anzeigen

@@ -65,11 +65,6 @@ SlopWindow::SlopWindow() {
65 65
     glViewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
66 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 68
     // Last, we actually display the window <:o)
74 69
 	XMapWindow( x11->display, window );
75 70
 }

+ 0
- 1
src/window.hpp Datei anzeigen

@@ -31,7 +31,6 @@
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>
35 34
 
36 35
 #include "x.hpp"
37 36
 #include "framebuffer.hpp"

+ 1
- 1
src/windowhelper.cpp Datei anzeigen

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