Work around duplicate button-press-events and gtk-auto-mnemonics.
authorterminatorX <>
Sun, 30 Jan 2011 19:39:47 +0000 (19:39 +0000)
committerterminatorX <>
Sun, 30 Jan 2011 19:39:47 +0000 (19:39 +0000)
src/tX_engine.cc
src/tX_mastergui.cc
src/tX_mouse.cc
src/tX_mouse.h
src/tX_seqpar.cc
src/tX_vttgui.cc

index 00add7e680dc7f1f7638e5c70e71f6da76963d7a..358b696fbd6de7eefabc469dbe06d89c996f84b9 100644 (file)
@@ -1,6 +1,6 @@
 /*
     terminatorX - realtime audio scratching software
-    Copyright (C) 1999-2011  Alexander König
+    Copyright (C) 1999-2011  Alexander Knig
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -76,16 +76,6 @@ int16_t* tX_engine::render_cycle() {
        /* Record the audio if necessary... */
        if (is_recording()) tape->eat(data);
        
-       /* check for GUI thread starvation */
-//     if (cycles_ctr++ > 100) {
-//             tX_error("engine detected overload condition.");
-//             overload_error=true;
-//             stop_flag=true;
-               // give the audio thread some air to breathe
-               // so it can acquire the mutex
-//             usleep(500);
-//     }
-       
        return  data;
 }
 
@@ -131,7 +121,7 @@ void tX_engine::loop() {
                        grab_active=false;
                        grab_off();
                } */
-               
+
                if (!stop_flag) {
                        runtime_error=true;
                        usleep(100);
index e778e55ab0eb37b59a0c7fc78de7910d16d11d50..92423665d632de0c49224c91d42d08ad39ca7080 100644 (file)
@@ -181,6 +181,9 @@ gint pos_update(gpointer data)
                        old_focus=vtt_class::focused_vtt;
                        if (old_focus) gui_show_frame(old_focus, 1);                    
                }
