fix initialized result in grab, fix empty mixer paste, tweak cuda drop compute_30...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bcwindowbase.C
index e64b2eb04b15fbed85aa667d67aaec122acb650c..9f3e2123c843c7e0f336ae1d4c53105b03b04a71 100644 (file)
@@ -224,6 +224,7 @@ BC_WindowBase::~BC_WindowBase()
        }
 
        resize_history.remove_all_objects();
+       delete grab_lock;
 
 #ifndef SINGLE_THREAD
        common_events.remove_all_objects();
@@ -346,6 +347,7 @@ int BC_WindowBase::initialize()
        event_condition = new Condition(0, "BC_WindowBase::event_condition");
        init_lock = new Condition(0, "BC_WindowBase::init_lock");
 #endif
+       grab_lock = new Mutex("BC_WindowBase::grab_lock");
 
        cursor_timer = new Timer;
        event_thread = 0;
@@ -959,10 +961,15 @@ if( debug && event->type != ClientMessage ) {
 }
 
        if( active_grab ) {
+               grab_lock->lock("BC_WindowBase::dispatch_event 3");
                unlock_window();
-               active_grab->lock_window("BC_WindowBase::dispatch_event 3");
-               result = active_grab->grab_event(event);
-               active_grab->unlock_window();
+               result = 0;
+               if( active_grab ) {
+                       active_grab->lock_window("BC_WindowBase::dispatch_event 3");
+                       result = active_grab->grab_event(event);
+                       active_grab->unlock_window();
+               }
+               grab_lock->unlock();
                if( result ) return result;
                lock_window("BC_WindowBase::dispatch_event 4");
        }
@@ -3415,17 +3422,36 @@ void BC_WindowBase::close(int return_value)
 
 int BC_WindowBase::grab(BC_WindowBase *window)
 {
-       if( window->active_grab && this != window->active_grab ) return 0;
-       window->active_grab = this;
-       this->grab_active = window;
-       return 1;
+       int ret = 0;
+       BC_WindowBase *grab_window = window->active_grab;
+       if( grab_window ) {
+               int locked = get_window_lock();
+               if( locked ) unlock_window();
+               grab_window->lock_window("BC_WindowBase::grab(BC_WindowBase");
+               grab_window->handle_ungrab();
+               grab_window->unlock_window();
+               if( locked ) lock_window("BC_WindowBase::grab(BC_WindowBase");
+       }
+       window->grab_lock->lock("BC_WindowBase::grab");
+       if( !window->active_grab ) {
+               window->active_grab = this;
+               this->grab_active = window;
+               ret = 1;
+       }
+       window->grab_lock->unlock();
+       return ret;
 }
 int BC_WindowBase::ungrab(BC_WindowBase *window)
 {
-       if( window->active_grab && this != window->active_grab ) return 0;
-       window->active_grab = 0;
-       this->grab_active = 0;
-       return 1;
+       int ret = 0;
+       window->grab_lock->lock("BC_WindowBase::ungrab");
+       if( this == window->active_grab ) {
+               window->active_grab = 0;
+               this->grab_active = 0;
+               ret = 1;
+       }
+       window->grab_lock->unlock();
+       return ret;
 }
 int BC_WindowBase::grab_event_count()
 {
@@ -4357,6 +4383,10 @@ void BC_WindowBase::init_resources(float scale)
                int wx, wy, ww, wh;
                int cins = info.xinerama_big_screen();
                if( !info.xinerama_geometry(cins, wx, wy, ww, wh) ) {
+                       int sh = ww * 9 / 16;
+                       int sw = wh * 16 / 9;
+                       if( sw < ww ) ww = sw;
+                       if( sh < wh ) wh = sh;
                        if( (x_scale = ww/1920.) < 1 ) x_scale = 1;
                        if( (y_scale = wh/1080.) < 1 ) y_scale = 1;
                }