Pārlūkot izejas kodu

Added detection for compositors

naelstrof 7 gadus atpakaļ
vecāks
revīzija
0bddcbc002
3 mainītis faili ar 21 papildinājumiem un 6 dzēšanām
  1. 11
    6
      src/slop.cpp
  2. 7
    0
      src/x.cpp
  3. 3
    0
      src/x.hpp

+ 11
- 6
src/slop.cpp Parādīt failu

@@ -42,14 +42,19 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled ) {
42 42
     // Set up x11 temporarily
43 43
     x11 = new X11(options->xdisplay);
44 44
     keyboard = new Keyboard( x11 );
45
-    // First we try to make an OpenGL enabled window
46 45
     bool success = false;
47 46
     SlopWindow* window;
48
-    try {
49
-        window = new SlopWindow();
50
-        success = true;
51
-    } catch (...) {
52
-        success = false;
47
+    // First we check if we have a compositor available
48
+	if ( x11->hasCompositor() ) {
49
+        // If we have a compositor, we try using OpenGL
50
+        try {
51
+            window = new SlopWindow();
52
+            success = true;
53
+        } catch (...) {
54
+            success = false;
55
+        }
56
+    } else {
57
+        std::cerr << "Failed to detect a compositor, OpenGL hardware-accelleration disabled...\n";
53 58
     }
54 59
     if ( !success ) {
55 60
         // If we fail, we launch the XShape version of slop.

+ 7
- 0
src/x.cpp Parādīt failu

@@ -1,5 +1,12 @@
1 1
 #include "x.hpp"
2 2
 
3
+bool X11::hasCompositor() {
4
+    std::stringstream prop_name;
5
+    prop_name << "_NET_WM_CM_S" << XScreenNumberOfScreen( screen );
6
+    Atom prop_atom = XInternAtom(display, prop_name.str().c_str(), False);
7
+    return XGetSelectionOwner(display, prop_atom) != None;
8
+}
9
+
3 10
 X11::X11( std::string displayName ) {
4 11
     // Initialize display
5 12
     display = XOpenDisplay( displayName.c_str() );

+ 3
- 0
src/x.hpp Parādīt failu

@@ -24,10 +24,13 @@
24 24
 #include <iostream>
25 25
 #include <X11/Xlib.h>
26 26
 #include <string>
27
+#include <sstream>
27 28
 #include <stdexcept>
29
+#include <X11/Xatom.h>
28 30
 
29 31
 class X11 {
30 32
 public:
33
+    bool hasCompositor();
31 34
     X11( std::string displayName );
32 35
     ~X11();
33 36
     Display* display;