text: // Generated by CoffeeScript 2.3.2
  (function() {
    'use strict';
    var CND, CP, L, badge, rpr;
  
    //###########################################################################################################
    CND = require('cnd');
  
    rpr = CND.rpr;
  
    badge = 'INTERFLUG/WID-FROM-PID';
  
    // debug                     = CND.get_logger 'debug',     badge
    // warn                      = CND.get_logger 'warn',      badge
    // info                      = CND.get_logger 'info',      badge
    // urge                      = CND.get_logger 'urge',      badge
    // help                      = CND.get_logger 'help',      badge
    // whisper                   = CND.get_logger 'whisper',   badge
    // echo                      = CND.echo.bind CND
    //...........................................................................................................
    CP = require('child_process');
  
    //-----------------------------------------------------------------------------------------------------------
    this._read_pids_and_window_ids = function(pid = null) {
      /* Associate process IDs (PIDs) and GUI window IDs (WIDs) using `wmctrl`. When no `pid` is given, return
      a POD that maps PIDs to WIDs; if a `pid` is given, return either the matching WID or `null` if none was
      found. Instead of using this method directly, use `get_pids_and_window_ids()` and `window_id_from_pid pid`
      instead because of their clearer semantics. */
      var R, command, i, len, line, line_pattern, lines, message, split_line, that_pid, that_wid;
      line_pattern = /^(?<wid>\S+)\s+(?:\S+)\s+(?<pid>\S+)\s+/;
      R = pid != null ? null : {};
      command = "wmctrl -lp";
      //.........................................................................................................
      split_line = function(line) {
        var groups;
        groups = (line.match(line_pattern)).groups;
        // return { wid: groups.wid, pid: ( parseInt groups.pid, 10 ), }
        return [parseInt(groups.pid, 10), groups.wid];
      };
      //.........................................................................................................
      message = CP.execSync(command, {
        encoding: 'utf-8'
      });
      lines = message.split(/\n/);
      for (i = 0, len = lines.length; i < len; i++) {
        line = lines[i];
        if (line === '') {
          continue;
        }
        [that_pid, that_wid] = split_line(line);
        if (pid != null) {
          if (pid === that_pid) {
            return that_wid;
          }
          continue;
        }
        R[that_pid] = that_wid;
      }
      return R;
    };
  
    //-----------------------------------------------------------------------------------------------------------
    this.get_pids_and_window_ids = function() {
      return this._read_pids_and_window_ids();
    };
  
    this.window_id_from_pid = function(pid) {
      return this._read_pids_and_window_ids(pid);
    };
  
    //-----------------------------------------------------------------------------------------------------------
    this.wait_for_window_id_from_pid = function(pid, dtms = 500) {
      return new Promise((resolve, reject) => {
        var probe_wid, tid;
        probe_wid = () => {
          var R;
          R = this.window_id_from_pid(pid);
          if (R != null) {
            clearInterval(tid);
            resolve(R);
          }
          return null;
        };
        tid = setInterval(probe_wid, dtms);
        return null;
      });
    };
  
    //###########################################################################################################
    if (module.parent == null) {
      L = this;
      (function() {
        info(L.get_pids_and_window_ids());
        info(L.window_id_from_pid(26418));
        info(L.window_id_from_pid(1111111));
        return null;
      })();
    }
  
  }).call(this);
  
  //# sourceMappingURL=wid-from-pid.js.map
  