Module Snarl::SnarlAPI
In: lib/snarl.rb

This is the lowlevel API implemenation using DL and a few handy constants from the snarl api and the Win32 API Note that I have jump through some hoops to get the array of characters to work corretly — if you know a better way please send me (phurley@gmail.com) a note.

Methods

send   to_cha  

Constants

SNARL_SHOW = 1
SNARL_HIDE = 2
SNARL_UPDATE = 3
SNARL_IS_VISIBLE = 4
SNARL_GET_VERSION = 5
SNARL_REGISTER_CONFIG_WINDOW = 6
SNARL_REVOKE_CONFIG_WINDOW = 7
SNARL_TEXT_LENGTH = 1024
WM_COPYDATA = 0x4a
SnarlStruct = struct [ "int cmd", "long id", "long timeout", "long data2", "char title[#{SNARL_TEXT_LENGTH}]", "char text[#{SNARL_TEXT_LENGTH}]", "char icon[#{SNARL_TEXT_LENGTH}]", ]
CopyDataStruct = struct [ "long dwData", "long cbData", "void* lpData", ]

Public Class methods

Send the structure off to snarl, the routine will return (if everything goes well) the result of SendMessage which has an overloaded meaning based upon the cmd being sent

[Source]

    # File lib/snarl.rb, line 60
60:     def self.send(ss)
61:       if isWindow(hwnd = findWindow(nil, 'Snarl'))
62:         cd = CopyDataStruct.malloc
63:         cd.dwData = 2
64:         cd.cbData = ss.size
65:         cd.lpData = ss.to_ptr
66:         sendMessage(hwnd, WM_COPYDATA, 0, cd.to_ptr)
67:       end
68:     end

character array hoop jumping, we take the passed string and convert it into an array of integers, padded out to the correct length to_cha —> to character array I do this as it seems necessary to fit the DL API, if there is a better way please let me know

[Source]

    # File lib/snarl.rb, line 52
52:     def self.to_cha(str)
53:       result = str.split(/(.)/).map { |ch| ch[0] }.compact
54:       result + Array.new(SNARL_TEXT_LENGTH - result.size, 0)
55:     end

[Validate]