Quellcode durchsuchen

Added optional CMake flag CMAKE_OPENGL_SUPPORT to enable slop's OpenGL implementation.

Dalton Nell vor 9 Jahren
Ursprung
Commit
3af00283a4
8 geänderte Dateien mit 309 neuen und 104 gelöschten Zeilen
  1. 53
    45
      CMakeLists.txt
  2. 91
    0
      cmakemodules/FindImlib2.cmake
  3. 1
    1
      src/framebuffer.cpp
  4. 124
    53
      src/glselectrectangle.cpp
  5. 5
    5
      src/glselectrectangle.hpp
  6. 23
    0
      src/main.cpp
  7. 10
    0
      src/x.cpp
  8. 2
    0
      src/x.hpp

+ 53
- 45
CMakeLists.txt Datei anzeigen

@@ -5,6 +5,8 @@ set( slop_VERSION_MAJOR 4 )
5 5
 set( slop_VERSION_MINOR 2 )
6 6
 set( slop_VERSION_PATCH 16 )
7 7
 
8
+set( CMAKE_OPENGL_SUPPORT FALSE CACHE BOOL "Whether or not to compile with OpenGL, shaders, magnification, and theming support." )
9
+
8 10
 set( BIN_TARGET     "${PROJECT_NAME}" )
9 11
 if( NOT CMAKE_INSTALL_PREFIX )
10 12
    set( CMAKE_INSTALL_PREFIX "/usr" )
@@ -75,26 +77,35 @@ configure_file( "src/cmdline.in" "${CMAKE_SOURCE_DIR}/src/cmdline.h" )
75 77
 add_custom_target( README.md "./generateReadme.sh" DEPENDS "slop" )
76 78
 
77 79
 # Sources
78
-set( source
79
-     src/cmdline.c
80
-     src/selectrectangle.cpp
81
-     src/glselectrectangle.cpp
82
-     src/shader.cpp
83
-     src/framebuffer.cpp
84
-     src/resource.cpp
85
-     src/xselectrectangle.cpp
86
-     src/x.cpp
87
-     src/main.cpp )
80
+if( CMAKE_OPENGL_SUPPORT )
81
+    set( source
82
+         src/cmdline.c
83
+         src/selectrectangle.cpp
84
+         src/glselectrectangle.cpp
85
+         src/shader.cpp
86
+         src/framebuffer.cpp
87
+         src/resource.cpp
88
+         src/xselectrectangle.cpp
89
+         src/x.cpp
90
+         src/main.cpp )
91
+else()
92
+    set( source
93
+         src/cmdline.c
94
+         src/selectrectangle.cpp
95
+         src/xselectrectangle.cpp
96
+         src/x.cpp
97
+         src/main.cpp )
98
+endif()
88 99
 
89 100
 # Obtain library paths and make sure they exist.
90 101
 set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmakemodules" )
102
+find_package( Imlib2    REQUIRED )
91 103
 find_package( X11       REQUIRED )
92 104
 find_package( XExt      REQUIRED )
93 105
 find_package( OpenGL    REQUIRED )
94 106
 find_package( GLX       REQUIRED )
95 107
 find_package( XRender   REQUIRED )
96 108
 find_package( XRandr    REQUIRED )
97
-find_package( DevIL     REQUIRED )
98 109
 find_package( GLEW      REQUIRED )
99 110
 # This library is needed only for Ubuntu it seems, some platforms don't even
100 111
 # ship with it. I couldn't find a way to do a test compile to check if librt
@@ -105,56 +116,53 @@ set( CMAKE_CXX_FLAGS
105 116
      "${CMAKE_CXX_FLAGS} ${CMAKE_IMLIB2_CXX_FLAGS}" )
106 117
 
107 118
 # Includes
119
+include_directories( "${X11_INCLUDE_DIR}"
120
+                     "${XEXT_INCLUDE_DIR}" )
121
+
122
+if ( CMAKE_OPENGL_SUPPORT )
123
+include_directories( "${IMLIB2_INCLUDE_DIR}"
124
+                     "${XRANDR_INCLUDE_DIR}"
125
+                     "${OPENGL_INCLUDE_DIR}"
126
+                     "${GLX_INCLUDE_DIR}"
127
+                     ${GLEW_INCLUDE_DIRS}
128
+                     ${XRENDER_INCLUDE_DIRS} )
129
+endif()
130
+
108 131
 if ( RT_INCLUDE_DIR )
