Browse Source

Added detection for compositors

naelstrof 7 years ago
parent
commit
0bddcbc002
3 changed files with 21 additions and 6 deletions
  1. 11
    6
      src/slop.cpp
  2. 7
    0
      src/x.cpp
  3. 3
    0
      src/x.hpp

+ 11
- 6
src/slop.cpp View File

42
     // Set up x11 temporarily
42
     // Set up x11 temporarily
43
     x11 = new X11(options->xdisplay);
43
     x11 = new X11(options->xdisplay);
44
     keyboard = new Keyboard( x11 );
44
     keyboard = new Keyboard( x11 );
45
-    // First we try to make an OpenGL enabled window
46
     bool success = false;
45
     bool success = false;
47
     SlopWindow* window;
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
     if ( !success ) {
59
     if ( !success ) {
55
         // If we fail, we launch the XShape version of slop.
60
         // If we fail, we launch the XShape version of slop.

+ 7
- 0
src/x.cpp View File

1
 #include "x.hpp"
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
 X11::X11( std::string displayName ) {
10
 X11::X11( std::string displayName ) {
4
     // Initialize display
11
     // Initialize display
5
     display = XOpenDisplay( displayName.c_str() );
12
     display = XOpenDisplay( displayName.c_str() );

+ 3
- 0
src/x.hpp View File

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