(q_recv, q_send, background_send)
Check for running processes.
    As refreshing the list takes some time but not CPU, this is put in its own thread
    and sends the currently running program to the backgrund process.
Check for running processes.
    As refreshing the list takes some time but not CPU, this is put in its own thread
    and sends the currently running program to the backgrund process.
Check for running processes . As refreshing the list takes some time but not CPU this is put in its own thread and sends the currently running program to the backgrund process .
def running_processes(q_recv, q_send, background_send):
    """Check for running processes.
    As refreshing the list takes some time but not CPU, this is put in its own thread
    and sends the currently running program to the backgrund process.
    """
    try:
        previous_app = None
        last_coordinates = None
        last_resolution = None
        
        NOTIFY(LANGUAGE.strings['Tracking']['ApplicationListen']).put(q_send)

        while True:
                
            received_data = q_recv.get()

            if 'Reload' in received_data:
                try:
                    running_apps.reload_file()
                except (NameError, UnboundLocalError):
                    running_apps = RunningApplications(queue=q_send)
                
                NOTIFY(LANGUAGE.strings['Tracking']['ApplistReload'], FILE_NAME=running_apps.applist.name)

            if 'Update' in received_data:
                running_apps.refresh()
                
                current_app = running_apps.check()
                send = {}
                
                if current_app is not None and current_app[0] == TRACKING_IGNORE:
                    current_app = None
                
                #Send custom resolution
                if running_apps.focus is not None:
                    
                    if current_app is None:
                        app_resolution = None
                    
                    else:
                        app_resolution = (running_apps.focus.rect, running_apps.focus.resolution)
                        
                        if current_app == previous_app:
                            if app_resolution[1] != last_resolution:
                                NOTIFY(LANGUAGE.strings['Tracking']['ResolutionAppResize'],
                                       XRES_OLD=last_resolution[0], YRES_OLD=last_resolution[1],
                                       XRES=app_resolution[1][0], YRES=app_resolution[1][1])
                            elif app_resolution[0] != last_coordinates:
                                NOTIFY(LANGUAGE.strings['Tracking']['ResolutionAppMove'],
                                       XPOS_OLD=last_coordinates[0], YPOS_OLD=last_coordinates[1],
                                       XPOS=app_resolution[0][0], YPOS=app_resolution[0][1])
                        else:
                            NOTIFY(LANGUAGE.strings['Tracking']['ResolutionAppLoad'], 
                                   XRES=app_resolution[1][0], YRES=app_resolution[1][1])
                            
                        last_coordinates, last_resolution = app_resolution
                
                #Detect running program
                if current_app != previous_app:
                    
                    if running_apps.focus is None:
                        send['ApplicationResolution'] = None
                        app_start = LANGUAGE.strings['Tracking']['ApplicationStart']
                        app_end = LANGUAGE.strings['Tracking']['ApplicationEnd']
                    else:
                        # Somewhat hacky way to detect if the application is full screen spanning multiple monitors
                        # If this is the case, we want to record both monitors as normal
                        app_is_windowed = True
                        if MULTI_MONITOR and app_resolution is not None:
                            x_min = x_max = y_min = y_max = 0
                            for info in monitor_info():
                                x1, y1, x2, y2 = info
                                x_min = min(x_min, x1)
                                x_max = max(x_max, x2)
                                y_min = min(y_min, y1)
                                y_max = max(y_max, y2)
                            if (x_max - x_min, y_max - y_min) == app_resolution[1]:
                                app_is_windowed = False

                        send['ApplicationResolution'] = app_resolution if app_is_windowed else None
                        app_start = LANGUAGE.strings['Tracking']['ApplicationFocused']
                        app_end = LANGUAGE.strings['Tracking']['ApplicationUnfocused']
                
                    process_id = None
                    if current_app is None:
                        NOTIFY(app_end, APPLICATION_NAME=previous_app[0])
                    else:
                        if running_apps.focus is not None:
                            if previous_app is not None:
                                NOTIFY(app_end, APPLICATION_NAME=previous_app[0])
                            process_id = running_apps.focus.pid
                        NOTIFY(app_start, APPLICATION_NAME=current_app[0])
                        
                    NOTIFY.put(q_send)
                    send['Program'] = (process_id, current_app)
                    
                    previous_app = current_app
                
                if send:
                    background_send.put(send)
                    q_send.put(send)
    
    #Catch error after KeyboardInterrupt
    except EOFError:
        return
    
    except Exception:
        q_send.put(traceback.format_exc())