109
-    include_directories( ${X11_INCLUDE_DIR}
110
-                         ${XEXT_INCLUDE_DIR}
111
-                         ${XRANDR_INCLUDE_DIR}
112
-                         ${OPENGL_INCLUDE_DIR}
113
-                         ${IL_INCLUDE_DIR}
114
-                         ${GLX_INCLUDE_DIR}
115
-                         ${GLEW_INCLUDE_DIRS}
116
-                         ${XRENDER_INCLUDE_DIRS}
117
-                         ${RT_INCLUDE_DIR} )
118
-else()
119
-    include_directories( ${X11_INCLUDE_DIR}
120
-                         ${OPENGL_INCLUDE_DIR}
121
-                         ${IL_INCLUDE_DIR}
122
-                         ${GLEW_INCLUDE_DIRS}
123
-                         ${GLX_INCLUDE_DIR}
124
-                         ${XEXT_INCLUDE_DIR} )
132
+    include_directories( ${RT_INCLUDE_DIR} )
125 133
 endif()
126 134
 
127 135
 # Executable
128 136
 add_executable( "${BIN_TARGET}" ${source} )
129 137
 
130 138
 # Libraries
131
-if ( RT_LIBRARY )
139
+target_link_libraries( "${BIN_TARGET}"
140
+                       ${X11_LIBRARIES}
141
+                       "${XEXT_LIBRARY}" )
142
+
143
+if ( CMAKE_OPENGL_SUPPORT )
132 144
     target_link_libraries( "${BIN_TARGET}"
133
-                           ${X11_LIBRARIES}
145
+                           ${IMLIB2_LIBRARIES}
134 146
                            ${OPENGL_LIBRARIES}
135
-                           ${IL_LIBRARIES}
136
-                           ${ILUT_LIBRARIES}
137 147
                            ${GLX_LIBRARIES}
138 148
                            ${GLEW_LIBRARIES}
139 149
                            ${XRENDER_LIBRARIES}
140
-                           "${XEXT_LIBRARY}"
141
-                           "${XRANDR_LIBRARY}"
142
-                           "${RT_LIBRARY}" )
143
-else()
150
+                           "${XRANDR_LIBRARY}" )
151
+endif()
152
+
153
+
154
+if ( RT_LIBRARY )
144 155
     target_link_libraries( "${BIN_TARGET}"
145
-                           ${OPENGL_LIBRARIES}
146
-                           ${IL_LIBRARIES}
147
-                           ${ILUT_LIBRARIES}
148
-                           ${GLEW_LIBRARIES}
149
-                           ${GLX_LIBRARIES}
150
-                           ${X11_LIBRARIES}
151
-                           "${XEXT_LIBRARY}" )
156
+                           "${RT_LIBRARY}" )
152 157
 endif()
153 158
 
