瀏覽代碼

fixed mouse typo

naelstrof 11 年之前
父節點
當前提交
38d3a46149
共有 3 個文件被更改,包括 19 次插入9 次删除
  1. 8
    7
      main.cpp
  2. 9
    2
      x.cpp
  3. 2
    0
      x.hpp

+ 8
- 7
main.cpp 查看文件

@@ -28,6 +28,9 @@ int parseOptions( int argc, char** argv ) {
28 28
                 arg.at( find ) = ' ';
29 29
             }
30 30
             int num = sscanf( arg.c_str(), "%*s %i", &borderSize );
31
+            if ( borderSize < 0 ) {
32
+                borderSize = 0;
33
+            }
31 34
             if ( num != 1 ) {
32 35
                 printf( "Error parsing command arguments near %s\n", argv[i] );
33 36
                 printf( "Usage: -b=INT or --bordersize=INT\n" );
@@ -135,7 +138,6 @@ int main( int argc, char** argv ) {
135 138
             }
136 139
             case 1: {
137 140
                 selection = new is::Rectangle( xengine->m_mousex, xengine->m_mousey, 0, 0, borderSize, padding );
138
-                selection->setPos( xengine->m_mousex, xengine->m_mousey );
139 141
                 xengine->addRect( selection );
140 142
                 state++;
141 143
                 break;
@@ -146,14 +148,13 @@ int main( int argc, char** argv ) {
146 148
                     break;
147 149
                 }
148 150
                 selection->setDim( xengine->m_mousex - selection->m_x, xengine->m_mousey - selection->m_y );
149
-                // x and y offsets can indicate if the selection is inside-out, which lets us know which kind of cursor we need.
150
-                int x = selection->m_xoffset;
151
-                int y = selection->m_yoffset;
152
-                if ( x == 0 && y == 0) {
151
+                bool x = selection->m_flippedx;
152
+                bool y = selection->m_flippedy;
153
+                if ( !x && !y ) {
153 154
                     xengine->setCursor( is::LowerRightCorner );
154
-                } else if ( x && y == 0 ) {
155
+                } else if ( x && !y ) {
155 156
                     xengine->setCursor( is::LowerLeftCorner );
156
-                } else if ( x == 0 && y ) {
157
+                } else if ( !x && y ) {
157 158
                     xengine->setCursor( is::UpperRightCorner );
158 159
                 } else {
159 160
                     xengine->setCursor( is::UpperLeftCorner );

+ 9
- 2
x.cpp 查看文件

@@ -85,7 +85,7 @@ int is::XEngine::grabCursor( is::CursorType type ) {
85 85
     unsigned int mask;
86 86
     XQueryPointer( m_display, m_root, &root, &child, &mx, &my, &wx, &wy, &mask );
87 87
     m_mousex = mx;
88
-    m_mousex = my;
88
+    m_mousey = my;
89 89
     updateHoverWindow( child );
90 90
     return 0;
91 91
 }
@@ -102,7 +102,7 @@ void is::XEngine::tick() {
102 102
     if ( !m_good ) {
103 103
         return;
104 104
     }
105
-    XSync( m_display, false );
105
+    XFlush( m_display );
106 106
     XEvent event;
107 107
     while ( XPending( m_display ) ) {
108 108
         XNextEvent( m_display, &event );
@@ -239,6 +239,9 @@ void is::Rectangle::setDim( int w, int h ) {
239 239
     }
240 240
 
241 241
     constrain( w, h );
242
+    if ( m_border == 0 ) {
243
+        return;
244
+    }
242 245
 
243 246
     XResizeWindow( xengine->m_display, m_window, m_width+m_border*2, m_height+m_border*2 );
244 247
     XMoveWindow( xengine->m_display, m_window, m_x+m_xoffset, m_y+m_yoffset );
@@ -308,9 +311,11 @@ void is::Rectangle::constrain( int w, int h ) {
308 311
         pad = 0;
309 312
     }
310 313
     if ( w < 0 ) {
314
+        m_flippedx = true;
311 315
         m_xoffset = w - pad - m_border;
312 316
         m_width = -w + pad*2;
313 317
     } else {
318
+        m_flippedx = false;
314 319
         m_xoffset = -pad - m_border;
315 320
         m_width = w + pad*2;
316 321
     }
@@ -320,9 +325,11 @@ void is::Rectangle::constrain( int w, int h ) {
320 325
         pad = 0;
321 326
     }
322 327
     if ( h < 0 ) {
328
+        m_flippedy = true;
323 329
         m_yoffset = h - pad - m_border;
324 330
         m_height = -h + pad*2;
325 331
     } else {
332
+        m_flippedy = false;
326 333
         m_yoffset = -pad - m_border;
327 334
         m_height = h + pad*2;
328 335
     }

+ 2
- 0
x.hpp 查看文件

@@ -52,6 +52,8 @@ public:
52 52
     int     m_padding;
53 53
     XColor  m_forground, m_forgroundExact;
54 54
     XColor  m_background, m_backgroundExact;
55
+    bool    m_flippedx;
56
+    bool    m_flippedy;
55 57
 private:
56 58
     void    constrain( int w, int h );
57 59
 };