|
@@ -3,6 +3,8 @@
|
3
|
3
|
|
4
|
4
|
#include <chrono>
|
5
|
5
|
#include <thread>
|
|
6
|
+#include <string>
|
|
7
|
+#include <vector>
|
6
|
8
|
|
7
|
9
|
#include <stdlib.h>
|
8
|
10
|
|
|
@@ -25,8 +27,8 @@ Mouse* mouse;
|
25
|
27
|
Keyboard* keyboard;
|
26
|
28
|
Resource* resource;
|
27
|
29
|
|
28
|
|
-SlopSelection GLSlopSelect( slop::SlopOptions* options, bool* cancelled, slop::SlopWindow* window );
|
29
|
|
-SlopSelection XShapeSlopSelect( slop::SlopOptions* options, bool* cancelled);
|
|
30
|
+SlopSelection GLSlopSelect( slop::SlopOptions* options, slop::SlopWindow* window );
|
|
31
|
+SlopSelection XShapeSlopSelect( slop::SlopOptions* options );
|
30
|
32
|
|
31
|
33
|
static int TmpXError(Display * d, XErrorEvent * ev) {
|
32
|
34
|
return 0;
|
|
@@ -34,40 +36,63 @@ static int TmpXError(Display * d, XErrorEvent * ev) {
|
34
|
36
|
|
35
|
37
|
}
|
36
|
38
|
|
|
39
|
+template<typename Out>
|
|
40
|
+static void split(const std::string &s, char delim, Out result) {
|
|
41
|
+ std::stringstream ss;
|
|
42
|
+ ss.str(s);
|
|
43
|
+ std::string item;
|
|
44
|
+ while (std::getline(ss, item, delim)) {
|
|
45
|
+ *(result++) = item;
|
|
46
|
+ }
|
|
47
|
+}
|
|
48
|
+
|
|
49
|
+static std::vector<std::string> split(const std::string &s, char delim) {
|
|
50
|
+ std::vector<std::string> elems;
|
|
51
|
+ split(s, delim, std::back_inserter(elems));
|
|
52
|
+ return elems;
|
|
53
|
+}
|
|
54
|
+
|
|
55
|
+
|
37
|
56
|
using namespace slop;
|
38
|
57
|
|
|
58
|
+char slop_default_xdisplay[] = ":0";
|
|
59
|
+char slop_default_shaders[] = "textured";
|
|
60
|
+
|
39
|
61
|
// Defaults!
|
40
|
62
|
slop::SlopOptions::SlopOptions() {
|
41
|
|
- borderSize = 1;
|
|
63
|
+ border = 1;
|
42
|
64
|
nokeyboard = false;
|
43
|
65
|
noopengl = false;
|
44
|
66
|
nodecorations = false;
|
45
|
67
|
tolerance = 2;
|
46
|
68
|
padding = 0;
|
47
|
|
- shaders.push_back("textured");
|
|
69
|
+ shaders = slop_default_shaders;
|
48
|
70
|
highlight = false;
|
49
|
71
|
r = 0.5;
|
50
|
72
|
g = 0.5;
|
51
|
73
|
b = 0.5;
|
52
|
74
|
a = 1;
|
|
75
|
+ quiet = false;
|
53
|
76
|
|
54
|
|
- char * envdisplay = getenv("DISPLAY");
|
55
|
|
- if (envdisplay == NULL)
|
56
|
|
- xdisplay = ":0";
|
57
|
|
- else
|
|
77
|
+ char* envdisplay = getenv("DISPLAY");
|
|
78
|
+ if (envdisplay == NULL) {
|
|
79
|
+ xdisplay = slop_default_xdisplay;
|
|
80
|
+ } else {
|
58
|
81
|
xdisplay = envdisplay;
|
|
82
|
+ }
|
59
|
83
|
}
|
60
|
84
|
|
61
|
|
-slop::SlopSelection::SlopSelection( float x, float y, float w, float h, int id ) {
|
|
85
|
+slop::SlopSelection::SlopSelection( float x, float y, float w, float h, int id, bool cancelled ) {
|
62
|
86
|
this->x = x;
|
63
|
87
|
this->y = y;
|
64
|
88
|
this->w = w;
|
65
|
89
|
this->h = h;
|
66
|
90
|
this->id = id;
|
|
91
|
+ this->cancelled = cancelled;
|
67
|
92
|
}
|
68
|
93
|
|
69
|
|
-slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options, bool* cancelled, bool quiet) {
|
70
|
|
- slop::SlopSelection returnval(0,0,0,0,0);
|
|
94
|
+slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options ) {
|
|
95
|
+ slop::SlopSelection returnval(0,0,0,0,0,true);
|
71
|
96
|
bool deleteOptions = false;
|
72
|
97
|
if ( !options ) {
|
73
|
98
|
deleteOptions = true;
|
|
@@ -105,7 +130,7 @@ slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options, bool* cancelle
|
105
|
130
|
}
|
106
|
131
|
if ( !success ) {
|
107
|
132
|
// If we fail, we launch the XShape version of slop.
|
108
|
|
- if ( !quiet && !options->noopengl ) {
|
|
133
|
+ if ( !options->quiet && !options->noopengl ) {
|
109
|
134
|
if ( errorstring.length() <= 0 ) {
|
110
|
135
|
errorstring += "Failed to launch OpenGL context, --shader parameter will be ignored.\n";
|
111
|
136
|
std::cerr << errorstring;
|
|
@@ -113,9 +138,9 @@ slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options, bool* cancelle
|
113
|
138
|
std::cerr << errorstring;
|
114
|
139
|
}
|
115
|
140
|
}
|
116
|
|
- returnval = slop::XShapeSlopSelect( options, cancelled );
|
|
141
|
+ returnval = slop::XShapeSlopSelect( options );
|
117
|
142
|
} else {
|
118
|
|
- returnval = slop::GLSlopSelect( options, cancelled, window );
|
|
143
|
+ returnval = slop::GLSlopSelect( options, window );
|
119
|
144
|
}
|
120
|
145
|
delete x11;
|
121
|
146
|
delete slop::resource;
|
|
@@ -125,9 +150,10 @@ slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options, bool* cancelle
|
125
|
150
|
return returnval;
|
126
|
151
|
}
|
127
|
152
|
|
128
|
|
-slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* cancelled ) {
|
|
153
|
+slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options ) {
|
129
|
154
|
// Init our little state machine, memory is a tad of a misnomer
|
130
|
|
- slop::SlopMemory* memory = new slop::SlopMemory( 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) );
|
|
155
|
+ bool cancelled = false;
|
|
156
|
+ slop::SlopMemory* memory = new slop::SlopMemory( options, new XShapeRectangle(glm::vec2(0,0), glm::vec2(0,0), options->border, options->padding, glm::vec4( options->r, options->g, options->b, options->a ), options->highlight) );
|
131
|
157
|
slop::mouse = new slop::Mouse( x11, options->nodecorations, ((XShapeRectangle*)memory->rectangle)->window );
|
132
|
158
|
|
133
|
159
|
// We have no GL context, so the matrix is useless...
|
|
@@ -156,11 +182,7 @@ slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* ca
|
156
|
182
|
// Then we draw the framebuffer to the screen
|
157
|
183
|
if ( (!options->nokeyboard && slop::keyboard->anyKeyDown()) || slop::mouse->getButton( 3 ) ) {
|
158
|
184
|
memory->running = false;
|
159
|
|
- if ( cancelled ) {
|
160
|
|
- *cancelled = true;
|
161
|
|
- }
|
162
|
|
- } else {
|
163
|
|
- *cancelled = false;
|
|
185
|
+ cancelled = true;
|
164
|
186
|
}
|
165
|
187
|
}
|
166
|
188
|
|
|
@@ -184,18 +206,20 @@ slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* ca
|
184
|
206
|
tries++;
|
185
|
207
|
}
|
186
|
208
|
// Finally return the data.
|
187
|
|
- return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow );
|
|
209
|
+ return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow, cancelled );
|
188
|
210
|
}
|
189
|
211
|
|
190
|
|
-slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancelled, SlopWindow* window ) {
|
|
212
|
+slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, SlopWindow* window ) {
|
|
213
|
+ bool cancelled = false;
|
191
|
214
|
slop::mouse = new slop::Mouse( x11, options->nodecorations, window->window );
|
192
|
215
|
|
193
|
216
|
std::string vert = "#version 120\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 uvCoord;\nvoid main()\n{\nuvCoord = uv;\ngl_Position = vec4(position,0,1);\n}\n";
|
194
|
217
|
std::string frag = "#version 120\nuniform sampler2D texture;\nvarying vec2 uvCoord;\nvoid main()\n {\ngl_FragColor = texture2D( texture, uvCoord );\n}\n";
|
195
|
218
|
slop::Shader* textured = new slop::Shader( vert, frag, false );
|
196
|
219
|
std::vector<slop::Shader*> shaders;
|
197
|
|
- for( int i=0;i<options->shaders.size();i++ ) {
|
198
|
|
- std::string sn = options->shaders[i];
|
|
220
|
+ std::vector<std::string> stringShaders = split( options->shaders, ',' );
|
|
221
|
+ for( int i=0;i<stringShaders.size();i++ ) {
|
|
222
|
+ std::string sn = stringShaders[i];
|
199
|
223
|
if ( sn != "textured" ) {
|
200
|
224
|
shaders.push_back( new slop::Shader( sn + ".vert", sn + ".frag" ) );
|
201
|
225
|
} else {
|
|
@@ -203,7 +227,7 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
|
203
|
227
|
}
|
204
|
228
|
}
|
205
|
229
|
// Init our little state machine, memory is a tad of a misnomer
|
206
|
|
- slop::SlopMemory* memory = new slop::SlopMemory( 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) );
|
|
230
|
+ slop::SlopMemory* memory = new slop::SlopMemory( options, new GLRectangle(glm::vec2(0,0), glm::vec2(0,0), options->border, options->padding, glm::vec4( options->r, options->g, options->b, options->a ), options->highlight) );
|
207
|
231
|
|
208
|
232
|
slop::Framebuffer* pingpong = new slop::Framebuffer(WidthOfScreen(x11->screen), HeightOfScreen(x11->screen));
|
209
|
233
|
|
|
@@ -282,11 +306,7 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
|
282
|
306
|
}
|
283
|
307
|
if ( (!options->nokeyboard && slop::keyboard->anyKeyDown()) || slop::mouse->getButton( 3 ) ) {
|
284
|
308
|
memory->running = false;
|
285
|
|
- if ( cancelled ) {
|
286
|
|
- *cancelled = true;
|
287
|
|
- }
|
288
|
|
- } else {
|
289
|
|
- *cancelled = false;
|
|
309
|
+ cancelled = true;
|
290
|
310
|
}
|
291
|
311
|
}
|
292
|
312
|
|
|
@@ -320,5 +340,5 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
|
320
|
340
|
tries++;
|
321
|
341
|
}
|
322
|
342
|
// Finally return the data.
|
323
|
|
- return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow );
|
|
343
|
+ return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow, cancelled );
|
324
|
344
|
}
|