154 159
 install( TARGETS ${BIN_TARGET}
155 160
          DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
156 161
 
157
-install( DIRECTORY "${CMAKE_SOURCE_DIR}/share"
158
-         DESTINATION "${CMAKE_INSTALL_PREFIX}" )
159
-
160 162
 add_definitions(-DINSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")
163
+
164
+if( CMAKE_OPENGL_SUPPORT )
165
+    install( DIRECTORY "${CMAKE_SOURCE_DIR}/share"
166
+             DESTINATION "${CMAKE_INSTALL_PREFIX}" )
167
+    add_definitions(-DOPENGL_ENABLED=1)
168
+endif()

+ 91
- 0
cmakemodules/FindImlib2.cmake Datei anzeigen

@@ -0,0 +1,91 @@
1
+#
2
+# This module finds if IMLIB2 is available and determines where the
3
+# include files and libraries are.
4
+# On Unix/Linux it relies on the output of imlib2-config.
5
+# This code sets the following variables:
6
+#
7
+#
8
+#
9
+# IMLIB2_FOUND              = system has IMLIB2 lib
10
+#
11
+# IMLIB2_LIBRARIES          = full path to the libraries
12
+#    on Unix/Linux with additional linker flags from "imlib2-config --libs"
13
+#
14
+# CMAKE_IMLIB2_CXX_FLAGS    = Unix compiler flags for IMLIB2, essentially "`imlib2-config --cxxflags`"
15
+#
16
+# IMLIB2_INCLUDE_DIR        = where to find headers
17
+#
18
+# IMLIB2_LINK_DIRECTORIES   = link directories, useful for rpath on Unix
19
+#
20
+#
21
+# author Jan Woetzel and Jan-Friso Evers
22
+# www.mip.informatik.uni-kiel.de/~jw
23
+
24
+IF(WIN32)
25
+    MESSAGE("FindIMLIB2.cmake: IMLIB2 not (yet) supported on WIN32")
26
+    SET(IMLIB2_FOUND OFF	)
27
+ELSE(WIN32)
28
+    IF(UNIX)
29
+        SET(IMLIB2_CONFIG_PREFER_PATH "$ENV{IMLIB2_HOME}/bin" CACHE STRING "preferred path to imlib2")
30
+        FIND_PROGRAM(IMLIB2_CONFIG imlib2-config
31
+                     ${IMLIB2_CONFIG_PREFER_PATH}
32
+                     /usr/bin/
33
+                     /opt/gnome/bin/)
34
+
35
+        IF (IMLIB2_CONFIG)
36
+            # OK, found imlib2-config.
37
+            # set CXXFLAGS to be fed into CXX_FLAGS by the user:
38
+            SET(IMLIB2_CXX_FLAGS "`${IMLIB2_CONFIG} --cflags`")
39
+
40
+            # set INCLUDE_DIRS to prefix+include
41
+            EXEC_PROGRAM(${IMLIB2_CONFIG}
42
+            ARGS --prefix
43
+            OUTPUT_VARIABLE IMLIB2_PREFIX)
44
+            SET(IMLIB2_INCLUDE_DIR ${IMLIB2_PREFIX}/include CACHE STRING INTERNAL)
45
+
46
+            # extract link dirs for rpath
47
+            EXEC_PROGRAM(${IMLIB2_CONFIG}
48
+                         ARGS --libs
49
+                         OUTPUT_VARIABLE IMLIB2_CONFIG_LIBS)
50
+
51
+            # set link libraries and link flags
52
+            #SET(IMLIB2_LIBRARIES "`${IMLIB2_CONFIG} --libs`")
53
+            SET(IMLIB2_LIBRARIES ${IMLIB2_CONFIG_LIBS})
54
+
55
+            # split off the link dirs (for rpath)
56
+            # use regular expression to match wildcard equivalent "-L*<endchar>"
57
+            # with <endchar> is a space or a semicolon
58
+            STRING(REGEX MATCHALL "[-][L]([^ ;])+"
59
+                   IMLIB2_LINK_DIRECTORIES_WITH_PREFIX
60
+                   "${IMLIB2_CONFIG_LIBS}")
61
+            #MESSAGE("DBG  IMLIB2_LINK_DIRECTORIES_WITH_PREFIX=${IMLIB2_LINK_DIRECTORIES_WITH_PREFIX}")
62
+
63
+            # remove prefix -L because we need the pure directory for LINK_DIRECTORIES
64
+            # replace -L by ; because the separator seems to be lost otherwise (bug or feature?)
65
+            IF (IMLIB2_LINK_DIRECTORIES_WITH_PREFIX)
66
+                STRING(REGEX REPLACE "[-][L]" ";" IMLIB2_LINK_DIRECTORIES ${IMLIB2_LINK_DIRECTORIES_WITH_PREFIX} )
67
+                #MESSAGE("DBG  IMLIB2_LINK_DIRECTORIES=${IMLIB2_LINK_DIRECTORIES}")
68
+            ENDIF (IMLIB2_LINK_DIRECTORIES_WITH_PREFIX)
69
+
70
+            # replace space separated string by semicolon separated vector to make 
71
+            # it work with LINK_DIRECTORIES
72
+            SEPARATE_ARGUMENTS(IMLIB2_LINK_DIRECTORIES)
73
+
74
+            MARK_AS_ADVANCED(IMLIB2_CXX_FLAGS
75
+                             IMLIB2_INCLUDE_DIR
76
+                             IMLIB2_LIBRARIES
77
+                             IMLIB2_LINK_DIRECTORIES
78
+                             IMLIB2_CONFIG_PREFER_PATH
79
+                             IMLIB2_CONFIG)
80
+
81
+        ELSE(IMLIB2_CONFIG)
82
+            MESSAGE( "FindIMLIB2.cmake: imlib2-config not found. Please set it manually. IMLIB2_CONFIG=${IMLIB2_CONFIG}")
83
+        ENDIF(IMLIB2_CONFIG)
84
+    ENDIF(UNIX)
85
+ENDIF(WIN32)
86
+
87
+IF(IMLIB2_LIBRARIES)
88
+    IF(IMLIB2_INCLUDE_DIR OR IMLIB2_CXX_FLAGS)
89
+        SET(IMLIB2_FOUND 1)
90
+    ENDIF(IMLIB2_INCLUDE_DIR OR IMLIB2_CXX_FLAGS)
91
+ENDIF(IMLIB2_LIBRARIES)

+ 1
- 1
src/framebuffer.cpp Datei anzeigen

@@ -90,7 +90,7 @@ slop::Framebuffer::Framebuffer( unsigned int width, unsigned int height, unsigne
90 90
         //Make sure we unbind when we're done.
91 91
         glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
92 92
     } else {
93
-        fprintf( stderr, "Error: Failed to create framebuffer! You need OpenGL 3.0 or the GL_EXT_framebuffer_object extension!\n" );
93
+        throw std::runtime_error( "Error: Failed to create framebuffer! You need OpenGL 3.0 or the GL_EXT_framebuffer_object extension!" );
94 94
     }
95 95
 }
96 96
 

+ 124
- 53
src/glselectrectangle.cpp Datei anzeigen

@@ -27,6 +27,7 @@ slop::GLSelectRectangle::~GLSelectRectangle() {
27 27
     if ( m_window == None ) {
28 28
         return;
29 29
     }
30
+    xengine->freeCRTCS( m_monitors );
30 31
     delete m_framebuffer;
31 32
     // Try to erase the window before destroying it.
32 33
     glClearColor( 0, 0, 0, 0 );
@@ -229,7 +230,7 @@ void slop::GLSelectRectangle::generateMagnifyingGlass() {
229 230
 }
230 231
 
231 232
 void slop::GLSelectRectangle::setTheme( bool on, std::string name ) {
232
-    if ( !on ) {
233
+    if ( !on || name == "none" ) {
233 234
         return;
234 235
     }
235 236
     std::string root = resource->getRealPath( name );
@@ -248,29 +249,99 @@ void slop::GLSelectRectangle::setTheme( bool on, std::string name ) {
248 249
         return;
249 250
     }
250 251
     // Otherwise we load each one :)
251
-    ilInit();
252
-    ilutInit();
253
-    ilutRenderer(ILUT_OPENGL);
254
-    ILuint corner;
255
-    ilGenImages( 1, &corner );
256
-    ilBindImage( corner );
257
-    ilLoadImage( tl.c_str() );
258
-    m_cornerids[0] = ilutGLBindMipmaps();
259
-    ilLoadImage( tr.c_str() );
260
-    m_cornerids[1] = ilutGLBindMipmaps();
261
-    ilLoadImage( bl.c_str() );
262
-    m_cornerids[2] = ilutGLBindMipmaps();
263
-    ilLoadImage( br.c_str() );
264
-    m_cornerids[3] = ilutGLBindMipmaps();
265
-    ilLoadImage( straight.c_str() );
266
-    m_straightwidth = ilGetInteger( IL_IMAGE_WIDTH );
267
-    m_straightheight = ilGetInteger( IL_IMAGE_HEIGHT );
268
-    m_straightid = ilutGLBindMipmaps();
269
-    // And clean up after.
270
-    ilDeleteImages( 1, &corner );
252
+    loadImage( &(m_cornerids[0]), tl );
253
+    loadImage( &(m_cornerids[1]), tr );
254
+    loadImage( &(m_cornerids[2]), bl );
255
+    loadImage( &(m_cornerids[3]), br );
256
+    loadImage( &(m_straightid), straight );
257
+    glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &m_straightwidth );
258
+    glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &m_straightheight );
271 259
     m_themed = on;
272 260
 }
273 261
 
262
+unsigned int slop::GLSelectRectangle::loadImage( unsigned int* texture, std::string path ) {
263
+    glActiveTexture(GL_TEXTURE0);
264
+    glEnable(GL_TEXTURE_2D);
265
+    glGenTextures( 1, texture );
266
+    glBindTexture( GL_TEXTURE_2D, *texture );
267
+    Imlib_Load_Error err;
268
+    Imlib_Image image = imlib_load_image_with_error_return( path.c_str(), &err );
269
+    if ( err != IMLIB_LOAD_ERROR_NONE ) {
270
+        std::string message = "Failed to load image: ";
271
+        message += path;
272
+        message += "\n\t";
273
+        switch( err ) {
274
+            default: {
275
+                message += "unknown error ";
276
+                message += (int)err;
277
+                message += "\n";
278
+                break;
279
+            }
280
+            case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS:
281
+                message += "out of file descriptors\n";
282
+                break;
283
+            case IMLIB_LOAD_ERROR_OUT_OF_MEMORY:
284
+                message += "out of memory\n";
285
+                break;
286
+            case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS:
287
+                message += "path contains too many symbolic links\n";
288
+                break;
289
+            case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE:
290
+                message += "path points outside address space\n";
291
+                break;
292
+            case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY:
293
+                message += "path component is not a directory\n";
294
+                break;
295
+            case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT:
296
+                message += "path component is non-existant (~ isn't expanded inside quotes!)\n";
297
+                break;
298
+            case IMLIB_LOAD_ERROR_PATH_TOO_LONG:
299
+                message += "path is too long\n";
300
+                break;
301
+            case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT:
302
+                message += "no loader for file format (unsupported format)\n";
303
+                break;
304
+            case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: {
305
+                message += "not enough disk space\n";
306
+                break;
307
+            }
308
+            case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: {
309
+                message += "file does not exist\n";
310
+                break;
311
+            }
312
+            case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: {
313
+                message += "file is a directory\n";
314
+                break;
315
+            }
316
+            case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE:
317
+            case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: {
318
+                message += "permission denied\n";
319
+                break;
320
+            }
321
+        }
322
+        throw std::runtime_error( message.c_str() );
323
+        return *texture;
324
+    }
325
+    imlib_context_set_image( image );
326
+    DATA32* data = imlib_image_get_data_for_reading_only();
327
+    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, imlib_image_get_width(), imlib_image_get_height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)data );
328
+    if ( GLEW_VERSION_3_0 ) {
329
+        glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST );
330
+        glGenerateMipmap( GL_TEXTURE_2D );
331
+        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
332
+        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );
333
+    } else {
334
+        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
335
+        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
336
+    }
337
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
338
+    imlib_free_image();
339
+    glDisable(GL_TEXTURE_2D);
340
+    return *texture;
341
+}
342
+
343
+
344
+
274 345
 slop::GLSelectRectangle::GLSelectRectangle( int sx, int sy, int ex, int ey, int border, bool highlight, float r, float g, float b, float a ) {
275 346
     m_x = std::min( sx, ex );
276 347
     m_y = std::min( sy, ey );
@@ -475,57 +546,57 @@ void slop::GLSelectRectangle::update( double dt ) {
475 546
         //float ratio = ((float)m_straightwidth/(float)m_straightheight);
476 547
         glBegin( GL_QUADS );
477 548
         // straight top
478
-        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border/2, m_y-m_border );
479
-        glTexCoord2f(txoffset, 1.0); glVertex2f( m_x+m_width+m_border/2, m_y-m_border );
480
-        glTexCoord2f(txoffset, 0.0); glVertex2f( m_x+m_width+m_border/2, m_y );
481
-        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border/2, m_y );
549
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border/2, m_y-m_border );
550
+        glTexCoord2f(txoffset, 0.0); glVertex2f( m_x+m_width+m_border/2, m_y-m_border );
551
+        glTexCoord2f(txoffset, 1.0); glVertex2f( m_x+m_width+m_border/2, m_y );
552
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border/2, m_y );
482 553
         // straight bot
