Преглед изворни кода

added some comments and separated options parsing to its own object

naelstrof пре 11 година
родитељ
комит
47bcbc0432
6 измењених фајлова са 230 додато и 120 уклоњено
  1. 52
    94
      main.cpp
  2. 1
    1
      makefile
  3. 124
    0
      options.cpp
  4. 28
    0
      options.hpp
  5. 20
    20
      x.cpp
  6. 5
    5
      x.hpp

+ 52
- 94
main.cpp Прегледај датотеку

1
 #include <unistd.h>
1
 #include <unistd.h>
2
 #include <cstdio>
2
 #include <cstdio>
3
 #include "x.hpp"
3
 #include "x.hpp"
4
-
5
-int borderSize = 10;
6
-int padding = 0;
7
-std::string xserver = ":0";
8
-
9
-void printHelp() {
10
-    printf( "Usage: slrn [options]\n" );
11
-    printf( "Print user selected region to stdout.\n" );
12
-    printf( "\n" );
13
-    printf( "options\n" );
14
-    printf( "    -h, --help                     show this message.\n" );
15
-    printf( "    -b=INT, --bordersize=INT       set selection rectangle border size.\n" );
16
-    printf( "    -p=INT, --padding=INT          set padding size for selection.\n" );
17
-    printf( "    -x=STRING, --xdisplay=STRING   set x display (STRING must be hostname:number.screen_number format)\n" );
18
-    printf( "examples\n" );
19
-    printf( "    slrn -b=10 -x=:0 -p=-30\n" );
20
-}
21
-
22
-int parseOptions( int argc, char** argv ) {
23
-    for ( int i=0; i<argc; i++ ) {
24
-        std::string arg = argv[i];
25
-        if ( arg.substr( 0, 3 ) == "-b=" || arg.substr( 0, 13 ) == "--bordersize=" ) {
26
-            int find = arg.find( "=" );
27
-            if ( find != arg.npos ) {
28
-                arg.at( find ) = ' ';
29
-            }
30
-            int num = sscanf( arg.c_str(), "%*s %i", &borderSize );
31
-            if ( borderSize < 0 ) {
32
-                borderSize = 0;
33
-            }
34
-            if ( num != 1 ) {
35
-                printf( "Error parsing command arguments near %s\n", argv[i] );
36
-                printf( "Usage: -b=INT or --bordersize=INT\n" );
37
-                printf( "Example: -b=10 or --bordersize=12\n" );
38
-                return 1;
39
-            }
40
-        } else if ( arg.substr( 0, 3 ) == "-p=" || arg.substr( 0, 10 ) == "--padding=" ) {
41
-            int find = arg.find( "=" );
42
-            if ( find != arg.npos ) {
43
-                arg.at( find ) = ' ';
44
-            }
45
-            int num = sscanf( arg.c_str(), "%*s %i", &padding );
46
-            if ( num != 1 ) {
47
-                printf( "Error parsing command arguments near %s\n", argv[i] );
48
-                printf( "Usage: -p=INT or --padding=INT\n" );
49
-                printf( "Example: -p=0 or --padding=-12\n" );
50
-                return 1;
51
-            }
52
-        } else if ( arg.substr( 0, 3 ) == "-x=" || arg.substr( 0, 11 ) == "--xdisplay=" ) {
53
-            int find = arg.find( "=" );
54
-            if ( find != arg.npos ) {
55
-                arg.at( find ) = ' ';
56
-            }
57
-            char* x = new char[ arg.size() ];
58
-            int num = sscanf( arg.c_str(), "%*s %s", x );
59
-            if ( num != 1 ) {
60
-                printf( "Error parsing command arguments near %s\n", argv[i] );
61
-                printf( "Usage: -x=STRING or --xserver=STRING.\n" );
62
-                printf( "Example: -x=:0 or --xserver=winston:1.3\n" );
63
-                delete[] x;
64
-                return 1;
65
-            }
66
-            xserver = x;
67
-            delete[] x;
68
-        } else if ( arg == "-h" || arg == "--help" ) {
69
-            printHelp();
70
-            return 2;
71
-        } else {
72
-            if ( i == 0 ) {
73
-                continue;
74
-            }
75
-            printf( "Error: Unknown argument %s\n", argv[i] );
76
-            printf( "Try -h or --help for help.\n" );
77
-            return 1;
78
-        }
79
-    }
80
-    return 0;
81
-}
4
+#include "options.hpp"
82
 
