ソースを参照

finished c interface to slop

naelstrof 7 年 前
コミット
ccffce612a
共有2 個のファイルを変更した99 個の追加2 個の削除を含む
  1. 54
    0
      src/slop.cpp
  2. 45
    2
      src/slop.hpp

+ 54
- 0
src/slop.cpp ファイルの表示

@@ -342,3 +342,57 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, SlopWindow*
342 342
     // Finally return the data.
343 343
     return slop::SlopSelection( output.x, output.y, output.z, output.w, selectedWindow, cancelled );
344 344
 }
345
+
346
+extern "C" struct slop_options slop_options_default() {
347
+    struct slop_options options;
348
+    options.border = 1;
349
+    options.nokeyboard = false;
350
+    options.noopengl = false;
351
+    options.nodecorations = false;
352
+    options.tolerance = 2;
353
+    options.padding = 0;
354
+    options.shaders = slop_default_shaders;
355
+    options.highlight = false;
356
+    options.r = 0.5;
357
+    options.g = 0.5;
358
+    options.b = 0.5;
359
+    options.a = 1;
360
+    options.quiet = false;
361
+
362
+    char* envdisplay = getenv("DISPLAY");
363
+    if (envdisplay == NULL) {
364
+        options.xdisplay = slop_default_xdisplay;
365
+    } else {
366
+        options.xdisplay = envdisplay;
367
+    }
368
+    return options;
369
+}
370
+
371
+extern "C" struct slop_selection slop_select( struct slop_options* options ) {
372
+    slop::SlopOptions realOptions = slop::SlopOptions();
373
+    if ( options != NULL ) {
374
+        realOptions.border = options->border;
375
+        realOptions.nokeyboard = options->nokeyboard;
376
+        realOptions.noopengl = options->noopengl;
377
+        realOptions.nodecorations = options->nodecorations;
378
+        realOptions.tolerance = options->tolerance;
379
+        realOptions.padding = options->padding;
380
+        realOptions.shaders = options->shaders;
381
+        realOptions.highlight = options->highlight;
382
+        realOptions.r = options->r;
383
+        realOptions.g = options->g;
384
+        realOptions.b = options->b;
385
+        realOptions.a = options->a;
386
+        realOptions.quiet = options->quiet;
387
+        realOptions.xdisplay = options->xdisplay;
388
+    }
389
+    slop::SlopSelection select = SlopSelect( &realOptions );
390
+    slop_selection realSelect;
391
+    realSelect.x = select.x;
392
+    realSelect.y = select.y;
393
+    realSelect.w = select.w;
394
+    realSelect.h = select.h;
395
+    realSelect.id = select.id;
396
+    realSelect.cancelled = select.cancelled;
397
+    return realSelect;
398
+}

+ 45
- 2
src/slop.hpp ファイルの表示

@@ -1,4 +1,4 @@
1
-/* glslop.hpp: exposes an opengl selection interface
1
+/* slop.hpp: exposes a selection interface
2 2
  *
3 3
  * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
4 4
  *
@@ -21,6 +21,39 @@
21 21
 #ifndef N_SLOP_H_
22 22
 #define N_SLOP_H_
23 23
 
24
+// Here we make some C-styled structs and function definitions, 
25
+// allows other people to have a pure C interface to slop.
26
+
27
+struct slop_options {
28
+    //SlopOptions();
29
+    int quiet;
30
+    float border;
31
+    float padding;
32
+    float tolerance;
33
+    int highlight;
34
+    int noopengl;
35
+    int nokeyboard;
36
+    int nodecorations;
37
+    char* shaders;
38
+    float r;
39
+    float g;
40
+    float b;
41
+    float a;
42
+    char* xdisplay;
43
+};
44
+
45
+struct slop_selection {
46
+    //SlopSelection( float x, float y, float w, float h, int id, bool cancelled );
47
+    int cancelled;
48
+    float x;
49
+    float y;
50
+    float w;
51
+    float h;
52
+// This is an X11 Window ID
53
+    int id;
54
+};
55
+
56
+#ifdef __cplusplus
24 57
 namespace slop {
25 58
 
26 59
 class SlopOptions {
@@ -33,7 +66,7 @@ public:
33 66
     bool highlight;
34 67
     bool noopengl;
35 68
     bool nokeyboard;
36
-    int nodecorations;
69
+    bool nodecorations;
37 70
     char* shaders;
38 71
     float r;
39 72
     float g;
@@ -58,4 +91,14 @@ SlopSelection SlopSelect( SlopOptions* options = NULL );
58 91
 
59 92
 }
60 93
 
94
+extern "C" struct slop_options slop_options_default();
95
+extern "C" struct slop_selection slop_select( struct slop_options* options );
96
+
97
+#else // __cplusplus
98
+
99
+struct slop_options slop_options_default();
100
+struct slop_selection slop_select( struct slop_options* options );
101
+
102
+#endif
103
+
61 104
 #endif // N_SLOP_H_