483
-        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border/2, m_y+m_height );
484
-        glTexCoord2f(txoffset, 1.0); glVertex2f( m_x+m_width+m_border/2, m_y+m_height );
485
-        glTexCoord2f(txoffset, 0.0); glVertex2f( m_x+m_width+m_border/2, m_y+m_height+m_border );
486
-        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border/2, m_y+m_height+m_border );
554
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border/2, m_y+m_height );
555
+        glTexCoord2f(txoffset, 0.0); glVertex2f( m_x+m_width+m_border/2, m_y+m_height );
556
+        glTexCoord2f(txoffset, 1.0); glVertex2f( m_x+m_width+m_border/2, m_y+m_height+m_border );
557
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border/2, m_y+m_height+m_border );
487 558
         // straight left
488
-        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border, m_y-m_border/2 );
489
-        glTexCoord2f(0.0, 1.0); glVertex2f( m_x, m_y-m_border/2 );
490
-        glTexCoord2f(tyoffset, 1.0); glVertex2f( m_x, m_y+m_height+m_border/2 );
491
-        glTexCoord2f(tyoffset, 0.0); glVertex2f( m_x-m_border, m_y+m_height+m_border/2 );
559
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border, m_y-m_border/2 );
560
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x, m_y-m_border/2 );
561
+        glTexCoord2f(tyoffset, 0.0); glVertex2f( m_x, m_y+m_height+m_border/2 );
562
+        glTexCoord2f(tyoffset, 1.0); glVertex2f( m_x-m_border, m_y+m_height+m_border/2 );
492 563
         // straight right
