|
@@ -120,14 +120,14 @@ slop::SlopSelection slop::SlopSelect( slop::SlopOptions* options, bool* cancelle
|
120
|
120
|
|
121
|
121
|
slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* cancelled ) {
|
122
|
122
|
// Init our little state machine, memory is a tad of a misnomer
|
123
|
|
- 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) );
|
124
|
|
- slop::mouse = new slop::Mouse( x11, options->nodecorations, ((XShapeRectangle*)memory.rectangle)->window );
|
|
123
|
+ 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) );
|
|
124
|
+ slop::mouse = new slop::Mouse( x11, options->nodecorations, ((XShapeRectangle*)memory->rectangle)->window );
|
125
|
125
|
|
126
|
126
|
// We have no GL context, so the matrix is useless...
|
127
|
127
|
glm::mat4 fake;
|
128
|
128
|
// This is where we'll run through all of our stuffs
|
129
|
129
|
auto last = std::chrono::high_resolution_clock::now();
|
130
|
|
- while( memory.running ) {
|
|
130
|
+ while( memory->running ) {
|
131
|
131
|
slop::mouse->update();
|
132
|
132
|
if ( !options->nokeyboard ) {
|
133
|
133
|
slop::keyboard->update();
|
|
@@ -136,11 +136,11 @@ slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* ca
|
136
|
136
|
auto current = std::chrono::high_resolution_clock::now();
|
137
|
137
|
std::chrono::duration<double, std::milli> frametime = current-last;
|
138
|
138
|
last = current;
|
139
|
|
- memory.update( frametime.count()/1000.f );
|
|
139
|
+ memory->update( frametime.count()/1000.f );
|
140
|
140
|
|
141
|
141
|
// We don't actually draw anything, but the state machine uses
|
142
|
142
|
// this to know when to spawn the window.
|
143
|
|
- memory.draw( fake );
|
|
143
|
+ memory->draw( fake );
|
144
|
144
|
|
145
|
145
|
// X11 explodes if we update as fast as possible, here's a tiny sleep.
|
146
|
146
|
XFlush(x11->display);
|
|
@@ -148,7 +148,7 @@ slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* ca
|
148
|
148
|
|
149
|
149
|
// Then we draw the framebuffer to the screen
|
150
|
150
|
if ( (!options->nokeyboard && slop::keyboard->anyKeyDown()) || slop::mouse->getButton( 3 ) ) {
|
151
|
|
- memory.running = false;
|
|
151
|
+ memory->running = false;
|
152
|
152
|
if ( cancelled ) {
|
153
|
153
|
*cancelled = true;
|
154
|
154
|
}
|
|
@@ -158,14 +158,26 @@ slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* ca
|
158
|
158
|
}
|
159
|
159
|
|
160
|
160
|
// Now we should have a selection! We parse everything we know about it here.
|
161
|
|
- glm::vec4 output = memory.rectangle->getRect();
|
|
161
|
+ glm::vec4 output = memory->rectangle->getRect();
|
162
|
162
|
|
163
|
163
|
// Lets now clear both front and back buffers before closing.
|
164
|
164
|
// hopefully it'll be completely transparent while closing!
|
165
|
165
|
// Then we clean up.
|
166
|
166
|
delete slop::mouse;
|
|
167
|
+ Window selectedWindow = memory->selectedWindow;
|
|
168
|
+ delete memory;
|
|
169
|
+
|
|
170
|
+ // Try to detect the window dying.
|
|
171
|
+ int tries = 0;
|
|
172
|
+ while( tries < 50 ) {
|
|
173
|
+ XEvent event;
|
|
174
|
+ if ( XCheckTypedEvent( x11->display, UnmapNotify, &event ) ) { break; }
|
|
175
|
+ if ( XCheckTypedEvent( x11->display, DestroyNotify, &event ) ) { break; }
|
|
176
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
177
|
+ tries++;
|
|
178
|
+ }
|
167
|
179
|
// Finally return the data.
|
168
|
|
- return slop::SlopSelection( output.x, output.y, output.z, output.w, memory.selectedWindow );
|
|
180
|
+ return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow );
|
169
|
181
|
}
|
170
|
182
|
|
171
|
183
|
slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancelled, SlopWindow* window ) {
|
|
@@ -184,14 +196,14 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
|
184
|
196
|
}
|
185
|
197
|
}
|
186
|
198
|
// Init our little state machine, memory is a tad of a misnomer
|
187
|
|
- 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) );
|
|
199
|
+ 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) );
|
188
|
200
|
|
189
|
201
|
slop::Framebuffer* pingpong = new slop::Framebuffer(WidthOfScreen(x11->screen), HeightOfScreen(x11->screen));
|
190
|
202
|
|
191
|
203
|
// This is where we'll run through all of our stuffs
|
192
|
204
|
auto start = std::chrono::high_resolution_clock::now();
|
193
|
205
|
auto last = start;
|
194
|
|
- while( memory.running ) {
|
|
206
|
+ while( memory->running ) {
|
195
|
207
|
slop::mouse->update();
|
196
|
208
|
if ( !options->nokeyboard ) {
|
197
|
209
|
slop::keyboard->update();
|
|
@@ -200,14 +212,14 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
|
200
|
212
|
auto current = std::chrono::high_resolution_clock::now();
|
201
|
213
|
std::chrono::duration<double, std::milli> frametime = current-last;
|
202
|
214
|
last = current;
|
203
|
|
- memory.update( frametime.count()/1000.f );
|
|
215
|
+ memory->update( frametime.count()/1000.f );
|
204
|
216
|
|
205
|
217
|
// Then we draw our junk to a framebuffer.
|
206
|
218
|
window->framebuffer->setShader( textured );
|
207
|
219
|
window->framebuffer->bind();
|
208
|
220
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
209
|
221
|
glClear (GL_COLOR_BUFFER_BIT);
|
210
|
|
- memory.draw( window->camera );
|
|
222
|
+ memory->draw( window->camera );
|
211
|
223
|
window->framebuffer->unbind();
|
212
|
224
|
|
213
|
225
|
std::chrono::duration<double, std::milli> elapsed = current-start;
|
|
@@ -259,7 +271,7 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
|
259
|
271
|
throw new std::runtime_error( "OpenGL threw an error: " + error );
|
260
|
272
|
}
|
261
|
273
|
if ( (!options->nokeyboard && slop::keyboard->anyKeyDown()) || slop::mouse->getButton( 3 ) ) {
|
262
|
|
- memory.running = false;
|
|
274
|
+ memory->running = false;
|
263
|
275
|
if ( cancelled ) {
|
264
|
276
|
*cancelled = true;
|
265
|
277
|
}
|
|
@@ -269,7 +281,7 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
|
269
|
281
|
}
|
270
|
282
|
|
271
|
283
|
// Now we should have a selection! We parse everything we know about it here.
|
272
|
|
- glm::vec4 output = memory.rectangle->getRect();
|
|
284
|
+ glm::vec4 output = memory->rectangle->getRect();
|
273
|
285
|
|
274
|
286
|
// Lets now clear both front and back buffers before closing.
|
275
|
287
|
// hopefully it'll be completely transparent while closing!
|
|
@@ -281,6 +293,18 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
|
281
|
293
|
// Then we clean up.
|
282
|
294
|
delete window;
|
283
|
295
|
delete slop::mouse;
|
|
296
|
+ Window selectedWindow = memory->selectedWindow;
|
|
297
|
+ delete memory;
|
|
298
|
+
|
|
299
|
+ // Try to detect the window dying.
|
|
300
|
+ int tries = 0;
|
|
301
|
+ while( tries < 50 ) {
|
|
302
|
+ XEvent event;
|
|
303
|
+ if ( XCheckTypedEvent( x11->display, UnmapNotify, &event ) ) { break; }
|
|
304
|
+ if ( XCheckTypedEvent( x11->display, DestroyNotify, &event ) ) { break; }
|
|
305
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
306
|
+ tries++;
|
|
307
|
+ }
|
284
|
308
|
// Finally return the data.
|
285
|
|
- return slop::SlopSelection( output.x, output.y, output.z, output.w, memory.selectedWindow );
|
|
309
|
+ return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow );
|
286
|
310
|
}
|