Sha256: 0166dbea1b5b63787c1d71515c83dfcd7af8c2bd4ba4312bfab7402f7e55d577

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require "clock_window/version"

module ClockWindow
  class ClockIt
    # As this will get more sophisticated this class is the UI
    def initialize
      @os_cmd = OScommand.new
    end

    def active_window
      exe, format = @os_cmd.active_window
      format.call(`#{exe}`)
    end
  end

  class OScommand
    # As this will get more sophisticated this class is the Back End
    def initialize
      # Detect operating system
      @os = "Linux"
    end

    # output will be a two parameter array
    # the first will be an OS specific executable string
    # the second will be formatting the return value from the executables output
    def active_window
      # Choose script to execute and format output to just window name
      case @os
      when "Linux"
        exe = "xprop -id $(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2) _NET_WM_NAME"
        format = ->str{ str.match(/.*\"(.*)\"\n\z/)[1][0..60] }
        [exe, format]
      else
        raise "Not implemented"
      end
    end
  end
  private_constant :OScommand
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clock_window-0.0.3 lib/clock_window.rb
clock_window-0.0.2 lib/clock_window.rb