493
-        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width, m_y-m_border/2 );
494
-        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width+m_border, m_y-m_border/2 );
495
-        glTexCoord2f(tyoffset, 1.0); glVertex2f( m_x+m_width+m_border, m_y+m_height+m_border/2 );
496
-        glTexCoord2f(tyoffset, 0.0); glVertex2f( m_x+m_width, m_y+m_height+m_border/2 );
564
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width, m_y-m_border/2 );
565
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width+m_border, m_y-m_border/2 );
566
+        glTexCoord2f(tyoffset, 0.0); glVertex2f( m_x+m_width+m_border, m_y+m_height+m_border/2 );
567
+        glTexCoord2f(tyoffset, 1.0); glVertex2f( m_x+m_width, m_y+m_height+m_border/2 );
497 568
         glEnd();
498 569
         // top left corner
499 570
         glBindTexture( GL_TEXTURE_2D, m_cornerids[0] );
500 571
         glBegin( GL_QUADS );
501
-        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border, m_y-m_border );
502
-        glTexCoord2f(1.0, 1.0); glVertex2f( m_x, m_y-m_border );
503
-        glTexCoord2f(1.0, 0.0); glVertex2f( m_x, m_y );
504
-        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border, m_y );
572
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border, m_y-m_border );
573
+        glTexCoord2f(1.0, 0.0); glVertex2f( m_x, m_y-m_border );
574
+        glTexCoord2f(1.0, 1.0); glVertex2f( m_x, m_y );
575
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border, m_y );
505 576
         glEnd();