def running_processes ( q_recv , q_send , background_send ) : try : previous_app = None last_coordinates = None last_resolution = None NOTIFY ( LANGUAGE . strings [ 'Tracking' ] [ 'ApplicationListen' ] ) . put ( q_send ) while True : received_data = q_recv . get ( ) if 'Reload' in received_data : try : running_apps . reload_file ( ) except ( NameError , UnboundLocalError ) : running_apps = RunningApplications ( queue = q_send ) NOTIFY ( LANGUAGE . strings [ 'Tracking' ] [ 'ApplistReload' ] , FILE_NAME = running_apps . applist . name ) if 'Update' in received_data : running_apps . refresh ( ) current_app = running_apps . check ( ) send = { } if current_app is not None and current_app [ 0 ] == TRACKING_IGNORE : current_app = None #Send custom resolution if running_apps . focus is not None : if current_app is None : app_resolution = None else : app_resolution = ( running_apps . focus . rect , running_apps . focus . resolution ) if current_app == previous_app : if app_resolution [ 1 ] != last_resolution : NOTIFY ( LANGUAGE . strings [ 'Tracking' ] [ 'ResolutionAppResize' ] , XRES_OLD = last_resolution [ 0 ] , YRES_OLD = last_resolution [ 1 ] , XRES = app_resolution [ 1 ] [ 0 ] , YRES = app_resolution [ 1 ] [ 1 ] ) elif app_resolution [ 0 ] != last_coordinates : NOTIFY ( LANGUAGE . strings [ 'Tracking' ] [ 'ResolutionAppMove' ] , XPOS_OLD = last_coordinates [ 0 ] , YPOS_OLD = last_coordinates [ 1 ] , XPOS = app_resolution [ 0 ] [ 0 ] , YPOS = app_resolution [ 0 ] [ 1 ] ) else : NOTIFY ( LANGUAGE . strings [ 'Tracking' ] [ 'ResolutionAppLoad' ] , XRES = app_resolution [ 1 ] [ 0 ] , YRES = app_resolution [ 1 ] [ 1 ] ) last_coordinates , last_resolution = app_resolution #Detect running program if current_app != previous_app : if running_apps . focus is None : send [ 'ApplicationResolution' ] = None app_start = LANGUAGE . strings [ 'Tracking' ] [ 'ApplicationStart' ] app_end = LANGUAGE . strings [ 'Tracking' ] [ 'ApplicationEnd' ] else : # Somewhat hacky way to detect if the application is full screen spanning multiple monitors # If this is the case, we want to record both monitors as normal app_is_windowed = True if MULTI_MONITOR and app_resolution is not None : x_min = x_max = y_min = y_max = 0 for info in monitor_info ( ) : x1 , y1 , x2 , y2 = info x_min = min ( x_min , x1 ) x_max = max ( x_max , x2 ) y_min = min ( y_min , y1 ) y_max = max ( y_max , y2 ) if ( x_max - x_min , y_max - y_min ) == app_resolution [ 1 ] : app_is_windowed = False send [ 'ApplicationResolution' ] = app_resolution if app_is_windowed else None app_start = LANGUAGE . strings [ 'Tracking' ] [ 'ApplicationFocused' ] app_end = LANGUAGE . strings [ 'Tracking' ] [ 'ApplicationUnfocused' ] process_id = None if current_app is None : NOTIFY ( app_end , APPLICATION_NAME = previous_app [ 0 ] ) else : if running_apps . focus is not None : if previous_app is not None : NOTIFY ( app_end , APPLICATION_NAME = previous_app [ 0 ] ) process_id = running_apps . focus . pid NOTIFY ( app_start , APPLICATION_NAME = current_app [ 0 ] ) NOTIFY . put ( q_send ) send [ 'Program' ] = ( process_id , current_app ) previous_app = current_app if send : background_send . put ( send ) q_send . put ( send ) #Catch error after KeyboardInterrupt except EOFError : return except Exception : q_send . put ( traceback . format_exc ( ) )