- bool quit = false;
- bool button1_pressed = false;
- bool check_for_double_click = false;
- XEvent Event;
-
- while( quit == false ) {
- if( ( check_for_double_click != false ) &&
- ( XPending( dockapp.display ) == 0 ) ) {
- /* If no other button 1 events are received after the delay, then it is a
- single-click mouse event. */
- if( SingleClickCallback != NULL ) {
- (*SingleClickCallback)();
- }
-
- check_for_double_click = false;
- }
- /* XNextEvent is a blocking call: it will return only when an event is
- ready to be processed, thus freeing the CPU for other tasks when no
- events are available. */
- (void) XNextEvent( dockapp.display, &Event );
- switch( Event.type ) {
- case Expose:
- /* Window was uncovered... */
- RedrawWindow();
- break;
- case DestroyNotify:
- /* Window was killed... */
- /* Is this necessary ? */
- (void) XCloseDisplay( dockapp.display );
- quit = true;
- break;
- case ClientMessage:
- /* Doesn't seem to work... */
- printf( "Client message received...\n" );
- break;
- case ButtonPress:
- if( Event.xbutton.button == Button1 ) {
- /* Mouse LEFT button pressed. */
- button1_pressed = true;
- }
- break;
- case ButtonRelease:
- if( Event.xbutton.button == Button1 ) {
- /* Mouse LEFT button released. */
- if( button1_pressed != false ) {
- /* We act only when the button is released */
- if( check_for_double_click != false ) {
- /* Double-click */
- if( DoubleClickCallback != NULL ) {
- (*DoubleClickCallback)();
- }
- check_for_double_click = false;
- }
- else {
- (void) usleep( DOUBLE_CLICK_MAX_INTERVAL_MS * 1000 );
- check_for_double_click = true;
- }
- }
- }
- break;
- }
- } /* end while */
+ bool quit = false;
+ bool button1_pressed = false;
+ bool double_click = false;
+ XEvent Event;
+
+ while (quit == false) {
+ if ((double_click) &&
+ (XPending(dockapp.display) == 0)) {
+ /*
+ * If no other button 1 events are received after the
+ * delay, then it is a single-click mouse event.
+ */
+ if (SingleClickCallback != NULL)
+ (*SingleClickCallback)();
+
+ double_click = false;
+ }
+ /*
+ * XNextEvent is a blocking call: it will return only when an
+ * event is ready to be processed, thus freeing the CPU for
+ * other tasks when no events are available.
+ */
+ (void) XNextEvent(dockapp.display, &Event);
+ switch (Event.type) {
+ case Expose:
+ /* Window was uncovered... */
+ RedrawWindow();
+ break;
+ case DestroyNotify:
+ /* Window was killed... */
+ /* Is this necessary ? */
+ (void) XCloseDisplay(dockapp.display);
+ quit = true;
+ break;
+ case ClientMessage:
+ /* Doesn't seem to work... */
+ printf("Client message received...\n");
+ break;
+ case ButtonPress:
+ if (Event.xbutton.button == Button1) {
+ /* Mouse LEFT button pressed. */
+ button1_pressed = true;
+ }
+ break;
+ case ButtonRelease:
+ if (Event.xbutton.button == Button1) {
+ /* Mouse LEFT button released. */
+ if (button1_pressed)
+ detect_double_click(&double_click);
+ }
+ break;
+ }
+ } /* end while */