506 577
         // top right
507 578
         glBindTexture( GL_TEXTURE_2D, m_cornerids[1] );
508 579
         glBegin( GL_QUADS );
509
-        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width, m_y-m_border );
510
-        glTexCoord2f(1.0, 1.0); glVertex2f( m_x+m_width+m_border, m_y-m_border );
511
-        glTexCoord2f(1.0, 0.0); glVertex2f( m_x+m_width+m_border, m_y );
512
-        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width, m_y );
580
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width, m_y-m_border );
581
+        glTexCoord2f(1.0, 0.0); glVertex2f( m_x+m_width+m_border, m_y-m_border );
582
+        glTexCoord2f(1.0, 1.0); glVertex2f( m_x+m_width+m_border, m_y );
583
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width, m_y );
513 584
         glEnd();
514 585
         // bottom left
515 586
         glBindTexture( GL_TEXTURE_2D, m_cornerids[2] );
516 587
         glBegin( GL_QUADS );
517
-        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border, m_y+m_height );
518
-        glTexCoord2f(1.0, 1.0); glVertex2f( m_x, m_y+m_height );
519
-        glTexCoord2f(1.0, 0.0); glVertex2f( m_x, m_y+m_height+m_border );
520
-        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border, m_y+m_height+m_border );
588
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x-m_border, m_y+m_height );
589
+        glTexCoord2f(1.0, 0.0); glVertex2f( m_x, m_y+m_height );
590
+        glTexCoord2f(1.0, 1.0); glVertex2f( m_x, m_y+m_height+m_border );
591
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x-m_border, m_y+m_height+m_border );
521 592
         glEnd();
522 593
         // bottom right
523 594
         glBindTexture( GL_TEXTURE_2D, m_cornerids[2] );
524 595
         glBegin( GL_QUADS );
525
-        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width, m_y+m_height );
526
-        glTexCoord2f(1.0, 1.0); glVertex2f( m_x+m_width+m_border, m_y+m_height );
527
-        glTexCoord2f(1.0, 0.0); glVertex2f( m_x+m_width+m_border, m_y+m_height+m_border );
528
-        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width, m_y+m_height+m_border );
596
+        glTexCoord2f(0.0, 0.0); glVertex2f( m_x+m_width, m_y+m_height );
597
+        glTexCoord2f(1.0, 0.0); glVertex2f( m_x+m_width+m_border, m_y+m_height );
598
+        glTexCoord2f(1.0, 1.0); glVertex2f( m_x+m_width+m_border, m_y+m_height+m_border );
599
+        glTexCoord2f(0.0, 1.0); glVertex2f( m_x+m_width, m_y+m_height+m_border );
529 600
         glEnd();
530 601
     }
531 602
 

+ 5
- 5
src/glselectrectangle.hpp Datei anzeigen

@@ -28,13 +28,11 @@
28 28
 
29 29
 #include <unistd.h>
30 30
 
31
+#include <Imlib2.h>
31 32
 #include <GL/gl.h>
32 33
 #include <GL/glx.h>
33 34
 #include <GL/glew.h>
34 35
 #include <GL/glxext.h>
