Browse Source

improved namespace clashing

naelstrof 7 years ago
parent
commit
4db2dbc6fe

+ 0
- 1
CMakeLists.txt View File

32
                                     src/x.cpp
32
                                     src/x.cpp
33
                                     src/slopstates.cpp
33
                                     src/slopstates.cpp
34
                                     src/framebuffer.cpp
34
                                     src/framebuffer.cpp
35
-                                    src/windowhelper.cpp
36
                                     src/resource.cpp
35
                                     src/resource.cpp
37
                                     src/gl_core_3_3.c
36
                                     src/gl_core_3_3.c
38
                                     src/shader.cpp
37
                                     src/shader.cpp

+ 7
- 7
src/framebuffer.cpp View File

1
 #include "framebuffer.hpp"
1
 #include "framebuffer.hpp"
2
 
2
 
3
-Framebuffer::Framebuffer( int w, int h ) {
3
+slop::Framebuffer::Framebuffer( int w, int h ) {
4
     std::string vert = "#version 130\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 uvCoord;\nvoid main()\n{\nuvCoord = uv;\ngl_Position = vec4(position,0,1);\n}\n";
4
     std::string vert = "#version 130\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 uvCoord;\nvoid main()\n{\nuvCoord = uv;\ngl_Position = vec4(position,0,1);\n}\n";
5
     std::string frag = "#version 130\nuniform sampler2D texture;\nvarying vec2 uvCoord;\nout vec4 outColor;void main()\n{\noutColor = texture2D( texture, uvCoord );\n}\n";
5
     std::string frag = "#version 130\nuniform sampler2D texture;\nvarying vec2 uvCoord;\nout vec4 outColor;void main()\n{\noutColor = texture2D( texture, uvCoord );\n}\n";
6
     shader = new Shader( vert, frag, false );
6
     shader = new Shader( vert, frag, false );
38
     vertCount = verts.size();
38
     vertCount = verts.size();
39
 }
39
 }
40
 
40
 
41
-void Framebuffer::setShader( std::string name ) {
41
+void slop::Framebuffer::setShader( std::string name ) {
42
     delete shader;
42
     delete shader;
43
     shader = new Shader( name + ".vert", name + ".frag" );
43
     shader = new Shader( name + ".vert", name + ".frag" );
44
 }
44
 }
45
 
45
 
46
-Framebuffer::~Framebuffer() {
46
+slop::Framebuffer::~Framebuffer() {
47
     glDeleteTextures(1, &image);
47
     glDeleteTextures(1, &image);
48
     glDeleteFramebuffers(1,&fbuffer);
48
     glDeleteFramebuffers(1,&fbuffer);
49
     glDeleteBuffers(2,buffers);
49
     glDeleteBuffers(2,buffers);
50
     delete shader;
50
     delete shader;
51
 }
51
 }
52
 
52
 
53
-void Framebuffer::resize( int w, int h ) {
53
+void slop::Framebuffer::resize( int w, int h ) {
54
     // Regenerate the image
54
     // Regenerate the image
55
     glDeleteTextures(1, &image);
55
     glDeleteTextures(1, &image);
56
     glBindTexture(GL_TEXTURE_2D, image);
56
     glBindTexture(GL_TEXTURE_2D, image);
64
     glBindFramebuffer(GL_FRAMEBUFFER, 0);
64
     glBindFramebuffer(GL_FRAMEBUFFER, 0);
65
 }
65
 }
66
 
66
 
67
-void Framebuffer::bind() {
67
+void slop::Framebuffer::bind() {
68
     glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
68
     glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
69
 }
69
 }
70
 
70
 
71
-void Framebuffer::unbind() {
71
+void slop::Framebuffer::unbind() {
72
     glBindFramebuffer( GL_FRAMEBUFFER, 0 );
72
     glBindFramebuffer( GL_FRAMEBUFFER, 0 );
73
 }
73
 }
74
 
74
 
