<commit_before>import os
import logging
import gtk.gdk

ARBITRARY_AREA = 0 # Specified area
ACTIVE_WINDOW = 1 # Focused/top window only
ACTIVE_MONITOR = 2 # Monitor containing the active window
CURSOR_MONITOR = 3 # Monitor containing the cursor
ENTIRE_DESKTOP = 4 # Everything

logger = logging.getLogger(__name__)

def get_active_window(root=None):
    """Returns the active (focused, top) window, or None."""
    root = root or gtk.gdk.get_root_window()
    # Make sure active window hinting is working
    if root.supports_net_wm_hint("_NET_ACTIVE_WINDOW") and root.supports_net_wm_hint("_NET_WM_WINDOW_TYPE"):
        active = root.get_active_window()
        # If active window is a desktop, fail
        if active.property_get("_NET_WM_WINDOW_TYPE")[-1][0] == '_NET_WM_WINDOW_TYPE_DESKTOP':
            return None
        return active
    else:
        return None

def get_active_monitor(root=None):
    """Returns the index of the active monitor, or -1 if undetermined."""
    root = root or gtk.gdk.get_root_window()
    num_monitors = root.get_n_monitors()
    if (num_monitors == 1):
        return 0
    active = get_active_window()
    if active != None:
        return root.get_monitor_at_window(active)
    else:
        return -1

def take_screenshot(filepath, target=ACTIVE_MONITOR, fmt="png", scale=1.0, area=(0,0,0,0), fmt_options={}):
    """Take a screenshot of the desired target area."""
    logger.debug("Taking screenshot (target=%d)." % target)
    root = gtk.gdk.screen_get_default()
    root_win = root.get_root_window()
    active = get_active_window(root)
    if active == None and target in (ACTIVE_WINDOW, ACTIVE_MONITOR):
        # Fallback to everything
        target = ENTIRE_DESKTOP
    
    if target == ARBITRARY_AREA:<commit_msg>Allow None as active window.<commit_after>import os
import logging
import gtk.gdk

ARBITRARY_AREA = 0 # Specified area
ACTIVE_WINDOW = 1 # Focused/top window only
ACTIVE_MONITOR = 2 # Monitor containing the active window
CURSOR_MONITOR = 3 # Monitor containing the cursor
ENTIRE_DESKTOP = 4 # Everything

logger = logging.getLogger(__name__)

def get_active_window(root=None):
    """Returns the active (focused, top) window, or None."""
    root = root or gtk.gdk.get_root_window()
    # Make sure active window hinting is working
    if root.supports_net_wm_hint("_NET_ACTIVE_WINDOW") and root.supports_net_wm_hint("_NET_WM_WINDOW_TYPE"):
        active = root.get_active_window()
        if not active:
            return None
        # If active window is a desktop, fail
        if active.property_get("_NET_WM_WINDOW_TYPE")[-1][0] == '_NET_WM_WINDOW_TYPE_DESKTOP':
            return None
        return active
    else:
        return None

def get_active_monitor(root=None):
    """Returns the index of the active monitor, or -1 if undetermined."""
    root = root or gtk.gdk.get_root_window()
    num_monitors = root.get_n_monitors()
    if (num_monitors == 1):
        return 0
    active = get_active_window()
    if active != None:
        return root.get_monitor_at_window(active)
    else:
        return -1

def take_screenshot(filepath, target=ACTIVE_MONITOR, fmt="png", scale=1.0, area=(0,0,0,0), fmt_options={}):
    """Take a screenshot of the desired target area."""
    logger.debug("Taking screenshot (target=%d)." % target)
    root = gtk.gdk.screen_get_default()
    root_win = root.get_root_window()
    active = get_active_window(root)
    if active == None and target in (ACTIVE_WINDOW, ACTIVE_MONITOR):
        # Fallback to everything
        target = ENTIRE_DESKTOP
    
    if target == ARBITRARY_AREA:
{'fraction_non_alphanumeric': 0.097669256381798, 'fraction_numerical': 0.009433962264150943, 'mean_word_length': 3.523212045169385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3044118', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1170, 'n_words': 312}