35
-#define ILUT_USE_OPENGL
36
-#include <IL/il.h>
37
-#include <IL/ilut.h>
38 36
 #include <X11/Xlib.h>
39 37
 #include <X11/Xatom.h>
40 38
 #include <X11/extensions/Xrender.h>
@@ -76,8 +74,8 @@ public:
76 74
     unsigned int        m_texid;
77 75
     unsigned int        m_cornerids[4];
78 76
     unsigned int        m_straightid;
79
-    unsigned int        m_straightwidth;
80
-    unsigned int        m_straightheight;
77
+    int                 m_straightwidth;
78
+    int                 m_straightheight;
81 79
     int                 m_offsetx;
82 80
     int                 m_offsety;
83 81
     int                 m_offsetw;
@@ -95,6 +93,8 @@ public:
95 93
     std::string         m_shader;
96 94
     std::vector<XRRCrtcInfo*> m_monitors;
97 95
     slop::Framebuffer*  m_framebuffer;
96
+private:
97
+    unsigned int loadImage( unsigned int* texture, std::string path );
98 98
 };
99 99
 
100 100
 }

+ 23
- 0
src/main.cpp Datei anzeigen

@@ -22,6 +22,7 @@
22 22
 #include <cstdio>
23 23
 #include <sstream>
24 24
 #include <execinfo.h>
25
+#include <stdexcept>
25 26
 
26 27
 #ifdef __MACH__
27 28
 #include <mach/clock.h>
@@ -30,7 +31,9 @@
30 31
 
31 32
 #include "x.hpp"
32 33
 #include "selectrectangle.hpp"
34
+#ifdef OPENGL_ENABLED
33 35
 #include "glselectrectangle.hpp"
36
+#endif //OPENGL_ENABLED
34 37
 #include "xselectrectangle.hpp"
35 38
 #include "cmdline.h"
36 39
 