75
-void Framebuffer::draw(){
75
+void slop::Framebuffer::draw(){
76
     shader->bind();
76
     shader->bind();
77
     shader->setParameter( "texture", 0 );
77
     shader->setParameter( "texture", 0 );
78
     shader->setAttribute( "position", buffers[0], 2 );
78
     shader->setAttribute( "position", buffers[0], 2 );

+ 4
- 0
src/framebuffer.hpp View File

28
 
28
 
29
 #include "shader.hpp"
29
 #include "shader.hpp"
30
 
30
 
31
+namespace slop {
32
+
31
 class Framebuffer {
33
 class Framebuffer {
32
 private:
34
 private:
33
     unsigned int fbuffer;
35
     unsigned int fbuffer;
45
     void unbind();
47
     void unbind();
46
 };
48
 };
47
 
49
 
50
+}
51
+
48
 #endif
52
 #endif

+ 6
- 6
src/glrectangle.cpp View File

1
 #include "glrectangle.hpp"
1
 #include "glrectangle.hpp"
2
 
2
 
3
-GLRectangle::GLRectangle( glm::vec2 p1, glm::vec2 p2, float border, float padding, glm::vec4 color, bool highlight ) {
3
+slop::GLRectangle::GLRectangle( glm::vec2 p1, glm::vec2 p2, float border, float padding, glm::vec4 color, bool highlight ) {
4
     this->color = color;
4
     this->color = color;
5
     this->border = border;
5
     this->border = border;
6
     this->padding = padding;
6
     this->padding = padding;
27
     shader = new Shader( vert, frag, false );
27
     shader = new Shader( vert, frag, false );
28
 }
28
 }
29
 
29
 
30
-void GLRectangle::setPoints( glm::vec2 p1, glm::vec2 p2 ) {
30
+void slop::GLRectangle::setPoints( glm::vec2 p1, glm::vec2 p2 ) {
31
     // Find each corner of the rectangle
31
     // Find each corner of the rectangle
32
     ul = glm::vec2( glm::min( p1.x, p2.x ), glm::max( p1.y, p2.y ) ) ;
32
     ul = glm::vec2( glm::min( p1.x, p2.x ), glm::max( p1.y, p2.y ) ) ;
33
     bl = glm::vec2( glm::min( p1.x, p2.x ), glm::min( p1.y, p2.y ) ) ;
33
     bl = glm::vec2( glm::min( p1.x, p2.x ), glm::min( p1.y, p2.y ) ) ;
46
     generateBuffers();
46
     generateBuffers();
47
 }
47
 }
48
 
48
 
49
-void GLRectangle::generateBuffers() {
49
+void slop::GLRectangle::generateBuffers() {
50
     std::vector<glm::vec2> rectangle_verts;
50
     std::vector<glm::vec2> rectangle_verts;
51
     std::vector<glm::vec2> rectangle_uvs;
51
     std::vector<glm::vec2> rectangle_uvs;
52
     std::vector<glm::vec2> corner_verts;
52
     std::vector<glm::vec2> corner_verts;
208
     center_vertCount = center_verts.size();
208
     center_vertCount = center_verts.size();
209
 }
209
 }
210
 
210
 
211
-GLRectangle::~GLRectangle() {
211
+slop::GLRectangle::~GLRectangle() {
212
     delete shader;
212
     delete shader;
213
     glDeleteBuffers( 6, (GLuint*)&buffer );
213
     glDeleteBuffers( 6, (GLuint*)&buffer );
214
 }
214
 }
215
 
215
 
216
-void GLRectangle::draw( glm::mat4& matrix ) {
216
+void slop::GLRectangle::draw( glm::mat4& matrix ) {
217
     glEnable( GL_BLEND );
217
     glEnable( GL_BLEND );
218
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
218
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
219
     shader->bind();
219
     shader->bind();
241
     glDisable( GL_BLEND );
241
     glDisable( GL_BLEND );
242
 }
242
 }
243
 
243
 
244
-glm::vec4 GLRectangle::getRect() {
244
+glm::vec4 slop::GLRectangle::getRect() {
245
     return glm::vec4( bl.x, bl.y, ur.x-ul.x, ul.y-bl.y );
245
     return glm::vec4( bl.x, bl.y, ur.x-ul.x, ul.y-bl.y );
246
 }
246
 }

+ 4
- 0
src/glrectangle.hpp View File

30
 #include "shader.hpp"
30
 #include "shader.hpp"
31
 #include "rectangle.hpp"
31
 #include "rectangle.hpp"
32
 
32
 
33
+namespace slop {
34
+
33
 struct RectangleBuffer {
35
 struct RectangleBuffer {
34
     unsigned int corner_verts;
36
     unsigned int corner_verts;
35
     unsigned int corner_uvs;
37
     unsigned int corner_uvs;
63
     void draw(glm::mat4& matrix);
65
     void draw(glm::mat4& matrix);
64
 };
66
 };
65
 
67
 
68
+}
69
+
66
 #endif // N_RECTANGLE_H_
70
 #endif // N_RECTANGLE_H_

+ 5
- 5
src/keyboard.cpp View File

1
 #include "keyboard.hpp"
1
 #include "keyboard.hpp"
2
 
2
 
3
-bool Keyboard::getKey( KeySym key ) {
3
+bool slop::Keyboard::getKey( KeySym key ) {
4
     KeyCode keycode = XKeysymToKeycode( x11->display, key );
4
     KeyCode keycode = XKeysymToKeycode( x11->display, key );
5
     if ( keycode != 0 ) {
5
     if ( keycode != 0 ) {
6
         // Get the whole keyboard state
6
         // Get the whole keyboard state
13
     }
13
     }
14
 }
14
 }
15
 
15
 
16
-bool Keyboard::anyKeyDown() {
16
+bool slop::Keyboard::anyKeyDown() {
17
     return keyDown;
17
     return keyDown;
18
 }
18
 }
19
 
19
 
20
-void Keyboard::update() {
20
+void slop::Keyboard::update() {
21
     char keys[32];
21
     char keys[32];
22
     XQueryKeymap( x11->display, keys );
22
     XQueryKeymap( x11->display, keys );
23
     keyDown = false;
23
     keyDown = false;
38
     }
38
     }
39
 }
39
 }
40
 
40
 