+
+               grab_status = mouse.is_grabbed();
+
                if (grab_status!=last_grab_status) {
                        last_grab_status=grab_status;
                        if (!grab_status) {
@@ -1432,13 +1435,6 @@ void create_mastergui(int x, int y)
        gtk_window_set_title(GTK_WINDOW(main_window), "terminatorX");
 
        gtk_widget_realize(main_window);
-       
-       g_signal_connect(G_OBJECT(main_window), "motion_notify_event", G_CALLBACK(tx_mouse::motion_notify_wrap), &mouse);
-       g_signal_connect(G_OBJECT(main_window), "button_press_event", G_CALLBACK(tx_mouse::button_press_wrap), &mouse);
-       g_signal_connect(G_OBJECT(main_window), "button_release_event", G_CALLBACK(tx_mouse::button_release_wrap), &mouse);
-       g_signal_connect(G_OBJECT(main_window), "key_press_event", G_CALLBACK(tx_mouse::key_press_wrap), &mouse);
-       g_signal_connect(G_OBJECT(main_window), "key_release_event", G_CALLBACK(tx_mouse::key_release_wrap), &mouse);
-
 
        wrapbox=gtk_vbox_new(FALSE, 5);
        gtk_container_add(GTK_CONTAINER(main_window), wrapbox);
@@ -1454,6 +1450,12 @@ void create_mastergui(int x, int y)
        gtk_widget_show(mother_of_all_boxen);   
 
        create_master_menu();
+
+       g_signal_connect(G_OBJECT(main_window), "motion_notify_event", G_CALLBACK(tx_mouse::motion_notify_wrap), &mouse);
+       g_signal_connect(G_OBJECT(main_window), "button_press_event", G_CALLBACK(tx_mouse::button_press_wrap), &mouse);
+       g_signal_connect(G_OBJECT(main_window), "button_release_event", G_CALLBACK(tx_mouse::button_release_wrap), &mouse);
+       g_signal_connect(G_OBJECT(main_window), "key_press_event", G_CALLBACK(tx_mouse::key_press_wrap), &mouse);
+       g_signal_connect(G_OBJECT(main_window), "key_release_event", G_CALLBACK(tx_mouse::key_release_wrap), &mouse);
        
        main_vbox=gtk_hbox_new(FALSE, 5);
        gtk_box_pack_start(GTK_BOX(mother_of_all_boxen), main_vbox, WID_DYN);
index 8ba880820625136e74759101bf08a0947fc4cf97..41ab919e1e7663c858e1eeb32a2dc5dc64a7d97b 100644 (file)
@@ -67,6 +67,10 @@ tx_mouse :: tx_mouse()
        
        grabbed=0;
        warp=TX_MOUSE_SPEED_NORMAL;
+       enable_auto_mnemonics = FALSE;
+
+       last_button_press = 0;
+       last_button_release = 0;
 }
 
 
@@ -112,6 +116,16 @@ int tx_mouse :: grab()
 //             }
 //     }
 
+//     GdkModifierType modifiers = (GdkModifierType)NULL;
+//     gtk_window_set_mnemonic_modifier(GTK_WINDOW(main_window), modifiers);
+//     gtk_window_set_mnemonics_visible(GTK_WINDOW(main_window), false);
+
+       g_object_get (gtk_widget_get_settings (main_window), "gtk-auto-mnemonics", &enable_auto_mnemonics, NULL);
+
+       if (enable_auto_mnemonics) {
+               gboolean off = FALSE;
+               g_object_set (gtk_widget_get_settings (main_window), "gtk-auto-mnemonics", off, NULL);
+       }
 
        GdkGrabStatus grab_status =gdk_pointer_grab(top_window, FALSE, GdkEventMask (GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK), NULL, NULL, GDK_CURRENT_TIME);
 
@@ -199,6 +213,10 @@ void tx_mouse :: ungrab()
 
        gdk_window_set_events(top_window, savedEventMask);
 
+       if (enable_auto_mnemonics) {
+               g_object_set (gtk_widget_get_settings (main_window), "gtk-auto-mnemonics", enable_auto_mnemonics, NULL);
+       }
+
        tX_debug("tX_mouse::ungrab(): done");
        
        grabbed=0;
@@ -418,23 +436,36 @@ gboolean tx_mouse::motion_notify_wrap(GtkWidget *widget, GdkEventMotion *eventMo
 gboolean tx_mouse::button_press_wrap(GtkWidget *widget, GdkEventButton *eventButton, void *data) {
        tx_mouse* mouse = (tx_mouse *) data;
        if (mouse->grabbed) {
-               tX_debug("tX_mouse::button-press-event (%u)", eventButton->button);
-               mouse->button_press(widget, eventButton);
+               if (mouse->last_button_press != eventButton->time) {
+                       mouse->last_button_press = eventButton->time;
+
+                       tX_debug("tX_mouse::button-press-event (%u)", eventButton->button);
+                       mouse->button_press(widget, eventButton);
+               } else {
+                       tX_debug("tX_mouse::button-press-event (%u) identical event skipped", eventButton->button);
+               }
                return TRUE;
-       } else {
-               return FALSE;
        }
+
+       return FALSE;
 }
 
 gboolean tx_mouse::button_release_wrap(GtkWidget *widget, GdkEventButton *eventButton, void *data) {
        tx_mouse* mouse = (tx_mouse *) data;
        if (mouse->grabbed) {
-               tX_debug("tX_mouse::button-release-event (%u)", eventButton->button);
-               mouse->button_release(widget, eventButton);
+               if (mouse->last_button_release != eventButton->time) {
+                       mouse->last_button_release = eventButton->time;
+
+                       tX_debug("tX_mouse::button-release-event (%u)", eventButton->button);
+                       mouse->button_release(widget, eventButton);
+               } else {
+                       tX_debug("tX_mouse::button-release-event (%u) identical event skipped", eventButton->button);
+               }
+
                return TRUE;
-       } else {
-               return FALSE;
        }
+
+       return FALSE;
 }
 
 gboolean tx_mouse::key_press_wrap(GtkWidget *widget, GdkEventKey *eventKey, void *data) {
index 5849127f232eccbe1279ba64ea7d200dffbb63a5..71241eed4e90cec8a2789d486cdbc5bfcb8fbc65 100644 (file)
@@ -131,6 +131,10 @@ class tx_mouse
        bool warp_override;
        GdkEventMask savedEventMask;
 
+       gboolean enable_auto_mnemonics;
+       guint last_button_press;
+       guint last_button_release;
+
 #ifdef USE_DGA2        
        XEvent xev_copy;
        XDGAButtonEvent *xdgabut;
@@ -144,12 +148,12 @@ class tx_mouse
        KeySym key;
        float warp;
        
-       public:
-       
        int grabbed;
 
+       public:
        int set_xinput();
        void reset_xinput();
+       bool is_grabbed() { return grabbed != 0; }
                
        int grab();
        int check_event();
index b36d9456bb2e3d832ee9db3289797b0f1f39ce5d..cd6043d5862af290b91999b3c1b9095188d77084 100644 (file)
@@ -39,8 +39,13 @@ pthread_mutex_t tX_seqpar :: update_lock = PTHREAD_MUTEX_INITIALIZER;
 
 #define tt ((vtt_class *) vtt)
 
+#ifdef DEBUG_SEQPAR_LOCK
 #define seqpar_mutex_lock(lock) { tX_debug("lock: %i", __LINE__); pthread_mutex_lock(lock); }
 #define seqpar_mutex_unlock(lock) { tX_debug("unlock: %i", __LINE__); pthread_mutex_unlock(lock); }
+#else
+#define seqpar_mutex_lock(lock) pthread_mutex_lock(lock)
+#define seqpar_mutex_unlock(lock) pthread_mutex_unlock(lock)
+#endif
 
 tX_seqpar :: tX_seqpar () : bound_midi_event()
 {
@@ -368,13 +373,8 @@ void tX_seqpar :: update_all_graphics()
                seqpar_mutex_unlock(&update_lock);
                return; 
        }
-//     /* Events may trigger lock, too so we unlock temporarily. */
-//     seqpar_mutex_unlock(&update_lock);
-//
-//     while (gtk_events_pending()) gtk_main_iteration();
-//
-//     seqpar_mutex_lock(&update_lock);
-       for (sp=update.begin(); sp!=update.end(); sp++) {
+
+       for (sp=update.begin(); sp!=update.end(); sp++) {
                (*sp)->update_graphics(false);
        }
        update.erase(update.begin(), update.end());
@@ -392,9 +392,9 @@ void tX_seqpar :: init_all_graphics()
        for (sp=all.begin(); sp!=all.end(); sp++) {
                (*sp)->update_graphics();
        }
-       while (gtk_events_pending()) gtk_main_iteration();      
-
        seqpar_mutex_unlock(&update_lock);
+
+       while (gtk_events_pending()) gtk_main_iteration();      
 }
 
 void tX_seqpar_update :: exec_value(const float value)
index 9af7cb9344268ddc3e55eaf7d4415632ff80dead..0c3a6c5da4294768934cd3f7f7bb791ba8cd477a 100644 (file)
@@ -891,7 +891,7 @@ void build_vtt_gui(vtt_class *vtt)
 
        g->mouse_mapping=gtk_button_new_with_label("Mouse");
        gtk_widget_show(g->mouse_mapping);
-       gui_set_tooltip(g->mouse_mapping, "Determines what parameters should be affected on mouse moition in mouse grab mode.");
+       gui_set_tooltip(g->mouse_mapping, "Determines what parameters should be affected on mouse motion in mouse grab mode.");
        gtk_box_pack_start(GTK_BOX(tempbox2), g->mouse_mapping, WID_FIX);
 
 #ifdef USE_ALSA_MIDI_IN