@@ -251,6 +254,7 @@ int app( int argc, char** argv ) {
251 254
     bool decorations = !options.nodecorations_flag;
252 255
     bool themeon = (bool)options.theme_given;
253 256
     std::string theme = options.theme_arg;
257
+    bool shadergiven = (bool)options.shader_given;
254 258
     std::string shader = options.shader_arg;
255 259
     struct timespec start, time;
256 260
     int xoffset = 0;
@@ -278,6 +282,15 @@ int app( int argc, char** argv ) {
278 282
     }
279 283
     unsigned int magpixels = (unsigned int)options.magpixels_arg;
280 284
     cmdline_parser_free( &options );
285
+#ifndef OPENGL_ENABLED
286
+    if ( opengl || themeon || magenabled ) {
287
+        throw std::runtime_error( "Slop wasn't compiled with OpenGL support, so themes, magnifications, and shaders are disabled! Try compiling it with the CMAKE_OPENGL_ENABLED set to true." );
288
+    }
289
+#else // OPENGL_ENABLED
290
+    if ( ( themeon || magenabled || shadergiven ) && !opengl ) {
291
+        throw std::runtime_error( "Slop needs --opengl enabled to use themes, shaders, or magnifications." );
292
+    }
293
+#endif
281 294
 
282 295
     // First we set up the x interface and grab the mouse,
283 296
     // if we fail for either we exit immediately.
@@ -364,6 +377,7 @@ int app( int argc, char** argv ) {
364 377
                     t.applyMinMaxSize( minimumsize, maximumsize );
365 378
                     // Make sure we only apply offsets to windows that we've forcibly removed decorations on.
366 379
                     if ( !selection ) {
380
+#ifdef OPENGL_ENABLED
367 381
                         if ( opengl ) {
368 382
                             selection = new slop::GLSelectRectangle( t.m_x, t.m_y,
369 383
                                                                      t.m_x + t.m_width,
@@ -376,13 +390,16 @@ int app( int argc, char** argv ) {
376 390
                             ((slop::GLSelectRectangle*)(selection))->setTheme( themeon, theme );
377 391
                             ((slop::GLSelectRectangle*)(selection))->setShader( shader );
378 392
                         } else {
393
+#endif // OPENGL_ENABLED
379 394
                             selection = new slop::XSelectRectangle( t.m_x, t.m_y,
380 395
                                                                     t.m_x + t.m_width,
381 396
                                                                     t.m_y + t.m_height,
382 397
                                                                     borderSize,
383 398
                                                                     highlight,
384 399
                                                                     r, g, b, a );
400
+#ifdef OPENGL_ENABLED
385 401
                         }
402
+#endif // OPENGL_ENABLED
386 403
                     } else {
387 404
                         selection->setGeo( t.m_x, t.m_y, t.m_x + t.m_width, t.m_y + t.m_height );
388 405
                     }
@@ -424,6 +441,7 @@ int app( int argc, char** argv ) {
424 441
                 if ( !selection ) {
425 442
                     int sx, sy, ex, ey;
426 443
                     constrain( cx, cy, xengine->m_mousex, xengine->m_mousey, padding, minimumsize, maximumsize, &sx, &sy, &ex, &ey );
444
+#ifdef OPENGL_ENABLED
427 445
                     if ( opengl ) {
428 446
                         selection = new slop::GLSelectRectangle( sx, sy,
429 447
                                                                  ex, ey,
@@ -435,12 +453,15 @@ int app( int argc, char** argv ) {
435 453
                         ((slop::GLSelectRectangle*)(selection))->setTheme( themeon, theme );
436 454
                         ((slop::GLSelectRectangle*)(selection))->setShader( shader );
437 455
                     } else {
456
+#endif // OPENGL_ENABLED
438 457
                         selection = new slop::XSelectRectangle( sx, sy,
439 458
                                                                 ex, ey,
440 459
                                                                 borderSize,
441 460
                                                                 highlight,
442 461
                                                                 r, g, b, a );
462
+#ifdef OPENGL_ENABLED
443 463
                     }
464
+#endif // OPENGL_ENABLED
444 465
                 }
445 466
                 windowmemory = window;
446 467
                 // If the user has let go of the mouse button, we'll just
@@ -537,6 +558,8 @@ int main( int argc, char** argv ) {
537 558
         fprintf( stderr, "Unhandled Exception Thrown: %s\n", exception.what() );
538 559
     } catch( std::string err ) {
539 560
         fprintf( stderr, "Unhandled Exception Thrown: %s\n", err.c_str() );
561
+    } catch( char* err ) {
562
+        fprintf( stderr, "Unhandled Exception Thrown: %s\n", err );
540 563
     } catch( ... ) {
541 564
         fprintf( stderr, "Unknown Exception Thrown!\n" );
542 565
     }

+ 10
- 0
src/x.cpp Datei anzeigen

@@ -104,7 +104,9 @@ int slop::XEngine::init( std::string display ) {
104 104
     //m_root      = RootWindow     ( m_display, XScreenNumberOfScreen( m_screen ) );
105 105
     m_root      = DefaultRootWindow( m_display );
106 106
 
107
+#ifdef OPENGL_ENABLED
107 108
     m_res = XRRGetScreenResourcesCurrent( m_display, m_root);
109
+#endif // OPENGL_ENABLED
108 110
 
109 111
     m_good = true;
110 112
     XSetErrorHandler( slop::XEngineErrorHandler );
@@ -112,6 +114,7 @@ int slop::XEngine::init( std::string display ) {
112 114
     return EXIT_SUCCESS;
113 115
 }
114 116
 
117
+#ifdef OPENGL_ENABLED
115 118
 std::vector<XRRCrtcInfo*> slop::XEngine::getCRTCS() {
116 119
     std::vector<XRRCrtcInfo*> monitors;
117 120
     if ( !m_res ) {
@@ -123,6 +126,13 @@ std::vector<XRRCrtcInfo*> slop::XEngine::getCRTCS() {
123 126
     return monitors;
124 127
 }
125 128
 
129
+void slop::XEngine::freeCRTCS( std::vector<XRRCrtcInfo*> monitors ) {
130
+    for ( unsigned int i=0;i<monitors.size();i++ ) {
131
+        XRRFreeCrtcInfo( monitors[ i ] );
132
+    }
133
+}
134
+#endif // OPENGL_ENABLED
135
+
126 136
 bool slop::XEngine::keyPressed( KeySym key ) {
127 137
     KeyCode keycode = XKeysymToKeycode( m_display, key );
128 138
     if ( keycode != 0 ) {

+ 2
- 0
src/x.hpp Datei anzeigen

@@ -82,8 +82,10 @@ public:
82 82
     void                drawRect( int x, int y, unsigned int w, unsigned int h );
83 83
     unsigned int        getWidth();
84 84
     unsigned int        getHeight();
85
+#ifdef OPENGL_ENABLED
85 86
     std::vector<XRRCrtcInfo*>        getCRTCS();
86 87
     void                freeCRTCS( std::vector<XRRCrtcInfo*> monitors );
88
+#endif // OPENGL_ENABLED
87 89
     int                 m_mousex;
88 90
     int                 m_mousey;
89 91
     Display*            m_display;