naelstrof 7 лет назад
Родитель
Сommit
4db2dbc6fe

+ 0
- 1
CMakeLists.txt Просмотреть файл

@@ -32,7 +32,6 @@ add_library(${LIBRARY_NAME} SHARED  src/mouse.cpp
32 32
                                     src/x.cpp
33 33
                                     src/slopstates.cpp
34 34
                                     src/framebuffer.cpp
35
-                                    src/windowhelper.cpp
36 35
                                     src/resource.cpp
37 36
                                     src/gl_core_3_3.c
38 37
                                     src/shader.cpp

+ 7
- 7
src/framebuffer.cpp Просмотреть файл

@@ -1,6 +1,6 @@
1 1
 #include "framebuffer.hpp"
2 2
 
3
-Framebuffer::Framebuffer( int w, int h ) {
3
+slop::Framebuffer::Framebuffer( int w, int h ) {
4 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 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 6
     shader = new Shader( vert, frag, false );
@@ -38,19 +38,19 @@ Framebuffer::Framebuffer( int w, int h ) {
38 38
     vertCount = verts.size();
39 39
 }
40 40
 
41
-void Framebuffer::setShader( std::string name ) {
41
+void slop::Framebuffer::setShader( std::string name ) {
42 42
     delete shader;
43 43
     shader = new Shader( name + ".vert", name + ".frag" );
44 44
 }
45 45
 
46
-Framebuffer::~Framebuffer() {
46
+slop::Framebuffer::~Framebuffer() {
47 47
     glDeleteTextures(1, &image);
48 48
     glDeleteFramebuffers(1,&fbuffer);
49 49
     glDeleteBuffers(2,buffers);
50 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 54
     // Regenerate the image
55 55
     glDeleteTextures(1, &image);
56 56
     glBindTexture(GL_TEXTURE_2D, image);
@@ -64,15 +64,15 @@ void Framebuffer::resize( int w, int h ) {
64 64
     glBindFramebuffer(GL_FRAMEBUFFER, 0);
65 65
 }
66 66
 
67
-void Framebuffer::bind() {
67
+void slop::Framebuffer::bind() {
68 68
     glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
69 69
 }
70 70
 
71
-void Framebuffer::unbind() {
71
+void slop::Framebuffer::unbind() {
72 72
     glBindFramebuffer( GL_FRAMEBUFFER, 0 );
73 73
 }
74 74
 
75
-void Framebuffer::draw(){
75
+void slop::Framebuffer::draw(){
76 76
     shader->bind();
77 77
     shader->setParameter( "texture", 0 );
78 78
     shader->setAttribute( "position", buffers[0], 2 );

+ 4
- 0
src/framebuffer.hpp Просмотреть файл

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

+ 6
- 6
src/glrectangle.cpp Просмотреть файл

@@ -1,6 +1,6 @@
1 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 4
     this->color = color;
5 5
     this->border = border;
6 6
     this->padding = padding;
@@ -27,7 +27,7 @@ GLRectangle::GLRectangle( glm::vec2 p1, glm::vec2 p2, float border, float paddin
27 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 31
     // Find each corner of the rectangle
32 32
     ul = glm::vec2( glm::min( p1.x, p2.x ), glm::max( p1.y, p2.y ) ) ;
33 33
     bl = glm::vec2( glm::min( p1.x, p2.x ), glm::min( p1.y, p2.y ) ) ;
@@ -46,7 +46,7 @@ void GLRectangle::setPoints( glm::vec2 p1, glm::vec2 p2 ) {
46 46
     generateBuffers();
47 47
 }
48 48
 
49
-void GLRectangle::generateBuffers() {
49
+void slop::GLRectangle::generateBuffers() {
50 50
     std::vector<glm::vec2> rectangle_verts;
51 51
     std::vector<glm::vec2> rectangle_uvs;
52 52
     std::vector<glm::vec2> corner_verts;
@@ -208,12 +208,12 @@ void GLRectangle::generateBuffers() {
208 208
     center_vertCount = center_verts.size();
209 209
 }
210 210
 
211
-GLRectangle::~GLRectangle() {
211
+slop::GLRectangle::~GLRectangle() {
212 212
     delete shader;
213 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 217
     glEnable( GL_BLEND );
218 218
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
219 219
     shader->bind();
@@ -241,6 +241,6 @@ void GLRectangle::draw( glm::mat4& matrix ) {
241 241
     glDisable( GL_BLEND );
242 242
 }
243 243
 
244
-glm::vec4 GLRectangle::getRect() {
244
+glm::vec4 slop::GLRectangle::getRect() {
245 245
     return glm::vec4( bl.x, bl.y, ur.x-ul.x, ul.y-bl.y );
246 246
 }

+ 4
- 0
src/glrectangle.hpp Просмотреть файл

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

+ 5
- 5
src/keyboard.cpp Просмотреть файл

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

+ 4
- 0
src/keyboard.hpp Просмотреть файл

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

+ 2
- 0
src/main.cpp Просмотреть файл

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

+ 8
- 8
src/mouse.cpp Просмотреть файл

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

+ 4
- 1
src/mouse.hpp Просмотреть файл

@@ -27,7 +27,8 @@
27 27
 #include <iostream>
28 28
 
29 29
 #include "x.hpp"
30
-#include "windowhelper.hpp"
30
+
31
+namespace slop {
31 32
 
32 33
 class Mouse {
33 34
 private:
@@ -51,4 +52,6 @@ public:
51 52
 
52 53
 extern Mouse* mouse;
53 54
 
55
+}
56
+
54 57
 #endif // N_MOUSE_H_

+ 5
- 5
src/rectangle.cpp Просмотреть файл

@@ -1,13 +1,13 @@
1 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 12
     return glm::vec4();
13 13
 }

+ 4
- 0
src/rectangle.hpp Просмотреть файл

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

+ 3
- 3
src/resource.cpp Просмотреть файл

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

+ 4
- 0
src/resource.hpp Просмотреть файл

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

+ 14
- 14
src/shader.cpp Просмотреть файл

@@ -1,6 +1,6 @@
1 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 4
     std::string vert_contents;
5 5
     std::string frag_contents;
6 6
     if ( file ) {
@@ -73,19 +73,19 @@ Shader::Shader( std::string vert, std::string frag, bool file ) {
73 73
     glUseProgram( 0 );
74 74
 }
75 75
 
76
-Shader::~Shader() {
76
+slop::Shader::~Shader() {
77 77
     glDeleteProgram( program );
78 78
 }
79 79
 
80
-unsigned int Shader::getProgram() {
80
+unsigned int slop::Shader::getProgram() {
81 81
     return program;
82 82
 }
83 83
 
84
-void Shader::bind() {
84
+void slop::Shader::bind() {
85 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 89
     glCompileShader( shader );
90 90
 
91 91
     // Compiling the shader is the easy part, all this junk down here is for printing the error it might generate.
@@ -103,7 +103,7 @@ int Shader::compile( unsigned int shader, std::string& error ) {
103 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 107
     glAttachShader( program, vertshader );
108 108
     glAttachShader( program, fragshader );
109 109
     glLinkProgram( program );
@@ -123,32 +123,32 @@ int Shader::link( unsigned int vertshader, unsigned int fragshader, std::string&
123 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 127
     glUseProgram( program );
128 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 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 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 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 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 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 152
     unsigned int a = glGetAttribLocation( program, name.c_str() );
153 153
     glEnableVertexAttribArray( a );
154 154
     glBindBuffer( GL_ARRAY_BUFFER, buffer );
@@ -156,7 +156,7 @@ void Shader::setAttribute( std::string name, unsigned int buffer, unsigned int s
156 156
     activeAttributes.push_back( a );
157 157
 }
158 158
 
159
-void Shader::unbind() {
159
+void slop::Shader::unbind() {
160 160
     for ( unsigned int i=0; i<activeAttributes.size(); i++ ) {
161 161
         glDisableVertexAttribArray( activeAttributes[i] );
162 162
     }

+ 4
- 0
src/shader.hpp Просмотреть файл

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

+ 33
- 27
src/slop.cpp Просмотреть файл

@@ -13,13 +13,22 @@
13 13
 #include "xshaperectangle.hpp"
14 14
 #include "slop.hpp"
15 15
 
16
+namespace slop {
17
+
16 18
 X11* x11;
17 19
 Mouse* mouse;
18 20
 Keyboard* keyboard;
19 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 30
 // Defaults!
22
-SlopOptions::SlopOptions() {
31
+slop::SlopOptions::SlopOptions() {
23 32
     borderSize = 1;
24 33
     nokeyboard = false;
25 34
     nodecorations = false;
@@ -34,7 +43,7 @@ SlopOptions::SlopOptions() {
34 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 47
     this->x = x;
39 48
     this->y = y;
40 49
     this->w = w;
@@ -42,15 +51,12 @@ SlopSelection::SlopSelection( float x, float y, float w, float h, int id ) {
42 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 56
     bool deleteOptions = false;
51 57
     if ( !options ) {
52 58
         deleteOptions = true;
53
-        options = new SlopOptions();
59
+        options = new slop::SlopOptions();
54 60
     }
55 61
     resource = new Resource();
56 62
     // Set up x11 temporarily
@@ -81,29 +87,29 @@ SlopSelection SlopSelect( SlopOptions* options, bool* cancelled, bool quiet) {
81 87
                 std::cerr << errorstring;
82 88
             }
83 89
         }
84
-        returnval = XShapeSlopSelect( options, cancelled );
90
+        returnval = slop::XShapeSlopSelect( options, cancelled );
85 91
     } else {
86
-        returnval = GLSlopSelect( options, cancelled, window );
92
+        returnval = slop::GLSlopSelect( options, cancelled, window );
87 93
     }
88 94
     delete x11;
89
-    delete resource;
95
+    delete slop::resource;
90 96
     if ( deleteOptions ) {
91 97
         delete options;
92 98
     }
93 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 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 107
     // We have no GL context, so the matrix is useless...
102 108
     glm::mat4 fake;
103 109
     // This is where we'll run through all of our stuffs
104 110
     while( memory.running ) {
105
-        mouse->update();
106
-        keyboard->update();
111
+        slop::mouse->update();
112
+        slop::keyboard->update();
107 113
         // We move our statemachine forward.
108 114
         memory.update( 1 );
109 115
 
@@ -116,7 +122,7 @@ SlopSelection XShapeSlopSelect( SlopOptions* options, bool* cancelled ) {
116 122
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
117 123
 
118 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 126
             memory.running = false;
121 127
             if ( cancelled ) {
122 128
                 *cancelled = true;
@@ -132,25 +138,25 @@ SlopSelection XShapeSlopSelect( SlopOptions* options, bool* cancelled ) {
132 138
     // Lets now clear both front and back buffers before closing.
133 139
     // hopefully it'll be completely transparent while closing!
134 140
     // Then we clean up.
135
-    delete mouse;
141
+    delete slop::mouse;
136 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 149
     if ( options->shader != "textured" ) {
144 150
         window->framebuffer->setShader( options->shader );
145 151
     }
146 152
 
147 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 156
     // This is where we'll run through all of our stuffs
151 157
     while( memory.running ) {
152
-        mouse->update();
153
-        keyboard->update();
158
+        slop::mouse->update();
159
+        slop::keyboard->update();
154 160
         // We move our statemachine forward.
155 161
         memory.update( 1 );
156 162
 
@@ -168,7 +174,7 @@ SlopSelection GLSlopSelect( SlopOptions* options, bool* cancelled, SlopWindow* w
168 174
         if ( err != GL_NO_ERROR ) {
169 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 178
             memory.running = false;
173 179
             if ( cancelled ) {
174 180
                 *cancelled = true;
@@ -190,7 +196,7 @@ SlopSelection GLSlopSelect( SlopOptions* options, bool* cancelled, SlopWindow* w
190 196
     window->display();
191 197
     // Then we clean up.
192 198
     delete window;
193
-    delete mouse;
199
+    delete slop::mouse;
194 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 Просмотреть файл

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

+ 20
- 18
src/slopstates.cpp Просмотреть файл

@@ -1,6 +1,8 @@
1 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 6
     running = true;
5 7
     state = (SlopState*)new SlopStart();
6 8
     nextState = NULL;
@@ -11,7 +13,7 @@ SlopMemory::SlopMemory( SlopOptions* options, Rectangle* rect ) {
11 13
     state->onEnter( *this );
12 14
 }
13 15
 
14
-SlopMemory::~SlopMemory() {
16
+slop::SlopMemory::~SlopMemory() {
15 17
     delete state;
16 18
     if ( nextState ) {
17 19
         delete nextState;
@@ -19,7 +21,7 @@ SlopMemory::~SlopMemory() {
19 21
     delete rectangle;
20 22
 }
21 23
 
22
-void SlopMemory::update( double dt ) {
24
+void slop::SlopMemory::update( double dt ) {
23 25
     state->update( *this, dt );
24 26
     if ( nextState ) {
25 27
         state->onExit( *this );
@@ -30,33 +32,33 @@ void SlopMemory::update( double dt ) {
30 32
     }
31 33
 }
32 34
 
33
-void SlopMemory::setState( SlopState* state ) {
35
+void slop::SlopMemory::setState( SlopState* state ) {
34 36
     if ( nextState ) {
35 37
         delete nextState;
36 38
     }
37 39
     nextState = state;
38 40
 }
39 41
 
40
-void SlopMemory::draw( glm::mat4& matrix ) {
42
+void slop::SlopMemory::draw( glm::mat4& matrix ) {
41 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 59
     setStartPos = false;
58 60
 }
59
-void SlopStart::update( SlopMemory& memory, double dt ) {
61
+void slop::SlopStart::update( SlopMemory& memory, double dt ) {
60 62
     if ( mouse->getButton( 1 ) && !setStartPos ) {
61 63
         startPos = mouse->getMousePos();
62 64
         setStartPos = true;
@@ -74,21 +76,21 @@ void SlopStart::update( SlopMemory& memory, double dt ) {
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 80
     if ( memory.tolerance > 0 ) {
79 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 86
     startPoint = point;
85 87
 }
86 88
 
87
-void SlopStartDrag::onEnter( SlopMemory& memory ) {
89
+void slop::SlopStartDrag::onEnter( SlopMemory& memory ) {
88 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 94
     char a = startPoint.y > mouse->getMousePos().y;
93 95
     char b = startPoint.x > mouse->getMousePos().x;
94 96
     char c = (a << 1) | b;
@@ -111,10 +113,10 @@ void SlopStartDrag::update( SlopMemory& memory, double dt ) {
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 117
     memory.rectangle->draw( matrix );
116 118
 }
117 119
 
118
-void SlopEndDrag::onEnter( SlopMemory& memory ) {
120
+void slop::SlopEndDrag::onEnter( SlopMemory& memory ) {
119 121
     memory.running = false;
120 122
 }

+ 4
- 5
src/slopstates.hpp Просмотреть файл

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

+ 7
- 5
src/window.cpp Просмотреть файл

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

+ 4
- 1
src/window.hpp Просмотреть файл

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

+ 0
- 36
src/windowhelper.cpp Просмотреть файл

@@ -1,36 +0,0 @@
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 Просмотреть файл

@@ -1,31 +0,0 @@
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 Просмотреть файл

@@ -1,5 +1,42 @@
1 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 40
 bool X11::hasCompositor() {
4 41
     std::stringstream prop_name;
5 42
     prop_name << "_NET_WM_CM_S" << XScreenNumberOfScreen( screen );

+ 7
- 0
src/x.hpp Просмотреть файл

@@ -27,6 +27,11 @@
27 27
 #include <sstream>
28 28
 #include <stdexcept>
29 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 36
 class X11 {
32 37
 public:
@@ -41,4 +46,6 @@ public:
41 46
 
42 47
 extern X11* x11;
43 48
 
49
+}
50
+
44 51
 #endif

+ 8
- 8
src/xshaperectangle.cpp Просмотреть файл

@@ -1,6 +1,6 @@
1 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 4
     this->color = convertColor( color );
5 5
     this->border = border;
6 6
     this->padding = padding;
@@ -51,7 +51,7 @@ XShapeRectangle::XShapeRectangle( glm::vec2 p1, glm::vec2 p2, float border, floa
51 51
     createdWindow = false;
52 52
 }
53 53
 
54
-void XShapeRectangle::createWindow() {
54
+void slop::XShapeRectangle::createWindow() {
55 55
     if ( createdWindow ) {
56 56
         return;
57 57
     }
@@ -59,7 +59,7 @@ void XShapeRectangle::createWindow() {
59 59
     createdWindow = true;
60 60
 }
61 61
 
62
-void XShapeRectangle::generateHoles() {
62
+void slop::XShapeRectangle::generateHoles() {
63 63
     if ( !highlight ) {
64 64
         XRectangle rects[4];
65 65
         // Left
@@ -93,7 +93,7 @@ void XShapeRectangle::generateHoles() {
93 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 97
     // Find each corner of the rectangle
98 98
     ul = glm::vec2( glm::min( p1.x, p2.x ), glm::max( p1.y, p2.y ) ) ;
99 99
     bl = glm::vec2( glm::min( p1.x, p2.x ), glm::min( p1.y, p2.y ) ) ;
@@ -112,19 +112,19 @@ void XShapeRectangle::setPoints( glm::vec2 p1, glm::vec2 p2 ) {
112 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 119
     // We don't want to be visible until we're asked to draw.
120 120
     createWindow();
121 121
 }
122 122
 
123
-glm::vec4 XShapeRectangle::getRect() {
123
+glm::vec4 slop::XShapeRectangle::getRect() {
124 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 128
     // Convert float colors to shorts.
129 129
     short red   = short( floor( color.r * 65535.f ) );
130 130
     short green = short( floor( color.g * 65535.f ) );

+ 4
- 0
src/xshaperectangle.hpp Просмотреть файл

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