41
-Keyboard::Keyboard( X11* x11 ) {
41
+slop::Keyboard::Keyboard( X11* x11 ) {
42
     this->x11 = x11;
42
     this->x11 = x11;
43
     int err = XGrabKeyboard( x11->display, x11->root, False, GrabModeAsync, GrabModeAsync, CurrentTime );
43
     int err = XGrabKeyboard( x11->display, x11->root, False, GrabModeAsync, GrabModeAsync, CurrentTime );
44
     if ( err != GrabSuccess ) {
44
     if ( err != GrabSuccess ) {
48
     keyDown = false;
48
     keyDown = false;
49
 }
49
 }
50
 
50
 
51
-Keyboard::~Keyboard() {
51
+slop::Keyboard::~Keyboard() {
52
     XUngrabKeyboard( x11->display, CurrentTime );
52
     XUngrabKeyboard( x11->display, CurrentTime );
53
 }
53
 }

+ 4
- 0
src/keyboard.hpp View File

23
 
23
 
24
 #include "x.hpp"
24
 #include "x.hpp"
25
 
25
 
26
+namespace slop {
27
+
26
 class Keyboard {
28
 class Keyboard {
27
 private:
29
 private:
28
     char deltaState[32];
30
     char deltaState[32];
38
 
40
 
39
 extern Keyboard* keyboard;
41
 extern Keyboard* keyboard;
40
 
42
 
43
+}
44
+
41
 #endif // N_KEYBOARD_H_
45
 #endif // N_KEYBOARD_H_

+ 2
- 0
src/main.cpp View File

23
 #include "slop.hpp"
23
 #include "slop.hpp"
24
 #include "options.hpp"
24
 #include "options.hpp"
25
 
25
 
26
+using namespace slop;
27
+
26
 SlopOptions* getOptions( Options& options ) {
28
 SlopOptions* getOptions( Options& options ) {
27
     SlopOptions* foo = new SlopOptions();
29
     SlopOptions* foo = new SlopOptions();
28
     options.getFloat("bordersize", 'b', foo->borderSize);
30
     options.getFloat("bordersize", 'b', foo->borderSize);

+ 8
- 8
src/mouse.cpp View File

1
 #include "mouse.hpp"
1
 #include "mouse.hpp"
2
 
2
 
3
-void Mouse::setButton( int button, int state ) {
3
+void slop::Mouse::setButton( int button, int state ) {
4
     for (unsigned int i=0;i<buttons.size();i++ ) {
4
     for (unsigned int i=0;i<buttons.size();i++ ) {
5
         if ( buttons[i].x == button ) {
5
         if ( buttons[i].x == button ) {
6
             buttons[i].y = state;
6
             buttons[i].y = state;
10
     buttons.push_back(glm::ivec2(button,state));
10
     buttons.push_back(glm::ivec2(button,state));
11
 }
11
 }
12
 
12
 
13
-int Mouse::getButton( int button ) {
13
+int slop::Mouse::getButton( int button ) {
14
     for (unsigned int i=0;i<buttons.size();i++ ) {
14
     for (unsigned int i=0;i<buttons.size();i++ ) {
15
         if ( buttons[i].x == button ) {
15
         if ( buttons[i].x == button ) {
16
             return buttons[i].y;
16
             return buttons[i].y;
19
     return 0;
19
     return 0;
20
 }
20
 }
21
 
21
 
22
-glm::vec2 Mouse::getMousePos() {
22
+glm::vec2 slop::Mouse::getMousePos() {
23
     Window root, child;
23
     Window root, child;
24
     int mx, my;
24
     int mx, my;
25
     int wx, wy;
25
     int wx, wy;
28
     return glm::vec2( mx, my );
28
     return glm::vec2( mx, my );
29
 }
29
 }
30
 
30
 
31
-void Mouse::setCursor( int cursor ) {
31
+void slop::Mouse::setCursor( int cursor ) {
32
     if ( currentCursor == cursor ) {
32
     if ( currentCursor == cursor ) {
33
         return;
33
         return;
34
     }
34
     }
39
                               xcursor, CurrentTime );
39
                               xcursor, CurrentTime );
40
 }
40
 }
41
 
41
 
42
-Mouse::Mouse(X11* x11, int nodecorations, Window ignoreWindow ) {
42
+slop::Mouse::Mouse(X11* x11, int 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 );
52
     hoverWindow = findWindow(x11->root);
52
     hoverWindow = findWindow(x11->root);
53
 }
53
 }
54
 
54
 
55
-Mouse::~Mouse() {
55
+slop::Mouse::~Mouse() {
56
 	XUngrabPointer( x11->display, CurrentTime );
56
 	XUngrabPointer( x11->display, CurrentTime );
57
 }
57
 }
58
 
58
 
59
-void Mouse::update() {
59
+void slop::Mouse::update() {
60
     XEvent event;
60
     XEvent event;
61
     while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
61
     while ( XCheckTypedEvent( x11->display, ButtonPress, &event ) ) {
62
 		setButton( event.xbutton.button, 1 );
62
 		setButton( event.xbutton.button, 1 );
76
 	}
76
 	}
77
 }
77
 }
78
 
78
 
79
-Window Mouse::findWindow( Window foo ) {
79
+Window slop::Mouse::findWindow( Window foo ) {
80
     glm::vec2 pos = getMousePos();
80
     glm::vec2 pos = getMousePos();
81
     Window root, parent;
81
     Window root, parent;
82
     Window* children;
82
     Window* children;

+ 4
- 1
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
+namespace slop {
31
 
32
 
32
 class Mouse {
33
 class Mouse {
33
 private:
34
 private:
51
 
52
 
52
 extern Mouse* mouse;
53
 extern Mouse* mouse;
53
 
54
 
55
+}
56
+
54
 #endif // N_MOUSE_H_
57
 #endif // N_MOUSE_H_

+ 5
- 5
src/rectangle.cpp View File

1
 #include "rectangle.hpp"
1
 #include "rectangle.hpp"
2
 
2
 
3
-Rectangle::Rectangle() {
3
+slop::Rectangle::Rectangle() {
4
 }
4
 }
5
-Rectangle::~Rectangle() {
5
+slop::Rectangle::~Rectangle() {
6
 }
6
 }
7
-void Rectangle::setPoints( glm::vec2 p1, glm::vec2 p2 ) {
7
+void slop::Rectangle::setPoints( glm::vec2 p1, glm::vec2 p2 ) {
8
 }
8
 }
9
-void Rectangle::draw(glm::mat4& matrix) {
9
+void slop::Rectangle::draw(glm::mat4& matrix) {
10
 }
10
 }
11
-glm::vec4 Rectangle::getRect() {
11
+glm::vec4 slop::Rectangle::getRect() {
12
     return glm::vec4();
12
     return glm::vec4();
13
 }
13
 }

+ 4
- 0
src/rectangle.hpp View File

23
 
23
 
24
 #include <glm/glm.hpp>
24
 #include <glm/glm.hpp>
25
 
25
 
26
+namespace slop {
27
+
26
 class Rectangle {
28
 class Rectangle {
27
 public:
29
 public:
28
     Rectangle();
30
     Rectangle();
32
     virtual void draw(glm::mat4& matrix);
34
     virtual void draw(glm::mat4& matrix);
33
 };
35
 };
34
 
36
 
37
+}
38
+
35
 #endif // N_RECTANGLE_H_
39
 #endif // N_RECTANGLE_H_

+ 3
- 3
src/resource.cpp View File

20
 
20
 
21
 #include "resource.hpp"
21
 #include "resource.hpp"
22
 
22
 
23
-Resource::Resource() {
23
+slop::Resource::Resource() {
24
     // Find the configuration directory.
24
     // Find the configuration directory.
25
     // usually ~/.config/slop and /usr/share/slop
25
     // usually ~/.config/slop and /usr/share/slop
26
     char* config = getenv( "XDG_CONFIG_HOME" );
26
     char* config = getenv( "XDG_CONFIG_HOME" );
34
     usrconfig += "/slop/";
34
     usrconfig += "/slop/";
35
 }
35
 }
36
 
36
 
37
-std::string Resource::getRealPath( std::string localpath ) {
37
+std::string slop::Resource::getRealPath( std::string localpath ) {
38
     if ( validatePath( usrconfig + localpath ) ) {
38
     if ( validatePath( usrconfig + localpath ) ) {
39
         return usrconfig + localpath;
39
         return usrconfig + localpath;
40
     }
40
     }
43
     return localpath;
43
     return localpath;
44
 }
44
 }
45
 
45
 
46
-bool Resource::validatePath( std::string path ) {
46
+bool slop::Resource::validatePath( std::string path ) {
47
     struct stat st;
47
     struct stat st;
48
     const char* dirname = path.c_str();
48
     const char* dirname = path.c_str();
49
     if ( stat( dirname, &st ) != 0 ) {
49
     if ( stat( dirname, &st ) != 0 ) {

+ 4
- 0
src/resource.hpp View File

33
 #include <sys/stat.h>
33
 #include <sys/stat.h>
34
 #include <pwd.h>
34
 #include <pwd.h>
35
 
35
 
36
+namespace slop {
37
+
36
 class Resource {
38
 class Resource {
37
 public:
39
 public:
38
     Resource();
40
     Resource();
44
 
46
 
45
 extern Resource* resource;
47
 extern Resource* resource;
46
 
48
 
49
+}
50
+
47
 #endif // IS_RESOURCE_H_
51
 #endif // IS_RESOURCE_H_

+ 14
- 14
src/shader.cpp View File

1
 #include "shader.hpp"
1
 #include "shader.hpp"
2
 
2
 
3
-Shader::Shader( std::string vert, std::string frag, bool file ) {
3
+slop::Shader::Shader( std::string vert, std::string frag, bool file ) {
4
     std::string vert_contents;
4
     std::string vert_contents;
5
     std::string frag_contents;
5
     std::string frag_contents;
6
     if ( file ) {
6
     if ( file ) {
73
     glUseProgram( 0 );
73
     glUseProgram( 0 );
74
 }
74
 }
75
 
75
 
76
-Shader::~Shader() {
76
+slop::Shader::~Shader() {
77
     glDeleteProgram( program );
77
     glDeleteProgram( program );
78
 }
78
 }
79
 
79
 
80
-unsigned int Shader::getProgram() {
80
+unsigned int slop::Shader::getProgram() {
81
     return program;
81
     return program;
82
 }
82
 }
83
 
83
 
84
-void Shader::bind() {
84
+void slop::Shader::bind() {
85
     glUseProgram( program );
85
     glUseProgram( program );
86
 }
86
 }
87
 
87
 
88
-int Shader::compile( unsigned int shader, std::string& error ) {
88
+int slop::Shader::compile( unsigned int shader, std::string& error ) {
89
     glCompileShader( shader );
89
     glCompileShader( shader );
90
 
90
 
91
     // Compiling the shader is the easy part, all this junk down here is for printing the error it might generate.
91
     // Compiling the shader is the easy part, all this junk down here is for printing the error it might generate.
103
     return 0;
103
     return 0;
104
 }
104
 }
105
 
105
 
106
-int Shader::link( unsigned int vertshader, unsigned int fragshader, std::string& error ) {
106
+int slop::Shader::link( unsigned int vertshader, unsigned int fragshader, std::string& error ) {
107
     glAttachShader( program, vertshader );
107
     glAttachShader( program, vertshader );
108
     glAttachShader( program, fragshader );
108
     glAttachShader( program, fragshader );
109
     glLinkProgram( program );
109
     glLinkProgram( program );
123
     return 0;
123
     return 0;
124
 }
124
 }
125
 
125
 
126
-unsigned int Shader::getUniformLocation( std::string name ) {
126
+unsigned int slop::Shader::getUniformLocation( std::string name ) {
127
     glUseProgram( program );
127
     glUseProgram( program );
128
     return glGetUniformLocation( program, name.c_str() );
128
     return glGetUniformLocation( program, name.c_str() );
129
 }
129
 }
130
 
130
 
131
-void Shader::setParameter( std::string name, int foo ) {
131
+void slop::Shader::setParameter( std::string name, int foo ) {
132
     glUniform1i( getUniformLocation( name ), foo );
132
     glUniform1i( getUniformLocation( name ), foo );
133
 }
133
 }
134
 
134
 
135
-void Shader::setParameter( std::string name, float foo ) {
135
+void slop::Shader::setParameter( std::string name, float foo ) {
136
     glUniform1f( getUniformLocation( name ), foo );
136
     glUniform1f( getUniformLocation( name ), foo );
137
 }
137
 }
138
 
138
 
139
-void Shader::setParameter( std::string name, glm::mat4& foo ) {
139
+void slop::Shader::setParameter( std::string name, glm::mat4& foo ) {
140
     glUniformMatrix4fv( getUniformLocation( name ), 1, GL_FALSE, glm::value_ptr( foo ) );
140
     glUniformMatrix4fv( getUniformLocation( name ), 1, GL_FALSE, glm::value_ptr( foo ) );
141
 }
141
 }
142
 
142
 
143
-void Shader::setParameter( std::string name, glm::vec4 foo ) {
143
+void slop::Shader::setParameter( std::string name, glm::vec4 foo ) {
144
     glUniform4f( getUniformLocation( name ), foo.x, foo.y, foo.z, foo.w );
144
     glUniform4f( getUniformLocation( name ), foo.x, foo.y, foo.z, foo.w );
145
 }
145
 }
146
 
146
 
147
-void Shader::setParameter( std::string name, glm::vec2 foo ) {
147
+void slop::Shader::setParameter( std::string name, glm::vec2 foo ) {
148
     glUniform2f( getUniformLocation( name ), foo.x, foo.y );
148
     glUniform2f( getUniformLocation( name ), foo.x, foo.y );
149
 }
149
 }
150
 
150
 
151
-void Shader::setAttribute( std::string name, unsigned int buffer, unsigned int stepsize ) {
151
+void slop::Shader::setAttribute( std::string name, unsigned int buffer, unsigned int stepsize ) {
152
     unsigned int a = glGetAttribLocation( program, name.c_str() );
152
     unsigned int a = glGetAttribLocation( program, name.c_str() );
153
     glEnableVertexAttribArray( a );
153
     glEnableVertexAttribArray( a );
154
     glBindBuffer( GL_ARRAY_BUFFER, buffer );
154
     glBindBuffer( GL_ARRAY_BUFFER, buffer );
156
     activeAttributes.push_back( a );
156
     activeAttributes.push_back( a );
157
 }
157
 }
158
 
158
 
159
-void Shader::unbind() {
159
+void slop::Shader::unbind() {
160
     for ( unsigned int i=0; i<activeAttributes.size(); i++ ) {
160
     for ( unsigned int i=0; i<activeAttributes.size(); i++ ) {
161
         glDisableVertexAttribArray( activeAttributes[i] );
161
         glDisableVertexAttribArray( activeAttributes[i] );
162
     }
162
     }

+ 4
- 0
src/shader.hpp View File

34
 
34
 
35
 #include "resource.hpp"
35
 #include "resource.hpp"
36
 
36
 
37
+namespace slop {
38
+
37
 class Shader {
39
 class Shader {
38
 public:
40
 public:
39
     Shader( std::string vert, std::string frag, bool file = true );
41
     Shader( std::string vert, std::string frag, bool file = true );
55
     unsigned int                program;
57
     unsigned int                program;
56
 };
58
 };
57
 
59
 
60
+}
61
+
58
 #endif // N_SHADER_H_
62
 #endif // N_SHADER_H_

+ 33
- 27
src/slop.cpp View File

13
 #include "xshaperectangle.hpp"
13
 #include "xshaperectangle.hpp"
14
 #include "slop.hpp"
14
 #include "slop.hpp"
15
 
15
 
16
+namespace slop {
17
+
16
 X11* x11;
18
 X11* x11;
17
 Mouse* mouse;
19
 Mouse* mouse;
18
 Keyboard* keyboard;
20
 Keyboard* keyboard;
19
 Resource* resource;
21
 Resource* resource;
20
 
22
 
23
+SlopSelection GLSlopSelect( slop::SlopOptions* options, bool* cancelled, slop::SlopWindow* window );
24
+SlopSelection XShapeSlopSelect( slop::SlopOptions* options, bool* cancelled);
25
+
26
+}
27
+
28
+using namespace slop;
29
+
21
 // Defaults!
30
 // Defaults!
22
-SlopOptions::SlopOptions() {
31
+slop::SlopOptions::SlopOptions() {
23
     borderSize = 1;
32
     borderSize = 1;
24
     nokeyboard = false;
33
     nokeyboard = false;
25
     nodecorations = false;
34
     nodecorations = false;
34
     a = 1;
43
     a = 1;
35
 }
44
 }
36
 
45
 
37
-SlopSelection::SlopSelection( float x, float y, float w, float h, int id ) {
46
+slop::SlopSelection::SlopSelection( float x, float y, float w, float h, int id ) {
38
     this->x = x;
47
     this->x = x;
39
     this->y = y;
48
     this->y = y;
40
     this->w = w;
49
     this->w = w;
42
     this->id = id;
51
     this->id = id;
43
 }
52
 }
44
 
53
 
45
-SlopSelection GLSlopSelect( SlopOptions* options, bool* cancelled, SlopWindow* window );
46
-SlopSelection XShapeSlopSelect( SlopOptions* options, bool* cancelled);
47
-
48
-SlopSelection SlopSelect( SlopOptions* options, bool* cancelled, bool quiet) {
49
-    SlopSelection returnval(0,0,0,0,0);
54
+slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options, bool* cancelled, bool quiet) {
55
+    slop::SlopSelection returnval(0,0,0,0,0);
50
     bool deleteOptions = false;
56
     bool deleteOptions = false;
51
     if ( !options ) {
57
     if ( !options ) {
52
         deleteOptions = true;
58
         deleteOptions = true;
53
-        options = new SlopOptions();
59
+        options = new slop::SlopOptions();
54
     }
60
     }
55
     resource = new Resource();
61
     resource = new Resource();
56
     // Set up x11 temporarily
62
     // Set up x11 temporarily
81
                 std::cerr << errorstring;
87
                 std::cerr << errorstring;
82
             }
88
             }
83
         }
89
         }
84
-        returnval = XShapeSlopSelect( options, cancelled );
90
+        returnval = slop::XShapeSlopSelect( options, cancelled );
85
     } else {
91
     } else {
86
-        returnval = GLSlopSelect( options, cancelled, window );
92
+        returnval = slop::GLSlopSelect( options, cancelled, window );
87
     }
93
     }
88
     delete x11;
94
     delete x11;
89
-    delete resource;
95
+    delete slop::resource;
90
     if ( deleteOptions ) {
96
     if ( deleteOptions ) {
91
         delete options;
97
         delete options;
92
     }
98
     }
93
     return returnval;
99
     return returnval;
94
 }
100
 }
95
 
101
 
96
-SlopSelection XShapeSlopSelect( SlopOptions* options, bool* cancelled ) {
102
+slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* cancelled ) {
97
     // Init our little state machine, memory is a tad of a misnomer
103
     // Init our little state machine, memory is a tad of a misnomer
98
-    SlopMemory memory( options, new XShapeRectangle(glm::vec2(0,0), glm::vec2(0,0), options->borderSize, options->padding, glm::vec4( options->r, options->g, options->b, options->a ), options->highlight) );
99
-    mouse = new Mouse( x11, options->nodecorations, ((XShapeRectangle*)memory.rectangle)->window );
104
+    slop::SlopMemory memory( options, new XShapeRectangle(glm::vec2(0,0), glm::vec2(0,0), options->borderSize, options->padding, glm::vec4( options->r, options->g, options->b, options->a ), options->highlight) );
105
+    slop::mouse = new slop::Mouse( x11, options->nodecorations, ((XShapeRectangle*)memory.rectangle)->window );
100
 
106
 
101
     // We have no GL context, so the matrix is useless...
107
     // We have no GL context, so the matrix is useless...
102
     glm::mat4 fake;
108
     glm::mat4 fake;
103
     // This is where we'll run through all of our stuffs
109
     // This is where we'll run through all of our stuffs
104
     while( memory.running ) {
110
     while( memory.running ) {
105
-        mouse->update();
106
-        keyboard->update();
111
+        slop::mouse->update();
112
+        slop::keyboard->update();
107
         // We move our statemachine forward.
113
         // We move our statemachine forward.
108
         memory.update( 1 );
114
         memory.update( 1 );
109
 
115
 
116
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
122
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
117
 
123
 
118
         // Then we draw the framebuffer to the screen
124
         // Then we draw the framebuffer to the screen
119
-        if ( (keyboard->anyKeyDown() && !options->nokeyboard) || mouse->getButton( 3 ) ) {
125
+        if ( (slop::keyboard->anyKeyDown() && !options->nokeyboard) || slop::mouse->getButton( 3 ) ) {
120
             memory.running = false;
126
             memory.running = false;
121
             if ( cancelled ) {
127
             if ( cancelled ) {
122
                 *cancelled = true;
128
                 *cancelled = true;
132
     // Lets now clear both front and back buffers before closing.
138
     // Lets now clear both front and back buffers before closing.
133
     // hopefully it'll be completely transparent while closing!
139
     // hopefully it'll be completely transparent while closing!
134
     // Then we clean up.
140
     // Then we clean up.
135
-    delete mouse;
141
+    delete slop::mouse;
136
     // Finally return the data.
142
     // Finally return the data.
137
-    return SlopSelection( output.x, output.y, output.z, output.w, memory.selectedWindow );
143
+    return slop::SlopSelection( output.x, output.y, output.z, output.w, memory.selectedWindow );
138
 }
144
 }
139
 
145
 
140
-SlopSelection GLSlopSelect( SlopOptions* options, bool* cancelled, SlopWindow* window ) {
141
-    mouse = new Mouse( x11, options->nodecorations, window->window );
146
+slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancelled, SlopWindow* window ) {
147
+    slop::mouse = new slop::Mouse( x11, options->nodecorations, window->window );
142
 
148
 
143
     if ( options->shader != "textured" ) {
149
     if ( options->shader != "textured" ) {
144
         window->framebuffer->setShader( options->shader );
150
         window->framebuffer->setShader( options->shader );
145
     }
151
     }
146
 
152
 
147
     // Init our little state machine, memory is a tad of a misnomer
153
     // Init our little state machine, memory is a tad of a misnomer
148
-    SlopMemory memory( options, new GLRectangle(glm::vec2(0,0), glm::vec2(0,0), options->borderSize, options->padding, glm::vec4( options->r, options->g, options->b, options->a ), options->highlight) );
154
+    slop::SlopMemory memory( options, new GLRectangle(glm::vec2(0,0), glm::vec2(0,0), options->borderSize, options->padding, glm::vec4( options->r, options->g, options->b, options->a ), options->highlight) );
149
 
155
 
150
     // This is where we'll run through all of our stuffs
156
     // This is where we'll run through all of our stuffs
151
     while( memory.running ) {
157
     while( memory.running ) {
152
-        mouse->update();
153
-        keyboard->update();
158
+        slop::mouse->update();
159
+        slop::keyboard->update();
154
         // We move our statemachine forward.
160
         // We move our statemachine forward.
155
         memory.update( 1 );
161
         memory.update( 1 );
156
 
162
 
168
         if ( err != GL_NO_ERROR ) {
174
         if ( err != GL_NO_ERROR ) {
169
             throw err;
175
             throw err;
170
         }
176
         }
171
-        if ( (keyboard->anyKeyDown() && !options->nokeyboard) || mouse->getButton( 3 ) ) {
177
+        if ( (slop::keyboard->anyKeyDown() && !options->nokeyboard) || slop::mouse->getButton( 3 ) ) {
172
             memory.running = false;
178
             memory.running = false;
173
             if ( cancelled ) {
179
             if ( cancelled ) {
174
                 *cancelled = true;
180
                 *cancelled = true;
190
     window->display();
196
     window->display();
191
     // Then we clean up.
197
     // Then we clean up.
192
     delete window;
198
     delete window;
193
-    delete mouse;
199
+    delete slop::mouse;
194
     // Finally return the data.
200
     // Finally return the data.
195
-    return SlopSelection( output.x, output.y, output.z, output.w, memory.selectedWindow );
201
+    return slop::SlopSelection( output.x, output.y, output.z, output.w, memory.selectedWindow );
196
 }
202
 }

+ 4
- 0
src/slop.hpp View File

23
 
23
 
24
 #include <string>
24
 #include <string>
25
 
25
 
26
+namespace slop {
27
+
26
 class SlopOptions {
28
 class SlopOptions {
27
 public:
29
 public:
28
     SlopOptions();
30
     SlopOptions();
53
 
55
 
54
 SlopSelection SlopSelect( SlopOptions* options = NULL, bool* cancelled = NULL, bool quiet = false );
56
 SlopSelection SlopSelect( SlopOptions* options = NULL, bool* cancelled = NULL, bool quiet = false );
55
 
57
 
58
+}
59
+
56
 #endif // N_SLOP_H_
60
 #endif // N_SLOP_H_

+ 20
- 18
src/slopstates.cpp View File

1
 #include "slopstates.hpp"
1
 #include "slopstates.hpp"
2
 
2
 
3
-SlopMemory::SlopMemory( SlopOptions* options, Rectangle* rect ) {
3
+using namespace slop;
4
+
5
+slop::SlopMemory::SlopMemory( SlopOptions* options, Rectangle* rect ) {
4
     running = true;
6
     running = true;
5
     state = (SlopState*)new SlopStart();
7
     state = (SlopState*)new SlopStart();
6
     nextState = NULL;
8
     nextState = NULL;
11
     state->onEnter( *this );
13
     state->onEnter( *this );
12
 }
14
 }
13
 
15
 
14
-SlopMemory::~SlopMemory() {
16
+slop::SlopMemory::~SlopMemory() {
15
     delete state;
17
     delete state;
16
     if ( nextState ) {
18
     if ( nextState ) {
17
         delete nextState;
19
         delete nextState;
19
     delete rectangle;
21
     delete rectangle;
20
 }
22
 }
21
 
23
 
22
-void SlopMemory::update( double dt ) {
24
+void slop::SlopMemory::update( double dt ) {
23
     state->update( *this, dt );
25
     state->update( *this, dt );
24
     if ( nextState ) {
26
     if ( nextState ) {
25
         state->onExit( *this );
27
         state->onExit( *this );
30
     }
32
     }
31
 }
33
 }
32
 
34
 
33
-void SlopMemory::setState( SlopState* state ) {
35
+void slop::SlopMemory::setState( SlopState* state ) {
34
     if ( nextState ) {
36
     if ( nextState ) {
35
         delete nextState;
37
         delete nextState;
36
     }
38
     }
37
     nextState = state;
39
     nextState = state;
38
 }
40
 }
39
 
41
 
40
-void SlopMemory::draw( glm::mat4& matrix ) {
42
+void slop::SlopMemory::draw( glm::mat4& matrix ) {
41
     state->draw( *this, matrix );
43
     state->draw( *this, matrix );
42
 }
44
 }
43
 
45
 
44
 
46
 
45
-SlopState::~SlopState() {
47
+slop::SlopState::~SlopState() {
46
 }
48
 }
47
-void SlopState::onEnter( SlopMemory& memory ) {
49
+void slop::SlopState::onEnter( SlopMemory& memory ) {
48
 }
50
 }
49
-void SlopState::onExit( SlopMemory& memory ) {
51
+void slop::SlopState::onExit( SlopMemory& memory ) {
50
 }
52
 }
51
-void SlopState::update( SlopMemory& memory, double dt ) {
53
+void slop::SlopState::update( SlopMemory& memory, double dt ) {
52
 }
54
 }
53
-void SlopState::draw( SlopMemory& memory, glm::mat4 matrix ) {
55
+void slop::SlopState::draw( SlopMemory& memory, glm::mat4 matrix ) {
54
 }
56
 }
55
 
57
 
56
-void SlopStart::onEnter( SlopMemory& memory ) {
58
+void slop::SlopStart::onEnter( SlopMemory& memory ) {
57
     setStartPos = false;
59
     setStartPos = false;
58
 }
60
 }
59
-void SlopStart::update( SlopMemory& memory, double dt ) {
61
+void slop::SlopStart::update( SlopMemory& memory, double dt ) {
60
     if ( mouse->getButton( 1 ) && !setStartPos ) {
62
     if ( mouse->getButton( 1 ) && !setStartPos ) {
61
         startPos = mouse->getMousePos();
63
         startPos = mouse->getMousePos();
62
         setStartPos = true;
64
         setStartPos = true;
74
     }
76
     }
75
 }
77
 }
76
 
78
 
77
-void SlopStart::draw( SlopMemory& memory, glm::mat4 matrix ) {
79
+void slop::SlopStart::draw( SlopMemory& memory, glm::mat4 matrix ) {
78
     if ( memory.tolerance > 0 ) {
80
     if ( memory.tolerance > 0 ) {
79
         memory.rectangle->draw( matrix );
81
         memory.rectangle->draw( matrix );
80
     }
82
     }
81
 }
83
 }
82
 
84
 
83
-SlopStartDrag::SlopStartDrag( glm::vec2 point ) {
85
+slop::SlopStartDrag::SlopStartDrag( glm::vec2 point ) {
84
     startPoint = point;
86
     startPoint = point;
85
 }
87
 }
86
 
88
 
87
-void SlopStartDrag::onEnter( SlopMemory& memory ) {
89
+void slop::SlopStartDrag::onEnter( SlopMemory& memory ) {
88
     memory.rectangle->setPoints(startPoint, startPoint);
90
     memory.rectangle->setPoints(startPoint, startPoint);
89
 }
91
 }
90
 
92
 
91
-void SlopStartDrag::update( SlopMemory& memory, double dt ) {
93
+void slop::SlopStartDrag::update( SlopMemory& memory, double dt ) {
92
     char a = startPoint.y > mouse->getMousePos().y;
94
     char a = startPoint.y > mouse->getMousePos().y;
93
     char b = startPoint.x > mouse->getMousePos().x;
95
     char b = startPoint.x > mouse->getMousePos().x;
94
     char c = (a << 1) | b;
96
     char c = (a << 1) | b;
111
     }
113
     }
112
 }
114
 }
113
 
115
 
114
-void SlopStartDrag::draw( SlopMemory& memory, glm::mat4 matrix ) {
116
+void slop::SlopStartDrag::draw( SlopMemory& memory, glm::mat4 matrix ) {
115
     memory.rectangle->draw( matrix );
117
     memory.rectangle->draw( matrix );
116
 }
118
 }
117
 
119
 
118
-void SlopEndDrag::onEnter( SlopMemory& memory ) {
120
+void slop::SlopEndDrag::onEnter( SlopMemory& memory ) {
119
     memory.running = false;
121
     memory.running = false;
120
 }
122
 }

+ 4
- 5
src/slopstates.hpp View File

22
 #define N_SLOPSTATES_H_
22
 #define N_SLOPSTATES_H_
23
 
23
 
24
 #include "mouse.hpp"
24
 #include "mouse.hpp"
25
-#include "windowhelper.hpp"
26
 #include "slop.hpp"
25
 #include "slop.hpp"
27
 
26
 
28
-#ifdef SLOP_LEGACY_MODE
29
-#include "xshaperectangle.hpp"
30
-#else
31
 #include "rectangle.hpp"
27
 #include "rectangle.hpp"
32
-#endif
28
+
29
+namespace slop {
33
 
30
 
34
 class SlopMemory;
31
 class SlopMemory;
35
 class SlopOptions;
32
 class SlopOptions;
85
     void draw( glm::mat4& matrix );
82
     void draw( glm::mat4& matrix );
86
 };
83
 };
87
 
84
 
85
+}
86
+
88
 #endif // N_SLOPSTATES_H_
87
 #endif // N_SLOPSTATES_H_

+ 7
- 5
src/window.cpp View File

1
 #include "window.hpp"
1
 #include "window.hpp"
2
 
2
 
3
-SlopWindow::SlopWindow() {
3
+using namespace slop;
4
+
5
+slop::SlopWindow::SlopWindow() {
4
     XVisualInfo visual;
6
     XVisualInfo visual;
5
     XMatchVisualInfo(x11->display, DefaultScreen(x11->display), 32, TrueColor, &visual);
7
     XMatchVisualInfo(x11->display, DefaultScreen(x11->display), 32, TrueColor, &visual);
6
 
8
 
16
 
18
 
17
 
19
 
18
     // Create the window
20
     // Create the window
19
-    window = XCreateWindow( x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ),
21
+    window = XCreateWindow( slop::x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ),
20
                             0, visual.depth, InputOutput,
22
                             0, visual.depth, InputOutput,
21
                             visual.visual, valueMask, &attributes );
23
                             visual.visual, valueMask, &attributes );
22
 
24
 
69
 	XMapWindow( x11->display, window );
71
 	XMapWindow( x11->display, window );
70
 }
72
 }
71
 
73
 
72
-SlopWindow::~SlopWindow() {
74
+slop::SlopWindow::~SlopWindow() {
73
     delete framebuffer;
75
     delete framebuffer;
74
     // Try to erase the window before destroying it.
76
     // Try to erase the window before destroying it.
75
     glClearColor( 0, 0, 0, 0 );
77
     glClearColor( 0, 0, 0, 0 );
82
     XDestroyWindow( x11->display, window );
84
     XDestroyWindow( x11->display, window );
83
 }
85
 }
84
 
86
 
85
-void SlopWindow::display() {
87
+void slop::SlopWindow::display() {
86
     glXSwapBuffers( x11->display, window );
88
     glXSwapBuffers( x11->display, window );
87
     glXWaitGL();
89
     glXWaitGL();
88
 }
90
 }
89
 
91
 
90
-void SlopWindow::setCurrent() {
92
+void slop::SlopWindow::setCurrent() {
91
     glXMakeCurrent( x11->display, window, context ) ;
93
     glXMakeCurrent( x11->display, window, context ) ;
92
 }
94
 }

+ 4
- 1
src/window.hpp View File

35
 #include "x.hpp"
35
 #include "x.hpp"
36
 #include "framebuffer.hpp"
36
 #include "framebuffer.hpp"
37
 
37
 
38
-// Gotta name it SlopWindow since Window and GLXWindow are taken... :/
38
+namespace slop {
39
+
39
 class SlopWindow {
40
 class SlopWindow {
40
 public:
41
 public:
41
     Framebuffer* framebuffer;
42
     Framebuffer* framebuffer;
49
     void display();
50
     void display();
50
 };
51
 };
51
 
52
 
53
+}
54
+
52
 #endif // N_WINDOW_H_
55
 #endif // N_WINDOW_H_

+ 0
- 36
src/windowhelper.cpp View File

1
-#include "windowhelper.hpp"
2
-
3
-glm::vec4 getWindowGeometry( Window win, bool removeDecoration) {
4
-    XWindowAttributes attr;         
5
-    XGetWindowAttributes( x11->display, win, &attr );
6
-    unsigned int width = attr.width;           
7
-    unsigned int height = attr.height;         
8
-    unsigned int border = attr.border_width;   
9
-    int x, y;
10
-    Window junk;
11
-    XTranslateCoordinates( x11->display, win, attr.root, -attr.border_width, -attr.border_width, &x, &y, &junk );
12
-    if ( !removeDecoration ) {
13
-        width += border*2;
14
-        height += border*2;
15
-        return glm::vec4( x, y, width, height );
16
-    }
17
-    // This is required to be defined by the window manager, so we can assume it exists.
18
-    Atom actual_type;
19
-    int actual_format;
20
-    unsigned long nitems, bytes_after;
21
-    unsigned char *data;
22
-    int result = XGetWindowProperty(x11->display, win,
23
-                                    XInternAtom(x11->display, "_NET_FRAME_EXTENTS", true),
24
-                                    0, 4, False, AnyPropertyType, 
25
-                                    &actual_type, &actual_format, &nitems, &bytes_after, &data);
26
-    if ( result == Success ) {
27
-        // Make sure we got the data we expect...
28
-        if ((nitems == 4) && (bytes_after == 0)) {
29
-            x += (int)data[0];
30
-            width -= (int)data[1];
31
-            y += (int)data[2];
32
-            height -= (int)data[3];
33
-        }
34
-    }
35
-    return glm::vec4( x, y, width, height );
36
-}

+ 0
- 31
src/windowhelper.hpp View File

1
-/* windowhelper.hpp: Analyzes input windows to determine decorations and such.
2
- *
3
- * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
4
- *
5
- * This file is part of Slop.
6
- *
7
- * Slop is free software: you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation, either version 3 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * Slop is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with Slop.  If not, see <http://www.gnu.org/licenses/>.
19
- */
20
-
21
-#ifndef N_WINDOWHELPER_H_
22
-#define N_WINDOWHELPER_H_
23
-
24
-#include <glm/glm.hpp>
25
-#include <X11/Xlib.h>
26
-
27
-#include "x.hpp"
28
-
29
-glm::vec4 getWindowGeometry( Window win, bool removeDecoration );
30
-
31
-#endif

+ 37
- 0
src/x.cpp View File

1
 #include "x.hpp"
1
 #include "x.hpp"
2
 
2
 
3
+using namespace slop;
4
+
5
+glm::vec4 slop::getWindowGeometry( Window win, bool removeDecoration) {
6
+    XWindowAttributes attr;         
7
+    XGetWindowAttributes( x11->display, win, &attr );
8
+    unsigned int width = attr.width;           
9
+    unsigned int height = attr.height;         
10
+    unsigned int border = attr.border_width;   
11
+    int x, y;
12
+    Window junk;
13
+    XTranslateCoordinates( x11->display, win, attr.root, -attr.border_width, -attr.border_width, &x, &y, &junk );
14
+    if ( !removeDecoration ) {
15
+        width += border*2;
16
+        height += border*2;
17
+        return glm::vec4( x, y, width, height );
18
+    }
19
+    // This is required to be defined by the window manager, so we can assume it exists.
20
+    Atom actual_type;
21
+    int actual_format;
22
+    unsigned long nitems, bytes_after;
23
+    unsigned char *data;
24
+    int result = XGetWindowProperty(x11->display, win,
25
+                                    XInternAtom(x11->display, "_NET_FRAME_EXTENTS", true),
26
+                                    0, 4, False, AnyPropertyType, 
27
+                                    &actual_type, &actual_format, &nitems, &bytes_after, &data);
28
+    if ( result == Success ) {
29
+        // Make sure we got the data we expect...
30
+        if ((nitems == 4) && (bytes_after == 0)) {
31
+            x += (int)data[0];
32
+            width -= (int)data[1];
33
+            y += (int)data[2];
34
+            height -= (int)data[3];
35
+        }
36
+    }
37
+    return glm::vec4( x, y, width, height );
38
+}
39
+
3
 bool X11::hasCompositor() {
40
 bool X11::hasCompositor() {
4
     std::stringstream prop_name;
41
     std::stringstream prop_name;
5
     prop_name << "_NET_WM_CM_S" << XScreenNumberOfScreen( screen );
42
     prop_name << "_NET_WM_CM_S" << XScreenNumberOfScreen( screen );

+ 7
- 0
src/x.hpp View File

27
 #include <sstream>
27
 #include <sstream>
28
 #include <stdexcept>
28
 #include <stdexcept>
29
 #include <X11/Xatom.h>
29
 #include <X11/Xatom.h>
30
+#include <glm/glm.hpp>
31
+
32
+namespace slop {
33
+
34
+glm::vec4 getWindowGeometry( Window win, bool removeDecoration );
30
 
35
 
31
 class X11 {
36
 class X11 {
32
 public:
37
 public:
41
 
46
 
42
 extern X11* x11;
47
 extern X11* x11;
43
 
48
 
49
+}
50
+
44
 #endif
51
 #endif

+ 8
- 8
src/xshaperectangle.cpp View File

1
 #include "xshaperectangle.hpp"
1
 #include "xshaperectangle.hpp"
2
 
2
 
3
-XShapeRectangle::XShapeRectangle( glm::vec2 p1, glm::vec2 p2, float border, float padding, glm::vec4 color, bool highlight ) {
3
+slop::XShapeRectangle::XShapeRectangle( glm::vec2 p1, glm::vec2 p2, float border, float padding, glm::vec4 color, bool highlight ) {
4
     this->color = convertColor( color );
4
     this->color = convertColor( color );
5
     this->border = border;
5
     this->border = border;
6
     this->padding = padding;
6
     this->padding = padding;
51
     createdWindow = false;
51
     createdWindow = false;
52
 }
52
 }
53
 
53
 
54
-void XShapeRectangle::createWindow() {
54
+void slop::XShapeRectangle::createWindow() {
55
     if ( createdWindow ) {
55
     if ( createdWindow ) {
56
         return;
56
         return;
57
     }
57
     }
59
     createdWindow = true;
59
     createdWindow = true;
60
 }
60
 }
61
 
61
 
62
-void XShapeRectangle::generateHoles() {
62
+void slop::XShapeRectangle::generateHoles() {
63
     if ( !highlight ) {
63
     if ( !highlight ) {
64
         XRectangle rects[4];
64
         XRectangle rects[4];
65
         // Left
65
         // Left
93
     XShapeCombineRectangles( x11->display, window, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
93
     XShapeCombineRectangles( x11->display, window, ShapeBounding, 0, 0, &rect, 1, ShapeSet, 0);
94
 }
94
 }
95
 
95
 
96
-void XShapeRectangle::setPoints( glm::vec2 p1, glm::vec2 p2 ) {
96
+void slop::XShapeRectangle::setPoints( glm::vec2 p1, glm::vec2 p2 ) {
97
     // Find each corner of the rectangle
97
     // Find each corner of the rectangle
98
     ul = glm::vec2( glm::min( p1.x, p2.x ), glm::max( p1.y, p2.y ) ) ;
98
     ul = glm::vec2( glm::min( p1.x, p2.x ), glm::max( p1.y, p2.y ) ) ;
99
     bl = glm::vec2( glm::min( p1.x, p2.x ), glm::min( p1.y, p2.y ) ) ;
99
     bl = glm::vec2( glm::min( p1.x, p2.x ), glm::min( p1.y, p2.y ) ) ;
112
     generateHoles();
112
     generateHoles();
113
 }
113
 }
114
 
114
 
115
-XShapeRectangle::~XShapeRectangle() {
115
+slop::XShapeRectangle::~XShapeRectangle() {
116
 }
116
 }
117
 
117
 
118
-void XShapeRectangle::draw( glm::mat4& matrix ) {
118
+void slop::XShapeRectangle::draw( glm::mat4& matrix ) {
119
     // We don't want to be visible until we're asked to draw.
119
     // We don't want to be visible until we're asked to draw.
120
     createWindow();
120
     createWindow();
121
 }
121
 }
122
 
122
 
123
-glm::vec4 XShapeRectangle::getRect() {
123
+glm::vec4 slop::XShapeRectangle::getRect() {
124
     return glm::vec4( bl.x, bl.y, ur.x-ul.x, ul.y-bl.y );
124
     return glm::vec4( bl.x, bl.y, ur.x-ul.x, ul.y-bl.y );
125
 }
125
 }
126
 
126
 
127
-XColor XShapeRectangle::convertColor( glm::vec4 color ) {
127
+XColor slop::XShapeRectangle::convertColor( glm::vec4 color ) {
128
     // Convert float colors to shorts.
128
     // Convert float colors to shorts.
129
     short red   = short( floor( color.r * 65535.f ) );
129
     short red   = short( floor( color.r * 65535.f ) );
130
     short green = short( floor( color.g * 65535.f ) );
130
     short green = short( floor( color.g * 65535.f ) );

+ 4
- 0
src/xshaperectangle.hpp View File

32
 #include "x.hpp"
32
 #include "x.hpp"
33
 #include "rectangle.hpp"
33
 #include "rectangle.hpp"
34
 
34
 
35
+namespace slop {
36
+
35
 class XShapeRectangle : public Rectangle {
37
 class XShapeRectangle : public Rectangle {
36
 private:
38
 private:
37
     glm::vec2 ul, oul;
39
     glm::vec2 ul, oul;
56
     void draw(glm::mat4& matrix);
58
     void draw(glm::mat4& matrix);
57
 };
59
 };
58
 
60
 
61
+}
62
+
59
 #endif // N_XSHAPERECTANGLE_H_
63
 #endif // N_XSHAPERECTANGLE_H_