5
 
83
 int main( int argc, char** argv ) {
6
 int main( int argc, char** argv ) {
84
-    int err = parseOptions( argc, argv );
7
+    int err = options->parseOptions( argc, argv );
85
     if ( err ) {
8
     if ( err ) {
86
         return err;
9
         return err;
87
     }
10
     }
88
     int state = 0;
11
     int state = 0;
89
     bool running = true;
12
     bool running = true;
90
-    is::Rectangle* selection;
91
-    is::Rectangle* windowselection = NULL;
13
+    slrn::Rectangle* selection;
14
+    slrn::Rectangle* windowselection = NULL;
92
     Window window = None;
15
     Window window = None;
16
+    std::string xdisplay = options->m_xdisplay;
17
+    int padding = options->m_padding;
18
+    int borderSize = options->m_borderSize;
19
+    int tolerance = options->m_tolerance;
93
 
20
 
94
-    err = xengine->init( xserver.c_str() );
21
+    // First we set up the x interface and grab the mouse,
22
+    // if we fail for either we exit immediately.
23
+    err = xengine->init( xdisplay.c_str() );
95
     if ( err ) {
24
     if ( err ) {
96
         return err;
25
         return err;
97
     }
26
     }
98
-    err = xengine->grabCursor( is::Cross );
27
+    err = xengine->grabCursor( slrn::Cross );
99
     if ( err ) {
28
     if ( err ) {
100
         return err;
29
         return err;
101
     }
30
     }
102
     while ( running ) {
31
     while ( running ) {
32
+        // "ticking" the xengine makes it process all queued events.
103
         xengine->tick();
33
         xengine->tick();
104
         if ( xengine->mouseDown( 3 ) ) {
34
         if ( xengine->mouseDown( 3 ) ) {
105
             printf( "X=0\n" );
35
             printf( "X=0\n" );
110
             state = -1;
40
             state = -1;
111
             running = false;
41
             running = false;
112
         }
42
         }
43
+        // Our adorable little state manager will handle what state we're in.
113
         switch ( state ) {
44
         switch ( state ) {
114
             default: {
45
             default: {
115
                 break;
46
                 break;
116
             }
47
             }
117
             case 0: {
48
             case 0: {
49
+                // If xengine has found a window we're hovering over (or if it changed)
50
+                // create a rectangle around it so the user knows he/she can click on it.
118
                 if ( window != xengine->m_hoverXWindow ) {
51
                 if ( window != xengine->m_hoverXWindow ) {
52
+                    // Make sure to delete the old selection rectangle.
119
                     if ( windowselection ) {
53
                     if ( windowselection ) {
120
-                        xengine->removeRect( windowselection );
54
+                        xengine->removeRect( windowselection ); // removeRect also dealloc's the rectangle for us.
121
                     }
55
                     }
122
-                    is::WindowRectangle t = xengine->m_hoverWindow;
123
-                    windowselection = new is::Rectangle( t.m_x - t.m_border,
56
+                    slrn::WindowRectangle t = xengine->m_hoverWindow;
57
+                    windowselection = new slrn::Rectangle( t.m_x - t.m_border,
124
                                                          t.m_y - t.m_border,
58
                                                          t.m_y - t.m_border,
125
                                                          t.m_width + t.m_border,
59
                                                          t.m_width + t.m_border,
126
                                                          t.m_height + t.m_border,
60
                                                          t.m_height + t.m_border,
128
                     xengine->addRect( windowselection );
62
                     xengine->addRect( windowselection );
129
                     window = xengine->m_hoverXWindow;
63
                     window = xengine->m_hoverXWindow;
130
                 }
64
                 }
65
+                // If the user clicked, remove the old selection rectangle and then
66
+                // move on to the next state.
131
                 if ( xengine->mouseDown( 1 ) ) {
67
                 if ( xengine->mouseDown( 1 ) ) {
132
                     if ( windowselection ) {
68
                     if ( windowselection ) {
133
                         xengine->removeRect( windowselection );
69
                         xengine->removeRect( windowselection );
137
                 break;
73
                 break;
138
             }
74
             }
139
             case 1: {
75
             case 1: {
140
-                selection = new is::Rectangle( xengine->m_mousex, xengine->m_mousey, 0, 0, borderSize, padding );
76
+                // Simply create a new rectangle at the mouse position and move on
77
+                // to the next state.
78
+                selection = new slrn::Rectangle( xengine->m_mousex, xengine->m_mousey, 0, 0, borderSize, padding );
141
                 xengine->addRect( selection );
79
                 xengine->addRect( selection );
142
                 state++;
80
                 state++;
143
                 break;
81
                 break;
144
             }
82
             }
145
             case 2: {
83
             case 2: {
84
+                // If the user has let go of the mouse button, we'll just
85
+                // continue to the next state.
146
                 if ( !xengine->mouseDown( 1 ) ) {
86
                 if ( !xengine->mouseDown( 1 ) ) {
147
                     state++;
87
                     state++;
148
                     break;
88
                     break;
149
                 }
89
                 }
90
+                // Set the selection rectangle's dimensions to mouse movement.
91
+                // We use the function setDim since rectangles can't have negative widths,
92
+                // and because the rectangles have borders and padding to worry about.
150
                 selection->setDim( xengine->m_mousex - selection->m_x, xengine->m_mousey - selection->m_y );
93
                 selection->setDim( xengine->m_mousex - selection->m_x, xengine->m_mousey - selection->m_y );
94
+                // We also detect which way the user is pulling and set the mouse icon accordingly.
151
                 bool x = selection->m_flippedx;
95
                 bool x = selection->m_flippedx;
152
                 bool y = selection->m_flippedy;
96
                 bool y = selection->m_flippedy;
153
                 if ( !x && !y ) {
97
                 if ( !x && !y ) {
154
-                    xengine->setCursor( is::LowerRightCorner );
98
+                    xengine->setCursor( slrn::LowerRightCorner );
155
                 } else if ( x && !y ) {
99
                 } else if ( x && !y ) {
156
-                    xengine->setCursor( is::LowerLeftCorner );
100
+                    xengine->setCursor( slrn::LowerLeftCorner );
157
                 } else if ( !x && y ) {
101
                 } else if ( !x && y ) {
158
-                    xengine->setCursor( is::UpperRightCorner );
102
+                    xengine->setCursor( slrn::UpperRightCorner );
159
                 } else {
103
                 } else {
160
-                    xengine->setCursor( is::UpperLeftCorner );
104
+                    xengine->setCursor( slrn::UpperLeftCorner );
161
                 }
105
                 }
162
 
106
 
163
                 break;
107
                 break;
164
             }
108
             }
165
             case 3: {
109
             case 3: {
110
+                // We pull the dimensions and positions from the selection rectangle.
111
+                // The selection rectangle automatically converts the positions and
112
+                // dimensions to absolute coordinates when we set them earilier.
166
                 int x = selection->m_x+selection->m_xoffset;
113
                 int x = selection->m_x+selection->m_xoffset;
167
                 int y = selection->m_y+selection->m_yoffset;
114
                 int y = selection->m_y+selection->m_yoffset;
168
                 int w = selection->m_width;
115
                 int w = selection->m_width;
169
                 int h = selection->m_height;
116
                 int h = selection->m_height;
117
+                // Delete the rectangle.
170
                 xengine->removeRect( selection );
118
                 xengine->removeRect( selection );
119
+                // Exit the utility after this state runs once.
171
                 running = false;
120
                 running = false;
172
-                if ( w || h || xengine->m_hoverXWindow == None ) {
121
+                // If the user simply clicked (and thus made the width and height smaller than
122
+                // our tolerance) or if we're not hovering over a window, just print the selection
123
+                // rectangle's stuff.
124
+                if ( w > tolerance || h > tolerance || xengine->m_hoverXWindow == None ) {
173
                     printf( "X=%i\n", x );
125
                     printf( "X=%i\n", x );
174
                     printf( "Y=%i\n", y );
126
                     printf( "Y=%i\n", y );
175
                     printf( "W=%i\n", w + 1 );
127
                     printf( "W=%i\n", w + 1 );
176
                     printf( "H=%i\n", h + 1 );
128
                     printf( "H=%i\n", h + 1 );
177
                     break;
129
                     break;
178
                 }
130
                 }
179
-                is::WindowRectangle t = xengine->m_hoverWindow;
131
+                // Otherwise lets grab the window's dimensions and use those (with padding).
132
+                slrn::WindowRectangle t = xengine->m_hoverWindow;
180
                 x = t.m_x - padding - t.m_border;
133
                 x = t.m_x - padding - t.m_border;
181
                 y = t.m_y - padding - t.m_border;
134
                 y = t.m_y - padding - t.m_border;
182
                 w = t.m_width + t.m_border + padding*2;
135
                 w = t.m_width + t.m_border + padding*2;
188
                 break;
141
                 break;
189
             }
142
             }
190
         }
143
         }
191
-        // No need to max out CPU--
144
+        // No need to max out CPU
145
+        // FIXME: This could be adjusted to measure how much time has passed,
146
+        // we may very well need to max out the CPU if someone has a really- really
147
+        // bad computer.
192
         usleep( 1000 );
148
         usleep( 1000 );
193
     }
149
     }
150
+    // Clean up global classes.
194
     delete xengine;
151
     delete xengine;
152
+    delete options;
195
     return 0;
153
     return 0;
196
 }
154
 }

+ 1
- 1
makefile Прегледај датотеку

1
 CC=g++
1
 CC=g++
2
 CFLAGS=-O2 -g
2
 CFLAGS=-O2 -g
3
 LDFLAGS=-lX11 -lXext
3
 LDFLAGS=-lX11 -lXext
4
-SOURCES=main.cpp x.cpp
4
+SOURCES=main.cpp x.cpp options.cpp
5
 OBJECTS=$(SOURCES:.cpp=.o)
5
 OBJECTS=$(SOURCES:.cpp=.o)
6
 EXECUTABLE=slrn
6
 EXECUTABLE=slrn
7
 
7
 

+ 124
- 0
options.cpp Прегледај датотеку

1
+#include "options.hpp"
2
+
3
+slrn::Options* options = new slrn::Options();
4
+
5
+slrn::Options::Options() {
6
+    m_borderSize = 10;
7
+    m_padding = 0;
8
+    m_xdisplay = ":0";
9
+    m_tolerance = 4;
10
+}
11
+
12
+void slrn::Options::printHelp() {
13
+    printf( "Usage: slrn [options]\n" );
14
+    printf( "Print user selected region to stdout.\n" );
15
+    printf( "\n" );
16
+    printf( "options\n" );
17
+    printf( "    -h, --help                     show this message.\n" );
18
+    printf( "    -b=INT, --bordersize=INT       set selection rectangle border size.\n" );
19
+    printf( "    -p=INT, --m_padding=INT        set m_padding size for selection.\n" );
20
+    printf( "    -t=INT, --tolerance=INT        if you have a shaky mouse, increasing this value will make slrn detect single clicks better. Rather than interpreting your shaky clicks as region selections.\n" );
21
+    printf( "    -x=STRING, --xdisplay=STRING   set x display (STRING must be hostname:number.screen_number format)\n" );
22
+    printf( "examples\n" );
23
+    printf( "    slrn -b=10 -x=:0 -p=-30 -t=4\n" );
24
+}
25
+
26
+int slrn::Options::parseOptions( int argc, char** argv ) {
27
+    // Simple command parsing. Just uses sscanf to read each argument.
28
+    // It looks complicated because you have to have spaces for delimiters for sscanf.
29
+    for ( int i=0; i<argc; i++ ) {
30
+        std::string arg = argv[i];
31
+        if ( matches( arg, "--b=", "--bordersize=" ) ) {
32
+            int err = parseInt( arg, &m_borderSize );
33
+            if ( err ) {
34
+                return 1;
35
+            }
36
+            if ( m_borderSize < 0 ) {
37
+                m_borderSize = 0;
38
+            }
39
+        } else if ( matches( arg, "-p=", "--padding=" ) ) {
40
+            int err = parseInt( arg, &m_padding );
41
+            if ( err ) {
42
+                return 1;
43
+            }
44
+        } else if ( matches( arg, "-t=", "--tolerance=" ) ) {
45
+            int err = parseInt( arg, &m_tolerance );
46
+            if ( err ) {
47
+                return 1;
48
+            }
49
+            if ( m_tolerance < 0 ) {
50
+                m_tolerance = 0;
51
+            }
52
+        } else if ( matches( arg, "-x=", "--xdisplay=" ) ) {
53
+            int err = parseString( arg, &m_xdisplay );
54
+            if ( err ) {
55
+                return 1;
56
+            }
57
+        } else if ( arg == "-h" || arg == "--help" ) {
58
+            printHelp();
59
+            return 2;
60
+        } else {
61
+            if ( i == 0 ) {
62
+                continue;
63
+            }
64
+            printf( "Error: Unknown argument %s\n", argv[i] );
65
+            printf( "Try -h or --help for help.\n" );
66
+            return 1;
67
+        }
68
+    }
69
+    return 0;
70
+}
71
+
72
+int slrn::Options::parseInt( std::string arg, int* returnInt ) {
73
+    std::string copy = arg;
74
+    int find = copy.find( "=" );
75
+    if ( find != copy.npos ) {
76
+        copy.at( find ) = ' ';
77
+    }
78
+    // Just in case we error out, grab the actual argument name into x.
79
+    char* x = new char[ arg.size() ];
80
+    int num = sscanf( copy.c_str(), "%s %i", x, returnInt );
81
+    if ( num != 2 ) {
82
+        printf( "Error parsing command arguments near %s\n", arg.c_str() );
83
+        printf( "Usage: %s=INT\n", x );
84
+        printf( "Example: %s=10 or %s=-12\n", x, x );
85
+        printf( "Try -h or --help for help.\n" );
86
+        delete[] x;
87
+        return 1;
88
+    }
89
+    delete[] x;
90
+    return 0;
91
+}
92
+
93
+bool slrn::Options::matches( std::string arg, std::string shorthand, std::string longhand ) {
94
+    if ( arg.substr( 0, shorthand.size() ) == shorthand ||
95
+         arg.substr( 0, longhand.size() ) == longhand ) {
96
+        return true;
97
+    }
98
+    return false;
99
+}
100
+
101
+int slrn::Options::parseString( std::string arg, std::string* returnString ) {
102
+    std::string copy = arg;
103
+    int find = copy.find( "=" );
104
+    if ( find != copy.npos ) {
105
+        copy.at( find ) = ' ';
106
+    }
107
+    // Just in case we error out, grab the actual argument name into x.
108
+    char* x = new char[ arg.size() ];
109
+    char* y = new char[ arg.size() ];
110
+    int num = sscanf( copy.c_str(), "%s %s", x, y );
111
+    if ( num != 2 ) {
112
+        printf( "Error parsing command arguments near %s\n", arg.c_str() );
113
+        printf( "Usage: %s=STRING\n", x );
114
+        printf( "Example: %s=:0 or %s=hostname:0.1\n", x, x );
115
+        printf( "Try -h or --help for help.\n" );
116
+        delete[] x;
117
+        delete[] y;
118
+        return 1;
119
+    }
120
+    *returnString = y;
121
+    delete[] x;
122
+    delete[] y;
123
+    return 0;
124
+}

+ 28
- 0
options.hpp Прегледај датотеку

1
+#ifndef IS_OPTIONS_H_
2
+
3
+#include <string>
4
+#include <cstdio>
5
+
6
+namespace slrn {
7
+
8
+class Options {
9
+public:
10
+                Options();
11
+    int         parseOptions( int argc, char** argv );
12
+    void        printHelp();
13
+
14
+    int         m_borderSize;
15
+    int         m_padding;
16
+    int         m_tolerance;
17
+    std::string m_xdisplay;
18
+private:
19
+    int         parseInt( std::string arg, int* returnInt );
20
+    int         parseString( std::string arg, std::string* returnString );
21
+    bool        matches( std::string arg, std::string shorthand, std::string longhand );
22
+};
23
+
24
+}
25
+
26
+extern slrn::Options* options;
27
+
28
+#endif // IS_OPTIONS_H_

+ 20
- 20
x.cpp Прегледај датотеку

1
 #include "x.hpp"
1
 #include "x.hpp"
2
 
2
 
3
-is::XEngine* xengine = new is::XEngine();
3
+slrn::XEngine* xengine = new slrn::XEngine();
4
 
4
 
5
-is::XEngine::XEngine() {
5
+slrn::XEngine::XEngine() {
6
     m_display = NULL;
6
     m_display = NULL;
7
     m_visual = NULL;
7
     m_visual = NULL;
8
     m_screen = NULL;
8
     m_screen = NULL;
12
     m_hoverXWindow = None;
12
     m_hoverXWindow = None;
13
 }
13
 }
14
 
14
 
15
-is::XEngine::~XEngine() {
15
+slrn::XEngine::~XEngine() {
16
     if ( !m_good ) {
16
     if ( !m_good ) {
17
         return;
17
         return;
18
     }
18
     }
27
     XCloseDisplay( m_display );
27
     XCloseDisplay( m_display );
28
 }
28
 }
29
 
29
 
30
-void is::XEngine::addRect( Rectangle* rect ) {
30
+void slrn::XEngine::addRect( Rectangle* rect ) {
31
     m_rects.push_back( rect );
31
     m_rects.push_back( rect );
32
 }
32
 }
33
 
33
 
34
-void is::XEngine::removeRect( Rectangle* rect ) {
34
+void slrn::XEngine::removeRect( Rectangle* rect ) {
35
     for ( unsigned int i=0; i<m_rects.size(); i++ ) {
35
     for ( unsigned int i=0; i<m_rects.size(); i++ ) {
36
         if ( m_rects.at( i ) == rect ) {
36
         if ( m_rects.at( i ) == rect ) {
37
             m_rects.erase( m_rects.begin() + i );
37
             m_rects.erase( m_rects.begin() + i );
42
     }
42
     }
43
 }
43
 }
44
 
44
 
45
-bool is::XEngine::mouseDown( unsigned int button ) {
45
+bool slrn::XEngine::mouseDown( unsigned int button ) {
46
     if ( button >= m_mouse.size() ) {
46
     if ( button >= m_mouse.size() ) {
47
         return false;
47
         return false;
48
     }
48
     }
49
     return m_mouse.at( button );
49
     return m_mouse.at( button );
50
 }
50
 }
51
 
51
 
52
-int is::XEngine::init( std::string display ) {
52
+int slrn::XEngine::init( std::string display ) {
53
     // Initialize display
53
     // Initialize display
54
     m_display = XOpenDisplay( display.c_str() );
54
     m_display = XOpenDisplay( display.c_str() );
55
     if ( !m_display ) {
55
     if ( !m_display ) {
65
     return 0;
65
     return 0;
66
 }
66
 }
67
 
67
 
68
-int is::XEngine::grabCursor( is::CursorType type ) {
68
+int slrn::XEngine::grabCursor( slrn::CursorType type ) {
69
     if ( !m_good ) {
69
     if ( !m_good ) {
70
         return 1;
70
         return 1;
71
     }
71
     }
74
                             PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
74
                             PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
75
                             GrabModeAsync, GrabModeAsync, m_root, xfontcursor, CurrentTime );
75
                             GrabModeAsync, GrabModeAsync, m_root, xfontcursor, CurrentTime );
76
     if ( err != GrabSuccess ) {
76
     if ( err != GrabSuccess ) {
77
-        printf( "Failed to grab X cursor\n" );
77
+        printf( "Failed to grab X cursor.\n" );
78
         return 1;
78
         return 1;
79
     }
79
     }
80
 
80
 
90
     return 0;
90
     return 0;
91
 }
91
 }
92
 
92
 
93
-int is::XEngine::releaseCursor() {
93
+int slrn::XEngine::releaseCursor() {
94
     if ( !m_good ) {
94
     if ( !m_good ) {
95
         return 1;
95
         return 1;
96
     }
96
     }
98
     return 0;
98
     return 0;
99
 }
99
 }
100
 
100
 
101
-void is::XEngine::tick() {
101
+void slrn::XEngine::tick() {
102
     if ( !m_good ) {
102
     if ( !m_good ) {
103
         return;
103
         return;
104
     }
104
     }
138
     updateHoverWindow();
138
     updateHoverWindow();
139
 }
139
 }
140
 
140
 
141
-Cursor is::XEngine::getCursor( is::CursorType type ) {
141
+Cursor slrn::XEngine::getCursor( slrn::CursorType type ) {
142
     int xfontcursor;
142
     int xfontcursor;
143
     switch ( type ) {
143
     switch ( type ) {
144
         default:
144
         default:
162
     return newcursor;
162
     return newcursor;
163
 }
163
 }
164
 
164
 
165
-void is::XEngine::setCursor( is::CursorType type ) {
165
+void slrn::XEngine::setCursor( slrn::CursorType type ) {
166
     if ( !m_good ) {
166
     if ( !m_good ) {
167
         return;
167
         return;
168
     }
168
     }
172
                               xfontcursor, CurrentTime );
172
                               xfontcursor, CurrentTime );
173
 }
173
 }
174
 
174
 
175
-is::Rectangle::~Rectangle() {
175
+slrn::Rectangle::~Rectangle() {
176
     //XFreeGC( xengine->m_display, m_gc );
176
     //XFreeGC( xengine->m_display, m_gc );
177
     if ( m_window == None ) {
177
     if ( m_window == None ) {
178
         return;
178
         return;
181
     XDestroyWindow( xengine->m_display, m_window );
181
     XDestroyWindow( xengine->m_display, m_window );
182
 }
182
 }
183
 
183
 
184
-is::Rectangle::Rectangle( int x, int y, int width, int height, int border, int padding ) {
184
+slrn::Rectangle::Rectangle( int x, int y, int width, int height, int border, int padding ) {
185
     m_xoffset = 0;
185
     m_xoffset = 0;
186
     m_yoffset = 0;
186
     m_yoffset = 0;
187
     m_x = x;
187
     m_x = x;
221
     XMapWindow( xengine->m_display, m_window );
221
     XMapWindow( xengine->m_display, m_window );
222
 }
222
 }
223
 
223
 
224
-void is::Rectangle::setPos( int x, int y ) {
224
+void slrn::Rectangle::setPos( int x, int y ) {
225
     if ( m_x == x && m_y == y ) {
225
     if ( m_x == x && m_y == y ) {
226
         return;
226
         return;
227
     }
227
     }
233
     XMoveWindow( xengine->m_display, m_window, m_x+m_xoffset, m_y+m_yoffset );
233
     XMoveWindow( xengine->m_display, m_window, m_x+m_xoffset, m_y+m_yoffset );
234
 }
234
 }
235
 
235
 
236
-void is::Rectangle::setDim( int w, int h ) {
236
+void slrn::Rectangle::setDim( int w, int h ) {
237
     if ( m_width == w && m_height == h ) {
237
     if ( m_width == w && m_height == h ) {
238
         return;
238
         return;
239
     }
239
     }
258
     XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
258
     XShapeCombineRectangles( xengine->m_display, m_window, ShapeBounding, 0, 0, &rect, 1, ShapeSubtract, 0);
259
 }
259
 }
260
 
260
 
261
-void is::XEngine::updateHoverWindow() {
261
+void slrn::XEngine::updateHoverWindow() {
262
     Window root, child;
262
     Window root, child;
263
     int mx, my;
263
     int mx, my;
264
     int wx, wy;
264
     int wx, wy;
283
                   &(m_hoverWindow.m_border), &depth );
283
                   &(m_hoverWindow.m_border), &depth );
284
 }
284
 }
285
 
285
 
286
-void is::XEngine::updateHoverWindow( Window child ) {
286
+void slrn::XEngine::updateHoverWindow( Window child ) {
287
     if ( m_hoverXWindow == child ) {
287
     if ( m_hoverXWindow == child ) {
288
         return;
288
         return;
289
     }
289
     }
305
 }
305
 }
306
 
306
 
307
 // Keeps our rectangle's sizes all positive, so Xlib doesn't throw an exception.
307
 // Keeps our rectangle's sizes all positive, so Xlib doesn't throw an exception.
308
-void is::Rectangle::constrain( int w, int h ) {
308
+void slrn::Rectangle::constrain( int w, int h ) {
309
     int pad = m_padding;
309
     int pad = m_padding;
310
     if ( pad < 0 && std::abs( w ) < std::abs( pad )*2 ) {
310
     if ( pad < 0 && std::abs( w ) < std::abs( pad )*2 ) {
311
         pad = 0;
311
         pad = 0;

+ 5
- 5
x.hpp Прегледај датотеку

14
 #include <string>
14
 #include <string>
15
 #include <vector>
15
 #include <vector>
16
 
16
 
17
-namespace is {
17
+namespace slrn {
18
 
18
 
19
 enum CursorType {
19
 enum CursorType {
20
     Left,
20
     Left,
64
                         ~XEngine();
64
                         ~XEngine();
65
     int                 init( std::string display );
65
     int                 init( std::string display );
66
     void                tick();
66
     void                tick();
67
-    int                 grabCursor( is::CursorType type );
67
+    int                 grabCursor( slrn::CursorType type );
68
     int                 releaseCursor();
68
     int                 releaseCursor();
69
-    void                setCursor( is::CursorType type );
69
+    void                setCursor( slrn::CursorType type );
70
     void                drawRect( int x, int y, unsigned int w, unsigned int h );
70
     void                drawRect( int x, int y, unsigned int w, unsigned int h );
71
     void                addRect( Rectangle* rect );
71
     void                addRect( Rectangle* rect );
72
     void                removeRect( Rectangle* rect );
72
     void                removeRect( Rectangle* rect );
87
     bool                m_good;
87
     bool                m_good;
88
     std::vector<Cursor> m_cursors;
88
     std::vector<Cursor> m_cursors;
89
     std::vector<Rectangle*> m_rects;
89
     std::vector<Rectangle*> m_rects;
90
-    Cursor              getCursor( is::CursorType type );
90
+    Cursor              getCursor( slrn::CursorType type );
91
 };
91
 };
92
 
92
 
93
 }
93
 }
94
 
94
 
95
-extern is::XEngine* xengine;
95
+extern slrn::XEngine* xengine;
96
 
96
 
97
 #endif // IS_X_H_
97
 #endif // IS_X_H_